make injected client java8-compliant, dumb mixin
This commit is contained in:
@@ -23,6 +23,7 @@ import com.openosrs.injector.injectors.raw.RenderDraw;
|
||||
import com.openosrs.injector.injectors.raw.ScriptVM;
|
||||
import com.openosrs.injector.rsapi.RSApi;
|
||||
import com.openosrs.injector.transformers.InjectTransformer;
|
||||
import com.openosrs.injector.transformers.Java8Ifier;
|
||||
import com.openosrs.injector.transformers.SourceChanger;
|
||||
import static net.runelite.deob.util.JarUtil.load;
|
||||
import static net.runelite.deob.util.JarUtil.save;
|
||||
@@ -57,6 +58,8 @@ public class Injector extends InjectData implements InjectTaskHandler
|
||||
{
|
||||
log.debug("[DEBUG] Starting injection");
|
||||
|
||||
transform(new Java8Ifier(this));
|
||||
|
||||
inject(new CreateAnnotations(this));
|
||||
|
||||
inject(new InterfaceInjector(this));
|
||||
|
||||
@@ -43,6 +43,7 @@ import net.runelite.asm.attributes.code.Instructions;
|
||||
import net.runelite.asm.attributes.code.instructions.ALoad;
|
||||
import net.runelite.asm.attributes.code.instructions.BiPush;
|
||||
import net.runelite.asm.attributes.code.instructions.CheckCast;
|
||||
import net.runelite.asm.attributes.code.instructions.InvokeInterface;
|
||||
import net.runelite.asm.attributes.code.instructions.InvokeStatic;
|
||||
import net.runelite.asm.attributes.code.instructions.InvokeVirtual;
|
||||
import net.runelite.asm.attributes.code.instructions.LDC;
|
||||
@@ -131,6 +132,10 @@ public class InjectInvoke
|
||||
{
|
||||
ins.add(new InvokeStatic(instructions, vanillaMethod.getPoolMethod()));
|
||||
}
|
||||
else if (vanillaMethod.getClassFile().isInterface())
|
||||
{
|
||||
ins.add(new InvokeInterface(instructions, vanillaMethod.getPoolMethod()));
|
||||
}
|
||||
else
|
||||
{
|
||||
ins.add(new InvokeVirtual(instructions, vanillaMethod.getPoolMethod()));
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2020, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is licensed under GPL3, see the complete license in
|
||||
* the LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
package com.openosrs.injector.transformers;
|
||||
|
||||
import com.openosrs.injector.InjectException;
|
||||
import com.openosrs.injector.injection.InjectData;
|
||||
import java.util.ListIterator;
|
||||
import net.runelite.asm.ClassFile;
|
||||
import net.runelite.asm.Method;
|
||||
import net.runelite.asm.attributes.Code;
|
||||
import net.runelite.asm.attributes.code.Exception;
|
||||
import net.runelite.asm.attributes.code.Instruction;
|
||||
import net.runelite.asm.attributes.code.Instructions;
|
||||
import net.runelite.asm.attributes.code.Label;
|
||||
import net.runelite.asm.attributes.code.instructions.InvokeSpecial;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
public class Java8Ifier extends InjectTransformer
|
||||
{
|
||||
public Java8Ifier(InjectData inject)
|
||||
{
|
||||
super(inject);
|
||||
}
|
||||
|
||||
@Override
|
||||
void transformImpl()
|
||||
{
|
||||
inject.forEachPair(this::makeJava8);
|
||||
}
|
||||
|
||||
private void makeJava8(ClassFile rsc, ClassFile vanilla)
|
||||
{
|
||||
vanilla.setVersion(Opcodes.V1_8);
|
||||
for (Method method : vanilla.getMethods())
|
||||
{
|
||||
if (!method.getName().equals("<init>"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fixTryCatch(method);
|
||||
}
|
||||
}
|
||||
|
||||
private void fixTryCatch(Method method)
|
||||
{
|
||||
Code code = method.getCode();
|
||||
|
||||
if (code.getExceptions().getExceptions().stream().noneMatch(e -> e.getCatchType() != null && e.getCatchType().getName().equals("java/lang/RuntimeException")))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Instructions instructions = code.getInstructions();
|
||||
ListIterator<Instruction> insnIt = instructions.listIterator();
|
||||
Instruction insn;
|
||||
Label firstLabel = null;
|
||||
Label injectedLabel = null;
|
||||
while (insnIt.hasNext())
|
||||
{
|
||||
insn = insnIt.next();
|
||||
|
||||
if (firstLabel == null && insn instanceof Label)
|
||||
{
|
||||
firstLabel = (Label) insn;
|
||||
}
|
||||
else if (insn instanceof InvokeSpecial)
|
||||
{
|
||||
if (((InvokeSpecial) insn).getMethod().getName().equals("<init>"))
|
||||
{
|
||||
injectedLabel = new Label(instructions);
|
||||
insnIt.add(injectedLabel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this should never happen
|
||||
if (firstLabel == null)
|
||||
{
|
||||
throw new InjectException("Label missing from ctor " + method.toString() + " even though exception exists");
|
||||
}
|
||||
|
||||
// label was injected
|
||||
if (injectedLabel != null)
|
||||
{
|
||||
for (Exception ex : code.getExceptions().getExceptions())
|
||||
{
|
||||
if (ex.getStart().equals(firstLabel))
|
||||
{
|
||||
ex.setStart(injectedLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user