Files
myrzx_bot/tools/VerifySwfPatch.java

57 lines
2.9 KiB
Java

import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.abc.types.traits.TraitClass;
import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter;
import java.io.BufferedInputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
/** A deterministic regression check for the exact methods changed in the SWF. */
public final class VerifySwfPatch {
public static void main(String[] args) throws Exception {
if (args.length != 2 || !List.of("damage", "stats").contains(args[1])) {
throw new IllegalArgumentException("Usage: VerifySwfPatch file.app damage|stats");
}
boolean stats = args[1].equals("stats");
try (var input = new BufferedInputStream(Files.newInputStream(Path.of(args[0])))) {
SWF swf = new SWF(input, false);
for (ScriptPack pack : swf.getAS3Packs()) {
String target = stats ? "net.pixvi.myr.center.TeamCenter" : "net.pixvi.myr.battle.view.BattleMon";
if (!pack.getClassPath().toString().equals(target)) continue;
var abc = pack.abc;
String method = stats ? "getBattleTeamVo" : "beHurt";
int index = abc.findMethodBodyByName(target, method);
if (index < 0) throw new AssertionError(method + " not found");
var body = abc.bodies.get(index);
var trait = abc.getMethodIndexing().findMethodTraits(pack, index).get(0);
var signature = abc.method_info.get(((TraitMethodGetterSetter) trait).method_info);
String code = body.getCode().toASMSource(abc);
require(signature.param_types.length == (stats ? 1 : 13), "method signature changed");
if (stats) {
require(count(code, "multiply") == 16, "expected 16 doubled stats");
require(code.contains("getproperty QName(PackageNamespace(\"\"),\"hp\")")
&& code.contains("setproperty QName(PackageNamespace(\"\"),\"hpMax\")"), "HP not doubled");
} else {
require(code.matches("(?s).*pushbyte 10\\s+multiply.*"), "damage multiplier missing");
require(code.contains("pushint 50000"), "damage cap missing");
require(code.indexOf("onHurt") < code.indexOf("pushint 50000"), "controllers override multiplier");
}
System.out.println("PASS " + args[1] + ": " + target + "." + method
+ ", codeBytes=" + body.getCodeBytes().length);
return;
}
}
throw new AssertionError("target script missing");
}
private static void require(boolean condition, String message) {
if (!condition) throw new AssertionError(message);
}
private static int count(String text, String token) {
return text.split(token, -1).length - 1;
}
}