From 94e6c479359c68d7dbf9b657aad86ab3fa12e525 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 16 Oct 2023 11:50:28 +0200 Subject: properly using the hook to not have potential broken code in the mixin itself, added inSkyBlock checks before accessing the config to fix `lateinit property configManager has not been initialized` startup crash --- .../skyhanni/mixins/hooks/FontRendererHook.kt | 23 ++++++++++++++++++++-- .../mixins/transformers/MixinFontRenderer.java | 8 ++------ 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/FontRendererHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/FontRendererHook.kt index 808406946..a2fc3ad76 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/FontRendererHook.kt +++ b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/FontRendererHook.kt @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.mixins.transformers.AccessorFontRenderer import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraft.client.Minecraft import net.minecraft.client.renderer.GlStateManager +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo /** * Object to handle chroma font states from handler methods from MixinFontRenderer @@ -98,6 +99,8 @@ object FontRendererHook { @JvmStatic fun forceWhiteColorCode(i1: Int) : Int { + if (!LorenzUtils.inSkyBlock) return i1 + if (!SkyHanniMod.feature.chroma.enabled) return i1 val drawState = currentDrawState ?: return i1 @@ -112,16 +115,16 @@ object FontRendererHook { @JvmStatic fun restoreChromaState() { - if (!SkyHanniMod.feature.chroma.enabled) return if (!LorenzUtils.inSkyBlock) return + if (!SkyHanniMod.feature.chroma.enabled) return currentDrawState?.restoreChromaEnv() } @JvmStatic fun endChromaRendering() { - if (!SkyHanniMod.feature.chroma.enabled) return if (!LorenzUtils.inSkyBlock) return + if (!SkyHanniMod.feature.chroma.enabled) return if (previewChroma) { previewChroma = false @@ -132,4 +135,20 @@ object FontRendererHook { currentDrawState?.endChromaEnv() } + + @JvmStatic + fun insertZColorCode(constant: String): String { + return if (LorenzUtils.inSkyBlock && !SkyHanniMod.feature.chroma.enabled) constant else "0123456789abcdefklmnorz" + } + + @JvmStatic + fun toggleChromaCondition_shouldResetStyles(text: String, shadow: Boolean, ci: CallbackInfo, i: Int, c0: Char, i1: Int): Boolean { + if (!LorenzUtils.inSkyBlock) return false + if (!SkyHanniMod.feature.chroma.enabled) return false + if (i1 == 22) { + toggleChromaOn() + return true + } + return false + } } \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinFontRenderer.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinFontRenderer.java index 7b6631ae4..2b3d87c5c 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinFontRenderer.java +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinFontRenderer.java @@ -1,6 +1,5 @@ package at.hannibal2.skyhanni.mixins.transformers; -import at.hannibal2.skyhanni.SkyHanniMod; import at.hannibal2.skyhanni.features.misc.visualwords.ModifyVisualWords; import at.hannibal2.skyhanni.mixins.hooks.FontRendererHook; import net.minecraft.client.gui.FontRenderer; @@ -31,8 +30,7 @@ public abstract class MixinFontRenderer { */ @ModifyConstant(method = "renderStringAtPos", constant = @Constant(stringValue = "0123456789abcdefklmnor")) public String insertZColorCode(String constant) { - if (!SkyHanniMod.getFeature().chroma.enabled) return constant; - return "0123456789abcdefklmnorz"; + return FontRendererHook.insertZColorCode(constant); } /** @@ -54,10 +52,8 @@ public abstract class MixinFontRenderer { */ @Inject(method = "renderStringAtPos", at = @At(value = "INVOKE", target = "Ljava/lang/String;indexOf(I)I", ordinal = 0, shift = At.Shift.BY, by = 2), locals = LocalCapture.CAPTURE_FAILHARD) public void toggleChromaCondition(String text, boolean shadow, CallbackInfo ci, int i, char c0, int i1) { - if (!SkyHanniMod.getFeature().chroma.enabled) return; - if (i1 == 22) { + if (FontRendererHook.toggleChromaCondition_shouldResetStyles(text, shadow, ci, i, c0, i1)) { this.resetStyles(); - FontRendererHook.toggleChromaOn(); } } -- cgit