cache: fix assembler to set correct switch table index
The int operand of switch instructions is an index into the switch table. The operand was always 0, breaking scripts with multiple switches.
This commit is contained in:
@@ -32,6 +32,7 @@ import java.util.Objects;
|
||||
import net.runelite.cache.definitions.ScriptDefinition;
|
||||
import net.runelite.cache.script.Instruction;
|
||||
import net.runelite.cache.script.Instructions;
|
||||
import net.runelite.cache.script.Opcodes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -216,6 +217,8 @@ public class ScriptWriter extends rs2asmBaseListener
|
||||
|
||||
public ScriptDefinition buildScript()
|
||||
{
|
||||
setSwitchOperands();
|
||||
|
||||
ScriptDefinition script = new ScriptDefinition();
|
||||
script.setId(id);
|
||||
script.setIntStackCount(intStackCount);
|
||||
@@ -232,6 +235,20 @@ public class ScriptWriter extends rs2asmBaseListener
|
||||
return script;
|
||||
}
|
||||
|
||||
private void setSwitchOperands()
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < opcodes.size(); ++i)
|
||||
{
|
||||
if (opcodes.get(i) != Opcodes.SWITCH)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
iops.set(i, count++);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Integer, Integer>[] buildSwitches()
|
||||
{
|
||||
int count = (int) switches.stream().filter(Objects::nonNull).count();
|
||||
|
||||
Reference in New Issue
Block a user