From 85b1d52a5c5183ec9e2b25f61d0038b6c539c75a Mon Sep 17 00:00:00 2001 From: Graham Date: Fri, 20 Oct 2023 21:59:28 +0100 Subject: [PATCH] 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 --- asm/src/main/kotlin/org/openrs2/asm/InsnListUtils.kt | 5 ++--- .../openrs2/deob/bytecode/remap/StaticFieldUnscrambler.kt | 3 +-- .../org/openrs2/patcher/transform/HighDpiTransformer.kt | 7 +------ 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/asm/src/main/kotlin/org/openrs2/asm/InsnListUtils.kt b/asm/src/main/kotlin/org/openrs2/asm/InsnListUtils.kt index da159fa2..6cd8eacb 100644 --- a/asm/src/main/kotlin/org/openrs2/asm/InsnListUtils.kt +++ b/asm/src/main/kotlin/org/openrs2/asm/InsnListUtils.kt @@ -16,8 +16,8 @@ public fun getExpression( var insn: AbstractInsnNode? = last do { val (pops, pushes) = insn!!.stackMetadata + expr.add(insn) if (insn !== last) { - expr.add(insn) height -= pushes } height += pops @@ -38,7 +38,7 @@ public fun InsnList.replaceExpression( filter: (AbstractInsnNode) -> Boolean = ANY_INSN ): Boolean { val expr = getExpression(last, filter) ?: return false - expr.forEach(this::remove) + expr.filter { it !== last }.forEach(this::remove) this[last] = replacement return true } @@ -49,7 +49,6 @@ public fun InsnList.deleteExpression( ): Boolean { val expr = getExpression(last, filter) ?: return false expr.forEach(this::remove) - remove(last) return true } diff --git a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/remap/StaticFieldUnscrambler.kt b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/remap/StaticFieldUnscrambler.kt index 15cbd743..92739f06 100644 --- a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/remap/StaticFieldUnscrambler.kt +++ b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/remap/StaticFieldUnscrambler.kt @@ -105,8 +105,7 @@ public class StaticFieldUnscrambler( } // TODO(gpe): use a filter here (pure with no *LOADs?) - val expr = getExpression(putstatic) ?: continue - simpleInitializers[desc] = expr.plus(putstatic) + simpleInitializers[desc] = getExpression(putstatic) ?: continue } return Pair(simpleInitializers, complexInitializers) diff --git a/patcher/src/main/kotlin/org/openrs2/patcher/transform/HighDpiTransformer.kt b/patcher/src/main/kotlin/org/openrs2/patcher/transform/HighDpiTransformer.kt index 56787e1e..69597eac 100644 --- a/patcher/src/main/kotlin/org/openrs2/patcher/transform/HighDpiTransformer.kt +++ b/patcher/src/main/kotlin/org/openrs2/patcher/transform/HighDpiTransformer.kt @@ -22,7 +22,6 @@ import org.openrs2.asm.classpath.ClassPath import org.openrs2.asm.classpath.Library import org.openrs2.asm.getExpression import org.openrs2.asm.previousReal -import org.openrs2.asm.stackMetadata import org.openrs2.asm.transform.Transformer import kotlin.math.max @@ -272,11 +271,7 @@ public class HighDpiTransformer : Transformer() { var head = invoke.previousReal ?: return false while (exprs.size < 4) { - val expr = if (head.stackMetadata.pops == 0) { - listOf(head) - } else { - getExpression(head)?.plus(head) ?: return false - } + val expr = getExpression(head) ?: return false if (invoke.name == "glViewport" && expr.any { it.opcode == Opcodes.IALOAD }) { /*