From 382442c4c8754262c77acb50930df31c63a62355 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 12 Feb 2018 15:01:43 +0100 Subject: [PATCH] start decompiling overworld.s --- asm/battle_frontier_1.s | 2 +- asm/battle_frontier_2.s | 4 +- asm/battle_records.s | 6 +- asm/field_control_avatar.s | 2 +- asm/field_effect.s | 6 +- asm/field_screen.s | 4 +- asm/fieldmap.s | 2 +- asm/fldeff_flash.s | 2 +- asm/overworld.s | 1073 ++------------------------------- asm/party_menu.s | 4 +- asm/pokedex_area_screen.s | 6 +- asm/pokenav.s | 6 +- asm/post_battle_event_funcs.s | 2 +- asm/rom6.s | 2 +- asm/roulette.s | 2 +- data/event_scripts.s | 6 +- data/overworld.s | 52 -- include/constants/game_stat.h | 5 +- include/global.h | 19 +- include/overworld.h | 51 +- ld_script.txt | 3 +- src/battle_script_commands.c | 4 +- src/field_map_obj.c | 2 +- src/item_use.c | 4 +- src/overworld.c | 541 ++++++++++++++++- src/region_map.c | 12 +- sym_ewram.txt | 16 +- 27 files changed, 675 insertions(+), 1163 deletions(-) delete mode 100644 data/overworld.s diff --git a/asm/battle_frontier_1.s b/asm/battle_frontier_1.s index 60ac46859..43966b607 100644 --- a/asm/battle_frontier_1.s +++ b/asm/battle_frontier_1.s @@ -14665,7 +14665,7 @@ sub_819672C: @ 819672C ldrh r2, [r0, 0xA] ldrh r1, [r0, 0xC] adds r0, r2, 0 - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId ldrb r0, [r0, 0x14] pop {r1} bx r1 diff --git a/asm/battle_frontier_2.s b/asm/battle_frontier_2.s index 11220f369..491a87948 100644 --- a/asm/battle_frontier_2.s +++ b/asm/battle_frontier_2.s @@ -18683,7 +18683,7 @@ _081A4294: adds r0, r3, r4 ldrh r1, [r0] movs r0, 0x20 - bl sav12_xor_set + bl SetGameStat ldr r1, [r7] adds r0, r1, r6 adds r0, r4 @@ -31002,7 +31002,7 @@ sub_81AA810: @ 81AA810 ldrb r1, [r3] adds r1, 0x2C movs r0, 0x19 - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId adds r5, r0, 0 movs r7, 0 ldr r1, [r5, 0x4] diff --git a/asm/battle_records.s b/asm/battle_records.s index f688144d9..b203f339b 100644 --- a/asm/battle_records.s +++ b/asm/battle_records.s @@ -45,13 +45,13 @@ _0813BFCA: bge _0813BFCA movs r0, 0x17 movs r1, 0 - bl sav12_xor_set + bl SetGameStat movs r0, 0x18 movs r1, 0 - bl sav12_xor_set + bl SetGameStat movs r0, 0x19 movs r1, 0 - bl sav12_xor_set + bl SetGameStat pop {r4,r5} pop {r0} bx r0 diff --git a/asm/field_control_avatar.s b/asm/field_control_avatar.s index 89e6efa6a..240437049 100644 --- a/asm/field_control_avatar.s +++ b/asm/field_control_avatar.s @@ -2006,7 +2006,7 @@ _0809CF20: bl sub_8084D5C ldrb r0, [r5, 0x7] ldrb r1, [r5, 0x6] - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId ldr r1, [r0, 0x4] ldrb r0, [r5, 0x5] ldr r1, [r1, 0x8] diff --git a/asm/field_effect.s b/asm/field_effect.s index 80f2030aa..6d35cca61 100644 --- a/asm/field_effect.s +++ b/asm/field_effect.s @@ -2008,7 +2008,7 @@ _080B6A64: lsls r0, 24 cmp r0, 0 bne _080B6A8A - bl flag_var_implications_of_teleport_ + bl Overworld_ResetStateAfterFly bl warp_in ldr r0, =c2_load_new_map bl SetMainCallback2 @@ -4881,7 +4881,7 @@ _080B81B8: lsrs r0, 24 cmp r0, 0x1 bne _080B81E6 - bl copy_saved_warp3_bank_and_enter_x_to_warp1 + bl Overworld_SetWarpDestToLastHealLoc bl warp_in ldr r0, =c2_load_new_map bl SetMainCallback2 @@ -5211,7 +5211,7 @@ _080B8484: thumb_func_start sub_80B849C sub_80B849C: @ 80B849C push {r4,lr} - bl sav1_map_get_light_level + bl Overworld_GetMapTypeOfSaveblockLocation lsls r0, 24 lsrs r0, 24 bl is_light_level_1_2_3_5_or_6 diff --git a/asm/field_screen.s b/asm/field_screen.s index 0943fe1e3..0839e4bac 100644 --- a/asm/field_screen.s +++ b/asm/field_screen.s @@ -7855,7 +7855,7 @@ pal_fill_for_maplights: @ 80AF040 adds r4, r0, 0 lsls r4, 24 lsrs r4, 24 - bl sav1_map_get_light_level + bl Overworld_GetMapTypeOfSaveblockLocation adds r1, r0, 0 lsls r1, 24 lsrs r1, 24 @@ -7910,7 +7910,7 @@ pal_fill_black: @ 80AF0A0 thumb_func_start sub_80AF0B4 sub_80AF0B4: @ 80AF0B4 push {r4,lr} - bl sav1_map_get_light_level + bl Overworld_GetMapTypeOfSaveblockLocation adds r4, r0, 0 lsls r4, 24 lsrs r4, 24 diff --git a/asm/fieldmap.s b/asm/fieldmap.s index dbb8a3fa3..21aea8ad7 100644 --- a/asm/fieldmap.s +++ b/asm/fieldmap.s @@ -11,7 +11,7 @@ mapconnection_get_mapheader: @ 8087D44 ldrb r2, [r0, 0x8] ldrb r1, [r0, 0x9] adds r0, r2, 0 - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId pop {r1} bx r1 thumb_func_end mapconnection_get_mapheader diff --git a/asm/fldeff_flash.s b/asm/fldeff_flash.s index d52ee34fc..e7e605abe 100644 --- a/asm/fldeff_flash.s +++ b/asm/fldeff_flash.s @@ -217,7 +217,7 @@ sub_8137304: @ 8137304 bl get_map_light_from_warp0 lsls r0, 24 lsrs r6, r0, 24 - bl sav1_map_get_light_level + bl Overworld_GetMapTypeOfSaveblockLocation lsls r0, 24 lsrs r5, r0, 24 movs r3, 0 diff --git a/asm/overworld.s b/asm/overworld.s index 64ee678df..25c479c10 100644 --- a/asm/overworld.s +++ b/asm/overworld.s @@ -5,1008 +5,9 @@ .text - thumb_func_start sub_8084620 -sub_8084620: @ 8084620 - push {r4,lr} - ldr r0, =EverGrandeCity_HallOfFame_EventScript_271857 - bl ScriptContext2_RunNewScript - ldr r0, =gSaveBlock1Ptr - ldr r4, [r0] - movs r0, 0x92 - lsls r0, 3 - adds r4, r0 - adds r0, r4, 0 - bl GetMoney - adds r1, r0, 0 - lsrs r1, 1 - adds r0, r4, 0 - bl SetMoney - bl HealPlayerParty - bl sub_8084720 - bl copy_saved_warp3_bank_and_enter_x_to_warp1 - bl warp_in - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8084620 - - thumb_func_start flag_var_implications_of_teleport_ -flag_var_implications_of_teleport_: @ 8084660 - push {lr} - bl player_avatar_init_params_reset - ldr r0, =0x0000088b - bl FlagClear - ldr r0, =0x0000088d - bl FlagClear - ldr r0, =0x0000088c - bl FlagClear - ldr r0, =0x00000889 - bl FlagClear - ldr r0, =0x00000888 - bl FlagClear - pop {r0} - bx r0 - .pool - thumb_func_end flag_var_implications_of_teleport_ - - thumb_func_start Overworld_ResetStateAfterTeleport -Overworld_ResetStateAfterTeleport: @ 808469C - push {lr} - bl player_avatar_init_params_reset - ldr r0, =0x0000088b - bl FlagClear - ldr r0, =0x0000088d - bl FlagClear - ldr r0, =0x0000088c - bl FlagClear - ldr r0, =0x00000889 - bl FlagClear - ldr r0, =0x00000888 - bl FlagClear - ldr r0, =EverGrandeCity_HallOfFame_EventScript_271862 - bl ScriptContext2_RunNewScript - pop {r0} - bx r0 - .pool - thumb_func_end Overworld_ResetStateAfterTeleport - - thumb_func_start flagmods_08054D70 -flagmods_08054D70: @ 80846E4 - push {lr} - bl player_avatar_init_params_reset - ldr r0, =0x0000088b - bl FlagClear - ldr r0, =0x0000088d - bl FlagClear - ldr r0, =0x0000088c - bl FlagClear - ldr r0, =0x00000889 - bl FlagClear - ldr r0, =0x00000888 - bl FlagClear - pop {r0} - bx r0 - .pool - thumb_func_end flagmods_08054D70 - - thumb_func_start sub_8084720 -sub_8084720: @ 8084720 - push {r4,lr} - bl player_avatar_init_params_reset - ldr r0, =0x0000088b - bl FlagClear - ldr r0, =0x0000088d - bl FlagClear - ldr r0, =0x0000088c - bl FlagClear - ldr r0, =0x00000889 - bl FlagClear - ldr r0, =0x00000888 - bl FlagClear - ldr r4, =0x00004039 - adds r0, r4, 0 - bl VarGet - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x1 - bne _08084764 - adds r0, r4, 0 - movs r1, 0 - bl VarSet - ldr r0, =0x00004037 - movs r1, 0 - bl VarSet -_08084764: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8084720 - - thumb_func_start sub_8084788 -sub_8084788: @ 8084788 - push {lr} - ldr r0, =0x0000088c - bl FlagClear - bl sub_8085B2C - bl ResetCyclingRoadChallengeData - bl UpdateLocationHistoryForRoamer - bl RoamerMoveToOtherLocationSet - pop {r0} - bx r0 - .pool - thumb_func_end sub_8084788 - - thumb_func_start ResetGameStats -ResetGameStats: @ 80847A8 - push {r4,lr} - movs r4, 0 -_080847AC: - lsls r0, r4, 24 - lsrs r0, 24 - movs r1, 0 - bl sav12_xor_set - adds r4, 0x1 - cmp r4, 0x3F - ble _080847AC - pop {r4} - pop {r0} - bx r0 - thumb_func_end ResetGameStats - - thumb_func_start IncrementGameStat -@ void IncrementGameStat(u8 a1) -IncrementGameStat: @ 80847C4 - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x33 - bhi _080847EC - adds r0, r4, 0 - bl GetGameStat - adds r1, r0, 0 - ldr r0, =0x00fffffe - cmp r1, r0 - bhi _080847E4 - adds r1, 0x1 - b _080847E6 - .pool -_080847E4: - ldr r1, =0x00ffffff -_080847E6: - adds r0, r4, 0 - bl sav12_xor_set -_080847EC: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end IncrementGameStat - - thumb_func_start GetGameStat -GetGameStat: @ 80847F8 - push {lr} - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0x33 - bhi _08084828 - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - lsls r0, r1, 2 - ldr r1, =0x0000159c - adds r2, r1 - adds r2, r0 - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - adds r1, 0xAC - ldr r0, [r2] - ldr r1, [r1] - eors r0, r1 - b _0808482A - .pool -_08084828: - movs r0, 0 -_0808482A: - pop {r1} - bx r1 - thumb_func_end GetGameStat - - thumb_func_start sav12_xor_set -sav12_xor_set: @ 8084830 - push {lr} - adds r3, r1, 0 - lsls r0, 24 - lsrs r2, r0, 24 - cmp r2, 0x33 - bhi _08084854 - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - lsls r0, r2, 2 - ldr r2, =0x0000159c - adds r1, r2 - adds r1, r0 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - adds r0, 0xAC - ldr r0, [r0] - eors r0, r3 - str r0, [r1] -_08084854: - pop {r0} - bx r0 - .pool - thumb_func_end sav12_xor_set - - thumb_func_start ApplyNewEncryptionKeyToGameStats -ApplyNewEncryptionKeyToGameStats: @ 8084864 - push {r4-r6,lr} - adds r5, r0, 0 - movs r4, 0 - ldr r6, =gSaveBlock1Ptr -_0808486C: - lsls r1, r4, 2 - ldr r0, =0x0000159c - adds r1, r0 - ldr r0, [r6] - adds r0, r1 - adds r1, r5, 0 - bl ApplyNewEncryptionKeyToWord - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x3F - bls _0808486C - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end ApplyNewEncryptionKeyToGameStats - - thumb_func_start CopyFieldObjectTemplatesToSav1 -@ void CopyFieldObjectTemplatesToSav1() -CopyFieldObjectTemplatesToSav1: @ 8084894 - push {r4,r5,lr} - sub sp, 0x4 - movs r0, 0 - str r0, [sp] - ldr r5, =gSaveBlock1Ptr - ldr r1, [r5] - movs r4, 0xC7 - lsls r4, 4 - adds r1, r4 - ldr r2, =0x05000180 - mov r0, sp - bl CpuSet - ldr r0, =gMapHeader - ldr r2, [r0, 0x4] - ldr r0, [r2, 0x4] - ldr r1, [r5] - adds r1, r4 - ldrb r3, [r2] - lsls r2, r3, 1 - adds r2, r3 - lsls r2, 1 - movs r3, 0x80 - lsls r3, 19 - orrs r2, r3 - bl CpuSet - add sp, 0x4 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end CopyFieldObjectTemplatesToSav1 - - thumb_func_start CopyFieldObjectTemplateCoordsToSav1 -@ void CopyFieldObjectTemplateCoordsToSav1() -CopyFieldObjectTemplateCoordsToSav1: @ 80848E0 - push {lr} - ldr r0, =gMapHeader - ldr r1, [r0, 0x4] - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r2, [r1, 0x4] - movs r3, 0xC7 - lsls r3, 4 - adds r1, r0, r3 - movs r3, 0x3F -_080848F4: - ldr r0, [r2, 0x10] - str r0, [r1, 0x10] - adds r2, 0x18 - adds r1, 0x18 - subs r3, 0x1 - cmp r3, 0 - bge _080848F4 - pop {r0} - bx r0 - .pool - thumb_func_end CopyFieldObjectTemplateCoordsToSav1 - - thumb_func_start Overworld_SetMapObjTemplateCoords -Overworld_SetMapObjTemplateCoords: @ 8084910 - push {r4-r6,lr} - lsls r0, 24 - lsrs r5, r0, 24 - lsls r1, 16 - lsrs r4, r1, 16 - lsls r2, 16 - lsrs r2, 16 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0 - movs r6, 0xC7 - lsls r6, 4 - adds r3, r0, r6 -_0808492A: - ldrb r0, [r3] - cmp r0, r5 - bne _0808493C - strh r4, [r3, 0x4] - strh r2, [r3, 0x6] - b _08084944 - .pool -_0808493C: - adds r3, 0x18 - adds r1, 0x1 - cmp r1, 0x3F - ble _0808492A -_08084944: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end Overworld_SetMapObjTemplateCoords - - thumb_func_start Overworld_SetMapObjTemplateMovementType -Overworld_SetMapObjTemplateMovementType: @ 808494C - push {r4,r5,lr} - lsls r0, 24 - lsrs r4, r0, 24 - lsls r1, 24 - lsrs r1, 24 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r3, 0 - movs r5, 0xC7 - lsls r5, 4 - adds r2, r0, r5 -_08084962: - ldrb r0, [r2] - cmp r0, r4 - bne _08084970 - strb r1, [r2, 0x9] - b _08084978 - .pool -_08084970: - adds r2, 0x18 - adds r3, 0x1 - cmp r3, 0x3F - ble _08084962 -_08084978: - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end Overworld_SetMapObjTemplateMovementType - - thumb_func_start mapdata_load_assets_to_gpu_and_full_redraw -mapdata_load_assets_to_gpu_and_full_redraw: @ 8084980 - push {r4,lr} - bl move_tilemap_camera_to_upper_left_corner - ldr r4, =gMapHeader - ldr r0, [r4] - bl copy_map_tileset1_tileset2_to_vram - ldr r0, [r4] - bl apply_map_tileset1_tileset2_palette - bl DrawWholeMapView - bl cur_mapheader_run_tileset_funcs_after_some_cpuset - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end mapdata_load_assets_to_gpu_and_full_redraw - - thumb_func_start get_mapdata_header -@ mapdata_header *get_mapdata_header() -get_mapdata_header: @ 80849A8 - push {lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldrh r1, [r0, 0x32] - cmp r1, 0 - bne _080849BC - movs r0, 0 - b _080849C6 - .pool -_080849BC: - ldr r0, =gMapAttributes - subs r1, 0x1 - lsls r1, 2 - adds r1, r0 - ldr r0, [r1] -_080849C6: - pop {r1} - bx r1 - .pool - thumb_func_end get_mapdata_header - - thumb_func_start warp_shift -@ void warp_shift() -warp_shift: @ 80849D0 - ldr r3, =gUnknown_020322DC - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - ldr r0, [r2, 0x4] - ldr r1, [r2, 0x8] - str r0, [r3] - str r1, [r3, 0x4] - ldr r0, =gUnknown_020322E4 - ldr r1, [r0, 0x4] - ldr r0, [r0] - str r0, [r2, 0x4] - str r1, [r2, 0x8] - ldr r2, =gUnknown_020322EC - ldr r0, =gUnknown_08339D3C - ldr r1, [r0, 0x4] - ldr r0, [r0] - str r0, [r2] - str r1, [r2, 0x4] - ldr r2, =gUnknown_020322F4 - str r0, [r2] - str r1, [r2, 0x4] - bx lr - .pool - thumb_func_end warp_shift - - thumb_func_start set_warp2_warp3_to_neg_1 -@ void set_warp2_warp3_to_neg_1() -set_warp2_warp3_to_neg_1: @ 8084A14 - ldr r2, =gUnknown_020322EC - ldr r0, =gUnknown_08339D3C - ldr r1, [r0, 0x4] - ldr r0, [r0] - str r0, [r2] - str r1, [r2, 0x4] - ldr r2, =gUnknown_020322F4 - str r0, [r2] - str r1, [r2, 0x4] - bx lr - .pool - thumb_func_end set_warp2_warp3_to_neg_1 - - thumb_func_start warp_set -@ void warp_set(warpdata *warp, char bank, char map, char warpid, char enter_x, char enter_y) -warp_set: @ 8084A34 - push {r4,r5,lr} - ldr r4, [sp, 0xC] - ldr r5, [sp, 0x10] - strb r1, [r0] - strb r2, [r0, 0x1] - strb r3, [r0, 0x2] - lsls r4, 24 - asrs r4, 24 - strh r4, [r0, 0x4] - lsls r5, 24 - asrs r5, 24 - strh r5, [r0, 0x6] - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end warp_set - - thumb_func_start warp_data_is_not_neg_1 -@ int warp_data_is_not_neg_1(warpdata *warp) -warp_data_is_not_neg_1: @ 8084A54 - push {lr} - adds r1, r0, 0 - movs r2, 0 - ldrsb r2, [r1, r2] - movs r0, 0x1 - negs r0, r0 - cmp r2, r0 - bne _08084A88 - movs r0, 0x1 - ldrsb r0, [r1, r0] - cmp r0, r2 - bne _08084A88 - movs r2, 0x2 - ldrsb r2, [r1, r2] - cmp r2, r0 - bne _08084A88 - movs r0, 0x4 - ldrsh r3, [r1, r0] - cmp r3, r2 - bne _08084A88 - movs r2, 0x6 - ldrsh r0, [r1, r2] - cmp r0, r3 - bne _08084A88 - movs r0, 0x1 - b _08084A8A -_08084A88: - movs r0, 0 -_08084A8A: - pop {r1} - bx r1 - thumb_func_end warp_data_is_not_neg_1 - - thumb_func_start get_mapheader_by_bank_and_number -@ struct mapheader *get_mapheader_by_bank_and_number(unsigned int bank, unsigned int num) -get_mapheader_by_bank_and_number: @ 8084A90 - lsls r0, 16 - lsls r1, 16 - ldr r2, =gMapGroups - lsrs r0, 14 - adds r0, r2 - ldr r0, [r0] - lsrs r1, 14 - adds r1, r0 - ldr r0, [r1] - bx lr - .pool - thumb_func_end get_mapheader_by_bank_and_number - - thumb_func_start warp1_get_mapheader -@ struct mapheader *warp1_get_mapheader() -warp1_get_mapheader: @ 8084AA8 - push {lr} - ldr r1, =gUnknown_020322E4 - movs r0, 0 - ldrsb r0, [r1, r0] - lsls r0, 16 - lsrs r0, 16 - ldrb r1, [r1, 0x1] - lsls r1, 24 - asrs r1, 24 - lsls r1, 16 - lsrs r1, 16 - bl get_mapheader_by_bank_and_number - pop {r1} - bx r1 - .pool - thumb_func_end warp1_get_mapheader - - thumb_func_start set_current_map_header_from_sav1_save_old_name -@ void set_current_map_header_from_sav1_save_old_name() -set_current_map_header_from_sav1_save_old_name: @ 8084ACC - push {r4-r6,lr} - ldr r1, =gUnknown_020322FC - ldr r4, =gMapHeader - ldrb r0, [r4, 0x14] - strh r0, [r1] - ldr r5, =gSaveBlock1Ptr - ldr r1, [r5] - movs r0, 0x4 - ldrsb r0, [r1, r0] - lsls r0, 16 - lsrs r0, 16 - ldrb r1, [r1, 0x5] - lsls r1, 24 - asrs r1, 24 - lsls r1, 16 - lsrs r1, 16 - bl get_mapheader_by_bank_and_number - adds r1, r4, 0 - ldm r0!, {r2,r3,r6} - stm r1!, {r2,r3,r6} - ldm r0!, {r2,r3,r6} - stm r1!, {r2,r3,r6} - ldr r0, [r0] - str r0, [r1] - ldr r1, [r5] - ldrh r0, [r4, 0x12] - strh r0, [r1, 0x32] - bl get_mapdata_header - str r0, [r4] - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end set_current_map_header_from_sav1_save_old_name - - thumb_func_start set_current_map_header_from_sav1 -set_current_map_header_from_sav1: @ 8084B1C - push {r4,r5,lr} - ldr r4, =gMapHeader - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - movs r0, 0x4 - ldrsb r0, [r1, r0] - lsls r0, 16 - lsrs r0, 16 - ldrb r1, [r1, 0x5] - lsls r1, 24 - asrs r1, 24 - lsls r1, 16 - lsrs r1, 16 - bl get_mapheader_by_bank_and_number - adds r1, r4, 0 - ldm r0!, {r2,r3,r5} - stm r1!, {r2,r3,r5} - ldm r0!, {r2,r3,r5} - stm r1!, {r2,r3,r5} - ldr r0, [r0] - str r0, [r1] - bl get_mapdata_header - str r0, [r4] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end set_current_map_header_from_sav1 - - thumb_func_start update_camera_pos_from_warpid -@ void update_camera_pos_from_warpid() -update_camera_pos_from_warpid: @ 8084B5C - push {r4,r5,lr} - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - movs r1, 0x6 - ldrsb r1, [r2, r1] - adds r4, r0, 0 - cmp r1, 0 - blt _08084B94 - ldr r3, =gMapHeader - ldr r0, [r3, 0x4] - ldrb r5, [r0, 0x1] - cmp r1, r5 - bge _08084B94 - ldr r0, [r0, 0x8] - lsls r1, 3 - adds r0, r1, r0 - ldrh r0, [r0] - strh r0, [r2] - ldr r0, [r3, 0x4] - ldr r0, [r0, 0x8] - adds r1, r0 - ldrh r0, [r1, 0x2] - strh r0, [r2, 0x2] - b _08084BCC - .pool -_08084B94: - ldr r1, [r4] - ldrh r3, [r1, 0x8] - movs r2, 0x8 - ldrsh r0, [r1, r2] - cmp r0, 0 - blt _08084BB0 - ldrh r2, [r1, 0xA] - movs r5, 0xA - ldrsh r0, [r1, r5] - cmp r0, 0 - blt _08084BB0 - strh r3, [r1] - strh r2, [r1, 0x2] - b _08084BCC -_08084BB0: - ldr r3, [r4] - ldr r2, =gMapHeader - ldr r0, [r2] - ldr r0, [r0] - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - strh r0, [r3] - ldr r0, [r2] - ldr r0, [r0, 0x4] - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - strh r0, [r3, 0x2] -_08084BCC: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end update_camera_pos_from_warpid - - thumb_func_start warp_in -warp_in: @ 8084BD8 - push {lr} - bl warp_shift - bl set_current_map_header_from_sav1_save_old_name - bl update_camera_pos_from_warpid - pop {r0} - bx r0 - thumb_func_end warp_in - - thumb_func_start Overworld_SetWarpDestination -@ void Overworld_SetWarpDestination(char bank, char map, char warpid, char enter_x, char enter_y) -Overworld_SetWarpDestination: @ 8084BEC - push {r4-r6,lr} - sub sp, 0x8 - adds r4, r0, 0 - adds r5, r1, 0 - adds r6, r2, 0 - ldr r1, [sp, 0x18] - ldr r0, =gUnknown_020322E4 - lsls r4, 24 - asrs r4, 24 - lsls r5, 24 - asrs r5, 24 - lsls r6, 24 - asrs r6, 24 - lsls r3, 24 - asrs r3, 24 - str r3, [sp] - lsls r1, 24 - asrs r1, 24 - str r1, [sp, 0x4] - adds r1, r4, 0 - adds r2, r5, 0 - adds r3, r6, 0 - bl warp_set - add sp, 0x8 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end Overworld_SetWarpDestination - - thumb_func_start warp1_set_2 -@ void warp1_set_2(char bank, char map, char warpid) -warp1_set_2: @ 8084C28 - push {lr} - sub sp, 0x4 - lsls r0, 24 - asrs r0, 24 - lsls r1, 24 - asrs r1, 24 - lsls r2, 24 - asrs r2, 24 - movs r3, 0x1 - negs r3, r3 - str r3, [sp] - bl Overworld_SetWarpDestination - add sp, 0x4 - pop {r0} - bx r0 - thumb_func_end warp1_set_2 - - thumb_func_start saved_warp2_set -@ void saved_warp2_set(char bank, char map, char warpid) -saved_warp2_set: @ 8084C48 - push {r4,r5,lr} - sub sp, 0x8 - ldr r0, =gSaveBlock1Ptr - ldr r5, [r0] - adds r0, r5, 0 - adds r0, 0x14 - lsls r1, 24 - asrs r1, 24 - lsls r2, 24 - asrs r2, 24 - lsls r3, 24 - asrs r3, 24 - movs r4, 0 - ldrsb r4, [r5, r4] - str r4, [sp] - movs r4, 0x2 - ldrsb r4, [r5, r4] - str r4, [sp, 0x4] - bl warp_set - add sp, 0x8 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end saved_warp2_set - - thumb_func_start saved_warp2_set_2 -saved_warp2_set_2: @ 8084C7C - push {r4,r5,lr} - sub sp, 0x8 - ldr r4, [sp, 0x14] - ldr r5, [sp, 0x18] - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - adds r0, 0x14 - lsls r1, 24 - asrs r1, 24 - lsls r2, 24 - asrs r2, 24 - lsls r3, 24 - asrs r3, 24 - lsls r4, 24 - asrs r4, 24 - str r4, [sp] - lsls r5, 24 - asrs r5, 24 - str r5, [sp, 0x4] - bl warp_set - add sp, 0x8 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end saved_warp2_set_2 - - thumb_func_start copy_saved_warp2_bank_and_enter_x_to_warp1 -copy_saved_warp2_bank_and_enter_x_to_warp1: @ 8084CB4 - ldr r2, =gUnknown_020322E4 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, [r0, 0x18] - ldr r0, [r0, 0x14] - str r0, [r2] - str r1, [r2, 0x4] - bx lr - .pool - thumb_func_end copy_saved_warp2_bank_and_enter_x_to_warp1 - - thumb_func_start sub_8084CCC -@ void sub_8084CCC(int a1) -sub_8084CCC: @ 8084CCC - push {r4,lr} - sub sp, 0x4 - lsls r0, 24 - lsrs r0, 24 - bl GetHealLocationPointer - adds r4, r0, 0 - cmp r4, 0 - beq _08084CFA - movs r0, 0 - ldrsb r0, [r4, r0] - movs r1, 0x1 - ldrsb r1, [r4, r1] - movs r2, 0x1 - negs r2, r2 - movs r3, 0x2 - ldrsb r3, [r4, r3] - ldrb r4, [r4, 0x4] - lsls r4, 24 - asrs r4, 24 - str r4, [sp] - bl Overworld_SetWarpDestination -_08084CFA: - add sp, 0x4 - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_8084CCC - - thumb_func_start copy_saved_warp3_bank_and_enter_x_to_warp1 -@ void copy_saved_warp3_bank_and_enter_x_to_warp1() -copy_saved_warp3_bank_and_enter_x_to_warp1: @ 8084D04 - ldr r2, =gUnknown_020322E4 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, [r0, 0x20] - ldr r0, [r0, 0x1C] - str r0, [r2] - str r1, [r2, 0x4] - bx lr - .pool - thumb_func_end copy_saved_warp3_bank_and_enter_x_to_warp1 - - thumb_func_start Overworld_SetHealLocationWarp -Overworld_SetHealLocationWarp: @ 8084D1C - push {r4,r5,lr} - sub sp, 0x8 - lsls r0, 24 - lsrs r0, 24 - bl GetHealLocationPointer - adds r5, r0, 0 - cmp r5, 0 - beq _08084D50 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - adds r0, 0x1C - movs r1, 0 - ldrsb r1, [r5, r1] - movs r2, 0x1 - ldrsb r2, [r5, r2] - movs r3, 0x1 - negs r3, r3 - movs r4, 0x2 - ldrsb r4, [r5, r4] - str r4, [sp] - movs r4, 0x4 - ldrsb r4, [r5, r4] - str r4, [sp, 0x4] - bl warp_set -_08084D50: - add sp, 0x8 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end Overworld_SetHealLocationWarp - - thumb_func_start sub_8084D5C -sub_8084D5C: @ 8084D5C - push {r4-r7,lr} - sub sp, 0x4 - lsls r0, 16 - lsrs r6, r0, 16 - lsls r1, 16 - lsrs r7, r1, 16 - bl sav1_map_get_light_level - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - ldr r1, =gUnknown_020322E4 - movs r0, 0 - ldrsb r0, [r1, r0] - ldrb r1, [r1, 0x1] - lsls r1, 24 - asrs r1, 24 - bl get_map_light_level_by_bank_and_number - lsls r0, 24 - lsrs r5, r0, 24 - adds r0, r4, 0 - bl is_light_level_1_2_3_5_or_6 - lsls r0, 24 - cmp r0, 0 - beq _08084DC4 - adds r0, r5, 0 - bl is_light_level_1_2_3_5_or_6 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - beq _08084DC4 - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - movs r0, 0x4 - ldrsb r0, [r1, r0] - ldrb r1, [r1, 0x5] - lsls r1, 24 - asrs r1, 24 - movs r2, 0x1 - negs r2, r2 - subs r3, r6, 0x7 - lsls r3, 24 - asrs r3, 24 - subs r4, r7, 0x6 - lsls r4, 24 - asrs r4, 24 - str r4, [sp] - bl sub_8084DD4 -_08084DC4: - add sp, 0x4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8084D5C - - thumb_func_start sub_8084DD4 -sub_8084DD4: @ 8084DD4 - push {r4-r6,lr} - sub sp, 0x8 - adds r4, r0, 0 - adds r5, r1, 0 - adds r6, r2, 0 - ldr r1, [sp, 0x18] - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - adds r0, 0x24 - lsls r4, 24 - asrs r4, 24 - lsls r5, 24 - asrs r5, 24 - lsls r6, 24 - asrs r6, 24 - lsls r3, 24 - asrs r3, 24 - str r3, [sp] - lsls r1, 24 - asrs r1, 24 - str r1, [sp, 0x4] - adds r1, r4, 0 - adds r2, r5, 0 - adds r3, r6, 0 - bl warp_set - add sp, 0x8 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8084DD4 - thumb_func_start sub_8084E14 sub_8084E14: @ 8084E14 - ldr r2, =gUnknown_020322E4 + ldr r2, =gWarpDestination ldr r0, =gSaveBlock1Ptr ldr r0, [r0] ldr r1, [r0, 0x28] @@ -1041,7 +42,7 @@ sub_8084E2C: @ 8084E2C adds r1, r4, 0 adds r2, r5, 0 adds r3, r6, 0 - bl warp_set + bl SetWarpData add sp, 0x8 pop {r4-r6} pop {r0} @@ -1051,7 +52,7 @@ sub_8084E2C: @ 8084E2C thumb_func_start warp1_set_to_warp2 warp1_set_to_warp2: @ 8084E68 - ldr r2, =gUnknown_020322E4 + ldr r2, =gWarpDestination ldr r0, =gUnknown_020322EC ldr r1, [r0, 0x4] ldr r0, [r0] @@ -1085,7 +86,7 @@ sub_8084E80: @ 8084E80 adds r1, r4, 0 adds r2, r5, 0 adds r3, r6, 0 - bl warp_set + bl SetWarpData add sp, 0x8 pop {r4-r6} pop {r0} @@ -1106,7 +107,7 @@ sub_8084EBC: @ 8084EBC bl warp_data_is_not_neg_1 cmp r0, 0x1 bne _08084EF0 - ldr r2, =gUnknown_020322E4 + ldr r2, =gWarpDestination ldr r0, =gUnknown_020322DC ldr r1, [r0, 0x4] ldr r0, [r0] @@ -1136,7 +137,7 @@ _08084F0A: thumb_func_start warp1_set_to_sav1w warp1_set_to_sav1w: @ 8084F14 - ldr r2, =gUnknown_020322E4 + ldr r2, =gWarpDestination ldr r0, =gSaveBlock1Ptr ldr r0, [r0] ldr r1, [r0, 0x10] @@ -1173,7 +174,7 @@ sub_8084F2C: @ 8084F2C adds r1, r4, 0 adds r2, r5, 0 adds r3, r6, 0 - bl warp_set + bl SetWarpData add sp, 0x8 pop {r4-r6} pop {r0} @@ -1206,7 +207,7 @@ sub_8084F6C: @ 8084F6C movs r4, 0x4 ldrsb r4, [r5, r4] str r4, [sp, 0x4] - bl warp_set + bl SetWarpData _08084FA0: add sp, 0x8 pop {r4,r5} @@ -1372,9 +373,9 @@ mliX_load_map: @ 8085098 beq _080850C8 bl sub_8085810 _080850C8: - bl warp_shift + bl ApplyCurrentWarp bl set_current_map_header_from_sav1_save_old_name - bl CopyFieldObjectTemplatesToSav1 + bl LoadMapObjTemplatesFromHeader bl TrySetMapSaveWarpStatus bl ClearTempFieldEventData bl ResetCyclingRoadChallengeData @@ -1384,7 +385,7 @@ _080850C8: bl TryUpdateRandomTrainerRematches bl DoTimeBasedEvents bl SetSav1WeatherFromCurrMapHeader - bl sub_8085B2C + bl ChooseAmbientCrySpecies bl update_sav1_flash_used_on_map bl Overworld_ClearSavedMusic bl mapheader_run_script_with_tag_x3 @@ -1411,7 +412,7 @@ _08085116: ldrb r0, [r2, 0x14] cmp r0, 0x3A bne _0808514C - ldr r1, =gUnknown_020322FC + ldr r1, =gLastMapSectionId ldrh r1, [r1] cmp r0, r1 beq _08085150 @@ -1451,7 +452,7 @@ _08085190: bl sub_81D5DF8 b _080851A2 _0808519E: - bl CopyFieldObjectTemplatesToSav1 + bl LoadMapObjTemplatesFromHeader _080851A2: ldr r4, =gMapHeader ldrb r0, [r4, 0x17] @@ -1484,7 +485,7 @@ _080851A2: bl DoTimeBasedEvents _080851EE: bl SetSav1WeatherFromCurrMapHeader - bl sub_8085B2C + bl ChooseAmbientCrySpecies cmp r5, 0 beq _08085200 ldr r0, =0x00000888 @@ -1589,7 +590,7 @@ _080852CA: thumb_func_start sub_80852D4 sub_80852D4: @ 80852D4 push {r4-r7,lr} - bl sav1_map_get_light_level + bl Overworld_GetMapTypeOfSaveblockLocation adds r5, r0, 0 lsls r5, 24 lsrs r5, 24 @@ -2111,7 +1112,7 @@ _080856A4: ldrsb r1, [r4, r1] lsls r1, 16 lsrs r1, 16 - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId ldrh r0, [r0, 0x10] b _080856CE _080856CA: @@ -2175,7 +1176,7 @@ _08085730: thumb_func_start warp1_target_get_music warp1_target_get_music: @ 8085738 push {lr} - ldr r0, =gUnknown_020322E4 + ldr r0, =gWarpDestination bl warp_target_get_music lsls r0, 16 lsrs r1, r0, 16 @@ -2233,7 +1234,7 @@ Overworld_PlaySpecialMapMusic: @ 8085784 b _080857D6 .pool _080857B4: - bl sav1_map_get_light_level + bl Overworld_GetMapTypeOfSaveblockLocation lsls r0, 24 lsrs r0, 24 cmp r0, 0x5 @@ -2441,7 +1442,7 @@ music_something: @ 8085910 lsls r0, 3 cmp r2, r0 bne _08085972 - ldr r3, =gUnknown_020322E4 + ldr r3, =gWarpDestination ldrh r0, [r3] ands r1, r0 cmp r1, r2 @@ -2658,8 +1659,8 @@ _08085B20: bx r0 thumb_func_end wild_encounter_related - thumb_func_start sub_8085B2C -sub_8085B2C: @ 8085B2C + thumb_func_start ChooseAmbientCrySpecies +ChooseAmbientCrySpecies: @ 8085B2C push {lr} ldr r0, =gSaveBlock1Ptr ldr r0, [r0] @@ -2687,11 +1688,11 @@ _08085B62: pop {r0} bx r0 .pool - thumb_func_end sub_8085B2C + thumb_func_end ChooseAmbientCrySpecies - thumb_func_start get_map_light_level_by_bank_and_number -@ int get_map_light_level_by_bank_and_number(int bank, int number) -get_map_light_level_by_bank_and_number: @ 8085B74 + thumb_func_start GetMapTypeByGroupAndId +@ int GetMapTypeByGroupAndId(int bank, int number) +GetMapTypeByGroupAndId: @ 8085B74 push {lr} lsls r0, 24 asrs r0, 8 @@ -2699,11 +1700,11 @@ get_map_light_level_by_bank_and_number: @ 8085B74 lsls r1, 24 asrs r1, 8 lsrs r1, 16 - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId ldrb r0, [r0, 0x17] pop {r1} bx r1 - thumb_func_end get_map_light_level_by_bank_and_number + thumb_func_end GetMapTypeByGroupAndId thumb_func_start get_map_light_level_from_warp @ int get_map_light_level_from_warp(warpdata *warp) @@ -2714,15 +1715,15 @@ get_map_light_level_from_warp: @ 8085B8C movs r1, 0x1 ldrsb r1, [r0, r1] adds r0, r2, 0 - bl get_map_light_level_by_bank_and_number + bl GetMapTypeByGroupAndId lsls r0, 24 lsrs r0, 24 pop {r1} bx r1 thumb_func_end get_map_light_level_from_warp - thumb_func_start sav1_map_get_light_level -sav1_map_get_light_level: @ 8085BA4 + thumb_func_start Overworld_GetMapTypeOfSaveblockLocation +Overworld_GetMapTypeOfSaveblockLocation: @ 8085BA4 push {lr} ldr r0, =gSaveBlock1Ptr ldr r0, [r0] @@ -2733,7 +1734,7 @@ sav1_map_get_light_level: @ 8085BA4 pop {r1} bx r1 .pool - thumb_func_end sav1_map_get_light_level + thumb_func_end Overworld_GetMapTypeOfSaveblockLocation thumb_func_start get_map_light_from_warp0 get_map_light_from_warp0: @ 8085BBC @@ -2828,7 +1829,7 @@ sav1_saved_warp2_map_get_name: @ 8085C30 asrs r1, 24 lsls r1, 16 lsrs r1, 16 - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId ldrb r0, [r0, 0x14] pop {r1} bx r1 @@ -2849,7 +1850,7 @@ sav1_map_get_name: @ 8085C58 asrs r1, 24 lsls r1, 16 lsrs r1, 16 - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId ldrb r0, [r0, 0x14] pop {r1} bx r1 @@ -2870,7 +1871,7 @@ GetCurrentMapBattleScene: @ 8085C80 asrs r1, 24 lsls r1, 16 lsrs r1, 16 - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId ldrb r0, [r0, 0x1B] pop {r1} bx r1 @@ -3210,7 +2211,7 @@ CB2_WhiteOut: @ 8085F58 bl sub_808631C bl StopMapMusic bl ResetSafariZoneFlag_ - bl sub_8084620 + bl DoWhiteOut bl player_avatar_init_params_reset bl ScriptContext1_Init bl ScriptContext2_Disable @@ -3502,7 +2503,7 @@ sub_8086230: @ 8086230 bne _0808624A bl sub_81A3908 _0808624A: - bl set_current_map_header_from_sav1 + bl LoadSaveblockMapHeader bl set_warp2_warp3_to_neg_1 bl GetCurrentTrainerHillMapId lsls r0, 24 @@ -3523,7 +2524,7 @@ _08086278: bl sub_81D5F48 b _0808628A _08086286: - bl CopyFieldObjectTemplateCoordsToSav1 + bl LoadSaveblockMapObjScripts _0808628A: bl UnfreezeMapObjects bl DoTimeBasedEvents diff --git a/asm/party_menu.s b/asm/party_menu.s index 6e134d444..0827a5a12 100644 --- a/asm/party_menu.s +++ b/asm/party_menu.s @@ -10032,7 +10032,7 @@ _081B557C: asrs r1, 24 lsls r1, 16 lsrs r1, 16 - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId adds r1, r0, 0 ldr r0, =gStringVar1 ldrb r1, [r1, 0x14] @@ -10057,7 +10057,7 @@ _081B55B8: asrs r1, 24 lsls r1, 16 lsrs r1, 16 - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId adds r1, r0, 0 ldr r0, =gStringVar1 ldrb r1, [r1, 0x14] diff --git a/asm/pokedex_area_screen.s b/asm/pokedex_area_screen.s index 5f9e01974..579788e14 100644 --- a/asm/pokedex_area_screen.s +++ b/asm/pokedex_area_screen.s @@ -308,7 +308,7 @@ _0813CCB8: ldr r1, [r5] ldrb r0, [r1, 0x10] ldrb r1, [r1, 0x11] - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId ldr r1, [r5] ldrb r0, [r0, 0x14] strh r0, [r1, 0x12] @@ -360,7 +360,7 @@ sub_813CD04: @ 813CD04 strb r3, [r1, 0x11] adds r0, r5, 0 adds r1, r3, 0 - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId ldrb r0, [r0, 0x14] bl CorrectSpecialMapSecId ldr r2, [r4] @@ -496,7 +496,7 @@ sub_813CE34: @ 813CE34 lsrs r0, 24 lsls r1, 24 lsrs r1, 24 - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId ldrb r0, [r0, 0x14] pop {r1} bx r1 diff --git a/asm/pokenav.s b/asm/pokenav.s index 680752c85..d98605dde 100644 --- a/asm/pokenav.s +++ b/asm/pokenav.s @@ -8095,7 +8095,7 @@ sub_81CB0C8: @ 81CB0C8 ldrh r2, [r0, 0xA] ldrh r1, [r0, 0xC] adds r0, r2, 0 - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId ldrb r0, [r0, 0x14] pop {r1} bx r1 @@ -30295,7 +30295,7 @@ sub_81D6120: @ 81D6120 push {lr} movs r0, 0x1A movs r1, 0x40 - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId ldr r0, [r0, 0x4] ldr r0, [r0, 0x8] adds r0, 0x8 @@ -30334,7 +30334,7 @@ _081D6162: adds r0, r1 ldrh r1, [r0] movs r0, 0x1A - bl get_mapheader_by_bank_and_number + bl Overworld_GetMapHeaderByGroupAndId ldr r0, [r0, 0x4] ldr r0, [r0, 0x8] _081D6176: diff --git a/asm/post_battle_event_funcs.s b/asm/post_battle_event_funcs.s index da84a6565..c6d4fd88f 100644 --- a/asm/post_battle_event_funcs.s +++ b/asm/post_battle_event_funcs.s @@ -44,7 +44,7 @@ _0813776C: ldrb r0, [r2, 0x11] orrs r1, r0 movs r0, 0x1 - bl sav12_xor_set + bl SetGameStat _0813778E: bl sub_8076D48 ldr r0, =gSaveBlock2Ptr diff --git a/asm/rom6.s b/asm/rom6.s index 297c81128..b103c0875 100644 --- a/asm/rom6.s +++ b/asm/rom6.s @@ -376,7 +376,7 @@ _0813574C: thumb_func_start hm2_dig hm2_dig: @ 8135760 push {lr} - bl flagmods_08054D70 + bl Overworld_ResetStateAfterDigEscRope movs r0, 0x26 bl FieldEffectStart bl GetCursorSelectionMonId diff --git a/asm/roulette.s b/asm/roulette.s index e03bbea91..ab873dd32 100644 --- a/asm/roulette.s +++ b/asm/roulette.s @@ -2570,7 +2570,7 @@ sub_8141800: @ 8141800 movs r0, 0x1E ldrsh r1, [r4, r0] movs r0, 0x1D - bl sav12_xor_set + bl SetGameStat _08141848: ldr r1, =sub_8141A18 ldr r2, =0x0000ffff diff --git a/data/event_scripts.s b/data/event_scripts.s index b2b895903..7b9d6519c 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -1287,12 +1287,12 @@ EverGrandeCity_HallOfFame_EventScript_271851:: @ 8271851 setvar VAR_0x40D3, 1 return -EverGrandeCity_HallOfFame_EventScript_271857:: @ 8271857 +EventScript_WhiteOut:: @ 8271857 call EverGrandeCity_HallOfFame_EventScript_2718CC - goto EverGrandeCity_HallOfFame_EventScript_271862 + goto EventScript_271862 end -EverGrandeCity_HallOfFame_EventScript_271862:: @ 8271862 +EventScript_271862:: @ 8271862 compare VAR_0x4096, 1 goto_eq EverGrandeCity_HallOfFame_EventScript_271884 compare VAR_0x4096, 2 diff --git a/data/overworld.s b/data/overworld.s deleted file mode 100644 index 186af6f44..000000000 --- a/data/overworld.s +++ /dev/null @@ -1,52 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - .align 2, 0 -gUnknown_08339D3C:: @ 8339D3C - .4byte 0xFFFFFF, 0xFFFFFFFF, 0x4B0, 0xE10, 0x4B0, 0x960, 0x32, 0x50, 0xFFFFFFD4, 0x2C - -gUnknown_08339D64:: @ 8339D64 - .4byte 0, 0 - .4byte 0, 1 - .4byte 0, -1 - .4byte -1, 0 - .4byte 1, 0 - .4byte -1, 1 - .4byte 1, 1 - .4byte -1, -1 - .4byte 1, -1 - -gUnknown_08339DAC:: @ 8339DAC - .4byte 0x1F8 - .4byte 0x11D1 - .4byte 0x21C2 - .4byte 0x31E3 - -gUnknown_08339DBC:: @ 8339DBC - .4byte REG_WIN0H - .4byte 0xa2600001 - .byte 1, 0 - - .align 2 -gUnknown_08339DC8:: @ 8339DC8 - .4byte sub_80879D8 - .4byte sub_80879F8 - .4byte sub_80879FC - -gUnknown_08339DD4:: @ 8339DD4 - .4byte sub_8087A1C - .4byte sub_8087A20 - .4byte sub_8087A20 - .4byte sub_8087A20 - .4byte sub_8087A20 - .4byte sub_8087A1C - .4byte sub_8087A1C - .4byte sub_8087A88 - .4byte sub_8087A88 - .4byte sub_8087A88 - .4byte sub_8087A88 - -gUnknown_08339E00:: @ 8339E00 - .4byte sub_8087AA0 - .4byte sub_8087AA8 diff --git a/include/constants/game_stat.h b/include/constants/game_stat.h index b1f3d4197..7ebf3501b 100644 --- a/include/constants/game_stat.h +++ b/include/constants/game_stat.h @@ -51,9 +51,10 @@ #define GAME_STAT_USED_DAYCARE 47 #define GAME_STAT_RODE_CABLE_CAR 48 #define GAME_STAT_ENTERED_HOT_SPRINGS 49 +#define GAME_STAT_50 50 +#define GAME_STAT_51 51 -/*TODO: add new stats added in Emerald*/ - +#define NUM_USED_GAME_STATS 52 #define NUM_GAME_STATS 64 #endif // GUARD_CONSTANTS_GAME_STAT_H diff --git a/include/global.h b/include/global.h index 4a71a8a87..8913432ba 100644 --- a/include/global.h +++ b/include/global.h @@ -618,7 +618,7 @@ struct SaveBlock1 /*0x04*/ struct WarpData location; /*0x0C*/ struct WarpData warp1; /*0x14*/ struct WarpData warp2; - /*0x1C*/ struct WarpData warp3; + /*0x1C*/ struct WarpData lastHealLocation; /*0x24*/ struct WarpData warp4; /*0x2C*/ u16 battleMusic; /*0x2E*/ u8 weather; @@ -705,6 +705,23 @@ struct SaveBlock1 extern struct SaveBlock1* gSaveBlock1Ptr; +struct MapPosition +{ + s16 x; + s16 y; + u8 height; +}; + +struct UnkStruct_8054FF8 +{ + u8 a; + u8 b; + u8 c; + u8 d; + struct MapPosition sub; + u16 field_C; +}; + struct Bitmap // TODO: Find a better spot for this { u8* pixels; diff --git a/include/overworld.h b/include/overworld.h index 630b0a617..904f61c8e 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -25,11 +25,49 @@ struct UCoords32 extern struct LinkPlayerMapObject gLinkPlayerMapObjects[4]; extern MainCallback gFieldCallback; +void DoWhiteOut(void); +void Overworld_ResetStateAfterFly(void); +void Overworld_ResetStateAfterTeleport(void); +void Overworld_ResetStateAfterDigEscRope(void); +void sub_8084788(void); +void ResetGameStats(void); +void IncrementGameStat(u8 index); +u32 GetGameStat(u8 index); +void SetGameStat(u8 index, u32 value); +void ApplyNewEncryptionKeyToGameStats(u32 newKey); +void LoadMapObjTemplatesFromHeader(void); +void LoadSaveblockMapObjScripts(void); +void Overworld_SetMapObjTemplateCoords(u8 localId, s16 x, s16 y); +void Overworld_SetMapObjTemplateMovementType(u8 localId, u8 movementType); +void mapdata_load_assets_to_gpu_and_full_redraw(void); +struct MapData *get_mapdata_header(void); +void ApplyCurrentWarp(void); +void set_warp2_warp3_to_neg_1(void); +void SetWarpData(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); +bool32 warp_data_is_not_neg_1(struct WarpData *warp); +struct MapHeader *const Overworld_GetMapHeaderByGroupAndId(u16 mapGroup, u16 mapNum); +struct MapHeader *const warp1_get_mapheader(void); +void set_current_map_header_from_sav1_save_old_name(void); +void LoadSaveblockMapHeader(void); +void update_camera_pos_from_warpid(void); +void warp_in(void); +void Overworld_SetWarpDestination(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); +void warp1_set_2(s8 mapGroup, s8 mapNum, s8 warpId); +void saved_warp2_set(int unused, s8 mapGroup, s8 mapNum, s8 warpId); +void saved_warp2_set_2(int unused, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); +void copy_saved_warp2_bank_and_enter_x_to_warp1(u8 unused); +void sub_8084CCC(u8 a1); +void Overworld_SetWarpDestToLastHealLoc(void); +void Overworld_SetHealLocationWarp(u8 healLocationId); +void sub_8084D5C(s16 a1, s16 a2); +void sub_8084DD4(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); + +// to erase later +u8 GetMapTypeByGroupAndId(s8 mapGroup, s8 mapNum); +u8 Overworld_GetMapTypeOfSaveblockLocation(void); void Overworld_SetMapObjTemplateCoords(u8, s16, s16); void Overworld_SetMapObjTemplateMovementType(u8, u8); - void Overworld_SetWarpDestination(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); - void saved_warp2_set(int unused, s8 mapGroup, s8 mapNum, s8 warpId); void saved_warp2_set_2(int unused, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); void Overworld_SetHealLocationWarp(u8); @@ -37,25 +75,18 @@ void sub_8084DD4(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); void sub_8084E2C(s8, s8, s8, s8, s8); void sub_8084E80(s8, s8, s8, s8, s8); void sub_8084EBC(s16, s16); - void player_avatar_init_params_reset(void); - bool8 Overworld_MapTypeAllowsTeleportAndFly(u8 mapType); void Overworld_ResetStateAfterTeleport(void); - void Overworld_SetFlashLevel(s32 a1); //u8 Overworld_GetFlashLevel(void); void sub_8085524(u16); - void Overworld_SetSavedMusic(u16); void Overworld_ChangeMusicToDefault(void); void Overworld_ChangeMusicTo(u16); - bool32 is_c1_link_related_active(void); extern u16 gUnknown_03005DA8; - void strange_npc_table_clear(void); -const struct MapHeader *get_mapheader_by_bank_and_number(u16, u16); void FieldObjectMoveDestCoords(struct MapObject *, u32, s16 *, s16 *); void sub_8086230(void); void c2_exit_to_overworld_2_switch(void); @@ -71,13 +102,11 @@ void copy_saved_warp2_bank_and_enter_x_to_warp1(u8 unused); void mapldr_default(void); u8 get_map_light_from_warp0(void); bool8 is_light_level_1_2_3_5_or_6(u8 a1); - bool32 sub_80875C8(void); bool32 sub_8087634(void); bool32 sub_808766C(void); void IncrementGameStat(u8); u32 GetGameStat(u8); - void CB2_OverworldBasic(void); #endif //GUARD_ROM4_H diff --git a/ld_script.txt b/ld_script.txt index 81911e574..bb015446f 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -86,6 +86,7 @@ SECTIONS { src/berry_blender.o(.text); src/play_time.o(.text); src/new_game.o(.text); + src/overworld.o(.text); asm/overworld.o(.text); asm/fieldmap.o(.text); src/metatile_behavior.o(.text); @@ -393,7 +394,7 @@ SECTIONS { data/trade.o(.rodata); src/berry_blender.o(.rodata); src/new_game.o(.rodata); - data/overworld.o(.rodata); + src/overworld.o(.rodata); data/tilesets.o(.rodata); data/maps.o(.rodata); data/fieldmap.o(.rodata); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 75f05e86f..2da48de49 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -76,7 +76,7 @@ extern bool8 sub_81B1250(void); // ? extern bool8 InBattlePike(void); extern bool8 InBattlePyramid(void); extern u16 GetBattlePyramidPickupItemId(void); -extern u8 sav1_map_get_light_level(void); +extern u8 Overworld_GetMapTypeOfSaveblockLocation(void); extern u8 sub_813B21C(void); extern u16 get_unknown_box_id(void); @@ -10578,7 +10578,7 @@ static void atkEF_handleballthrow(void) ballMultiplier = 10; break; case ITEM_DIVE_BALL: - if (sav1_map_get_light_level() == 5) + if (Overworld_GetMapTypeOfSaveblockLocation() == 5) ballMultiplier = 35; else ballMultiplier = 10; diff --git a/src/field_map_obj.c b/src/field_map_obj.c index 906eff4b7..84613365c 100644 --- a/src/field_map_obj.c +++ b/src/field_map_obj.c @@ -1673,7 +1673,7 @@ struct MapObjectTemplate *GetFieldObjectTemplateByLocalIdAndMap(u8 localId, u8 m } else { - mapHeader = get_mapheader_by_bank_and_number(mapGroup, mapNum); + mapHeader = Overworld_GetMapHeaderByGroupAndId(mapGroup, mapNum); templates = mapHeader->events->mapObjects; count = mapHeader->events->mapObjectCount; } diff --git a/src/item_use.c b/src/item_use.c index bcd453660..99dce9cbd 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -85,7 +85,7 @@ extern void sub_81C59BC(void); extern void sub_81AB9A8(u8); extern void sub_81ABA88(u8); extern void sub_80B7CC8(void); -extern void flagmods_08054D70(void); +extern void Overworld_ResetStateAfterDigEscRope(void); extern u8* sub_806CF78(u16); extern void sub_81B89F0(void); extern u8 GetItemEffectType(u16); @@ -904,7 +904,7 @@ void task08_080A1C44(u8 taskId) void re_escape_rope(u8 taskId) { - flagmods_08054D70(); + Overworld_ResetStateAfterDigEscRope(); sub_80FE058(); gTasks[taskId].data[0] = 0; DisplayItemMessageOnField(taskId, gStringVar4, task08_080A1C44); diff --git a/src/overworld.c b/src/overworld.c index c538595f2..5757ca20a 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -1,10 +1,82 @@ - -// Includes #include "global.h" +#include "overworld.h" +#include "battle_setup.h" +#include "berry.h" +// #include "cable_club.h" +#include "clock.h" +#include "event_data.h" +#include "field_camera.h" +// #include "field_control_avatar.h" +#include "field_effect.h" +#include "field_fadetransition.h" +#include "field_ground_effect.h" +#include "field_map_obj.h" +#include "field_map_obj_helpers.h" +#include "field_message_box.h" +#include "field_player_avatar.h" +#include "field_screen_effect.h" +// #include "field_special_scene.h" +#include "field_specials.h" +#include "field_tasks.h" +#include "field_weather.h" +#include "fieldmap.h" +// #include "fldeff_flash.h" +#include "heal_location.h" +#include "link.h" +#include "load_save.h" +#include "main.h" +#include "m4a.h" +#include "constants/maps.h" +#include "map_name_popup.h" +#include "menu.h" +#include "metatile_behavior.h" +#include "new_game.h" +#include "palette.h" +#include "play_time.h" +#include "random.h" +#include "roamer.h" +// #include "rotating_gate.h" +#include "safari_zone.h" +#include "script.h" +// #include "script_pokemon_80C4.h" +#include "secret_base.h" +#include "constants/songs.h" +#include "sound.h" +#include "constants/species.h" +#include "start_menu.h" +#include "task.h" +// #include "tileset_anim.h" +#include "time_events.h" +#include "tv.h" +#include "scanline_effect.h" +#include "wild_encounter.h" +#include "bg.h" +#include "money.h" -// Static type declarations +// event scripts +extern const u8 EventScript_WhiteOut[]; +extern const u8 EventScript_271862[]; -// Static RAM declarations +// vars +extern struct MapData * const gMapAttributes[]; +extern struct MapHeader * const * const gMapGroups[]; +extern s32 gMaxFlashLevel; + +// functions +extern void HealPlayerParty(void); +extern void move_tilemap_camera_to_upper_left_corner(void); +extern void cur_mapheader_run_tileset_funcs_after_some_cpuset(void); +extern void DrawWholeMapView(void); +extern void copy_map_tileset1_tileset2_to_vram(struct MapData *); +extern void apply_map_tileset1_tileset2_palette(struct MapData *); +extern void ResetCyclingRoadChallengeData(void); +extern void ApplyNewEncryptionKeyToWord(u32 *word, u32 newKey); + +// this file's functions +static void Overworld_ResetStateAfterWhiteOut(void); +void ChooseAmbientCrySpecies(void); + +// IWRAM bss vars IWRAM_DATA void *gUnknown_03000E0C; IWRAM_DATA u8 gUnknown_03000E10[4]; IWRAM_DATA u8 (*gUnknown_03000E14)(u32); @@ -12,8 +84,463 @@ IWRAM_DATA u8 gUnknown_03000E18; IWRAM_DATA u8 gUnknown_03000E19; IWRAM_DATA void *rom4_c_unused_03000e1c; -// Static ROM declarations +// EWRAM vars +EWRAM_DATA struct WarpData gUnknown_020322DC = {0}; +EWRAM_DATA struct WarpData gWarpDestination = {0}; // new warp position +EWRAM_DATA struct WarpData gUnknown_020322EC = {0}; +EWRAM_DATA struct WarpData gUnknown_020322F4 = {0}; +EWRAM_DATA u16 gLastMapSectionId = 0; +// EWRAM_DATA struct UnkPlayerStruct gUnknown_02029810 = {0}; +// EWRAM_DATA u16 sAmbientCrySpecies = 0; +// EWRAM_DATA bool8 sIsAmbientCryWaterMon = FALSE; +// EWRAM_DATA struct LinkPlayerMapObject gLinkPlayerMapObjects[4] = {0}; -// .rodata +// const rom data +const struct WarpData sDummyWarpData = +{ + .mapGroup = -1, + .mapNum = -1, + .warpId = -1, + .x = -1, + .y = -1, +}; -// .text +const u8 sUnusedData[] = +{ + 0xB0, 0x04, 0x00, 0x00, + 0x10, 0x0E, 0x00, 0x00, + 0xB0, 0x04, 0x00, 0x00, + 0x60, 0x09, 0x00, 0x00, + 0x32, 0x00, 0x00, 0x00, + 0x50, 0x00, 0x00, 0x00, + 0xD4, 0xFF, 0xFF, 0xFF, + 0x2C, 0x00, 0x00, 0x00, +}; + +const struct UCoords32 gUnknown_08339D64[] = +{ + { 0, 0}, + { 0, 1}, + { 0, -1}, + {-1, 0}, + { 1, 0}, + {-1, 1}, + { 1, 1}, + {-1, -1}, + { 1, -1}, +}; + +const struct BgTemplate gUnknown_08339DAC[] = +{ + { + .bg = 0, + .charBaseIndex = 2, + .mapBaseIndex = 31, + .screenSize = 0, + .paletteMode = 0, + .priority = 0, + .baseTile = 0 + }, + { + .bg = 1, + .charBaseIndex = 0, + .mapBaseIndex = 29, + .screenSize = 0, + .paletteMode = 0, + .priority = 1, + .baseTile = 0 + }, + { + .bg = 2, + .charBaseIndex = 0, + .mapBaseIndex = 28, + .screenSize = 0, + .paletteMode = 0, + .priority = 2, + .baseTile = 0 + }, + { + .bg = 3, + .charBaseIndex = 0, + .mapBaseIndex = 30, + .screenSize = 0, + .paletteMode = 0, + .priority = 3, + .baseTile = 0 + } +}; + +const struct ScanlineEffectParams gUnknown_08339DBC = +{ + (void *)REG_ADDR_WIN0H, + ((DMA_ENABLE | DMA_START_HBLANK | DMA_REPEAT | DMA_DEST_RELOAD) << 16) | 1, + 1, + 0, +}; + +u8 sub_80879D8(struct LinkPlayerMapObject *, struct MapObject *, u8); +u8 sub_80879F8(struct LinkPlayerMapObject *, struct MapObject *, u8); +u8 sub_80879FC(struct LinkPlayerMapObject *, struct MapObject *, u8); + +u8 (*const gUnknown_08339DC8[])(struct LinkPlayerMapObject *, struct MapObject *, u8) = +{ + sub_80879D8, + sub_80879F8, + sub_80879FC, +}; + +u8 sub_8087A1C(struct LinkPlayerMapObject *, struct MapObject *, u8); +u8 sub_8087A20(struct LinkPlayerMapObject *, struct MapObject *, u8); +u8 sub_8087A88(struct LinkPlayerMapObject *, struct MapObject *, u8); + +u8 (*const gUnknown_08339DD4[])(struct LinkPlayerMapObject *, struct MapObject *, u8) = +{ + sub_8087A1C, + sub_8087A20, + sub_8087A20, + sub_8087A20, + sub_8087A20, + sub_8087A1C, + sub_8087A1C, + sub_8087A88, + sub_8087A88, + sub_8087A88, + sub_8087A88, +}; + +void sub_8087AA0(struct LinkPlayerMapObject *, struct MapObject *); +void sub_8087AA8(struct LinkPlayerMapObject *, struct MapObject *); + +void (*const gUnknown_08339E00[])(struct LinkPlayerMapObject *, struct MapObject *) = +{ + sub_8087AA0, + sub_8087AA8, +}; + +// code +void DoWhiteOut(void) +{ + ScriptContext2_RunNewScript(EventScript_WhiteOut); + SetMoney(&gSaveBlock1Ptr->money, GetMoney(&gSaveBlock1Ptr->money) / 2); + HealPlayerParty(); + Overworld_ResetStateAfterWhiteOut(); + Overworld_SetWarpDestToLastHealLoc(); + warp_in(); +} + +void Overworld_ResetStateAfterFly(void) +{ + player_avatar_init_params_reset(); + FlagClear(FLAG_SYS_CYCLING_ROAD); + FlagClear(FLAG_SYS_CRUISE_MODE); + FlagClear(FLAG_SYS_SAFARI_MODE); + FlagClear(FLAG_SYS_USE_STRENGTH); + FlagClear(FLAG_SYS_USE_FLASH); +} + +void Overworld_ResetStateAfterTeleport(void) +{ + player_avatar_init_params_reset(); + FlagClear(FLAG_SYS_CYCLING_ROAD); + FlagClear(FLAG_SYS_CRUISE_MODE); + FlagClear(FLAG_SYS_SAFARI_MODE); + FlagClear(FLAG_SYS_USE_STRENGTH); + FlagClear(FLAG_SYS_USE_FLASH); + ScriptContext2_RunNewScript(EventScript_271862); +} + +void Overworld_ResetStateAfterDigEscRope(void) +{ + player_avatar_init_params_reset(); + FlagClear(FLAG_SYS_CYCLING_ROAD); + FlagClear(FLAG_SYS_CRUISE_MODE); + FlagClear(FLAG_SYS_SAFARI_MODE); + FlagClear(FLAG_SYS_USE_STRENGTH); + FlagClear(FLAG_SYS_USE_FLASH); +} + +static void Overworld_ResetStateAfterWhiteOut(void) +{ + player_avatar_init_params_reset(); + FlagClear(FLAG_SYS_CYCLING_ROAD); + FlagClear(FLAG_SYS_CRUISE_MODE); + FlagClear(FLAG_SYS_SAFARI_MODE); + FlagClear(FLAG_SYS_USE_STRENGTH); + FlagClear(FLAG_SYS_USE_FLASH); + if (VarGet(VAR_0x4039) == 1) + { + VarSet(VAR_0x4039, 0); + VarSet(VAR_0x4037, 0); + } +} + +void sub_8084788(void) +{ + FlagClear(FLAG_SYS_SAFARI_MODE); + ChooseAmbientCrySpecies(); + ResetCyclingRoadChallengeData(); + UpdateLocationHistoryForRoamer(); + RoamerMoveToOtherLocationSet(); +} + +void ResetGameStats(void) +{ + s32 i; + + for (i = 0; i < NUM_GAME_STATS; i++) + SetGameStat(i, 0); +} + +void IncrementGameStat(u8 index) +{ + if (index < NUM_USED_GAME_STATS) + { + u32 statVal = GetGameStat(index); + if (statVal < 0xFFFFFF) + statVal++; + else + statVal = 0xFFFFFF; + + SetGameStat(index, statVal); + } +} + +u32 GetGameStat(u8 index) +{ + if (index >= NUM_USED_GAME_STATS) + return 0; + + return gSaveBlock1Ptr->gameStats[index] ^ gSaveBlock2Ptr->encryptionKey; +} + +void SetGameStat(u8 index, u32 value) +{ + if (index < NUM_USED_GAME_STATS) + gSaveBlock1Ptr->gameStats[index] = value ^ gSaveBlock2Ptr->encryptionKey; +} + +void ApplyNewEncryptionKeyToGameStats(u32 newKey) +{ + u8 i; + + for (i = 0; i < NUM_GAME_STATS; i++) + ApplyNewEncryptionKeyToWord(&gSaveBlock1Ptr->gameStats[i], newKey); +} + +void LoadMapObjTemplatesFromHeader(void) +{ + // Clear map object templates + CpuFill32(0, gSaveBlock1Ptr->mapObjectTemplates, sizeof(gSaveBlock1Ptr->mapObjectTemplates)); + + // Copy map header events to save block + CpuCopy32(gMapHeader.events->mapObjects, + gSaveBlock1Ptr->mapObjectTemplates, + gMapHeader.events->mapObjectCount * sizeof(struct MapObjectTemplate)); +} + +void LoadSaveblockMapObjScripts(void) +{ + struct MapObjectTemplate *mapHeaderObjTemplates = gMapHeader.events->mapObjects; + struct MapObjectTemplate *savObjTemplates = gSaveBlock1Ptr->mapObjectTemplates; + s32 i; + + for (i = 0; i < 64; i++) + savObjTemplates[i].script = mapHeaderObjTemplates[i].script; +} + +void Overworld_SetMapObjTemplateCoords(u8 localId, s16 x, s16 y) +{ + s32 i; + struct MapObjectTemplate *savObjTemplates = gSaveBlock1Ptr->mapObjectTemplates; + + for (i = 0; i < 64; i++) + { + struct MapObjectTemplate *mapObjectTemplate = &savObjTemplates[i]; + if (mapObjectTemplate->localId == localId) + { + mapObjectTemplate->x = x; + mapObjectTemplate->y = y; + return; + } + } +} + +void Overworld_SetMapObjTemplateMovementType(u8 localId, u8 movementType) +{ + s32 i; + + struct MapObjectTemplate *savObjTemplates = gSaveBlock1Ptr->mapObjectTemplates; + for (i = 0; i < 64; i++) + { + struct MapObjectTemplate *mapObjectTemplate = &savObjTemplates[i]; + if (mapObjectTemplate->localId == localId) + { + mapObjectTemplate->movementType = movementType; + return; + } + } +} + +void mapdata_load_assets_to_gpu_and_full_redraw(void) +{ + move_tilemap_camera_to_upper_left_corner(); + copy_map_tileset1_tileset2_to_vram(gMapHeader.mapData); + apply_map_tileset1_tileset2_palette(gMapHeader.mapData); + DrawWholeMapView(); + cur_mapheader_run_tileset_funcs_after_some_cpuset(); +} + +struct MapData *get_mapdata_header(void) +{ + u16 mapDataId = gSaveBlock1Ptr->mapDataId; + if (mapDataId) + return gMapAttributes[mapDataId - 1]; + return NULL; +} + +void ApplyCurrentWarp(void) +{ + gUnknown_020322DC = gSaveBlock1Ptr->location; + gSaveBlock1Ptr->location = gWarpDestination; + gUnknown_020322EC = sDummyWarpData; + gUnknown_020322F4 = sDummyWarpData; +} + +void set_warp2_warp3_to_neg_1(void) +{ + gUnknown_020322EC = sDummyWarpData; + gUnknown_020322F4 = sDummyWarpData; +} + +void SetWarpData(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) +{ + warp->mapGroup = mapGroup; + warp->mapNum = mapNum; + warp->warpId = warpId; + warp->x = x; + warp->y = y; +} + +bool32 warp_data_is_not_neg_1(struct WarpData *warp) +{ + if (warp->mapGroup != -1) + return FALSE; + if (warp->mapNum != -1) + return FALSE; + if (warp->warpId != -1) + return FALSE; + if (warp->x != -1) + return FALSE; + if (warp->y != -1) + return FALSE; + return TRUE; +} + +struct MapHeader *const Overworld_GetMapHeaderByGroupAndId(u16 mapGroup, u16 mapNum) +{ + return gMapGroups[mapGroup][mapNum]; +} + +struct MapHeader *const warp1_get_mapheader(void) +{ + return Overworld_GetMapHeaderByGroupAndId(gWarpDestination.mapGroup, gWarpDestination.mapNum); +} + +void set_current_map_header_from_sav1_save_old_name(void) +{ + gLastMapSectionId = gMapHeader.regionMapSectionId; + gMapHeader = *Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum); + gSaveBlock1Ptr->mapDataId = gMapHeader.mapDataId; + gMapHeader.mapData = get_mapdata_header(); +} + +void LoadSaveblockMapHeader(void) +{ + gMapHeader = *Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum); + gMapHeader.mapData = get_mapdata_header(); +} + +void update_camera_pos_from_warpid(void) +{ + if (gSaveBlock1Ptr->location.warpId >= 0 && gSaveBlock1Ptr->location.warpId < gMapHeader.events->warpCount) + { + gSaveBlock1Ptr->pos.x = gMapHeader.events->warps[gSaveBlock1Ptr->location.warpId].x; + gSaveBlock1Ptr->pos.y = gMapHeader.events->warps[gSaveBlock1Ptr->location.warpId].y; + } + else if (gSaveBlock1Ptr->location.x >= 0 && gSaveBlock1Ptr->location.y >= 0) + { + gSaveBlock1Ptr->pos.x = gSaveBlock1Ptr->location.x; + gSaveBlock1Ptr->pos.y = gSaveBlock1Ptr->location.y; + } + else + { + gSaveBlock1Ptr->pos.x = gMapHeader.mapData->width / 2; + gSaveBlock1Ptr->pos.y = gMapHeader.mapData->height / 2; + } +} + +void warp_in(void) +{ + ApplyCurrentWarp(); + set_current_map_header_from_sav1_save_old_name(); + update_camera_pos_from_warpid(); +} + +void Overworld_SetWarpDestination(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) +{ + SetWarpData(&gWarpDestination, mapGroup, mapNum, warpId, x, y); +} + +void warp1_set_2(s8 mapGroup, s8 mapNum, s8 warpId) +{ + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, -1, -1); +} + +void saved_warp2_set(int unused, s8 mapGroup, s8 mapNum, s8 warpId) +{ + SetWarpData(&gSaveBlock1Ptr->warp2, mapGroup, mapNum, warpId, gSaveBlock1Ptr->pos.x, gSaveBlock1Ptr->pos.y); +} + +void saved_warp2_set_2(int unused, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) +{ + SetWarpData(&gSaveBlock1Ptr->warp2, mapGroup, mapNum, warpId, x, y); +} + +void copy_saved_warp2_bank_and_enter_x_to_warp1(u8 unused) +{ + gWarpDestination = gSaveBlock1Ptr->warp2; +} + +void sub_8084CCC(u8 a1) +{ + const struct HealLocation *warp = GetHealLocationPointer(a1); + + if (warp) + Overworld_SetWarpDestination(warp->group, warp->map, -1, warp->x, warp->y); +} + +void Overworld_SetWarpDestToLastHealLoc(void) +{ + gWarpDestination = gSaveBlock1Ptr->lastHealLocation; +} + +void Overworld_SetHealLocationWarp(u8 healLocationId) +{ + const struct HealLocation *healLocation = GetHealLocationPointer(healLocationId); + + if (healLocation != NULL) + SetWarpData(&gSaveBlock1Ptr->lastHealLocation, healLocation->group, healLocation->map, -1, healLocation->x, healLocation->y); +} + +void sub_8084D5C(s16 a1, s16 a2) +{ + u8 currMapType = Overworld_GetMapTypeOfSaveblockLocation(); + u8 destMapType = GetMapTypeByGroupAndId(gWarpDestination.mapGroup, gWarpDestination.mapNum); + if (is_light_level_1_2_3_5_or_6(currMapType) && is_light_level_1_2_3_5_or_6(destMapType) != TRUE) + sub_8084DD4(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, a1 - 7, a2 - 6); +} + +void sub_8084DD4(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) +{ + SetWarpData(&gSaveBlock1Ptr->warp4, mapGroup, mapNum, warpId, x, y); +} diff --git a/src/region_map.c b/src/region_map.c index 086c0ba68..7f121d1de 100644 --- a/src/region_map.c +++ b/src/region_map.c @@ -881,7 +881,7 @@ static void RegionMap_InitializeStateBasedOnPlayerLocation(void) return; } - switch (get_map_light_level_by_bank_and_number(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum)) + switch (GetMapTypeByGroupAndId(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum)) { default: case 1: @@ -904,7 +904,7 @@ static void RegionMap_InitializeStateBasedOnPlayerLocation(void) case 7: if (gMapHeader.flags & 0x02) { - mapHeader = get_mapheader_by_bank_and_number(gSaveBlock1Ptr->warp4.mapGroup, gSaveBlock1Ptr->warp4.mapNum); + mapHeader = Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->warp4.mapGroup, gSaveBlock1Ptr->warp4.mapNum); gRegionMap->mapSecId = mapHeader->regionMapSectionId; gRegionMap->playerIsInCave = TRUE; mapWidth = mapHeader->mapData->width; @@ -923,7 +923,7 @@ static void RegionMap_InitializeStateBasedOnPlayerLocation(void) } break; case 9: - mapHeader = get_mapheader_by_bank_and_number((u16)gSaveBlock1Ptr->warp2.mapGroup, (u16)gSaveBlock1Ptr->warp2.mapNum); + mapHeader = Overworld_GetMapHeaderByGroupAndId((u16)gSaveBlock1Ptr->warp2.mapGroup, (u16)gSaveBlock1Ptr->warp2.mapNum); gRegionMap->mapSecId = mapHeader->regionMapSectionId; gRegionMap->playerIsInCave = TRUE; mapWidth = mapHeader->mapData->width; @@ -937,12 +937,12 @@ static void RegionMap_InitializeStateBasedOnPlayerLocation(void) if (gRegionMap->mapSecId != MAPSEC_DYNAMIC) { storedWarp = &gSaveBlock1Ptr->warp4; - mapHeader = get_mapheader_by_bank_and_number(storedWarp->mapGroup, storedWarp->mapNum); + mapHeader = Overworld_GetMapHeaderByGroupAndId(storedWarp->mapGroup, storedWarp->mapNum); } else { storedWarp = &gSaveBlock1Ptr->warp2; - mapHeader = get_mapheader_by_bank_and_number(storedWarp->mapGroup, storedWarp->mapNum); + mapHeader = Overworld_GetMapHeaderByGroupAndId(storedWarp->mapGroup, storedWarp->mapNum); gRegionMap->mapSecId = mapHeader->regionMapSectionId; } if (RegionMap_IsPlayerInCave(gRegionMap->mapSecId)) @@ -1065,7 +1065,7 @@ static void RegionMap_InitializeStateBasedOnSSTidalLocation(void) break; default: case 0: - mapHeader = get_mapheader_by_bank_and_number(mapGroup, mapNum); + mapHeader = Overworld_GetMapHeaderByGroupAndId(mapGroup, mapNum); gRegionMap->mapSecId = mapHeader->regionMapSectionId; dimensionScale = mapHeader->mapData->width / gRegionMapEntries[gRegionMap->mapSecId].width; diff --git a/sym_ewram.txt b/sym_ewram.txt index 206fa96e8..ed231e96f 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -214,21 +214,9 @@ gUnknown_020322D5: @ 20322D5 gUnknown_020322D8: @ 20322D8 .space 0x4 -gUnknown_020322DC: @ 20322DC - .space 0x8 - -gUnknown_020322E4: @ 20322E4 - .space 0x8 - -gUnknown_020322EC: @ 20322EC - .space 0x8 - -gUnknown_020322F4: @ 20322F4 - .space 0x8 - -gUnknown_020322FC: @ 20322FC - .space 0x4 + .include "src/overworld.o" +.align 2 gUnknown_02032300: @ 2032300 .space 0x4