cache: some work on the interpreter
This commit is contained in:
92
cache/src/main/java/net/runelite/cache/script/interpreter/Frame.java
vendored
Normal file
92
cache/src/main/java/net/runelite/cache/script/interpreter/Frame.java
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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 net.runelite.cache.definitions.ScriptDefinition;
|
||||
|
||||
public class Frame
|
||||
{
|
||||
private final Interpreter interpreter;
|
||||
private final ScriptDefinition script;
|
||||
private final Stack intStack;
|
||||
private final Stack stringStack;
|
||||
|
||||
private boolean running = true;
|
||||
int pc;
|
||||
|
||||
public Frame(Interpreter interpreter, ScriptDefinition script)
|
||||
{
|
||||
this.interpreter = interpreter;
|
||||
this.script = script;
|
||||
this.intStack = new Stack();
|
||||
this.stringStack = new Stack();
|
||||
}
|
||||
|
||||
public Frame(Interpreter interpreter, Frame other)
|
||||
{
|
||||
this.interpreter = interpreter;
|
||||
this.script = other.script;
|
||||
this.intStack = new Stack(other.intStack);
|
||||
this.stringStack = new Stack(other.stringStack);
|
||||
this.pc = other.pc;
|
||||
}
|
||||
|
||||
public Stack getIntStack()
|
||||
{
|
||||
return intStack;
|
||||
}
|
||||
|
||||
public Stack getStringStack()
|
||||
{
|
||||
return stringStack;
|
||||
}
|
||||
|
||||
public ScriptDefinition getScript()
|
||||
{
|
||||
return script;
|
||||
}
|
||||
|
||||
public Frame dup()
|
||||
{
|
||||
Frame frame = new Frame(interpreter, this);
|
||||
interpreter.addFrame(this);
|
||||
return frame;
|
||||
}
|
||||
|
||||
public boolean isRunning()
|
||||
{
|
||||
return running;
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
running = false;
|
||||
}
|
||||
|
||||
public void jump(int offset)
|
||||
{
|
||||
pc += offset + 1;
|
||||
}
|
||||
}
|
||||
80
cache/src/main/java/net/runelite/cache/script/interpreter/GenericInstructionHandler.java
vendored
Normal file
80
cache/src/main/java/net/runelite/cache/script/interpreter/GenericInstructionHandler.java
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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 net.runelite.cache.script.Instruction;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class GenericInstructionHandler extends InstructionHandler
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(GenericInstructionHandler.class);
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame, InstructionContext ctx)
|
||||
{
|
||||
Instruction i = ctx.getScriptInstruction().getInstruction();
|
||||
Stack istack = frame.getIntStack();
|
||||
Stack sstack = frame.getStringStack();
|
||||
|
||||
int ipops = i.getIntStackPops();
|
||||
for (int j = 0; j < ipops; ++j)
|
||||
{
|
||||
StackContext value = istack.pop();
|
||||
ctx.popsInt(value);
|
||||
value.poppedBy(ctx);
|
||||
}
|
||||
|
||||
int spops = i.getStringStackPops();
|
||||
for (int j = 0; j < spops; ++j)
|
||||
{
|
||||
StackContext value = sstack.pop();
|
||||
ctx.popsString(value);
|
||||
value.poppedBy(ctx);
|
||||
}
|
||||
|
||||
int ipushes = i.getIntStackPushes();
|
||||
for (int j = 0; j < ipushes; ++j)
|
||||
{
|
||||
StackContext sctx = new StackContext(ctx, null);
|
||||
istack.push(sctx);
|
||||
ctx.pushesInt(sctx);
|
||||
}
|
||||
|
||||
int spushes = i.getStringStackPushes();
|
||||
for (int j = 0; j < spushes; ++j)
|
||||
{
|
||||
StackContext sctx = new StackContext(ctx, null);
|
||||
sstack.push(sctx);
|
||||
ctx.pushesString(sctx);
|
||||
}
|
||||
|
||||
if (ipushes > 0 || spushes > 0)
|
||||
{
|
||||
logger.debug("Executed instruction {} with {}/{} pushes!", i, ipushes, spushes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
101
cache/src/main/java/net/runelite/cache/script/interpreter/InstructionContext.java
vendored
Normal file
101
cache/src/main/java/net/runelite/cache/script/interpreter/InstructionContext.java
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InstructionContext
|
||||
{
|
||||
private final ScriptInstruction scriptInstruction;
|
||||
|
||||
private final List<StackContext> ipops = new ArrayList<>();
|
||||
private final List<StackContext> spops = new ArrayList<>();
|
||||
private final List<StackContext> ipushes = new ArrayList<>();
|
||||
private final List<StackContext> spushes = new ArrayList<>();
|
||||
|
||||
public InstructionContext(ScriptInstruction scriptInstruction)
|
||||
{
|
||||
this.scriptInstruction = scriptInstruction;
|
||||
}
|
||||
|
||||
public ScriptInstruction getScriptInstruction()
|
||||
{
|
||||
return scriptInstruction;
|
||||
}
|
||||
|
||||
public void popsInt(StackContext... ctx)
|
||||
{
|
||||
for (StackContext s : ctx)
|
||||
{
|
||||
ipops.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
public void popsString(StackContext... ctx)
|
||||
{
|
||||
for (StackContext s : ctx)
|
||||
{
|
||||
spops.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
public void pushesInt(StackContext... ctx)
|
||||
{
|
||||
for (StackContext s : ctx)
|
||||
{
|
||||
ipushes.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
public void pushesString(StackContext... ctx)
|
||||
{
|
||||
for (StackContext s : ctx)
|
||||
{
|
||||
spushes.add(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<StackContext> getIpops()
|
||||
{
|
||||
return ipops;
|
||||
}
|
||||
|
||||
public List<StackContext> getSpops()
|
||||
{
|
||||
return spops;
|
||||
}
|
||||
|
||||
public List<StackContext> getIpushes()
|
||||
{
|
||||
return ipushes;
|
||||
}
|
||||
|
||||
public List<StackContext> getSpushes()
|
||||
{
|
||||
return spushes;
|
||||
}
|
||||
}
|
||||
30
cache/src/main/java/net/runelite/cache/script/interpreter/InstructionHandler.java
vendored
Normal file
30
cache/src/main/java/net/runelite/cache/script/interpreter/InstructionHandler.java
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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 abstract class InstructionHandler
|
||||
{
|
||||
public abstract void execute(Frame frame, InstructionContext ctx);
|
||||
}
|
||||
72
cache/src/main/java/net/runelite/cache/script/interpreter/InstructionHandlers.java
vendored
Normal file
72
cache/src/main/java/net/runelite/cache/script/interpreter/InstructionHandlers.java
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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.HashMap;
|
||||
import java.util.Map;
|
||||
import net.runelite.cache.script.Opcodes;
|
||||
import net.runelite.cache.script.interpreter.instructions.If_ICmpEQ;
|
||||
import net.runelite.cache.script.interpreter.instructions.If_ICmpGE;
|
||||
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.Jump;
|
||||
import net.runelite.cache.script.interpreter.instructions.LoadInt;
|
||||
import net.runelite.cache.script.interpreter.instructions.Return;
|
||||
|
||||
public class InstructionHandlers
|
||||
{
|
||||
private static final Map<Integer, InstructionHandler> handlers = new HashMap<>();
|
||||
|
||||
static
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
private static void init()
|
||||
{
|
||||
add(Opcodes.LOAD_INT, new LoadInt());
|
||||
add(Opcodes.JUMP, new Jump());
|
||||
add(Opcodes.IF_ICMPNE, new If_ICmpNE());
|
||||
add(Opcodes.IF_ICMPEQ, new If_ICmpEQ());
|
||||
add(Opcodes.IF_ICMPLT, new If_ICmpLT());
|
||||
add(Opcodes.IF_ICMPGT, new If_ICmpGT());
|
||||
add(Opcodes.IF_ICMPLE, new If_ICmpLE());
|
||||
add(Opcodes.IF_ICMPGE, new If_ICmpGE());
|
||||
add(Opcodes.RETURN, new Return());
|
||||
}
|
||||
|
||||
private static void add(int opcode, InstructionHandler handler)
|
||||
{
|
||||
assert handlers.containsKey(opcode) == false;
|
||||
handlers.put(opcode, handler);
|
||||
}
|
||||
|
||||
public static InstructionHandler find(int opcode)
|
||||
{
|
||||
return handlers.get(opcode);
|
||||
}
|
||||
}
|
||||
111
cache/src/main/java/net/runelite/cache/script/interpreter/Interpreter.java
vendored
Normal file
111
cache/src/main/java/net/runelite/cache/script/interpreter/Interpreter.java
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
import net.runelite.cache.definitions.ScriptDefinition;
|
||||
import net.runelite.cache.script.Instruction;
|
||||
import net.runelite.cache.script.Instructions;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Interpreter
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Interpreter.class);
|
||||
|
||||
private final Queue<Frame> frames = new ArrayDeque<>();
|
||||
private final GenericInstructionHandler genericInstructionHandler = new GenericInstructionHandler();
|
||||
|
||||
public void run(ScriptDefinition script)
|
||||
{
|
||||
Instructions.init();
|
||||
|
||||
Frame frame = new Frame(this, script);
|
||||
frames.add(frame);
|
||||
|
||||
int count = 0;
|
||||
|
||||
while (!frames.isEmpty())
|
||||
{
|
||||
frame = frames.remove();
|
||||
run(frame);
|
||||
++count;
|
||||
}
|
||||
|
||||
logger.info("Processed {} frames", count);
|
||||
}
|
||||
|
||||
private void run(Frame frame)
|
||||
{
|
||||
ScriptDefinition script = frame.getScript();
|
||||
|
||||
int[] instructions = script.getInstructions();
|
||||
int[] iops = script.getIntOperands();
|
||||
String[] sops = script.getStringOperands();
|
||||
|
||||
while (frame.isRunning())
|
||||
{
|
||||
if (frame.pc >= instructions.length)
|
||||
{
|
||||
throw new RuntimeException("PC went past end of instructions - maybe missing return");
|
||||
}
|
||||
|
||||
int opcode = instructions[frame.pc];
|
||||
int iop = iops[frame.pc];
|
||||
String sop = sops[frame.pc];
|
||||
|
||||
Instruction i = Instructions.find(opcode);
|
||||
if (i == null)
|
||||
{
|
||||
throw new RuntimeException("Unknown instruction " + opcode + " in script at pc " + frame.pc);
|
||||
}
|
||||
|
||||
ScriptInstruction scriptInstruction = new ScriptInstruction(frame.pc, i, iop, sop);
|
||||
InstructionContext ctx = new InstructionContext(scriptInstruction);
|
||||
|
||||
InstructionHandler handler = InstructionHandlers.find(opcode);
|
||||
if (handler == null)
|
||||
{
|
||||
handler = genericInstructionHandler;
|
||||
}
|
||||
|
||||
int old = frame.pc;
|
||||
|
||||
handler.execute(frame, ctx);
|
||||
|
||||
if (old == frame.pc)
|
||||
{
|
||||
// not a jump
|
||||
++frame.pc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addFrame(Frame frame)
|
||||
{
|
||||
frames.add(frame);
|
||||
}
|
||||
}
|
||||
68
cache/src/main/java/net/runelite/cache/script/interpreter/ScriptInstruction.java
vendored
Normal file
68
cache/src/main/java/net/runelite/cache/script/interpreter/ScriptInstruction.java
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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 net.runelite.cache.script.Instruction;
|
||||
|
||||
/**
|
||||
* an instruction in a script
|
||||
*
|
||||
* @author Adam
|
||||
*/
|
||||
public class ScriptInstruction
|
||||
{
|
||||
private final int pc;
|
||||
private final Instruction instruction;
|
||||
private final int iop;
|
||||
private final String sop;
|
||||
|
||||
public ScriptInstruction(int pc, Instruction instruction, int iop, String sop)
|
||||
{
|
||||
this.pc = pc;
|
||||
this.instruction = instruction;
|
||||
this.iop = iop;
|
||||
this.sop = sop;
|
||||
}
|
||||
|
||||
public int getPc()
|
||||
{
|
||||
return pc;
|
||||
}
|
||||
|
||||
public Instruction getInstruction()
|
||||
{
|
||||
return instruction;
|
||||
}
|
||||
|
||||
public int getIop()
|
||||
{
|
||||
return iop;
|
||||
}
|
||||
|
||||
public String getSop()
|
||||
{
|
||||
return sop;
|
||||
}
|
||||
}
|
||||
57
cache/src/main/java/net/runelite/cache/script/interpreter/Stack.java
vendored
Normal file
57
cache/src/main/java/net/runelite/cache/script/interpreter/Stack.java
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Stack
|
||||
{
|
||||
private final List<StackContext> stack = new ArrayList<>();
|
||||
|
||||
public Stack()
|
||||
{
|
||||
}
|
||||
|
||||
public Stack(Stack other)
|
||||
{
|
||||
stack.addAll(other.stack);
|
||||
}
|
||||
|
||||
public void push(StackContext ctx)
|
||||
{
|
||||
stack.add(ctx);
|
||||
}
|
||||
|
||||
public StackContext pop()
|
||||
{
|
||||
if (stack.isEmpty())
|
||||
{
|
||||
throw new RuntimeException("stack underflow");
|
||||
}
|
||||
|
||||
return stack.remove(stack.size() - 1);
|
||||
}
|
||||
}
|
||||
62
cache/src/main/java/net/runelite/cache/script/interpreter/StackContext.java
vendored
Normal file
62
cache/src/main/java/net/runelite/cache/script/interpreter/StackContext.java
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StackContext
|
||||
{
|
||||
private final InstructionContext pushed;
|
||||
private final List<InstructionContext> popped = new ArrayList<>();
|
||||
private final Object value;
|
||||
|
||||
public StackContext(InstructionContext pushed, Object value)
|
||||
{
|
||||
assert value == null || value instanceof String || value instanceof Integer;
|
||||
this.pushed = pushed;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void poppedBy(InstructionContext ctx)
|
||||
{
|
||||
popped.add(ctx);
|
||||
}
|
||||
|
||||
public InstructionContext getPushed()
|
||||
{
|
||||
return pushed;
|
||||
}
|
||||
|
||||
public List<InstructionContext> getPopped()
|
||||
{
|
||||
return popped;
|
||||
}
|
||||
|
||||
public Object getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
49
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/If.java
vendored
Normal file
49
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/If.java
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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.Stack;
|
||||
import net.runelite.cache.script.interpreter.StackContext;
|
||||
|
||||
public abstract class If extends InstructionHandler
|
||||
{
|
||||
@Override
|
||||
public final void execute(Frame frame, InstructionContext ctx)
|
||||
{
|
||||
Stack intStack = frame.getIntStack();
|
||||
int iop = ctx.getScriptInstruction().getIop();
|
||||
|
||||
StackContext sctx1 = intStack.pop();
|
||||
StackContext sctx2 = intStack.pop();
|
||||
|
||||
ctx.popsInt(sctx1, sctx2);
|
||||
|
||||
Frame dup = frame.dup();
|
||||
dup.jump(iop);
|
||||
}
|
||||
}
|
||||
30
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/If_ICmpEQ.java
vendored
Normal file
30
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/If_ICmpEQ.java
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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;
|
||||
|
||||
public class If_ICmpEQ extends If
|
||||
{
|
||||
|
||||
}
|
||||
30
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/If_ICmpGE.java
vendored
Normal file
30
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/If_ICmpGE.java
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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;
|
||||
|
||||
public class If_ICmpGE extends If
|
||||
{
|
||||
|
||||
}
|
||||
30
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/If_ICmpGT.java
vendored
Normal file
30
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/If_ICmpGT.java
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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;
|
||||
|
||||
public class If_ICmpGT extends If
|
||||
{
|
||||
|
||||
}
|
||||
30
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/If_ICmpLE.java
vendored
Normal file
30
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/If_ICmpLE.java
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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;
|
||||
|
||||
public class If_ICmpLE extends If
|
||||
{
|
||||
|
||||
}
|
||||
30
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/If_ICmpLT.java
vendored
Normal file
30
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/If_ICmpLT.java
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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;
|
||||
|
||||
public class If_ICmpLT extends If
|
||||
{
|
||||
|
||||
}
|
||||
30
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/If_ICmpNE.java
vendored
Normal file
30
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/If_ICmpNE.java
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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;
|
||||
|
||||
public class If_ICmpNE extends If
|
||||
{
|
||||
|
||||
}
|
||||
40
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/Jump.java
vendored
Normal file
40
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/Jump.java
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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;
|
||||
|
||||
public class Jump extends InstructionHandler
|
||||
{
|
||||
@Override
|
||||
public void execute(Frame frame, InstructionContext ctx)
|
||||
{
|
||||
int iop = ctx.getScriptInstruction().getIop();
|
||||
frame.jump(iop);
|
||||
}
|
||||
|
||||
}
|
||||
46
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/LoadInt.java
vendored
Normal file
46
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/LoadInt.java
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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.Stack;
|
||||
import net.runelite.cache.script.interpreter.StackContext;
|
||||
|
||||
public class LoadInt extends InstructionHandler
|
||||
{
|
||||
@Override
|
||||
public void execute(Frame frame, InstructionContext ctx)
|
||||
{
|
||||
Stack intStack = frame.getIntStack();
|
||||
int iop = ctx.getScriptInstruction().getIop();
|
||||
|
||||
StackContext sctx = new StackContext(ctx, iop);
|
||||
ctx.pushesInt(sctx);
|
||||
|
||||
intStack.push(sctx);
|
||||
}
|
||||
}
|
||||
39
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/Return.java
vendored
Normal file
39
cache/src/main/java/net/runelite/cache/script/interpreter/instructions/Return.java
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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;
|
||||
|
||||
public class Return extends InstructionHandler
|
||||
{
|
||||
@Override
|
||||
public void execute(Frame frame, InstructionContext ctx)
|
||||
{
|
||||
frame.stop();
|
||||
}
|
||||
|
||||
}
|
||||
49
cache/src/test/java/net/runelite/cache/script/interpreter/InterpreterTest.java
vendored
Normal file
49
cache/src/test/java/net/runelite/cache/script/interpreter/InterpreterTest.java
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import net.runelite.cache.definitions.ScriptDefinition;
|
||||
import net.runelite.cache.script.assembler.Assembler;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class InterpreterTest
|
||||
{
|
||||
@Test
|
||||
public void testRun() throws IOException
|
||||
{
|
||||
InputStream in = InterpreterTest.class.getResourceAsStream("397.rs2asm");
|
||||
Assert.assertNotNull(in);
|
||||
|
||||
Assembler assembler = new Assembler();
|
||||
ScriptDefinition script = assembler.assemble(in);
|
||||
|
||||
Interpreter interpreter = new Interpreter();
|
||||
interpreter.run(script);
|
||||
}
|
||||
|
||||
}
|
||||
50
cache/src/test/resources/net/runelite/cache/script/interpreter/397.rs2asm
vendored
Normal file
50
cache/src/test/resources/net/runelite/cache/script/interpreter/397.rs2asm
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
033
|
||||
load_int 1
|
||||
if_icmpne LABEL4
|
||||
jump LABEL5
|
||||
LABEL4:
|
||||
return
|
||||
LABEL5:
|
||||
load_int 2871
|
||||
load_int 1
|
||||
load_int 0
|
||||
3200
|
||||
033 1
|
||||
load_int 1
|
||||
if_icmpeq LABEL13
|
||||
jump LABEL20
|
||||
LABEL13:
|
||||
025 3985
|
||||
033 2
|
||||
iadd
|
||||
load_int 4
|
||||
modulo
|
||||
027 3985
|
||||
jump LABEL41
|
||||
LABEL20:
|
||||
033 1
|
||||
load_int 2
|
||||
if_icmpeq LABEL24
|
||||
jump LABEL31
|
||||
LABEL24:
|
||||
025 3986
|
||||
033 2
|
||||
iadd
|
||||
load_int 4
|
||||
modulo
|
||||
027 3986
|
||||
jump LABEL41
|
||||
LABEL31:
|
||||
033 1
|
||||
load_int 3
|
||||
if_icmpeq LABEL35
|
||||
jump LABEL41
|
||||
LABEL35:
|
||||
025 3987
|
||||
033 2
|
||||
iadd
|
||||
load_int 4
|
||||
modulo
|
||||
027 3987
|
||||
LABEL41:
|
||||
return
|
||||
Reference in New Issue
Block a user