2023-05-04 11:03:02 +02:00
|
|
|
#!/usr/bin/env python3
|
2021-08-18 18:28:32 +02:00
|
|
|
|
|
|
|
import struct
|
2022-01-02 13:10:49 +01:00
|
|
|
import argparse
|
2021-08-18 18:28:32 +02:00
|
|
|
|
2023-07-29 19:03:17 +02:00
|
|
|
|
2021-08-18 18:28:32 +02:00
|
|
|
def fmt_size(val):
|
|
|
|
if val == 0:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_8x8"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 1:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_16x16"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 2:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_24x24"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 3:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_32x32"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 4:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_48x48"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 5:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_64x64"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 6:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_8x16"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 7:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_16x8"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 8:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_16x24"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 9:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_16x32"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 10:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_64x32"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 11:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_32x16"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 12:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_12x12"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 13:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_48x24"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 14:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_32x8"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 15:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_24x8"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 16:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_64x16"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 17:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_16x64"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 18:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_192x32"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 19:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_40x40"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 20:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_24x16"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 21:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_32x40"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 22:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_40x16"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 23:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_40x24"
|
2021-08-18 18:28:32 +02:00
|
|
|
elif val == 24:
|
2023-07-29 19:03:17 +02:00
|
|
|
return "HUD_ELEMENT_SIZE_32x24"
|
2021-08-18 18:28:32 +02:00
|
|
|
else:
|
|
|
|
return val
|
|
|
|
|
2022-01-02 13:10:49 +01:00
|
|
|
|
2023-07-29 19:03:17 +02:00
|
|
|
class HudElementScript:
|
2021-08-18 18:28:32 +02:00
|
|
|
def __init__(self, symbol):
|
|
|
|
self.symbol = symbol
|
|
|
|
self.buffer = []
|
|
|
|
|
|
|
|
def feed(self, word):
|
|
|
|
self.buffer.append(word)
|
|
|
|
|
|
|
|
def print(self):
|
|
|
|
buf = iter(self.buffer)
|
|
|
|
indent = " "
|
|
|
|
op = 99
|
|
|
|
|
2022-01-16 14:28:09 +01:00
|
|
|
print(f"HudScript {self.symbol} = {{")
|
2021-08-18 18:28:32 +02:00
|
|
|
|
|
|
|
while op:
|
|
|
|
op = next(buf, -1)
|
|
|
|
if op == -1:
|
|
|
|
break
|
|
|
|
|
|
|
|
if op == 0x00:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_End")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x01:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_SetRGBA({next(buf)}, {next(buf)}, {next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x02:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_SetCI({next(buf)}, {next(buf)}, {next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x03:
|
|
|
|
indent = indent[4:]
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_Restart")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x04:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_Loop")
|
2021-08-18 18:28:32 +02:00
|
|
|
indent = indent + " "
|
|
|
|
elif op == 0x05:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_SetTileSize({fmt_size(next(buf))})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x06:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_SetSizesAutoScale({fmt_size(next(buf))}, {fmt_size(next(buf))})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x07:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_SetSizesFixedScale({fmt_size(next(buf))}, {fmt_size(next(buf))})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x08:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_SetVisible")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x09:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_SetHidden")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x0A:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_AddTexelOffsetX({next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x0B:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_AddTexelOffsetY({next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x0C:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_SetTexelOffset({next(buf)}, {next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x0D:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_SetIcon({next(buf)}, {next(buf)}, {next(buf)}, {next(buf)}, {next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x0E:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_SetScale({next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x0F:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_SetAlpha({next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x10:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_RandomDelay({next(buf)}, {next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x11:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_Delete")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x12:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_UseIA8")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x13:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_SetCustomSize({next(buf)}, {next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x14:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_RandomRestart({next(buf)}, {next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x15:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_op_15({next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x17:
|
|
|
|
count = next(buf)
|
|
|
|
args = []
|
|
|
|
for i in range(count):
|
|
|
|
args.append(next(buf))
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_RandomBranch({', '.join(args)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x18:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_SetFlags({next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x19:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_ClearFlags({next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x1A:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_PlaySound({next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
elif op == 0x1B:
|
2022-05-21 06:56:54 +02:00
|
|
|
print(f"{indent}hs_SetPivot({next(buf)})")
|
2021-08-18 18:28:32 +02:00
|
|
|
else:
|
|
|
|
print(f"{indent}{op},")
|
|
|
|
|
|
|
|
print("};\n")
|
|
|
|
|
|
|
|
|
2022-01-02 13:10:49 +01:00
|
|
|
if __name__ == "__main__":
|
2021-08-18 18:28:32 +02:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("file", type=str, help=".data.s file to dissassemble")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
with open(args.file, "r") as f:
|
|
|
|
lines = f.readlines()
|
|
|
|
current_script = None
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
line = line.strip()
|
|
|
|
|
|
|
|
if line.startswith("glabel"):
|
|
|
|
if current_script:
|
|
|
|
current_script.print()
|
|
|
|
|
|
|
|
current_script = HudElementScript(line.split(" ")[1])
|
|
|
|
elif line.startswith(".word"):
|
|
|
|
words = line[6:].split(", ")
|
|
|
|
|
|
|
|
for word in words:
|
|
|
|
try:
|
|
|
|
word = int(word, base=0)
|
|
|
|
|
|
|
|
if word > 0x8000000:
|
|
|
|
word = f"0x{word:X}"
|
|
|
|
else:
|
2023-07-29 19:03:17 +02:00
|
|
|
(word,) = struct.unpack(">i", struct.pack(">I", word))
|
2021-08-18 18:28:32 +02:00
|
|
|
print(word)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
current_script.feed(word)
|
|
|
|
|
|
|
|
if current_script:
|
|
|
|
current_script.print()
|