Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed pmdsky-debug sync adding to out-of-range subsymbol dirs #84

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions tools/sync_pmdsky_debug/sync_to_pmdsky_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def find_symbol_in_header(symbol_name: str, is_data: bool, header_contents: List
class SubsymbolDir:
file_path: str
addresses: Dict[str, int]
length: Dict[str, int]

subsymbol_dirs = {}

Expand Down Expand Up @@ -99,12 +100,13 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, section
file_path = os.path.join(root, file)
with open(file_path, 'r') as yaml_file:
yaml_contents = yaml.load(yaml_file)
subsymbol_dirs[subsymbol_dir].append(SubsymbolDir(file_path, yaml_contents[file[:-4]]['address']))
subsymbol_dirs[subsymbol_dir].append(SubsymbolDir(file_path, yaml_contents[file[:-4]]['address'], yaml_contents[file[:-4]]['length']))

if subsymbol_dirs[subsymbol_dir] is not None:
matching_subsymbol_file = None
for file in subsymbol_dirs[subsymbol_dir]:
if address > file.addresses[language_key] and (matching_subsymbol_file is None or file.addresses[language_key] > matching_subsymbol_file.addresses[language_key]):
file_address = file.addresses[language_key]
if address > file_address and address < file_address + file.length[language_key] and (matching_subsymbol_file is None or file_address > matching_subsymbol_file.addresses[language_key]):
matching_subsymbol_file = file
if matching_subsymbol_file is not None:
symbol_path = matching_subsymbol_file.file_path
Expand Down Expand Up @@ -158,7 +160,7 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, section
# This will be used as an anchor when appending to the header file.
symbol_header_line = find_symbol_in_header(symbol_entry['name'], symbol.is_data, header_contents)
if symbol_header_line is not None and insert_index is None:
target_header_line = symbol_header_line
target_header_line = symbol_header_line - 1
if language_key in symbol_entry['address']:
current_symbol_address: int | List[int] = symbol_entry['address'][language_key]
if isinstance(current_symbol_address, list):
Expand All @@ -175,10 +177,6 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, section
else:
symbol_array.insert(insert_index, matching_symbol_entry)

if symbol_preexisting:
print(f'Updating address of {base_symbol_name} in {base_symbol_path}')
else:
print(f'Adding {base_symbol_name} to {base_symbol_path}')

symbol_entry_language_addresses: Dict[str, Any] = matching_symbol_entry['address']
if language_key not in symbol_entry_language_addresses:
Expand Down Expand Up @@ -213,6 +211,11 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, section
if reorder_languages:
symbol_entry_language_addresses.move_to_end('NA-WRAM')

if symbol_preexisting:
print(f'Updating address of {base_symbol_name} (region {language_key}) in {symbol_path}')
else:
print(f'Adding {base_symbol_name} (region {language_key}) to {symbol_path}')

if symbol_preexisting:
return

Expand Down Expand Up @@ -275,6 +278,8 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, section

header_contents[target_header_line] += symbol_header

print(f'Adding {base_symbol_name} to {header_path}')

with open(header_path, 'w') as header_file:
header_file.writelines(header_contents)

Expand Down