diff options
author | Phlosioneer <mattmdrr2@gmail.com> | 2019-02-15 03:40:57 -0500 |
---|---|---|
committer | Phlosioneer <mattmdrr2@gmail.com> | 2019-02-15 03:40:57 -0500 |
commit | 986d3d8b2fc03bc3e384da15e5d1be4af8507e7b (patch) | |
tree | 0dbc9b94fb4d643ed06a5e253eb65b7f0659ae94 /src | |
parent | e95140270be790b03e693f539770abfd6473916e (diff) |
Finish and polish new_game.c
Only one function is left undocumented. I tried to go into the assembly
to at least name it, but it clears fields in the save block that aren't
even documented yet.
Diffstat (limited to 'src')
-rw-r--r-- | src/easy_chat.c | 2 | ||||
-rw-r--r-- | src/event_data.c | 4 | ||||
-rw-r--r-- | src/frontier_util.c | 12 | ||||
-rw-r--r-- | src/link_rfu.c | 63 | ||||
-rw-r--r-- | src/new_game.c | 46 | ||||
-rw-r--r-- | src/pokedex.c | 7 | ||||
-rw-r--r-- | src/record_mixing.c | 2 | ||||
-rw-r--r-- | src/rom_8011DC0.c | 6 | ||||
-rw-r--r-- | src/save_location.c | 14 |
9 files changed, 81 insertions, 75 deletions
diff --git a/src/easy_chat.c b/src/easy_chat.c index c84895df5..7158253d1 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -359,7 +359,7 @@ void easy_chat_input_maybe(void) words = gSaveBlock2Ptr->apprentices[0].easyChatWords; break; case 20: - words = sub_801B058(); + words = GetSaveBlock1Field3564(); break; default: return; diff --git a/src/event_data.c b/src/event_data.c index a9da142e5..e75c37773 100644 --- a/src/event_data.c +++ b/src/event_data.c @@ -28,8 +28,6 @@ EWRAM_DATA static u8 gUnknown_020375FC[16] = {0}; extern u16 *const gSpecialVars[]; -extern void sub_80BB358(void); - void InitEventData(void) { memset(gSaveBlock1Ptr->flags, 0, sizeof(gSaveBlock1Ptr->flags)); @@ -69,7 +67,7 @@ void EnableNationalPokedex(void) FlagSet(FLAG_SYS_NATIONAL_DEX); gSaveBlock2Ptr->pokedex.mode = DEX_MODE_NATIONAL; gSaveBlock2Ptr->pokedex.order = 0; - sub_80BB358(); + ResetPokedexScrollPositions(); } bool32 IsNationalPokedexEnabled(void) diff --git a/src/frontier_util.c b/src/frontier_util.c index e6954c356..6fcbd4ffb 100644 --- a/src/frontier_util.c +++ b/src/frontier_util.c @@ -1528,7 +1528,7 @@ static void ShowLinkContestResultsWindow(void) static void sub_81A31FC(void) { - u8 text[32]; + u8 name[32]; s32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; s32 facility = VarGet(VAR_FRONTIER_FACILITY); s32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); @@ -1541,9 +1541,9 @@ static void sub_81A31FC(void) gSaveBlock2Ptr->frontier.towerRecordWinStreaks[battleMode][lvlMode] = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode]; if (battleMode == FRONTIER_MODE_LINK_MULTIS) { - StringCopy(text, gLinkPlayers[gBattleScripting.multiplayerId ^ 1].name); - StripExtCtrlCodes(text); - StringCopy(gSaveBlock2Ptr->frontier.field_EE1[lvlMode], text); + StringCopy(name, gLinkPlayers[gBattleScripting.multiplayerId ^ 1].name); + StripExtCtrlCodes(name); + StringCopy(gSaveBlock2Ptr->frontier.opponentName[lvlMode], name); SetTrainerId(gLinkPlayers[gBattleScripting.multiplayerId ^ 1].trainerId, gSaveBlock2Ptr->frontier.field_EF1[lvlMode]); } if (gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] > 1 @@ -2336,8 +2336,8 @@ static void PrintHallRecords(s32 hallFacilityId, s32 lvlMode) AddTextPrinterParameterized(gRecordsWindowId, 1, gLevelModeText[lvlMode], x, 1, TEXT_SPEED_FF, NULL); if (hallFacilityId == HALL_FACILITIES_COUNT) { - gSaveBlock2Ptr->frontier.field_EE1[0][PLAYER_NAME_LENGTH] = EOS; - gSaveBlock2Ptr->frontier.field_EE1[1][PLAYER_NAME_LENGTH] = EOS; + gSaveBlock2Ptr->frontier.opponentName[0][PLAYER_NAME_LENGTH] = EOS; + gSaveBlock2Ptr->frontier.opponentName[1][PLAYER_NAME_LENGTH] = EOS; Fill2PRecords(records2P, lvlMode); for (i = 0; i < 3; i++) Print2PRecord(i, 1, 4, &records2P[i]); diff --git a/src/link_rfu.c b/src/link_rfu.c index ebfc802e0..122ffd243 100644 --- a/src/link_rfu.c +++ b/src/link_rfu.c @@ -16,6 +16,7 @@ #include "task.h" #include "text.h" #include "constants/species.h" +#include "save.h" extern u16 gUnknown_03005DA8; extern void nullsub_89(u8 taskId); @@ -2347,17 +2348,17 @@ void sub_800E174(void) } } -void sub_800E378(struct UnkSaveSubstruct_3b98 *dest, u32 trainerId, const u8 *name) +void CopyTrainerRecord(struct TrainerNameRecord *dest, u32 trainerId, const u8 *name) { dest->trainerId = trainerId; StringCopy(dest->trainerName, name); } -bool32 sub_800E388(const u8 *name) +bool32 NameIsNotEmpty(const u8 *name) { s32 i; - for (i = 0; i < 8; i++) + for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++) { if (name[i] != 0) { @@ -2367,52 +2368,64 @@ bool32 sub_800E388(const u8 *name) return FALSE; } -void sub_800E3A8(void) +// Save the currently connected players into the trainer records, shifting all previous records down. +void RecordMixTrainerNames(void) { if (gWirelessCommType != 0) { s32 i; s32 j; - s32 cnt; - s32 sp0[5]; - struct UnkSaveSubstruct_3b98 *sp14 = calloc(20, sizeof(struct UnkSaveSubstruct_3b98)); + s32 nextSpace; + s32 connectedTrainerRecordIndecies[5]; + struct TrainerNameRecord *newRecords = calloc(20, sizeof(struct TrainerNameRecord)); + + // Check if we already have a record saved for connected trainers. for (i = 0; i < GetLinkPlayerCount(); i++) { - sp0[i] = -1; + connectedTrainerRecordIndecies[i] = -1; for (j = 0; j < 20; j++) { - if ((u16)gLinkPlayers[i].trainerId == gSaveBlock1Ptr->unk_3B98[j].trainerId && StringCompare(gLinkPlayers[i].name, gSaveBlock1Ptr->unk_3B98[j].trainerName) == 0) + if ((u16)gLinkPlayers[i].trainerId == gSaveBlock1Ptr->trainerNameRecords[j].trainerId && StringCompare(gLinkPlayers[i].name, gSaveBlock1Ptr->trainerNameRecords[j].trainerName) == 0) { - sp0[i] = j; + connectedTrainerRecordIndecies[i] = j; } } } - cnt = 0; + + // Save the connected trainers first, at the top of the list. + nextSpace = 0; for (i = 0; i < GetLinkPlayerCount(); i++) { if (i != GetMultiplayerId() && gLinkPlayers[i].language != LANGUAGE_JAPANESE) { - sub_800E378(&sp14[cnt], (u16)gLinkPlayers[i].trainerId, gLinkPlayers[i].name); - if (sp0[i] >= 0) + CopyTrainerRecord(&newRecords[nextSpace], (u16)gLinkPlayers[i].trainerId, gLinkPlayers[i].name); + + // If we already had a record for this trainer, wipe it so that the next step doesn't duplicate it. + if (connectedTrainerRecordIndecies[i] >= 0) { - memset(gSaveBlock1Ptr->unk_3B98[sp0[i]].trainerName, 0, 8); + memset(gSaveBlock1Ptr->trainerNameRecords[connectedTrainerRecordIndecies[i]].trainerName, 0, 8); } - cnt++; + nextSpace++; } } + + // Copy all non-empty records to the new list, in the order they appear on the old list. If the list is full, + // the last (oldest) records will be dropped. for (i = 0; i < 20; i++) { - if (sub_800E388(gSaveBlock1Ptr->unk_3B98[i].trainerName)) + if (NameIsNotEmpty(gSaveBlock1Ptr->trainerNameRecords[i].trainerName)) { - sub_800E378(&sp14[cnt], gSaveBlock1Ptr->unk_3B98[i].trainerId, gSaveBlock1Ptr->unk_3B98[i].trainerName); - if (++cnt >= 20) + CopyTrainerRecord(&newRecords[nextSpace], gSaveBlock1Ptr->trainerNameRecords[i].trainerId, gSaveBlock1Ptr->trainerNameRecords[i].trainerName); + if (++nextSpace >= 20) { break; } } } - memcpy(gSaveBlock1Ptr->unk_3B98, sp14, 20 * sizeof(struct UnkSaveSubstruct_3b98)); - free(sp14); + + // Finalize the new list, and clean up. + memcpy(gSaveBlock1Ptr->trainerNameRecords, newRecords, 20 * sizeof(struct TrainerNameRecord)); + free(newRecords); } } @@ -2422,11 +2435,11 @@ bool32 sub_800E540(u16 id, u8 *name) for (i = 0; i < 20; i++) { - if (StringCompare(gSaveBlock1Ptr->unk_3B98[i].trainerName, name) == 0 && gSaveBlock1Ptr->unk_3B98[i].trainerId == id) + if (StringCompare(gSaveBlock1Ptr->trainerNameRecords[i].trainerName, name) == 0 && gSaveBlock1Ptr->trainerNameRecords[i].trainerId == id) { return TRUE; } - if (!sub_800E388(gSaveBlock1Ptr->unk_3B98[i].trainerName)) + if (!NameIsNotEmpty(gSaveBlock1Ptr->trainerNameRecords[i].trainerName)) { return FALSE; } @@ -2434,14 +2447,14 @@ bool32 sub_800E540(u16 id, u8 *name) return FALSE; } -void sub_800E5AC(void) +void WipeTrainerNameRecords(void) { s32 i; for (i = 0; i < 20; i++) { - gSaveBlock1Ptr->unk_3B98[i].trainerId = 0; - CpuFill16(0, gSaveBlock1Ptr->unk_3B98[i].trainerName, 8); + gSaveBlock1Ptr->trainerNameRecords[i].trainerId = 0; + CpuFill16(0, gSaveBlock1Ptr->trainerNameRecords[i].trainerName, 8); } } diff --git a/src/new_game.c b/src/new_game.c index a4bf2951f..be84445bf 100644 --- a/src/new_game.c +++ b/src/new_game.c @@ -30,31 +30,25 @@ #include "apprentice.h" #include "frontier_util.h" #include "constants/maps.h" +#include "pokedex.h" +#include "save.h" +#include "link_rfu.h" +#include "main.h" +#include "contest.h" +#include "item_menu.h" +#include "pokemon_storage_system.h" +#include "decoration_inventory.h" +#include "secret_base.h" +#include "player_pc.h" +#include "field_specials.h" + -extern u16 gSaveFileStatus; -extern u8 gUnknown_030060B0; - -// TODO: replace those declarations with file headers -extern u16 GetGeneratedTrainerIdLower(void); -extern void ClearContestWinnerPicsInContestHall(void); -extern void sub_80BB358(void); -extern void ResetBagScrollPositions(void); -extern void ResetGabbyAndTy(void); -extern void ResetSecretBases(void); -extern void ResetLinkContestBoolean(void); -extern void sub_8052DA8(void); -extern void ResetPokemonStorageSystem(void); -extern void NewGameInitPCItems(void); -extern void ClearDecorationInventories(void); -extern void ResetFanClub(void); extern void copy_strings_to_sav1(void); extern void sub_801AFD8(void); -extern void sub_800E5AC(void); -extern void ResetContestLinkResults(void); extern void ResetPokeJumpResults(void); extern void SetBerryPowder(u32* powder, u32 newValue); -extern const u8 EventScript_2715DE[]; +extern const u8 EventScript_ResetAllMapFlags[]; // this file's functions static void ClearFrontierRecord(void); @@ -112,7 +106,7 @@ static void SetDefaultOptions(void) static void ClearPokedexFlags(void) { - gUnknown_030060B0 = 0; + gUnusedU8 = 0; memset(&gSaveBlock2Ptr->pokedex.owned, 0, sizeof(gSaveBlock2Ptr->pokedex.owned)); memset(&gSaveBlock2Ptr->pokedex.seen, 0, sizeof(gSaveBlock2Ptr->pokedex.seen)); } @@ -130,8 +124,8 @@ static void ClearFrontierRecord(void) { CpuFill32(0, &gSaveBlock2Ptr->frontier, sizeof(gSaveBlock2Ptr->frontier)); - gSaveBlock2Ptr->frontier.field_EE1[0][0] = EOS; - gSaveBlock2Ptr->frontier.field_EE1[1][0] = EOS; + gSaveBlock2Ptr->frontier.opponentName[0][0] = EOS; + gSaveBlock2Ptr->frontier.opponentName[1][0] = EOS; } static void WarpToTruck(void) @@ -149,7 +143,7 @@ void Sav2_ClearSetDefault(void) void ResetMenuAndMonGlobals(void) { gDifferentSaveFile = 0; - sub_80BB358(); + ResetPokedexScrollPositions(); ZeroPlayerPartyMons(); ZeroEnemyPartyMons(); ResetBagScrollPositions(); @@ -170,7 +164,7 @@ void NewGameInitData(void) ClearSav1(); ClearMailData(); gSaveBlock2Ptr->specialSaveWarpFlags = 0; - gSaveBlock2Ptr->field_A8 = 0; + gSaveBlock2Ptr->unusedFlagField = 0; InitPlayerTrainerId(); PlayTimeCounter_Reset(); ClearPokedexFlags(); @@ -203,7 +197,7 @@ void NewGameInitData(void) ResetFanClub(); ResetLotteryCorner(); WarpToTruck(); - ScriptContext2_RunNewScript(EventScript_2715DE); + ScriptContext2_RunNewScript(EventScript_ResetAllMapFlags); ResetMiniGamesResults(); copy_strings_to_sav1(); SetLilycoveLady(); @@ -211,7 +205,7 @@ void NewGameInitData(void) ClearRankingHallRecords(); InitMatchCallCounters(); sub_801AFD8(); - sub_800E5AC(); + WipeTrainerNameRecords(); ResetTrainerHillResults(); ResetContestLinkResults(); } diff --git a/src/pokedex.c b/src/pokedex.c index c47ada5b8..b2eba6836 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -37,7 +37,8 @@ static EWRAM_DATA u8 gUnknown_02039B52 = 0; static EWRAM_DATA struct PokedexListItem *sPokedexListItem = NULL; // IWRAM common -u8 gUnknown_030060B0; +// This is written to, but never read. +u8 gUnusedU8; void (*gUnknown_030060B4)(void); struct PokedexOption @@ -1225,7 +1226,7 @@ void ResetPokedex(void) gUnknown_02039B50 = 0; gUnknown_02039B52 = 64; - gUnknown_030060B0 = 0; + gUnusedU8 = 0; gSaveBlock2Ptr->pokedex.mode = DEX_MODE_HOENN; gSaveBlock2Ptr->pokedex.order = 0; gSaveBlock2Ptr->pokedex.nationalMagic = 0; @@ -1243,7 +1244,7 @@ void ResetPokedex(void) } } -void sub_80BB358(void) +void ResetPokedexScrollPositions(void) { gUnknown_02039B50 = 0; gUnknown_02039B52 = 64; diff --git a/src/record_mixing.c b/src/record_mixing.c index 189033685..c0ca5f19c 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -1087,7 +1087,7 @@ void GetPlayerHallRecords(struct PlayerHallRecords *dst) CopyTrainerId(dst->twoPlayers[j].id1, gSaveBlock2Ptr->playerTrainerId); CopyTrainerId(dst->twoPlayers[j].id2, gSaveBlock2Ptr->frontier.field_EF1[j]); StringCopy(dst->twoPlayers[j].name1, gSaveBlock2Ptr->playerName); - StringCopy(dst->twoPlayers[j].name2, gSaveBlock2Ptr->frontier.field_EE1[j]); + StringCopy(dst->twoPlayers[j].name2, gSaveBlock2Ptr->frontier.opponentName[j]); } for (i = 0; i < 2; i++) diff --git a/src/rom_8011DC0.c b/src/rom_8011DC0.c index 9bdd86167..baed26cf8 100644 --- a/src/rom_8011DC0.c +++ b/src/rom_8011DC0.c @@ -1687,7 +1687,7 @@ void sub_801440C(u8 taskId) case 9 ... 11: case 13: case 15: - sub_800E3A8(); + RecordMixTrainerNames(); break; } @@ -1800,12 +1800,12 @@ void sub_8014790(u8 taskId) sendBuff[1] = GetMonData(&gPlayerParty[gSelectedOrderFromParty[1] - 1], MON_DATA_SPECIES, NULL); gMain.savedCallback = NULL; data[0] = 4; - sub_800E3A8(); + RecordMixTrainerNames(); ResetBlockReceivedFlags(); break; case 16: case 23 ... 27: - sub_800E3A8(); + RecordMixTrainerNames(); DestroyTask(taskId); default: EnableBothScriptContexts(); diff --git a/src/save_location.c b/src/save_location.c index 2443b3161..20972873c 100644 --- a/src/save_location.c +++ b/src/save_location.c @@ -120,13 +120,13 @@ void TrySetMapSaveWarpStatus(void) 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; + gSaveBlock2Ptr->unusedFlagField |= 0x8000; + gSaveBlock2Ptr->unusedFlagField |= 0x1; + gSaveBlock2Ptr->unusedFlagField |= 0x2; + gSaveBlock2Ptr->unusedFlagField |= 0x4; + gSaveBlock2Ptr->unusedFlagField |= 0x10; + gSaveBlock2Ptr->unusedFlagField |= 0x20; + gSaveBlock2Ptr->unusedFlagField |= 0x8; } void sub_81AFDD0(void) |