forked from jss2a98aj/ArsMagica2
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathBytecodeTransformers.java
1471 lines (1217 loc) · 71.3 KB
/
BytecodeTransformers.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package am2.preloader;
import am2.LogHelper;
import net.minecraft.launchwrapper.IClassTransformer;
import net.tclproject.mysteriumlib.asm.common.CustomLoadingPlugin;
import net.tclproject.mysteriumlib.asm.fixes.MysteriumPatchesFixLoaderMagicka;
import org.apache.logging.log4j.Level;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.function.Consumer;
public class BytecodeTransformers implements IClassTransformer{
@Override
public byte[] transform(String name, String transformedName, byte[] bytes){
boolean is_obfuscated = !CustomLoadingPlugin.isDevEnvironment;
if (transformedName.equals("am2.armor.ItemMageHood") && (CustomLoadingPlugin.foundThaumcraft || checkIsThaumcraftFilePresent())){
LogHelper.info("Core: Altering definition of " + transformedName + " to be thaumcraft compatible.");
ClassReader cr = new ClassReader(bytes);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
cn.interfaces.add("thaumcraft/api/IGoggles");
cn.interfaces.add("thaumcraft/api/nodes/IRevealer");
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
bytes = cw.toByteArray();
}else if (transformedName.equals("net.minecraft.client.renderer.EntityRenderer")) {
LogHelper.info("Core: Altering definition of " + transformedName + ", " + (is_obfuscated ? " (obfuscated)" : "(not obfuscated)"));
bytes = alterEntityRenderer(bytes, is_obfuscated);
}else if(name.equals("net.minecraft.server.MinecraftServer") || transformedName.equals("net.minecraft.server.MinecraftServer")) {
LogHelper.info("Core: Altering definition of " + transformedName + ", " + (is_obfuscated ? " (obfuscated)" : "(not obfuscated)"));
bytes = alterServerTickrate(bytes);
}else if (transformedName.equals("net.minecraft.client.entity.EntityPlayerSP")){
LogHelper.info("Core: Altering definition of " + transformedName + ", " + (is_obfuscated ? " (obfuscated)" : "(not obfuscated)"));
bytes = alterEntityPlayerSP(bytes, is_obfuscated);
/*
// this part is actually no longer necessary
// it was used to handle storing the player's information on dimension transfers
// but we take care of that now in the event handler
// (it's actually a stroke of good luck that this code was never updated to 1.7.10 and never activated in a dev environment)
// (otherwise, I'd most likely not have been able to implement the fix for soulbound items in the End)
}else if (transformedName.equals("net.minecraft.entity.EntityPlayerMP")){
LogHelper.info("Core: Altering definition of " + transformedName + ", " + (is_obfuscated ? " (obfuscated)" : "(not obfuscated)"));
bytes = alterEntityPlayerMP(bytes, is_obfuscated);
*/
// MC r1.6.4: NetServerHandler.handleFlying, ka/a
// MC r1.7.10, NetHandlerPlayServer.processPlayer, nh/a
// }else if (transformedName.equals("net.minecraft.network.NetServerHandler")){
}else if (transformedName.equals("net.minecraft.network.NetHandlerPlayServer")){
LogHelper.info("Core: Altering definition of " + transformedName + ", " + (is_obfuscated ? " (obfuscated)" : "(not obfuscated)"));
// bytes = alterNetServerHandler(bytes);
bytes = alterNetHandlerPlayServer(bytes, is_obfuscated);
}else if (transformedName.equals("net.minecraft.client.renderer.entity.RendererLivingEntity")){
LogHelper.info("Core: Altering definition of " + transformedName + ", " + (is_obfuscated ? " (obfuscated)" : "(not obfuscated)"));
bytes = alterRendererLivingEntity(bytes, is_obfuscated);
}else if (transformedName.equals("net.minecraft.world.World")){
LogHelper.info("Core: Altering definition of " + transformedName + ", " + (is_obfuscated ? " (obfuscated)" : "(not obfuscated)"));
bytes = alterWorld(bytes, is_obfuscated);
}else if (transformedName.equals("net.minecraft.potion.PotionEffect") && !(CustomLoadingPlugin.foundDragonAPI || checkIsDragonApiFilePresent())){
// DragonAPI already has its own way to handle potion list ID extension
// you get horrible crashes when the two extensions are applied at the same time
// also, there's no sense in duplicating effort, so we'll do nothing in that situation
LogHelper.info("Core: Altering definition of " + transformedName + ", " + (is_obfuscated ? " (obfuscated)" : "(not obfuscated)"));
bytes = alterPotionEffect(bytes, is_obfuscated);
}else if (transformedName.equals("net.minecraft.network.play.server.S1DPacketEntityEffect") && !(CustomLoadingPlugin.foundDragonAPI || checkIsDragonApiFilePresent())){
LogHelper.info("Core: Altering definition of " + transformedName + ", " + (is_obfuscated ? " (obfuscated)" : "(not obfuscated)"));
String passedname = name.replace(".", "/");
bytes = alterS1DPacketEntityEffect(bytes, is_obfuscated, passedname);
}else if (transformedName.equals("net.minecraft.client.network.NetHandlerPlayClient") && !(CustomLoadingPlugin.foundDragonAPI || checkIsDragonApiFilePresent())){
LogHelper.info("Core: Altering definition of " + transformedName + ", " + (is_obfuscated ? " (obfuscated)" : "(not obfuscated)"));
bytes = alterNetHandlerPlayClient(bytes, is_obfuscated);
}else if (transformedName.equals("net.minecraft.network.play.server.S1EPacketRemoveEntityEffect") && !(CustomLoadingPlugin.foundDragonAPI || checkIsDragonApiFilePresent())){
LogHelper.info("Core: Altering definition of " + transformedName + ", " + (is_obfuscated ? " (obfuscated)" : "(not obfuscated)"));
bytes = alterS1EPacketRemoveEntityEffect(bytes, is_obfuscated);
}
return bytes;
}
// this method is courtesy of Guichaguri (TickRateChanger mod)
private byte[] alterServerTickrate(byte[] bytes) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, 0);
Iterator<MethodNode> methods = classNode.methods.iterator();
while(methods.hasNext()) {
MethodNode method = methods.next();
if((method.name.equals("run")) && (method.desc.equals("()V"))) {
InsnList list = new InsnList();
intrucLoop: for(AbstractInsnNode node : method.instructions.toArray()) {
if(node instanceof LdcInsnNode) {
LdcInsnNode ldcNode = (LdcInsnNode)node;
if((ldcNode.cst instanceof Long) && ((Long)ldcNode.cst == 50L)) {
list.add(new FieldInsnNode(Opcodes.GETSTATIC, "net/tclproject/mysteriumlib/asm/fixes/MysteriumPatchesFixesMagicka", "servertickrate", "J"));
continue intrucLoop;
}
}
list.add(node);
}
method.instructions.clear();
method.instructions.add(list);
}
}
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classNode.accept(writer);
return writer.toByteArray();
}
private byte[] alterRendererLivingEntity(byte[] bytes, boolean is_obfuscated){
ClassReader cr = new ClassReader(bytes);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
// Minecraft r1.7.10:
// net.minecraft.client.renderer.entity.RendererLivingEntity.java = boh.class
// RendererLivingEntity.doRender = boh.a
// MCP mapping: boh/a (Lsv;DDDFF)V net/minecraft/client/renderer/entity/RendererLivingEntity/func_76986_a (Lnet/minecraft/entity/EntityLivingBase;DDDFF)V
// RendererLivingEntity.renderLivingAt = boh.a
// MCP mapping: boh/a (Lsv;DDD)V net/minecraft/client/renderer/entity/RendererLivingEntity/func_77039_a (Lnet/minecraft/entity/EntityLivingBase;DDD)V
obf_deobf_pair method1_name = new obf_deobf_pair();
method1_name.setVal("doRender", false);
method1_name.setVal("a", true);
obf_deobf_pair method1_desc = new obf_deobf_pair();
method1_desc.setVal("(Lnet/minecraft/entity/EntityLivingBase;DDDFF)V", false);
method1_desc.setVal("(Lsv;DDDFF)V", true);
obf_deobf_pair method1_searchinstruction_function = new obf_deobf_pair();
method1_searchinstruction_function.setVal("renderLivingAt", false);
method1_searchinstruction_function.setVal("a", true);
obf_deobf_pair method1_searchinstruction_desc = new obf_deobf_pair();
method1_searchinstruction_desc.setVal("(Lnet/minecraft/entity/EntityLivingBase;DDD)V", false);
method1_searchinstruction_desc.setVal("(Lsv;DDD)V", true);
obf_deobf_pair method1_replaceinstruction_desc = new obf_deobf_pair();
method1_replaceinstruction_desc.setVal("(Lnet/minecraft/entity/EntityLivingBase;)V", false);
method1_replaceinstruction_desc.setVal("(Lsv;)V", true);
for (MethodNode mn : cn.methods){
if (mn.name.equals(method1_name.getVal(is_obfuscated)) && mn.desc.equals(method1_desc.getVal(is_obfuscated))){
AbstractInsnNode target = null;
LogHelper.debug("Core: Located target method " + mn.name + mn.desc);
Iterator<AbstractInsnNode> instructions = mn.instructions.iterator();
while (instructions.hasNext()){
AbstractInsnNode node = instructions.next();
if (node instanceof MethodInsnNode){
MethodInsnNode method = (MethodInsnNode)node;
if (method.name.equals(method1_searchinstruction_function.getVal(is_obfuscated)) && method.desc.equals(method1_searchinstruction_desc.getVal(is_obfuscated))){ //renderLivingAt(EntityLivingBase, double, double, double)
target = node;
break;
}
}
}
if (target != null){
VarInsnNode aLoad = new VarInsnNode(Opcodes.ALOAD, 1);
MethodInsnNode callout = new MethodInsnNode(Opcodes.INVOKESTATIC, "am2/utility/RenderUtilities", "setupShrinkRender", method1_replaceinstruction_desc.getVal(is_obfuscated));
mn.instructions.insert(target, aLoad);
mn.instructions.insert(aLoad, callout);
LogHelper.debug("Core: Success! Inserted opcodes!");
break;
}
}
}
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
return cw.toByteArray();
}
private byte[] alterEntityRenderer(byte[] bytes, boolean is_obfuscated){
ClassReader cr = new ClassReader(bytes);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
// Minecraft r1.7.10:
// net.minecraft.client.renderer.EntityRenderer.java = blt.class
// method 1:
// EntityRenderer.setupCameraTransform = blt.a
// MCP mapping: blt/a (FI)V net/minecraft/client/renderer/EntityRenderer/func_78479_a (FI)V
obf_deobf_pair method1_name = new obf_deobf_pair();
method1_name.setVal("setupCameraTransform", false);
method1_name.setVal("a", true);
String method1_desc = "(FI)V";
// search for this function call:
// EntityRenderer.orientCamera = blt.g
// MCP mapping: blt/g (F)V net/minecraft/client/renderer/EntityRenderer/func_78475_f (F)V
obf_deobf_pair method1_searchinstruction_function = new obf_deobf_pair();
method1_searchinstruction_function.setVal("orientCamera", false);
method1_searchinstruction_function.setVal("g", true);
String method1_searchinstruction_desc = "(F)V";
// we are also searching for gluPerspective, description (FFFF)V, but this is a GL function call and is not obfuscated.
// method 2:
// EntityRenderer.updateCameraAndRender = blt.b
// MCP mapping: MD: blt/b (F)V net/minecraft/client/renderer/EntityRenderer/func_78480_b (F)V
obf_deobf_pair method2_name = new obf_deobf_pair();
method2_name.setVal("updateCameraAndRender", false);
method2_name.setVal("b", true);
String method2_desc = "(F)V";
// search for this function call:
// net.minecraft.profiler.Profiler.startSection = qi.a
// MCP mapping: MD: qi/a (Ljava/lang/String;)V net/minecraft/profiler/Profiler/func_76320_a (Ljava/lang/String;)V
obf_deobf_pair method2_searchinstruction_class = new obf_deobf_pair();
method2_searchinstruction_class.setVal("net/minecraft/profiler/Profiler", false);
method2_searchinstruction_class.setVal("qi", true);
obf_deobf_pair method2_searchinstruction_function = new obf_deobf_pair();
method2_searchinstruction_function.setVal("startSection", false);
method2_searchinstruction_function.setVal("a", true);
String method2_searchinstruction_desc = "(Ljava/lang/String;)V";
// we will be inserting a call to am2.guis.AMGuiHelper.overrideMouseInput()
// description (Lnet/minecraft/client/renderer/EntityRenderer;FZ)Z
obf_deobf_pair method2_insertinstruction_desc = new obf_deobf_pair();
method2_insertinstruction_desc.setVal("(Lnet/minecraft/client/renderer/EntityRenderer;FZ)Z", false);
method2_insertinstruction_desc.setVal("(Lblt;FZ)Z", true);
for (MethodNode mn : cn.methods){
if (mn.name.equals(method1_name.getVal(is_obfuscated)) && mn.desc.equals(method1_desc)){ // setupCameraTransform
AbstractInsnNode orientCameraNode = null;
AbstractInsnNode gluPerspectiveNode = null;
LogHelper.debug("Core: Located target method " + mn.name + mn.desc);
Iterator<AbstractInsnNode> instructions = mn.instructions.iterator();
while (instructions.hasNext()){
AbstractInsnNode node = instructions.next();
if (node instanceof MethodInsnNode){
MethodInsnNode method = (MethodInsnNode)node;
if (orientCameraNode == null && method.name.equals(method1_searchinstruction_function.getVal(is_obfuscated)) && method.desc.equals(method1_searchinstruction_desc)){ //orientCamera
LogHelper.debug("Core: Located target method insn node: " + method.name + method.desc);
orientCameraNode = node;
continue;
}else if (gluPerspectiveNode == null && method.name.equals("gluPerspective") && method.desc.equals("(FFFF)V")){
LogHelper.debug("Core: Located target method insn node: " + method.name + method.desc);
gluPerspectiveNode = node;
continue;
}
}
if (orientCameraNode != null && gluPerspectiveNode != null){
//found all nodes we're looking for
break;
}
}
if (orientCameraNode != null){
VarInsnNode floatset = new VarInsnNode(Opcodes.FLOAD, 1);
MethodInsnNode callout = new MethodInsnNode(Opcodes.INVOKESTATIC, "am2/guis/AMGuiHelper", "shiftView", "(F)V");
mn.instructions.insert(orientCameraNode, callout);
mn.instructions.insert(orientCameraNode, floatset);
LogHelper.debug("Core: Success! Inserted callout function op (shift)!");
}
if (gluPerspectiveNode != null){
VarInsnNode floatset = new VarInsnNode(Opcodes.FLOAD, 1);
MethodInsnNode callout = new MethodInsnNode(Opcodes.INVOKESTATIC, "am2/guis/AMGuiHelper", "flipView", "(F)V");
mn.instructions.insert(gluPerspectiveNode, callout);
mn.instructions.insert(gluPerspectiveNode, floatset);
LogHelper.debug("Core: Success! Inserted callout function op (flip)!");
}
}else if (mn.name.equals(method2_name.getVal(is_obfuscated)) && mn.desc.equals(method2_desc)){ //updateCameraAndRender
AbstractInsnNode target = null;
LogHelper.debug("Core: Located target method " + mn.name + mn.desc);
Iterator<AbstractInsnNode> instructions = mn.instructions.iterator();
AbstractInsnNode node = null;
boolean mouseFound = false;
while (instructions.hasNext()){
node = instructions.next();
//look for the line:
//this.mc.mcProfiler.startSection("mouse");
if (!mouseFound){
if (node instanceof LdcInsnNode){
if (((LdcInsnNode)node).cst.equals("mouse")){
mouseFound = true;
}
}
}else{
if (node instanceof MethodInsnNode){
MethodInsnNode method = (MethodInsnNode)node;
if (method.owner.equals(method2_searchinstruction_class.getVal(is_obfuscated)) && method.name.equals(method2_searchinstruction_function.getVal(is_obfuscated)) && method.desc.equals(method2_searchinstruction_desc)){
LogHelper.debug("Core: Located target method insn node: " + method.owner + "." + method.name + ", " + method.desc);
target = node;
break;
}
}
}
}
if (target != null){
int iRegister = (MysteriumPatchesFixLoaderMagicka.isOptiFinePresent() || checkIsOptifineFilePresent()) ? 3 : 2;
VarInsnNode aLoad = new VarInsnNode(Opcodes.ALOAD, 0);
VarInsnNode fLoad = new VarInsnNode(Opcodes.FLOAD, 1);
VarInsnNode iLoad = new VarInsnNode(Opcodes.ILOAD, iRegister);
MethodInsnNode callout = new MethodInsnNode(Opcodes.INVOKESTATIC, "am2/guis/AMGuiHelper", "overrideMouseInput", method2_insertinstruction_desc.getVal(is_obfuscated));
VarInsnNode iStore = new VarInsnNode(Opcodes.ISTORE, iRegister);
mn.instructions.insert(target, iStore);
mn.instructions.insert(target, callout);
mn.instructions.insert(target, iLoad);
mn.instructions.insert(target, fLoad);
mn.instructions.insert(target, aLoad);
LogHelper.debug("Core: Success! Inserted opcodes!");
}
}
}
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
return cw.toByteArray();
}
private boolean checkIsOptifineFilePresent() {
File file = new File(".");
fetchFiles(file, f -> checkForOpt(f.getAbsolutePath()));
return isOptifineFilePresent;
}
private boolean checkIsThaumcraftFilePresent() {
File file = new File(".");
fetchFiles(file, f -> checkForOpt(f.getAbsolutePath()));
return isThaumcraftFilePresent;
}
private boolean checkIsDragonApiFilePresent() {
File file = new File(".");
fetchFiles(file, f -> checkForOpt(f.getAbsolutePath()));
return isDragonApiFilePresent;
}
private void checkForOpt(String path) {
if ((path.contains("optifine") && path.endsWith(".jar")) || (path.contains("OptiFine") && path.endsWith(".jar")) || (path.contains("Optifine") && path.endsWith(".jar"))) {
System.out.println("Optifine detected! Attempting compatibility. If you do not have optifine, this is an error; report it.");
isOptifineFilePresent = true;
}
if ((path.contains("DragonAPI") && path.endsWith(".jar")) || (path.contains("dragonapi") && path.endsWith(".jar")) || (path.contains("Dragonapi") && path.endsWith(".jar"))) {
System.out.println("DragonAPI detected! Attempting compatibility. If you do not have DragonAPI, this is an error; report it.");
isDragonApiFilePresent = true;
}
if ((path.contains("Thaumcraft") && path.endsWith(".jar")) || (path.contains("thaumcraft") && path.endsWith(".jar")) || (path.contains("ThaumCraft") && path.endsWith(".jar"))) {
System.out.println("Thaumcraft detected! Attempting compatibility. If you do not have Thaumcraft, this is an error; report it.");
isThaumcraftFilePresent = true;
}
}
public boolean isOptifineFilePresent = false;
public boolean isDragonApiFilePresent = false;
public boolean isThaumcraftFilePresent = false;
public static void fetchFiles(File dir, Consumer<File> fileConsumer) {
if (dir.isDirectory()) {
for (File file1 : dir.listFiles()) {
fetchFiles(file1, fileConsumer);
}
} else {
fileConsumer.accept(dir);
}
}
private byte[] alterEntityPlayerSP(byte[] bytes, boolean is_obfuscated){
ClassReader cr = new ClassReader(bytes);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
// Minecraft r1.7.10: net.minecraft.client.entity.EntityPlayerSP.java = blk.class
// EntityPlayerSP.onLivingUpdate() = blk/e
// MCP mapping: blk/e ()V net/minecraft/client/entity/EntityPlayerSP/func_70636_d ()V
obf_deobf_pair method1_name = new obf_deobf_pair();
method1_name.setVal("onLivingUpdate", false);
method1_name.setVal("e", true);
String method1_desc = "()V";
// MovementInput.updatePlayerMoveState() = bli/a
// note that we don't need the class name, it's referencing an internal variable
obf_deobf_pair method1_searchinstruction = new obf_deobf_pair();
method1_searchinstruction.setVal("updatePlayerMoveState", false);
method1_searchinstruction.setVal("a", true);
String searchinstruction_desc = "()V";
for (MethodNode mn : cn.methods){
if (mn.name.equals(method1_name.getVal(is_obfuscated)) && mn.desc.equals(method1_desc)){ //onLivingUpdate
AbstractInsnNode target = null;
LogHelper.debug("Core: Located target method " + mn.name + mn.desc);
Iterator<AbstractInsnNode> instructions = mn.instructions.iterator();
//look for the line:
//this.movementInput.updatePlayerMoveState();
while (instructions.hasNext()){
AbstractInsnNode node = instructions.next();
if (node instanceof VarInsnNode && ((VarInsnNode)node).getOpcode() == Opcodes.ALOAD){ //this.
node = instructions.next();
if (node instanceof FieldInsnNode && ((FieldInsnNode)node).getOpcode() == Opcodes.GETFIELD){ //movementInput.
node = instructions.next();
if (node instanceof MethodInsnNode){
MethodInsnNode method = (MethodInsnNode)node;
if (method.name.equals(method1_searchinstruction.getVal(is_obfuscated)) && method.desc.equals(searchinstruction_desc)){ //updatePlayerMoveState
LogHelper.debug("Core: Located target method insn node: " + method.name + method.desc);
target = node;
break;
}
}
}
}
}
if (target != null){
MethodInsnNode callout = new MethodInsnNode(Opcodes.INVOKESTATIC, "am2/guis/AMGuiHelper", "overrideKeyboardInput", "()V");
mn.instructions.insert(target, callout);
LogHelper.debug("Core: Success! Inserted operations!");
break;
}
}
}
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
return cw.toByteArray();
}
private byte[] alterWorld(byte[] bytes, boolean is_obfuscated){
ClassReader cr = new ClassReader(bytes);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
// Minecraft r1.7.10:
// net.minecraft.world.World.java = ahb.class
// World.playSoundAtEntity = ahb.a
// MCP mapping: ahb/a (Lsa;Ljava/lang/String;FF)V net/minecraft/world/World/func_72956_a (Lnet/minecraft/entity/Entity;Ljava/lang/String;FF)V
obf_deobf_pair method1_name = new obf_deobf_pair();
method1_name.setVal("playSoundAtEntity", false);
method1_name.setVal("a", true);
obf_deobf_pair method1_desc = new obf_deobf_pair();
method1_desc.setVal("(Lnet/minecraft/entity/Entity;Ljava/lang/String;FF)V", false);
method1_desc.setVal("(Lsa;Ljava/lang/String;FF)V", true);
obf_deobf_pair method1_replacement_desc = new obf_deobf_pair();
method1_replacement_desc.setVal("(Lnet/minecraft/entity/Entity;F)F", false);
method1_replacement_desc.setVal("(Lsa;F)F", true);
for (MethodNode mn : cn.methods){
if (mn.name.equals(method1_name.getVal(is_obfuscated)) && mn.desc.equals(method1_desc.getVal(is_obfuscated))){
AbstractInsnNode target = null;
LogHelper.debug("Core: Located target method " + mn.name + mn.desc);
Iterator<AbstractInsnNode> instructions = mn.instructions.iterator();
while (instructions.hasNext()){
AbstractInsnNode node = instructions.next();
if (node instanceof VarInsnNode &&
((VarInsnNode)node).getOpcode() == Opcodes.ALOAD &&
((VarInsnNode)node).var == 5){
AbstractInsnNode potentialMatch = node;
node = instructions.next();
if (node instanceof FieldInsnNode &&
((FieldInsnNode)node).getOpcode() == Opcodes.GETFIELD &&
((FieldInsnNode)node).name.equals("name") &&
((FieldInsnNode)node).desc.equals("Ljava/lang/String;") &&
((FieldInsnNode)node).owner.equals("net/minecraftforge/event/entity/PlaySoundAtEntityEvent")){
LogHelper.debug("Core: Located target method insn node: " + ((FieldInsnNode)node).name + ", " + ((FieldInsnNode)node).desc);
target = potentialMatch;
break;
}
}
}
if (target != null){
VarInsnNode aload1 = new VarInsnNode(Opcodes.ALOAD, 1);
VarInsnNode fload4 = new VarInsnNode(Opcodes.FLOAD, 4);
MethodInsnNode callout = new MethodInsnNode(Opcodes.INVOKESTATIC, "am2/utility/EntityUtilities", "modifySoundPitch", method1_replacement_desc.getVal(is_obfuscated));
VarInsnNode fstore4 = new VarInsnNode(Opcodes.FSTORE, 4);
mn.instructions.insertBefore(target, aload1);
mn.instructions.insertBefore(target, fload4);
mn.instructions.insertBefore(target, callout);
mn.instructions.insertBefore(target, fstore4);
LogHelper.debug("Core: Success! Inserted operations!");
break;
}
}
}
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
return cw.toByteArray();
}
// this function is no longer necessary in 1.7.10, since our event handler seems to handle dimension transfers properly
// (in fact, it never actually triggered in 1.7.10 - the variable and function names were never updated)
// the commented out code has been left here for future reference, in case the current event handler approach fails in the future
/*
private byte[] alterEntityPlayerMP(byte[] bytes){
ClassReader cr = new ClassReader(bytes);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
for (MethodNode mn : cn.methods){
LogHelper.debug("%s %s", mn.name, mn.desc);
if (mn.name.equals("b_") && mn.desc.equals("(Luf;)V")){ //travelToDimension
AbstractInsnNode target = null;
LogHelper.debug("Core: Located target method " + mn.name + mn.desc);
Iterator<AbstractInsnNode> instructions = mn.instructions.iterator();
//look for the line:
//this.worldObj.removeEntity(this)
while (instructions.hasNext()){
AbstractInsnNode node = instructions.next();
if (node instanceof MethodInsnNode){
MethodInsnNode method = (MethodInsnNode)node;
if (method.name.equals("e") && method.desc.equals("(Lnn;)V")){ //removeEntity
//instructions for the method go:
//ALOAD 0
//GETFIELD...
//ALOAD 0
//INVOKEVIRTUAL
target = method.getPrevious().getPrevious().getPrevious(); //back up to the first ALOAD
break;
}
}
}
if (target != null){
//GETSTATIC am2/AMCore.proxy : Lam2/proxy/CommonProxy;
FieldInsnNode proxyGet = new FieldInsnNode(Opcodes.GETSTATIC, "am2/AMCore", "proxy", "Lam2/proxy/CommonProxy");
//GETFIELD am2/proxy/CommonProxy.playerTracker : Lam2/PlayerTracker;
FieldInsnNode fieldGet = new FieldInsnNode(Opcodes.GETFIELD, "am2/proxy/CommonProxy", "playerTracker", "Lam2/PlayerTracker");
//ALOAD 0
VarInsnNode aLoad = new VarInsnNode(Opcodes.ALOAD, 0);
//INVOKEVIRTUAL am2/PlayerTracker.onPlayerDeath (Lnet/minecraft/entity/player/EntityPlayer;)V
MethodInsnNode callout = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "am2/PlayerTracker", "onPlayerDeath", "(Luf;)V");
mn.instructions.insertBefore(target, proxyGet);
mn.instructions.insertBefore(target, fieldGet);
mn.instructions.insertBefore(target, aLoad);
mn.instructions.insertBefore(target, callout);
LogHelper.debug("Core: Success! Inserted opcodes!");
}
}
}
return bytes;
}
*/
private byte[] alterNetHandlerPlayServer(byte[] bytes, boolean is_obfuscated){
ClassReader cr = new ClassReader(bytes);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
// Minecraft r1.6.4: NetServerHandler.java = ka.class
// Minecraft r1.7.10: net.minecraft.network.NetHandlerPlayServer.java = nh.class
// NetHandlerPlayServer.processPlayer(C03PacketPlayer), nh.a(jd)
// MCP mapping: nh/a (Ljd;)V net/minecraft/network/NetHandlerPlayServer/func_147347_a (Lnet/minecraft/network/play/client/C03PacketPlayer;)V
obf_deobf_pair method1_name = new obf_deobf_pair();
method1_name.setVal("processPlayer", false);
method1_name.setVal("a", true);
obf_deobf_pair method1_desc = new obf_deobf_pair();
method1_desc.setVal("(Lnet/minecraft/network/play/client/C03PacketPlayer;)V", false);
method1_desc.setVal("(Ljd;)V", true);
// in MC r1.6.4, this was a GETFIELD
// fetching Packet10Flying.stance and Packet10Flying.yPosition
// in MC r1.7.10, these are no longer public variables and we now have to call their access wrapper functions
// INVOKEVIRTUAL in both cases
// net/minecraft/network/play/client/C03PacketPlayer/func_149471_f = jd/f
// net/minecraft/network/play/client/C03PacketPlayer/func_149467_d = jd/d
// both have description ()D
obf_deobf_pair method1_searchinstruction_class = new obf_deobf_pair();
method1_searchinstruction_class.setVal("net/minecraft/network/play/client/C03PacketPlayer", false);
method1_searchinstruction_class.setVal("jd", true);
obf_deobf_pair method1_searchinstruction_function1 = new obf_deobf_pair();
method1_searchinstruction_function1.setVal("func_149471_f", false);
method1_searchinstruction_function1.setVal("f", true);
obf_deobf_pair method1_searchinstruction_function2 = new obf_deobf_pair();
method1_searchinstruction_function2.setVal("func_149467_d", false);
method1_searchinstruction_function2.setVal("d", true);
String method1_searchinstructions_desc = "()D";
for (MethodNode mn : cn.methods){
if (mn.name.equals(method1_name.getVal(is_obfuscated)) && mn.desc.equals(method1_desc.getVal(is_obfuscated))){ //processPlayer
AbstractInsnNode target = null;
LogHelper.debug("Core: Located target method " + mn.name + mn.desc);
Iterator<AbstractInsnNode> instructions = mn.instructions.iterator();
//look for the line:
// d4 = p_147347_1_.func_149471_f() - p_147347_1_.func_149467_d();
// p_147347_1_ = C03PacketPlayer
//in MC r1.6.4, d4 = par1Packet10Flying.stance - par1Packet10Flying.yPosition;
while (instructions.hasNext()){
AbstractInsnNode node = instructions.next();
if (node instanceof VarInsnNode && ((VarInsnNode)node).var == 1 && ((VarInsnNode)node).getOpcode() == Opcodes.ALOAD){ //ALOAD 1
node = instructions.next();
if (node instanceof MethodInsnNode && matchMethodNode((MethodInsnNode)node, Opcodes.INVOKEVIRTUAL, method1_searchinstruction_class.getVal(is_obfuscated), method1_searchinstruction_function1.getVal(is_obfuscated), method1_searchinstructions_desc)){
node = instructions.next();
if (node instanceof VarInsnNode && ((VarInsnNode)node).var == 1 && ((VarInsnNode)node).getOpcode() == Opcodes.ALOAD){ //ALOAD 1
node = instructions.next();
if (node instanceof MethodInsnNode && matchMethodNode((MethodInsnNode)node, Opcodes.INVOKEVIRTUAL, method1_searchinstruction_class.getVal(is_obfuscated), method1_searchinstruction_function2.getVal(is_obfuscated), method1_searchinstructions_desc)){
node = instructions.next();
if (node instanceof InsnNode && ((InsnNode)node).getOpcode() == Opcodes.DSUB){ //DSUB
node = instructions.next();
if (node instanceof VarInsnNode && ((VarInsnNode)node).var == 13 && ((VarInsnNode)node).getOpcode() == Opcodes.DSTORE){ //DSTORE 13
target = node;
break;
}
}
}
}
}
}
}
if (target != null){
LdcInsnNode ldc = new LdcInsnNode(1.5);
VarInsnNode dstore13 = new VarInsnNode(Opcodes.DSTORE, 13);
mn.instructions.insert(target, ldc);
mn.instructions.insert(ldc, dstore13);
LogHelper.debug("Core: Success! Inserted opcodes!");
}
}
}
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
return cw.toByteArray();
}
private byte[] alterPotionEffect(byte[] bytes, boolean is_obfuscated){
ClassReader cr = new ClassReader(bytes);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
// Minecraft r1.7.10:
// PotionEffect.java --> rw.class
// PotionEffect.writeCustomPotionEffectToNBT = rw.a
// MCP mapping: rw/a (Ldh;)Ldh; net/minecraft/potion/PotionEffect/func_82719_a (Lnet/minecraft/nbt/NBTTagCompound;)Lnet/minecraft/nbt/NBTTagCompound
// PotionEffect.readCustomPotionEffectFromNBT = rw.b
// MCP mapping: rw/b (Ldh;)Lrw; net/minecraft/potion/PotionEffect/func_82722_b (Lnet/minecraft/nbt/NBTTagCompound;)Lnet/minecraft/potion/PotionEffect;
// PotionEffect.getPotionID = rw.a
// MCP mapping: rw/a ()I net/minecraft/potion/PotionEffect/func_76456_a ()I
// note: called as this.getPotionID(), original has a typecast to byte before calling it
// NBTTagCompound.java --> dh.class
// NBTTagCompound.setByte(string, value) = dh.a
// MCP mapping: dh/a (Ljava/lang/String;B)V net/minecraft/nbt/NBTTagCompound/func_74774_a (Ljava/lang/String;B)V
// NBTTagCompound.setInteger(string, value) = dh.a
// MCP mapping: dh/a (Ljava/lang/String;I)V net/minecraft/nbt/NBTTagCompound/func_74768_a (Ljava/lang/String;I)V
// NBTTagCompound.getByte(string) = dh.d
// MCP mapping: dh/d (Ljava/lang/String;)B net/minecraft/nbt/NBTTagCompound/func_74771_c (Ljava/lang/String;)B
// NBTTagCompound.getInteger(string) = dh.f
// MCP mapping: dh/f (Ljava/lang/String;)I net/minecraft/nbt/NBTTagCompound/func_74762_e (Ljava/lang/String;)I
obf_deobf_pair method1_name = new obf_deobf_pair();
method1_name.setVal("writeCustomPotionEffectToNBT", false);
method1_name.setVal("a", true);
obf_deobf_pair method1_desc = new obf_deobf_pair();
method1_desc.setVal("(Lnet/minecraft/nbt/NBTTagCompound;)Lnet/minecraft/nbt/NBTTagCompound;", false);
method1_desc.setVal("(Ldh;)Ldh;", true);
// don't forget, you need to remove the i2b instruction which immediately precedes this one
obf_deobf_pair method1_searchinstruction_class = new obf_deobf_pair();
method1_searchinstruction_class.setVal("net/minecraft/nbt/NBTTagCompound", false);
method1_searchinstruction_class.setVal("dh", true);
obf_deobf_pair method1_searchinstruction_function = new obf_deobf_pair();
method1_searchinstruction_function.setVal("setByte", false);
method1_searchinstruction_function.setVal("a", true);
obf_deobf_pair method1_searchinstruction_desc = new obf_deobf_pair();
method1_searchinstruction_desc.setVal("(Ljava/lang/String;B)V", false);
method1_searchinstruction_desc.setVal("(Ljava/lang/String;B)V", true);
// replace instruction class is the same as the search instruction class for method1
obf_deobf_pair method1_replaceinstruction_function = new obf_deobf_pair();
method1_replaceinstruction_function.setVal("setInteger", false);
method1_replaceinstruction_function.setVal("a", true);
obf_deobf_pair method1_replaceinstruction_desc = new obf_deobf_pair();
method1_replaceinstruction_desc.setVal("(Ljava/lang/String;I)V", false);
method1_replaceinstruction_desc.setVal("(Ljava/lang/String;I)V", true);
obf_deobf_pair method2_name = new obf_deobf_pair();
method2_name.setVal("readCustomPotionEffectFromNBT", false);
method2_name.setVal("b", true);
obf_deobf_pair method2_desc = new obf_deobf_pair();
method2_desc.setVal("(Lnet/minecraft/nbt/NBTTagCompound;)Lnet/minecraft/potion/PotionEffect;", false);
method2_desc.setVal("(Ldh;)Lrw;", true);
obf_deobf_pair method2_searchinstruction_class = new obf_deobf_pair();
method2_searchinstruction_class.setVal("net/minecraft/nbt/NBTTagCompound", false);
method2_searchinstruction_class.setVal("dh", true);
obf_deobf_pair method2_searchinstruction_function = new obf_deobf_pair();
method2_searchinstruction_function.setVal("getByte", false);
method2_searchinstruction_function.setVal("d", true);
obf_deobf_pair method2_searchinstruction_desc = new obf_deobf_pair();
method2_searchinstruction_desc.setVal("(Ljava/lang/String;)B", false);
method2_searchinstruction_desc.setVal("(Ljava/lang/String;)B", true);
// replace instruction class is the same as the search instruction class for method2 as well
obf_deobf_pair method2_replaceinstruction_function = new obf_deobf_pair();
method2_replaceinstruction_function.setVal("getInteger", false);
method2_replaceinstruction_function.setVal("f", true);
obf_deobf_pair method2_replaceinstruction_desc = new obf_deobf_pair();
method2_replaceinstruction_desc.setVal("(Ljava/lang/String;)I", false);
method2_replaceinstruction_desc.setVal("(Ljava/lang/String;)I", true);
// LogHelper.debug("Core: looking for method " + method1_name.getVal(is_obfuscated) + " with signature " + method1_desc.getVal(is_obfuscated));
// LogHelper.debug("Core: looking for method " + method2_name.getVal(is_obfuscated) + " with signature " + method2_desc.getVal(is_obfuscated));
for (MethodNode mn : cn.methods){
// LogHelper.debug("Currently on: method " + mn.name + ", description " + mn.desc);
if (mn.name.equals(method1_name.getVal(is_obfuscated)) && mn.desc.equals(method1_desc.getVal(is_obfuscated))){
// writeCustomPotionEffectToNBT
AbstractInsnNode target = null;
AbstractInsnNode toRemove = null;
LogHelper.debug("Core: Located target method " + mn.name + mn.desc);
Iterator<AbstractInsnNode> instructions = mn.instructions.iterator();
while (instructions.hasNext()){
AbstractInsnNode node = instructions.next();
if (node instanceof MethodInsnNode){
MethodInsnNode method = (MethodInsnNode)node;
if (method.owner.equals(method1_searchinstruction_class.getVal(is_obfuscated)) && method.name.equals(method1_searchinstruction_function.getVal(is_obfuscated)) && method.desc.equals(method1_searchinstruction_desc.getVal(is_obfuscated))){ //setByte(string, byte)
target = method;
// don't forget, you need to remove the i2b instruction which immediately precedes this one
toRemove = method.getPrevious();
break;
}
}
}
if (target != null){
MethodInsnNode newset = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, method1_searchinstruction_class.getVal(is_obfuscated), method1_replaceinstruction_function.getVal(is_obfuscated), method1_replaceinstruction_desc.getVal(is_obfuscated));
InsnNode new_nop = new InsnNode(Opcodes.NOP);
// removing instructions makes the game crash, we'll just replace it with NOP
mn.instructions.set(toRemove, new_nop);
mn.instructions.set(target, newset);
LogHelper.debug("Core: Success! Replaced opcodes!");
}
} else if (mn.name.equals(method2_name.getVal(is_obfuscated)) && mn.desc.equals(method2_desc.getVal(is_obfuscated))){
// readCustomPotionEffectFromNBT
AbstractInsnNode target = null;
LogHelper.debug("Core: Located target method " + mn.name + mn.desc);
Iterator<AbstractInsnNode> instructions = mn.instructions.iterator();
while (instructions.hasNext()){
AbstractInsnNode node = instructions.next();
if (node instanceof MethodInsnNode){
MethodInsnNode method = (MethodInsnNode)node;
if (method.owner.equals(method2_searchinstruction_class.getVal(is_obfuscated)) && method.name.equals(method2_searchinstruction_function.getVal(is_obfuscated)) && method.desc.equals(method2_searchinstruction_desc.getVal(is_obfuscated))){ //getByte(string, byte)
target = method;
break;
}
}
}
if (target != null){
MethodInsnNode newset = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, method2_searchinstruction_class.getVal(is_obfuscated), method2_replaceinstruction_function.getVal(is_obfuscated), method2_replaceinstruction_desc.getVal(is_obfuscated));
mn.instructions.set(target, newset);
LogHelper.debug("Core: Success! Replaced opcodes!");
}
}
}
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
return cw.toByteArray();
}
private byte[] alterS1DPacketEntityEffect(byte[] bytes, boolean is_obfuscated, String classname){
ClassReader cr = new ClassReader(bytes);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
//debug
if (!is_obfuscated){
try{
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
File outDir = new File("asm/am2");
outDir.mkdirs();
DataOutputStream dout = new DataOutputStream(new FileOutputStream(new File(outDir, "SD1PacketEntityEffect_pre.class")));
dout.write(cw.toByteArray());
dout.flush();
dout.close();
}catch (Exception e){
e.printStackTrace();
}
}
// Minecraft r1.7.10:
// S1DPacketEntityEffect.java --> in.class
// S1DPacketEntityEffect.field_149432_b = in.b
// S1DPacketEntityEffect.<init> = in.<init>
// Method name and description: S1DPacketEntityEffect/<init> (ILnet/minecraft/potion/PotionEffect;)V;
// Obfuscated: in/<init>, (ILrw;)V;
// changes in init: look for invokevirtual rw/a, signature ()I
// check to see if the 3 following instructions are SIPUSH, IAND, I2B
// if so, replace all with NOP
// the fourth instruction, PUTFIELD, might possibly need its signature changed
// but I'm going to see exactly what the ASM documentation means when it says
// "hopefully ASM hides all the details related to the constant pool"
// well, the documentation is talking bollocks
// we need to change the constant pool manually... which is not an easy thing to accomplish
// S1DPacketEntityEffect.readPacketData(PacketBuffer) = in.a(et)
// MCP mapping: in/a (Let;)V net/minecraft/network/play/server/S1DPacketEntityEffect/func_148837_a (Lnet/minecraft/network/PacketBuffer;)V
// --conveniently, PacketBuffer extends an external library, so the important bits can't be obfuscated
// PacketBuffer.readByte() = et.readByte()
// MCP mapping: et/readByte ()B net/minecraft/network/PacketBuffer/readByte ()B
// PacketBuffer.readInt() = et.readInt()
// MCP mapping: et/readInt ()I net/minecraft/network/PacketBuffer/readInt ()I
// S1DPacketEntityEffect.writePacketData(PacketBuffer) = in.b(et)
// MCP mapping: in/b (Let;)V net/minecraft/network/play/server/S1DPacketEntityEffect/func_148840_b (Lnet/minecraft/network/PacketBuffer;)V
// PacketBuffer/writeByte() = et.writeByte()
// MCP mapping: MD: et/writeByte (I)Lio/netty/buffer/ByteBuf; net/minecraft/network/PacketBuffer/writeByte (I)Lio/netty/buffer/ByteBuf;
// PacketBuffer.writeInt() = et.writeInt()
// MCP mapping: MD: et/writeInt (I)Lio/netty/buffer/ByteBuf; net/minecraft/network/PacketBuffer/writeInt (I)Lio/netty/buffer/ByteBuf;
// S1DPacketEntityEffect.func_149427_e() = in.e()
// MCP mapping: in/e ()B net/minecraft/network/play/server/S1DPacketEntityEffect/func_149427_e ()B
// need to change signature to ()I, don't change the method at all
obf_deobf_pair potionid_bytevar_name = new obf_deobf_pair();
potionid_bytevar_name.setVal("field_149432_b", false);
potionid_bytevar_name.setVal("b", true);
String potionid_bytevar_origdesc = "B";
// we'll have to make a new field for this
// existing one had description B (change this to I), access 2, signature null, value null
String initmethod_name = "<init>";
obf_deobf_pair initmethod_desc = new obf_deobf_pair();
initmethod_desc.setVal("(ILnet/minecraft/potion/PotionEffect;)V", false);
initmethod_desc.setVal("(ILrw;)V", true);
obf_deobf_pair initmethod_searchinstruction_owner = new obf_deobf_pair();
initmethod_searchinstruction_owner.setVal("net/minecraft/potion/PotionEffect", false);
initmethod_searchinstruction_owner.setVal("rw", true);
obf_deobf_pair initmethod_searchinstruction_function = new obf_deobf_pair();
initmethod_searchinstruction_function.setVal("getPotionID", false);
initmethod_searchinstruction_function.setVal("a", true);
String initmethod_searchinstruction_desc = "()I";
obf_deobf_pair method1_name = new obf_deobf_pair();
method1_name.setVal("readPacketData", false);
method1_name.setVal("a", true);
obf_deobf_pair method1_desc = new obf_deobf_pair();
method1_desc.setVal("(Lnet/minecraft/network/PacketBuffer;)V", false);
method1_desc.setVal("(Let;)V", true);
obf_deobf_pair method1_searchinstruction_owner = new obf_deobf_pair();
method1_searchinstruction_owner.setVal("net/minecraft/network/PacketBuffer", false);
method1_searchinstruction_owner.setVal("et", true);
String method1_searchinstruction_function = "readByte";
String method1_searchinstruction_desc = "()B";
// method used to check if receiving a vanilla or AM2 packet
String method1_checkinstruction_function = "readableBytes";
String method1_checkinstruction_desc = "()I";
// replacement class is the same
String method1_replaceinstruction_function = "readInt";
String method1_replaceinstruction_desc = "()I";
obf_deobf_pair method2_name = new obf_deobf_pair();
method2_name.setVal("writePacketData", false);
method2_name.setVal("b", true);
obf_deobf_pair method2_desc = new obf_deobf_pair();
method2_desc.setVal("(Lnet/minecraft/network/PacketBuffer;)V", false);
method2_desc.setVal("(Let;)V", true);
obf_deobf_pair method2_searchinstruction_owner = new obf_deobf_pair();
method2_searchinstruction_owner.setVal("net/minecraft/network/PacketBuffer", false);
method2_searchinstruction_owner.setVal("et", true);
String method2_searchinstruction_function = "writeByte";
String method2_searchinstruction_desc = "(I)Lio/netty/buffer/ByteBuf;";
// String method2_checkinstruction_function = "writableBytes";
// String method2_checkinstruction_desc = "()I";
// replacement class is the same
// so is the instruction, but we'll leave it as being explicitly defined just in case
String method2_replaceinstruction_function = "writeInt";
String method2_replaceinstruction_desc = "(I)Lio/netty/buffer/ByteBuf;";
// need to replace only this method descriptor
obf_deobf_pair method3_name = new obf_deobf_pair();
method3_name.setVal("func_149427_e", false);
method3_name.setVal("e", true);
// String method3_desc = "()B";
String method3_newdesc = "()I";
String potionID_intvar_name = "potionID_intvalue";
String potionID_intvar_desc = "I";
int potionID_intvar_access = 2;
FieldNode potionID_intvar = new FieldNode(potionID_intvar_access, potionID_intvar_name, potionID_intvar_desc, null, null);
cn.fields.add(potionID_intvar);
for (MethodNode mn : cn.methods){
// LogHelper.debug("Currently on: method " + mn.name + ", description " + mn.desc);
if (mn.name.equals(initmethod_name) && mn.desc.equals(initmethod_desc.getVal(is_obfuscated))){
// init method
AbstractInsnNode toRemove1 = null;
AbstractInsnNode toRemove2 = null;
AbstractInsnNode toRemove3 = null;
AbstractInsnNode toReplace = null;
LogHelper.debug("Core: Located target method " + mn.name + mn.desc);
Iterator<AbstractInsnNode> instructions = mn.instructions.iterator();
while (instructions.hasNext()){
AbstractInsnNode node = instructions.next();