-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_act_format.py
86 lines (72 loc) · 2.31 KB
/
generate_act_format.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import re
import click
# Convert opcodes to the ACT expected format
desired_names = {
"StatusEffectList": None,
"StatusEffectList2": None,
"StatusEffectList3": None,
"BossStatusEffectList": None,
"Effect": "Ability1",
"AoeEffect8": "Ability8",
"AoeEffect16": "Ability16",
"AoeEffect24": "Ability24",
"AoeEffect32": "Ability32",
"ActorCast": None,
"EffectResult": None,
"EffectResultBasic": None,
"ActorControl": None,
"ActorControlSelf": None,
"ActorControlTarget": None,
"UpdateHpMpTp": None,
"PlayerSpawn": None,
"NpcSpawn": None,
"NpcSpawn2": None,
"ActorMove": None,
"ActorSetPos": None,
"ActorGauge": None,
"PlaceFieldMarkerPreset": "PresetWaymark",
"PlaceFieldMarker": "Waymark",
"SystemLogMessage": None,
}
def write_act_format(opcodes_lines):
output_lines = []
opcode_mapping = dict()
for line in opcodes_lines:
match_groups = re.findall(r"^\s*([^\/].*)=\s*(.*),\s*\/\/.*$", line)
if len(match_groups) != 1:
continue
opcode_name = match_groups[0][0].strip()
opcode_val = match_groups[0][1]
if opcode_val == "UNKNOWN":
opcodes = []
elif " or " in opcode_val:
opcodes = [int(v, 16) for v in opcode_val.split(" or ")]
else:
opcodes = [int(opcode_val, 16)]
opcode_mapping[opcode_name] = opcodes
for name, desired in desired_names.items():
if desired == None:
desired = name
opcodes = opcode_mapping[name]
if len(opcodes) == 1:
output_lines.append(f"{desired}|{opcodes[0]:x}")
elif len(opcodes) > 1:
output_lines.append(f'{desired}|{[f"{opcode:x}" for opcode in opcodes]}')
else:
output_lines.append(f"{desired}|???")
return output_lines
@click.command()
@click.argument("opcodes_file", type=click.File("r"))
def generate_act_format(opcodes_file):
"""
Parses an OPCODES_FILE and outputs opcodes in a format expected by ACT.
This is also just a bunch of regexes slapped together.
Outputs to stdout.
Example:
python generate_act_format.py Ipcs.h
"""
lines = write_act_format(opcodes_file.readlines())
for line in lines:
print(line)
if __name__ == "__main__":
generate_act_format()