"""Reproducibly bundle original, public combat configuration. No account inputs. Run from the repo root: python tools/build_battle_simulation_data.py Only this build tool opens the supplied, hash-checked original APK. Runtime loads a small immutable cache from combat_tables.json.gz instead. """ from __future__ import annotations import argparse import gzip import hashlib import json from pathlib import Path import re import struct import sys import zipfile import zlib ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT)) from tools.research_battle_v12 import recover_table ORIGINAL_APK_SHA256 = "01678ee3a8465d818d32cbbd94baa0d8253b04b4c57b70ebc5544ed341f1015d" TABLES = ("monster_info", "monster_skill", "monster_setting", "game_setting", "team_info", "setting", "potential_info", "entangle_info", "upstar_info", "item_info", "stage_info", "task_info") # HitAction1..10, verified at the sendHit callbacks, not sound/visual timing. ACTION_HIT_MS = {"JUMP_HIT": 200, "Y_SCALE_SHOOT": 100, "HORIZON_HIT": 200, "DOWN_HIT": 200, "NONE": 0, "HORIZON_HIT_DELAY": 0, "HORIZON_HIT_QUICK": 100, "FRONT_HIT": 200, "JUMP_HIT2": 200, "X_SCALE_SHOOT": 200} def compact(value): if isinstance(value, dict): return {str(k): compact(v) for k, v in value.items() if not str(k).startswith("c_")} if isinstance(value, list): return [compact(v) for v in value] return value def attack_profiles(sources): folder = sources / "net/pixvi/myr/view/attack" factory = (folder / "type/AttackType.as").read_text(encoding="utf-8") profiles, fingerprints = {}, {} paths = list(folder.glob("AttackType*.as")) + list((folder / "action").rglob("*.as")) paths += [folder / "type/AttackType.as", folder / "BaseAttack.as"] for path in sorted(paths): fingerprints[path.relative_to(sources).as_posix()] = hashlib.sha256(path.read_bytes()).hexdigest() for key, cls in re.findall(r'case "(\d+)":\s*attack = new (AttackType\d+)\(\);', factory): source = (folder / (cls + ".as")).read_text(encoding="utf-8") action = re.search(r"type_action\s*=\s*HitActionType\.(\w+)", source) speed = re.search(r"spd_bullet\s*=\s*([\d.]+)", source) if not action or action.group(1) not in ACTION_HIT_MS: raise ValueError(f"Unreviewed attack timing: {cls}") profiles[key] = {"source_class": cls, "projectile": bool(re.search(r"shotter\s*=\s*true", source)), "projectile_speed": float(speed.group(1)) if speed else 6, "hit_delay_ms": ACTION_HIT_MS[action.group(1)], "action": action.group(1)} return profiles, fingerprints def build(apk, output, *, sources=None): apk, output = Path(apk), Path(output) source_hash = hashlib.sha256(apk.read_bytes()).hexdigest() if source_hash != ORIGINAL_APK_SHA256: raise ValueError("Expected the unmodified original 1.9.68 APK (SHA-256 mismatch)") data, table_meta = {"schema_version": 1}, {} with zipfile.ZipFile(apk) as archive: swf = archive.read("assets/MYRMain.app") swf_body = zlib.decompress(swf[8:]) if swf[:3] == b"CWS" else swf[8:] rect_bytes = (5 + 4 * (swf_body[0] >> 3) + 7) // 8 fps = struct.unpack_from("