Skip to content

Commit

Permalink
Fixed some incorrect symbol names
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonymousRandomPerson committed Nov 22, 2023
1 parent 6493241 commit 3a591b0
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 73 deletions.
2 changes: 1 addition & 1 deletion asm/include/overlay_11.inc
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,12 @@
.public sub_02017AB0
.public sub_02017ACC
.public sub_02017B18
.public sub_02017B64
.public sub_02017B70
.public sub_02017B7C
.public sub_02017B88
.public sub_02017B94
.public sub_02017BD4
.public sub_02017BE0
.public sub_02017BEC
.public sub_02017BF8
.public sub_02017C04
Expand Down
2 changes: 1 addition & 1 deletion asm/include/overlay_29_022EAB50.inc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
.public ov29_0237C922
.public ov29_0237C96C
.public PlayBgmByIdVeneer
.public PlayBgmByIdVolumeVeneer
.public RANDOM_MUSIC_ID_TABLE
.public RemoveEmptyItemsInBagWrapper
.public RemoveEquivItemNoHole
Expand All @@ -71,7 +72,6 @@
.public sub_0200D208
.public sub_02017ACC
.public sub_02017B18
.public sub_02017B64
.public sub_02017B70
.public sub_02017B7C
.public sub_02017C50
Expand Down
2 changes: 1 addition & 1 deletion asm/include/overlay_29_0231CBEC.inc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
.public GetWeatherColorTable
.public GINSENG_CHANCE_3
.public GUMMI_BELLY_RESTORE_TABLE
.public GUMMI_IQ_STRING_IDS
.public GUMMI_LIKE_STRING_IDS
.public HandleSir0Translation
.public InitMove
.public IQ_GUMMI_GAIN_TABLE
Expand Down
2 changes: 1 addition & 1 deletion asm/include/overlay_29_02325644.inc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
.public ov10_022BED90
.public ov10_022BF160
.public ov10_022BFC5C
.public ov10_022C48A8
.public ov10_022C4C0C
.public ov10_022C4C0E
.public ov29_022E2CA0
Expand Down Expand Up @@ -91,6 +90,7 @@
.public ROLLOUT_DAMAGE_MULT_TABLE
.public SILVER_WIND_BOOST_CHANCE
.public SKY_ATTACK_CRINGE_CHANCE
.public SKY_ATTACK_DAMAGE_MULTIPLIER
.public SLEEP_TURN_RANGE
.public SMOKESCREEN_TURN_RANGE
.public SNORE_CRINGE_CHANCE
Expand Down
32 changes: 16 additions & 16 deletions asm/main_0200C4CC.s
Original file line number Diff line number Diff line change
Expand Up @@ -14849,13 +14849,13 @@ PlayBgmByIdVeneer: ; 0x02017B58
_02017B60: .word PlayBgmById
arm_func_end PlayBgmByIdVeneer

arm_func_start sub_02017B64
sub_02017B64: ; 0x02017B64
ldr ip, _02017B6C ; =sub_02017E70
arm_func_start PlayBgmByIdVolumeVeneer
PlayBgmByIdVolumeVeneer: ; 0x02017B64
ldr ip, _02017B6C ; =PlayBgmByIdVolume
bx ip
.align 2, 0
_02017B6C: .word sub_02017E70
arm_func_end sub_02017B64
_02017B6C: .word PlayBgmByIdVolume
arm_func_end PlayBgmByIdVolumeVeneer

arm_func_start sub_02017B70
sub_02017B70: ; 0x02017B70
Expand Down Expand Up @@ -14912,13 +14912,13 @@ sub_02017BD4: ; 0x02017BD4
_02017BDC: .word sub_02018024
arm_func_end sub_02017BD4

arm_func_start PlayBgmByIdVolumeVeneer
PlayBgmByIdVolumeVeneer: ; 0x02017BE0
ldr ip, _02017BE8 ; =PlayBgmByIdVolume
arm_func_start sub_02017BE0
sub_02017BE0: ; 0x02017BE0
ldr ip, _02017BE8 ; =sub_020180A0
bx ip
.align 2, 0
_02017BE8: .word PlayBgmByIdVolume
arm_func_end PlayBgmByIdVolumeVeneer
_02017BE8: .word sub_020180A0
arm_func_end sub_02017BE0

arm_func_start sub_02017BEC
sub_02017BEC: ; 0x02017BEC
Expand Down Expand Up @@ -15188,8 +15188,8 @@ _02017E68: .word 0x000003E7
_02017E6C: .word _022A4BEC
arm_func_end PlayBgmById

arm_func_start sub_02017E70
sub_02017E70: ; 0x02017E70
arm_func_start PlayBgmByIdVolume
PlayBgmByIdVolume: ; 0x02017E70
stmdb sp!, {r3, r4, r5, r6, r7, lr}
ldr r3, _02017EE0 ; =0x000003E7
mov r6, r0
Expand Down Expand Up @@ -15221,7 +15221,7 @@ sub_02017E70: ; 0x02017E70
.align 2, 0
_02017EE0: .word 0x000003E7
_02017EE4: .word _022A4BEC
arm_func_end sub_02017E70
arm_func_end PlayBgmByIdVolume

arm_func_start StopBgmCommand
StopBgmCommand: ; 0x02017EE8
Expand Down Expand Up @@ -15368,8 +15368,8 @@ _02018098: .word 0x000003E7
_0201809C: .word _022A4BEC
arm_func_end sub_02018024

arm_func_start PlayBgmByIdVolume
PlayBgmByIdVolume: ; 0x020180A0
arm_func_start sub_020180A0
sub_020180A0: ; 0x020180A0
stmdb sp!, {r3, r4, r5, r6, r7, lr}
ldr r3, _02018110 ; =0x000003E7
mov r6, r0
Expand Down Expand Up @@ -15401,7 +15401,7 @@ PlayBgmByIdVolume: ; 0x020180A0
.align 2, 0
_02018110: .word 0x000003E7
_02018114: .word _022A4BEC
arm_func_end PlayBgmByIdVolume
arm_func_end sub_020180A0

arm_func_start sub_02018118
sub_02018118: ; 0x02018118
Expand Down
4 changes: 2 additions & 2 deletions asm/overlay_10.s
Original file line number Diff line number Diff line change
Expand Up @@ -10036,8 +10036,8 @@ ov10_022C48A0:
.global SOLARBEAM_DAMAGE_MULTIPLIER
SOLARBEAM_DAMAGE_MULTIPLIER:
.byte 0x00, 0x02, 0x00, 0x00
.global ov10_022C48A8
ov10_022C48A8:
.global SKY_ATTACK_DAMAGE_MULTIPLIER
SKY_ATTACK_DAMAGE_MULTIPLIER:
.byte 0x00, 0x02, 0x00, 0x00
.global ov10_022C48AC
ov10_022C48AC:
Expand Down
4 changes: 2 additions & 2 deletions asm/overlay_11.s
Original file line number Diff line number Diff line change
Expand Up @@ -6761,7 +6761,7 @@ _022E20D0:
mov r2, r3, lsl #0x10
mov r1, r1, lsr #0x10
mov r2, r2, lsr #0x10
bl sub_02017B64
bl PlayBgmByIdVolumeVeneer
b _022E2464
_022E2120:
bl sub_02017B70
Expand Down Expand Up @@ -6822,7 +6822,7 @@ _022E21A8:
mov r2, r3, lsl #0x10
mov r1, r1, lsr #0x10
mov r2, r2, lsr #0x10
bl PlayBgmByIdVolumeVeneer
bl sub_02017BE0
b _022E2464
_022E21F8:
bl sub_02017BEC
Expand Down
2 changes: 1 addition & 1 deletion asm/overlay_29_022EAB50.s
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ _022EB0D4:
ldrh r1, [r4, #8]
mov r0, r0, lsr #0x10
mov r2, #0x100
bl sub_02017B64
bl PlayBgmByIdVolumeVeneer
_022EB0EC:
ldrh r1, [r4, #0xa]
mov r0, #4
Expand Down
4 changes: 2 additions & 2 deletions asm/overlay_29_0231CBEC.s
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ _0231D214:
movge fp, #2
movlt fp, #3
_0231D23C:
ldr r0, _0231D480 ; =GUMMI_IQ_STRING_IDS
ldr r0, _0231D480 ; =GUMMI_LIKE_STRING_IDS
mov r1, r5, lsl #1
ldrh r2, [r0, r1]
mov r0, sl
Expand Down Expand Up @@ -634,7 +634,7 @@ _0231D470: .word IQ_GUMMI_GAIN_TABLE
_0231D474: .word GUMMI_BELLY_RESTORE_TABLE
_0231D478: .word 0x000003E7
_0231D47C: .word 0x00000BF3
_0231D480: .word GUMMI_IQ_STRING_IDS
_0231D480: .word GUMMI_LIKE_STRING_IDS
_0231D484: .word ov29_02353324
_0231D488: .word ov10_022C44CC
_0231D48C: .word ov10_022C45E4
Expand Down
4 changes: 2 additions & 2 deletions asm/overlay_29_02325644.s
Original file line number Diff line number Diff line change
Expand Up @@ -2808,7 +2808,7 @@ DoMoveSkyAttack: ; 0x02327A28
bl IsChargingTwoTurnMove
cmp r0, #0
beq _02327AB8
ldr r1, _02327AE8 ; =ov10_022C48A8
ldr r1, _02327AE8 ; =SKY_ATTACK_DAMAGE_MULTIPLIER
mov r0, r8
ldr r3, [r1]
mov r1, r7
Expand Down Expand Up @@ -2849,7 +2849,7 @@ _02327ADC:
add sp, sp, #4
ldmia sp!, {r3, r4, r5, r6, r7, r8, pc}
.align 2, 0
_02327AE8: .word ov10_022C48A8
_02327AE8: .word SKY_ATTACK_DAMAGE_MULTIPLIER
_02327AEC: .word SKY_ATTACK_CRINGE_CHANCE
_02327AF0: .word 0x00000CD1
arm_func_end DoMoveSkyAttack
Expand Down
8 changes: 4 additions & 4 deletions asm/overlay_29_0234EC38.s
Original file line number Diff line number Diff line change
Expand Up @@ -3920,8 +3920,8 @@ ov29_023532C0:
ov29_023532C8:
.byte 0x0D, 0x00, 0x00, 0x00
.byte 0xDD, 0x3F, 0x00, 0x00
.global GUMMI_IQ_STRING_IDS
GUMMI_IQ_STRING_IDS:
.global GUMMI_LIKE_STRING_IDS
GUMMI_LIKE_STRING_IDS:
.byte 0x48, 0x0B, 0x49, 0x0B
.byte 0x4A, 0x0B, 0x4B, 0x0B
.global ov29_023532D8
Expand Down Expand Up @@ -4052,8 +4052,8 @@ ov29_023532C0:
ov29_023532C8:
.byte 0x0D, 0x00, 0x00, 0x00
.byte 0xDB, 0x3F, 0x00, 0x00
.global GUMMI_IQ_STRING_IDS
GUMMI_IQ_STRING_IDS:
.global GUMMI_LIKE_STRING_IDS
GUMMI_LIKE_STRING_IDS:
.byte 0x48, 0x0B, 0x49, 0x0B, 0x4A, 0x0B, 0x4B, 0x0B
.global ov29_023532D8
ov29_023532D8:
Expand Down
44 changes: 31 additions & 13 deletions tools/sync_pmdsky_debug/pmdsky_debug_reader.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import os
import yaml
from typing import Dict, List

from containing_folder import CONTAINING_FOLDER
from typing import Dict
from symbol_details import SymbolDetails

SYMBOLS_FOLDER = 'symbols'
pmdsky_debug_path = None

LANGUAGE_KEYS = {
LANGUAGE_KEYS_PMDSKY_DEBUG_TO_XMAP = {
'NA': 'us',
'EU': 'eu',
}

LANGUAGE_KEYS_XMAP_TO_PMDSKY_DEBUG = {value: key for key, value in LANGUAGE_KEYS_PMDSKY_DEBUG_TO_XMAP.items()}

# Symbols with duplicate addresses that should be ignored.
SYMBOL_BLACKLIST = set([
'EXCLUSIVE_ITEM_STAT_BOOST_DATA',
'GAME_STATE_VALUES',
'GUMMI_IQ_STRING_IDS',
])

def get_pmdsky_debug_location() -> str:
global pmdsky_debug_path
if not pmdsky_debug_path:
Expand Down Expand Up @@ -42,40 +52,48 @@ def get_pmdsky_debug_location() -> str:
"""
def read_pmdsky_debug_symbols() -> Dict[str, Dict[str, Dict[int, SymbolDetails]]]:
pmdsky_debug_symbols: Dict[str, Dict[str, Dict[int, SymbolDetails]]] = {}
for language in LANGUAGE_KEYS:
pmdsky_debug_symbols[LANGUAGE_KEYS[language]] = {}
for language in LANGUAGE_KEYS_PMDSKY_DEBUG_TO_XMAP:
pmdsky_debug_symbols[LANGUAGE_KEYS_PMDSKY_DEBUG_TO_XMAP[language]] = {}

pmdsky_debug_path = get_pmdsky_debug_location()

def read_yaml_symbols(file_path: str, symbols_key: str, address_suffix = '') -> Dict[int, SymbolDetails]:
full_file_path = os.path.join(pmdsky_debug_path, SYMBOLS_FOLDER, file_path)
with open(full_file_path, 'r') as symbols_file:
symbols_yaml = yaml.safe_load(symbols_file)
symbols_yaml: Dict[str, any] = yaml.safe_load(symbols_file)

def read_symbols_from_array(array_key: str, is_data: bool):
for symbol in symbols_yaml[list(symbols_yaml.keys())[0]][array_key]:
for language in symbol['address'].keys():
if not language.endswith(address_suffix):
continue
base_language = language.replace(address_suffix, '')
if base_language not in LANGUAGE_KEYS:
base_language: str = language.replace(address_suffix, '')
if base_language not in LANGUAGE_KEYS_PMDSKY_DEBUG_TO_XMAP:
continue

language_symbols = pmdsky_debug_symbols[LANGUAGE_KEYS[base_language]]
language_symbols = pmdsky_debug_symbols[LANGUAGE_KEYS_PMDSKY_DEBUG_TO_XMAP[base_language]]
if symbols_key not in language_symbols:
language_symbols[symbols_key] = {}
symbols = language_symbols[symbols_key]

addresses = symbol['address'][language]
symbol_name = symbol['name']
addresses: int | List[int] = symbol['address'][language]
symbol_name: str = symbol['name']
if symbol_name in SYMBOL_BLACKLIST:
continue

def add_symbol_address(address: int, symbol_details: SymbolDetails):
if address in symbols:
print(f'Warning: Duplicate symbols found for address {hex(address)}: {symbols[address].name}, {symbol_details.name}')
symbols[address] = symbol_details

if isinstance(addresses, list):
if len(addresses) > 1:
for address in addresses:
symbols[address] = SymbolDetails(f'{symbol_name}__{address:08X}', full_file_path, is_data)
add_symbol_address(address, SymbolDetails(f'{symbol_name}__{address:08X}', full_file_path, is_data))
else:
symbols[addresses[0]] = SymbolDetails(symbol_name, full_file_path, is_data)
add_symbol_address(addresses[0], SymbolDetails(symbol_name, full_file_path, is_data))
else:
symbols[addresses] = SymbolDetails(symbol_name, full_file_path, is_data)
add_symbol_address(addresses, SymbolDetails(symbol_name, full_file_path, is_data))

read_symbols_from_array('functions', False)
read_symbols_from_array('data', True)
Expand Down
11 changes: 9 additions & 2 deletions tools/sync_pmdsky_debug/symbol_details.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass

MIXED_CASE_SYMBOLS = {
MIXED_CASE_SYMBOLS_ARM9 = {
'_secure': 'SECURE',
'_start_AutoloadDoneCallback': 'StartAutoloadDoneCallback',
'_start_ModuleParams': 'START_MODULE_PARAMS',
Expand All @@ -9,9 +9,16 @@
'SVC_CpuSet': 'SvcCpuSet',
'SVC_SoftReset': 'SvcSoftReset',
'SVC_WaitByLoop': 'SvcWaitByLoop',
'SVC_WaitByLoop': 'SvcWaitByLoop',
}

MIXED_CASE_SYMBOLS_ARM7 = {
'_start': '_start_arm7',
'_start_AutoloadDoneCallback': 'StartAutoloadDoneCallbackArm7',
'do_autoload': 'do_autoload_arm7',
}

WRAM_OFFSET = 0x1477E18

@dataclass
class SymbolDetails:
name: str
Expand Down
11 changes: 6 additions & 5 deletions tools/sync_pmdsky_debug/sync_from_pmdsky_debug.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import re
from typing import List

from pmdsky_debug_reader import *
from symbol_details import *
from xmap_reader import *
from pmdsky_debug_reader import read_pmdsky_debug_symbols
from symbol_details import MIXED_CASE_SYMBOLS_ARM7, MIXED_CASE_SYMBOLS_ARM9, WRAM_OFFSET
from xmap_reader import HEADER_FOLDER, read_xmap_symbols

# Syncs symbols from pmdsky-debug (https://github.com/UsernameFodder/pmdsky-debug) to the decomp.
# To use this script, you will need:
Expand Down Expand Up @@ -43,8 +44,8 @@ def add_files_with_extensions(folder: str, extensions: List[str]) -> List[str]:
for address, symbol in pmdsky_debug_section.items():
if section_name == 'arm7' and address < 0x27E0000:
# Shift ARM 7 WRAM to its RAM location.
address += 0x1477E18
if address in xmap_section and xmap_section[address].name != symbol.name and xmap_section[address].name not in MIXED_CASE_SYMBOLS and xmap_section[address].name not in replaced_symbols:
address += WRAM_OFFSET
if address in xmap_section and xmap_section[address].name != symbol.name and xmap_section[address].name not in MIXED_CASE_SYMBOLS_ARM9 and xmap_section[address].name not in MIXED_CASE_SYMBOLS_ARM7 and xmap_section[address].name not in replaced_symbols:
old_symbol = xmap_section[address]

if '__' in old_symbol.name:
Expand Down
Loading

0 comments on commit 3a591b0

Please sign in to comment.