Include last instruction in expression in getExpression output

Every call site except replaceExpression() appended the last instruction
to the end of the list.

Signed-off-by: Graham <gpe@openrs2.org>
Graham 1 year ago
parent 1083839720
commit 85b1d52a5c
  1. 5
      asm/src/main/kotlin/org/openrs2/asm/InsnListUtils.kt
  2. 3
      deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/remap/StaticFieldUnscrambler.kt
  3. 7
      patcher/src/main/kotlin/org/openrs2/patcher/transform/HighDpiTransformer.kt

@ -16,8 +16,8 @@ public fun getExpression(
var insn: AbstractInsnNode? = last var insn: AbstractInsnNode? = last
do { do {
val (pops, pushes) = insn!!.stackMetadata val (pops, pushes) = insn!!.stackMetadata
expr.add(insn)
if (insn !== last) { if (insn !== last) {
expr.add(insn)
height -= pushes height -= pushes
} }
height += pops height += pops
@ -38,7 +38,7 @@ public fun InsnList.replaceExpression(
filter: (AbstractInsnNode) -> Boolean = ANY_INSN filter: (AbstractInsnNode) -> Boolean = ANY_INSN
): Boolean { ): Boolean {
val expr = getExpression(last, filter) ?: return false val expr = getExpression(last, filter) ?: return false
expr.forEach(this::remove) expr.filter { it !== last }.forEach(this::remove)
this[last] = replacement this[last] = replacement
return true return true
} }
@ -49,7 +49,6 @@ public fun InsnList.deleteExpression(
): Boolean { ): Boolean {
val expr = getExpression(last, filter) ?: return false val expr = getExpression(last, filter) ?: return false
expr.forEach(this::remove) expr.forEach(this::remove)
remove(last)
return true return true
} }

@ -105,8 +105,7 @@ public class StaticFieldUnscrambler(
} }
// TODO(gpe): use a filter here (pure with no *LOADs?) // TODO(gpe): use a filter here (pure with no *LOADs?)
val expr = getExpression(putstatic) ?: continue simpleInitializers[desc] = getExpression(putstatic) ?: continue
simpleInitializers[desc] = expr.plus(putstatic)
} }
return Pair(simpleInitializers, complexInitializers) return Pair(simpleInitializers, complexInitializers)

@ -22,7 +22,6 @@ import org.openrs2.asm.classpath.ClassPath
import org.openrs2.asm.classpath.Library import org.openrs2.asm.classpath.Library
import org.openrs2.asm.getExpression import org.openrs2.asm.getExpression
import org.openrs2.asm.previousReal import org.openrs2.asm.previousReal
import org.openrs2.asm.stackMetadata
import org.openrs2.asm.transform.Transformer import org.openrs2.asm.transform.Transformer
import kotlin.math.max import kotlin.math.max
@ -272,11 +271,7 @@ public class HighDpiTransformer : Transformer() {
var head = invoke.previousReal ?: return false var head = invoke.previousReal ?: return false
while (exprs.size < 4) { while (exprs.size < 4) {
val expr = if (head.stackMetadata.pops == 0) { val expr = getExpression(head) ?: return false
listOf(head)
} else {
getExpression(head)?.plus(head) ?: return false
}
if (invoke.name == "glViewport" && expr.any { it.opcode == Opcodes.IALOAD }) { if (invoke.name == "glViewport" && expr.any { it.opcode == Opcodes.IALOAD }) {
/* /*

Loading…
Cancel
Save