summaryrefslogtreecommitdiff
path: root/tools/overlayhelpers/colchkinfoinit.py
blob: fb14a204a858e2e5ab3af060ce436b9f1f0bc806 (plain)
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
#!/usr/bin/env python3

import struct
import argparse
from actor_symbols import resolve_symbol

def HexParse(s):
    return int(s, 16)


def NameMass(info):
    if info[-1] == 0xFE:
        info[-1] = "MASS_HEAVY"
    else:
        if info[-1] == 0xFF:
            info[-1] = "MASS_IMMOVABLE"

def main():
    parser = argparse.ArgumentParser(description='Decompiles a ColChkInfoInit')
    parser.add_argument('address', help='VRAM or VROM address of a ColChkInfoInit', type=HexParse)
    parser.add_argument('type', help="Type: ColChkInfoInit or ColChkInfoInit2", choices=['ColChkInfoInit', 'ColChkInfoInit2'])
    args = parser.parse_args()

    file_path, file_offset = resolve_symbol(args.address)

    with open(file_path, 'rb') as f:
        filedata = f.read()

    if args.type == "ColChkInfoInit":
        info = list(struct.unpack(">Bx2hB", filedata[file_offset:file_offset+7]))
        NameMass(info)
        output="// sColChkInfoInit\nstatic CollisionCheckInfoInit D_{0:08X} = {{ ".format(args.address) + ", ".join(map(str,info)) + "};"
    else:
        info = list(struct.unpack(">Bx3hB", filedata[file_offset:file_offset+9]))
        NameMass(info)
        output="// sColChkInfoInit\nstatic CollisionCheckInfoInit2 D_{0:08X} = {{ ".format(args.address) + ", ".join(map(str,info)) + "};"

    print(output)

if __name__ == "__main__":
    main()