1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-22 05:14:47 +00:00
oot/tools/overlayhelpers/GenColliderInit.py
Ethan Roseman d58983494c
Decompiled ovl_En_Ma1 (#83)
* first steps

* some more

* fixing merge

* more progress

* progs

* Decompiled ovl_En_Ma1

* newline

* Pr suggestion

* Fixing some small things

* Update src/overlays/actors/ovl_En_Ma1/z_en_ma1.c

Co-Authored-By: Roman971 <32455037+Roman971@users.noreply.github.com>

* Removing padding

* Fixing script

* Fixing some things

Co-authored-by: Roman971 <32455037+Roman971@users.noreply.github.com>
2020-04-27 01:47:35 -04:00

206 lines
5.6 KiB
Python

#!/usr/bin/env python3
import struct
T_DEFAULT = ''
T_SET3 = '_Set3'
T_ACTOR = '_Actor'
TYPE_ENUM = [
"COLTYPE_UNK0",
"COLTYPE_UNK1",
"COLTYPE_UNK2",
"COLTYPE_UNK3",
"COLTYPE_UNK4",
"COLTYPE_UNK5",
"COLTYPE_UNK6",
"COLTYPE_UNK7",
"COLTYPE_UNK8",
"COLTYPE_METAL_SHIELD",
"COLTYPE_UNK10",
"COLTYPE_WOODEN_SHIELD",
"COLTYPE_UNK12",
"COLTYPE_UNK13" ]
SHAPE_ENUM = [
"COLSHAPE_JNTSPH",
"COLSHAPE_CYLINDER",
"COLSHAPE_TRIS",
"COLSHAPE_QUAD" ]
sf_ColliderInit = ">BBBBBB"
sf_ColliderInit_Set3 = ">BBBBB"
sf_ColliderInit_Actor = ">IBBBB"
sf_ColliderBodyInit = ">B3xIBB2xIBB2xBBB"
sf_JntSph = ">II"
sf_JntSphItem = ">Bx5h"
sf_Cylinder16 = ">6h"
sf_Tris = ">II"
sf_TrisItem = ">9f"
sf_Quad = ">12f"
f_ColliderInit = "{{ {0}, 0x{1:02X}, 0x{2:02X}, 0x{3:02X}, 0x{4:02X}, {5} }}"
f_ColliderInit_Set3 = "{{ {0}, 0x{1:02X}, 0x{2:02X}, 0x{3:02X}, {4} }}"
f_ColliderInit_Actor = "{{ {0}, 0x{1:02X}, 0x{2:02X}, 0x{3:02X}, {4} }}"
f_ColliderBodyInit = "{{ 0x{0:02X}, {{ 0x{1:08X}, 0x{2:02X}, 0x{3:02X} }}, {{ 0x{4:08X}, 0x{5:02X}, 0x{6:02X} }}, 0x{7:02X}, 0x{8:02X}, 0x{9:02X} }}"
f_JntSph = "{{ {0}, D_{1:08X} }}"
f_JntSphItem = "{{ {0}, {{ {{ {1}, {2}, {3} }}, {4} }}, {5} }}"
f_Cylinder16 = "{{ {0}, {1}, {2}, {{ {3}, {4}, {5} }} }}"
f_Tris = "{{ {0}, D_{1:08X} }}"
f_TrisItem = "{{ {{ {0}f, {1}f, {2}f }}, {{ {3}f, {4}f, {5}f }}, {{ {6}f, {7}f, {8}f }} }}"
f_Quad = "{{ {{ {0}f, {1}f, {2}f }}, {{ {3}f, {4}f, {5}f }}, {{ {6}f, {7}f, {8}f }}, {{ {9}f, {10}f, {11}f }} }}"
def GetColliderFormat(type):
if type == T_DEFAULT:
return (sf_ColliderInit, f_ColliderInit)
if type == T_SET3:
return (sf_ColliderInit_Set3, f_ColliderInit_Set3)
if type == T_ACTOR:
return (sf_ColliderInit_Actor, f_ColliderInit_Actor)
return None
def GetColliderStr(data, off, type):
cf = GetColliderFormat(type)
cBase = list(struct.unpack_from(cf[0], data, off))
if type == T_ACTOR:
if cBase[0] == 0:
cBase[0] = 'NULL'
else:
cBase[0] = '0x{0:08X}'.format(cBase[0])
else:
if cBase[0] < 14:
cBase[0] = TYPE_ENUM[cBase[0]]
else:
cBase[0] = '0x{0:02X}'.format(cBase[0])
i = 4
if type == T_DEFAULT:
i = 5
if cBase[i] < 4:
cBase[i] = SHAPE_ENUM[cBase[i]]
else:
cBase[i] = '0x{0:02X}'.format(cBase[i])
return cf[1].format(*cBase);
def GetItems(data, off, count, structf, fmt, size):
result = ''
for i in range(count):
ioff = (i * size)
cBody = struct.unpack_from(sf_ColliderBodyInit, data, off + ioff)
cItem = struct.unpack_from(structf, data, off + 0x18 + ioff)
result += '''
{{
{0},
{1},
}},'''.format(f_ColliderBodyInit.format(*cBody), fmt.format(*cItem))
return result
def GetJntSphItems(data, off, count):
items = GetItems(data, off, count, sf_JntSphItem, f_JntSphItem, 0x0C)
print('''
ColliderJntSphItemInit jntsphItemsInit[{0}] = {{{1}
}};
'''.format(count, items))
def GetJntSph(data, off, type):
sBase = GetColliderStr(data, off, type)
cJntSph = struct.unpack_from(sf_JntSph, data, off + 8)
print('''
ColliderJntSphInit{0} jntsphInit =
{{
{1},
{2},
}};
'''.format(type, sBase, f_JntSph.format(*cJntSph)))
def GetTrisItems(data, off, count):
items = GetItems(data, off, count, sf_TrisItem, f_TrisItem, 0x24)
print('''
ColliderTrisItemInit trisItemsInit[{0}] = {{{1}
}};
'''.format(count, items))
def GetCylinder(data, off, type):
sBase = GetColliderStr(data, off, type)
cBody = struct.unpack_from(sf_ColliderBodyInit, data, off + 0x08)
cCyl16 = struct.unpack_from(sf_Cylinder16, data, off + 0x20)
print('''
ColliderCylinderInit{0} cylinderInit =
{{
{1},
{2},
{3},
}};
'''.format(type, sBase, f_ColliderBodyInit.format(*cBody),f_Cylinder16.format(*cCyl16)))
def GetTris(data, off, type):
sBase = GetColliderStr(data, off, type)
cTris = struct.unpack_from(sf_Tris, data, off + 8)
print('''
ColliderTrisInit{0} trisInit =
{{
{1},
{2},
}};
'''.format(type, sBase, f_Tris.format(*cTris)))
def GetQuad(data, off, type):
sBase = GetColliderStr(data, off, type)
cBody = struct.unpack_from(sf_ColliderBodyInit, data, off + 0x08)
cQuad = struct.unpack_from(sf_Quad, data, off + 0x20)
print(cQuad)
print('''
ColliderQuadInit{0} quadInit =
{{
{1},
{2},
{3},
}};
'''.format(type, sBase, f_ColliderBodyInit.format(*cBody), f_Quad.format(*cQuad)))
TYPE_DICT = {
'ColliderJntSphInit' : (GetJntSph, 'Shape', T_DEFAULT),
'ColliderCylinderInit' : (GetCylinder, 'Shape', T_DEFAULT),
'ColliderTrisInit': (GetTris, 'Shape', T_DEFAULT),
'ColliderQuadInit': (GetQuad, 'Shape', T_DEFAULT),
'ColliderJntSphItemInit' : (GetJntSphItems, 'Item'),
'ColliderTrisItemInit' : (GetTrisItems, 'Item')
}
update = [(k, v[0]) for k,v in TYPE_DICT.items() if v[1] == 'Shape']
for i in update:
for j in (T_SET3, T_ACTOR):
TYPE_DICT[i[0] + j] = (i[1], 'Shape', j)
#ovlName = 'ovl_Obj_Comb'
#address = 0x000780
#inputType = 'ColliderJntSphItemInit'
#ovlName = 'ovl_En_Boom'
#address = 0x0007D0
#inputType = 'ColliderQuadInit'
ovlName = input("Overlay Name (baserom): ")
ovlFile = open("../../baserom/" + ovlName, "rb")
ovlData = bytearray(ovlFile.read())
ovlFile.close()
address = int(input("Address: 0x"), 16)
inputType = input("Type (e.g. ColliderQuadInit): ")
selectedType = TYPE_DICT[inputType]
arg2 = None
if selectedType[1] == 'Shape':
arg2 = selectedType[2]
else:
arg2 = int(input("Number of items: "))
selectedType[0](ovlData, address, arg2)