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>
master
Graham 8 months ago
parent 6412b70343
commit 5b44a4bca6
  1. 28
      archive/src/main/kotlin/org/openrs2/archive/client/ClientImporter.kt

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

Loading…
Cancel
Save