@@ -215,6 +215,11 @@ public byte[] transform(final String name, final String transformedName, final b
215
215
methodNode .instructions .remove (toPatch );
216
216
}
217
217
218
+ int index1 = -1 ;
219
+ int index2 = -1 ;
220
+ int index3 = -1 ;
221
+ int index4 = -1 ;
222
+
218
223
for (final MethodInsnNode toPatch : foundFogFloatBufCalls ) {
219
224
System .out .println ("Patching call to " + toPatch .owner + "." + toPatch .name + toPatch .desc + " at class " + name );
220
225
// RGBA to BRGA
@@ -234,20 +239,28 @@ public byte[] transform(final String name, final String transformedName, final b
234
239
final InsnNode dup_3 = new InsnNode (Opcodes .DUP );
235
240
final MethodInsnNode get_4 = new MethodInsnNode (Opcodes .INVOKEVIRTUAL , "java/nio/FloatBuffer" , "get" , "()F" );
236
241
final InsnNode swap_4 = new InsnNode (Opcodes .SWAP );
242
+
243
+ if (index1 == -1 ) {
244
+ index1 = methodNode .maxLocals ;
245
+ methodNode .maxLocals ++;
246
+ }
247
+
237
248
// Store reference to buffer
238
- final int indexR = methodNode .maxLocals ;
239
- methodNode .maxLocals ++;
240
- final VarInsnNode storeBuffer = new VarInsnNode (Opcodes .ASTORE , indexR );
249
+ final VarInsnNode storeBuffer = new VarInsnNode (Opcodes .ASTORE , index1 );
241
250
// RGBA -> ARGB because values get consumed in reverse order when putting float values in buffer
242
251
final InsnNode swap = new InsnNode (Opcodes .SWAP );
243
- final int indexB = methodNode .maxLocals ;
244
- methodNode .maxLocals ++;
245
- final VarInsnNode storeBlue = new VarInsnNode (Opcodes .FSTORE , indexB );
252
+
253
+ if (index2 == -1 ) {
254
+ index2 = methodNode .maxLocals ;
255
+ methodNode .maxLocals ++;
256
+ }
257
+
258
+ final VarInsnNode storeBlue = new VarInsnNode (Opcodes .FSTORE , index2 );
246
259
final InsnNode dup_x2 = new InsnNode (Opcodes .DUP_X2 );
247
260
final InsnNode pop = new InsnNode (Opcodes .POP );
248
- final VarInsnNode loadBlue = new VarInsnNode (Opcodes .FLOAD , indexB );
261
+ final VarInsnNode loadBlue = new VarInsnNode (Opcodes .FLOAD , index2 );
249
262
// Load reference to buffer
250
- final VarInsnNode loadBuffer = new VarInsnNode (Opcodes .ALOAD , indexR );
263
+ final VarInsnNode loadBuffer = new VarInsnNode (Opcodes .ALOAD , index1 );
251
264
final InsnNode dup = new InsnNode (Opcodes .DUP );
252
265
// Clear buffer
253
266
final MethodInsnNode clear = new MethodInsnNode (Opcodes .INVOKEVIRTUAL , "java/nio/FloatBuffer" , "clear" , "()Ljava/nio/Buffer;" );
@@ -264,7 +277,7 @@ public byte[] transform(final String name, final String transformedName, final b
264
277
// Flip buffer
265
278
final MethodInsnNode flip = new MethodInsnNode (Opcodes .INVOKEVIRTUAL , "java/nio/FloatBuffer" , "flip" , "()Ljava/nio/Buffer;" );
266
279
final InsnNode pop_return_2 = new InsnNode (Opcodes .POP );
267
- final VarInsnNode loadBuffer2 = new VarInsnNode (Opcodes .ALOAD , indexR );
280
+ final VarInsnNode loadBuffer2 = new VarInsnNode (Opcodes .ALOAD , index1 );
268
281
269
282
if (RetroTweaker .m1PatchMode != M1PatchMode .ForceEnable ) {
270
283
methodNode .instructions .insertBefore (toPatch , getFullscreen );
@@ -343,7 +356,17 @@ public byte[] transform(final String name, final String transformedName, final b
343
356
if (reorderLoadIns != null ) {
344
357
reorder3LoadIns (methodNode , reorderLoadIns , toPatch , _p1 , _p2 , _p3 );
345
358
} else {
346
- swap3Type2 (methodNode , toPatch );
359
+ if (index1 == -1 ) {
360
+ index1 = methodNode .maxLocals ;
361
+ methodNode .maxLocals ++;
362
+ }
363
+
364
+ if (index2 == -1 ) {
365
+ index2 = methodNode .maxLocals ;
366
+ methodNode .maxLocals ++;
367
+ }
368
+
369
+ swap3Type2 (methodNode , toPatch , index1 );
347
370
}
348
371
}
349
372
}
@@ -366,8 +389,13 @@ public byte[] transform(final String name, final String transformedName, final b
366
389
} else if (isP1Load ) {
367
390
swap3Type1 (methodNode , _p1 );
368
391
} else {
392
+ if (index1 == -1 ) {
393
+ index1 = methodNode .maxLocals ;
394
+ methodNode .maxLocals ++;
395
+ }
396
+
369
397
final Type storeType = Type .getArgumentTypes (toPatch .desc )[0 ];
370
- swap4Type1 (methodNode , toPatch , storeType );
398
+ swap4Type1 (methodNode , toPatch , storeType , index1 );
371
399
}
372
400
}
373
401
}
@@ -390,9 +418,39 @@ public byte[] transform(final String name, final String transformedName, final b
390
418
if (isP1Load && (reorderLoadIns != null )) {
391
419
reorder3LoadIns (methodNode , reorderLoadIns , _p1 , _p2 , _p3 , _p4 );
392
420
} else if (isP1Load ) {
393
- swap3Type2 (methodNode , _p1 );
421
+ if (index1 == -1 ) {
422
+ index1 = methodNode .maxLocals ;
423
+ methodNode .maxLocals ++;
424
+ }
425
+
426
+ if (index2 == -1 ) {
427
+ index2 = methodNode .maxLocals ;
428
+ methodNode .maxLocals ++;
429
+ }
430
+
431
+ swap3Type2 (methodNode , _p1 , index1 );
394
432
} else {
395
- swap4Type2 (methodNode , toPatch );
433
+ if (index1 == -1 ) {
434
+ index1 = methodNode .maxLocals ;
435
+ methodNode .maxLocals ++;
436
+ }
437
+
438
+ if (index2 == -1 ) {
439
+ index2 = methodNode .maxLocals ;
440
+ methodNode .maxLocals ++;
441
+ }
442
+
443
+ if (index3 == -1 ) {
444
+ index3 = methodNode .maxLocals ;
445
+ methodNode .maxLocals ++;
446
+ }
447
+
448
+ if (index4 == -1 ) {
449
+ index4 = methodNode .maxLocals ;
450
+ methodNode .maxLocals ++;
451
+ }
452
+
453
+ swap4Type2 (methodNode , toPatch , index1 , index3 );
396
454
}
397
455
}
398
456
}
@@ -484,12 +542,10 @@ private static void swap3Type1(MethodNode methodNode, AbstractInsnNode toPatch)
484
542
}
485
543
}
486
544
487
- private static void swap3Type2 (MethodNode methodNode , AbstractInsnNode toPatch ) {
545
+ private static void swap3Type2 (MethodNode methodNode , AbstractInsnNode toPatch , int index ) {
488
546
final LabelNode target = new LabelNode ();
489
547
final FieldInsnNode getFullscreen = new FieldInsnNode (Opcodes .GETSTATIC , "com/zero/retrowrapper/injector/M1ColorTweakInjector" , "isMinecraftFullscreen" , "Z" );
490
548
final JumpInsnNode skipIfFullscreen = new JumpInsnNode (Opcodes .IFNE , target );
491
- final int index = methodNode .maxLocals ;
492
- methodNode .maxLocals += 2 ;
493
549
// RGB
494
550
final InsnNode dup2_x2 = new InsnNode (Opcodes .DUP2_X2 );
495
551
// RBGB
@@ -527,9 +583,7 @@ private static void swap3Type2(MethodNode methodNode, AbstractInsnNode toPatch)
527
583
}
528
584
}
529
585
530
- private static void swap4Type1 (MethodNode methodNode , AbstractInsnNode toPatch , Type storeType ) {
531
- final int index = methodNode .maxLocals ;
532
- methodNode .maxLocals ++;
586
+ private static void swap4Type1 (MethodNode methodNode , AbstractInsnNode toPatch , Type storeType , int index ) {
533
587
final LabelNode target = new LabelNode ();
534
588
final FieldInsnNode getFullscreen = new FieldInsnNode (Opcodes .GETSTATIC , "com/zero/retrowrapper/injector/M1ColorTweakInjector" , "isMinecraftFullscreen" , "Z" );
535
589
final JumpInsnNode skipIfFullscreen = new JumpInsnNode (Opcodes .IFNE , target );
@@ -555,11 +609,7 @@ private static void swap4Type1(MethodNode methodNode, AbstractInsnNode toPatch,
555
609
}
556
610
}
557
611
558
- private static void swap4Type2 (MethodNode methodNode , AbstractInsnNode toPatch ) {
559
- final int index = methodNode .maxLocals ;
560
- methodNode .maxLocals += 2 ;
561
- final int index2 = methodNode .maxLocals ;
562
- methodNode .maxLocals += 2 ;
612
+ private static void swap4Type2 (MethodNode methodNode , AbstractInsnNode toPatch , int index , int index2 ) {
563
613
final LabelNode target = new LabelNode ();
564
614
final FieldInsnNode getFullscreen = new FieldInsnNode (Opcodes .GETSTATIC , "com/zero/retrowrapper/injector/M1ColorTweakInjector" , "isMinecraftFullscreen" , "Z" );
565
615
final JumpInsnNode skipIfFullscreen = new JumpInsnNode (Opcodes .IFNE , target );
0 commit comments