mirror of
https://github.com/zeldaret/oot.git
synced 2025-07-15 20:35:13 +00:00
Merge branch 'main' into meta_new_assets_2025
This commit is contained in:
commit
7b503e9e8c
673 changed files with 4740 additions and 1898 deletions
|
@ -725,6 +725,8 @@ def disassemble_cutscene(cs_in) -> tuple[int, str]:
|
|||
if total_entries < 0:
|
||||
raise Exception("Could not disassemble cutscene: Number of commands is negative")
|
||||
macros = format_cmd(begin_cutscene_entry[0], [total_entries, cutscene_end_frame])+line_end
|
||||
# iterate total_entries+1 times to also parse the CS_END_OF_SCRIPT command,
|
||||
# which is not included in the count
|
||||
for k in range(0,total_entries+1):
|
||||
cmd_type = cs_in[i]
|
||||
if (cmd_type == 0xFFFFFFFF):
|
||||
|
|
|
@ -170,9 +170,9 @@ def get_file_pointers(
|
|||
|
||||
# For relocations against a global symbol, subtract the addend so that the pointer
|
||||
# is for the start of the symbol. This can help deal with things like STACK_TOP
|
||||
# (where the pointer is past the end of the symbol) or negative addends. If the
|
||||
# relocation is against a section however, it's not useful to subtract the addend,
|
||||
# so we keep it as-is and hope for the best.
|
||||
# (where the pointer is past the end of the symbol) or negative addends. We can't
|
||||
# do this for relocations against a section though, since we need the addend to
|
||||
# distinguish between different static variables.
|
||||
if reloc.name.startswith("."): # section
|
||||
addend = reloc.addend
|
||||
else: # symbol
|
||||
|
@ -446,13 +446,13 @@ def determine_base_bss_ordering(
|
|||
new_symbol = None
|
||||
new_offset = 0
|
||||
for symbol in build_bss_symbols:
|
||||
if (
|
||||
symbol.offset <= build_offset
|
||||
and build_offset < symbol.offset + symbol.size
|
||||
):
|
||||
# To handle one-past-the-end pointers, we check <= instead of < for the symbol end.
|
||||
# This won't work if there is another symbol right after this one, since we'll
|
||||
# attribute this pointer to that symbol instead. This could prevent us from solving
|
||||
# BSS ordering, but often the two symbols are adjacent in the baserom too so it works anyway.
|
||||
if symbol.offset <= build_offset <= symbol.offset + symbol.size:
|
||||
new_symbol = symbol
|
||||
new_offset = base_offset - (build_offset - symbol.offset)
|
||||
break
|
||||
|
||||
if new_symbol is None:
|
||||
if p.addend > 0:
|
||||
|
|
67
tools/patch_data_with_rodata_mdebug.py
Executable file
67
tools/patch_data_with_rodata_mdebug.py
Executable file
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# SPDX-FileCopyrightText: © 2025 ZeldaRET
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
import argparse
|
||||
import struct
|
||||
|
||||
import elftools.elf.elffile
|
||||
|
||||
# Patches mdebug for files linked with data_with_rodata.ld by replacing storage
|
||||
# class stData with stRData, since .data symbols are now in the .rodata section
|
||||
|
||||
SC_MASK = 0x03E00000
|
||||
SC_SHIFT = 21
|
||||
|
||||
|
||||
def read_u32(f, offset):
|
||||
f.seek(offset)
|
||||
return struct.unpack(">I", f.read(4))[0]
|
||||
|
||||
|
||||
def write_u32(f, offset, value):
|
||||
f.seek(offset)
|
||||
f.write(struct.pack(">I", value))
|
||||
|
||||
|
||||
def patch_sc(f, offset):
|
||||
value = read_u32(f, offset)
|
||||
sc = (value & SC_MASK) >> SC_SHIFT
|
||||
if sc == 2: # scData
|
||||
value = (value & ~SC_MASK) | (15 << SC_SHIFT) # scRData
|
||||
write_u32(f, offset, value)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument("file", help="input file")
|
||||
args = parser.parse_args()
|
||||
|
||||
with open(args.file, "r+b") as f:
|
||||
elf = elftools.elf.elffile.ELFFile(f)
|
||||
|
||||
mdebug_offset = 0
|
||||
for section in elf.iter_sections():
|
||||
if section.name == ".mdebug":
|
||||
mdebug_offset = section["sh_offset"]
|
||||
break
|
||||
|
||||
if mdebug_offset == 0:
|
||||
return
|
||||
|
||||
isymMax = read_u32(f, mdebug_offset + 0x20)
|
||||
cbSymOffset = read_u32(f, mdebug_offset + 0x24)
|
||||
iextMax = read_u32(f, mdebug_offset + 0x58)
|
||||
cbExtOffset = read_u32(f, mdebug_offset + 0x5C)
|
||||
|
||||
for i in range(isymMax):
|
||||
patch_sc(f, cbSymOffset + i * 0xC + 0x8)
|
||||
|
||||
for i in range(iextMax):
|
||||
patch_sc(f, cbExtOffset + i * 0x10 + 0xC)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue