71 lines
3.9 KiB
Java
71 lines
3.9 KiB
Java
import com.jpexs.decompiler.flash.SWF;
|
|
import com.jpexs.decompiler.flash.abc.ABC;
|
|
import com.jpexs.decompiler.flash.abc.ScriptPack;
|
|
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
|
|
import com.jpexs.decompiler.flash.abc.types.MethodBody;
|
|
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
|
|
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
|
|
import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter;
|
|
|
|
import java.io.BufferedInputStream;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
|
|
/** Checks the actual ABC method association instead of relying on name lookup. */
|
|
public final class InspectBattlePatch {
|
|
public static void main(String[] args) throws Exception {
|
|
for (String arg : args) {
|
|
System.out.println("FILE " + arg);
|
|
try (BufferedInputStream in = new BufferedInputStream(Files.newInputStream(Path.of(arg)))) {
|
|
SWF swf = new SWF(in, false);
|
|
for (ScriptPack pack : swf.getAS3Packs()) {
|
|
String name = pack.getClassPath().toString();
|
|
if (!name.equals("net.pixvi.myr.battle.view.BattleMon")
|
|
&& !name.equals("net.pixvi.myr.center.TeamCenter")
|
|
&& !name.equals("net.pixvi.myrloader.MYRLoaderStarter")) {
|
|
continue;
|
|
}
|
|
ABC abc = pack.abc;
|
|
var tag = (com.jpexs.decompiler.flash.tags.DoABC2Tag) abc.parentTag;
|
|
System.out.println("PACK " + name + " tag=" + tag.name
|
|
+ " tagPos=" + tag.getPos() + " bodies=" + abc.bodies.size());
|
|
System.out.println(" originalData=" + tag.getOriginalDataLength()
|
|
+ " modified=" + tag.isModified()
|
|
+ " originalHash=" + java.util.HexFormat.of().formatHex(
|
|
java.security.MessageDigest.getInstance("SHA-256").digest(tag.getOriginalData())));
|
|
AVM2ConstantPool c = abc.constants;
|
|
var methods = new java.util.ArrayList<TraitMethodGetterSetter>();
|
|
for (var instance : abc.instance_info) {
|
|
for (Trait trait : instance.instance_traits.traits) {
|
|
if (trait instanceof TraitMethodGetterSetter tm) methods.add(tm);
|
|
}
|
|
}
|
|
for (var klass : abc.class_info) {
|
|
for (Trait trait : klass.static_traits.traits) {
|
|
if (trait instanceof TraitMethodGetterSetter tm) methods.add(tm);
|
|
}
|
|
}
|
|
for (TraitMethodGetterSetter method : methods) {
|
|
MethodInfo info = abc.method_info.get(method.method_info);
|
|
String methodName = c.getString(info.name_index);
|
|
if (!methodName.equals("beHurt") && !methodName.equals("getBattleTeamVo")
|
|
&& !methodName.equals("fixComplete")) continue;
|
|
int index = abc.findBodyIndex(method.method_info);
|
|
MethodBody body = abc.bodies.get(index);
|
|
String code = body.getCode().toASMSource(abc);
|
|
System.out.println(name + "." + methodName + " method=" + method.method_info
|
|
+ " body=" + index + " codeBytes=" + body.getCodeBytes().length
|
|
+ " stats=" + body.max_stack + "/" + body.max_regs
|
|
+ " multiplies=" + count(code, "multiply")
|
|
+ " cap=" + code.contains("pushint 50000"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static int count(String text, String token) {
|
|
return text.split(token, -1).length - 1;
|
|
}
|
|
}
|