23
23
import org .objectweb .asm .tree .AbstractInsnNode ;
24
24
import org .objectweb .asm .tree .ClassNode ;
25
25
import org .objectweb .asm .tree .FieldNode ;
26
- import org .objectweb .asm .tree .InsnList ;
27
26
import org .objectweb .asm .tree .IntInsnNode ;
28
27
import org .objectweb .asm .tree .MethodInsnNode ;
29
28
import org .objectweb .asm .tree .MethodNode ;
64
63
*
65
64
*/
66
65
public class DelCharTweaker implements Tweaker {
67
- private static String guiName ;
68
- private static String guiScreenName ;
69
-
70
66
private LegacyTweakContext context ;
71
67
private LaunchConfig config ;
72
68
69
+ private String guiName ;
70
+ private String guiScreenName ;
71
+
73
72
public DelCharTweaker (LaunchConfig config , LegacyTweakContext context ) {
74
73
this .config = config ;
75
74
this .context = context ;
76
75
}
77
76
78
77
private String getGuiScreenName (ClassNode node ) {
79
- if (node == null ) {
80
- return null ;
81
- }
82
-
83
78
// public void displayGuiScreen(GuiScreen)
84
79
for (MethodNode method : node .methods ) {
85
80
if ((method .access & ACC_PUBLIC ) == 0 ) {
86
81
continue ;
87
82
}
88
83
89
84
Type [] argTypes = Type .getArgumentTypes (method .desc );
90
- Type returnType = Type .getReturnType (method .desc );
91
-
92
- if (argTypes .length != 1 || argTypes [0 ].getSort () != Type .OBJECT || returnType .getSort () != Type .VOID ) {
85
+ if (argTypes .length != 1 || argTypes [0 ].getSort () != Type .OBJECT ) {
93
86
continue ;
94
87
}
95
88
96
- InsnList insns = method .instructions ;
89
+ Type returnType = Type .getReturnType (method .desc );
90
+ if (returnType .getSort () != Type .VOID ) {
91
+ continue ;
92
+ }
97
93
98
94
// ((GuiScreen) _).setWorldAndResolution(Minecraft, int, int)
99
95
// ALOAD 1, ALOAD 0, ILOAD, ILOAD, INVOKEVIRTUAL
100
- for (int index = 0 ; index <= insns .size () - 5 ; index ++) {
101
- AbstractInsnNode insn0 = insns .get (index );
102
- AbstractInsnNode insn1 = insns .get (index + 1 );
103
- AbstractInsnNode insn2 = insns .get (index + 2 );
104
- AbstractInsnNode insn3 = insns .get (index + 3 );
105
- AbstractInsnNode insn4 = insns .get (index + 4 );
106
-
107
- if (!compareInsn (insn0 , ALOAD , 1 ) || !compareInsn (insn1 , ALOAD , 0 ) ||
108
- !compareInsn (insn2 , ILOAD ) || !compareInsn (insn3 , ILOAD ) ||
109
- !compareInsn (insn4 , INVOKEVIRTUAL )) {
96
+ for (int index = 0 ; index <= method .instructions .size () - 5 ; index ++) {
97
+ AbstractInsnNode [] insns = fill (method .instructions .get (index ), 5 );
98
+
99
+ if (!compareInsn (insns [0 ], ALOAD , 1 ) || !compareInsn (insns [1 ], ALOAD , 0 ) ||
100
+ !compareInsn (insns [2 ], ILOAD ) || !compareInsn (insns [3 ], ILOAD ) ||
101
+ !compareInsn (insns [4 ], INVOKEVIRTUAL )) {
110
102
continue ;
111
103
}
112
104
113
- MethodInsnNode methodInvocation = (MethodInsnNode ) insn4 ;
114
- Type [] methodArgTypes = Type .getArgumentTypes (methodInvocation .desc );
115
- Type methodReturnType = Type .getReturnType (methodInvocation .desc );
116
-
117
- if (!methodInvocation .owner .equals (argTypes [0 ].getInternalName ()) ||
118
- methodArgTypes .length != 3 ||
119
- methodArgTypes [0 ].getSort () != Type .OBJECT ||
120
- !methodArgTypes [0 ].getInternalName ().equals (node .name ) ||
121
- methodArgTypes [1 ].getSort () != Type .INT ||
122
- methodArgTypes [2 ].getSort () != Type .INT ||
123
- methodReturnType .getSort () != Type .VOID ) {
105
+ MethodInsnNode invokeInsn = (MethodInsnNode ) insns [4 ];
106
+ if (!invokeInsn .owner .equals (argTypes [0 ].getInternalName ())) {
107
+ continue ;
108
+ }
109
+
110
+ Type [] invokeArgTypes = Type .getArgumentTypes (invokeInsn .desc );
111
+ if (invokeArgTypes .length != 3 ||
112
+ invokeArgTypes [0 ].getSort () != Type .OBJECT ||
113
+ !invokeArgTypes [0 ].getInternalName ().equals (node .name ) ||
114
+ invokeArgTypes [1 ].getSort () != Type .INT ||
115
+ invokeArgTypes [2 ].getSort () != Type .INT ) {
116
+ continue ;
117
+ }
118
+
119
+ Type invokeReturnType = Type .getReturnType (invokeInsn .desc );
120
+ if (invokeReturnType .getSort () != Type .VOID ) {
124
121
continue ;
125
122
}
126
123
@@ -132,7 +129,7 @@ private String getGuiScreenName(ClassNode node) {
132
129
}
133
130
134
131
private boolean isGuiChat (ClassNode node ) {
135
- if (node == null || guiScreenName == null || !node .superName .equals (guiScreenName )) {
132
+ if (!node .superName .equals (guiScreenName )) {
136
133
return false ;
137
134
}
138
135
@@ -181,12 +178,13 @@ else if ((field.access & ACC_PRIVATE) != 0 &&
181
178
}
182
179
183
180
Type [] argTypes = Type .getArgumentTypes (method .desc );
184
- Type returnType = Type .getReturnType (method .desc );
181
+ if (argTypes .length != 2 || !argTypes [0 ].equals (Type .CHAR_TYPE ) &&
182
+ !argTypes [1 ].equals (Type .INT_TYPE )) {
183
+ continue ;
184
+ }
185
185
186
- if (argTypes .length == 2 &&
187
- argTypes [0 ].equals (Type .CHAR_TYPE ) &&
188
- argTypes [1 ].equals (Type .INT_TYPE ) &&
189
- returnType .equals (Type .VOID_TYPE )) {
186
+ Type returnType = Type .getReturnType (method .desc );
187
+ if (returnType .equals (Type .VOID_TYPE )) {
190
188
return true ;
191
189
}
192
190
}
@@ -195,7 +193,7 @@ else if ((field.access & ACC_PRIVATE) != 0 &&
195
193
}
196
194
197
195
private boolean isGuiTextField (ClassNode node ) {
198
- if (node == null || guiName == null || !node .superName .equals (guiName )) {
196
+ if (!node .superName .equals (guiName )) {
199
197
return false ;
200
198
}
201
199
@@ -274,7 +272,7 @@ public boolean tweakClass(ClassNodeSource source, String name) {
274
272
return false ;
275
273
}
276
274
277
- DelCharTweaker .guiScreenName = guiScreenName ;
275
+ this .guiScreenName = guiScreenName ;
278
276
}
279
277
280
278
ClassNode guiScreenNode = source .getClass (guiScreenName );
@@ -288,7 +286,7 @@ public boolean tweakClass(ClassNodeSource source, String name) {
288
286
return false ;
289
287
}
290
288
291
- DelCharTweaker .guiName = guiName ;
289
+ this .guiName = guiName ;
292
290
}
293
291
294
292
ClassNode sourceNode = source .getClass (name );
0 commit comments