Merge pull request #69 from ProjectRevoTPP/save_location

decompile save_location.c
This commit is contained in:
Diegoisawesome 2017-10-09 00:33:23 -05:00 committed by GitHub
commit 96c5966ff3
5 changed files with 149 additions and 222 deletions

View File

@ -1375,7 +1375,7 @@ _080850C8:
bl warp_shift
bl set_current_map_header_from_sav1_save_old_name
bl CopyFieldObjectTemplatesToSav1
bl sav2_set_x9_depending_on_sav1_map
bl TrySetMapSaveWarpStatus
bl ClearTempFieldEventData
bl wild_pokemon_reroll
bl prev_quest_postbuffer_cursor_backup_reset
@ -1463,7 +1463,7 @@ _080851A2:
lsls r0, 24
lsrs r6, r0, 24
bl sub_80EB218
bl sav2_set_x9_depending_on_sav1_map
bl TrySetMapSaveWarpStatus
bl ClearTempFieldEventData
bl wild_pokemon_reroll
bl prev_quest_postbuffer_cursor_backup_reset

View File

@ -1,205 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.syntax unified
.text
thumb_func_start sav1_are_mapnumbers_in_given_list
sav1_are_mapnumbers_in_given_list: @ 81AFC84
push {r4,lr}
adds r2, r0, 0
ldr r0, =gSaveBlock1Ptr
ldr r0, [r0]
movs r1, 0x4
ldrsb r1, [r0, r1]
lsls r1, 8
ldrb r0, [r0, 0x5]
lsls r0, 24
asrs r0, 24
adds r0, r1
lsls r0, 16
lsrs r3, r0, 16
ldrh r0, [r2]
ldr r1, =0x0000ffff
cmp r0, r1
beq _081AFCC4
adds r4, r1, 0
adds r1, r2, 0
_081AFCAA:
ldrh r0, [r1]
cmp r0, r3
bne _081AFCBC
movs r0, 0x1
b _081AFCC6
.pool
_081AFCBC:
adds r1, 0x2
ldrh r0, [r1]
cmp r0, r4
bne _081AFCAA
_081AFCC4:
movs r0, 0
_081AFCC6:
pop {r4}
pop {r1}
bx r1
thumb_func_end sav1_are_mapnumbers_in_given_list
thumb_func_start sav1_is_in_pokecenter
sav1_is_in_pokecenter: @ 81AFCCC
push {lr}
ldr r0, =gUnknown_086143BC
bl sav1_are_mapnumbers_in_given_list
pop {r1}
bx r1
.pool
thumb_func_end sav1_is_in_pokecenter
thumb_func_start sub_81AFCDC
sub_81AFCDC: @ 81AFCDC
push {lr}
ldr r0, =gUnknown_0861440A
bl sav1_are_mapnumbers_in_given_list
pop {r1}
bx r1
.pool
thumb_func_end sub_81AFCDC
thumb_func_start sub_81AFCEC
sub_81AFCEC: @ 81AFCEC
push {lr}
ldr r0, =gUnknown_0861440E
bl sav1_are_mapnumbers_in_given_list
pop {r1}
bx r1
.pool
thumb_func_end sub_81AFCEC
thumb_func_start sav2_set_x9_bit3_when_sav1_in_pokecenter
sav2_set_x9_bit3_when_sav1_in_pokecenter: @ 81AFCFC
push {lr}
bl sav1_is_in_pokecenter
cmp r0, 0
bne _081AFD18
ldr r0, =gSaveBlock2Ptr
ldr r2, [r0]
ldrb r1, [r2, 0x9]
movs r0, 0xFD
ands r0, r1
b _081AFD22
.pool
_081AFD18:
ldr r0, =gSaveBlock2Ptr
ldr r2, [r0]
ldrb r1, [r2, 0x9]
movs r0, 0x2
orrs r0, r1
_081AFD22:
strb r0, [r2, 0x9]
pop {r0}
bx r0
.pool
thumb_func_end sav2_set_x9_bit3_when_sav1_in_pokecenter
thumb_func_start sub_81AFD2C
sub_81AFD2C: @ 81AFD2C
push {lr}
bl sub_81AFCDC
cmp r0, 0
bne _081AFD48
ldr r0, =gSaveBlock2Ptr
ldr r2, [r0]
ldrb r1, [r2, 0x9]
movs r0, 0xFB
ands r0, r1
b _081AFD52
.pool
_081AFD48:
ldr r0, =gSaveBlock2Ptr
ldr r2, [r0]
ldrb r1, [r2, 0x9]
movs r0, 0x4
orrs r0, r1
_081AFD52:
strb r0, [r2, 0x9]
pop {r0}
bx r0
.pool
thumb_func_end sub_81AFD2C
thumb_func_start sub_81AFD5C
sub_81AFD5C: @ 81AFD5C
push {lr}
bl sub_81AFCEC
cmp r0, 0
bne _081AFD78
ldr r0, =gSaveBlock2Ptr
ldr r2, [r0]
ldrb r1, [r2, 0x9]
movs r0, 0xF7
ands r0, r1
b _081AFD82
.pool
_081AFD78:
ldr r0, =gSaveBlock2Ptr
ldr r2, [r0]
ldrb r1, [r2, 0x9]
movs r0, 0x8
orrs r0, r1
_081AFD82:
strb r0, [r2, 0x9]
pop {r0}
bx r0
.pool
thumb_func_end sub_81AFD5C
thumb_func_start sav2_set_x9_depending_on_sav1_map
sav2_set_x9_depending_on_sav1_map: @ 81AFD8C
push {lr}
bl sav2_set_x9_bit3_when_sav1_in_pokecenter
bl sub_81AFD2C
bl sub_81AFD5C
pop {r0}
bx r0
thumb_func_end sav2_set_x9_depending_on_sav1_map
thumb_func_start sub_81AFDA0
sub_81AFDA0: @ 81AFDA0
ldr r0, =gSaveBlock2Ptr
ldr r2, [r0]
adds r2, 0xA8
ldr r0, [r2]
movs r1, 0x80
lsls r1, 8
orrs r0, r1
movs r1, 0x1
orrs r0, r1
movs r1, 0x2
orrs r0, r1
movs r1, 0x4
orrs r0, r1
movs r1, 0x10
orrs r0, r1
movs r1, 0x20
orrs r0, r1
movs r1, 0x8
orrs r0, r1
str r0, [r2]
bx lr
.pool
thumb_func_end sub_81AFDA0
thumb_func_start sub_81AFDD0
sub_81AFDD0: @ 81AFDD0
ldr r0, =gSaveBlock2Ptr
ldr r2, [r0]
ldrb r1, [r2, 0x9]
movs r0, 0x80
orrs r0, r1
strb r0, [r2, 0x9]
bx lr
.pool
thumb_func_end sub_81AFDD0
.align 2, 0 @ Don't pad with nop.

View File

@ -1,13 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.section .rodata
gUnknown_086143BC:: @ 86143BC
.incbin "baserom.gba", 0x6143bc, 0x4e
gUnknown_0861440A:: @ 861440A
.incbin "baserom.gba", 0x61440a, 0x4
gUnknown_0861440E:: @ 861440E
.incbin "baserom.gba", 0x61440e, 0x2

View File

@ -244,7 +244,7 @@ SECTIONS {
asm/list_menu.o(.text);
asm/menu_indicators.o(.text);
asm/unk_text_util.o(.text);
asm/save_location.o(.text);
src/save_location.o(.text);
asm/item_icon.o(.text);
asm/party_menu.o(.text);
asm/battle_tent.o(.text);
@ -451,7 +451,7 @@ SECTIONS {
data/battle_frontier_2.o(.rodata);
data/item_menu.o(.rodata);
data/menu_indicators.o(.rodata);
data/save_location.o(.rodata);
src/save_location.o(.rodata);
data/item_icon.o(.rodata);
data/party_menu.o(.rodata);
data/battle_tent.o(.rodata);

145
src/save_location.c Executable file
View File

@ -0,0 +1,145 @@
#include "global.h"
#include "map_constants.h"
// used to make the list defines a little less ugly.
#define MAP(name) ((MAP_GROUP_##name << 8) + (MAP_ID_##name))
// specialSaveWarp flags
#define POKECENTER_SAVEWARP (1 << 1)
#define LOBBY_SAVEWARP (1 << 2)
#define UNK_SPECIAL_SAVE_WARP_FLAG_3 (1 << 3)
static bool32 IsCurMapInLocationList(const u16 *list)
{
u16 locSum = (gSaveBlock1Ptr->location.mapGroup << 8) + (gSaveBlock1Ptr->location.mapNum);
// im sure it was written a different way, but for the love of christ I cant figure out how to write it different where it still matches.
if (*list != 0xFFFF)
{
u16 termValue = 0xFFFF;
const u16 *localList;
for (localList = list; *localList != termValue; localList++)
if (*localList == locSum)
return TRUE;
}
return FALSE;
}
// TODO: Not require a packed u16 array for these lists
static const u16 gSaveLocationPokeCenterList[] =
{
MAP(OLDALE_TOWN_POKEMON_CENTER_1F),
MAP(OLDALE_TOWN_POKEMON_CENTER_2F),
MAP(DEWFORD_TOWN_POKEMON_CENTER_1F),
MAP(DEWFORD_TOWN_POKEMON_CENTER_2F),
MAP(LAVARIDGE_TOWN_POKEMON_CENTER_1F),
MAP(LAVARIDGE_TOWN_POKEMON_CENTER_2F),
MAP(FALLARBOR_TOWN_POKEMON_CENTER_1F),
MAP(FALLARBOR_TOWN_POKEMON_CENTER_2F),
MAP(VERDANTURF_TOWN_POKEMON_CENTER_1F),
MAP(VERDANTURF_TOWN_POKEMON_CENTER_2F),
MAP(PACIFIDLOG_TOWN_POKEMON_CENTER_1F),
MAP(PACIFIDLOG_TOWN_POKEMON_CENTER_2F),
MAP(PETALBURG_CITY_POKEMON_CENTER_1F),
MAP(PETALBURG_CITY_POKEMON_CENTER_2F),
MAP(SLATEPORT_CITY_POKEMON_CENTER_1F),
MAP(SLATEPORT_CITY_POKEMON_CENTER_2F),
MAP(MAUVILLE_CITY_POKEMON_CENTER_1F),
MAP(MAUVILLE_CITY_POKEMON_CENTER_2F),
MAP(RUSTBORO_CITY_POKEMON_CENTER_1F),
MAP(RUSTBORO_CITY_POKEMON_CENTER_2F),
MAP(FORTREE_CITY_POKEMON_CENTER_1F),
MAP(FORTREE_CITY_POKEMON_CENTER_2F),
MAP(LILYCOVE_CITY_POKEMON_CENTER_1F),
MAP(LILYCOVE_CITY_POKEMON_CENTER_2F),
MAP(MOSSDEEP_CITY_POKEMON_CENTER_1F),
MAP(MOSSDEEP_CITY_POKEMON_CENTER_2F),
MAP(SOOTOPOLIS_CITY_POKEMON_CENTER_1F),
MAP(SOOTOPOLIS_CITY_POKEMON_CENTER_2F),
MAP(EVER_GRANDE_CITY_POKEMON_CENTER_1F),
MAP(EVER_GRANDE_CITY_POKEMON_CENTER_2F),
MAP(EVER_GRANDE_CITY_POKEMON_LEAGUE_1F),
MAP(EVER_GRANDE_CITY_POKEMON_LEAGUE_2F),
MAP(BATTLE_FRONTIER_POKEMON_CENTER_1F),
MAP(BATTLE_FRONTIER_POKEMON_CENTER_2F),
MAP(SINGLE_BATTLE_COLOSSEUM),
MAP(TRADE_CENTER),
MAP(RECORD_CORNER),
MAP(DOUBLE_BATTLE_COLOSSEUM),
0xFFFF,
};
static bool32 IsCurMapPokeCenter(void)
{
return IsCurMapInLocationList(gSaveLocationPokeCenterList);
}
static const u16 gSaveLocationReloadLocList[] = // there's only 1 location, and it's presumed its for the save reload feature for battle tower
{
MAP(BATTLE_TOWER_LOBBY),
0xFFFF,
};
static bool32 IsCurMapReloadLocation(void)
{
return IsCurMapInLocationList(gSaveLocationReloadLocList);
}
// nulled out list. unknown what this would have been
static const u16 gUnknown_0861440E[] =
{
0xFFFF,
};
bool32 sub_81AFCEC(void)
{
return IsCurMapInLocationList(gUnknown_0861440E);
}
static void TrySetPokeCenterWarpStatus(void)
{
if (IsCurMapPokeCenter() == FALSE)
gSaveBlock2Ptr->specialSaveWarp &= ~(POKECENTER_SAVEWARP);
else
gSaveBlock2Ptr->specialSaveWarp |= POKECENTER_SAVEWARP;
}
static void TrySetReloadWarpStatus(void)
{
if (!IsCurMapReloadLocation())
gSaveBlock2Ptr->specialSaveWarp &= ~(LOBBY_SAVEWARP);
else
gSaveBlock2Ptr->specialSaveWarp |= LOBBY_SAVEWARP;
}
// this function definitely sets a warp status, but because the list is empty, it's unknown what this does yet.
static void sub_81AFD5C(void)
{
if (!sub_81AFCEC())
gSaveBlock2Ptr->specialSaveWarp &= ~(UNK_SPECIAL_SAVE_WARP_FLAG_3);
else
gSaveBlock2Ptr->specialSaveWarp |= UNK_SPECIAL_SAVE_WARP_FLAG_3;
}
void TrySetMapSaveWarpStatus(void)
{
TrySetPokeCenterWarpStatus();
TrySetReloadWarpStatus();
sub_81AFD5C();
}
void sub_81AFDA0(void)
{
gSaveBlock2Ptr->field_A8 |= 0x8000;
gSaveBlock2Ptr->field_A8 |= 0x1;
gSaveBlock2Ptr->field_A8 |= 0x2;
gSaveBlock2Ptr->field_A8 |= 0x4;
gSaveBlock2Ptr->field_A8 |= 0x10;
gSaveBlock2Ptr->field_A8 |= 0x20;
gSaveBlock2Ptr->field_A8 |= 0x8;
}
void sub_81AFDD0(void)
{
gSaveBlock2Ptr->specialSaveWarp |= 0x80;
}