diff --git a/src/Client/JClassPatcher.java b/src/Client/JClassPatcher.java index 2a7e20d..eab3eeb 100644 --- a/src/Client/JClassPatcher.java +++ b/src/Client/JClassPatcher.java @@ -34,6 +34,7 @@ import org.objectweb.asm.tree.FieldInsnNode; import org.objectweb.asm.tree.FieldNode; import org.objectweb.asm.tree.IincInsnNode; +import org.objectweb.asm.tree.InsnList; import org.objectweb.asm.tree.InsnNode; import org.objectweb.asm.tree.IntInsnNode; import org.objectweb.asm.tree.JumpInsnNode; @@ -41,6 +42,7 @@ import org.objectweb.asm.tree.LdcInsnNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; +import org.objectweb.asm.tree.TryCatchBlockNode; import org.objectweb.asm.tree.VarInsnNode; import org.objectweb.asm.util.Printer; import org.objectweb.asm.util.Textifier; @@ -732,6 +734,14 @@ private void patchClient(ClassNode node) { methodNode.instructions.insertBefore( findNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "init", "()V", false)); + + // Camera view distance crash fix + if (insnNode.getOpcode() == Opcodes.SIPUSH) { + IntInsnNode call = (IntInsnNode) insnNode; + if (call.operand == 15000) { + call.operand = 32767; + } + } } } if (methodNode.name.equals("dj") && methodNode.desc.equals("()V")) { @@ -2182,6 +2192,9 @@ private void patchScene(ClassNode node) { // Patch crash due to exceeding max polygons if (methodNode.name.equals("qi") && methodNode.desc.equals("()V")) { + + safeify(methodNode); + Iterator insnNodeList = methodNode.instructions.iterator(); int times = 0; while (insnNodeList.hasNext()) { @@ -2640,4 +2653,26 @@ public static JClassPatcher getInstance() { } return instance; } + + /** + * Wraps a given {@link MethodNode} in a try-catch block which simply returns, + * to prevent application crashes. + * + * @author Stormy + */ + private static void safeify(MethodNode methodNode) { + LabelNode method_start = new LabelNode(); + LabelNode method_end = new LabelNode(); + methodNode.instructions.insert(method_start); + methodNode.instructions.add(method_end); + + LabelNode handler = new LabelNode(); + InsnList list = new InsnList(); + list.add(handler); + list.add(new InsnNode(Opcodes.RETURN)); + methodNode.instructions.add(list); + + TryCatchBlockNode n = new TryCatchBlockNode(method_start, method_end, handler, "java/lang/RuntimeException"); + methodNode.tryCatchBlocks.add(n); + } }