2323import org .objectweb .asm .tree .AbstractInsnNode ;
2424import org .objectweb .asm .tree .ClassNode ;
2525import org .objectweb .asm .tree .FieldNode ;
26- import org .objectweb .asm .tree .InsnList ;
2726import org .objectweb .asm .tree .IntInsnNode ;
2827import org .objectweb .asm .tree .MethodInsnNode ;
2928import org .objectweb .asm .tree .MethodNode ;
6463 *
6564 */
6665public class DelCharTweaker implements Tweaker {
67- private static String guiName ;
68- private static String guiScreenName ;
69-
7066 private LegacyTweakContext context ;
7167 private LaunchConfig config ;
7268
69+ private String guiName ;
70+ private String guiScreenName ;
71+
7372 public DelCharTweaker (LaunchConfig config , LegacyTweakContext context ) {
7473 this .config = config ;
7574 this .context = context ;
7675 }
7776
7877 private String getGuiScreenName (ClassNode node ) {
79- if (node == null ) {
80- return null ;
81- }
82-
8378 // public void displayGuiScreen(GuiScreen)
8479 for (MethodNode method : node .methods ) {
8580 if ((method .access & ACC_PUBLIC ) == 0 ) {
8681 continue ;
8782 }
8883
8984 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 ) {
9386 continue ;
9487 }
9588
96- InsnList insns = method .instructions ;
89+ Type returnType = Type .getReturnType (method .desc );
90+ if (returnType .getSort () != Type .VOID ) {
91+ continue ;
92+ }
9793
9894 // ((GuiScreen) _).setWorldAndResolution(Minecraft, int, int)
9995 // 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 )) {
110102 continue ;
111103 }
112104
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 ) {
124121 continue ;
125122 }
126123
@@ -132,7 +129,7 @@ private String getGuiScreenName(ClassNode node) {
132129 }
133130
134131 private boolean isGuiChat (ClassNode node ) {
135- if (node == null || guiScreenName == null || !node .superName .equals (guiScreenName )) {
132+ if (!node .superName .equals (guiScreenName )) {
136133 return false ;
137134 }
138135
@@ -181,12 +178,13 @@ else if ((field.access & ACC_PRIVATE) != 0 &&
181178 }
182179
183180 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+ }
185185
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 )) {
190188 return true ;
191189 }
192190 }
@@ -195,7 +193,7 @@ else if ((field.access & ACC_PRIVATE) != 0 &&
195193 }
196194
197195 private boolean isGuiTextField (ClassNode node ) {
198- if (node == null || guiName == null || !node .superName .equals (guiName )) {
196+ if (!node .superName .equals (guiName )) {
199197 return false ;
200198 }
201199
@@ -274,7 +272,7 @@ public boolean tweakClass(ClassNodeSource source, String name) {
274272 return false ;
275273 }
276274
277- DelCharTweaker .guiScreenName = guiScreenName ;
275+ this .guiScreenName = guiScreenName ;
278276 }
279277
280278 ClassNode guiScreenNode = source .getClass (guiScreenName );
@@ -288,7 +286,7 @@ public boolean tweakClass(ClassNodeSource source, String name) {
288286 return false ;
289287 }
290288
291- DelCharTweaker .guiName = guiName ;
289+ this .guiName = guiName ;
292290 }
293291
294292 ClassNode sourceNode = source .getClass (name );
0 commit comments