Improve client build number matching

The regex captures too much if there's a NEW prior to the NEW client
instruction.

Signed-off-by: Graham <gpe@openrs2.org>
Graham 1 year ago
parent 6412b70343
commit 5b44a4bca6
  1. 18
      archive/src/main/kotlin/org/openrs2/archive/client/ClientImporter.kt

@ -17,6 +17,7 @@ import jakarta.inject.Inject
import jakarta.inject.Singleton
import net.fornwall.jelf.ElfFile
import net.fornwall.jelf.ElfSymbol
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodInsnNode
@ -597,20 +598,21 @@ public class ClientImporter @Inject constructor(
}
}
for (match in NEW_ENGINE_VERSION_MATCHER.match(method)) {
val new = match[0] as TypeInsnNode
if (new.desc != "client") {
continue
}
var betweenNewAndReturn = false
val candidates = mutableListOf<Int>()
for (insn in match) {
for (insn in method.instructions) {
if (insn is TypeInsnNode && insn.desc == "client") {
betweenNewAndReturn = true
} else if (insn.opcode == Opcodes.RETURN) {
break
} else if (betweenNewAndReturn) {
val candidate = insn.intConstant
if (candidate != null && candidate in NEW_ENGINE_BUILDS) {
candidates += candidate
}
}
}
candidates -= NEW_ENGINE_RESOLUTIONS
@ -619,7 +621,6 @@ public class ClientImporter @Inject constructor(
return CacheExporter.Build(version, null)
}
}
}
return null
}
@ -722,7 +723,6 @@ public class ClientImporter @Inject constructor(
private val OLD_ENGINE_VERSION_MATCHER =
InsnMatcher.compile("LDC INVOKESPECIAL (ICONST | BIPUSH | SIPUSH | LDC)")
private val NEW_ENGINE_VERSION_MATCHER = InsnMatcher.compile("NEW .*? RETURN")
private val NEW_ENGINE_RESOLUTIONS = listOf(765, 503, 1024, 768)
private val NEW_ENGINE_BUILDS = 402..916

Loading…
Cancel
Save