fix merge conflict and use EVENT_OBJECT_TEMPLATES_COUNT
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "battle_controllers.h"
|
||||
#include "battle_interface.h"
|
||||
#include "battle_message.h"
|
||||
#include "battle_pyramid.h"
|
||||
#include "battle_scripts.h"
|
||||
#include "battle_setup.h"
|
||||
#include "battle_tower.h"
|
||||
@@ -109,10 +110,8 @@ extern const u8 gText_Love[];
|
||||
// functions
|
||||
extern void sub_81B9150(void);
|
||||
extern void sub_80B3AF8(u8 taskId); // cable club
|
||||
extern u8 sub_81A9E28(void); // battle frontier 2
|
||||
extern void sub_81B8FB0(u8, u8); // party menu
|
||||
extern u8 pokemon_order_func(u8); // party menu
|
||||
extern bool8 InBattlePyramid(void);
|
||||
|
||||
// this file's functions
|
||||
static void CB2_InitBattleInternal(void);
|
||||
@@ -5604,7 +5603,7 @@ bool8 TryRunFromBattle(u8 battler)
|
||||
if (InBattlePyramid())
|
||||
{
|
||||
gBattleStruct->runTries++;
|
||||
pyramidMultiplier = sub_81A9E28();
|
||||
pyramidMultiplier = GetPyramidRunMultiplier();
|
||||
speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30);
|
||||
if (speedVar > (Random() & 0xFF))
|
||||
{
|
||||
@@ -5630,7 +5629,7 @@ bool8 TryRunFromBattle(u8 battler)
|
||||
{
|
||||
if (InBattlePyramid())
|
||||
{
|
||||
pyramidMultiplier = sub_81A9E28();
|
||||
pyramidMultiplier = GetPyramidRunMultiplier();
|
||||
speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30);
|
||||
if (speedVar > (Random() & 0xFF))
|
||||
effect++;
|
||||
|
||||
1297
src/battle_pyramid.c
Normal file
1297
src/battle_pyramid.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -45,6 +45,7 @@
|
||||
#include "party_menu.h"
|
||||
#include "battle_arena.h"
|
||||
#include "battle_pike.h"
|
||||
#include "battle_pyramid.h"
|
||||
|
||||
extern u16 gBattle_BG1_X;
|
||||
extern u16 gBattle_BG1_Y;
|
||||
@@ -62,11 +63,8 @@ extern void sub_81D388C(struct Pokemon* mon, void* statStoreLocation); // pokena
|
||||
extern void sub_81D3640(u8 arg0, void* statStoreLocation1, void* statStoreLocation2, u8 arg3, u8 arg4, u8 arg5); // pokenav.s
|
||||
extern void sub_81D3784(u8 arg0, void* statStoreLocation1, u8 arg2, u8 arg3, u8 arg4); // pokenav.s
|
||||
extern u8* GetMonNickname(struct Pokemon* mon, u8* dst); // party_menu
|
||||
extern u8 BattleArena_ShowJudgmentWindow(u8* arg0); // battle frontier 2
|
||||
extern void sub_81B8E80(u8 battlerId, u8, u8); // party menu
|
||||
extern bool8 sub_81B1250(void); // ?
|
||||
extern bool8 InBattlePyramid(void);
|
||||
extern u16 GetBattlePyramidPickupItemId(void);
|
||||
extern u8 sub_813B21C(void);
|
||||
extern u16 get_unknown_box_id(void);
|
||||
|
||||
@@ -9860,71 +9858,72 @@ static void atkE4_getsecretpowereffect(void)
|
||||
|
||||
static void atkE5_pickup(void)
|
||||
{
|
||||
if (!InBattlePike())
|
||||
s32 i;
|
||||
u16 species, heldItem;
|
||||
u8 ability;
|
||||
|
||||
if (InBattlePike())
|
||||
{
|
||||
s32 i;
|
||||
u16 species, heldItem;
|
||||
u8 ability;
|
||||
|
||||
if (InBattlePyramid())
|
||||
}
|
||||
else if (InBattlePyramid())
|
||||
{
|
||||
for (i = 0; i < PARTY_SIZE; i++)
|
||||
{
|
||||
for (i = 0; i < PARTY_SIZE; i++)
|
||||
species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2);
|
||||
heldItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM);
|
||||
|
||||
if (GetMonData(&gPlayerParty[i], MON_DATA_ALT_ABILITY))
|
||||
ability = gBaseStats[species].ability2;
|
||||
else
|
||||
ability = gBaseStats[species].ability1;
|
||||
|
||||
if (ability == ABILITY_PICKUP
|
||||
&& species != 0
|
||||
&& species != SPECIES_EGG
|
||||
&& heldItem == ITEM_NONE
|
||||
&& (Random() % 10) == 0)
|
||||
{
|
||||
species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2);
|
||||
heldItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM);
|
||||
|
||||
if (GetMonData(&gPlayerParty[i], MON_DATA_ALT_ABILITY))
|
||||
ability = gBaseStats[species].ability2;
|
||||
else
|
||||
ability = gBaseStats[species].ability1;
|
||||
|
||||
if (ability == ABILITY_PICKUP
|
||||
&& species != 0
|
||||
&& species != SPECIES_EGG
|
||||
&& heldItem == ITEM_NONE
|
||||
&& (Random() % 10) == 0)
|
||||
{
|
||||
heldItem = GetBattlePyramidPickupItemId();
|
||||
SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &heldItem);
|
||||
}
|
||||
heldItem = GetBattlePyramidPickupItemId();
|
||||
SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &heldItem);
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < PARTY_SIZE; i++)
|
||||
{
|
||||
for (i = 0; i < PARTY_SIZE; i++)
|
||||
species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2);
|
||||
heldItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM);
|
||||
|
||||
if (GetMonData(&gPlayerParty[i], MON_DATA_ALT_ABILITY))
|
||||
ability = gBaseStats[species].ability2;
|
||||
else
|
||||
ability = gBaseStats[species].ability1;
|
||||
|
||||
if (ability == ABILITY_PICKUP
|
||||
&& species != 0
|
||||
&& species != SPECIES_EGG
|
||||
&& heldItem == ITEM_NONE
|
||||
&& (Random() % 10) == 0)
|
||||
{
|
||||
species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2);
|
||||
heldItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM);
|
||||
s32 j;
|
||||
s32 rand = Random() % 100;
|
||||
u8 lvlDivBy10 = (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) - 1) / 10;
|
||||
if (lvlDivBy10 > 9)
|
||||
lvlDivBy10 = 9;
|
||||
|
||||
if (GetMonData(&gPlayerParty[i], MON_DATA_ALT_ABILITY))
|
||||
ability = gBaseStats[species].ability2;
|
||||
else
|
||||
ability = gBaseStats[species].ability1;
|
||||
|
||||
if (ability == ABILITY_PICKUP
|
||||
&& species != 0
|
||||
&& species != SPECIES_EGG
|
||||
&& heldItem == ITEM_NONE
|
||||
&& (Random() % 10) == 0)
|
||||
for (j = 0; j < 9; j++)
|
||||
{
|
||||
s32 j;
|
||||
s32 rand = Random() % 100;
|
||||
u8 lvlDivBy10 = (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) - 1) / 10;
|
||||
if (lvlDivBy10 > 9)
|
||||
lvlDivBy10 = 9;
|
||||
|
||||
for (j = 0; j < 9; j++)
|
||||
if (sPickupProbabilities[j] > rand)
|
||||
{
|
||||
if (sPickupProbabilities[j] > rand)
|
||||
{
|
||||
SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sPickupItems[lvlDivBy10 + j]);
|
||||
break;
|
||||
}
|
||||
else if (rand == 99 || rand == 98)
|
||||
{
|
||||
SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sRarePickupItems[lvlDivBy10 + (99 - rand)]);
|
||||
break;
|
||||
}
|
||||
SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sPickupItems[lvlDivBy10 + j]);
|
||||
break;
|
||||
}
|
||||
else if (rand == 99 || rand == 98)
|
||||
{
|
||||
SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sRarePickupItems[lvlDivBy10 + (99 - rand)]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "battle_tower.h"
|
||||
#include "gym_leader_rematch.h"
|
||||
#include "battle_pike.h"
|
||||
#include "battle_pyramid.h"
|
||||
#include "constants/map_types.h"
|
||||
#include "constants/battle_frontier.h"
|
||||
|
||||
@@ -54,7 +55,6 @@ struct TrainerBattleParameter
|
||||
u8 ptrType;
|
||||
};
|
||||
|
||||
extern bool8 InBattlePyramid(void);
|
||||
extern bool32 InTrainerHill(void);
|
||||
extern bool32 FieldPoisonEffectIsRunning(void);
|
||||
extern void RestartWildEncounterImmunitySteps(void);
|
||||
@@ -63,17 +63,13 @@ extern void sub_81BE72C(void);
|
||||
extern void sub_808BCF4(void);
|
||||
extern void sub_80EECC8(void);
|
||||
extern void sub_80AF6F0(void);
|
||||
extern u16 sub_81A9AA8(u8 localId);
|
||||
extern u16 sub_81D6180(u8 localId);
|
||||
extern bool8 GetBattlePyramidTrainerFlag(u8 eventObjId);
|
||||
extern bool8 GetTrainerHillTrainerFlag(u8 eventObjId);
|
||||
extern bool8 sub_81D5C18(void);
|
||||
extern void sub_81A9B04(void);
|
||||
extern void sub_81D639C(void);
|
||||
extern void sub_81D6384(void);
|
||||
extern void sub_81D61E8(void);
|
||||
extern void sub_80982B8(void);
|
||||
extern void sub_81A9EDC(u16 a0);
|
||||
extern void CopyTrainerHillTrainerText(u8 a0, u16 arg1);
|
||||
|
||||
// this file's functions
|
||||
@@ -1131,12 +1127,12 @@ const u8 *BattleSetup_ConfigureTrainerBattle(const u8 *data)
|
||||
{
|
||||
TrainerBattleLoadArgs(sOrdinaryBattleParams, data);
|
||||
SetMapVarsToTrainer();
|
||||
gTrainerBattleOpponent_A = sub_81A9AA8(gSpecialVar_LastTalked);
|
||||
gTrainerBattleOpponent_A = LocalIdToPyramidTrainerId(gSpecialVar_LastTalked);
|
||||
}
|
||||
else
|
||||
{
|
||||
TrainerBattleLoadArgs(sTrainerBOrdinaryBattleParams, data);
|
||||
gTrainerBattleOpponent_B = sub_81A9AA8(gSpecialVar_LastTalked);
|
||||
gTrainerBattleOpponent_B = LocalIdToPyramidTrainerId(gSpecialVar_LastTalked);
|
||||
}
|
||||
return EventScript_271362;
|
||||
case TRAINER_BATTLE_SET_TRAINER_A:
|
||||
@@ -1360,9 +1356,9 @@ void ShowTrainerIntroSpeech(void)
|
||||
if (InBattlePyramid())
|
||||
{
|
||||
if (gNoOfApproachingTrainers == 0 || gNoOfApproachingTrainers == 1)
|
||||
sub_81A9EDC(sub_81A9AA8(gSpecialVar_LastTalked));
|
||||
CopyPyramidTrainerSpeechBefore(LocalIdToPyramidTrainerId(gSpecialVar_LastTalked));
|
||||
else
|
||||
sub_81A9EDC(sub_81A9AA8(gEventObjects[gApproachingTrainers[gApproachingTrainerId].eventObjectId].localId));
|
||||
CopyPyramidTrainerSpeechBefore(LocalIdToPyramidTrainerId(gEventObjects[gApproachingTrainers[gApproachingTrainerId].eventObjectId].localId));
|
||||
|
||||
sub_80982B8();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "bg.h"
|
||||
#include "text_window.h"
|
||||
#include "constants/songs.h"
|
||||
#include "constants/rgb.h"
|
||||
|
||||
extern const u8 gText_ClearAllSaveData[];
|
||||
extern const u8 gText_ClearingData[];
|
||||
@@ -72,7 +73,7 @@ static const struct WindowTemplate sClearSaveYesNo[] =
|
||||
|
||||
void CB2_InitClearSaveDataScreen(void)
|
||||
{
|
||||
if(SetupClearSaveDataScreen())
|
||||
if (SetupClearSaveDataScreen())
|
||||
CreateTask(Task_DoClearSaveDataScreenYesNo, 0);
|
||||
}
|
||||
|
||||
@@ -86,18 +87,18 @@ static void Task_DoClearSaveDataScreenYesNo(u8 taskId)
|
||||
|
||||
static void Task_ClearSaveDataScreenYesNoChoice(u8 taskId)
|
||||
{
|
||||
switch(Menu_ProcessInputNoWrapClearOnChoose())
|
||||
switch (Menu_ProcessInputNoWrapClearOnChoose())
|
||||
{
|
||||
case 0:
|
||||
FillWindowPixelBuffer(0, 17);
|
||||
AddTextPrinterParameterized(0, 1, gText_ClearingData, 0, 1, 0, 0);
|
||||
gTasks[taskId].func = Task_ClearSaveData;
|
||||
break;
|
||||
case 1:
|
||||
case -1:
|
||||
PlaySE(SE_SELECT);
|
||||
DestroyTask(taskId);
|
||||
SetMainCallback2(CB2_FadeAndDoReset);
|
||||
case 0:
|
||||
FillWindowPixelBuffer(0, 17);
|
||||
AddTextPrinterParameterized(0, 1, gText_ClearingData, 0, 1, 0, 0);
|
||||
gTasks[taskId].func = Task_ClearSaveData;
|
||||
break;
|
||||
case 1:
|
||||
case -1:
|
||||
PlaySE(SE_SELECT);
|
||||
DestroyTask(taskId);
|
||||
SetMainCallback2(CB2_FadeAndDoReset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,55 +126,55 @@ static bool8 SetupClearSaveDataScreen(void)
|
||||
|
||||
switch(gMain.state)
|
||||
{
|
||||
case 0:
|
||||
default:
|
||||
SetVBlankCallback(NULL);
|
||||
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0);
|
||||
SetGpuReg(REG_OFFSET_BG0HOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG0VOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG3HOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG3VOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_WIN0H, 0);
|
||||
SetGpuReg(REG_OFFSET_WIN0V, 0);
|
||||
SetGpuReg(REG_OFFSET_WININ, 0);
|
||||
SetGpuReg(REG_OFFSET_WINOUT, 0);
|
||||
SetGpuReg(REG_OFFSET_BLDCNT, 0);
|
||||
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
|
||||
SetGpuReg(REG_OFFSET_BLDY, 0);
|
||||
DmaFill16(3, 0, (void *)VRAM, VRAM_SIZE);
|
||||
DmaFill32(3, 0, (void *)OAM, OAM_SIZE);
|
||||
DmaFill16(3, 0, (void *)(PLTT + 2), PLTT_SIZE - 2);
|
||||
ResetPaletteFade();
|
||||
gPlttBufferUnfaded[0] = 0x7fff;
|
||||
gPlttBufferFaded[0] = 0x7fff;
|
||||
gPlttBufferUnfaded[1] = 0x3945;
|
||||
gPlttBufferFaded[1] = 0x3945;
|
||||
for (i = 0; i < 0x10; i++)
|
||||
((u16 *)(VRAM + 0x20))[i] = 0x1111;
|
||||
case 0:
|
||||
default:
|
||||
SetVBlankCallback(NULL);
|
||||
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0);
|
||||
SetGpuReg(REG_OFFSET_BG0HOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG0VOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG3HOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG3VOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_WIN0H, 0);
|
||||
SetGpuReg(REG_OFFSET_WIN0V, 0);
|
||||
SetGpuReg(REG_OFFSET_WININ, 0);
|
||||
SetGpuReg(REG_OFFSET_WINOUT, 0);
|
||||
SetGpuReg(REG_OFFSET_BLDCNT, 0);
|
||||
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
|
||||
SetGpuReg(REG_OFFSET_BLDY, 0);
|
||||
DmaFill16(3, 0, (void *)VRAM, VRAM_SIZE);
|
||||
DmaFill32(3, 0, (void *)OAM, OAM_SIZE);
|
||||
DmaFill16(3, 0, (void *)(PLTT + 2), PLTT_SIZE - 2);
|
||||
ResetPaletteFade();
|
||||
gPlttBufferUnfaded[0] = RGB_WHITE;
|
||||
gPlttBufferFaded[0] = RGB_WHITE;
|
||||
gPlttBufferUnfaded[1] = RGB(5, 10, 14);
|
||||
gPlttBufferFaded[1] = RGB(5, 10, 14);
|
||||
for (i = 0; i < 0x10; i++)
|
||||
((u16 *)(VRAM + 0x20))[i] = 0x1111;
|
||||
|
||||
for (i = 0; i < 0x400; i++)
|
||||
((u16 *)(VRAM + 0xF000))[i] = 0x0001;
|
||||
ResetTasks();
|
||||
ResetSpriteData();
|
||||
ResetBgsAndClearDma3BusyFlags(0);
|
||||
InitBgsFromTemplates(0, sClearSaveBgTemplates, ARRAY_COUNT(sClearSaveBgTemplates));
|
||||
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
|
||||
ShowBg(0);
|
||||
ShowBg(3);
|
||||
SetGpuReg(REG_OFFSET_BLDCNT, 0);
|
||||
InitClearSaveDataScreenWindows();
|
||||
BeginNormalPaletteFade(0x0000FFFF, 0, 0x10, 0, 0xFFFF);
|
||||
EnableInterrupts(1);
|
||||
SetVBlankCallback(VBlankCB);
|
||||
gMain.state = 1;
|
||||
break;
|
||||
case 1:
|
||||
UpdatePaletteFade();
|
||||
if(!gPaletteFade.active)
|
||||
{
|
||||
SetMainCallback2(MainCB);
|
||||
return TRUE;
|
||||
}
|
||||
for (i = 0; i < 0x400; i++)
|
||||
((u16 *)(VRAM + 0xF000))[i] = 0x0001;
|
||||
ResetTasks();
|
||||
ResetSpriteData();
|
||||
ResetBgsAndClearDma3BusyFlags(0);
|
||||
InitBgsFromTemplates(0, sClearSaveBgTemplates, ARRAY_COUNT(sClearSaveBgTemplates));
|
||||
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
|
||||
ShowBg(0);
|
||||
ShowBg(3);
|
||||
SetGpuReg(REG_OFFSET_BLDCNT, 0);
|
||||
InitClearSaveDataScreenWindows();
|
||||
BeginNormalPaletteFade(0x0000FFFF, 0, 0x10, 0, 0xFFFF);
|
||||
EnableInterrupts(INTR_FLAG_VBLANK);
|
||||
SetVBlankCallback(VBlankCB);
|
||||
gMain.state = 1;
|
||||
break;
|
||||
case 1:
|
||||
UpdatePaletteFade();
|
||||
if(!gPaletteFade.active)
|
||||
{
|
||||
SetMainCallback2(MainCB);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
@@ -182,18 +183,19 @@ static void CB2_FadeAndDoReset(void)
|
||||
{
|
||||
switch(gMain.state)
|
||||
{
|
||||
case 0:
|
||||
default:
|
||||
BeginNormalPaletteFade(0x0000FFFF, 0, 0, 0x10, 0xFFFF);
|
||||
gMain.state = 1;
|
||||
break;
|
||||
case 1:
|
||||
UpdatePaletteFade();
|
||||
if(!gPaletteFade.active)
|
||||
{
|
||||
FreeAllWindowBuffers();
|
||||
DoSoftReset();
|
||||
}
|
||||
case 0:
|
||||
default:
|
||||
BeginNormalPaletteFade(0x0000FFFF, 0, 0, 0x10, RGB_WHITEALPHA);
|
||||
gMain.state = 1;
|
||||
break;
|
||||
case 1:
|
||||
UpdatePaletteFade();
|
||||
if(!gPaletteFade.active)
|
||||
{
|
||||
FreeAllWindowBuffers();
|
||||
DoSoftReset();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2559,7 +2559,7 @@ struct EventObjectTemplate *GetBaseTemplateForEventObject(const struct EventObje
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < 64; i++) // Using ARRAY_COUNT here results in the wrong conditional branch instruction (bls instead of ble)
|
||||
for (i = 0; i < EVENT_OBJECT_TEMPLATES_COUNT; i++)
|
||||
{
|
||||
if (eventObject->localId == gSaveBlock1Ptr->eventObjectTemplates[i].localId)
|
||||
{
|
||||
|
||||
@@ -1485,7 +1485,7 @@ const u32 gUnknown_08DD4C4C[] = INCBIN_U32("graphics/link/link_winedge.bin.lz");
|
||||
|
||||
const u32 gUnknown_08DD4CF8[] = INCBIN_U32("graphics/interface/unk_change_case.4bpp.lz");
|
||||
|
||||
const u16 gTilesetPalettes_General[][16] =
|
||||
const u16 gTilesetPalettes_General[][16] =
|
||||
{
|
||||
INCBIN_U16("data/tilesets/primary/general/palettes/00.gbapal"),
|
||||
INCBIN_U16("data/tilesets/primary/general/palettes/01.gbapal"),
|
||||
|
||||
@@ -521,7 +521,7 @@ static void Task_Hof_InitTeamSaveData(u8 taskId)
|
||||
static void Task_Hof_TrySaveData(u8 taskId)
|
||||
{
|
||||
gGameContinueCallback = CB2_DoHallOfFameScreenDontSaveData;
|
||||
if (TrySavingData(3) == 0xFF && gDamagedSaveSectors != 0)
|
||||
if (TrySavingData(SAVE_HALL_OF_FAME) == 0xFF && gDamagedSaveSectors != 0)
|
||||
{
|
||||
UnsetBgTilemapBuffer(1);
|
||||
UnsetBgTilemapBuffer(3);
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include "item_menu.h"
|
||||
#include "strings.h"
|
||||
#include "load_save.h"
|
||||
#include "battle_pyramid.h"
|
||||
#include "battle_pyramid_bag.h"
|
||||
|
||||
extern bool8 InBattlePyramid(void);
|
||||
extern u16 gUnknown_0203CF30[];
|
||||
extern const struct Item gItems[];
|
||||
|
||||
|
||||
@@ -6,14 +6,15 @@
|
||||
#include "random.h"
|
||||
#include "malloc.h"
|
||||
#include "item.h"
|
||||
#include "overworld.h"
|
||||
#include "decoration_inventory.h"
|
||||
|
||||
static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey);
|
||||
|
||||
extern void* gUnknown_0203CF5C;
|
||||
|
||||
extern bool16 IdentifyFlash(void);
|
||||
extern void SetDecorationInventoriesPointers(void);
|
||||
extern void ApplyNewEncryptionKeyToGameStats(u32 key);
|
||||
extern void ApplyNewEncryptionKeyToBerryPowder(u32 key);
|
||||
extern void sub_8084FAC(int unused);
|
||||
|
||||
#define SAVEBLOCK_MOVE_RANGE 128
|
||||
|
||||
@@ -286,7 +287,7 @@ void ApplyNewEncryptionKeyToWord(u32 *word, u32 newKey)
|
||||
*word ^= newKey;
|
||||
}
|
||||
|
||||
void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey)
|
||||
static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey)
|
||||
{
|
||||
ApplyNewEncryptionKeyToGameStats(encryptionKey);
|
||||
ApplyNewEncryptionKeyToBagItems_(encryptionKey);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "global.h"
|
||||
#include "overworld.h"
|
||||
#include "battle_pyramid.h"
|
||||
#include "battle_setup.h"
|
||||
#include "berry.h"
|
||||
#include "bg.h"
|
||||
@@ -113,7 +114,6 @@ extern void ShowMapNamePopup(void);
|
||||
extern bool32 InTrainerHill(void);
|
||||
extern bool32 sub_808651C(void);
|
||||
extern bool8 sub_80AF6A4(void);
|
||||
extern bool8 sub_81A9E6C(void);
|
||||
extern bool8 sub_80E909C(void);
|
||||
extern void sub_81AA1D8(void);
|
||||
extern void c2_change_map(void);
|
||||
@@ -517,7 +517,7 @@ void LoadSaveblockEventObjScripts(void)
|
||||
struct EventObjectTemplate *savObjTemplates = gSaveBlock1Ptr->eventObjectTemplates;
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < 64; i++)
|
||||
for (i = 0; i < EVENT_OBJECT_TEMPLATES_COUNT; i++)
|
||||
savObjTemplates[i].script = mapHeaderObjTemplates[i].script;
|
||||
}
|
||||
|
||||
@@ -526,7 +526,7 @@ void Overworld_SetEventObjTemplateCoords(u8 localId, s16 x, s16 y)
|
||||
s32 i;
|
||||
struct EventObjectTemplate *savObjTemplates = gSaveBlock1Ptr->eventObjectTemplates;
|
||||
|
||||
for (i = 0; i < 64; i++)
|
||||
for (i = 0; i < EVENT_OBJECT_TEMPLATES_COUNT; i++)
|
||||
{
|
||||
struct EventObjectTemplate *eventObjectTemplate = &savObjTemplates[i];
|
||||
if (eventObjectTemplate->localId == localId)
|
||||
@@ -543,7 +543,7 @@ void Overworld_SetEventObjTemplateMovementType(u8 localId, u8 movementType)
|
||||
s32 i;
|
||||
|
||||
struct EventObjectTemplate *savObjTemplates = gSaveBlock1Ptr->eventObjectTemplates;
|
||||
for (i = 0; i < 64; i++)
|
||||
for (i = 0; i < EVENT_OBJECT_TEMPLATES_COUNT; i++)
|
||||
{
|
||||
struct EventObjectTemplate *eventObjectTemplate = &savObjTemplates[i];
|
||||
if (eventObjectTemplate->localId == localId)
|
||||
@@ -764,7 +764,7 @@ void sub_8084F6C(u8 a1)
|
||||
SetWarpData(&gSaveBlock1Ptr->warp1, warp->group, warp->map, -1, warp->x, warp->y);
|
||||
}
|
||||
|
||||
void sub_8084FAC(void)
|
||||
void sub_8084FAC(int unused)
|
||||
{
|
||||
gSaveBlock1Ptr->warp1 = gSaveBlock1Ptr->warp2;
|
||||
}
|
||||
@@ -1808,7 +1808,7 @@ static void InitCurrentFlashLevelScanlineEffect(void)
|
||||
{
|
||||
u8 flashLevel;
|
||||
|
||||
if (sub_81A9E6C())
|
||||
if (InBattlePyramid_())
|
||||
{
|
||||
door_upload_tiles();
|
||||
ScanlineEffect_SetParams(sFlashEffectParams);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "battle_controllers.h"
|
||||
#include "battle_message.h"
|
||||
#include "battle_pike.h"
|
||||
#include "battle_pyramid.h"
|
||||
#include "battle_setup.h"
|
||||
#include "battle_tower.h"
|
||||
#include "event_data.h"
|
||||
@@ -81,9 +82,7 @@ extern u8 StorageGetCurrentBox(void);
|
||||
extern void set_unknown_box_id(u8);
|
||||
extern void sub_803FA70(u8 battlerId);
|
||||
extern u8 sav1_map_get_name(void);
|
||||
extern bool8 InBattlePyramid(void);
|
||||
extern bool8 sub_806F104(void);
|
||||
extern u8 GetTrainerEncounterMusicIdInBattlePyramind(u16 trainerOpponentId);
|
||||
extern u8 sub_81D63C8(u16 trainerOpponentId);
|
||||
extern void SummaryScreen_SetUnknownTaskId(u8);
|
||||
|
||||
|
||||
@@ -490,7 +490,7 @@ bool32 MoveRecordedBattleToSaveData(void)
|
||||
|
||||
static bool32 TryCopyRecordedBattleSaveData(struct RecordedBattleSave *dst, struct SaveSection *saveBuffer)
|
||||
{
|
||||
if (TryCopySpecialSaveSection(SECTION_ID_RECORDED_BATTLE, (void*)(saveBuffer)) != 1)
|
||||
if (TryCopySpecialSaveSection(SECTOR_ID_RECORDED_BATTLE, (void*)(saveBuffer)) != 1)
|
||||
return FALSE;
|
||||
|
||||
memcpy(dst, saveBuffer, sizeof(struct RecordedBattleSave));
|
||||
|
||||
122
src/save.c
122
src/save.c
@@ -1,15 +1,23 @@
|
||||
#include "global.h"
|
||||
#include "gba/flash_internal.h"
|
||||
#include "save.h"
|
||||
#include "constants/game_stat.h"
|
||||
#include "task.h"
|
||||
#include "decompress.h"
|
||||
#include "load_save.h"
|
||||
#include "overworld.h"
|
||||
#include "main.h"
|
||||
#include "constants/game_stat.h"
|
||||
|
||||
static u16 CalculateChecksum(void *data, u16 size);
|
||||
static u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section);
|
||||
static u8 GetSaveValidStatus(const struct SaveSectionLocation *location);
|
||||
static u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location);
|
||||
static u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location);
|
||||
static u8 TryWriteSector(u8 sector, u8 *data);
|
||||
static u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location);
|
||||
|
||||
// for the chunk declarations
|
||||
|
||||
extern bool8 gSoftResetDisabled;
|
||||
extern u32 gUnknown_0203CF5C;
|
||||
|
||||
// Divide save blocks into individual chunks to be written to flash sectors
|
||||
@@ -24,7 +32,7 @@ extern u32 gUnknown_0203CF5C;
|
||||
* Sectors 0 - 13: Save Slot 1
|
||||
* Sectors 14 - 27: Save Slot 2
|
||||
* Sectors 28 - 29: Hall of Fame
|
||||
* Sector 30: e-Reader/Mystery Gift Stuff (note: e-Reader is deprecated in Emerald US)
|
||||
* Sector 30: Trainer Hill
|
||||
* Sector 31: Recorded Battle
|
||||
*
|
||||
* There are two save slots for saving the player's game data. We alternate between
|
||||
@@ -105,7 +113,7 @@ void Save_ResetSaveCounters(void)
|
||||
gDamagedSaveSectors = 0;
|
||||
}
|
||||
|
||||
bool32 SetDamagedSectorBits(u8 op, u8 bit)
|
||||
static bool32 SetDamagedSectorBits(u8 op, u8 bit)
|
||||
{
|
||||
bool32 retVal = FALSE;
|
||||
|
||||
@@ -126,7 +134,7 @@ bool32 SetDamagedSectorBits(u8 op, u8 bit)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location)
|
||||
static u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location)
|
||||
{
|
||||
u32 retVal;
|
||||
u16 i;
|
||||
@@ -142,11 +150,11 @@ u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location)
|
||||
gLastKnownGoodSector = gLastWrittenSector; // backup the current written sector before attempting to write.
|
||||
gLastSaveCounter = gSaveCounter;
|
||||
gLastWrittenSector++;
|
||||
gLastWrittenSector = gLastWrittenSector % 0xE; // array count save sector locations
|
||||
gLastWrittenSector = gLastWrittenSector % SECTOR_SAVE_SLOT_LENGTH; // array count save sector locations
|
||||
gSaveCounter++;
|
||||
retVal = 1;
|
||||
|
||||
for (i = 0; i < 0xE; i++)
|
||||
for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++)
|
||||
HandleWriteSector(i, location);
|
||||
|
||||
if (gDamagedSaveSectors != 0) // skip the damaged sector.
|
||||
@@ -160,7 +168,7 @@ u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location)
|
||||
static u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location)
|
||||
{
|
||||
u16 i;
|
||||
u16 sector;
|
||||
@@ -168,8 +176,8 @@ u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location)
|
||||
u16 size;
|
||||
|
||||
sector = a1 + gLastWrittenSector;
|
||||
sector %= 0xE;
|
||||
sector += 0xE * (gSaveCounter % 2);
|
||||
sector %= SECTOR_SAVE_SLOT_LENGTH;
|
||||
sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2);
|
||||
|
||||
data = location[a1].data;
|
||||
size = location[a1].size;
|
||||
@@ -189,7 +197,7 @@ u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location)
|
||||
return TryWriteSector(sector, gFastSaveSection->data);
|
||||
}
|
||||
|
||||
u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size)
|
||||
static u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size)
|
||||
{
|
||||
u16 i;
|
||||
struct SaveSection *section = &gSaveDataBuffer;
|
||||
@@ -206,7 +214,7 @@ u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size)
|
||||
return TryWriteSector(sector, section->data);
|
||||
}
|
||||
|
||||
u8 TryWriteSector(u8 sector, u8 *data)
|
||||
static u8 TryWriteSector(u8 sector, u8 *data)
|
||||
{
|
||||
if (ProgramFlashSectorAndVerify(sector, data) != 0) // is damaged?
|
||||
{
|
||||
@@ -220,20 +228,20 @@ u8 TryWriteSector(u8 sector, u8 *data)
|
||||
}
|
||||
}
|
||||
|
||||
u32 RestoreSaveBackupVarsAndIncrement(const struct SaveSectionLocation *location) // location is unused
|
||||
static u32 RestoreSaveBackupVarsAndIncrement(const struct SaveSectionLocation *location) // location is unused
|
||||
{
|
||||
gFastSaveSection = &gSaveDataBuffer;
|
||||
gLastKnownGoodSector = gLastWrittenSector;
|
||||
gLastSaveCounter = gSaveCounter;
|
||||
gLastWrittenSector++;
|
||||
gLastWrittenSector = gLastWrittenSector % 0xE;
|
||||
gLastWrittenSector %= SECTOR_SAVE_SLOT_LENGTH;
|
||||
gSaveCounter++;
|
||||
gUnknown_03006208 = 0;
|
||||
gDamagedSaveSectors = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location) // only ever called once, and gSaveBlock2 is passed to this function. location is unused
|
||||
static u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location) // only ever called once, and gSaveBlock2 is passed to this function. location is unused
|
||||
{
|
||||
gFastSaveSection = &gSaveDataBuffer;
|
||||
gLastKnownGoodSector = gLastWrittenSector;
|
||||
@@ -243,7 +251,7 @@ u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location) // only ev
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location)
|
||||
static u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location)
|
||||
{
|
||||
u8 retVal;
|
||||
|
||||
@@ -267,7 +275,7 @@ u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location)
|
||||
static u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location)
|
||||
{
|
||||
u8 retVal = 1;
|
||||
|
||||
@@ -282,7 +290,7 @@ u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location)
|
||||
static u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location)
|
||||
{
|
||||
u16 i;
|
||||
u16 sector;
|
||||
@@ -291,8 +299,8 @@ u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location)
|
||||
u8 status;
|
||||
|
||||
sector = a1 + gLastWrittenSector;
|
||||
sector %= 0xE;
|
||||
sector += 0xE * (gSaveCounter % 2);
|
||||
sector %= SECTOR_SAVE_SLOT_LENGTH;
|
||||
sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2);
|
||||
|
||||
data = location[a1].data;
|
||||
size = location[a1].size;
|
||||
@@ -356,13 +364,13 @@ u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location)
|
||||
}
|
||||
}
|
||||
|
||||
u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location)
|
||||
static u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location)
|
||||
{
|
||||
u16 sector;
|
||||
|
||||
sector = a1 + gLastWrittenSector; // no sub 1?
|
||||
sector %= 0xE;
|
||||
sector += 0xE * (gSaveCounter % 2);
|
||||
sector %= SECTOR_SAVE_SLOT_LENGTH;
|
||||
sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2);
|
||||
|
||||
if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), 0x25))
|
||||
{
|
||||
@@ -379,13 +387,13 @@ u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location)
|
||||
}
|
||||
}
|
||||
|
||||
u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location)
|
||||
static u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location)
|
||||
{
|
||||
u16 sector;
|
||||
|
||||
sector = a1 + gLastWrittenSector - 1;
|
||||
sector %= 0xE;
|
||||
sector += 0xE * (gSaveCounter % 2);
|
||||
sector %= SECTOR_SAVE_SLOT_LENGTH;
|
||||
sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2);
|
||||
|
||||
if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), ((u8 *)gFastSaveSection)[sizeof(struct UnkSaveSection)]))
|
||||
{
|
||||
@@ -402,13 +410,13 @@ u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location)
|
||||
}
|
||||
}
|
||||
|
||||
u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location)
|
||||
static u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location)
|
||||
{
|
||||
u16 sector;
|
||||
|
||||
sector = a1 + gLastWrittenSector - 1; // no sub 1?
|
||||
sector %= 0xE;
|
||||
sector += 0xE * (gSaveCounter % 2);
|
||||
sector %= SECTOR_SAVE_SLOT_LENGTH;
|
||||
sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2);
|
||||
|
||||
if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), 0x25))
|
||||
{
|
||||
@@ -425,7 +433,7 @@ u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location)
|
||||
}
|
||||
}
|
||||
|
||||
u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location)
|
||||
static u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location)
|
||||
{
|
||||
u8 retVal;
|
||||
gFastSaveSection = &gSaveDataBuffer;
|
||||
@@ -442,14 +450,14 @@ u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location)
|
||||
static u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location)
|
||||
{
|
||||
u16 i;
|
||||
u16 checksum;
|
||||
u16 v3 = 0xE * (gSaveCounter % 2);
|
||||
u16 v3 = SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2);
|
||||
u16 id;
|
||||
|
||||
for (i = 0; i < 0xE; i++)
|
||||
for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++)
|
||||
{
|
||||
DoReadFlashWholeSection(i + v3, gFastSaveSection);
|
||||
id = gFastSaveSection->id;
|
||||
@@ -468,7 +476,7 @@ u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location)
|
||||
return 1;
|
||||
}
|
||||
|
||||
u8 GetSaveValidStatus(const struct SaveSectionLocation *location)
|
||||
static u8 GetSaveValidStatus(const struct SaveSectionLocation *location)
|
||||
{
|
||||
u16 i;
|
||||
u16 checksum;
|
||||
@@ -480,7 +488,7 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location)
|
||||
u8 saveSlot2Status;
|
||||
|
||||
// check save slot 1.
|
||||
for (i = 0; i < 0xE; i++)
|
||||
for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++)
|
||||
{
|
||||
DoReadFlashWholeSection(i, gFastSaveSection);
|
||||
if (gFastSaveSection->security == UNKNOWN_CHECK_VALUE)
|
||||
@@ -511,9 +519,9 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location)
|
||||
securityPassed = FALSE;
|
||||
|
||||
// check save slot 2.
|
||||
for (i = 0; i < 0xE; i++)
|
||||
for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++)
|
||||
{
|
||||
DoReadFlashWholeSection(i + 0xE, gFastSaveSection);
|
||||
DoReadFlashWholeSection(i + SECTOR_SAVE_SLOT_LENGTH, gFastSaveSection);
|
||||
if (gFastSaveSection->security == UNKNOWN_CHECK_VALUE)
|
||||
{
|
||||
securityPassed = TRUE;
|
||||
@@ -543,24 +551,16 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location)
|
||||
if ((saveSlot1Counter == -1 && saveSlot2Counter == 0) || (saveSlot1Counter == 0 && saveSlot2Counter == -1))
|
||||
{
|
||||
if ((unsigned)(saveSlot1Counter + 1) < (unsigned)(saveSlot2Counter + 1))
|
||||
{
|
||||
gSaveCounter = saveSlot2Counter;
|
||||
}
|
||||
else
|
||||
{
|
||||
gSaveCounter = saveSlot1Counter;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (saveSlot1Counter < saveSlot2Counter)
|
||||
{
|
||||
gSaveCounter = saveSlot2Counter;
|
||||
}
|
||||
else
|
||||
{
|
||||
gSaveCounter = saveSlot1Counter;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -593,7 +593,7 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location)
|
||||
return 2;
|
||||
}
|
||||
|
||||
u8 sub_81530DC(u8 a1, u8 *data, u16 size)
|
||||
static u8 sub_81530DC(u8 a1, u8 *data, u16 size)
|
||||
{
|
||||
u16 i;
|
||||
struct SaveSection *section = &gSaveDataBuffer;
|
||||
@@ -618,13 +618,13 @@ u8 sub_81530DC(u8 a1, u8 *data, u16 size)
|
||||
}
|
||||
}
|
||||
|
||||
u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section)
|
||||
static u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section)
|
||||
{
|
||||
ReadFlash(sector, 0, section->data, sizeof(struct SaveSection));
|
||||
return 1;
|
||||
}
|
||||
|
||||
u16 CalculateChecksum(void *data, u16 size)
|
||||
static u16 CalculateChecksum(void *data, u16 size)
|
||||
{
|
||||
u16 i;
|
||||
u32 checksum = 0;
|
||||
@@ -635,7 +635,7 @@ u16 CalculateChecksum(void *data, u16 size)
|
||||
return ((checksum >> 16) + checksum);
|
||||
}
|
||||
|
||||
void UpdateSaveAddresses(void)
|
||||
static void UpdateSaveAddresses(void)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
@@ -668,7 +668,7 @@ u8 HandleSavingData(u8 saveType)
|
||||
switch (saveType)
|
||||
{
|
||||
case SAVE_HALL_OF_FAME_ERASE_BEFORE: // deletes HOF before overwriting HOF completely. unused
|
||||
for (i = 0xE * 2 + 0; i < 32; i++)
|
||||
for (i = SECTOR_ID_HOF_1; i < SECTORS_COUNT; i++)
|
||||
EraseFlashSector(i);
|
||||
case SAVE_HALL_OF_FAME: // hall of fame.
|
||||
if (GetGameStat(GAME_STAT_ENTERED_HOF) < 999)
|
||||
@@ -676,8 +676,8 @@ u8 HandleSavingData(u8 saveType)
|
||||
SaveSerializedGame();
|
||||
save_write_to_flash(0xFFFF, gRamSaveSectionLocations);
|
||||
tempAddr = gDecompressionBuffer;
|
||||
HandleWriteSectorNBytes(0x1C, tempAddr, 0xF80);
|
||||
HandleWriteSectorNBytes(0x1D, tempAddr + 0xF80, 0xF80);
|
||||
HandleWriteSectorNBytes(SECTOR_ID_HOF_1, tempAddr, 0xF80);
|
||||
HandleWriteSectorNBytes(SECTOR_ID_HOF_2, tempAddr + 0xF80, 0xF80);
|
||||
break;
|
||||
case SAVE_NORMAL: // normal save. also called by overwriting your own save.
|
||||
default:
|
||||
@@ -692,7 +692,7 @@ u8 HandleSavingData(u8 saveType)
|
||||
for(i = 0; i < 5; i++)
|
||||
sav12_xor_get(i, gRamSaveSectionLocations);
|
||||
break;
|
||||
// support for Ereader was removed in Emerald.
|
||||
// Support for Ereader was removed in Emerald.
|
||||
/*
|
||||
case EREADER_SAVE: // used in mossdeep "game corner" before/after battling old man e-reader trainer
|
||||
SaveSerializedGame();
|
||||
@@ -700,7 +700,7 @@ u8 HandleSavingData(u8 saveType)
|
||||
break;
|
||||
*/
|
||||
case SAVE_OVERWRITE_DIFFERENT_FILE:
|
||||
for (i = (0xE * 2 + 0); i < 32; i++)
|
||||
for (i = SECTOR_ID_HOF_1; i < SECTORS_COUNT; i++)
|
||||
EraseFlashSector(i); // erase HOF.
|
||||
SaveSerializedGame();
|
||||
save_write_to_flash(0xFFFF, gRamSaveSectionLocations);
|
||||
@@ -710,7 +710,7 @@ u8 HandleSavingData(u8 saveType)
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 TrySavingData(u8 saveType) // TrySave
|
||||
u8 TrySavingData(u8 saveType)
|
||||
{
|
||||
if (gFlashMemoryPresent != TRUE)
|
||||
{
|
||||
@@ -744,7 +744,7 @@ bool8 sub_8153380(void) // trade.s save
|
||||
|
||||
bool8 sub_81533AC(void) // trade.s save
|
||||
{
|
||||
u8 retVal = sub_81529D4(0xE, gRamSaveSectionLocations);
|
||||
u8 retVal = sub_81529D4(SECTOR_SAVE_SLOT_LENGTH, gRamSaveSectionLocations);
|
||||
if (gDamagedSaveSectors)
|
||||
DoSaveFailedScreen(0);
|
||||
if (retVal == 0xFF)
|
||||
@@ -755,7 +755,7 @@ bool8 sub_81533AC(void) // trade.s save
|
||||
|
||||
u8 sub_81533E0(void) // trade.s save
|
||||
{
|
||||
sub_8152A34(0xE, gRamSaveSectionLocations);
|
||||
sub_8152A34(SECTOR_SAVE_SLOT_LENGTH, gRamSaveSectionLocations);
|
||||
if (gDamagedSaveSectors)
|
||||
DoSaveFailedScreen(0);
|
||||
return 0;
|
||||
@@ -763,7 +763,7 @@ u8 sub_81533E0(void) // trade.s save
|
||||
|
||||
u8 sub_8153408(void) // trade.s save
|
||||
{
|
||||
sub_8152CAC(0xE, gRamSaveSectionLocations);
|
||||
sub_8152CAC(SECTOR_SAVE_SLOT_LENGTH, gRamSaveSectionLocations);
|
||||
if (gDamagedSaveSectors)
|
||||
DoSaveFailedScreen(0);
|
||||
return 0;
|
||||
@@ -840,8 +840,8 @@ u16 sub_815355C(void)
|
||||
return 0;
|
||||
UpdateSaveAddresses();
|
||||
GetSaveValidStatus(gRamSaveSectionLocations);
|
||||
v3 = 0xE * (gSaveCounter % 2);
|
||||
for (i = 0; i < 14; i++)
|
||||
v3 = SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2);
|
||||
for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++)
|
||||
{
|
||||
DoReadFlashWholeSection(i + v3, gFastSaveSection);
|
||||
if (gFastSaveSection->id == 0)
|
||||
@@ -859,7 +859,7 @@ u32 TryCopySpecialSaveSection(u8 sector, u8* dst)
|
||||
s32 size;
|
||||
u8* savData;
|
||||
|
||||
if (sector != 30 && sector != 31)
|
||||
if (sector != SECTOR_ID_TRAINER_HILL && sector != SECTOR_ID_RECORDED_BATTLE)
|
||||
return 0xFF;
|
||||
ReadFlash(sector, 0, (u8 *)&gSaveDataBuffer, sizeof(struct SaveSection));
|
||||
if (*(u32*)(&gSaveDataBuffer.data[0]) != 0xB39D)
|
||||
|
||||
@@ -13,16 +13,17 @@
|
||||
#include "starter_choose.h"
|
||||
#include "gba/flash_internal.h"
|
||||
#include "text_window.h"
|
||||
#include "constants/rgb.h"
|
||||
|
||||
#define MSG_WIN_TOP 12
|
||||
#define CLOCK_WIN_TOP (MSG_WIN_TOP - 4)
|
||||
|
||||
extern u8 gText_SaveFailedCheckingBackup[];
|
||||
extern u8 gText_BackupMemoryDamaged[];
|
||||
extern u8 gText_CheckCompleted[];
|
||||
extern u8 gText_SaveCompleteGameCannotContinue[];
|
||||
extern u8 gText_SaveCompletePressA[];
|
||||
extern u8 gText_GamePlayCannotBeContinued[];
|
||||
extern const u8 gText_SaveFailedCheckingBackup[];
|
||||
extern const u8 gText_BackupMemoryDamaged[];
|
||||
extern const u8 gText_CheckCompleted[];
|
||||
extern const u8 gText_SaveCompleteGameCannotContinue[];
|
||||
extern const u8 gText_SaveCompletePressA[];
|
||||
extern const u8 gText_GamePlayCannotBeContinued[];
|
||||
|
||||
// gSaveFailedClockInfo enum
|
||||
enum
|
||||
@@ -155,8 +156,8 @@ static void VBlankCB_UpdateClockGraphics(void);
|
||||
static bool8 VerifySectorWipe(u16 sector);
|
||||
static bool8 WipeSectors(u32);
|
||||
|
||||
// although this is a general text printer, it's only used in this file.
|
||||
static void SaveFailedScreenTextPrint(u8 *text, u8 var1, u8 var2)
|
||||
// Although this is a general text printer, it's only used in this file.
|
||||
static void SaveFailedScreenTextPrint(const u8 *text, u8 var1, u8 var2)
|
||||
{
|
||||
u8 color[3];
|
||||
|
||||
@@ -187,72 +188,70 @@ static void CB2_SaveFailedScreen(void)
|
||||
{
|
||||
switch (gMain.state)
|
||||
{
|
||||
case 0:
|
||||
default:
|
||||
SetVBlankCallback(NULL);
|
||||
SetGpuReg(REG_OFFSET_DISPCNT, 0);
|
||||
SetGpuReg(REG_OFFSET_BG3CNT, 0);
|
||||
SetGpuReg(REG_OFFSET_BG2CNT, 0);
|
||||
SetGpuReg(REG_OFFSET_BG1CNT, 0);
|
||||
SetGpuReg(REG_OFFSET_BG0CNT, 0);
|
||||
SetGpuReg(REG_OFFSET_BG3HOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG3VOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG2HOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG2VOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG1HOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG1VOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG0HOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG0VOFS, 0);
|
||||
// how come this doesnt use the Dma manager?
|
||||
DmaFill16(3, 0, VRAM, VRAM_SIZE);
|
||||
DmaFill32(3, 0, OAM, OAM_SIZE);
|
||||
DmaFill16(3, 0, PLTT, PLTT_SIZE);
|
||||
LZ77UnCompVram(gBirchHelpGfx, (void *)VRAM);
|
||||
LZ77UnCompVram(gBirchBagTilemap, (void *)(VRAM + 0x7000));
|
||||
LZ77UnCompVram(gBirchGrassTilemap, (void *)(VRAM + 0x7800));
|
||||
LZ77UnCompVram(sSaveFailedClockGfx, (void *)(VRAM + 0x10020));
|
||||
ResetBgsAndClearDma3BusyFlags(0);
|
||||
InitBgsFromTemplates(0, gUnknown_085EFD88, 3);
|
||||
SetBgTilemapBuffer(0, (void *)&gDecompressionBuffer[0x2000]);
|
||||
CpuFill32(0, &gDecompressionBuffer[0x2000], 0x800);
|
||||
LoadBgTiles(0, gTextWindowFrame1_Gfx, 0x120, 0x214);
|
||||
InitWindows(gUnknown_085EFD94);
|
||||
// AddWindowWithoutTileMap returns a u16/integer, but the info is clobbered into a u8 here resulting in lost info. Bug?
|
||||
gSaveFailedWindowIds[TEXT_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFD9C);
|
||||
SetWindowAttribute(gSaveFailedWindowIds[TEXT_WIN_ID], 7, (u32)&gDecompressionBuffer[0x2800]);
|
||||
gSaveFailedWindowIds[CLOCK_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFDA4);
|
||||
SetWindowAttribute(gSaveFailedWindowIds[CLOCK_WIN_ID], 7, (u32)&gDecompressionBuffer[0x3D00]);
|
||||
DeactivateAllTextPrinters();
|
||||
ResetSpriteData();
|
||||
ResetTasks();
|
||||
ResetPaletteFade();
|
||||
LoadPalette(gBirchBagGrassPal, 0, 0x40);
|
||||
LoadPalette(sSaveFailedClockPal, 0x100, 0x20);
|
||||
LoadPalette(gTextWindowFrame1_Pal, 0xE0, 0x20);
|
||||
LoadPalette(gUnknown_0860F074, 0xF0, 0x20);
|
||||
SetWindowBorderStyle(gSaveFailedWindowIds[TEXT_WIN_ID], FALSE, 0x214, 0xE);
|
||||
SetWindowBorderStyle(gSaveFailedWindowIds[CLOCK_WIN_ID], FALSE, 0x214, 0xE);
|
||||
FillWindowPixelBuffer(gSaveFailedWindowIds[CLOCK_WIN_ID], 0x11); // backwards?
|
||||
FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11);
|
||||
CopyWindowToVram(gSaveFailedWindowIds[CLOCK_WIN_ID], 2); // again?
|
||||
CopyWindowToVram(gSaveFailedWindowIds[TEXT_WIN_ID], 1);
|
||||
SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0);
|
||||
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0);
|
||||
EnableInterrupts(1);
|
||||
SetVBlankCallback(VBlankCB);
|
||||
SetGpuReg(0, 0x1040);
|
||||
ShowBg(0);
|
||||
ShowBg(2);
|
||||
ShowBg(3);
|
||||
gMain.state++;
|
||||
break;
|
||||
case 1:
|
||||
if (!UpdatePaletteFade())
|
||||
{
|
||||
SetMainCallback2(CB2_WipeSave);
|
||||
SetVBlankCallback(VBlankCB_UpdateClockGraphics);
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
SetVBlankCallback(NULL);
|
||||
SetGpuReg(REG_OFFSET_DISPCNT, 0);
|
||||
SetGpuReg(REG_OFFSET_BG3CNT, 0);
|
||||
SetGpuReg(REG_OFFSET_BG2CNT, 0);
|
||||
SetGpuReg(REG_OFFSET_BG1CNT, 0);
|
||||
SetGpuReg(REG_OFFSET_BG0CNT, 0);
|
||||
SetGpuReg(REG_OFFSET_BG3HOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG3VOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG2HOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG2VOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG1HOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG1VOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG0HOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG0VOFS, 0);
|
||||
DmaFill16(3, 0, VRAM, VRAM_SIZE);
|
||||
DmaFill32(3, 0, OAM, OAM_SIZE);
|
||||
DmaFill16(3, 0, PLTT, PLTT_SIZE);
|
||||
LZ77UnCompVram(gBirchHelpGfx, (void *)VRAM);
|
||||
LZ77UnCompVram(gBirchBagTilemap, (void *)(VRAM + 0x7000));
|
||||
LZ77UnCompVram(gBirchGrassTilemap, (void *)(VRAM + 0x7800));
|
||||
LZ77UnCompVram(sSaveFailedClockGfx, (void *)(VRAM + 0x10020));
|
||||
ResetBgsAndClearDma3BusyFlags(0);
|
||||
InitBgsFromTemplates(0, gUnknown_085EFD88, 3);
|
||||
SetBgTilemapBuffer(0, (void *)&gDecompressionBuffer[0x2000]);
|
||||
CpuFill32(0, &gDecompressionBuffer[0x2000], 0x800);
|
||||
LoadBgTiles(0, gTextWindowFrame1_Gfx, 0x120, 0x214);
|
||||
InitWindows(gUnknown_085EFD94);
|
||||
gSaveFailedWindowIds[TEXT_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFD9C);
|
||||
SetWindowAttribute(gSaveFailedWindowIds[TEXT_WIN_ID], 7, (u32)&gDecompressionBuffer[0x2800]);
|
||||
gSaveFailedWindowIds[CLOCK_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFDA4);
|
||||
SetWindowAttribute(gSaveFailedWindowIds[CLOCK_WIN_ID], 7, (u32)&gDecompressionBuffer[0x3D00]);
|
||||
DeactivateAllTextPrinters();
|
||||
ResetSpriteData();
|
||||
ResetTasks();
|
||||
ResetPaletteFade();
|
||||
LoadPalette(gBirchBagGrassPal, 0, 0x40);
|
||||
LoadPalette(sSaveFailedClockPal, 0x100, 0x20);
|
||||
LoadPalette(gTextWindowFrame1_Pal, 0xE0, 0x20);
|
||||
LoadPalette(gUnknown_0860F074, 0xF0, 0x20);
|
||||
SetWindowBorderStyle(gSaveFailedWindowIds[TEXT_WIN_ID], FALSE, 0x214, 0xE);
|
||||
SetWindowBorderStyle(gSaveFailedWindowIds[CLOCK_WIN_ID], FALSE, 0x214, 0xE);
|
||||
FillWindowPixelBuffer(gSaveFailedWindowIds[CLOCK_WIN_ID], 0x11); // backwards?
|
||||
FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11);
|
||||
CopyWindowToVram(gSaveFailedWindowIds[CLOCK_WIN_ID], 2); // again?
|
||||
CopyWindowToVram(gSaveFailedWindowIds[TEXT_WIN_ID], 1);
|
||||
SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0);
|
||||
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK);
|
||||
EnableInterrupts(1);
|
||||
SetVBlankCallback(VBlankCB);
|
||||
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
|
||||
ShowBg(0);
|
||||
ShowBg(2);
|
||||
ShowBg(3);
|
||||
gMain.state++;
|
||||
break;
|
||||
case 1:
|
||||
if (!UpdatePaletteFade())
|
||||
{
|
||||
SetMainCallback2(CB2_WipeSave);
|
||||
SetVBlankCallback(VBlankCB_UpdateClockGraphics);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,7 +345,7 @@ static void CB2_ReturnToTitleScreen(void)
|
||||
|
||||
static void VBlankCB_UpdateClockGraphics(void)
|
||||
{
|
||||
unsigned int n = (gMain.vblankCounter2 >> 3) & 7;
|
||||
u32 n = (gMain.vblankCounter2 >> 3) & 7;
|
||||
|
||||
gMain.oamBuffer[0] = sClockOamData;
|
||||
gMain.oamBuffer[0].x = 112;
|
||||
|
||||
@@ -9,21 +9,18 @@
|
||||
|
||||
static bool32 IsCurMapInLocationList(const u16 *list)
|
||||
{
|
||||
s32 i;
|
||||
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)
|
||||
for (i = 0; list[i] != 0xFFFF; i++)
|
||||
{
|
||||
u16 termValue = 0xFFFF;
|
||||
const u16 *localList;
|
||||
for (localList = list; *localList != termValue; localList++)
|
||||
if (*localList == locSum)
|
||||
return TRUE;
|
||||
if (list[i] == locSum)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// TODO: Not require a packed u16 array for these lists
|
||||
static const u16 sSaveLocationPokeCenterList[] =
|
||||
{
|
||||
MAP_OLDALE_TOWN_POKEMON_CENTER_1F,
|
||||
@@ -72,7 +69,7 @@ static bool32 IsCurMapPokeCenter(void)
|
||||
return IsCurMapInLocationList(sSaveLocationPokeCenterList);
|
||||
}
|
||||
|
||||
static const u16 sSaveLocationReloadLocList[] = // there's only 1 location, and it's presumed its for the save reload feature for battle tower
|
||||
static const u16 sSaveLocationReloadLocList[] = // There's only 1 location, and it's presumed its for the save reload feature for battle tower.
|
||||
{
|
||||
MAP_BATTLE_FRONTIER_BATTLE_TOWER_LOBBY,
|
||||
0xFFFF,
|
||||
@@ -83,13 +80,13 @@ static bool32 IsCurMapReloadLocation(void)
|
||||
return IsCurMapInLocationList(sSaveLocationReloadLocList);
|
||||
}
|
||||
|
||||
// nulled out list. unknown what this would have been
|
||||
// Nulled out list. Unknown what this would have been.
|
||||
static const u16 sUnknown_0861440E[] =
|
||||
{
|
||||
0xFFFF,
|
||||
};
|
||||
|
||||
bool32 sub_81AFCEC(void)
|
||||
static bool32 sub_81AFCEC(void)
|
||||
{
|
||||
return IsCurMapInLocationList(sUnknown_0861440E);
|
||||
}
|
||||
|
||||
@@ -460,18 +460,18 @@ static bool32 InitStartMenuStep(void)
|
||||
sUnknown_02037619[0]++;
|
||||
break;
|
||||
case 3:
|
||||
if (GetSafariZoneFlag() != FALSE)
|
||||
if (GetSafariZoneFlag())
|
||||
{
|
||||
ShowSafariBallsWindow();
|
||||
}
|
||||
if (InBattlePyramid() != FALSE)
|
||||
if (InBattlePyramid())
|
||||
{
|
||||
ShowPyramidFloorWindow();
|
||||
}
|
||||
sUnknown_02037619[0]++;
|
||||
break;
|
||||
case 4:
|
||||
if (PrintStartMenuActions(&sUnknown_02037619[1], 2) == FALSE)
|
||||
if (!PrintStartMenuActions(&sUnknown_02037619[1], 2))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -12,11 +12,10 @@
|
||||
#include "task.h"
|
||||
#include "trainer_see.h"
|
||||
#include "util.h"
|
||||
#include "battle_pyramid.h"
|
||||
#include "constants/field_effects.h"
|
||||
|
||||
extern bool8 InBattlePyramid(void);
|
||||
extern bool32 InTrainerHill(void);
|
||||
extern bool8 GetBattlePyramidTrainerFlag(u8 eventObjectId);
|
||||
extern bool8 GetTrainerHillTrainerFlag(u8 eventObjectId);
|
||||
extern void sub_809BE48(u16 npcId);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "link.h"
|
||||
#include "script.h"
|
||||
#include "battle_pike.h"
|
||||
#include "battle_pyramid.h"
|
||||
#include "constants/items.h"
|
||||
#include "constants/maps.h"
|
||||
|
||||
@@ -26,9 +27,6 @@ extern const u8 EventScript_RepelWoreOff[];
|
||||
|
||||
#define NUM_FEEBAS_SPOTS 6
|
||||
|
||||
extern void GenerateBattlePyramidWildMon(void);
|
||||
extern bool8 InBattlePyramid(void);
|
||||
|
||||
// this file's functions
|
||||
static u16 FeebasRandom(void);
|
||||
static void FeebasSeedRng(u16 seed);
|
||||
|
||||
Reference in New Issue
Block a user