From 8b8693c557c81068e3f20ac1cf3f4b70c04aa728 Mon Sep 17 00:00:00 2001 From: asbyth Date: Sun, 8 Nov 2020 13:09:46 -0500 Subject: [PATCH] fix: resolve levelhead position issues --- .../LevelheadAboveHeadRenderTransformer.java | 8 +-- .../asm/forge/ForgeChunkManagerTransformer.kt | 4 +- .../asm/forge/ModelLoaderTransformer.kt | 25 ++++---- .../forge/VertexLighterSmoothAoTransformer.kt | 60 ++++++++++--------- 4 files changed, 49 insertions(+), 48 deletions(-) diff --git a/src/main/java/club/sk1er/patcher/tweaker/asm/levelhead/LevelheadAboveHeadRenderTransformer.java b/src/main/java/club/sk1er/patcher/tweaker/asm/levelhead/LevelheadAboveHeadRenderTransformer.java index 8a6bafbb6..972b7df23 100644 --- a/src/main/java/club/sk1er/patcher/tweaker/asm/levelhead/LevelheadAboveHeadRenderTransformer.java +++ b/src/main/java/club/sk1er/patcher/tweaker/asm/levelhead/LevelheadAboveHeadRenderTransformer.java @@ -12,7 +12,6 @@ package club.sk1er.patcher.tweaker.asm.levelhead; import club.sk1er.patcher.tweaker.transform.CommonTransformer; -import club.sk1er.patcher.tweaker.transform.PatcherTransformer; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.ClassNode; @@ -22,9 +21,7 @@ import org.objectweb.asm.tree.JumpInsnNode; import org.objectweb.asm.tree.LabelNode; import org.objectweb.asm.tree.LdcInsnNode; -import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; -import org.objectweb.asm.tree.VarInsnNode; import java.util.ListIterator; @@ -61,7 +58,7 @@ public void transform(ClassNode classNode, String name) { if (next instanceof InsnNode && next.getOpcode() == Opcodes.DCONST_0) { LabelNode gotoInsn = new LabelNode(); methodNode.instructions.insertBefore(next, moveNametag(gotoInsn)); - methodNode.instructions.insertBefore(next.getNext().getNext(), gotoInsn); + methodNode.instructions.insertBefore(next.getNext(), gotoInsn); break; } } @@ -75,9 +72,8 @@ private InsnList moveNametag(LabelNode gotoInsn) { LabelNode ifeq = new LabelNode(); list.add(new JumpInsnNode(Opcodes.IFEQ, ifeq)); list.add(new LdcInsnNode(0.3D)); - list.add(new VarInsnNode(Opcodes.DSTORE, 9)); - list.add(ifeq); list.add(new JumpInsnNode(Opcodes.GOTO, gotoInsn)); + list.add(ifeq); return list; } } diff --git a/src/main/kotlin/club/sk1er/patcher/asm/forge/ForgeChunkManagerTransformer.kt b/src/main/kotlin/club/sk1er/patcher/asm/forge/ForgeChunkManagerTransformer.kt index c6b61171d..6ab7f6299 100644 --- a/src/main/kotlin/club/sk1er/patcher/asm/forge/ForgeChunkManagerTransformer.kt +++ b/src/main/kotlin/club/sk1er/patcher/asm/forge/ForgeChunkManagerTransformer.kt @@ -33,7 +33,7 @@ class ForgeChunkManagerTransformer : PatcherTransformer { method.instructions.remove(insn.getPrevious()) } - val (assignForcedChunks) = assembleBlock { + val (assignForcedChunks, _) = assembleBlock { new(WeakHashMap::class) dup invokespecial(WeakHashMap::class, "", void) @@ -47,7 +47,7 @@ class ForgeChunkManagerTransformer : PatcherTransformer { } "unloadWorld" -> { - val (removeWorld) = assembleBlock { + val (removeWorld, _) = assembleBlock { getstatic("net/minecraftforge/common/ForgeChunkManager", "forcedChunks", Map::class) aload_0 invokeinterface(Map::class, "remove", Object::class, Object::class) diff --git a/src/main/kotlin/club/sk1er/patcher/asm/forge/ModelLoaderTransformer.kt b/src/main/kotlin/club/sk1er/patcher/asm/forge/ModelLoaderTransformer.kt index b366a20c0..e08ee8002 100644 --- a/src/main/kotlin/club/sk1er/patcher/asm/forge/ModelLoaderTransformer.kt +++ b/src/main/kotlin/club/sk1er/patcher/asm/forge/ModelLoaderTransformer.kt @@ -43,20 +43,21 @@ class ModelLoaderTransformer : PatcherTransformer { val callLoadItems = MethodNode(Opcodes.ACC_PUBLIC, "callLoadItems", "()V", null, null) callLoadItems.instructions.add(createCallLoadItems()) classNode.methods.add(callLoadItems) - for (methodNode in classNode.methods) { - val methodName = mapMethodName(classNode, methodNode) - if (methodNode.name == "onPostBakeEvent") { - val iterator = methodNode.instructions.iterator() - while (iterator.hasNext()) { - val next = iterator.next() - if (next is FieldInsnNode && next.name == "isLoading") { - methodNode.instructions.insertBefore(next.getPrevious(), clearMemory()) - break + classNode.methods.forEach { + when (mapMethodName(classNode, it)) { + "onPostBakeEvent" -> { + for (insn in it.instructions) { + if (insn is FieldInsnNode && insn.name == "isLoading") { + it.instructions.insertBefore(insn.previous, clearMemory()) + break + } } } - } else if (methodName == "setupModelRegistry" || methodName == "func_177570_a") { - clearInstructions(methodNode) - methodNode.instructions.insert(getAsyncLoader(methodNode)) + + "setupModelRegistry", "func_177570_a" -> { + clearInstructions(it) + it.instructions.insert(getAsyncLoader(it)) + } } } } diff --git a/src/main/kotlin/club/sk1er/patcher/asm/forge/VertexLighterSmoothAoTransformer.kt b/src/main/kotlin/club/sk1er/patcher/asm/forge/VertexLighterSmoothAoTransformer.kt index 1c5985cf0..4df0c3e2d 100644 --- a/src/main/kotlin/club/sk1er/patcher/asm/forge/VertexLighterSmoothAoTransformer.kt +++ b/src/main/kotlin/club/sk1er/patcher/asm/forge/VertexLighterSmoothAoTransformer.kt @@ -31,35 +31,39 @@ class VertexLighterSmoothAoTransformer : PatcherTransformer { * @param name the transformed class name */ override fun transform(classNode: ClassNode, name: String) { - for (methodNode in classNode.methods) { - if (methodNode.name == "calcLightmap") { - clearInstructions(methodNode) - methodNode.desc = "([FFFF)V" - injectInstructions { - of(VertexLighterSmoothAoHook::fastCalcLightmap) - into(methodNode) - params(0, 1, 2, 3, 4) - keepReturns + classNode.methods.forEach { + when (it.name) { + "calcLightMap" -> { + clearInstructions(it) + it.desc = "([FFFF)V" + injectInstructions { + of(VertexLighterSmoothAoHook::fastCalcLightmap) + into(it) + params(0, 1, 2, 3, 4) + keepReturns + } + } + + "updateLightmap" -> { + clearInstructions(it) + it.instructions.insert(assembleBlock { + aload_0 + aload_2 + fload_3 + fload(4) + fload(5) + invokevirtual( + "net/minecraftforge/client/model/pipeline/VertexLighterSmoothAo", + "calcLightmap", + void, + FloatArray::class, + float, + float, + float + ) + _return + }.first) } - } else if (methodNode.name == "updateLightmap") { - clearInstructions(methodNode) - methodNode.instructions.insert(assembleBlock { - aload_0 - aload_2 - fload_3 - fload(4) - fload(5) - invokevirtual( - "net/minecraftforge/client/model/pipeline/VertexLighterSmoothAo", - "calcLightmap", - void, - FloatArray::class, - float, - float, - float - ) - _return - }.first) } } }