From c0bc01d30150dae355b47bb3f42b71a7c00d0aec Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 13 Jan 2019 13:15:23 +0100 Subject: [PATCH] Move some vars to C --- data/battle_scripts_1.s | 6 +- data/event_scripts.s | 14 +- data/maps/TrainerHill_Entrance/scripts.inc | 24 +- data/maps/TrainerHill_Roof/scripts.inc | 8 +- data/pokenav.s | 53 ---- data/specials.inc | 2 +- include/constants/battle.h | 2 +- include/global.h | 4 +- include/strings.h | 12 +- include/trainer_hill.h | 6 + ld_script.txt | 1 + src/battle_script_commands.c | 2 +- src/load_save.c | 3 +- src/main.c | 2 +- src/save.c | 9 +- src/script_menu.c | 8 +- src/strings.c | 22 +- src/trainer_hill.c | 344 +++++++++++++-------- sym_ewram.txt | 10 +- 19 files changed, 282 insertions(+), 250 deletions(-) create mode 100644 include/trainer_hill.h diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index be91c7c7e..8ddf56ef8 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -599,7 +599,7 @@ BattleScript_EffectBide:: ppreduce attackanimation waitanimation - orword gHitMarker, HITMARKER_x8000000 + orword gHitMarker, HITMARKER_CHARGING setbide goto BattleScript_MoveEnd @@ -824,7 +824,7 @@ BattleScriptFirstChargingTurn:: ppreduce attackanimation waitanimation - orword gHitMarker, HITMARKER_x8000000 + orword gHitMarker, HITMARKER_CHARGING setmoveeffect MOVE_EFFECT_CHARGING | MOVE_EFFECT_AFFECTS_USER seteffectprimary copybyte cMULTISTRING_CHOOSER, sTWOTURN_STRINGID @@ -1941,7 +1941,7 @@ BattleScript_SolarbeamDecideTurn:: call BattleScriptFirstChargingTurn goto BattleScript_MoveEnd BattleScript_SolarbeamOnFirstTurn:: - orword gHitMarker, HITMARKER_x8000000 + orword gHitMarker, HITMARKER_CHARGING setmoveeffect MOVE_EFFECT_CHARGING | MOVE_EFFECT_AFFECTS_USER seteffectprimary ppreduce diff --git a/data/event_scripts.s b/data/event_scripts.s index 34a8484e5..d52f4f1ba 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -3221,7 +3221,7 @@ EventScript_2736F8:: @ 82736F8 compare VAR_RESULT, 2 goto_if_eq BattleFrontier_BattlePyramidTop_EventScript_252B42 setvar VAR_0x8004, 10 - special sp194_trainer_tower + special CallTrainerHillFunction compare VAR_RESULT, 1 goto_if_eq TrainerHill_1F_EventScript_2C83C9 special sub_80B05B4 @@ -7429,7 +7429,7 @@ TrainerHill_4F_MapScript1_2C8336: @ 82C8336 TrainerHill_Roof_MapScript1_2C8336: @ 82C8336 setvar VAR_TEMP_2, 0 setvar VAR_0x8004, 4 - special sp194_trainer_tower + special CallTrainerHillFunction setvar VAR_0x8004, 1 setvar VAR_0x8005, 5 special CallFrontierUtilFunc @@ -7462,7 +7462,7 @@ TrainerHill_Roof_MapScript2_2C8381: @ 82C8381 EventScript_TrainerHillTimer:: @ 82C8393 lockall setvar VAR_0x8004, 7 - special sp194_trainer_tower + special CallTrainerHillFunction msgbox TrainerHill_Entrance_Text_268D47, MSGBOX_DEFAULT releaseall end @@ -7470,7 +7470,7 @@ EventScript_TrainerHillTimer:: @ 82C8393 TrainerHill_1F_EventScript_2C83A6:: @ 82C83A6 setvar VAR_TEMP_2, 1 setvar VAR_0x8004, 9 - special sp194_trainer_tower + special CallTrainerHillFunction compare VAR_RESULT, 1 goto_if_eq TrainerHill_1F_EventScript_2C83BF end @@ -7482,9 +7482,9 @@ TrainerHill_1F_EventScript_2C83BF:: @ 82C83BF TrainerHill_1F_EventScript_2C83C9:: @ 82C83C9 setvar VAR_0x8004, 12 - special sp194_trainer_tower + special CallTrainerHillFunction setvar VAR_0x8004, 5 - special sp194_trainer_tower + special CallTrainerHillFunction setvar VAR_TEMP_1, 1 end @@ -7502,7 +7502,7 @@ TrainerHill_1F_Movement_2C83EE:: @ 82C83EE EventScript_2C83F0:: @ 82C83F0 trainerbattle TRAINER_BATTLE_12, TRAINER_PHILLIP, 0, BattleFrontier_BattlePyramidEmptySquare_Text_252C8D, BattleFrontier_BattlePyramidEmptySquare_Text_252C8D setvar VAR_0x8004, 11 - special sp194_trainer_tower + special CallTrainerHillFunction waitmessage waitbuttonpress closemessage diff --git a/data/maps/TrainerHill_Entrance/scripts.inc b/data/maps/TrainerHill_Entrance/scripts.inc index 4d315a158..846b7f6c3 100644 --- a/data/maps/TrainerHill_Entrance/scripts.inc +++ b/data/maps/TrainerHill_Entrance/scripts.inc @@ -16,10 +16,10 @@ TrainerHill_Entrance_MapScript1_2680CF: @ 82680CF TrainerHill_Entrance_MapScript1_2680D0: @ 82680D0 setvar VAR_0x8004, 4 - special sp194_trainer_tower + special CallTrainerHillFunction setvar VAR_TEMP_0, 0 setvar VAR_0x8004, 9 - special sp194_trainer_tower + special CallTrainerHillFunction compare VAR_RESULT, 0 goto_if_eq TrainerHill_Entrance_EventScript_2680FF setobjectxy EVENT_OBJ_ID_PLAYER, 9, 6 @@ -28,7 +28,7 @@ TrainerHill_Entrance_MapScript1_2680D0: @ 82680D0 TrainerHill_Entrance_EventScript_2680FF:: @ 82680FF setvar VAR_0x8004, 16 - special sp194_trainer_tower + special CallTrainerHillFunction compare VAR_RESULT, 1 goto_if_eq TrainerHill_Entrance_EventScript_26811A applymovement EVENT_OBJ_ID_PLAYER, TrainerHill_Entrance_Movement_26837F @@ -75,7 +75,7 @@ TrainerHill_Entrance_EventScript_268160:: @ 8268160 TrainerHill_Entrance_EventScript_268182:: @ 8268182 setvar VAR_TEMP_0, 1 setvar VAR_0x8004, 6 - special sp194_trainer_tower + special CallTrainerHillFunction switch VAR_RESULT case 0, TrainerHill_Entrance_EventScript_2681B5 case 1, TrainerHill_Entrance_EventScript_2681CA @@ -115,7 +115,7 @@ TrainerHill_Entrance_EventScript_2681FD:: @ 82681FD lock faceplayer setvar VAR_0x8004, 10 - special sp194_trainer_tower + special CallTrainerHillFunction compare VAR_RESULT, 0 goto_if_eq TrainerHill_Entrance_EventScript_26821F msgbox TrainerHill_Entrance_Text_2686F4, MSGBOX_DEFAULT @@ -134,11 +134,11 @@ TrainerHill_Entrance_EventScript_268229:: @ 8268229 goto_if_unset FLAG_SYS_GAME_CLEAR, TrainerHill_Entrance_EventScript_26836A msgbox TrainerHill_Entrance_Text_2684C6, MSGBOX_DEFAULT setvar VAR_0x8004, 13 - special sp194_trainer_tower + special CallTrainerHillFunction compare VAR_RESULT, 0 call_if_eq TrainerHill_Entrance_EventScript_26832E setvar VAR_0x8004, 8 - special sp194_trainer_tower + special CallTrainerHillFunction compare VAR_RESULT, 1 goto_if_eq TrainerHill_Entrance_EventScript_268275 msgbox TrainerHill_Entrance_Text_268564, MSGBOX_DEFAULT @@ -170,13 +170,13 @@ TrainerHill_Entrance_EventScript_2682C8:: @ 82682C8 case 127, TrainerHill_Entrance_EventScript_268314 setvar VAR_0x8004, 17 copyvar VAR_0x8005, VAR_RESULT - special sp194_trainer_tower + special CallTrainerHillFunction setvar VAR_0x40D6, 1 setvar VAR_TEMP_5, 0 special HealPlayerParty msgbox TrainerHill_Entrance_Text_26862A, MSGBOX_DEFAULT setvar VAR_0x8004, 0 - special sp194_trainer_tower + special CallTrainerHillFunction releaseall end @@ -192,18 +192,18 @@ TrainerHill_Entrance_EventScript_268314:: @ 8268314 TrainerHill_Entrance_EventScript_26832E:: @ 826832E msgbox TrainerHill_Entrance_Text_26851C, MSGBOX_DEFAULT setvar VAR_0x8004, 14 - special sp194_trainer_tower + special CallTrainerHillFunction setvar VAR_TEMP_5, 1 call TrainerHill_Entrance_EventScript_27134F compare VAR_RESULT, 0 goto_if_eq TrainerHill_Entrance_EventScript_26835C setvar VAR_0x8004, 14 - special sp194_trainer_tower + special CallTrainerHillFunction return TrainerHill_Entrance_EventScript_26835C:: @ 826835C setvar VAR_0x8004, 15 - special sp194_trainer_tower + special CallTrainerHillFunction goto TrainerHill_Entrance_EventScript_268314 end diff --git a/data/maps/TrainerHill_Roof/scripts.inc b/data/maps/TrainerHill_Roof/scripts.inc index 19e8ef567..b959481f2 100644 --- a/data/maps/TrainerHill_Roof/scripts.inc +++ b/data/maps/TrainerHill_Roof/scripts.inc @@ -5,11 +5,11 @@ TrainerHill_Roof_MapScripts:: @ 8268FA7 TrainerHill_Roof_EventScript_268FB2:: @ 8268FB2 setvar VAR_0x8004, 12 - special sp194_trainer_tower + special CallTrainerHillFunction lock faceplayer setvar VAR_0x8004, 1 - special sp194_trainer_tower + special CallTrainerHillFunction switch VAR_RESULT case 0, TrainerHill_Roof_EventScript_268FEA case 1, TrainerHill_Roof_EventScript_268FF2 @@ -20,7 +20,7 @@ TrainerHill_Roof_EventScript_268FEA:: @ 8268FEA TrainerHill_Roof_EventScript_268FF2:: @ 8268FF2 setvar VAR_0x8004, 2 - special sp194_trainer_tower + special CallTrainerHillFunction switch VAR_RESULT case 0, TrainerHill_Roof_EventScript_269020 case 1, TrainerHill_Roof_EventScript_269037 @@ -42,7 +42,7 @@ TrainerHill_Roof_EventScript_269037:: @ 8269037 TrainerHill_Roof_EventScript_269054:: @ 8269054 setvar VAR_0x8004, 3 - special sp194_trainer_tower + special CallTrainerHillFunction switch VAR_RESULT case 0, TrainerHill_Roof_EventScript_269082 case 1, TrainerHill_Roof_EventScript_269090 diff --git a/data/pokenav.s b/data/pokenav.s index eaa2ea269..23b17d9da 100644 --- a/data/pokenav.s +++ b/data/pokenav.s @@ -2382,56 +2382,3 @@ gUnknown_0862A5A4:: @ 862A5A4 gUnknown_0862A5CC:: @ 862A5CC .4byte gUnknown_0862A57C .4byte gUnknown_0862A5A4 - -gUnknown_0862A5D4:: @ 862A5D4 - .incbin "graphics/pokenav/862A5D4.gbapal" - -gUnknown_0862A5F4:: @ 862A5F4 - .byte 0, 2, 3, 0 - -gUnknown_0862A5F8:: @ 862A5F8 - .4byte gUnknown_08626814 - .4byte gUnknown_086276FC - .4byte gUnknown_086285E4 - .4byte gUnknown_086294CC - .4byte gUnknown_085EF8B6 - .4byte gUnknown_085EF8B9 - .4byte gUnknown_085EF8BC - .4byte gUnknown_085EF8BF - -gUnknown_0862A618:: @ 862A618 - .4byte sub_81D581C - .4byte sub_81D58D8 - .4byte sub_81D5924 - .4byte sub_81D59D0 - .4byte sub_81D5A70 - .4byte sub_81D5AB4 - .4byte sub_81D5AD0 - .4byte sub_81D5B2C - .4byte sub_81D5BBC - .4byte sub_81D5C00 - .4byte sub_81D5C5C - .4byte sub_81D62B4 - .4byte sub_81D64AC - .4byte sub_81D64DC - .4byte sub_81D64FC - .4byte sub_81D6518 - .4byte sub_81D6568 - .4byte sub_81D65A0 - -gUnknown_0862A660:: @ 862A660 - .4byte gUnknown_085EB32D - .4byte gUnknown_085EB33E - .4byte gUnknown_085EB350 - .4byte gUnknown_085EB361 - -gUnknown_0862A670:: @ 862A670 - .byte 0, 0x64 - .4byte NULL - .2byte 0, 0x103, 17, 1, 0, 0, 0, 0, 0 - -gUnknown_0862A688:: @ 862A688 - .2byte 0x3E, 0, 0x3F, 0, 0x40, 0, 0x41, 0 - -gUnknown_0862A698:: @ 862A698 - .byte 0, 1, 2, 3, 4, 5, 0, 0 diff --git a/data/specials.inc b/data/specials.inc index 5ac4930c7..a5f272dc9 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -515,7 +515,7 @@ gSpecials:: @ 81DBA64 def_special sub_813B514 def_special sub_813B568 def_special sub_813B534 - def_special sp194_trainer_tower + def_special CallTrainerHillFunction def_special sub_813B7D8 def_special sub_813B80C def_special sub_81D4BEC diff --git a/include/constants/battle.h b/include/constants/battle.h index acb0f6689..346d5d9ea 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -174,7 +174,7 @@ #define HITMARKER_GRUDGE 0x01000000 #define HITMARKER_OBEYS 0x02000000 #define HITMARKER_x4000000 0x04000000 -#define HITMARKER_x8000000 0x08000000 +#define HITMARKER_CHARGING 0x08000000 #define HITMARKER_FAINTED(battler) (gBitTable[battler] << 0x1C) #define HITMARKER_UNK(battler) (0x10000000 << battler) diff --git a/include/global.h b/include/global.h index d6a57320d..f45d36f68 100644 --- a/include/global.h +++ b/include/global.h @@ -805,7 +805,7 @@ struct SaveTrainerHill /*0x3D6E*/ u16 field_3D6E_0d:1; // 8 /*0x3D6E*/ u16 field_3D6E_0e:1; // x10 /*0x3D6E*/ u16 field_3D6E_0f:1; // x20 - /*0x3D6E*/ u16 field_3D6E_1:2; // x40, x80 = xC0 + /*0x3D6E*/ u16 tag:2; // x40, x80 = xC0 }; struct SaveBlock1 @@ -886,7 +886,7 @@ struct SaveBlock1 /*0x31DC*/ struct Roamer roamer; /*0x31F8*/ struct EnigmaBerry enigmaBerry; /*0x322C*/ u8 field_322C[1260]; - /*0x3718*/ u32 field_3718[4]; + /*0x3718*/ u32 trainerHillTimes[4]; /*0x3728*/ struct RamScript ramScript; /*0x3B14*/ struct RecordMixingGift recordMixingGift; /*0x3B24*/ u8 seen2[DEX_FLAGS_NO]; diff --git a/include/strings.h b/include/strings.h index d16dd21f8..65f81024e 100644 --- a/include/strings.h +++ b/include/strings.h @@ -1231,10 +1231,14 @@ extern const u8 gText_MtPyre[]; extern const u8 gText_SkyPillar[]; extern const u8 gText_DontRemember[]; extern const u8 gUnknown_085EB597[]; -extern const u8 gUnknown_085EB32D[]; -extern const u8 gUnknown_085EB33E[]; -extern const u8 gUnknown_085EB350[]; -extern const u8 gUnknown_085EB361[]; +extern const u8 gText_NormalTagMatch[]; +extern const u8 gText_VarietyTagMatch[]; +extern const u8 gText_UniqueTagMatch[]; +extern const u8 gText_ExpertTagMatch[]; +extern const u8 gText_TrainerHill1F[]; +extern const u8 gText_TrainerHill2F[]; +extern const u8 gText_TrainerHill3F[]; +extern const u8 gText_TrainerHill4F[]; extern const u8 OldaleTown_PokemonCenter_2F_Text_277F1B[]; extern const u8 OldaleTown_PokemonCenter_2F_Text_277F5A[]; diff --git a/include/trainer_hill.h b/include/trainer_hill.h new file mode 100644 index 000000000..5e9947c85 --- /dev/null +++ b/include/trainer_hill.h @@ -0,0 +1,6 @@ +#ifndef GUARD_TRAINER_HILL_H +#define GUARD_TRAINER_HILL_H + +extern u32 *gUnknown_0203CF5C; + +#endif // GUARD_TRAINER_HILL_H diff --git a/ld_script.txt b/ld_script.txt index 2551d884b..8491c00c4 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -597,6 +597,7 @@ SECTIONS { data/pokenav.o(.rodata); src/pokenav_match_call.o(.rodata); data/pokenav.o(.rodata.after.match.call); + src/trainer_hill.o(.rodata); src/rayquaza_scene.o(.rodata); src/walda_phrase.o(.rodata); src/gym_leader_rematch.o(.rodata); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 2490d6e13..0995eec45 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -8459,7 +8459,7 @@ static u8 AttacksThisTurn(u8 battlerId, u16 move) // Note: returns 1 if it's a c || gBattleMoves[move].effect == EFFECT_SEMI_INVULNERABLE || gBattleMoves[move].effect == EFFECT_BIDE) { - if ((gHitMarker & HITMARKER_x8000000)) + if ((gHitMarker & HITMARKER_CHARGING)) return 1; } return 2; diff --git a/src/load_save.c b/src/load_save.c index a7593d007..0d19c6dae 100644 --- a/src/load_save.c +++ b/src/load_save.c @@ -8,13 +8,12 @@ #include "pokemon_storage_system.h" #include "random.h" #include "save_location.h" +#include "trainer_hill.h" #include "gba/flash_internal.h" #include "decoration_inventory.h" static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey); -extern void* gUnknown_0203CF5C; - extern bool16 IdentifyFlash(void); extern void ApplyNewEncryptionKeyToBerryPowder(u32 key); diff --git a/src/main.c b/src/main.c index c4962286c..61c5e3386 100644 --- a/src/main.c +++ b/src/main.c @@ -22,10 +22,10 @@ #include "text.h" #include "intro.h" #include "main.h" +#include "trainer_hill.h" extern void sub_800B9B8(void); extern u8 gUnknown_03002748; -extern u32 *gUnknown_0203CF5C; static void VBlankIntr(void); static void HBlankIntr(void); diff --git a/src/save.c b/src/save.c index cfbe5b848..a22e20f0b 100644 --- a/src/save.c +++ b/src/save.c @@ -7,6 +7,7 @@ #include "overworld.h" #include "pokemon_storage_system.h" #include "main.h" +#include "trainer_hill.h" #include "constants/game_stat.h" static u16 CalculateChecksum(void *data, u16 size); @@ -17,10 +18,6 @@ static u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location); static u8 TryWriteSector(u8 sector, u8 *data); static u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location); -// for the chunk declarations - -extern u32 gUnknown_0203CF5C; - // Divide save blocks into individual chunks to be written to flash sectors // Each 4 KiB flash sector contains 3968 bytes of actual data followed by a 128 byte footer @@ -662,10 +659,10 @@ static void UpdateSaveAddresses(void) u8 HandleSavingData(u8 saveType) { u8 i; - u32 backupVar = gUnknown_0203CF5C; + u32 *backupVar = gUnknown_0203CF5C; u8 *tempAddr; - gUnknown_0203CF5C = 0; + gUnknown_0203CF5C = NULL; UpdateSaveAddresses(); switch (saveType) { diff --git a/src/script_menu.c b/src/script_menu.c index 4064e1810..a4f4c6086 100644 --- a/src/script_menu.c +++ b/src/script_menu.c @@ -782,10 +782,10 @@ const struct MenuAction MultichoiceList_112[] = const struct MenuAction MultichoiceList_113[] = { - {gUnknown_085EB32D, NULL}, - {gUnknown_085EB33E, NULL}, - {gUnknown_085EB350, NULL}, - {gUnknown_085EB361, NULL}, + {gText_NormalTagMatch, NULL}, + {gText_VarietyTagMatch, NULL}, + {gText_UniqueTagMatch, NULL}, + {gText_ExpertTagMatch, NULL}, {gText_Exit, NULL}, }; diff --git a/src/strings.c b/src/strings.c index 7b2b5ca4c..b0eb048ba 100644 --- a/src/strings.c +++ b/src/strings.c @@ -252,7 +252,7 @@ const u8 gText_ThePokemonList[] = _("the POKéMON LIST"); const u8 gText_TheShop[] = _("the shop"); const u8 gText_ThePC[] = _("the PC"); -const u8 *const gReturnToXStringsTable[] = +const u8 *const gReturnToXStringsTable[] = { gText_TheField, gText_TheBattle, @@ -268,7 +268,7 @@ const u8 *const gReturnToXStringsTable[] = gText_ThePC }; -const u8 *const gReturnToXStringsTable2[] = +const u8 *const gReturnToXStringsTable2[] = { gText_TheField, gText_TheBattle, @@ -283,7 +283,7 @@ const u8 gText_TMHMPocket[] = _("TMs & HMs"); const u8 gText_BerriesPocket[] = _("BERRIES"); const u8 gText_KeyItemsPocket[] = _("KEY ITEMS"); -const u8 *const gPocketNamesStringsTable[] = +const u8 *const gPocketNamesStringsTable[] = { gText_ItemsPocket, gText_PokeBallsPocket, @@ -749,10 +749,10 @@ const u8 gUnknown_085EB2FF[] = _("I'll battle now!"); const u8 gUnknown_085EB310[] = _("I won!"); const u8 gUnknown_085EB317[] = _("I lost!"); const u8 gUnknown_085EB31F[] = _("I won't tell."); -const u8 gUnknown_085EB32D[] = _("NORMAL TAG MATCH"); -const u8 gUnknown_085EB33E[] = _("VARIETY TAG MATCH"); -const u8 gUnknown_085EB350[] = _("UNIQUE TAG MATCH"); -const u8 gUnknown_085EB361[] = _("EXPERT TAG MATCH"); +const u8 gText_NormalTagMatch[] = _("NORMAL TAG MATCH"); +const u8 gText_VarietyTagMatch[] = _("VARIETY TAG MATCH"); +const u8 gText_UniqueTagMatch[] = _("UNIQUE TAG MATCH"); +const u8 gText_ExpertTagMatch[] = _("EXPERT TAG MATCH"); const u8 gUnknown_085EB372[] = _("TRADE CENTER"); const u8 gUnknown_085EB37F[] = _("COLOSSEUM"); const u8 gUnknown_085EB389[] = _("RECORD CORNER"); @@ -1737,10 +1737,10 @@ const u8 gText_Lv[] = _("{LV}"); const u8 gText_TimeBoard[] = _("TIME BOARD"); const u8 gText_TimeCleared[] = _("TIME CLEARED "); const u8 gText_XMinYDotZSec[] = _("{STR_VAR_1} min. {STR_VAR_2}.{STR_VAR_3} sec."); -const u8 gUnknown_085EF8B6[] = _("1F"); -const u8 gUnknown_085EF8B9[] = _("2F"); -const u8 gUnknown_085EF8BC[] = _("3F"); -const u8 gUnknown_085EF8BF[] = _("4F"); +const u8 gText_TrainerHill1F[] = _("1F"); +const u8 gText_TrainerHill2F[] = _("2F"); +const u8 gText_TrainerHill3F[] = _("3F"); +const u8 gText_TrainerHill4F[] = _("4F"); const u8 gText_TeachWhichMoveToPkmn[] = _("Teach which move to {STR_VAR_1}?"); const u8 gText_TeachX[] = _("Teach {STR_VAR_2}?"); const u8 gText_PkmnLearnedMove4[] = _("{STR_VAR_1} learned\n{STR_VAR_2}!"); diff --git a/src/trainer_hill.c b/src/trainer_hill.c index 4f3645963..20d686c88 100644 --- a/src/trainer_hill.c +++ b/src/trainer_hill.c @@ -15,16 +15,24 @@ #include "pokemon.h" #include "script.h" #include "string_util.h" +#include "strings.h" #include "text.h" +#include "trainer_hill.h" #include "window.h" #include "util.h" #include "constants/event_object_movement_constants.h" +#include "constants/event_objects.h" #include "constants/maps.h" +#define HILL_TAG_NORMAL 0 +#define HILL_TAG_VARIETY 1 +#define HILL_TAG_UNIQUE 2 +#define HILL_TAG_EXPERT 3 + #define HILL_TRAINER_NAME_LENGTH 11 #define HILL_MAX_TIME 215999 // 60 * 60 * 60 - 1 -struct TrHillStruct1 +struct TrHillRoomTrainers { u8 name[2][HILL_TRAINER_NAME_LENGTH]; u8 facilityClass[2]; @@ -34,7 +42,7 @@ struct TrainerHillTrainer { u8 name[HILL_TRAINER_NAME_LENGTH]; u8 facilityClass; - u32 field_18; + u32 unused; u16 speechBefore[6]; u16 speechWin[6]; u16 speechLose[6]; @@ -42,67 +50,81 @@ struct TrainerHillTrainer struct BattleTowerPokemon mons[PARTY_SIZE]; }; -struct TrHillStruct5 +struct TrHillFloor { u8 unk0; u8 unk1; struct TrainerHillTrainer trainers[2]; u8 data[0x100]; - u16 unk3A0[2]; - u8 data2[0x20 - 4]; + u16 unk3A0[16]; u8 coords[2]; // x first 4 bits, y last 4 bites u8 direction; // array of 4 bites for each trainer u8 range; // array of 4 bites for each trainer }; -struct TrHillStruct4 +struct TrHillTag { u8 unkField_0; - u8 unkField_1; + u8 unused1; u8 unkField_2; - u8 unkField_3; - u8 unkField_4; - u8 unkField_5; - u8 unkField_6; - struct TrHillStruct5 unk0[4]; + u8 unused3; + u8 unused4; + struct TrHillFloor floors[4]; }; struct TrHillStruct2 { - u8 layoutId; - struct TrHillStruct4 unk4; + u8 floorId; + struct TrHillTag tag; }; -extern struct TrHillStruct2 *gUnknown_0203CF54; -extern struct TrHillStruct1 *gUnknown_0203CF58; +// EWRAM +static EWRAM_DATA struct TrHillStruct2 *sHillData = NULL; +static EWRAM_DATA struct TrHillRoomTrainers *sRoomTrainers = NULL; +EWRAM_DATA u32 *gUnknown_0203CF5C = NULL; // This file's functions. -void sub_81D56B0(void); -void sub_81D5710(void); +void sub_81D581C(void); +void sub_81D58D8(void); +void sub_81D5924(void); +void sub_81D59D0(void); +void sub_81D5A70(void); +void sub_81D5AB4(void); +void sub_81D5AD0(void); +void sub_81D5B2C(void); +void sub_81D5BBC(void); +void sub_81D5C00(void); +void sub_81D5C5C(void); +void sub_81D62B4(void); +void sub_81D64AC(void); +void sub_81D64DC(void); +void sub_81D64FC(void); +void sub_81D6518(void); +void sub_81D6568(void); +void sub_81D65A0(void); +void SetUpDataStruct(void); +void FreeDataStruct(void); bool32 sub_81D5F48(void); void nullsub_2(void); -void sub_81D5DF4(u32 *dst, u32 val); +void SetTimerValue(u32 *dst, u32 val); bool32 sub_81D3B34(void); u16 sub_81D6640(void); -u32 sub_81D5DF0(u32 *src); +u32 GetTimerValue(u32 *src); u8 GetCurrentTrainerHillMapId(void); u8 sub_81D6490(void); void sub_81D642C(struct Pokemon *mon, u8 level); bool32 sub_81D6534(void); // const data -extern void (* const gUnknown_0862A618[])(void); -extern const struct TrHillStruct4 *const gUnknown_0862A5F8[]; -extern const u16 gUnknown_0862A5D4[]; extern const u8 gText_TimeBoard[]; extern const u8 gText_TimeCleared[]; extern const u8 gText_XMinYDotZSec[]; -extern const u8 gUnknown_0862A5F4[]; -extern const u8 *const gUnknown_0862A660[]; -extern const struct EventObjectTemplate gUnknown_0862A670; -extern const u32 gUnknown_0862A688[4]; -extern const u8 gUnknown_0862A698[][3]; +extern const struct TrHillTag gUnknown_08626814; +extern const struct TrHillTag gUnknown_086276FC; +extern const struct TrHillTag gUnknown_086285E4; +extern const struct TrHillTag gUnknown_086294CC; + extern const u16 *const *const gUnknown_0862A5CC[]; struct { @@ -112,11 +134,74 @@ struct extern const u8 EventScript_2C83F0[]; -void sp194_trainer_tower(void) +static const u16 gUnknown_0862A5D4[] = INCBIN_U16("graphics/pokenav/862A5D4.gbapal"); +static const u8 sRecordWinColors[] = {0, 2, 3}; + +static const struct TrHillTag *const sDataPerTag[] = { - sub_81D56B0(); - gUnknown_0862A618[gSpecialVar_0x8004](); - sub_81D5710(); + &gUnknown_08626814, + &gUnknown_086276FC, + &gUnknown_086285E4, + &gUnknown_086294CC, +}; + +// Unused. +static const u8 *const sFloorStrings[] = +{ + gText_TrainerHill1F, + gText_TrainerHill2F, + gText_TrainerHill3F, + gText_TrainerHill4F, +}; + +static void (* const sHillFunctions[])(void) = +{ + sub_81D581C, + sub_81D58D8, + sub_81D5924, + sub_81D59D0, + sub_81D5A70, + sub_81D5AB4, + sub_81D5AD0, + sub_81D5B2C, + sub_81D5BBC, + sub_81D5C00, + sub_81D5C5C, + sub_81D62B4, + sub_81D64AC, + sub_81D64DC, + sub_81D64FC, + sub_81D6518, + sub_81D6568, + sub_81D65A0, +}; + +static const u8 *const sTagMatchStrings[] = +{ + gText_NormalTagMatch, + gText_VarietyTagMatch, + gText_UniqueTagMatch, + gText_ExpertTagMatch, +}; + +static const struct EventObjectTemplate gUnknown_0862A670 = +{ + .graphicsId = EVENT_OBJ_GFX_RIVAL_BRENDAN_NORMAL, + .elevation = 3, + .movementType = MOVEMENT_TYPE_LOOK_AROUND, + .movementRangeX = 1, + .movementRangeY = 1, + .trainerType = 1, +}; + +static const u32 gUnknown_0862A688[] = {MAP_NUM(TRAINER_HILL_2F), MAP_NUM(TRAINER_HILL_3F), MAP_NUM(TRAINER_HILL_4F), MAP_NUM(TRAINER_HILL_ROOF)}; +static const u8 gUnknown_0862A698[][3] = {{0, 1, 2}, {3, 4, 5}}; + +void CallTrainerHillFunction(void) +{ + SetUpDataStruct(); + sHillFunctions[gSpecialVar_0x8004](); + FreeDataStruct(); } void sub_81D54BC(void) @@ -127,10 +212,10 @@ void sub_81D54BC(void) gSaveBlock2Ptr->frontier.field_EF9_0 = 0; gSaveBlock1Ptr->trainerHill.field_3D68 = 0; for (i = 0; i < 4; i++) - sub_81D5DF4(&gSaveBlock1Ptr->field_3718[i], HILL_MAX_TIME); + SetTimerValue(&gSaveBlock1Ptr->trainerHillTimes[i], HILL_MAX_TIME); } -u8 sub_81D5520(void) +u8 GetFloorId(void) { return gMapHeader.mapLayoutId - 159; } @@ -139,7 +224,7 @@ u8 GetTrainerHillOpponentClass(u16 trainerId) { u8 id = trainerId - 1; - return gFacilityClassToTrainerClass[gUnknown_0203CF58->facilityClass[id]]; + return gFacilityClassToTrainerClass[sRoomTrainers->facilityClass[id]]; } void GetTrainerHillTrainerName(u8 *dst, u16 trainerId) @@ -148,17 +233,17 @@ void GetTrainerHillTrainerName(u8 *dst, u16 trainerId) u8 id = trainerId - 1; for (i = 0; i < HILL_TRAINER_NAME_LENGTH; i++) - dst[i] = gUnknown_0203CF58->name[id][i]; + dst[i] = sRoomTrainers->name[id][i]; } u8 GetTrainerHillTrainerFrontSpriteId(u16 trainerId) { u8 id, facilityClass; - sub_81D56B0(); + SetUpDataStruct(); id = trainerId - 1; - facilityClass = gUnknown_0203CF54->unk4.unk0[gUnknown_0203CF54->layoutId].trainers[id].facilityClass; - sub_81D5710(); + facilityClass = sHillData->tag.floors[sHillData->floorId].trainers[id].facilityClass; + FreeDataStruct(); return gFacilityClassToPicIndex[facilityClass]; } @@ -167,69 +252,69 @@ void sub_81D55D0(void) { s32 i, j; - sub_81D56B0(); - gUnknown_0203CF58 = AllocZeroed(sizeof(*gUnknown_0203CF58)); + SetUpDataStruct(); + sRoomTrainers = AllocZeroed(sizeof(*sRoomTrainers)); for (i = 0; i < 2; i++) { for (j = 0; j < HILL_TRAINER_NAME_LENGTH; j++) { - gUnknown_0203CF58->name[i][j] = gUnknown_0203CF54->unk4.unk0[gUnknown_0203CF54->layoutId].trainers[i].name[j]; + sRoomTrainers->name[i][j] = sHillData->tag.floors[sHillData->floorId].trainers[i].name[j]; } - gUnknown_0203CF58->facilityClass[i] = gUnknown_0203CF54->unk4.unk0[gUnknown_0203CF54->layoutId].trainers[i].facilityClass; + sRoomTrainers->facilityClass[i] = sHillData->tag.floors[sHillData->floorId].trainers[i].facilityClass; } sub_80008DC(&gSaveBlock1Ptr->trainerHill.field_3D64); - sub_81D5710(); + FreeDataStruct(); } void sub_81D5694(void) { - if (gUnknown_0203CF58 != NULL) - FREE_AND_SET_NULL(gUnknown_0203CF58); + if (sRoomTrainers != NULL) + FREE_AND_SET_NULL(sRoomTrainers); } -void sub_81D56B0(void) +void SetUpDataStruct(void) { - if (gUnknown_0203CF54 == NULL) + if (sHillData == NULL) { - gUnknown_0203CF54 = AllocZeroed(sizeof(*gUnknown_0203CF54)); - gUnknown_0203CF54->layoutId = gMapHeader.mapLayoutId - 159; - CpuCopy32(gUnknown_0862A5F8[gSaveBlock1Ptr->trainerHill.field_3D6E_1], &gUnknown_0203CF54->unk4, sizeof(gUnknown_0203CF54->unk4)); + sHillData = AllocZeroed(sizeof(*sHillData)); + sHillData->floorId = gMapHeader.mapLayoutId - 159; + CpuCopy32(sDataPerTag[gSaveBlock1Ptr->trainerHill.tag], &sHillData->tag, sizeof(sHillData->tag)); nullsub_2(); } } -void sub_81D5710(void) +void FreeDataStruct(void) { - if (gUnknown_0203CF54 != NULL) - FREE_AND_SET_NULL(gUnknown_0203CF54); + if (sHillData != NULL) + FREE_AND_SET_NULL(sHillData); } void CopyTrainerHillTrainerText(u8 which, u16 trainerId) { - u8 id, layoutId; + u8 id, floorId; - sub_81D56B0(); - layoutId = sub_81D5520(); + SetUpDataStruct(); + floorId = GetFloorId(); id = trainerId - 1; switch (which) { case 2: - FrontierSpeechToString(gUnknown_0203CF54->unk4.unk0[layoutId].trainers[id].speechBefore); + FrontierSpeechToString(sHillData->tag.floors[floorId].trainers[id].speechBefore); break; case 3: - FrontierSpeechToString(gUnknown_0203CF54->unk4.unk0[layoutId].trainers[id].speechWin); + FrontierSpeechToString(sHillData->tag.floors[floorId].trainers[id].speechWin); break; case 4: - FrontierSpeechToString(gUnknown_0203CF54->unk4.unk0[layoutId].trainers[id].speechLose); + FrontierSpeechToString(sHillData->tag.floors[floorId].trainers[id].speechLose); break; case 5: - FrontierSpeechToString(gUnknown_0203CF54->unk4.unk0[layoutId].trainers[id].speechAfter); + FrontierSpeechToString(sHillData->tag.floors[floorId].trainers[id].speechAfter); break; } - sub_81D5710(); + FreeDataStruct(); } void sub_81D581C(void) @@ -267,7 +352,7 @@ void sub_81D5924(void) { u16 itemId = sub_81D6640(); - if (gUnknown_0203CF54->unk4.unkField_2 != 4 || gSaveBlock1Ptr->trainerHill.field_3D6E_0a) + if (sHillData->tag.unkField_2 != 4 || gSaveBlock1Ptr->trainerHill.field_3D6E_0a) { gSpecialVar_Result = 2; } @@ -290,10 +375,10 @@ void sub_81D59D0(void) { gSpecialVar_Result = 2; } - else if (sub_81D5DF0(&gSaveBlock1Ptr->trainerHill.field_3D68) > gSaveBlock1Ptr->trainerHill.field_3D64) + else if (GetTimerValue(&gSaveBlock1Ptr->trainerHill.field_3D68) > gSaveBlock1Ptr->trainerHill.field_3D64) { - sub_81D5DF4(&gSaveBlock1Ptr->trainerHill.field_3D68, gSaveBlock1Ptr->trainerHill.field_3D64); - gSaveBlock1Ptr->field_3718[gSaveBlock1Ptr->trainerHill.field_3D6E_1] = gSaveBlock1Ptr->trainerHill.field_3D68; + SetTimerValue(&gSaveBlock1Ptr->trainerHill.field_3D68, gSaveBlock1Ptr->trainerHill.field_3D64); + gSaveBlock1Ptr->trainerHillTimes[gSaveBlock1Ptr->trainerHill.tag] = gSaveBlock1Ptr->trainerHill.field_3D68; gSpecialVar_Result = 0; } else @@ -359,10 +444,10 @@ void sub_81D5B2C(void) void sub_81D5BBC(void) { - sub_81D56B0(); - if (gUnknown_0203CF54->unk4.unkField_2 != 4) + SetUpDataStruct(); + if (sHillData->tag.unkField_2 != 4) { - ConvertIntToDecimalStringN(gStringVar1, gUnknown_0203CF54->unk4.unkField_2, STR_CONV_MODE_LEFT_ALIGN, 1); + ConvertIntToDecimalStringN(gStringVar1, sHillData->tag.unkField_2, STR_CONV_MODE_LEFT_ALIGN, 1); gSpecialVar_Result = 0; } else @@ -370,14 +455,14 @@ void sub_81D5BBC(void) gSpecialVar_Result = 1; } - sub_81D5710(); + FreeDataStruct(); } void sub_81D5C00(void) { - sub_81D56B0(); + SetUpDataStruct(); gSpecialVar_Result = 0; - sub_81D5710(); + FreeDataStruct(); } bool8 sub_81D5C18(void) @@ -415,17 +500,17 @@ void PrintOnTrainerHillRecordsWindow(void) s32 i, x, y; u32 total, minutes, secondsWhole, secondsFraction; - sub_81D56B0(); + SetUpDataStruct(); FillWindowPixelBuffer(0, 0); x = GetStringCenterAlignXOffset(1, gText_TimeBoard, 0xD0); - AddTextPrinterParameterized3(0, 1, x, 2, gUnknown_0862A5F4, TEXT_SPEED_FF, gText_TimeBoard); + AddTextPrinterParameterized3(0, 1, x, 2, sRecordWinColors, TEXT_SPEED_FF, gText_TimeBoard); y = 18; for (i = 0; i < 4; i++) { - AddTextPrinterParameterized3(0, 1, 0, y, gUnknown_0862A5F4, TEXT_SPEED_FF, gUnknown_0862A660[i]); + AddTextPrinterParameterized3(0, 1, 0, y, sRecordWinColors, TEXT_SPEED_FF, sTagMatchStrings[i]); y += 15; - total = sub_81D5DF0(&gSaveBlock1Ptr->field_3718[i]); + total = GetTimerValue(&gSaveBlock1Ptr->trainerHillTimes[i]); minutes = total / (60 * 60); total %= (60 * 60); ConvertIntToDecimalStringN(gStringVar1, minutes, STR_CONV_MODE_RIGHT_ALIGN, 2); @@ -436,74 +521,75 @@ void PrintOnTrainerHillRecordsWindow(void) ConvertIntToDecimalStringN(gStringVar3, secondsFraction, STR_CONV_MODE_LEADING_ZEROS, 2); StringExpandPlaceholders(StringCopy(gStringVar4, gText_TimeCleared), gText_XMinYDotZSec); x = GetStringRightAlignXOffset(1, gStringVar4, 0xD0); - AddTextPrinterParameterized3(0, 1, x, y, gUnknown_0862A5F4, TEXT_SPEED_FF, gStringVar4); + AddTextPrinterParameterized3(0, 1, x, y, sRecordWinColors, TEXT_SPEED_FF, gStringVar4); y += 17; } PutWindowTilemap(0); CopyWindowToVram(0, 3); - sub_81D5710(); + FreeDataStruct(); } -// In fire red the counter had to be xored by the encryption key in Sav2. -u32 sub_81D5DF0(u32 *src) +// Leftover from Fire Red / Leaf Green as in these games, +// the timer had to be xored by the encryption key in Sav2. +u32 GetTimerValue(u32 *src) { return *src; } -void sub_81D5DF4(u32 *dst, u32 val) +void SetTimerValue(u32 *dst, u32 val) { *dst = val; } void sub_81D5DF8(void) { - u8 i, layoutId; + u8 i, floorId; struct EventObjectTemplate *eventTemplates = gSaveBlock1Ptr->eventObjectTemplates; if (!sub_81D5F48()) return; - sub_81D56B0(); + SetUpDataStruct(); for (i = 0; i < 2; i++) gSaveBlock2Ptr->frontier.field_CB4[i] = 0xFFFF; CpuFill32(0, gSaveBlock1Ptr->eventObjectTemplates, sizeof(gSaveBlock1Ptr->eventObjectTemplates)); - layoutId = sub_81D5520(); + floorId = GetFloorId(); for (i = 0; i < 2; i++) { u8 bits; eventTemplates[i] = gUnknown_0862A670; eventTemplates[i].localId = i + 1; - eventTemplates[i].graphicsId = FacilityClassToGraphicsId(gUnknown_0203CF54->unk4.unk0[layoutId].trainers[i].facilityClass); - eventTemplates[i].x = gUnknown_0203CF54->unk4.unk0[layoutId].coords[i] & 0xF; - eventTemplates[i].y = ((gUnknown_0203CF54->unk4.unk0[layoutId].coords[i] >> 4) & 0xF) + 5; + eventTemplates[i].graphicsId = FacilityClassToGraphicsId(sHillData->tag.floors[floorId].trainers[i].facilityClass); + eventTemplates[i].x = sHillData->tag.floors[floorId].coords[i] & 0xF; + eventTemplates[i].y = ((sHillData->tag.floors[floorId].coords[i] >> 4) & 0xF) + 5; bits = i << 2; - eventTemplates[i].movementType = ((gUnknown_0203CF54->unk4.unk0[layoutId].direction >> bits) & 0xF) + MOVEMENT_TYPE_FACE_UP; - eventTemplates[i].trainerRange_berryTreeId = (gUnknown_0203CF54->unk4.unk0[layoutId].range >> bits) & 0xF; + eventTemplates[i].movementType = ((sHillData->tag.floors[floorId].direction >> bits) & 0xF) + MOVEMENT_TYPE_FACE_UP; + eventTemplates[i].trainerRange_berryTreeId = (sHillData->tag.floors[floorId].range >> bits) & 0xF; eventTemplates[i].script = EventScript_2C83F0; gSaveBlock2Ptr->frontier.field_CB4[i] = i + 1; } - sub_81D5710(); + FreeDataStruct(); } bool32 sub_81D5F48(void) { - sub_81D56B0(); - sub_81D5710(); + SetUpDataStruct(); + FreeDataStruct(); return TRUE; } // Functionally equivalent. #ifdef NONMATCHING -u32 sub_81D5F58(u8 layoutId, u32 bit, u32 arg2, u32 arg3) +u32 sub_81D5F58(u8 floorId, u32 bit, u32 arg2, u32 arg3) { u32 var0, var1, var2, var3; - var0 = (gUnknown_0203CF54->unk4.unk0[layoutId].unk3A0[arg2] >> (15 - bit)) & 1; - var1 = gUnknown_0203CF54->unk4.unk0[layoutId].data[arg2 * arg3 + bit]; + var0 = (sHillData->tag.floors[floorId].unk3A0[arg2] >> (15 - bit)) & 1; + var1 = sHillData->tag.floors[floorId].data[arg2 * arg3 + bit]; var3 = 0x200; var2 = 0x3000; @@ -511,13 +597,13 @@ u32 sub_81D5F58(u8 layoutId, u32 bit, u32 arg2, u32 arg3) } #else NAKED -u32 sub_81D5F58(u8 layoutId, u32 bit, u32 arg2, u32 arg3) +u32 sub_81D5F58(u8 floorId, u32 bit, u32 arg2, u32 arg3) { asm_unified("\n\ push {r4,r5,lr}\n\ lsls r0, 24\n\ lsrs r0, 24\n\ - ldr r4, =gUnknown_0203CF54\n\ + ldr r4, =sHillData\n\ ldr r4, [r4]\n\ mov r12, r4\n\ lsls r4, r2, 1\n\ @@ -565,23 +651,23 @@ void sub_81D5FB4(u16 *mapArg) { s32 i, j; u16 *src, *dst; - u8 layoutId = GetCurrentTrainerHillMapId(); + u8 mapId = GetCurrentTrainerHillMapId(); - if (layoutId == 6) + if (mapId == 6) { InitMapFromSavedGame(); return; } - sub_81D56B0(); - if (layoutId == 5) + SetUpDataStruct(); + if (mapId == 5) { InitMapFromSavedGame(); - sub_81D5710(); + FreeDataStruct(); return; } - layoutId = sub_81D5520(); + mapId = GetFloorId(); src = gMapHeader.mapLayout->map; gBackupMapLayout.map = mapArg; gBackupMapLayout.width = 31; @@ -598,12 +684,12 @@ void sub_81D5FB4(u16 *mapArg) for (i = 0; i < 16; i++) { for (j = 0; j < 16; j++) - dst[j] = sub_81D5F58(layoutId, j, i, 0x10); + dst[j] = sub_81D5F58(mapId, j, i, 0x10); dst += 31; } mapheader_run_script_with_tag_x1(); - sub_81D5710(); + FreeDataStruct(); } bool32 InTrainerHill(void) @@ -685,8 +771,8 @@ u16 sub_81D6180(u8 localId) bool8 GetTrainerHillTrainerFlag(u8 eventObjectId) { - u32 layoutId = sub_81D5520() * 2; - u8 bitId = gEventObjects[eventObjectId].localId - 1 + layoutId; + u32 floorId = GetFloorId() * 2; + u8 bitId = gEventObjects[eventObjectId].localId - 1 + floorId; return gSaveBlock2Ptr->frontier.field_EE0 & gBitTable[bitId]; } @@ -694,13 +780,13 @@ bool8 GetTrainerHillTrainerFlag(u8 eventObjectId) void sub_81D61E8(void) { u8 i; - u8 layoutId = sub_81D5520() * 2; + u8 floorId = GetFloorId() * 2; for (i = 0; i < 2; i++) { if (gSaveBlock2Ptr->frontier.field_CB4[i] == gTrainerBattleOpponent_A) { - gSaveBlock2Ptr->frontier.field_EE0 |= gBitTable[layoutId + i]; + gSaveBlock2Ptr->frontier.field_EE0 |= gBitTable[floorId + i]; break; } } @@ -711,7 +797,7 @@ void sub_81D61E8(void) { if (gSaveBlock2Ptr->frontier.field_CB4[i] == gTrainerBattleOpponent_B) { - gSaveBlock2Ptr->frontier.field_EE0 |= gBitTable[layoutId + i]; + gSaveBlock2Ptr->frontier.field_EE0 |= gBitTable[floorId + i]; break; } } @@ -732,25 +818,25 @@ void sub_81D62B4(void) void sub_81D62CC(u16 trainerId, u8 firstMonId) { u8 trId, level; - s32 i, layoutId, arrId; + s32 i, floorId, arrId; if ((u16)(trainerId - 1) > 1) return; trId = trainerId - 1; - sub_81D56B0(); + SetUpDataStruct(); level = GetHighestLevelInPlayerParty(); - layoutId = sub_81D5520(); + floorId = GetFloorId(); for (i = firstMonId, arrId = 0; i < firstMonId + 3; i++, arrId++) { u8 id = gUnknown_0862A698[trId][arrId]; struct Pokemon *mon = &gEnemyParty[i]; - CreateBattleTowerMon(mon, &gUnknown_0203CF54->unk4.unk0[layoutId].trainers[trId].mons[id]); + CreateBattleTowerMon(mon, &sHillData->tag.floors[floorId].trainers[trId].mons[id]); sub_81D642C(mon, level); } - sub_81D5710(); + FreeDataStruct(); } void sub_81D6384(void) @@ -779,10 +865,10 @@ u8 sub_81D63C8(u16 trainerId) s32 i; u8 trId, facilityClass; - sub_81D56B0(); + SetUpDataStruct(); trId = trainerId - 1; - facilityClass = gUnknown_0203CF54->unk4.unk0[gUnknown_0203CF54->layoutId].trainers[trId].facilityClass; - sub_81D5710(); + facilityClass = sHillData->tag.floors[sHillData->floorId].trainers[trId].facilityClass; + FreeDataStruct(); for (i = 0; i < ARRAY_COUNT(gUnknown_0862A3B4); i++) { @@ -807,9 +893,9 @@ u8 sub_81D6490(void) { u8 ret; - sub_81D56B0(); - ret = gUnknown_0203CF54->unk4.unkField_2; - sub_81D5710(); + SetUpDataStruct(); + ret = sHillData->tag.unkField_2; + FreeDataStruct(); return ret; } @@ -862,8 +948,8 @@ void sub_81D6568(void) void sub_81D65A0(void) { - gSaveBlock1Ptr->trainerHill.field_3D6E_1 = gSpecialVar_0x8005; - gSaveBlock1Ptr->trainerHill.field_3D68 = gSaveBlock1Ptr->field_3718[gSpecialVar_0x8005]; + gSaveBlock1Ptr->trainerHill.tag = gSpecialVar_0x8005; + gSaveBlock1Ptr->trainerHill.field_3D68 = gSaveBlock1Ptr->trainerHillTimes[gSpecialVar_0x8005]; } u8 sub_81D65E8(u8 arg0) @@ -873,8 +959,8 @@ u8 sub_81D65E8(u8 arg0) var = 0; for (i = 0; i < 4; i++) { - var ^= gUnknown_0203CF54->unk4.unk0[i].unk0 & 0x1F; - var ^= gUnknown_0203CF54->unk4.unk0[i].unk1 & 0x1F; + var ^= sHillData->tag.floors[i].unk0 & 0x1F; + var ^= sHillData->tag.floors[i].unk1 & 0x1F; } if (arg0) @@ -894,18 +980,18 @@ u16 sub_81D6640(void) for (i = 0; i < 4; i++) { - var += gUnknown_0203CF54->unk4.unk0[i].unk0; - var += gUnknown_0203CF54->unk4.unk0[i].unk1; + var += sHillData->tag.floors[i].unk0; + var += sHillData->tag.floors[i].unk1; } var2 = var / 256; var2 %= 2; - if (FlagGet(FLAG_SYS_GAME_CLEAR) && gUnknown_0203CF54->unk4.unkField_0 == 8) + if (FlagGet(FLAG_SYS_GAME_CLEAR) && sHillData->tag.unkField_0 == 8) i = sub_81D65E8(1); else i = sub_81D65E8(0); - if (gSaveBlock1Ptr->trainerHill.field_3D6E_1 == 3) + if (gSaveBlock1Ptr->trainerHill.tag == HILL_TAG_EXPERT) i = (i + 1) % 10; ptr = gUnknown_0862A5CC[var2][i]; diff --git a/sym_ewram.txt b/sym_ewram.txt index 825a4632f..7b5b6663e 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -289,13 +289,5 @@ gUnknown_0203CF4C: @ 203CF4C gUnknown_0203CF50: @ 203CF50 .space 0x4 -gUnknown_0203CF54: @ 203CF54 - .space 0x4 - -gUnknown_0203CF58: @ 203CF58 - .space 0x4 - -gUnknown_0203CF5C: @ 203CF5C - .space 0x4 - + .include "src/trainer_hill.o" .include "src/rayquaza_scene.o"