aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMy-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com>2021-09-08 17:55:23 -0400
committerMy-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com>2021-09-08 18:01:27 -0400
commit48adf4239755cb089679eea805d1e7a47df49da2 (patch)
tree7991e98268f8e2fe4385f21a602769dc40ecab5b
parent4f7add0a130a120c09654db5c168e2a875f3e209 (diff)
downloadSkytilsMod-48adf4239755cb089679eea805d1e7a47df49da2.tar.gz
SkytilsMod-48adf4239755cb089679eea805d1e7a47df49da2.tar.bz2
SkytilsMod-48adf4239755cb089679eea805d1e7a47df49da2.zip
asm professional pt2
-rw-r--r--src/main/java/skytils/skytilsmod/mixins/transformers/forge/MixinSplashProgress.java34
-rw-r--r--src/main/kotlin/skytils/skytilsmod/asm/SkytilsTransformer.kt2
-rw-r--r--src/main/kotlin/skytils/skytilsmod/asm/transformers/SplashProgressTransformer.kt87
-rw-r--r--src/main/kotlin/skytils/skytilsmod/mixins/hooks/forge/SplashProgressHook.kt43
-rw-r--r--src/main/resources/mixins.skytils.json1
5 files changed, 89 insertions, 78 deletions
diff --git a/src/main/java/skytils/skytilsmod/mixins/transformers/forge/MixinSplashProgress.java b/src/main/java/skytils/skytilsmod/mixins/transformers/forge/MixinSplashProgress.java
deleted file mode 100644
index a79d4780..00000000
--- a/src/main/java/skytils/skytilsmod/mixins/transformers/forge/MixinSplashProgress.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Skytils - Hypixel Skyblock Quality of Life Mod
- * Copyright (C) 2021 Skytils
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published
- * by the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package skytils.skytilsmod.mixins.transformers.forge;
-
-import net.minecraft.util.ResourceLocation;
-import net.minecraftforge.fml.client.SplashProgress;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.ModifyVariable;
-import skytils.skytilsmod.mixins.hooks.forge.SplashProgressHookKt;
-
-@Mixin(value = SplashProgress.class, priority = 0x7fffffff)
-public abstract class MixinSplashProgress {
- @ModifyVariable(method = "start", at = @At(value = "STORE"), ordinal = 2, remap = false)
- private static ResourceLocation setForgeGif(ResourceLocation resourceLocation) {
- return SplashProgressHookKt.setForgeGif(resourceLocation);
- }
-}
diff --git a/src/main/kotlin/skytils/skytilsmod/asm/SkytilsTransformer.kt b/src/main/kotlin/skytils/skytilsmod/asm/SkytilsTransformer.kt
index b2a87b5f..122072b6 100644
--- a/src/main/kotlin/skytils/skytilsmod/asm/SkytilsTransformer.kt
+++ b/src/main/kotlin/skytils/skytilsmod/asm/SkytilsTransformer.kt
@@ -20,6 +20,7 @@ package skytils.skytilsmod.asm
import dev.falsehonesty.asmhelper.BaseClassTransformer
import skytils.skytilsmod.asm.transformers.addColoredNamesCheck
+import skytils.skytilsmod.asm.transformers.injectSplashProgressTransformer
class SkytilsTransformer : BaseClassTransformer() {
var transformed = false
@@ -28,6 +29,7 @@ class SkytilsTransformer : BaseClassTransformer() {
if (!transformed) {
transformed = true
addColoredNamesCheck()
+ injectSplashProgressTransformer()
}
}
} \ No newline at end of file
diff --git a/src/main/kotlin/skytils/skytilsmod/asm/transformers/SplashProgressTransformer.kt b/src/main/kotlin/skytils/skytilsmod/asm/transformers/SplashProgressTransformer.kt
new file mode 100644
index 00000000..bfda8f2c
--- /dev/null
+++ b/src/main/kotlin/skytils/skytilsmod/asm/transformers/SplashProgressTransformer.kt
@@ -0,0 +1,87 @@
+/*
+ * Skytils - Hypixel Skyblock Quality of Life Mod
+ * Copyright (C) 2021 Skytils
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package skytils.skytilsmod.asm.transformers
+
+import dev.falsehonesty.asmhelper.dsl.instructions.InsnListBuilder
+import dev.falsehonesty.asmhelper.dsl.modify
+import net.minecraft.util.ResourceLocation
+import org.objectweb.asm.Opcodes
+import org.objectweb.asm.tree.MethodInsnNode
+import org.objectweb.asm.tree.VarInsnNode
+import skytils.skytilsmod.utils.Utils
+import kotlin.random.Random
+
+fun injectSplashProgressTransformer() = modify("net.minecraftforge.fml.client.SplashProgress") {
+ findMethod("start", "()V").apply {
+ val v = localVariables.find {
+ it.name == "forgeLoc" && it.desc == "Lnet/minecraft/util/ResourceLocation;"
+ } ?: return@modify
+ var index = -1
+ for (insn in instructions) {
+ if (insn is MethodInsnNode) {
+ if (insn.owner == "net/minecraftforge/fml/client/SplashProgress" && insn.name == "getMaxTextureSize") {
+ val list = InsnListBuilder(this).apply {
+ aload(v.index)
+ invokeStatic(
+ "skytils/skytilsmod/asm/transformers/SplashProgressTransformer",
+ "setForgeGif",
+ "(Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/util/ResourceLocation;"
+ )
+ astore().also {
+ index = it.index
+ }
+ }
+ instructions.insertBefore(insn, list.build());
+ }
+ if (insn.owner == "net/minecraftforge/fml/client/SplashProgress$3" && insn.name == "<init>") {
+ if (index == -1) {
+ println("Failed to inject local variable, breaking")
+ break
+ }
+ instructions.remove(insn.previous)
+ instructions.insertBefore(insn, VarInsnNode(Opcodes.ALOAD, index))
+ }
+ }
+ }
+ }
+}
+
+object SplashProgressTransformer {
+ val gifs = mapOf(
+ 0.0 to ResourceLocation("skytils", "sychicpet.gif"),
+ 90.0 to ResourceLocation("skytils", "sychiccat.png"),
+ 96.0 to ResourceLocation("skytils", "azoopet.gif"),
+ 99.0 to ResourceLocation("skytils", "abdpfp.gif"),
+ // this is the chance of winning the jackpot on the lottery, but even less due to a loss of precision
+ 100 - 100 * 1 / 302_575_350.0 to ResourceLocation("skytils", "jamcat.gif")
+ )
+
+ @JvmStatic
+ fun setForgeGif(resourceLocation: ResourceLocation): ResourceLocation {
+ return if (Utils.noSychic) resourceLocation else {
+ val weight = Random.nextDouble() * 100
+ (gifs.entries.reversed().find { weight >= it.key }?.value ?: ResourceLocation(
+ "skytils",
+ "sychicpet.gif"
+ )).also {
+ println("Rolled a $weight, displaying ${it.resourcePath}")
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/skytils/skytilsmod/mixins/hooks/forge/SplashProgressHook.kt b/src/main/kotlin/skytils/skytilsmod/mixins/hooks/forge/SplashProgressHook.kt
deleted file mode 100644
index 6706f6c5..00000000
--- a/src/main/kotlin/skytils/skytilsmod/mixins/hooks/forge/SplashProgressHook.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Skytils - Hypixel Skyblock Quality of Life Mod
- * Copyright (C) 2021 Skytils
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published
- * by the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-package skytils.skytilsmod.mixins.hooks.forge
-
-import net.minecraft.util.ResourceLocation
-import skytils.skytilsmod.utils.Utils
-import kotlin.random.Random
-
-val gifs = mapOf(
- 0.0 to ResourceLocation("skytils", "sychicpet.gif"),
- 90.0 to ResourceLocation("skytils", "sychiccat.png"),
- 96.0 to ResourceLocation("skytils", "azoopet.gif"),
- 99.0 to ResourceLocation("skytils", "abdpfp.gif"),
- // this is the chance of winning the jackpot on the lottery, but even less due to a loss of precision
- 100 - 100 * 1 / 302_575_350.0 to ResourceLocation("skytils", "jamcat.gif")
-)
-
-fun setForgeGif(resourceLocation: ResourceLocation): ResourceLocation {
- return if (Utils.noSychic) resourceLocation else {
- val weight = Random.nextDouble() * 100
- (gifs.entries.reversed().find { weight >= it.key }?.value ?: ResourceLocation(
- "skytils",
- "sychicpet.gif"
- )).also {
- println("Rolled a $weight, displaying ${it.resourcePath}")
- }
- }
-} \ No newline at end of file
diff --git a/src/main/resources/mixins.skytils.json b/src/main/resources/mixins.skytils.json
index 9071d46f..5c4461cf 100644
--- a/src/main/resources/mixins.skytils.json
+++ b/src/main/resources/mixins.skytils.json
@@ -23,7 +23,6 @@
"entity.MixinEntityBlaze",
"entity.MixinEntityLivingBase",
"entity.MixinEntityPlayerSP",
- "forge.MixinSplashProgress",
"gui.MixinGuiContainer",
"gui.MixinGuiIngame",
"gui.MixinGuiIngameForge",