1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-07-03 06:24:30 +00:00

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>
This commit is contained in:
Ethan Roseman 2020-04-27 01:47:35 -04:00 committed by GitHub
parent e126e37084
commit d58983494c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 585 additions and 1379 deletions

View file

@ -10,121 +10,6 @@ root_dir = script_dir + "/../"
data_dir = root_dir + "data/"
asm_dir = root_dir + "asm/"
floats = {}
floats["0x3F800000"] = "1.0"
floats["0x46EC7A00"] = "30269.0"
floats["0x46ECC600"] = "30307.0"
floats["0x46ECE600"] = "30323.0"
floats["0x3B23D70A"] = "0.0025"
floats["0x3D4CCCCD"] = "0.05"
floats["0x3DCCCCCD"] = "0.1"
floats["0x451C4000"] = "2500.0"
floats["0x453B8000"] = "3000.0"
floats["0x44BB8000"] = "1500.0"
floats["0x3FCCCCCD"] = "1.6"
floats["0x3E99999A"] = "0.3"
floats["0x40C90FDB"] = "6.28318548203"
floats["0x3DA3D70A"] = "0.08"
floats["0x3F333333"] = "0.7"
floats["0x3F19999A"] = "0.6"
floats["0x40133333"] = "2.3"
floats["0x40933333"] = "4.6"
floats["0x44758000"] = "982.0"
floats["0x409FFFEB"] = "4.99998998642"
floats["0x40FFFFEB"] = "7.99998998642"
floats["0x3F3AE148"] = "0.73"
floats["0x3A83126F"] = "0.001"
floats["0x494EA400"] = "846400.0"
floats["0x3DE147AE"] = "0.11"
floats["0x3C23D70B"] = "0.0100000007078"
floats["0x3E16872B"] = "0.147"
floats["0x3B03126F"] = "0.002"
floats["0x40490FDB"] = "3.14159274101"
floats["0xC49C4000"] = "-1250.0"
floats["0x3FC90FDB"] = "1.57079637051"
floats["0x44278000"] = "670.0"
floats["0x3CA3D70A"] = "0.02"
floats["0x3F7851EC"] = "0.97"
floats["0x3E999999"] = "0.299999982119"
floats["0x3E4CCCCD"] = "0.2"
floats["0x3B83126E"] = "0.00399999972433"
floats["0x3F59999A"] = "0.85"
floats["0x38C90FDB"] = "9.58738019108e-05"
floats["0x3D23D70A"] = "0.04"
floats["0xC4548000"] = "-850.0"
floats["0x45034000"] = "2100.0"
floats["0xBC23D70A"] = "-0.01"
floats["0x3C23D70A"] = "0.01"
floats["0x3CCCCCCD"] = "0.025"
floats["0xBCF5C28F"] = "-0.03"
floats["0x3FE1307A"] = "1.75929188728"
floats["0x3FA4DEEC"] = "1.28805303574"
floats["0xBF20D97B"] = "-0.628318488598"
floats["0x3EF1463A"] = "0.471238911152"
floats["0x3F333334"] = "0.700000047684"
floats["0x407FEF9E"] = "3.99900007248"
floats["0x3FF33333"] = "1.9"
floats["0x3F666666"] = "0.9"
floats["0x44A8C000"] = "1350.0"
floats["0x44898000"] = "1100.0"
floats["0x40C8F5C3"] = "6.28"
floats["0x48742400"] = "250000.0"
floats["0xBF060A92"] = "-0.523598790169"
floats["0x3C888889"] = "0.0166666675359"
floats["0x3F4CCCCD"] = "0.8"
floats["0x3FFFDF3B"] = "1.99899995327"
floats["0x3A031270"] = "0.000500000081956"
floats["0x3F99999A"] = "1.2"
floats["0x471C4000"] = "40000.0"
floats["0x45992000"] = "4900.0"
floats["0x461C4000"] = "10000.0"
floats["0x3E19999A"] = "0.15"
floats["0x448FC000"] = "1150.0"
floats["0x3727C5AC"] = "9.99999974738e-06"
floats["0x358637BD"] = "9.99999997475e-07"
floats["0xBF99999A"] = "-1.2"
floats["0x3F8CCCCD"] = "1.1"
floats["0x40066666"] = "2.1"
floats["0x3ECCCCCD"] = "0.4"
floats["0x44A28000"] = "1300.0"
floats["0x3CF5C28F"] = "0.03"
floats["0x43A6AAAB"] = "333.333343506"
floats["0x3BA3D70A"] = "0.005"
floats["0x3C03126F"] = "0.008"
floats["0x459C4000"] = "5000.0"
floats["0x3FAAAAA8"] = "1.33333301544"
floats["0x3FD9999A"] = "1.7"
floats["0x45DAC000"] = "7000.0"
floats["0x4016CBE4"] = "2.35619449615"
floats["0x49095440"] = "562500.0"
floats["0x45BB8000"] = "6000.0"
floats["0x3FB33333"] = "1.4"
floats["0x3C134ACB"] = "0.00899"
floats["0x458CA000"] = "4500.0"
floats["0x3FA66666"] = "1.3"
floats["0xBF4CCCCD"] = "-0.8"
floats["0xBF666666"] = "-0.9"
floats["0xBF59999A"] = "-0.85"
floats["0x3FFEB852"] = "1.99000000954"
floats["0x404CCCCD"] = "3.2"
floats["0xBB449BA6"] = "-0.003"
floats["0x3D99999A"] = "0.075"
floats["0x3D0F5C29"] = "0.035"
floats["0xBFC90FDB"] = "-1.57079637051"
floats["0xB8D1B717"] = "-9.99999974738e-05"
floats["0x3B59E83E"] = "0.003325"
floats["0x3B9BA5E3"] = "0.00475"
floats["0x3AC49BA6"] = "0.0015"
floats["0x3CA3D70B"] = "0.0200000014156"
floats["0x4316199A"] = "150.1"
floats["0x3FD5DCA8"] = "1.67079639435"
floats["0xB8C90FDB"] = "-9.58738019108e-05"
floats["0x3B6BEDFA"] = "0.0036"
floats["0x3DF5C28F"] = "0.12"
floats["0x3B30F27C"] = "0.0027"
floats["0xC3E28000"] = "-453.0"
floats["0xC4DC2000"] = "-1761.0"
floats["0x449FC000"] = "1278.0"
def try_text(text_bytes):
bad_bytes = 0
for byte in text_bytes:
@ -156,8 +41,6 @@ def is_zeros(stuff):
def try_float(word):
if (word in floats):
return floats[word]
if (word[:3] == "0x3") or (word[:3] == "0x4") or \
(word[:3] == "0xB") or (word[:3] == "0xC"):
return struct.unpack('!f', bytes.fromhex(word[2:10]))[0]

View file

@ -0,0 +1,129 @@
#!/usr/bin/python3
import os
import sys
import subprocess
import re
import shlex
from disassemble import get_z_name
script_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = script_dir + "/../"
build_dir = root_dir + "build/"
src_dir = root_dir + "src/"
def find_build_command_line(c_file):
rel_c_file = os.path.relpath(c_file, root_dir)
make_cmd = ["make", "--always-make", "--dry-run", "--debug=j", "PERMUTER=1"]
debug_output = (
subprocess.check_output(make_cmd, cwd=root_dir).decode("utf-8").split("\n")
)
output = []
for line in debug_output:
while "//" in line:
line = line.replace("//", "/")
while "/./" in line:
line = line.replace("/./", "/")
if rel_c_file not in line:
continue
parts = shlex.split(line)
if rel_c_file not in parts:
continue
if "-o" not in parts:
continue
if "-fsyntax-only" in parts:
continue
output.append(line)
if len(output) > 1:
output_lines = "\n".join(output)
print(
f"Error: found multiple compile commands for {rel_c_file}:\n{output_lines}\n"
"Please modify the makefile such that if PERMUTER = 1, "
"only a single compile command is included.",
file=sys.stderr,
)
sys.exit(1)
return output[0]
def import_c_file(compiler, in_file):
in_file = os.path.relpath(in_file, root_dir)
include_next = 0
cpp_command = ["cpp", "-P"]
compiler_split = compiler.split(" ")
for arg in compiler_split:
if include_next > 0:
include_next -= 1
cpp_command.append(arg)
continue
if arg in ["-D", "-U", "-I"]:
cpp_command.append(arg)
include_next = 1
continue
if (
arg.startswith("-D")
or arg.startswith("-U")
or arg.startswith("-I")
or arg in ["-nostdinc"]
):
cpp_command.append(arg)
cpp_command.extend(
[
"-undef",
"-D__sgi",
"-D_LANGUAGE_C",
"-DNON_MATCHING",
"-D_Static_assert(x, y)=",
"-D__attribute__(x)=",
]
)
cpp_command.append(in_file)
try:
return subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8")
except subprocess.CalledProcessError:
print(
"Failed to preprocess input file, when running command:\n"
+ cpp_command,
file=sys.stderr,
)
sys.exit(1)
def get_c_dir(dirname):
for root, dirs, files in os.walk(src_dir):
for dir in dirs:
if dir == dirname:
return os.path.join(root, dir)
def get_c_file(dir):
for root, dirs, files in os.walk(dir):
for file in files:
if file.endswith(".c") and "data" not in file:
return file
def main():
target_script = sys.argv[1]
this_dir = os.getcwd().split("/")[-1]
c_dir_path = get_c_dir(this_dir)
c_file = get_c_file(c_dir_path)
c_file_path = os.path.join(c_dir_path, c_file)
compiler = find_build_command_line(c_file_path)
output = import_c_file(compiler, c_file_path)
with open(os.path.join(build_dir, "ctx.c"), "w") as f:
f.write(output)
if __name__ == "__main__":
main()

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import struct
T_DEFAULT = ''
@ -8,7 +10,7 @@ TYPE_ENUM = [
"COLTYPE_UNK0",
"COLTYPE_UNK1",
"COLTYPE_UNK2",
"COLTYPE_UNK3",
"COLTYPE_UNK3",
"COLTYPE_UNK4",
"COLTYPE_UNK5",
"COLTYPE_UNK6",
@ -17,14 +19,14 @@ TYPE_ENUM = [
"COLTYPE_METAL_SHIELD",
"COLTYPE_UNK10",
"COLTYPE_WOODEN_SHIELD",
"COLTYPE_UNK12",
"COLTYPE_UNK12",
"COLTYPE_UNK13" ]
SHAPE_ENUM = [
SHAPE_ENUM = [
"COLSHAPE_JNTSPH",
"COLSHAPE_CYLINDER",
"COLSHAPE_TRIS",
"COLSHAPE_QUAD" ]
"COLSHAPE_QUAD" ]
sf_ColliderInit = ">BBBBBB"
sf_ColliderInit_Set3 = ">BBBBB"
@ -40,7 +42,7 @@ 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_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} }} }}"
@ -56,7 +58,7 @@ def GetColliderFormat(type):
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))
@ -70,16 +72,16 @@ def GetColliderStr(data, off, type):
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):
@ -94,7 +96,7 @@ def GetItems(data, off, count, structf, fmt, size):
{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('''
@ -105,7 +107,7 @@ ColliderJntSphItemInit jntsphItemsInit[{0}] = {{{1}
def GetJntSph(data, off, type):
sBase = GetColliderStr(data, off, type)
cJntSph = struct.unpack_from(sf_JntSph, data, off + 8)
print('''
ColliderJntSphInit{0} jntsphInit =
{{
@ -121,13 +123,13 @@ def GetTrisItems(data, off, count):
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 =
{{
@ -136,11 +138,11 @@ ColliderCylinderInit{0} cylinderInit =
{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 =
{{
@ -164,8 +166,8 @@ ColliderQuadInit{0} quadInit =
'''.format(type, sBase, f_ColliderBodyInit.format(*cBody), f_Quad.format(*cQuad)))
TYPE_DICT = {
'ColliderJntSphInit' : (GetCylinder, 'Shape', T_DEFAULT),
'ColliderCylinderInit' : (GetJntSph, 'Shape', T_DEFAULT),
'ColliderJntSphInit' : (GetJntSph, 'Shape', T_DEFAULT),
'ColliderCylinderInit' : (GetCylinder, 'Shape', T_DEFAULT),
'ColliderTrisInit': (GetTris, 'Shape', T_DEFAULT),
'ColliderQuadInit': (GetQuad, 'Shape', T_DEFAULT),
'ColliderJntSphItemInit' : (GetJntSphItems, 'Item'),