From 4f14eebd9dcf49f1b1af5a14fa167eb449b6a419 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 21 May 2017 17:03:21 -0400 Subject: [PATCH] cache: document invoke/return some, add beginning of lvt to interpreter --- .../runelite/cache/script/Instructions.java | 2 +- .../net/runelite/cache/script/Opcodes.java | 2 +- .../cache/script/interpreter/Frame.java | 6 +++ .../interpreter/InstructionHandlers.java | 2 + .../script/interpreter/VariableContext.java | 30 +++++++++++ .../cache/script/interpreter/Variables.java | 42 ++++++++++++++++ .../interpreter/instructions/Invoke.java | 50 +++++++++++++++++++ .../interpreter/instructions/Return.java | 2 + 8 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 cache/src/main/java/net/runelite/cache/script/interpreter/VariableContext.java create mode 100644 cache/src/main/java/net/runelite/cache/script/interpreter/Variables.java create mode 100644 cache/src/main/java/net/runelite/cache/script/interpreter/instructions/Invoke.java diff --git a/cache/src/main/java/net/runelite/cache/script/Instructions.java b/cache/src/main/java/net/runelite/cache/script/Instructions.java index 7ccce47472..7ba72ea27a 100644 --- a/cache/src/main/java/net/runelite/cache/script/Instructions.java +++ b/cache/src/main/java/net/runelite/cache/script/Instructions.java @@ -58,7 +58,7 @@ public class Instructions // 37 - pops strings eq to int operand, pushes 1 string add(Opcodes.POP_INT, "pop_int", 1, 0); add(Opcodes.POP_STRING, "pop_string", 0, 0, 1, 0); - // 40 seems to interact with other scripts, variable pops/pushes + // 40 invoke script, variable pops/pushes add(42, 0, 1); add(43, 1, 0); add(44, 1, 0); diff --git a/cache/src/main/java/net/runelite/cache/script/Opcodes.java b/cache/src/main/java/net/runelite/cache/script/Opcodes.java index b1bd350e2a..f2eeaecf4c 100644 --- a/cache/src/main/java/net/runelite/cache/script/Opcodes.java +++ b/cache/src/main/java/net/runelite/cache/script/Opcodes.java @@ -44,7 +44,7 @@ public class Opcodes public static final int SSTORE = 36; public static final int POP_INT = 38; public static final int POP_STRING = 39; - //public static final int INVOKE = 40; + public static final int INVOKE = 40; public static final int SWITCH = 60; public static final int WIDGET_PUT_HIDDEN = 1003; public static final int WIDGET_PUT_SCROLL = 1100; diff --git a/cache/src/main/java/net/runelite/cache/script/interpreter/Frame.java b/cache/src/main/java/net/runelite/cache/script/interpreter/Frame.java index 6ab8fda798..62d2b2253b 100644 --- a/cache/src/main/java/net/runelite/cache/script/interpreter/Frame.java +++ b/cache/src/main/java/net/runelite/cache/script/interpreter/Frame.java @@ -32,6 +32,8 @@ public class Frame private final ScriptDefinition script; private final Stack intStack; private final Stack stringStack; + private final Variables intVariables; + private final Variables stringVariables; private boolean running = true; int pc; @@ -42,6 +44,8 @@ public class Frame this.script = script; this.intStack = new Stack(); this.stringStack = new Stack(); + this.intVariables = new Variables(script.getLocalIntCount()); + this.stringVariables = new Variables(script.getLocalStringCount()); } public Frame(Interpreter interpreter, Frame other) @@ -50,6 +54,8 @@ public class Frame this.script = other.script; this.intStack = new Stack(other.intStack); this.stringStack = new Stack(other.stringStack); + this.intVariables = new Variables(other.intVariables); + this.stringVariables = new Variables(other.stringVariables); this.pc = other.pc; } diff --git a/cache/src/main/java/net/runelite/cache/script/interpreter/InstructionHandlers.java b/cache/src/main/java/net/runelite/cache/script/interpreter/InstructionHandlers.java index 0c0cab5de3..66182e9d67 100644 --- a/cache/src/main/java/net/runelite/cache/script/interpreter/InstructionHandlers.java +++ b/cache/src/main/java/net/runelite/cache/script/interpreter/InstructionHandlers.java @@ -33,6 +33,7 @@ import net.runelite.cache.script.interpreter.instructions.If_ICmpGT; import net.runelite.cache.script.interpreter.instructions.If_ICmpLE; import net.runelite.cache.script.interpreter.instructions.If_ICmpLT; import net.runelite.cache.script.interpreter.instructions.If_ICmpNE; +import net.runelite.cache.script.interpreter.instructions.Invoke; import net.runelite.cache.script.interpreter.instructions.Jump; import net.runelite.cache.script.interpreter.instructions.LoadInt; import net.runelite.cache.script.interpreter.instructions.Return; @@ -56,6 +57,7 @@ public class InstructionHandlers add(Opcodes.IF_ICMPGT, new If_ICmpGT()); add(Opcodes.IF_ICMPLE, new If_ICmpLE()); add(Opcodes.IF_ICMPGE, new If_ICmpGE()); + add(Opcodes.INVOKE, new Invoke()); add(Opcodes.RETURN, new Return()); } diff --git a/cache/src/main/java/net/runelite/cache/script/interpreter/VariableContext.java b/cache/src/main/java/net/runelite/cache/script/interpreter/VariableContext.java new file mode 100644 index 0000000000..44c05fb14e --- /dev/null +++ b/cache/src/main/java/net/runelite/cache/script/interpreter/VariableContext.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.cache.script.interpreter; + +public class VariableContext +{ + +} diff --git a/cache/src/main/java/net/runelite/cache/script/interpreter/Variables.java b/cache/src/main/java/net/runelite/cache/script/interpreter/Variables.java new file mode 100644 index 0000000000..4bb38ed436 --- /dev/null +++ b/cache/src/main/java/net/runelite/cache/script/interpreter/Variables.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.cache.script.interpreter; + +import java.util.Arrays; + +public class Variables +{ + private final VariableContext[] variables; + + public Variables(int count) + { + variables = new VariableContext[count]; + } + + public Variables(Variables other) + { + variables = Arrays.copyOf(other.variables, other.variables.length); + } +} diff --git a/cache/src/main/java/net/runelite/cache/script/interpreter/instructions/Invoke.java b/cache/src/main/java/net/runelite/cache/script/interpreter/instructions/Invoke.java new file mode 100644 index 0000000000..e32665ee8a --- /dev/null +++ b/cache/src/main/java/net/runelite/cache/script/interpreter/instructions/Invoke.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.cache.script.interpreter.instructions; + +import net.runelite.cache.script.interpreter.Frame; +import net.runelite.cache.script.interpreter.InstructionContext; +import net.runelite.cache.script.interpreter.InstructionHandler; +import net.runelite.cache.script.interpreter.ScriptInstruction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Invoke extends InstructionHandler +{ + private static final Logger logger = LoggerFactory.getLogger(Invoke.class); + + @Override + public void execute(Frame frame, InstructionContext ctx) + { + ScriptInstruction scriptInstruction = ctx.getScriptInstruction(); + + int scriptToInvoke = scriptInstruction.getIop(); + + // copy new script's intStackCount/stringStackCount to the new LVT, and pop from caller's stack + + logger.warn("Invoke not implemented yet"); + } + +} diff --git a/cache/src/main/java/net/runelite/cache/script/interpreter/instructions/Return.java b/cache/src/main/java/net/runelite/cache/script/interpreter/instructions/Return.java index 78a34575a6..a123c4e40f 100644 --- a/cache/src/main/java/net/runelite/cache/script/interpreter/instructions/Return.java +++ b/cache/src/main/java/net/runelite/cache/script/interpreter/instructions/Return.java @@ -34,6 +34,8 @@ public class Return extends InstructionHandler public void execute(Frame frame, InstructionContext ctx) { frame.stop(); + + // restore lvt from calling script. return value is on the stack. } }