|
23 | 23 | */ |
24 | 24 | package com.fox2code.foxloader.patching.game; |
25 | 25 |
|
26 | | -import com.fox2code.foxloader.patching.TransformerUtils; |
27 | | -import org.objectweb.asm.Opcodes; |
28 | | -import org.objectweb.asm.Type; |
29 | 26 | import org.objectweb.asm.tree.*; |
30 | 27 |
|
31 | 28 | /** |
32 | 29 | * Theses are just hotfixes for the game, dedicated to fixing ReIndev bugs and crashes. |
33 | 30 | */ |
34 | 31 | final class HotfixesPatch extends GamePatch { |
35 | | - private static final String Packet = "net/minecraft/common/networking/Packet"; |
36 | | - private static final String Packet249Chunk = "net/minecraft/common/networking/Packet249Chunk"; |
37 | | - private static final String Minecraft = "net/minecraft/client/Minecraft"; |
38 | | - private static final String GameSettings = "net/minecraft/client/util/GameSettings"; |
39 | | - static final boolean USE_HOTFIXES = true; |
| 32 | + static final boolean USE_HOTFIXES = false; |
40 | 33 |
|
41 | 34 | HotfixesPatch() { |
42 | | - super(new String[]{Packet, Minecraft, GameSettings}); |
| 35 | + super(new String[]{}); |
43 | 36 | } |
44 | 37 |
|
45 | 38 | @Override |
46 | 39 | public ClassNode transform(ClassNode classNode) { |
47 | | - switch (classNode.name) { |
48 | | - case Packet: |
49 | | - patchPacket(classNode); |
50 | | - break; |
51 | | - case Minecraft: |
52 | | - patchMinecraft(classNode); |
53 | | - break; |
54 | | - case GameSettings: |
55 | | - patchGameSettings(classNode); |
56 | | - break; |
57 | | - } |
58 | 40 | return classNode; |
59 | 41 | } |
60 | 42 |
|
61 | | - private static void patchPacket(ClassNode classNode) { |
62 | | - // Hotfix Packet249Chunk being parsed by the server if sent by the client. |
63 | | - MethodNode clInit = TransformerUtils.getMethod(classNode, "<clinit>"); |
64 | | - for (AbstractInsnNode abstractInsnNode : clInit.instructions) { |
65 | | - if (abstractInsnNode.getOpcode() == LDC) { |
66 | | - LdcInsnNode ldcInsnNode = (LdcInsnNode) abstractInsnNode; |
67 | | - if (ldcInsnNode.cst instanceof Type && |
68 | | - Packet249Chunk.equals(((Type) ldcInsnNode.cst).getInternalName())) { |
69 | | - AbstractInsnNode previous = ldcInsnNode.getPrevious(); |
70 | | - AbstractInsnNode previous2 = previous.getPrevious(); |
71 | | - if (previous.getOpcode() == ICONST_1 && previous2.getOpcode() == ICONST_1) { |
72 | | - clInit.instructions.set(previous, new InsnNode(ICONST_0)); |
73 | | - clInit.instructions.set(previous2, new InsnNode(ICONST_0)); |
74 | | - } |
75 | | - break; |
76 | | - } |
77 | | - } |
78 | | - } |
79 | | - } |
80 | | - |
81 | | - private static void patchMinecraft(ClassNode classNode) { |
82 | | - // Hotfix switching to fullscreen sometimes causing the game to crash. |
83 | | - MethodNode toggleFullscreenImpl = TransformerUtils.findMethod(classNode, "toggleFullscreenImpl"); |
84 | | - FieldNode gameSettingsField = TransformerUtils.findFieldDesc(classNode, "L" + GameSettings + ";"); |
85 | | - if (toggleFullscreenImpl == null || gameSettingsField == null) return; |
86 | | - for (AbstractInsnNode abstractInsnNode : toggleFullscreenImpl.instructions) { |
87 | | - MethodInsnNode methodInsnNode; |
88 | | - if (abstractInsnNode.getOpcode() == Opcodes.INVOKEVIRTUAL && |
89 | | - GameSettings.equals((methodInsnNode = (MethodInsnNode) abstractInsnNode).owner) && |
90 | | - "setOptionValue".equals(methodInsnNode.name) && methodInsnNode.desc.endsWith(")V")) { |
91 | | - AbstractInsnNode start = TransformerUtils.previousNonCodeInsn(methodInsnNode); |
92 | | - TransformerUtils.removeInstructionsInRange( |
93 | | - toggleFullscreenImpl.instructions, start, methodInsnNode.getNext()); |
94 | | - InsnList insnList = new InsnList(); |
95 | | - insnList.add(new VarInsnNode(ALOAD, 0)); |
96 | | - insnList.add(new FieldInsnNode(GETFIELD, Minecraft, |
97 | | - gameSettingsField.name, gameSettingsField.desc)); |
98 | | - insnList.add(new VarInsnNode(ILOAD, 1)); |
99 | | - insnList.add(new MethodInsnNode(INVOKEVIRTUAL, GameSettings, |
100 | | - "setFullscreenState", "(Z)V")); |
101 | | - toggleFullscreenImpl.instructions.insert(start, insnList); |
102 | | - } |
103 | | - } |
104 | | - } |
105 | | - |
106 | | - private static void patchGameSettings(ClassNode classNode) { |
107 | | - // Hotfix switching to fullscreen sometimes causing the game to crash. |
108 | | - if (TransformerUtils.findMethod(classNode, "setFullscreenState", "(Z)V") != null) { |
109 | | - return; |
110 | | - } |
111 | | - FieldNode fullscreenField = TransformerUtils.getField(classNode, "fullScreen"); |
112 | | - MethodNode setFullscreenState = new MethodNode(ACC_PUBLIC, |
113 | | - "setFullscreenState", "(Z)V", null, null); |
114 | | - setFullscreenState.instructions.add(new VarInsnNode(ALOAD, 0)); |
115 | | - setFullscreenState.instructions.add(new VarInsnNode(ILOAD, 1)); |
116 | | - setFullscreenState.instructions.add(new FieldInsnNode(PUTFIELD, |
117 | | - GameSettings, fullscreenField.name, fullscreenField.desc)); |
118 | | - setFullscreenState.instructions.add(new InsnNode(RETURN)); |
119 | | - TransformerUtils.setThisParameterName(classNode, setFullscreenState); |
120 | | - TransformerUtils.setParameterName(setFullscreenState, 1, "fullscreen"); |
121 | | - classNode.methods.add(setFullscreenState); |
122 | | - } |
123 | 43 | } |
0 commit comments