From 97bbb326b8c94e0fc90bceb4e5dea1b80f86822f Mon Sep 17 00:00:00 2001 From: Diegoisawesome Date: Sat, 20 Oct 2018 19:53:41 -0500 Subject: [PATCH] GameClear nonsense --- asm/post_battle_event_funcs.s | 148 -------------------------- include/load_save.h | 2 +- include/script_pokemon_util_80F87D8.h | 1 + ld_script.txt | 1 + src/load_save.c | 2 +- src/post_battle_event_funcs.c | 88 +++++++++++++++ 6 files changed, 92 insertions(+), 150 deletions(-) create mode 100644 src/post_battle_event_funcs.c diff --git a/asm/post_battle_event_funcs.s b/asm/post_battle_event_funcs.s index c6d4fd88f..7617152fd 100644 --- a/asm/post_battle_event_funcs.s +++ b/asm/post_battle_event_funcs.s @@ -5,154 +5,6 @@ .text - thumb_func_start GameClear -GameClear: @ 8137734 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x1C - bl HealPlayerParty - ldr r4, =0x00000864 - adds r0, r4, 0 - bl FlagGet - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0x1 - bne _08137760 - ldr r0, =gHasHallOfFameRecords - strb r1, [r0] - b _0813776C - .pool -_08137760: - ldr r1, =gHasHallOfFameRecords - movs r0, 0 - strb r0, [r1] - adds r0, r4, 0 - bl FlagSet -_0813776C: - movs r0, 0x1 - bl GetGameStat - cmp r0, 0 - bne _0813778E - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - ldrh r1, [r2, 0xE] - lsls r1, 16 - ldrb r0, [r2, 0x10] - lsls r0, 8 - orrs r1, r0 - ldrb r0, [r2, 0x11] - orrs r1, r0 - movs r0, 0x1 - bl SetGameStat -_0813778E: - bl sub_8076D48 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldrb r0, [r0, 0x8] - cmp r0, 0 - bne _081377AC - movs r0, 0x1 - bl sub_8084F6C - b _081377B2 - .pool -_081377AC: - movs r0, 0x2 - bl sub_8084F6C -_081377B2: - movs r7, 0 - movs r6, 0 - add r0, sp, 0x18 - mov r8, r0 - mov r5, sp -_081377BC: - movs r0, 0x64 - adds r1, r6, 0 - muls r1, r0 - ldr r0, =gPlayerParty - adds r4, r1, r0 - movs r0, 0 - strb r6, [r5] - strb r0, [r5, 0x1] - adds r0, r4, 0 - movs r1, 0x5 - bl GetMonData - cmp r0, 0 - beq _0813780A - adds r0, r4, 0 - movs r1, 0x6 - bl GetMonData - cmp r0, 0 - bne _0813780A - adds r0, r4, 0 - movs r1, 0x43 - bl GetMonData - cmp r0, 0 - bne _0813780A - movs r0, 0x1 - mov r1, r8 - strb r0, [r1] - adds r0, r4, 0 - movs r1, 0x43 - add r2, sp, 0x18 - bl SetMonData - adds r0, r4, 0 - bl GetRibbonCount - strb r0, [r5, 0x1] - movs r7, 0x1 -_0813780A: - adds r5, 0x4 - adds r6, 0x1 - cmp r6, 0x5 - ble _081377BC - cmp r7, 0x1 - bne _0813785A - movs r0, 0x2A - bl IncrementGameStat - ldr r0, =0x0000089b - bl FlagSet - mov r3, sp - add r2, sp, 0x4 - movs r6, 0x4 -_08137828: - ldrb r1, [r3, 0x1] - ldrb r0, [r2, 0x1] - cmp r0, r1 - bls _08137838 - ldr r1, [sp] - ldr r0, [r2] - str r0, [sp] - str r1, [r2] -_08137838: - adds r2, 0x4 - subs r6, 0x1 - cmp r6, 0 - bge _08137828 - mov r0, sp - ldrb r0, [r0, 0x1] - cmp r0, 0x4 - bls _0813785A - mov r0, sp - ldrb r1, [r0] - movs r0, 0x64 - muls r0, r1 - ldr r1, =gPlayerParty - adds r0, r1 - movs r1, 0x43 - bl sub_80EE4DC -_0813785A: - ldr r0, =CB2_DoHallOfFameScreen - bl SetMainCallback2 - movs r0, 0 - add sp, 0x1C - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end GameClear - thumb_func_start sp0C8_whiteout_maybe sp0C8_whiteout_maybe: @ 813787C push {lr} diff --git a/include/load_save.h b/include/load_save.h index 5fb5f6c42..b8b27ade5 100644 --- a/include/load_save.h +++ b/include/load_save.h @@ -17,7 +17,7 @@ void SetSaveBlocksPointers(u16 offset); void MoveSaveBlocks_ResetHeap(void); u32 GetSecretBase2Field_9(void); void ClearSecretBase2Field_9(void); -void sub_8076D48(void); +void SetSecretBase2Field_9(void); void sub_8076D5C(void); void sav2_gender2_inplace_and_xFE(void); void SavePlayerParty(void); diff --git a/include/script_pokemon_util_80F87D8.h b/include/script_pokemon_util_80F87D8.h index 68aec7eb6..7c2a1ff66 100644 --- a/include/script_pokemon_util_80F87D8.h +++ b/include/script_pokemon_util_80F87D8.h @@ -4,5 +4,6 @@ u16 sub_80F903C(void); void ReducePlayerPartyToThree(void); +void HealPlayerParty(void); #endif // GUARD_SCRIPT_POKEMON_UTIL_80F87D8_H diff --git a/ld_script.txt b/ld_script.txt index 77f95e96f..d5a37c611 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -178,6 +178,7 @@ SECTIONS { src/rom6.o(.text); src/pokeblock.o(.text); src/fldeff_flash.o(.text); + src/post_battle_event_funcs.o(.text); asm/post_battle_event_funcs.o(.text); src/time_events.o(.text); src/birch_pc.o(.text); diff --git a/src/load_save.c b/src/load_save.c index 005af7c42..45b4d200b 100644 --- a/src/load_save.c +++ b/src/load_save.c @@ -144,7 +144,7 @@ void ClearSecretBase2Field_9(void) gSaveBlock2Ptr->specialSaveWarp &= ~1; } -void sub_8076D48(void) +void SetSecretBase2Field_9(void) { gSaveBlock2Ptr->specialSaveWarp |= 1; } diff --git a/src/post_battle_event_funcs.c b/src/post_battle_event_funcs.c new file mode 100644 index 000000000..8df702570 --- /dev/null +++ b/src/post_battle_event_funcs.c @@ -0,0 +1,88 @@ +#include "global.h" +#include "main.h" +#include "credits.h" +#include "event_data.h" +#include "hall_of_fame.h" +#include "load_save.h" +#include "overworld.h" +#include "script_pokemon_util_80F87D8.h" +#include "tv.h" +#include "constants/heal_locations.h" +#include "constants/flags.h" + +int GameClear(void) +{ + int i; + bool32 ribbonGet; + struct RibbonCounter { + u8 partyIndex; + u8 count; + } ribbonCounts[6]; + s8 val; + + HealPlayerParty(); + + if (FlagGet(FLAG_SYS_GAME_CLEAR) == TRUE) + { + gHasHallOfFameRecords = TRUE; + } + else + { + gHasHallOfFameRecords = FALSE; + FlagSet(FLAG_SYS_GAME_CLEAR); + } + + if (GetGameStat(GAME_STAT_FIRST_HOF_PLAY_TIME) == 0) + SetGameStat(GAME_STAT_FIRST_HOF_PLAY_TIME, (gSaveBlock2Ptr->playTimeHours << 16) | (gSaveBlock2Ptr->playTimeMinutes << 8) | gSaveBlock2Ptr->playTimeSeconds); + + SetSecretBase2Field_9(); + + if (gSaveBlock2Ptr->playerGender == MALE) + sub_8084F6C(HEAL_LOCATION_LITTLEROOT_TOWN_BRENDANS_HOUSE_2F); + else + sub_8084F6C(HEAL_LOCATION_LITTLEROOT_TOWN_MAYS_HOUSE_2F); + + ribbonGet = FALSE; + + for (i = 0; i < 6; i++) + { + struct Pokemon *mon = &gPlayerParty[i]; + + ribbonCounts[i].partyIndex = i; + ribbonCounts[i].count = 0; + + if (GetMonData(mon, MON_DATA_SANITY_BIT2) + && !GetMonData(mon, MON_DATA_SANITY_BIT3) + && !GetMonData(mon, MON_DATA_CHAMPION_RIBBON)) + { + val = TRUE; + SetMonData(mon, MON_DATA_CHAMPION_RIBBON, &val); + ribbonCounts[i].count = GetRibbonCount(mon); + ribbonGet = TRUE; + } + } + + if (ribbonGet == TRUE) + { + IncrementGameStat(GAME_STAT_RECEIVED_RIBBONS); + FlagSet(FLAG_SYS_RIBBON_GET); + + for (i = 1; i < 6; i++) + { + if (ribbonCounts[0].count > ribbonCounts[i].count) + { + struct RibbonCounter prevBest = ribbonCounts[0]; + ribbonCounts[0] = ribbonCounts[i]; + ribbonCounts[i] = prevBest; + } + } + + if (ribbonCounts[0].count > 4) + { + sub_80EE4DC(&gPlayerParty[ribbonCounts[0].partyIndex], MON_DATA_CHAMPION_RIBBON); + } + } + + SetMainCallback2(CB2_DoHallOfFameScreen); + return 0; +}