summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDizzyEggg <jajkodizzy@wp.pl>2018-10-30 21:45:26 +0100
committerDizzyEggg <jajkodizzy@wp.pl>2018-10-30 21:45:26 +0100
commit0da7d7e6ae7cb50ca0b52d1ea27d98e3f02e50d2 (patch)
tree37d43bf1997928a956055e6c3225a0de68d25d52 /src
parent3a9eeef84447c222a4638546d014e12b0098fe51 (diff)
why is this function so hard to match
Diffstat (limited to 'src')
-rw-r--r--src/battle_tower.c2
-rw-r--r--src/frontier_util.c174
-rw-r--r--src/new_game.c4
-rw-r--r--src/save.c36
4 files changed, 197 insertions, 19 deletions
diff --git a/src/battle_tower.c b/src/battle_tower.c
index 0f6e18169..4518e6ad9 100644
--- a/src/battle_tower.c
+++ b/src/battle_tower.c
@@ -10,7 +10,7 @@
#include "international_string_util.h"
#include "battle.h"
#include "battle_frontier_1.h"
-#include "battle_frontier_2.h"
+#include "frontier_util.h"
#include "recorded_battle.h"
#include "easy_chat.h"
#include "gym_leader_rematch.h"
diff --git a/src/frontier_util.c b/src/frontier_util.c
index bb349f6db..99419cc9a 100644
--- a/src/frontier_util.c
+++ b/src/frontier_util.c
@@ -25,6 +25,9 @@
#include "record_mixing.h"
#include "strings.h"
#include "malloc.h"
+#include "save.h"
+#include "load_save.h"
+#include "battle_dome.h"
#include "constants/battle_frontier.h"
#include "constants/trainers.h"
#include "constants/species.h"
@@ -1656,3 +1659,174 @@ void ScrollRankingHallRecordsWindow(void)
PrintHallRecords(gSpecialVar_0x8005, FRONTIER_LVL_OPEN);
CopyWindowToVram(gRecordsWindowId, 2);
}
+
+void ClearnRankingHallRecords(void)
+{
+ s32 i, j, k;
+
+ for (i = 0; i < HALL_FACILITIES_COUNT; i++)
+ {
+ for (j = 0; j < 2; j++)
+ {
+ for (k = 0; k < 3; k++)
+ {
+ CopyUnalignedWord(gSaveBlock2Ptr->hallRecords1P[i][j][k].id, 0); // BUG: Passing 0 as a pointer instead of a pointer holding a value of 0.
+ gSaveBlock2Ptr->hallRecords1P[i][j][k].name[0] = EOS;
+ gSaveBlock2Ptr->hallRecords1P[i][j][k].winStreak = 0;
+ }
+ }
+ }
+
+ for (j = 0; j < 2; j++)
+ {
+ for (k = 0; k < 3; k++)
+ {
+ CopyUnalignedWord(gSaveBlock2Ptr->hallRecords2P[j][k].id1, 0); // BUG: Passing 0 as a pointer instead of a pointer holding a value of 0.
+ CopyUnalignedWord(gSaveBlock2Ptr->hallRecords2P[j][k].id2, 0); // BUG: Passing 0 as a pointer instead of a pointer holding a value of 0.
+ gSaveBlock2Ptr->hallRecords2P[j][k].name1[0] = EOS;
+ gSaveBlock2Ptr->hallRecords2P[j][k].name2[0] = EOS;
+ gSaveBlock2Ptr->hallRecords2P[j][k].winStreak = 0;
+ }
+ }
+}
+
+void sub_81A4C30(void)
+{
+ s32 i;
+ struct Pokemon *monsParty = calloc(PARTY_SIZE, sizeof(struct Pokemon));
+
+ for (i = 0; i < PARTY_SIZE; i++)
+ monsParty[i] = gPlayerParty[i];
+
+ i = gPlayerPartyCount;
+ LoadPlayerParty();
+ sub_8076D5C();
+ TrySavingData(SAVE_LINK);
+ sav2_gender2_inplace_and_xFE();
+ gPlayerPartyCount = i;
+
+ for (i = 0; i < PARTY_SIZE; i++)
+ gPlayerParty[i] = monsParty[i];
+
+ free(monsParty);
+}
+
+extern const u16 gFacilityToBrainTrainerId[];
+extern const u8 gUnknown_08611C8C[][2];
+
+u8 GetFrontierBrainTrainerPicIndex(void)
+{
+ s32 facility;
+
+ if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
+ facility = GetRecordedBattleFrontierFacility();
+ else
+ facility = VarGet(VAR_FRONTIER_FACILITY);
+
+ return gTrainers[gFacilityToBrainTrainerId[facility]].trainerPic;
+}
+
+u8 GetFrontierBrainTrainerClass(void)
+{
+ s32 facility;
+
+ if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
+ facility = GetRecordedBattleFrontierFacility();
+ else
+ facility = VarGet(VAR_FRONTIER_FACILITY);
+
+ return gTrainers[gFacilityToBrainTrainerId[facility]].trainerClass;
+}
+
+void CopyFrontierBrainTrainerName(u8 *dst)
+{
+ s32 i;
+ s32 facility;
+
+ if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
+ facility = GetRecordedBattleFrontierFacility();
+ else
+ facility = VarGet(VAR_FRONTIER_FACILITY);
+
+ for (i = 0; i < PLAYER_NAME_LENGTH; i++)
+ dst[i] = gTrainers[gFacilityToBrainTrainerId[facility]].trainerName[i];
+
+ dst[i] = EOS;
+}
+
+bool8 IsFrontierBrainFemale(void)
+{
+ s32 facility = VarGet(VAR_FRONTIER_FACILITY);
+ return gUnknown_08611C8C[facility][1];
+}
+
+void SetFrontierBrainTrainerGfxId(void)
+{
+ s32 facility = VarGet(VAR_FRONTIER_FACILITY);
+ VarSet(VAR_OBJ_GFX_ID_0, gUnknown_08611C8C[facility][0]);
+}
+
+s32 sub_81A513C(void);
+
+#define FRONTIER_BRAIN_OTID 61226
+
+struct FrontierBrainMon
+{
+ u16 species;
+ u16 heldItem;
+ u8 fixedIV;
+ u8 nature;
+ u8 evs[6];
+ u16 moves[4];
+};
+
+extern const struct FrontierBrainMon sFrontierBrainsMons[][2][3];
+
+void CreateFrontierBrainPokemon(void)
+{
+ s32 i, j;
+ s32 monCountInBits;
+ s32 monPartyId;
+ s32 monLevel;
+ u8 friendship;
+ s32 facility = VarGet(VAR_FRONTIER_FACILITY);
+ s32 symbol = sub_81A513C();
+
+ if (facility == FRONTIER_FACILITY_DOME)
+ monCountInBits = GetTrainerMonCountInBits(TrainerIdToDomeTournamentId(TRAINER_FRONTIER_BRAIN));
+ else
+ monCountInBits = 7;
+
+ ZeroEnemyPartyMons();
+ monPartyId = 0;
+ monLevel = SetFacilityPtrsGetLevel();
+ for (i = 0; i < 3; monCountInBits >>= 1, i++)
+ {
+ if (!(monCountInBits & 1))
+ continue;
+
+ do
+ {
+ j = Random32();
+ } while (IsShinyOtIdPersonality(FRONTIER_BRAIN_OTID, j) || sFrontierBrainsMons[facility][symbol][i].nature != GetNatureFromPersonality(j));
+ CreateMon(&gEnemyParty[monPartyId],
+ sFrontierBrainsMons[facility][symbol][i].species,
+ monLevel,
+ sFrontierBrainsMons[facility][symbol][i].fixedIV,
+ TRUE, j,
+ TRUE, FRONTIER_BRAIN_OTID);
+ SetMonData(&gEnemyParty[monPartyId], MON_DATA_HELD_ITEM, &sFrontierBrainsMons[facility][symbol][i].heldItem);
+ for (j = 0; j < 6; j++)
+ SetMonData(&gEnemyParty[monPartyId], MON_DATA_HP_EV + j, &sFrontierBrainsMons[facility][symbol][i].evs[j]);
+ friendship = 0xFF;
+ for (j = 0; j < 4; j++)
+ {
+ SetMonMoveSlot(&gEnemyParty[monPartyId], sFrontierBrainsMons[facility][symbol][i].moves[j], j);
+ if (sFrontierBrainsMons[facility][symbol][i].moves[j] == MOVE_FRUSTRATION)
+ friendship = 0;
+ }
+ SetMonData(&gEnemyParty[monPartyId], MON_DATA_FRIENDSHIP, &friendship);
+ CalculateMonStats(&gEnemyParty[monPartyId]);
+ monPartyId++;
+ }
+}
diff --git a/src/new_game.c b/src/new_game.c
index 127e48c35..e6bafa7a7 100644
--- a/src/new_game.c
+++ b/src/new_game.c
@@ -26,6 +26,7 @@
#include "item.h"
#include "pokedex.h"
#include "apprentice.h"
+#include "frontier_util.h"
extern u8 gDifferentSaveFile;
extern u16 gSaveFileStatus;
@@ -45,7 +46,6 @@ extern void NewGameInitPCItems(void);
extern void ClearDecorationInventories(void);
extern void ResetFanClub(void);
extern void copy_strings_to_sav1(void);
-extern void sub_81A4B14(void);
extern void sub_8195E10(void);
extern void sub_801AFD8(void);
extern void sub_800E5AC(void);
@@ -204,7 +204,7 @@ void NewGameInitData(void)
copy_strings_to_sav1();
SetLilycoveLady();
ResetAllApprenticeData();
- sub_81A4B14();
+ ClearnRankingHallRecords();
sub_8195E10();
sub_801AFD8();
sub_800E5AC();
diff --git a/src/save.c b/src/save.c
index 68427c4c3..0bd48cca9 100644
--- a/src/save.c
+++ b/src/save.c
@@ -712,30 +712,34 @@ u8 HandleSavingData(u8 saveType)
u8 TrySavingData(u8 saveType) // TrySave
{
- if(gFlashMemoryPresent == TRUE)
+ if (gFlashMemoryPresent != TRUE)
{
- HandleSavingData(saveType);
- if(gDamagedSaveSectors)
- DoSaveFailedScreen(saveType);
- else
- goto OK; // really?
+ gUnknown_03006294 = 0xFF;
+ return 0xFF;
}
- gUnknown_03006294 = 0xFF;
- return 0xFF;
-OK:
- gUnknown_03006294 = 1;
- return 1;
+ HandleSavingData(saveType);
+ if (!gDamagedSaveSectors)
+ {
+ gUnknown_03006294 = 1;
+ return 1;
+ }
+ else
+ {
+ DoSaveFailedScreen(saveType);
+ gUnknown_03006294 = 0xFF;
+ return 0xFF;
+ }
}
-u8 sub_8153380(void) // trade.s save
+bool8 sub_8153380(void) // trade.s save
{
if (gFlashMemoryPresent != TRUE)
- return 1;
+ return TRUE;
UpdateSaveAddresses();
SaveSerializedGame();
RestoreSaveBackupVarsAndIncrement(gRamSaveSectionLocations);
- return 0;
+ return FALSE;
}
bool8 sub_81533AC(void) // trade.s save
@@ -744,9 +748,9 @@ bool8 sub_81533AC(void) // trade.s save
if (gDamagedSaveSectors)
DoSaveFailedScreen(0);
if (retVal == 0xFF)
- return 1;
+ return TRUE;
else
- return 0;
+ return FALSE;
}
u8 sub_81533E0(void) // trade.s save