2023-05-04 11:03:02 +02:00
|
|
|
#!/usr/bin/env python3
|
2022-06-09 15:49:57 +02:00
|
|
|
|
|
|
|
import struct
|
|
|
|
|
2023-07-29 19:03:17 +02:00
|
|
|
|
2022-06-09 15:49:57 +02:00
|
|
|
def read(f):
|
2023-07-29 19:03:17 +02:00
|
|
|
return struct.unpack(">h", f.read(2))[0]
|
|
|
|
|
2022-06-09 15:49:57 +02:00
|
|
|
|
|
|
|
def i2f(x):
|
|
|
|
return round(x * 180 / 32767 * 200) / 200
|
|
|
|
|
2023-07-29 19:03:17 +02:00
|
|
|
|
2022-06-09 15:49:57 +02:00
|
|
|
def parse(f):
|
2023-07-29 19:03:17 +02:00
|
|
|
print("AnimScript script = {")
|
|
|
|
indent = " "
|
2022-06-09 15:49:57 +02:00
|
|
|
while True:
|
|
|
|
op = read(f)
|
|
|
|
if op == 0:
|
2023-07-29 19:03:17 +02:00
|
|
|
print(f"{indent}AS_END,")
|
2022-06-09 15:49:57 +02:00
|
|
|
break
|
|
|
|
if op == 1:
|
2023-07-29 19:03:17 +02:00
|
|
|
print(f"{indent}AS_WAIT, {read(f)},")
|
2022-06-09 15:49:57 +02:00
|
|
|
elif op == 3:
|
|
|
|
indent = indent[:-4]
|
2023-07-29 19:03:17 +02:00
|
|
|
print(f"{indent}AS_END_LOOP,")
|
2022-06-09 15:49:57 +02:00
|
|
|
elif op == 5:
|
2023-07-29 19:03:17 +02:00
|
|
|
print(
|
|
|
|
f"{indent}AS_SET_ROTATION, {read(f)}, AS_F({i2f(read(f))}), AS_F({i2f(read(f))}), AS_F({i2f(read(f))}),"
|
|
|
|
)
|
2022-06-09 15:49:57 +02:00
|
|
|
elif op == 6:
|
2023-07-29 19:03:17 +02:00
|
|
|
print(
|
|
|
|
f"{indent}AS_ADD_ROTATION, {read(f)}, AS_F({i2f(read(f))}), AS_F({i2f(read(f))}), AS_F({i2f(read(f))}),"
|
|
|
|
)
|
2022-06-09 15:49:57 +02:00
|
|
|
elif op == 8:
|
2023-07-29 19:03:17 +02:00
|
|
|
print(f"{indent}AS_SET_POS, {read(f)}, {read(f)}, {read(f)}, {read(f)},")
|
2022-06-09 15:49:57 +02:00
|
|
|
elif op == 10:
|
2023-07-29 19:03:17 +02:00
|
|
|
print(f"{indent}AS_LOOP,")
|
|
|
|
indent += " "
|
2022-06-09 15:49:57 +02:00
|
|
|
elif op == 14:
|
2023-07-29 19:03:17 +02:00
|
|
|
print(f"{indent}AS_SET_FLAGS, {read(f)},")
|
2022-06-09 15:49:57 +02:00
|
|
|
elif op == 15:
|
2023-07-29 19:03:17 +02:00
|
|
|
print(f"{indent}AS_SET_NODE_FLAGS, {read(f)}, {read(f)},")
|
2022-06-09 15:49:57 +02:00
|
|
|
elif op == 16:
|
2023-07-29 19:03:17 +02:00
|
|
|
print(f"{indent}AS_CLEAR_NODE_FLAGS, {read(f)}, {read(f)},")
|
2022-06-09 15:49:57 +02:00
|
|
|
elif op == 17:
|
2023-07-29 19:03:17 +02:00
|
|
|
print(f"{indent}AS_SET_SCALE, {read(f)}, AS_F({i2f(read(f))}), AS_F({i2f(read(f))}), AS_F({i2f(read(f))}),")
|
2022-06-09 15:49:57 +02:00
|
|
|
elif op == 18:
|
2023-07-29 19:03:17 +02:00
|
|
|
print(f"{indent}AS_SET_RENDER_MODE, {read(f)},")
|
2022-06-09 15:49:57 +02:00
|
|
|
elif op == 19:
|
2023-07-29 19:03:17 +02:00
|
|
|
print(f"{indent}AS_OP_19,")
|
2022-06-09 15:49:57 +02:00
|
|
|
else:
|
2023-07-29 19:03:17 +02:00
|
|
|
raise Exception(str(f"Unknown opcode {op}"))
|
|
|
|
print("};")
|
2022-06-09 15:49:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import argparse
|
2023-07-29 19:03:17 +02:00
|
|
|
|
2022-06-09 15:49:57 +02:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("file", type=str, help="File to dissassemble from")
|
|
|
|
parser.add_argument("offset", help="Offset to start dissassembling from")
|
|
|
|
args = parser.parse_args()
|
|
|
|
offset = int(args.offset, 16)
|
|
|
|
with open(args.file, "rb") as f:
|
|
|
|
f.seek(offset)
|
|
|
|
parse(f)
|