Skip to content

Commit

Permalink
Many a change (Wyvest pls take a look)
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Jan 19, 2025
1 parent 1817724 commit 0890614
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name=OneConfig
mod_id=oneconfig
version_major=1
version_minor=0
version_patch=0-alpha.57
version_patch=0-alpha.58

polyfrost.defaults.loom=3

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ hypixel-data = "0.1.2" # Dep of hypixel-modapi
# Not in risk of needing to be relaunched / bumped by JiJ
snakeyaml = "1.31"
nightconfig = "3.6.6"
isolated-lwjgl3-loader = "0.1.1"
isolated-lwjgl3-loader = "0.1.3"
polyio = "0.1.0"
copycat = "0.1.3"
copycat-image-awt = "0.1.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,24 @@ class NanoVgImpl(
}

override fun createFont(name: String, buffer: ByteBuffer): Int {
return nvgCreateFontMem(handle, name, buffer, false)
val clz = Class.forName("org.lwjgl.nanovg.NanoVG")
try {
val method = clz.getDeclaredMethod("nvgCreateFontMem", Long::class.java, CharSequence::class.java, ByteBuffer::class.java, Boolean::class.java)
return method.invoke(null, handle, name, buffer, false) as Int
} catch (e: NoSuchMethodException) {
try {
// This is required because some time between LWJGL 3.2.3 and 3.3.0, the signature of nvgCreateFontMem changed
// from using an int to represent a bool to simply using a boolean. This is a workaround to make the code compatible
// with both versions of LWJGL.
val method = clz.getDeclaredMethod("nvgCreateFontMem", Long::class.java, CharSequence::class.java, ByteBuffer::class.java, Int::class.java)
return method.invoke(null, handle, name, buffer, 0) as Int
} catch (e: NoSuchMethodException) {
// Just prints all of the methods to see what's available
clz.declaredMethods.forEach { println(it) }

throw IllegalStateException("Failed to find nvgCreateFontMem method")
}
}
}

override fun fontSize(size: Float) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ object KeybindManager {

val m = Int2IntMap(8)
m[UKeyboard.KEY_LSHIFT] = KeyModifiers.LSHIFT.value.toInt()
m[UKeyboard.KEY_LSHIFT] = KeyModifiers.LSHIFT.value.toInt()
m[UKeyboard.KEY_RSHIFT] = KeyModifiers.RSHIFT.value.toInt()
m[UKeyboard.KEY_LCONTROL] = KeyModifiers.LCONTROL.value.toInt()
m[UKeyboard.KEY_RCONTROL] = KeyModifiers.RCONTROL.value.toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public class UIManagerImpl implements UIManager {
private final Renderer renderer;

public UIManagerImpl() throws Throwable {
// Tells the isolated LWJGL3 loader that we want to download & load a slightly older LWJGL version
// because these Minecraft versions explode otherwise. This is likely due to the natives being
// moved in ~3.2.3
//#if MC >= 1.16.5 && MC <= 1.17.1
//$$ System.setProperty("isolatedlwjgl3loader.earlyVersion3", "true");
//#endif

Lwjgl3Manager.initialize(getClass().getClassLoader(), new String[] { "nanovg", "stb", "tinyfd" });

IsolatedClassLoader classLoader = Lwjgl3Manager.getClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ private void onInit(net.minecraftforge.fml.common.event.FMLPostInitializationEve
//#else
//$$ @Override
//$$ public void onInitializeClient() {
//$$ init();
//$$ // Uhhhhhhhhhhhhhhhhhhhhhhhhhhh......................
//$$ }
//#endif


private void init() {
public void init() {
//#if FABRIC
//$$ try {
//$$ Class.forName("org.polyfrost.oneconfig.test.TestMod_Test", false, getClass().getClassLoader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public List<String> getMixins() {

// Inter-loader mixins
if (version >= 11600) {
mixins.add("Mixin_ModernEntrypoint");
mixins.add("commands.Mixin_AppendCustomCommands");

if (version < 11900) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.polyfrost.oneconfig.internal.mixin;

//#if MC >= 1.16.5
//$$ import net.minecraft.client.Minecraft;
//$$ import org.polyfrost.oneconfig.internal.OneConfig;
//$$ import org.spongepowered.asm.mixin.Mixin;
//$$ import org.spongepowered.asm.mixin.Unique;
//$$ import org.spongepowered.asm.mixin.injection.At;
//$$ import org.spongepowered.asm.mixin.injection.Inject;
//$$ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
//$$
//$$ @Mixin(Minecraft.class)
//$$ public class Mixin_ModernEntrypoint {
//$$
//$$ @Unique
//$$ private boolean ocfg$initialized = false;
//$$
//$$ @Inject(method = "<init>", at = @At("RETURN"))
//$$ private void ocfg$entrypoint(CallbackInfo ci) {
//$$ if (ocfg$initialized) {
//$$ return;
//$$ }
//$$
//$$ OneConfig.INSTANCE.init();
//$$ ocfg$initialized = true;
//$$ }
//$$
//$$ }
//#endif

0 comments on commit 0890614

Please sign in to comment.