diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/AALoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/AALoad.java index 3c860ff89c..7b4b293532 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/AALoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/AALoad.java @@ -27,7 +27,7 @@ public class AALoad extends Instruction implements ArrayLoad ins.pop(index, array); - StackContext ctx = new StackContext(ins, array.getType().getSubtype()); + StackContext ctx = new StackContext(ins, array.getType().getSubtype(), array.getValue().arrayGet(index.getValue())); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/AAStore.java b/src/main/java/net/runelite/deob/attributes/code/instructions/AAStore.java index 2f88e5f591..1f2775c1f4 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/AAStore.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/AAStore.java @@ -28,6 +28,8 @@ public class AAStore extends Instruction implements ArrayStore ins.pop(value, index, array); + array.getValue().arraySet(index.getValue(), value.getValue()); + frame.addInstructionContext(ins); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/AConstNull.java b/src/main/java/net/runelite/deob/attributes/code/instructions/AConstNull.java index 50a1b16165..d36fe138f4 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/AConstNull.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/AConstNull.java @@ -9,6 +9,7 @@ import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; import java.io.IOException; +import net.runelite.deob.execution.Value; public class AConstNull extends Instruction { @@ -23,7 +24,7 @@ public class AConstNull extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, Object.class); + StackContext ctx = new StackContext(ins, Object.class, Value.NULL); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad.java index 2d606f6275..0b0635d652 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad.java @@ -71,7 +71,7 @@ public class ALoad extends Instruction implements LVTInstruction, WideInstructio VariableContext vctx = var.get(index); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_0.java index 04ccac7e9f..0efa3a9f6c 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_0.java @@ -30,7 +30,7 @@ public class ALoad_0 extends Instruction implements LVTInstruction VariableContext vctx = var.get(0); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_1.java index 3f746bfdaa..279b364307 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_1.java @@ -30,7 +30,7 @@ public class ALoad_1 extends Instruction implements LVTInstruction VariableContext vctx = var.get(1); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_2.java index 84ffd5d993..9f5a93e489 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_2.java @@ -30,7 +30,7 @@ public class ALoad_2 extends Instruction implements LVTInstruction VariableContext vctx = var.get(2); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_3.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_3.java index 5cb26e5096..b7c09946fe 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_3.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad_3.java @@ -30,7 +30,7 @@ public class ALoad_3 extends Instruction implements LVTInstruction VariableContext vctx = var.get(3); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ANewArray.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ANewArray.java index 093d3ddf39..2261843eaa 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ANewArray.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ANewArray.java @@ -15,6 +15,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import net.runelite.deob.ClassGroup; +import net.runelite.deob.execution.Value; public class ANewArray extends Instruction { @@ -53,7 +54,7 @@ public class ANewArray extends Instruction ins.pop(count); Type t = new Type(new net.runelite.deob.signature.Type("[" + clazz.getName())); - StackContext ctx = new StackContext(ins, t); + StackContext ctx = new StackContext(ins, t, Value.newArray(count.getValue())); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ArrayLength.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ArrayLength.java index 8f9edc69f9..e252430c9b 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ArrayLength.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ArrayLength.java @@ -27,7 +27,7 @@ public class ArrayLength extends Instruction ins.pop(array); - StackContext ctx = new StackContext(ins, int.class); + StackContext ctx = new StackContext(ins, int.class, array.getValue().arrayLength()); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/BALoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/BALoad.java index 73a09a31cb..930353fab5 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/BALoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/BALoad.java @@ -27,7 +27,7 @@ public class BALoad extends Instruction implements ArrayLoad ins.pop(index, array); - StackContext ctx = new StackContext(ins, int.class); // sign extend + StackContext ctx = new StackContext(ins, int.class, array.getValue().arrayGet(index.getValue()).cast(int.class)); // sign extend stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/BAStore.java b/src/main/java/net/runelite/deob/attributes/code/instructions/BAStore.java index 9597caf911..32a50d44d9 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/BAStore.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/BAStore.java @@ -28,6 +28,8 @@ public class BAStore extends Instruction implements ArrayStore ins.pop(value, index, array); + array.getValue().arraySet(index.getValue(), value.getValue()); + frame.addInstructionContext(ins); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/BiPush.java b/src/main/java/net/runelite/deob/attributes/code/instructions/BiPush.java index 6404d7a48d..343e470dab 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/BiPush.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/BiPush.java @@ -13,6 +13,7 @@ import net.runelite.deob.pool.PoolEntry; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import net.runelite.deob.execution.Value; public class BiPush extends Instruction implements PushConstantInstruction { @@ -43,7 +44,7 @@ public class BiPush extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, int.class); // bipush sign extends the value to an int + StackContext ctx = new StackContext(ins, int.class, new Value((int) b)); // bipush sign extends the value to an int stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/CALoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/CALoad.java index d3703aad4d..7ccce45863 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/CALoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/CALoad.java @@ -27,7 +27,7 @@ public class CALoad extends Instruction implements ArrayLoad ins.pop(index, array); - StackContext ctx = new StackContext(ins, int.class); // zero extended to int + StackContext ctx = new StackContext(ins, int.class, array.getValue().arrayGet(index.getValue()).cast(int.class)); // zero extended to int stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/CAStore.java b/src/main/java/net/runelite/deob/attributes/code/instructions/CAStore.java index 9907e55873..1af78ad6b3 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/CAStore.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/CAStore.java @@ -28,6 +28,8 @@ public class CAStore extends Instruction implements ArrayStore ins.pop(value, index, array); + array.getValue().arraySet(index.getValue(), value.getValue()); + frame.addInstructionContext(ins); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/CheckCast.java b/src/main/java/net/runelite/deob/attributes/code/instructions/CheckCast.java index 0d3e51c0e9..14d81ee6d3 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/CheckCast.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/CheckCast.java @@ -14,6 +14,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import net.runelite.deob.ClassGroup; +import net.runelite.deob.execution.Type; public class CheckCast extends Instruction { @@ -49,7 +50,10 @@ public class CheckCast extends Instruction ins.pop(value); - StackContext ctx = new StackContext(ins, value.getType()); + StackContext ctx = new StackContext(ins, + new Type(new net.runelite.deob.signature.Type(clazz.getName())), + value.getValue() + ); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/D2F.java b/src/main/java/net/runelite/deob/attributes/code/instructions/D2F.java index ed882d0139..e64b6cc401 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/D2F.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/D2F.java @@ -27,7 +27,7 @@ public class D2F extends Instruction ins.pop(value); - StackContext ctx = new StackContext(ins, float.class); + StackContext ctx = new StackContext(ins, float.class, value.getValue().cast(float.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/D2I.java b/src/main/java/net/runelite/deob/attributes/code/instructions/D2I.java index f515583359..1d7ad4dc5c 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/D2I.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/D2I.java @@ -27,7 +27,7 @@ public class D2I extends Instruction ins.pop(value); - StackContext ctx = new StackContext(ins, int.class); + StackContext ctx = new StackContext(ins, int.class, value.getValue().cast(int.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/D2L.java b/src/main/java/net/runelite/deob/attributes/code/instructions/D2L.java index d7f149b432..5ef0d5eecb 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/D2L.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/D2L.java @@ -27,7 +27,7 @@ public class D2L extends Instruction ins.pop(value); - StackContext ctx = new StackContext(ins, long.class); + StackContext ctx = new StackContext(ins, long.class, value.getValue().cast(long.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DALoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DALoad.java index 7e074ec42f..324825aa97 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DALoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DALoad.java @@ -27,7 +27,7 @@ public class DALoad extends Instruction implements ArrayLoad ins.pop(index, array); - StackContext ctx = new StackContext(ins, double.class); + StackContext ctx = new StackContext(ins, double.class, array.getValue().arrayGet(index.getValue()).cast(double.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DAStore.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DAStore.java index 4d1399ae5b..1e0f2c333e 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DAStore.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DAStore.java @@ -28,6 +28,8 @@ public class DAStore extends Instruction implements ArrayStore ins.pop(value, index, array); + array.getValue().arraySet(index.getValue(), value.getValue()); + frame.addInstructionContext(ins); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DAdd.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DAdd.java index 567be24c0e..267803d865 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DAdd.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DAdd.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class DAdd extends Instruction { @@ -26,7 +27,16 @@ public class DAdd extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, double.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + double d2 = (double) two.getValue().getValue(), + d1 = (double) one.getValue().getValue(); + + result = new Value(d1 + d2); + } + + StackContext ctx = new StackContext(ins, double.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DCmpG.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DCmpG.java index 61647e2327..ea8b90cc04 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DCmpG.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DCmpG.java @@ -9,6 +9,7 @@ import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; import java.io.IOException; +import net.runelite.deob.execution.Value; public class DCmpG extends Instruction { @@ -23,12 +24,26 @@ public class DCmpG extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + double d2 = (double) two.getValue().getValue(), + d1 = (double) one.getValue().getValue(); + + if (d1 > d2) + result = new Value(1); + else if (d1 == d2) + result = new Value(0); + else if (d1 < d2) + result = new Value(-1); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DCmpL.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DCmpL.java index 376a9bc5a4..cae239003a 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DCmpL.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DCmpL.java @@ -9,6 +9,7 @@ import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; import java.io.IOException; +import net.runelite.deob.execution.Value; public class DCmpL extends Instruction { @@ -23,12 +24,26 @@ public class DCmpL extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + double d2 = (double) two.getValue().getValue(), + d1 = (double) one.getValue().getValue(); + + if (d1 > d2) + result = new Value(1); + else if (d1 == d2) + result = new Value(0); + else if (d1 < d2) + result = new Value(-1); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DConst_0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DConst_0.java index 8075194ae9..9803530e05 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DConst_0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DConst_0.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.StackContext; import net.runelite.deob.pool.PoolEntry; import java.io.IOException; +import net.runelite.deob.execution.Value; public class DConst_0 extends Instruction implements PushConstantInstruction { @@ -25,7 +26,7 @@ public class DConst_0 extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, double.class); + StackContext ctx = new StackContext(ins, double.class, new Value(0d)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DConst_1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DConst_1.java index 5957255930..8afde9f462 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DConst_1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DConst_1.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.StackContext; import net.runelite.deob.pool.PoolEntry; import java.io.IOException; +import net.runelite.deob.execution.Value; public class DConst_1 extends Instruction implements PushConstantInstruction { @@ -25,7 +26,7 @@ public class DConst_1 extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, double.class); + StackContext ctx = new StackContext(ins, double.class, new Value(1d)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DDiv.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DDiv.java index 54201eb69f..fba0b9322f 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DDiv.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DDiv.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class DDiv extends Instruction { @@ -21,12 +22,21 @@ public class DDiv extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, double.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + double d2 = (double) two.getValue().getValue(), + d1 = (double) one.getValue().getValue(); + + result = new Value(d1 / d2); + } + + StackContext ctx = new StackContext(ins, double.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad.java index ae1c069026..def0e5fc31 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad.java @@ -73,7 +73,7 @@ public class DLoad extends Instruction implements LVTInstruction, WideInstructio assert vctx.getType().equals(new Type(double.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_0.java index 1937d21826..0e36193c54 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_0.java @@ -32,7 +32,7 @@ public class DLoad_0 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(double.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_1.java index af355a2591..1a739fbce2 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_1.java @@ -32,7 +32,7 @@ public class DLoad_1 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(double.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_2.java index 7981e9325f..0eb0a95831 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_2.java @@ -32,7 +32,7 @@ public class DLoad_2 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(double.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, double.class); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_3.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_3.java index bc20a44070..ffddbf4ead 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_3.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad_3.java @@ -32,7 +32,7 @@ public class DLoad_3 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(double.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, double.class); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DMul.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DMul.java index 2692b1c46d..821c958a15 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DMul.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DMul.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class DMul extends Instruction { @@ -21,12 +22,21 @@ public class DMul extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, double.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + double d2 = (double) two.getValue().getValue(), + d1 = (double) one.getValue().getValue(); + + result = new Value(d1 * d2); + } + + StackContext ctx = new StackContext(ins, double.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DNeg.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DNeg.java index 60017f7b16..7730d273d9 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DNeg.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DNeg.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class DNeg extends Instruction { @@ -24,7 +25,15 @@ public class DNeg extends Instruction StackContext value = stack.pop(); ins.pop(value); - StackContext ctx = new StackContext(ins, double.class); + Value result = Value.NULL; + if (!value.getValue().isNull()) + { + double d = (double) value.getValue().getValue(); + + result = new Value(-d); + } + + StackContext ctx = new StackContext(ins, double.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DRem.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DRem.java index b4ab513c9f..aad1a52815 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DRem.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DRem.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class DRem extends Instruction { @@ -21,12 +22,21 @@ public class DRem extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, double.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + double d2 = (double) two.getValue().getValue(), + d1 = (double) one.getValue().getValue(); + + result = new Value(d1 % d2); + } + + StackContext ctx = new StackContext(ins, double.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DSub.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DSub.java index 5ddf28edd8..3b83fef81f 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DSub.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DSub.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class DSub extends Instruction { @@ -26,7 +27,16 @@ public class DSub extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, double.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + double d2 = (double) two.getValue().getValue(), + d1 = (double) one.getValue().getValue(); + + result = new Value(d1 - d2); + } + + StackContext ctx = new StackContext(ins, double.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup.java index f24a9803c9..84e619a016 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup.java @@ -27,12 +27,12 @@ public class Dup extends Instruction implements DupInstruction StackContext obj = stack.pop(); ins.pop(obj); - StackContext ctx = new StackContext(ins, obj.getType()); + StackContext ctx = new StackContext(ins, obj.getType(), obj.getValue()); stack.push(ctx); ins.push(ctx); - ctx = new StackContext(ins, obj.getType()); + ctx = new StackContext(ins, obj.getType(), obj.getValue()); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2.java index 348e361a30..f47ff14968 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2.java @@ -35,26 +35,26 @@ public class Dup2 extends Instruction implements DupInstruction if (two != null) { - StackContext ctx = new StackContext(ins, two.getType()); + StackContext ctx = new StackContext(ins, two.getType(), two.getValue()); stack.push(ctx); ins.push(ctx); } - StackContext ctx = new StackContext(ins, one.getType()); + StackContext ctx = new StackContext(ins, one.getType(), one.getValue()); stack.push(one); ins.push(ctx); if (two != null) { - ctx = new StackContext(ins, two.getType()); + ctx = new StackContext(ins, two.getType(), two.getValue()); stack.push(ctx); ins.push(ctx); } - ctx = new StackContext(ins, one.getType()); + ctx = new StackContext(ins, one.getType(), one.getValue()); stack.push(one); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X1.java index e68b359b99..11568773aa 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X1.java @@ -42,31 +42,31 @@ public class Dup2_X1 extends Instruction implements DupInstruction if (two != null) { - StackContext ctx = new StackContext(ins, two.getType()); + StackContext ctx = new StackContext(ins, two.getType(), two.getValue()); stack.push(ctx); ins.push(ctx); } - StackContext ctx = new StackContext(ins, one.getType()); + StackContext ctx = new StackContext(ins, one.getType(), one.getValue()); stack.push(ctx); ins.push(ctx); - ctx = new StackContext(ins, three.getType()); + ctx = new StackContext(ins, three.getType(), three.getValue()); stack.push(ctx); ins.push(ctx); if (two != null) { - ctx = new StackContext(ins, two.getType()); + ctx = new StackContext(ins, two.getType(), two.getValue()); stack.push(ctx); ins.push(ctx); } - ctx = new StackContext(ins, one.getType()); + ctx = new StackContext(ins, one.getType(), one.getValue()); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X2.java index e4ca17c5ef..775c52d021 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X2.java @@ -42,39 +42,39 @@ public class Dup2_X2 extends Instruction implements DupInstruction if (two != null) { - StackContext ctx = new StackContext(ins, two.getType()); + StackContext ctx = new StackContext(ins, two.getType(), two.getValue()); stack.push(ctx); ins.push(ctx); } - StackContext ctx = new StackContext(ins, one.getType()); + StackContext ctx = new StackContext(ins, one.getType(), one.getValue()); stack.push(one); ins.push(ctx); if (four != null) { - ctx = new StackContext(ins, four.getType()); + ctx = new StackContext(ins, four.getType(), four.getValue()); stack.push(ctx); ins.push(ctx); } - ctx = new StackContext(ins, three.getType()); + ctx = new StackContext(ins, three.getType(), three.getValue()); stack.push(one); ins.push(ctx); if (two != null) { - ctx = new StackContext(ins, two.getType()); + ctx = new StackContext(ins, two.getType(), two.getValue()); stack.push(ctx); ins.push(ctx); } - ctx = new StackContext(ins, one.getType()); + ctx = new StackContext(ins, one.getType(), one.getValue()); stack.push(one); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X1.java index 4e0ce8ded2..733949fe4e 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X1.java @@ -33,17 +33,17 @@ public class Dup_X1 extends Instruction implements DupInstruction ins.pop(one, two); - StackContext ctx = new StackContext(ins, one.getType()); + StackContext ctx = new StackContext(ins, one.getType(), one.getValue()); stack.push(ctx); ins.push(ctx); - ctx = new StackContext(ins, two.getType()); + ctx = new StackContext(ins, two.getType(), two.getValue()); stack.push(ctx); ins.push(ctx); - ctx = new StackContext(ins, one.getType()); + ctx = new StackContext(ins, one.getType(), one.getValue()); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X2.java index 8c300c0c74..2cead393a3 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X2.java @@ -34,25 +34,25 @@ public class Dup_X2 extends Instruction implements DupInstruction if (three != null) ins.pop(three); - StackContext ctx = new StackContext(ins, one.getType()); + StackContext ctx = new StackContext(ins, one.getType(), one.getValue()); stack.push(ctx); ins.push(ctx); if (three != null) { - ctx = new StackContext(ins, three.getType()); + ctx = new StackContext(ins, three.getType(), three.getValue()); stack.push(ctx); ins.push(ctx); } - ctx = new StackContext(ins, two.getType()); + ctx = new StackContext(ins, two.getType(), two.getValue()); stack.push(ctx); ins.push(ctx); - ctx = new StackContext(ins, one.getType()); + ctx = new StackContext(ins, one.getType(), one.getValue()); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/F2D.java b/src/main/java/net/runelite/deob/attributes/code/instructions/F2D.java index 4889e3d557..ee3e5d13eb 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/F2D.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/F2D.java @@ -26,7 +26,7 @@ public class F2D extends Instruction StackContext object = stack.pop(); ins.pop(object); - StackContext ctx = new StackContext(ins, double.class); + StackContext ctx = new StackContext(ins, double.class, object.getValue().cast(double.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/F2I.java b/src/main/java/net/runelite/deob/attributes/code/instructions/F2I.java index 049a0ce3fa..94b7d88f68 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/F2I.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/F2I.java @@ -26,7 +26,7 @@ public class F2I extends Instruction StackContext object = stack.pop(); ins.pop(object); - StackContext ctx = new StackContext(ins, int.class); + StackContext ctx = new StackContext(ins, int.class, object.getValue().cast(int.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/F2L.java b/src/main/java/net/runelite/deob/attributes/code/instructions/F2L.java index a4cac299fc..f7b5f7010e 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/F2L.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/F2L.java @@ -26,7 +26,7 @@ public class F2L extends Instruction StackContext object = stack.pop(); ins.pop(object); - StackContext ctx = new StackContext(ins, long.class); + StackContext ctx = new StackContext(ins, long.class, object.getValue().cast(long.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FALoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FALoad.java index aad69caf0c..1c82150e07 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FALoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FALoad.java @@ -27,7 +27,7 @@ public class FALoad extends Instruction implements ArrayLoad ins.pop(index, array); - StackContext ctx = new StackContext(ins, float.class); + StackContext ctx = new StackContext(ins, float.class, array.getValue().arrayGet(index.getValue()).cast(float.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FAStore.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FAStore.java index 6df897f4bd..b7507e7d13 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FAStore.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FAStore.java @@ -28,6 +28,8 @@ public class FAStore extends Instruction implements ArrayStore ins.pop(value, index, array); + array.getValue().arraySet(index.getValue(), value.getValue()); + frame.addInstructionContext(ins); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FAdd.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FAdd.java index fe514e1c97..dc0674de12 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FAdd.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FAdd.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class FAdd extends Instruction { @@ -26,7 +27,16 @@ public class FAdd extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, float.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + float f2 = (float) two.getValue().getValue(), + f1 = (float) one.getValue().getValue(); + + result = new Value(f1 + f2); + } + + StackContext ctx = new StackContext(ins, float.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FCmpG.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FCmpG.java index 596443658c..dcb64d4538 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FCmpG.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FCmpG.java @@ -9,6 +9,7 @@ import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; import java.io.IOException; +import net.runelite.deob.execution.Value; public class FCmpG extends Instruction { @@ -23,12 +24,26 @@ public class FCmpG extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + float f2 = (float) two.getValue().getValue(), + f1 = (float) one.getValue().getValue(); + + if (f1 > f2) + result = new Value(1); + else if (f1 == f2) + result = new Value(0); + else if (f1 < f2) + result = new Value(-1); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FCmpL.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FCmpL.java index d96aee0362..723a085cda 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FCmpL.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FCmpL.java @@ -9,6 +9,7 @@ import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; import java.io.IOException; +import net.runelite.deob.execution.Value; public class FCmpL extends Instruction { @@ -23,12 +24,26 @@ public class FCmpL extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + float f2 = (float) two.getValue().getValue(), + f1 = (float) one.getValue().getValue(); + + if (f1 > f2) + result = new Value(1); + else if (f1 == f2) + result = new Value(0); + else if (f1 < f2) + result = new Value(-1); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FConst_0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FConst_0.java index 4ce94c86d3..6681094ad7 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FConst_0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FConst_0.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.StackContext; import net.runelite.deob.pool.PoolEntry; import java.io.IOException; +import net.runelite.deob.execution.Value; public class FConst_0 extends Instruction implements PushConstantInstruction { @@ -25,7 +26,7 @@ public class FConst_0 extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, float.class); + StackContext ctx = new StackContext(ins, float.class, new Value(0f)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FConst_1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FConst_1.java index 4f8837cd38..2f2d29966f 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FConst_1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FConst_1.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.StackContext; import net.runelite.deob.pool.PoolEntry; import java.io.IOException; +import net.runelite.deob.execution.Value; public class FConst_1 extends Instruction implements PushConstantInstruction { @@ -25,7 +26,7 @@ public class FConst_1 extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, float.class); + StackContext ctx = new StackContext(ins, float.class, new Value(1f)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FConst_2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FConst_2.java index ff5f51ca4e..b33cb456e8 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FConst_2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FConst_2.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.StackContext; import net.runelite.deob.pool.PoolEntry; import java.io.IOException; +import net.runelite.deob.execution.Value; public class FConst_2 extends Instruction implements PushConstantInstruction { @@ -25,7 +26,7 @@ public class FConst_2 extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, float.class); + StackContext ctx = new StackContext(ins, float.class, new Value(2f)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FDiv.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FDiv.java index 57407afde7..925c5dfacc 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FDiv.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FDiv.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class FDiv extends Instruction { @@ -21,12 +22,21 @@ public class FDiv extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, float.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + float f2 = (float) two.getValue().getValue(), + f1 = (float) one.getValue().getValue(); + + result = new Value(f1 / f2); + } + + StackContext ctx = new StackContext(ins, float.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad.java index f6022d2464..51a7f010cf 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad.java @@ -73,7 +73,7 @@ public class FLoad extends Instruction implements LVTInstruction, WideInstructio assert vctx.getType().equals(new Type(float.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_0.java index 828111791b..b745a4ad0e 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_0.java @@ -32,7 +32,7 @@ public class FLoad_0 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(float.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_1.java index dd9a3d4e9c..97932f7cc7 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_1.java @@ -32,7 +32,7 @@ public class FLoad_1 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(float.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_2.java index e8f68909fa..0471ac86c6 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_2.java @@ -32,7 +32,7 @@ public class FLoad_2 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(float.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_3.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_3.java index a4b296d0ef..fc627dfa53 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_3.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad_3.java @@ -32,7 +32,7 @@ public class FLoad_3 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(float.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FMul.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FMul.java index 7324f191ee..e8722838e8 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FMul.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FMul.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class FMul extends Instruction { @@ -21,12 +22,21 @@ public class FMul extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, float.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + float f2 = (float) two.getValue().getValue(), + f1 = (float) one.getValue().getValue(); + + result = new Value(f1 * f2); + } + + StackContext ctx = new StackContext(ins, float.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FNeg.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FNeg.java index 7ef4bdc5e0..91618a516b 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FNeg.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FNeg.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class FNeg extends Instruction { @@ -24,7 +25,15 @@ public class FNeg extends Instruction StackContext value = stack.pop(); ins.pop(value); - StackContext ctx = new StackContext(ins, float.class); + Value result = Value.NULL; + if (!value.getValue().isNull()) + { + float f = (float) value.getValue().getValue(); + + result = new Value(-f); + } + + StackContext ctx = new StackContext(ins, float.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FRem.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FRem.java index b75b0269fd..fa1167ea0f 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FRem.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FRem.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class FRem extends Instruction { @@ -21,12 +22,21 @@ public class FRem extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, float.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + float d2 = (float) two.getValue().getValue(), + d1 = (float) one.getValue().getValue(); + + result = new Value(d1 % d2); + } + + StackContext ctx = new StackContext(ins, float.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FSub.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FSub.java index 6a0e83363b..be34ff426a 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FSub.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FSub.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class FSub extends Instruction { @@ -26,7 +27,16 @@ public class FSub extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, float.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + float f2 = (float) two.getValue().getValue(), + f1 = (float) one.getValue().getValue(); + + result = new Value(f1 - f2); + } + + StackContext ctx = new StackContext(ins, float.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/GetField.java b/src/main/java/net/runelite/deob/attributes/code/instructions/GetField.java index 781c7c9d9d..c751ba903f 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/GetField.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/GetField.java @@ -17,6 +17,7 @@ import net.runelite.deob.pool.NameAndType; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import net.runelite.deob.execution.Value; public class GetField extends Instruction implements GetFieldInstruction { @@ -51,7 +52,7 @@ public class GetField extends Instruction implements GetFieldInstruction StackContext object = stack.pop(); ins.pop(object); - StackContext ctx = new StackContext(ins, new Type(field.getNameAndType().getDescriptorType()).toStackType()); + StackContext ctx = new StackContext(ins, new Type(field.getNameAndType().getDescriptorType()).toStackType(), Value.NULL); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/GetStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/GetStatic.java index e27b0b846d..704161d3c5 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/GetStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/GetStatic.java @@ -17,6 +17,7 @@ import net.runelite.deob.pool.NameAndType; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import net.runelite.deob.execution.Value; public class GetStatic extends Instruction implements GetFieldInstruction { @@ -55,7 +56,7 @@ public class GetStatic extends Instruction implements GetFieldInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, new Type(field.getNameAndType().getDescriptorType()).toStackType()); + StackContext ctx = new StackContext(ins, new Type(field.getNameAndType().getDescriptorType()).toStackType(), Value.NULL); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/I2B.java b/src/main/java/net/runelite/deob/attributes/code/instructions/I2B.java index d77c6c94ab..851e561e26 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/I2B.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/I2B.java @@ -26,7 +26,7 @@ public class I2B extends Instruction StackContext object = stack.pop(); ins.pop(object); - StackContext ctx = new StackContext(ins, int.class); // sign extneded + StackContext ctx = new StackContext(ins, int.class, object.getValue().cast(int.class)); // sign extneded stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/I2C.java b/src/main/java/net/runelite/deob/attributes/code/instructions/I2C.java index dd2fcd55ef..39a35741d2 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/I2C.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/I2C.java @@ -26,7 +26,7 @@ public class I2C extends Instruction StackContext object = stack.pop(); ins.pop(object); - StackContext ctx = new StackContext(ins, int.class); // sign extended + StackContext ctx = new StackContext(ins, int.class, object.getValue().cast(int.class)); // sign extended stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/I2D.java b/src/main/java/net/runelite/deob/attributes/code/instructions/I2D.java index 0881ec96ee..8ba4bd273e 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/I2D.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/I2D.java @@ -26,7 +26,7 @@ public class I2D extends Instruction StackContext object = stack.pop(); ins.pop(object); - StackContext ctx = new StackContext(ins, double.class); + StackContext ctx = new StackContext(ins, double.class, object.getValue().cast(double.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/I2F.java b/src/main/java/net/runelite/deob/attributes/code/instructions/I2F.java index 4adbeea524..1b9e24d7c7 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/I2F.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/I2F.java @@ -26,7 +26,7 @@ public class I2F extends Instruction StackContext object = stack.pop(); ins.pop(object); - StackContext ctx = new StackContext(ins, float.class); + StackContext ctx = new StackContext(ins, float.class, object.getValue().cast(float.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/I2L.java b/src/main/java/net/runelite/deob/attributes/code/instructions/I2L.java index b8cadaf162..3ef56b15b7 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/I2L.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/I2L.java @@ -26,7 +26,7 @@ public class I2L extends Instruction StackContext object = stack.pop(); ins.pop(object); - StackContext ctx = new StackContext(ins, long.class); + StackContext ctx = new StackContext(ins, long.class, object.getValue().cast(long.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/I2S.java b/src/main/java/net/runelite/deob/attributes/code/instructions/I2S.java index 8349ec7591..7a2d7ff642 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/I2S.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/I2S.java @@ -26,7 +26,7 @@ public class I2S extends Instruction StackContext object = stack.pop(); ins.pop(object); - StackContext ctx = new StackContext(ins, int.class); // sign extended + StackContext ctx = new StackContext(ins, int.class, object.getValue().cast(int.class)); // sign extended stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IALoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IALoad.java index 4bdcd0faeb..375eef5ba2 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IALoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IALoad.java @@ -27,7 +27,7 @@ public class IALoad extends Instruction implements ArrayLoad ins.pop(index, array); - StackContext ctx = new StackContext(ins, int.class); + StackContext ctx = new StackContext(ins, int.class, array.getValue().arrayGet(index.getValue()).cast(int.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IAStore.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IAStore.java index 07012b7197..044e182dfb 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IAStore.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IAStore.java @@ -28,6 +28,8 @@ public class IAStore extends Instruction implements ArrayStore ins.pop(value, index, array); + array.getValue().arraySet(index.getValue(), value.getValue()); + frame.addInstructionContext(ins); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IAdd.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IAdd.java index 053a76de47..5134a2c251 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IAdd.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IAdd.java @@ -10,6 +10,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class IAdd extends Instruction { @@ -34,7 +35,16 @@ public class IAdd extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + int i2 = (int) two.getValue().getValue(), + i1 = (int) one.getValue().getValue(); + + result = new Value(i1 + i2); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IAnd.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IAnd.java index 739319db8e..8642e0928c 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IAnd.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IAnd.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class IAnd extends Instruction { @@ -26,7 +27,16 @@ public class IAnd extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + int i2 = (int) two.getValue().getValue(), + i1 = (int) one.getValue().getValue(); + + result = new Value(i1 & i2); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_0.java index 5a2e50663b..28d2ed37f0 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_0.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.StackContext; import net.runelite.deob.pool.PoolEntry; import java.io.IOException; +import net.runelite.deob.execution.Value; public class IConst_0 extends Instruction implements PushConstantInstruction { @@ -30,7 +31,7 @@ public class IConst_0 extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, int.class); + StackContext ctx = new StackContext(ins, int.class, new Value(0)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_1.java index 57ee54e0ec..b439222857 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_1.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.StackContext; import net.runelite.deob.pool.PoolEntry; import java.io.IOException; +import net.runelite.deob.execution.Value; public class IConst_1 extends Instruction implements PushConstantInstruction { @@ -30,7 +31,7 @@ public class IConst_1 extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, int.class); + StackContext ctx = new StackContext(ins, int.class, new Value(1)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_2.java index 38ba4721da..a9d9839939 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_2.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.StackContext; import net.runelite.deob.pool.PoolEntry; import java.io.IOException; +import net.runelite.deob.execution.Value; public class IConst_2 extends Instruction implements PushConstantInstruction { @@ -30,7 +31,7 @@ public class IConst_2 extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, int.class); + StackContext ctx = new StackContext(ins, int.class, new Value(2)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_3.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_3.java index 80f4e35955..b6d876e3e6 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_3.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_3.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.StackContext; import net.runelite.deob.pool.PoolEntry; import java.io.IOException; +import net.runelite.deob.execution.Value; public class IConst_3 extends Instruction implements PushConstantInstruction { @@ -30,7 +31,7 @@ public class IConst_3 extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, int.class); + StackContext ctx = new StackContext(ins, int.class, new Value(3)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_4.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_4.java index 815c0736e4..4d36497ae0 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_4.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_4.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.StackContext; import net.runelite.deob.pool.PoolEntry; import java.io.IOException; +import net.runelite.deob.execution.Value; public class IConst_4 extends Instruction implements PushConstantInstruction { @@ -30,7 +31,7 @@ public class IConst_4 extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, int.class); + StackContext ctx = new StackContext(ins, int.class, new Value(4)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_5.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_5.java index 416473bd8f..f85a37e3a9 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_5.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_5.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.StackContext; import net.runelite.deob.pool.PoolEntry; import java.io.IOException; +import net.runelite.deob.execution.Value; public class IConst_5 extends Instruction implements PushConstantInstruction { @@ -30,7 +31,7 @@ public class IConst_5 extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, int.class); + StackContext ctx = new StackContext(ins, int.class, new Value(5)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_M1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_M1.java index bfbe243c6b..12322dfbd3 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_M1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IConst_M1.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.StackContext; import net.runelite.deob.pool.PoolEntry; import java.io.IOException; +import net.runelite.deob.execution.Value; public class IConst_M1 extends Instruction implements PushConstantInstruction { @@ -30,7 +31,7 @@ public class IConst_M1 extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, int.class); + StackContext ctx = new StackContext(ins, int.class, new Value(-1)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IDiv.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IDiv.java index 4d39142f3f..8ca1568901 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IDiv.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IDiv.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class IDiv extends Instruction { @@ -26,12 +27,22 @@ public class IDiv extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + int i2 = (int) two.getValue().getValue(), + i1 = (int) one.getValue().getValue(); + + if (i2 != 0) + result = new Value(i1 / i2); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IInc.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IInc.java index 1afc4813b1..dd6c1efffb 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IInc.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IInc.java @@ -14,6 +14,7 @@ import net.runelite.deob.execution.Variables; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import net.runelite.deob.execution.Value; public class IInc extends Instruction implements LVTInstruction, WideInstruction { @@ -67,7 +68,15 @@ public class IInc extends Instruction implements LVTInstruction, WideInstruction assert vctx.getType().equals(new Type(int.class.getCanonicalName())); ins.read(vctx); - vctx = new VariableContext(ins, vctx); + Value value = vctx.getValue(); + if (!vctx.getValue().isNull()) + { + int i = (int) vctx.getValue().getValue(); + i += inc; + value = new Value(i); + } + + vctx = new VariableContext(ins, new Type(int.class.getCanonicalName()), value); var.set(index, vctx); frame.addInstructionContext(ins); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad.java index 88dd26a874..3ae70500b5 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad.java @@ -73,7 +73,7 @@ public class ILoad extends Instruction implements LVTInstruction, WideInstructio assert vctx.getType().equals(new Type(int.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_0.java index d90cceb755..f075e5b614 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_0.java @@ -32,7 +32,7 @@ public class ILoad_0 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(int.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_1.java index a1517c795f..3b944a1701 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_1.java @@ -32,7 +32,7 @@ public class ILoad_1 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(int.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_2.java index 81541b70f6..70fbf70839 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_2.java @@ -32,7 +32,7 @@ public class ILoad_2 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(int.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_3.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_3.java index 6bde3ce278..4d8a0740fa 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_3.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_3.java @@ -32,7 +32,7 @@ public class ILoad_3 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(int.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IMul.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IMul.java index 73e6f27e58..7985008126 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IMul.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IMul.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class IMul extends Instruction { @@ -30,12 +31,21 @@ public class IMul extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + int i2 = (int) two.getValue().getValue(), + i1 = (int) one.getValue().getValue(); + + result = new Value(i1 * i2); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/INeg.java b/src/main/java/net/runelite/deob/attributes/code/instructions/INeg.java index b3cf69bf63..3001733696 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/INeg.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/INeg.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class INeg extends Instruction { @@ -24,7 +25,15 @@ public class INeg extends Instruction StackContext value = stack.pop(); ins.pop(value); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!value.getValue().isNull()) + { + int i = (int) value.getValue().getValue(); + + result = new Value(-i); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IOr.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IOr.java index f9ffb31937..b9e2ef0150 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IOr.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IOr.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class IOr extends Instruction { @@ -26,7 +27,16 @@ public class IOr extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + int i2 = (int) two.getValue().getValue(), + i1 = (int) one.getValue().getValue(); + + result = new Value(i1 | i2); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IRem.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IRem.java index d0802680bf..bac8005ea5 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IRem.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IRem.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class IRem extends Instruction { @@ -21,12 +22,21 @@ public class IRem extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + int i2 = (int) two.getValue().getValue(), + i1 = (int) one.getValue().getValue(); + + result = new Value(i1 % i2); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IShL.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IShL.java index 879e419b60..b4c085d16b 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IShL.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IShL.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class IShL extends Instruction { @@ -21,12 +22,21 @@ public class IShL extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + int i2 = (int) two.getValue().getValue(), + i1 = (int) one.getValue().getValue(); + + result = new Value(i1 << i2); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IShR.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IShR.java index 32b1abd52b..962c7f5ae0 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IShR.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IShR.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class IShR extends Instruction { @@ -21,12 +22,21 @@ public class IShR extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + int i2 = (int) two.getValue().getValue(), + i1 = (int) one.getValue().getValue(); + + result = new Value(i1 >> i2); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ISub.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ISub.java index c1e2b73ceb..f22bc6bfd8 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ISub.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ISub.java @@ -9,6 +9,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class ISub extends Instruction { @@ -28,7 +29,16 @@ public class ISub extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + int i2 = (int) two.getValue().getValue(), + i1 = (int) one.getValue().getValue(); + + result = new Value(i1 - i2); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IUShR.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IUShR.java index e2f25473c5..a21a61245b 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IUShR.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IUShR.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class IUShR extends Instruction { @@ -21,12 +22,21 @@ public class IUShR extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + int i2 = (int) two.getValue().getValue(), + i1 = (int) one.getValue().getValue(); + + result = new Value(i1 >>> i2); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IXor.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IXor.java index 575fdbc6f1..07e5743f6f 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IXor.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IXor.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class IXor extends Instruction { @@ -26,7 +27,16 @@ public class IXor extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + int i2 = (int) two.getValue().getValue(), + i1 = (int) one.getValue().getValue(); + + result = new Value(i1 ^ i2); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InstanceOf.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InstanceOf.java index 3d7f206f6b..fff770fe54 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InstanceOf.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InstanceOf.java @@ -14,6 +14,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import net.runelite.deob.ClassGroup; +import net.runelite.deob.execution.Value; public class InstanceOf extends Instruction { @@ -48,7 +49,7 @@ public class InstanceOf extends Instruction StackContext obj = stack.pop(); ins.pop(obj); - StackContext ctx = new StackContext(ins, int.class); + StackContext ctx = new StackContext(ins, int.class, Value.NULL); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java index d2be2ed68f..ebad6e4b2b 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import net.runelite.deob.execution.Execution; +import net.runelite.deob.execution.Value; public class InvokeInterface extends Instruction implements InvokeInstruction { @@ -88,7 +89,10 @@ public class InvokeInterface extends Instruction implements InvokeInstruction if (!method.getNameAndType().isVoid()) { - StackContext ctx = new StackContext(ins, new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType()); + StackContext ctx = new StackContext(ins, + new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType(), + Value.NULL + ); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java index c03fba5138..ad3a161ea6 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import net.runelite.deob.execution.Execution; +import net.runelite.deob.execution.Value; public class InvokeSpecial extends Instruction implements InvokeInstruction { @@ -73,7 +74,10 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction if (!method.getNameAndType().isVoid()) { - StackContext ctx = new StackContext(ins, new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType()); + StackContext ctx = new StackContext(ins, + new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType(), + Value.NULL + ); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java index cc5dc7c11d..9116cad69e 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import net.runelite.deob.execution.Execution; +import net.runelite.deob.execution.Value; public class InvokeStatic extends Instruction implements InvokeInstruction { @@ -83,7 +84,10 @@ public class InvokeStatic extends Instruction implements InvokeInstruction if (!method.getNameAndType().isVoid()) { - StackContext ctx = new StackContext(ins, new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType()); + StackContext ctx = new StackContext(ins, + new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType(), + Value.NULL + ); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java index c75b3e3278..a8784f2352 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import net.runelite.deob.execution.Execution; +import net.runelite.deob.execution.Value; public class InvokeVirtual extends Instruction implements InvokeInstruction { @@ -73,7 +74,10 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction if (!method.getNameAndType().isVoid()) { - StackContext ctx = new StackContext(ins, new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType()); + StackContext ctx = new StackContext(ins, + new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType(), + Value.NULL + ); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/L2D.java b/src/main/java/net/runelite/deob/attributes/code/instructions/L2D.java index 3d974a1b0e..dc8dfc1abd 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/L2D.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/L2D.java @@ -26,7 +26,7 @@ public class L2D extends Instruction StackContext object = stack.pop(); ins.pop(object); - StackContext ctx = new StackContext(ins, double.class); + StackContext ctx = new StackContext(ins, double.class, object.getValue().cast(double.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/L2F.java b/src/main/java/net/runelite/deob/attributes/code/instructions/L2F.java index 1f3e1dcb7e..f3e03a205e 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/L2F.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/L2F.java @@ -26,7 +26,7 @@ public class L2F extends Instruction StackContext object = stack.pop(); ins.pop(object); - StackContext ctx = new StackContext(ins, float.class); + StackContext ctx = new StackContext(ins, float.class, object.getValue().cast(float.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/L2I.java b/src/main/java/net/runelite/deob/attributes/code/instructions/L2I.java index 1e41bfe555..aff60f4175 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/L2I.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/L2I.java @@ -26,7 +26,7 @@ public class L2I extends Instruction StackContext object = stack.pop(); ins.pop(object); - StackContext ctx = new StackContext(ins, int.class); + StackContext ctx = new StackContext(ins, int.class, object.getValue().cast(int.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LALoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LALoad.java index 6611348040..2286de46ba 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LALoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LALoad.java @@ -27,7 +27,7 @@ public class LALoad extends Instruction implements ArrayLoad ins.pop(index, array); - StackContext ctx = new StackContext(ins, long.class); + StackContext ctx = new StackContext(ins, long.class, array.getValue().arrayGet(index.getValue()).cast(long.class)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LAStore.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LAStore.java index 0d183114da..cf58357ee7 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LAStore.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LAStore.java @@ -28,6 +28,8 @@ public class LAStore extends Instruction implements ArrayStore ins.pop(value, index, array); + array.getValue().arraySet(index.getValue(), value.getValue()); + frame.addInstructionContext(ins); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LAdd.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LAdd.java index 8940463db4..87db46575c 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LAdd.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LAdd.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class LAdd extends Instruction { @@ -26,7 +27,16 @@ public class LAdd extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, long.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + long l2 = (long) two.getValue().getValue(), + l1 = (long) one.getValue().getValue(); + + result = new Value(l1 + l2); + } + + StackContext ctx = new StackContext(ins, long.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LAnd.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LAnd.java index c8fd3f3dae..d5fabb5f24 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LAnd.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LAnd.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class LAnd extends Instruction { @@ -26,7 +27,16 @@ public class LAnd extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, long.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + long l2 = (long) two.getValue().getValue(), + l1 = (long) one.getValue().getValue(); + + result = new Value(l1 & l2); + } + + StackContext ctx = new StackContext(ins, long.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LCmp.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LCmp.java index 5a02261c2a..21eb78e655 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LCmp.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LCmp.java @@ -9,6 +9,7 @@ import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; import java.io.IOException; +import net.runelite.deob.execution.Value; public class LCmp extends Instruction { @@ -23,12 +24,26 @@ public class LCmp extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, int.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + long l2 = (long) two.getValue().getValue(), + l1 = (long) one.getValue().getValue(); + + if (l1 > l2) + result = new Value(1); + else if (l1 == l2) + result = new Value(0); + else if (l1 < l2) + result = new Value(-1); + } + + StackContext ctx = new StackContext(ins, int.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_0.java index 06c339d661..90a96758e5 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_0.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.StackContext; import net.runelite.deob.pool.PoolEntry; import java.io.IOException; +import net.runelite.deob.execution.Value; public class LConst_0 extends Instruction implements PushConstantInstruction { @@ -25,7 +26,7 @@ public class LConst_0 extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, long.class); + StackContext ctx = new StackContext(ins, long.class, new Value(0L)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_1.java index db3350a661..83712595e9 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_1.java @@ -11,6 +11,7 @@ import net.runelite.deob.execution.StackContext; import net.runelite.deob.pool.PoolEntry; import java.io.IOException; +import net.runelite.deob.execution.Value; public class LConst_1 extends Instruction implements PushConstantInstruction { @@ -30,7 +31,7 @@ public class LConst_1 extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, long.class); + StackContext ctx = new StackContext(ins, long.class, new Value(1L)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LDC2_W.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LDC2_W.java index 36103b5f21..e22afc4240 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LDC2_W.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LDC2_W.java @@ -13,6 +13,7 @@ import net.runelite.deob.pool.PoolEntry; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import net.runelite.deob.execution.Value; import net.runelite.deob.pool.ConstantType; public class LDC2_W extends Instruction implements PushConstantInstruction @@ -62,7 +63,7 @@ public class LDC2_W extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, value.getTypeClass()); + StackContext ctx = new StackContext(ins, value.getTypeClass(), new Value(value.getObject())); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LDC_W.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LDC_W.java index 78dd3a39b5..1c64dcfa1a 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LDC_W.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LDC_W.java @@ -13,6 +13,7 @@ import net.runelite.deob.pool.PoolEntry; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import net.runelite.deob.execution.Value; import net.runelite.deob.pool.ConstantType; public class LDC_W extends Instruction implements PushConstantInstruction @@ -100,7 +101,7 @@ public class LDC_W extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, value.getTypeClass()); + StackContext ctx = new StackContext(ins, value.getTypeClass(), new Value(value.getObject())); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LDiv.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LDiv.java index f82c048fe3..547e29674a 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LDiv.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LDiv.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class LDiv extends Instruction { @@ -21,12 +22,21 @@ public class LDiv extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, long.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + long l2 = (long) two.getValue().getValue(), + l1 = (long) one.getValue().getValue(); + + result = new Value(l1 / l2); + } + + StackContext ctx = new StackContext(ins, long.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad.java index 2fc0129555..f1e69e1bbf 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad.java @@ -73,7 +73,7 @@ public class LLoad extends Instruction implements LVTInstruction, WideInstructio assert vctx.getType().equals(new Type(long.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_0.java index 229fc1e369..428a03cbdb 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_0.java @@ -32,7 +32,7 @@ public class LLoad_0 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(long.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_1.java index e2d1bdd332..7af0f54144 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_1.java @@ -32,7 +32,7 @@ public class LLoad_1 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(long.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_2.java index 57680d11db..7141603110 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_2.java @@ -32,7 +32,7 @@ public class LLoad_2 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(long.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_3.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_3.java index 959d9c97b9..8b56c1e9af 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_3.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad_3.java @@ -32,7 +32,7 @@ public class LLoad_3 extends Instruction implements LVTInstruction assert vctx.getType().equals(new Type(long.class.getName())); ins.read(vctx); - StackContext ctx = new StackContext(ins, vctx.getType()); + StackContext ctx = new StackContext(ins, vctx); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LMul.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LMul.java index 7be6001ca9..7a702271ce 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LMul.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LMul.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class LMul extends Instruction { @@ -27,12 +28,21 @@ public class LMul extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, long.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + long l2 = (long) two.getValue().getValue(), + l1 = (long) one.getValue().getValue(); + + result = new Value(l1 * l2); + } + + StackContext ctx = new StackContext(ins, long.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LNeg.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LNeg.java index 6dd0e5b04e..c5bba9387d 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LNeg.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LNeg.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class LNeg extends Instruction { @@ -24,7 +25,15 @@ public class LNeg extends Instruction StackContext value = stack.pop(); ins.pop(value); - StackContext ctx = new StackContext(ins, long.class); + Value result = Value.NULL; + if (!value.getValue().isNull()) + { + long l = (long) value.getValue().getValue(); + + result = new Value(-l); + } + + StackContext ctx = new StackContext(ins, long.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LOr.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LOr.java index e1b19fb879..6a3d0ccd8d 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LOr.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LOr.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class LOr extends Instruction { @@ -26,7 +27,16 @@ public class LOr extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, long.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + long l2 = (long) two.getValue().getValue(), + l1 = (long) one.getValue().getValue(); + + result = new Value(l1 | l2); + } + + StackContext ctx = new StackContext(ins, long.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LRem.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LRem.java index 58eebf382f..ec02d32779 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LRem.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LRem.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class LRem extends Instruction { @@ -26,7 +27,16 @@ public class LRem extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, long.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + long l2 = (long) two.getValue().getValue(), + l1 = (long) one.getValue().getValue(); + + result = new Value(l1 % l2); + } + + StackContext ctx = new StackContext(ins, long.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LShL.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LShL.java index 9ef15ddcf0..fd36ba828f 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LShL.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LShL.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class LShL extends Instruction { @@ -21,12 +22,21 @@ public class LShL extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, long.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + long l2 = (long) two.getValue().as(long.class), + l1 = (long) two.getValue().as(long.class); + + result = new Value(l1 << l2); + } + + StackContext ctx = new StackContext(ins, long.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LShR.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LShR.java index abb5010f95..c8783ae1b4 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LShR.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LShR.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class LShR extends Instruction { @@ -21,12 +22,21 @@ public class LShR extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, long.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + long l2 = (long) two.getValue().as(long.class), + l1 = (long) two.getValue().as(long.class); + + result = new Value(l1 >> l2); + } + + StackContext ctx = new StackContext(ins, long.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LSub.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LSub.java index e7b5e627a8..eccf344d52 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LSub.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LSub.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class LSub extends Instruction { @@ -26,7 +27,16 @@ public class LSub extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, long.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + long l2 = (long) two.getValue().getValue(), + l1 = (long) one.getValue().getValue(); + + result = new Value(l1 - l2); + } + + StackContext ctx = new StackContext(ins, long.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LUShR.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LUShR.java index 76d0494910..73d2a1b98a 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LUShR.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LUShR.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class LUShR extends Instruction { @@ -21,12 +22,21 @@ public class LUShR extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext one = stack.pop(); StackContext two = stack.pop(); + StackContext one = stack.pop(); - ins.pop(one, two); + ins.pop(two, one); - StackContext ctx = new StackContext(ins, long.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + long l2 = (long) two.getValue().as(long.class), + l1 = (long) two.getValue().as(long.class); + + result = new Value(l1 >>> l2); + } + + StackContext ctx = new StackContext(ins, long.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LXor.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LXor.java index 69c48a5cd1..47d70f9df7 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LXor.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LXor.java @@ -7,6 +7,7 @@ import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; +import net.runelite.deob.execution.Value; public class LXor extends Instruction { @@ -26,7 +27,16 @@ public class LXor extends Instruction ins.pop(two, one); - StackContext ctx = new StackContext(ins, long.class); + Value result = Value.NULL; + if (!two.getValue().isNull() && !one.getValue().isNull()) + { + long l2 = (long) two.getValue().getValue(), + l1 = (long) one.getValue().getValue(); + + result = new Value(l1 ^ l2); + } + + StackContext ctx = new StackContext(ins, long.class, result); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/MultiANewArray.java b/src/main/java/net/runelite/deob/attributes/code/instructions/MultiANewArray.java index 6a05b0aba7..53e0b897d4 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/MultiANewArray.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/MultiANewArray.java @@ -15,6 +15,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import net.runelite.deob.ClassGroup; +import net.runelite.deob.execution.Value; public class MultiANewArray extends Instruction { @@ -49,14 +50,17 @@ public class MultiANewArray extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); + Value[] lenghts = new Value[dimensions]; for (int i = 0; i < dimensions; ++i) { StackContext ctx = stack.pop(); ins.pop(ctx); + + lenghts[i] = ctx.getValue(); } Type t = new Type(new net.runelite.deob.signature.Type(clazz.getName())); - StackContext ctx = new StackContext(ins, t); + StackContext ctx = new StackContext(ins, t, Value.newArray(lenghts)); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/New.java b/src/main/java/net/runelite/deob/attributes/code/instructions/New.java index ed3d8905b1..0f3675a594 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/New.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/New.java @@ -15,6 +15,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import net.runelite.deob.ClassGroup; +import net.runelite.deob.execution.Value; public class New extends Instruction { @@ -46,7 +47,7 @@ public class New extends Instruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, new Type(clazz.getName())); + StackContext ctx = new StackContext(ins, new Type(clazz.getName()), Value.NULL); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/NewArray.java b/src/main/java/net/runelite/deob/attributes/code/instructions/NewArray.java index 77b522b7c5..bb389d87cf 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/NewArray.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/NewArray.java @@ -12,6 +12,7 @@ import net.runelite.deob.execution.Type; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import net.runelite.deob.execution.Value; public class NewArray extends Instruction { @@ -77,9 +78,11 @@ public class NewArray extends Instruction case 11: t = long.class; break; + default: + throw new IllegalStateException("unknown array type " + type); } - StackContext ctx = new StackContext(ins, new Type(t.getName())); + StackContext ctx = new StackContext(ins, new Type(t.getName()), Value.newArray(count.getValue())); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/SALoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/SALoad.java index 6c3282e833..c4a65f46bd 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/SALoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/SALoad.java @@ -27,7 +27,7 @@ public class SALoad extends Instruction implements ArrayLoad ins.pop(index, array); - StackContext ctx = new StackContext(ins, int.class); // sign extend + StackContext ctx = new StackContext(ins, int.class, array.getValue().arrayGet(index.getValue()).cast(int.class)); // sign extend stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/SAStore.java b/src/main/java/net/runelite/deob/attributes/code/instructions/SAStore.java index 6a1d9080ba..458d03f6e1 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/SAStore.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/SAStore.java @@ -28,6 +28,8 @@ public class SAStore extends Instruction implements ArrayStore ins.pop(value, index, array); + array.getValue().arraySet(index.getValue(), value.getValue()); + frame.addInstructionContext(ins); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/SiPush.java b/src/main/java/net/runelite/deob/attributes/code/instructions/SiPush.java index bb21093076..884d39b910 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/SiPush.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/SiPush.java @@ -13,6 +13,7 @@ import net.runelite.deob.pool.PoolEntry; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import net.runelite.deob.execution.Value; public class SiPush extends Instruction implements PushConstantInstruction { @@ -49,7 +50,7 @@ public class SiPush extends Instruction implements PushConstantInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, int.class); // sign extend + StackContext ctx = new StackContext(ins, int.class, new Value((int) s)); // sign extend stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Swap.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Swap.java index c80458cb9d..b587e86fd9 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Swap.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Swap.java @@ -26,12 +26,12 @@ public class Swap extends Instruction ins.pop(one, two); - StackContext ctx = new StackContext(ins, one.getType()); + StackContext ctx = new StackContext(ins, one.getType(), one.getValue()); stack.push(ctx); ins.push(ctx); - ctx = new StackContext(ins, two.getType()); + ctx = new StackContext(ins, two.getType(), two.getValue()); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/Rename2.java b/src/main/java/net/runelite/deob/deobfuscators/rename/Rename2.java index efbc712544..92641eb60e 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/Rename2.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/Rename2.java @@ -276,6 +276,8 @@ public class Rename2 // } // } + // e Edge{from=Vertex{object=client.init()V}, to=Vertex{object=static Ljava/lang/String;[] class14.field209}, type=SETFIELD} + // e2 Edge{from=Vertex{object=client.init()V}, to=Vertex{object=static Ljava/lang/String;[] class89.field1550}, type=SETFIELD} if (!e.getTo().couldBeEqual(e2.getTo())) { // System.out.println(e.getTo() + " != " + e2.getTo()); diff --git a/src/main/java/net/runelite/deob/execution/Frame.java b/src/main/java/net/runelite/deob/execution/Frame.java index 9e20bc0b8d..ea388d607b 100644 --- a/src/main/java/net/runelite/deob/execution/Frame.java +++ b/src/main/java/net/runelite/deob/execution/Frame.java @@ -264,7 +264,7 @@ public class Frame stack.pop(); InstructionContext ins = new InstructionContext(i, f); - StackContext ctx = new StackContext(ins, new Type("java/lang/Exception")); + StackContext ctx = new StackContext(ins, new Type("java/lang/Exception"), Value.NULL); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/execution/StackContext.java b/src/main/java/net/runelite/deob/execution/StackContext.java index 27cd190364..def515a237 100644 --- a/src/main/java/net/runelite/deob/execution/StackContext.java +++ b/src/main/java/net/runelite/deob/execution/StackContext.java @@ -2,30 +2,37 @@ package net.runelite.deob.execution; import java.util.ArrayList; import java.util.List; +import net.runelite.deob.util.PrimitiveUtils; public class StackContext { public InstructionContext pushed; // instruction which pushed this public List poppeds = new ArrayList<>(); // instructions which popped this public Type type; // type of this + private Value value; public boolean removed; - public StackContext(InstructionContext pushed, Type type) + public StackContext(InstructionContext pushed, Type type, Value value) { this.pushed = pushed; this.type = type; + this.value = value; } - public StackContext(InstructionContext pushed, Class clazz) + public StackContext(InstructionContext pushed, Class clazz, Value value) { + assert value.isNull() || value.getValue().getClass() == PrimitiveUtils.unbox(clazz); + this.pushed = pushed; type = new Type(clazz.getCanonicalName()); + this.value = value; } - public StackContext(InstructionContext pushed, net.runelite.deob.pool.Class c) + public StackContext(InstructionContext pushed, VariableContext vctx) { this.pushed = pushed; - type = new Type(c.getName()); + this.type = vctx.getType(); + this.value = vctx.getValue(); } public InstructionContext getPushed() @@ -48,6 +55,11 @@ public class StackContext { return type; } + + public Value getValue() + { + return value; + } // remove this object from the stack public List removeStack() diff --git a/src/main/java/net/runelite/deob/execution/Value.java b/src/main/java/net/runelite/deob/execution/Value.java new file mode 100644 index 0000000000..1e5554f218 --- /dev/null +++ b/src/main/java/net/runelite/deob/execution/Value.java @@ -0,0 +1,128 @@ +package net.runelite.deob.execution; + +import java.lang.reflect.Array; +import java.util.Arrays; +import net.runelite.deob.util.PrimitiveUtils; + +public class Value +{ + public static final Value NULL = new Value(null); + + private Object value; + + public Value(Object value) + { + assert !(value instanceof Value); + this.value = value; + } + + public boolean isNull() + { + assert (value == null) == (this == NULL); + return this == NULL; + } + + public Object getValue() + { + return value; + } + + private boolean isArray() + { + return !isNull() && value.getClass().isArray(); + } + + public Value arrayLength() + { + return isArray() ? new Value(Array.getLength(value)) : NULL; + } + + public Value arrayGet(Value index) + { + if (isNull() || index.isNull()) + return NULL; + + int i = (int) index.value; + + if (i < 0) + return NULL; + + assert isArray(); + + int len = Array.getLength(value); + if (len <= i) + return NULL; + + Value o = (Value) Array.get(value, i); + if (o.isNull()) + return NULL; + + return o; + } + + public void arraySet(Value index, Value object) + { + if (isNull() || index.isNull()) + return; + + int i = (int) index.value; + + if (i < 0) + return; + + assert isArray(); + + int len = Array.getLength(value); + if (len <= i) + { + value = Arrays.copyOf((Value[]) value, i + 1, Value[].class); + Arrays.fill((Value[]) value, len, i, NULL); + } + + Array.set(value, i, object); + } + + public Value cast(Class c) + { + if (isNull()) + return NULL; + + Object v = value; + + if (value instanceof Number && Number.class.isAssignableFrom(PrimitiveUtils.unbox(c))) + v = PrimitiveUtils.convert((Number) value, c); + + return new Value(PrimitiveUtils.unbox(c).cast(v)); + } + + public Object as(Class c) + { + return PrimitiveUtils.convert((Number) value, c); + } + + public static Value newArray(Value length) + { + if (length.isNull()) + { + return new Value(new Value[0]); + } + else + { + int len = (int) length.getValue(); + Value[] array = new Value[len]; + Arrays.fill(array, NULL); + return new Value(array); + } + } + + public static Value newArray(Value[] lenghts) + { + Value mainArray = new Value(new Value[lenghts.length]); + + int i = 0; + for (Value l : lenghts) + mainArray.arraySet(new Value(i++), newArray(l)); + + return mainArray; + } +} diff --git a/src/main/java/net/runelite/deob/execution/VariableContext.java b/src/main/java/net/runelite/deob/execution/VariableContext.java index 4c60dcc597..72d87264f3 100644 --- a/src/main/java/net/runelite/deob/execution/VariableContext.java +++ b/src/main/java/net/runelite/deob/execution/VariableContext.java @@ -9,12 +9,14 @@ public class VariableContext private InstructionContext ic; // the instruction which stored it. also ctx.popped? private Type type; private List read = new ArrayList<>(); // instructions which reads this + private Value value; public VariableContext(InstructionContext i, StackContext ctx) { ic = i; this.ctx = ctx; type = ctx.getType(); + value = ctx.getValue(); } public VariableContext(Type type) // for entrypoints @@ -27,6 +29,14 @@ public class VariableContext ic = i; ctx = other.ctx; type = other.type; + value = other.value; + } + + public VariableContext(InstructionContext i, Type type, Value value) + { + ic = i; + this.type = type; + this.value = value; } public StackContext getStackContext() @@ -43,6 +53,11 @@ public class VariableContext { return type; } + + public Value getValue() + { + return value; + } public void addRead(InstructionContext ctx) { diff --git a/src/main/java/net/runelite/deob/util/PrimitiveUtils.java b/src/main/java/net/runelite/deob/util/PrimitiveUtils.java new file mode 100644 index 0000000000..9ea9f7b8d6 --- /dev/null +++ b/src/main/java/net/runelite/deob/util/PrimitiveUtils.java @@ -0,0 +1,48 @@ +package net.runelite.deob.util; + +public class PrimitiveUtils +{ + public static Class unbox(Class c) + { + if (c == int.class) + return Integer.class; + else if (c == long.class) + return Long.class; + else if (c == byte.class) + return Byte.class; + else if (c == char.class) + return Character.class; + else if (c == short.class) + return Short.class; + else if (c == boolean.class) + return Boolean.class; + else if (c == float.class) + return Float.class; + else if (c == double.class) + return Double.class; + else if (c == void.class) + return Void.class; + else + return c; + } + + public static Object convert(Number n, Class c) + { + c = unbox(c); + + if (c == Integer.class) + return n.intValue(); + else if (c == Long.class) + return n.longValue(); + else if (c == Byte.class) + return n.byteValue(); + else if (c == Short.class) + return n.shortValue(); + else if (c == Float.class) + return n.floatValue(); + else if (c == Double.class) + return n.doubleValue(); + + throw new IllegalArgumentException(); + } +}