From cb2ebc82ebf59bc66401cec7838ed0277b50283e Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Sun, 23 Jun 2024 15:58:25 -0500 Subject: [PATCH] Added JP to pmdsky-debug syncing --- asm/include/itcm.inc | 2 +- asm/include/main_0200C4CC.inc | 4 +-- asm/main_0200C4CC.s | 30 +++++++++---------- .../sync_pmdsky_debug/sync_to_pmdsky_debug.py | 27 ++++++++++------- tools/sync_pmdsky_debug/xmap_reader.py | 2 +- 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/asm/include/itcm.inc b/asm/include/itcm.inc index 2982205e..5bc02410 100644 --- a/asm/include/itcm.inc +++ b/asm/include/itcm.inc @@ -178,4 +178,4 @@ .public TRIG_TABLE .public TryAddTargetToAiTargetList .public UpdateAiTargetPos -.public UpdateWindow \ No newline at end of file +.public UpdateWindow diff --git a/asm/include/main_0200C4CC.inc b/asm/include/main_0200C4CC.inc index 8c88c94f..5d792c8e 100644 --- a/asm/include/main_0200C4CC.inc +++ b/asm/include/main_0200C4CC.inc @@ -978,9 +978,9 @@ .public RemoveActiveMembersFromAllTeams .public RemoveActiveMembersFromRescueTeam .public RemoveActiveMembersFromSpecialEpisodeTeam +.public Render3dStack .public RENDER_3D .public RENDER_3D_FUNCTIONS_64 -.public Render3dStack .public ResumeBgm .public Rgb8ToRgb5 .public SCRIPT_VARS @@ -1175,4 +1175,4 @@ .public WONDER_MAIL_ENCRYPTION_TABLE .public WriteMonsterInfoToSave .public ZINC_STAT_BOOST -.public ZInit8 \ No newline at end of file +.public ZInit8 diff --git a/asm/main_0200C4CC.s b/asm/main_0200C4CC.s index 319ce344..aa260bd8 100644 --- a/asm/main_0200C4CC.s +++ b/asm/main_0200C4CC.s @@ -86739,31 +86739,31 @@ _0204F9B4: .word 0x000042BA arm_func_start sub_0204F9B8 sub_0204F9B8: ; 0x0204F9B8 - ldr ip, _0204F9C4 ; =sub_02050E08 + ldr ip, _0204F9C4 ; =ResetPlayTimer ldr r0, _0204F9C8 ; =_022AB694 bx ip .align 2, 0 -_0204F9C4: .word sub_02050E08 +_0204F9C4: .word ResetPlayTimer _0204F9C8: .word _022AB694 arm_func_end sub_0204F9B8 arm_func_start sub_0204F9CC sub_0204F9CC: ; 0x0204F9CC - ldr ip, _0204F9D8 ; =sub_02050E18 + ldr ip, _0204F9D8 ; =PlayTimerTick ldr r0, _0204F9DC ; =_022AB694 bx ip .align 2, 0 -_0204F9D8: .word sub_02050E18 +_0204F9D8: .word PlayTimerTick _0204F9DC: .word _022AB694 arm_func_end sub_0204F9CC arm_func_start sub_0204F9E0 sub_0204F9E0: ; 0x0204F9E0 - ldr ip, _0204F9EC ; =sub_02050E54 + ldr ip, _0204F9EC ; =GetPlayTimeSeconds ldr r0, _0204F9F0 ; =_022AB694 bx ip .align 2, 0 -_0204F9EC: .word sub_02050E54 +_0204F9EC: .word GetPlayTimeSeconds _0204F9F0: .word _022AB694 arm_func_end sub_0204F9E0 @@ -88501,16 +88501,16 @@ _02050E00: .word _022AB924 _02050E04: .word _022AB918 arm_func_end sub_02050D84 - arm_func_start sub_02050E08 -sub_02050E08: ; 0x02050E08 + arm_func_start ResetPlayTimer +ResetPlayTimer: ; 0x02050E08 mov r1, #0 strb r1, [r0, #4] str r1, [r0] bx lr - arm_func_end sub_02050E08 + arm_func_end ResetPlayTimer - arm_func_start sub_02050E18 -sub_02050E18: ; 0x02050E18 + arm_func_start PlayTimerTick +PlayTimerTick: ; 0x02050E18 ldrb r1, [r0, #4] add r2, r1, #1 and r1, r2, #0xff @@ -88527,13 +88527,13 @@ sub_02050E18: ; 0x02050E18 bx lr .align 2, 0 _02050E50: .word 0x022550FF - arm_func_end sub_02050E18 + arm_func_end PlayTimerTick - arm_func_start sub_02050E54 -sub_02050E54: ; 0x02050E54 + arm_func_start GetPlayTimeSeconds +GetPlayTimeSeconds: ; 0x02050E54 ldr r0, [r0] bx lr - arm_func_end sub_02050E54 + arm_func_end GetPlayTimeSeconds arm_func_start sub_02050E5C sub_02050E5C: ; 0x02050E5C diff --git a/tools/sync_pmdsky_debug/sync_to_pmdsky_debug.py b/tools/sync_pmdsky_debug/sync_to_pmdsky_debug.py index fc2844fa..84b014bb 100644 --- a/tools/sync_pmdsky_debug/sync_to_pmdsky_debug.py +++ b/tools/sync_pmdsky_debug/sync_to_pmdsky_debug.py @@ -1,5 +1,6 @@ import os import re +from collections import defaultdict from dataclasses import dataclass from typing import Any, Dict, List from ruamel.yaml.comments import CommentedMap @@ -46,7 +47,7 @@ class SubsymbolDir: subsymbol_dirs = {} -def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, yaml_manager: YamlManager, pmdsky_debug_section: Dict[int, SymbolDetails]): +def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, section_name: str, yaml_manager: YamlManager, pmdsky_debug_section: Dict[int, SymbolDetails]): if default_symbol_name.match(symbol.name): return @@ -68,8 +69,8 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, yaml_ma address -= WRAM_OFFSET path_prefix = os.path.join(pmdsky_debug_location, SYMBOLS_FOLDER) - if base_symbol_name in symbol_file_paths: - symbol_path = symbol_file_paths[base_symbol_name] + if base_symbol_name in symbol_file_paths[section_name]: + symbol_path = symbol_file_paths[section_name][base_symbol_name] base_symbol_path = symbol_path[len(path_prefix) + 1:] else: if section_name == 'main': @@ -119,7 +120,7 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, yaml_ma old_symbol = pmdsky_debug_section[address] base_old_symbol_names = [get_base_symbol_name(symbol_name) for symbol_name in old_symbol.get_all_names()] base_old_symbol_name = base_old_symbol_names[0] - if base_symbol_name not in base_old_symbol_names: + if base_symbol_name not in base_old_symbol_names and base_symbol_name not in symbol_file_paths[section_name]: print(f'Adding alias for {base_old_symbol_name}: {base_symbol_name}') symbol_array = read_symbol_array(symbol_path, symbol_type_key, yaml_manager) for yaml_symbol in symbol_array: @@ -138,6 +139,8 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, yaml_ma # Add the symbol to the correspond header file. base_symbol_path = base_symbol_path.replace('.yml', '.h') header_path = symbol_path.replace(SYMBOLS_FOLDER, os.path.join('headers', symbol_type_key)).replace('.yml', '.h') + if not os.path.exists(header_path): + return with open(header_path, 'r') as header_file: header_contents = header_file.readlines() @@ -160,9 +163,8 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, yaml_ma current_symbol_address: int | List[int] = symbol_entry['address'][language_key] if isinstance(current_symbol_address, list): current_symbol_address = current_symbol_address[0] - if current_symbol_address > address: + if current_symbol_address > address and insert_index is not None: insert_index = i - break if not matching_symbol_entry: matching_symbol_entry = { 'name': base_symbol_name, @@ -184,8 +186,8 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, yaml_ma symbol_entry_addresses: int | List[int] = symbol_entry_language_addresses[language_key] - # If needed, reorder language addresses within the YAML for consistency with existing pmdsky-debug entries. hex_address = HexCapsInt(address) + # When adding a new EU address, reorder it to the first key in the YAML for consistency with existing pmdsky-debug entries. reorder_languages = language_key == 'EU' and len(symbol_entry_language_addresses) > 1 and not symbol_entry_language_addresses[language_key] if multiple_symbol_suffix.search(symbol.name): if symbol_entry_addresses is None: @@ -193,8 +195,13 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, yaml_ma if reorder_languages: symbol_entry_language_addresses.move_to_end(language_key, last=False) else: + if isinstance(symbol_entry_addresses, HexCapsInt): + print(f'Converting single address into array for {base_symbol_name}.') + symbol_entry_addresses = [symbol_entry_addresses] + symbol_entry_language_addresses[language_key] = symbol_entry_addresses if address not in symbol_entry_addresses: symbol_entry_addresses.append(hex_address) + symbol_entry_addresses.sort() return else: symbol_entry_language_addresses[language_key] = HexCapsInt(hex_address) @@ -272,12 +279,12 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, yaml_ma header_file.writelines(header_contents) # Extract all pmdsky-debug file paths for symbols between all languages. -symbol_file_paths: Dict[str, str] = {} +symbol_file_paths: Dict[str, Dict[str, str]] = defaultdict(dict) for language, pmdsky_debug_language_symbols in pmdsky_debug_symbols.items(): for section_name, pmdsky_debug_section in pmdsky_debug_language_symbols.items(): for address, symbol in pmdsky_debug_section.items(): base_symbol_name = get_base_symbol_name(symbol.name) - symbol_file_paths[base_symbol_name] = symbol.file_path + symbol_file_paths[section_name][base_symbol_name] = symbol.file_path with YamlManager() as yaml_manager: for language, xmap_language_symbols in xmap_symbols.items(): @@ -289,4 +296,4 @@ with YamlManager() as yaml_manager: pmdsky_debug_section = {} for address, symbol in xmap_section.items(): - sync_xmap_symbol(address, symbol, language, yaml_manager, pmdsky_debug_section) + sync_xmap_symbol(address, symbol, language, section_name, yaml_manager, pmdsky_debug_section) diff --git a/tools/sync_pmdsky_debug/xmap_reader.py b/tools/sync_pmdsky_debug/xmap_reader.py index e74da77d..25e3232d 100644 --- a/tools/sync_pmdsky_debug/xmap_reader.py +++ b/tools/sync_pmdsky_debug/xmap_reader.py @@ -22,7 +22,7 @@ Dictionary format: """ def read_xmap_symbols() -> Dict[str, Dict[str, Dict[int, SymbolDetails]]]: xmap_symbols: Dict[str, Dict[str, Dict[int, SymbolDetails]]] = {} - for language in ['us', 'eu']: + for language in ['us', 'eu', 'jp']: xmap_symbols[language] = read_xmap_symbols_for_language(language) return xmap_symbols