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.
This commit is contained in:
Phlosioneer
2019-02-15 03:40:57 -05:00
parent e95140270b
commit 986d3d8b2f
23 changed files with 127 additions and 95 deletions

View File

@@ -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;

View File

@@ -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)

View File

@@ -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]);

View File

@@ -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);
}
}

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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++)

View File

@@ -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();

View File

@@ -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)