Skip to content

Commit

Permalink
fix: resolve levelhead position issues
Browse files Browse the repository at this point in the history
  • Loading branch information
asbyth committed Nov 8, 2020
1 parent 7462d7b commit 8b8693c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<init>", void)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit 8b8693c

Please sign in to comment.