summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorultima-soul <akshayjhanji@hotmail.com>2019-10-06 00:48:48 -0700
committerultima-soul <akshayjhanji@hotmail.com>2019-10-06 00:48:48 -0700
commitd84e9bed58db84bbb7db568c366bfa803be87139 (patch)
tree13a924bbf40b3a0ab38d915ef6349f8a4bd60c15 /src
parentb4b509f68477068ae111cc5a6094d858d396c4bb (diff)
Decompile/port new_game
Diffstat (limited to 'src')
-rw-r--r--src/berry_powder.c10
-rw-r--r--src/mevent.c2
-rw-r--r--src/new_game.c168
-rw-r--r--src/scrcmd.c14
-rw-r--r--src/seagallop.c2
5 files changed, 182 insertions, 14 deletions
diff --git a/src/berry_powder.c b/src/berry_powder.c
index 9b3bbc17f..ad824b24b 100644
--- a/src/berry_powder.c
+++ b/src/berry_powder.c
@@ -16,7 +16,7 @@ u32 sub_815EE3C(u32 * a0)
return *a0 ^ gSaveBlock2Ptr->encryptionKey;
}
-void sub_815EE54(u32 * a0, u32 a1)
+void SetBerryPowder(u32 * a0, u32 a1)
{
*a0 = gSaveBlock2Ptr->encryptionKey ^ a1;
}
@@ -48,12 +48,12 @@ bool8 sub_815EEE0(u32 a0)
u32 amount = sub_815EE3C(ptr) + a0;
if (amount > 99999)
{
- sub_815EE54(ptr, 99999);
+ SetBerryPowder(ptr, 99999);
return FALSE;
}
else
{
- sub_815EE54(ptr, amount);
+ SetBerryPowder(ptr, amount);
return TRUE;
}
}
@@ -66,7 +66,7 @@ bool8 sub_815EF20(u32 a0)
else
{
u32 amount = sub_815EE3C(ptr);
- sub_815EE54(ptr, amount - a0);
+ SetBerryPowder(ptr, amount - a0);
return TRUE;
}
}
@@ -79,7 +79,7 @@ bool8 sub_815EF5C(void)
else
{
u32 amount = sub_815EE3C(ptr);
- sub_815EE54(ptr, amount - gSpecialVar_0x8004);
+ SetBerryPowder(ptr, amount - gSpecialVar_0x8004);
return TRUE;
}
}
diff --git a/src/mevent.c b/src/mevent.c
index d0d7f59aa..b03f1ffe9 100644
--- a/src/mevent.c
+++ b/src/mevent.c
@@ -769,7 +769,7 @@ void sub_81442CC(struct MEventStruct_Unk1442CC * data)
data->unk_14 = 0;
for (i = 0; i < 4; i++)
data->unk_16[i] = gSaveBlock1Ptr->unk_3120.unk_338[i];
- CopyUnalignedWord(data->unk_4C, gSaveBlock2Ptr->playerTrainerId);
+ CopyTrainerId(data->unk_4C, gSaveBlock2Ptr->playerTrainerId);
StringCopy(data->unk_45, gSaveBlock2Ptr->playerName);
for (i = 0; i < 6; i++)
data->unk_50[i] = gSaveBlock1Ptr->unk2CA0[i];
diff --git a/src/new_game.c b/src/new_game.c
new file mode 100644
index 000000000..d3463f80b
--- /dev/null
+++ b/src/new_game.c
@@ -0,0 +1,168 @@
+#include "global.h"
+#include "new_game.h"
+#include "random.h"
+#include "main.h"
+#include "overworld.h"
+#include "constants/maps.h"
+#include "load_save.h"
+#include "item_menu.h"
+#include "tm_case.h"
+#include "berry_pouch.h"
+#include "quest_log.h"
+#include "wild_encounter.h"
+#include "event_data.h"
+#include "string_util.h"
+#include "mail_data.h"
+#include "play_time.h"
+#include "money.h"
+#include "battle_records.h"
+#include "pokemon_size_record.h"
+#include "pokemon_storage_system.h"
+#include "roamer.h"
+#include "item.h"
+#include "player_pc.h"
+#include "berry.h"
+#include "easy_chat.h"
+#include "union_room_chat.h"
+#include "mevent.h"
+#include "trainer_tower.h"
+#include "script.h"
+#include "berry_powder.h"
+#include "pokemon_jump.h"
+
+extern const u8 EventScript_ResetAllMapFlags[];
+
+// this file's functions
+void ResetMiniGamesResults(void);
+
+// EWRAM vars
+EWRAM_DATA bool8 gDifferentSaveFile = FALSE;
+
+void SetTrainerId(u32 trainerId, u8 *dst)
+{
+ dst[0] = trainerId;
+ dst[1] = trainerId >> 8;
+ dst[2] = trainerId >> 16;
+ dst[3] = trainerId >> 24;
+}
+
+void CopyTrainerId(u8 *dst, u8 *src)
+{
+ s32 i;
+ for (i = 0; i < 4; i++)
+ dst[i] = src[i];
+}
+
+/*static*/ void InitPlayerTrainerId(void)
+{
+ u32 trainerId = (Random() << 0x10) | GetGeneratedTrainerIdLower();
+ SetTrainerId(trainerId, gSaveBlock2Ptr->playerTrainerId);
+}
+
+/*static*/ void SetDefaultOptions(void)
+{
+ gSaveBlock2Ptr->optionsTextSpeed = OPTIONS_TEXT_SPEED_MID;
+ gSaveBlock2Ptr->optionsWindowFrameType = 0;
+ gSaveBlock2Ptr->optionsSound = OPTIONS_SOUND_MONO;
+ gSaveBlock2Ptr->optionsBattleStyle = OPTIONS_BATTLE_STYLE_SHIFT;
+ gSaveBlock2Ptr->optionsBattleSceneOff = FALSE;
+ gSaveBlock2Ptr->regionMapZoom = FALSE;
+ gSaveBlock2Ptr->optionsButtonMode = OPTIONS_BUTTON_MODE_NORMAL;
+}
+
+/*static*/ void ClearPokedexFlags(void)
+{
+ memset(&gSaveBlock2Ptr->pokedex.owned, 0, sizeof(gSaveBlock2Ptr->pokedex.owned));
+ memset(&gSaveBlock2Ptr->pokedex.seen, 0, sizeof(gSaveBlock2Ptr->pokedex.seen));
+}
+
+/*static*/ void sub_80549D4(void)
+{
+ CpuFill32(0, &gSaveBlock2Ptr->field_B0, (u32) &gSaveBlock2Ptr->mapView - (u32) &gSaveBlock2Ptr->field_B0);
+}
+
+/*static*/ void WarpToPlayersRoom(void)
+{
+ SetWarpDestination(MAP_GROUP(PALLET_TOWN_PLAYERS_HOUSE_2F), MAP_NUM(PALLET_TOWN_PLAYERS_HOUSE_2F), -1, 6, 6);
+ WarpIntoMap();
+}
+
+void Sav2_ClearSetDefault(void)
+{
+ ClearSav2();
+ SetDefaultOptions();
+}
+
+void ResetMenuAndMonGlobals(void)
+{
+ gDifferentSaveFile = 0;
+ ZeroPlayerPartyMons();
+ ZeroEnemyPartyMons();
+ sub_81089BC();
+ ResetTMCaseCursorPos();
+ BerryPouch_CursorResetToTop();
+ sub_811089C();
+ sub_8083214(Random());
+ sub_806E6FC();
+}
+
+void NewGameInitData(void)
+{
+ u8 rivalName[PLAYER_NAME_LENGTH];
+ StringCopy(rivalName, gSaveBlock1Ptr->rivalName);
+ gDifferentSaveFile = 1;
+ gSaveBlock2Ptr->encryptionKey = 0;
+ ZeroPlayerPartyMons();
+ ZeroEnemyPartyMons();
+ sub_80549D4();
+ ClearSav1();
+ ClearMailData();
+ gSaveBlock2Ptr->specialSaveWarpFlags = 0;
+ gSaveBlock2Ptr->field_A8 = 0;
+ gSaveBlock2Ptr->field_AC = 1;
+ gSaveBlock2Ptr->field_AD = 0;
+ InitPlayerTrainerId();
+ PlayTimeCounter_Reset();
+ ClearPokedexFlags();
+ sub_806E0D0();
+ ResetFameChecker();
+ SetMoney(&gSaveBlock1Ptr->money, 3000);
+ sub_8054E68();
+ InitLinkBattleRecords();
+ sub_80A0904();
+ sub_80A0958();
+ sub_806E190();
+ gPlayerPartyCount = 0;
+ ZeroPlayerPartyMons();
+ sub_808C7E0();
+ ClearRoamerData();
+ gSaveBlock1Ptr->registeredItem = 0;
+ ClearItemSlotsInAllBagPockets();
+ sub_80EB658();
+ sub_809C794();
+ sub_80BDD34();
+ sub_8113044();
+ copy_strings_to_sav1();
+ ResetMiniGamesResults();
+ sub_8143D24();
+ sub_815D838();
+ WarpToPlayersRoom();
+ ScriptContext2_RunNewScript(EventScript_ResetAllMapFlags);
+ StringCopy(gSaveBlock1Ptr->rivalName, rivalName);
+ sub_815EE0C();
+}
+
+/*static*/ void ResetMiniGamesResults(void)
+{
+ CpuFill16(0, &gSaveBlock2Ptr->berryCrush, sizeof(struct BerryCrush));
+ SetBerryPowder(&gSaveBlock2Ptr->berryCrush.berryPowderAmount, 0);
+ ResetPokeJumpResults();
+ CpuFill16(0, &gSaveBlock2Ptr->berryPick, sizeof(struct BerryPickingResults));
+}
+
+
+
+
+
+
+ \ No newline at end of file
diff --git a/src/scrcmd.c b/src/scrcmd.c
index bcf8c231d..85059691f 100644
--- a/src/scrcmd.c
+++ b/src/scrcmd.c
@@ -733,7 +733,7 @@ bool8 ScrCmd_warp(struct ScriptContext *ctx)
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
- Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y);
+ SetWarpDestination(mapGroup, mapNum, warpId, x, y);
DoWarp();
ResetInitialPlayerAvatarState();
return TRUE;
@@ -747,7 +747,7 @@ bool8 ScrCmd_warpsilent(struct ScriptContext *ctx)
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
- Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y);
+ SetWarpDestination(mapGroup, mapNum, warpId, x, y);
DoDiveWarp();
ResetInitialPlayerAvatarState();
return TRUE;
@@ -761,7 +761,7 @@ bool8 ScrCmd_warpdoor(struct ScriptContext *ctx)
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
- Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y);
+ SetWarpDestination(mapGroup, mapNum, warpId, x, y);
DoDoorWarp();
ResetInitialPlayerAvatarState();
return TRUE;
@@ -778,7 +778,7 @@ bool8 ScrCmd_warphole(struct ScriptContext *ctx)
if (mapGroup == 0xFF && mapNum == 0xFF)
SetWarpDestinationToFixedHoleWarp(x - 7, y - 7);
else
- Overworld_SetWarpDestination(mapGroup, mapNum, -1, x - 7, y - 7);
+ SetWarpDestination(mapGroup, mapNum, -1, x - 7, y - 7);
DoFallWarp();
ResetInitialPlayerAvatarState();
return TRUE;
@@ -792,7 +792,7 @@ bool8 ScrCmd_warpteleport(struct ScriptContext *ctx)
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
- Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y);
+ SetWarpDestination(mapGroup, mapNum, warpId, x, y);
sub_807E59C();
ResetInitialPlayerAvatarState();
return TRUE;
@@ -806,7 +806,7 @@ bool8 ScrCmd_warpteleport2(struct ScriptContext *ctx)
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
- Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y);
+ SetWarpDestination(mapGroup, mapNum, warpId, x, y);
sub_805DAE4(GetPlayerFacingDirection());
sub_807E500();
ResetInitialPlayerAvatarState();
@@ -821,7 +821,7 @@ bool8 ScrCmd_setwarp(struct ScriptContext *ctx)
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
- Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y);
+ SetWarpDestination(mapGroup, mapNum, warpId, x, y);
return FALSE;
}
diff --git a/src/seagallop.c b/src/seagallop.c
index e3333ef32..5374f7bac 100644
--- a/src/seagallop.c
+++ b/src/seagallop.c
@@ -319,7 +319,7 @@ static void Task_SeaGallop_3(void)
gSpecialVar_0x8006 = 0;
warpInfo = sSeaGallopSpawnTable[gSpecialVar_0x8006];
- Overworld_SetWarpDestination(warpInfo[0], warpInfo[1], -1, warpInfo[2], warpInfo[3]);
+ SetWarpDestination(warpInfo[0], warpInfo[1], -1, warpInfo[2], warpInfo[3]);
PlayRainStoppingSoundEffect();
PlaySE(SE_KAIDAN);
gFieldCallback = sub_807DF64;