1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-25 22:26:12 +00:00

Fix GenColliderInit bugs, add filemap.py for mapping rom/vram addresses (#133)

This commit is contained in:
mzxrules 2020-05-14 15:25:32 -04:00 committed by GitHub
parent 2a7bdc5c28
commit 23ad9cec33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 166 additions and 15 deletions

View file

@ -1,6 +1,8 @@
#!/usr/bin/env python3
import struct
import argparse
from filemap import FileResult, GetFromVRam, GetFromRom
T_DEFAULT = ''
T_SET3 = '_Set3'
@ -43,12 +45,12 @@ 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_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 }} }}"
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:
@ -98,7 +100,7 @@ def GetItems(data, off, count, structf, fmt, size):
return result
def GetJntSphItems(data, off, count):
items = GetItems(data, off, count, sf_JntSphItem, f_JntSphItem, 0x0C)
items = GetItems(data, off, count, sf_JntSphItem, f_JntSphItem, 0x24)
print('''
ColliderJntSphItemInit jntsphItemsInit[{0}] = {{{1}
}};
@ -155,7 +157,6 @@ 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 =
{{
@ -187,19 +188,43 @@ for i in update:
#address = 0x0007D0
#inputType = 'ColliderQuadInit'
ovlName = input("Overlay Name (baserom): ")
ovlFile = open("../../baserom/" + ovlName, "rb")
ovlData = bytearray(ovlFile.read())
ovlFile.close()
#ovlName = input("Overlay Name (baserom): ")
address = int(input("Address: 0x"), 16)
inputType = input("Type (e.g. ColliderQuadInit): ")
def HexParse(s):
return int(s, 16)
selectedType = TYPE_DICT[inputType]
parser = argparse.ArgumentParser()
parser.add_argument('address', help="VRam or Rom address of the struct", type=HexParse)
parser.add_argument('type', help="Type name (e.g. ColliderQuadInit)")
parser.add_argument('num', nargs='?', default=0, type=HexParse, help="Number of elements. Only applies to ItemInit types")
args = parser.parse_args()
fileResult = None
if args.address >= 0x80000000:
fileResult = GetFromVRam(args.address)
else:
fileResult = GetFromRom(args.address)
if fileResult is None:
print("Invalid address")
exit()
print(fileResult)
selectedType = TYPE_DICT[args.type]
arg2 = None
if selectedType[1] == 'Shape':
arg2 = selectedType[2]
elif args.num > 0:
arg2 = args.num
else:
arg2 = int(input("Number of items: "))
print("ItemInit type must specify number of elements")
exit()
selectedType[0](ovlData, address, arg2)
ovlFile = open("../../baserom/" + fileResult.name, "rb")
ovlData = bytearray(ovlFile.read())
ovlFile.close()
selectedType[0](ovlData, fileResult.offset, arg2)

View file

@ -0,0 +1,125 @@
#!/usr/bin/env python3
import struct
import json
table = None
class AddrRange:
def __init__(self, start, end):
self.start = start
self.end = end
def __str__(self):
return "{0:08X}:{1:08X}".format(self.start, self.end)
class FileResult:
def __init__(self, name, vrom, vram, offset):
self.name = name
self.vrom = vrom
self.vram = vram
self.offset = offset
def __str__(self):
return "{0}: Rom {1} VRam {2} Offset {3:06X}".format(self.name, self.vrom, self.vram, self.offset)
def PVA(a):
return a & 0x1FFFFFF
def UVA(a):
#a *= 0x10
a += 0x80000000
return a
def CreateAddrLookup(dict, recs, tracer):
recs = sorted(recs, key= lambda x: x[0])
length = len(recs)
print(length)
recs.append((recs[length-1][1], None, None))
recs = sorted(recs, key=lambda x: x[0], reverse=True)
for i in range(length):
if recs[i][0] != recs[i+1][1]:
if tracer != "ra" or recs[i][0] != recs[i+1][1] + 0xFFF & -0x1000:
print(tracer)
print(recs[i])
print(recs[i+1])
for item in recs:
dict[item[0]] = item[2]
def CreateTable():
vrecs = []
rrecs = []
vrecs.append((PVA(0x80157D90), PVA(0x80800000), None))
dict = {
"va" : {},
"ra" : {},
"ft" : {}
}
with open("filetable.txt", "r") as file:
for line in file:
li = line.rstrip().split('\t')
rrec = (int(li[2],16), int(li[3],16), li[7])
vrec = (PVA(int(li[4],16)), PVA(int(li[5],16)), li[7])
rrecs.append(rrec)
vrecs.append(vrec)
dict["ft"][li[7]] = (rrec[0], rrec[1])
file = None
with open("filetable2.txt", "r") as file:
for line in file:
li = line.rstrip().split('\t')
rrec = (int(li[2],16), int(li[3],16), li[5])
rrecs.append(rrec)
dict["ft"][li[5]] = (rrec[0], rrec[1])
CreateAddrLookup(dict["va"], vrecs, "va")
CreateAddrLookup(dict["ra"], rrecs, "ra")
with open("filetable.json", "w") as table:
json.dump(dict, table)
def AddressLookup(lookupTable, addr):
start = 0;
end = 0;
key = None;
for k, v in lookupTable.items():
if addr >= k:
start = k
key = v
break
end = k
return (key, start, end)
def GetFromVRam(addr):
key, vramStart, vramEnd = AddressLookup(table["va"], PVA(addr))
if key is None:
return None
ftl = table["ft"][key]
vrom = AddrRange(ftl[0], ftl[1])
vram = AddrRange(UVA(vramStart), UVA(vramEnd))
offset = addr - vram.start
return FileResult(key, vrom, vram, offset)
def GetFromRom(addr):
key, romStart, romEnd = AddressLookup(table["ra"], addr)
if key is None:
return None
vrom = AddrRange(romStart, romEnd)
offset = addr - vrom.start
return FileResult(key, vrom, None, offset)
#CreateTable()
with open("filetable.json", "r") as table:
table = json.load(table)
table["va"] = {int(k):v for k,v in table["va"].items()}
table["ra"] = {int(k):v for k,v in table["ra"].items()}

File diff suppressed because one or more lines are too long