diff options
author | PikalaxALT <PikalaxALT@users.noreply.github.com> | 2019-10-06 18:03:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-06 18:03:21 -0400 |
commit | fb9b695f9a366f662b5262f440d77c770b131d0d (patch) | |
tree | 4aea0466e25e069d4b17fc8d1d0cdd23bee6e128 /src | |
parent | b4b509f68477068ae111cc5a6094d858d396c4bb (diff) | |
parent | 076971ee687e1956a1b01144634b3e3468e23cff (diff) |
Merge pull request #112 from ultima-soul/new_game
Decompile/port new_game
Diffstat (limited to 'src')
-rw-r--r-- | src/battle_records.c | 12 | ||||
-rw-r--r-- | src/berry_powder.c | 24 | ||||
-rw-r--r-- | src/item.c | 2 | ||||
-rw-r--r-- | src/mevent.c | 4 | ||||
-rw-r--r-- | src/mevent_server.c | 2 | ||||
-rw-r--r-- | src/mystery_event_script.c | 2 | ||||
-rw-r--r-- | src/new_game.c | 161 | ||||
-rw-r--r-- | src/quest_log.c | 2 | ||||
-rw-r--r-- | src/scrcmd.c | 14 | ||||
-rw-r--r-- | src/seagallop.c | 2 | ||||
-rw-r--r-- | src/trainer_tower.c | 2 |
11 files changed, 194 insertions, 33 deletions
diff --git a/src/battle_records.c b/src/battle_records.c index 3c2032641..38889ca67 100644 --- a/src/battle_records.c +++ b/src/battle_records.c @@ -279,7 +279,7 @@ static void ResetBGPos(void) ChangeBgY(3, 0, 0); } -static void InitLinkBattleRecord(struct LinkBattleRecord * record) +static void ClearLinkBattleRecord(struct LinkBattleRecord *record) { CpuFill16(0, record, sizeof(*record)); record->name[0] = EOS; @@ -289,12 +289,12 @@ static void InitLinkBattleRecord(struct LinkBattleRecord * record) record->draws = 0; } -static void InitLinkBattleRecords_(struct LinkBattleRecords * records) +static void ClearLinkBattleRecords(struct LinkBattleRecords *records) { s32 i; for (i = 0; i < LINK_B_RECORDS_COUNT; i++) - InitLinkBattleRecord(&records->entries[i]); + ClearLinkBattleRecord(&records->entries[i]); SetGameStat(GAME_STAT_LINK_BATTLE_WINS, 0); SetGameStat(GAME_STAT_LINK_BATTLE_LOSSES, 0); SetGameStat(GAME_STAT_LINK_BATTLE_DRAWS, 0); @@ -404,7 +404,7 @@ static void AddOpponentLinkBattleRecord(struct LinkBattleRecords * records, cons { i = LINK_B_RECORDS_COUNT - 1; record = &records->entries[LINK_B_RECORDS_COUNT - 1]; - InitLinkBattleRecord(record); + ClearLinkBattleRecord(record); StringCopyN(record->name, namebuf, OT_NAME_LENGTH); record->trainerId = trainerId; } @@ -412,9 +412,9 @@ static void AddOpponentLinkBattleRecord(struct LinkBattleRecords * records, cons SortLinkBattleRecords(records); } -void InitLinkBattleRecords(void) +void ClearPlayerLinkBattleRecords(void) { - InitLinkBattleRecords_(&gSaveBlock2Ptr->linkBattleRecords); + ClearLinkBattleRecords(&gSaveBlock2Ptr->linkBattleRecords); } static void IncTrainerCardWinCount(s32 battlerId) diff --git a/src/berry_powder.c b/src/berry_powder.c index 9b3bbc17f..992e82522 100644 --- a/src/berry_powder.c +++ b/src/berry_powder.c @@ -11,12 +11,12 @@ EWRAM_DATA u8 gUnknown_203F464 = 0; -u32 sub_815EE3C(u32 * a0) +u32 DecryptBerryPowder(u32 * a0) { return *a0 ^ gSaveBlock2Ptr->encryptionKey; } -void sub_815EE54(u32 * a0, u32 a1) +void SetBerryPowder(u32 * a0, u32 a1) { *a0 = gSaveBlock2Ptr->encryptionKey ^ a1; } @@ -28,7 +28,7 @@ void sub_815EE6C(u32 a0) bool8 sub_815EE88(u32 a0) { - if (sub_815EE3C(&gSaveBlock2Ptr->berryCrush.berryPowderAmount) < a0) + if (DecryptBerryPowder(&gSaveBlock2Ptr->berryCrush.berryPowderAmount) < a0) return FALSE; else return TRUE; @@ -36,7 +36,7 @@ bool8 sub_815EE88(u32 a0) bool8 sub_815EEB0(void) { - if (sub_815EE3C(&gSaveBlock2Ptr->berryCrush.berryPowderAmount) < gSpecialVar_0x8004) + if (DecryptBerryPowder(&gSaveBlock2Ptr->berryCrush.berryPowderAmount) < gSpecialVar_0x8004) return FALSE; else return TRUE; @@ -45,15 +45,15 @@ bool8 sub_815EEB0(void) bool8 sub_815EEE0(u32 a0) { u32 * ptr = &gSaveBlock2Ptr->berryCrush.berryPowderAmount; - u32 amount = sub_815EE3C(ptr) + a0; + u32 amount = DecryptBerryPowder(ptr) + a0; if (amount > 99999) { - sub_815EE54(ptr, 99999); + SetBerryPowder(ptr, 99999); return FALSE; } else { - sub_815EE54(ptr, amount); + SetBerryPowder(ptr, amount); return TRUE; } } @@ -65,8 +65,8 @@ bool8 sub_815EF20(u32 a0) return FALSE; else { - u32 amount = sub_815EE3C(ptr); - sub_815EE54(ptr, amount - a0); + u32 amount = DecryptBerryPowder(ptr); + SetBerryPowder(ptr, amount - a0); return TRUE; } } @@ -78,15 +78,15 @@ bool8 sub_815EF5C(void) return FALSE; else { - u32 amount = sub_815EE3C(ptr); - sub_815EE54(ptr, amount - gSpecialVar_0x8004); + u32 amount = DecryptBerryPowder(ptr); + SetBerryPowder(ptr, amount - gSpecialVar_0x8004); return TRUE; } } u32 GetBerryPowder(void) { - return sub_815EE3C(&gSaveBlock2Ptr->berryCrush.berryPowderAmount); + return DecryptBerryPowder(&gSaveBlock2Ptr->berryCrush.berryPowderAmount); } void sub_815EFBC(u8 windowId, u32 powder, u8 x, u8 y, u8 speed) diff --git a/src/item.c b/src/item.c index 3f33f464d..42dfd334e 100644 --- a/src/item.c +++ b/src/item.c @@ -326,7 +326,7 @@ void ClearPCItemSlots(void) } } -void ClearItemSlotsInAllBagPockets(void) +void ClearBag(void) { u16 i; diff --git a/src/mevent.c b/src/mevent.c index d0d7f59aa..78880c228 100644 --- a/src/mevent.c +++ b/src/mevent.c @@ -588,7 +588,7 @@ void DestroyWonderCard(void) ClearRamScript(); sub_806E2D0(); sub_806E370(); - sub_80E7524(gSaveBlock2Ptr->unk_4A0); + sub_80E7524(gSaveBlock2Ptr->unk_B0.field_3F0); } bool32 sub_8143F68(const struct MEventBuffer_32E0_Sub * data) @@ -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/mevent_server.c b/src/mevent_server.c index 1c2dc4ced..4e2b7280d 100644 --- a/src/mevent_server.c +++ b/src/mevent_server.c @@ -226,7 +226,7 @@ static u32 ish_mainseq_4(struct mevent_client * svr) sub_8069EA4(svr->recvBuffer, 1000); break; case 18: - memcpy(gSaveBlock2Ptr->unk_4A0, svr->recvBuffer, 0xbc); + memcpy(gSaveBlock2Ptr->unk_B0.field_3F0, svr->recvBuffer, 0xbc); ValidateEReaderTrainer(); break; case 21: diff --git a/src/mystery_event_script.c b/src/mystery_event_script.c index 70566ca58..89df1ee34 100644 --- a/src/mystery_event_script.c +++ b/src/mystery_event_script.c @@ -281,7 +281,7 @@ bool8 MEScrCmd_givepokemon(struct ScriptContext *ctx) bool8 MEScrCmd_addtrainer(struct ScriptContext *ctx) { u32 data = ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]; - memcpy(gSaveBlock2Ptr->unk_4A0, (void *)data, 0xBC); + memcpy(gSaveBlock2Ptr->unk_B0.field_3F0, (void *)data, 0xBC); ValidateEReaderTrainer(); StringExpandPlaceholders(gStringVar4, gText_MysteryGiftNewTrainer); ctx->data[2] = 2; diff --git a/src/new_game.c b/src/new_game.c new file mode 100644 index 000000000..58deac9b9 --- /dev/null +++ b/src/new_game.c @@ -0,0 +1,161 @@ +#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" +#include "event_scripts.h" + +// this file's functions +static 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->unk_B0, sizeof(gSaveBlock2Ptr->unk_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 = FALSE; + 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 = TRUE; + 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(); + InitEventData(); + ResetFameChecker(); + SetMoney(&gSaveBlock1Ptr->money, 3000); + ResetGameStats(); + ClearPlayerLinkBattleRecords(); + sub_80A0904(); + sub_80A0958(); + sub_806E190(); + gPlayerPartyCount = 0; + ZeroPlayerPartyMons(); + ResetPokemonStorageSystem(); + ClearRoamerData(); + gSaveBlock1Ptr->registeredItem = 0; + ClearBag(); + NewGameInitPCItems(); + sub_809C794(); + InitEasyChatPhrases(); + sub_8113044(); + copy_strings_to_sav1(); + ResetMiniGamesResults(); + sub_8143D24(); + sub_815D838(); + WarpToPlayersRoom(); + ScriptContext2_RunNewScript(EventScript_ResetAllMapFlags); + StringCopy(gSaveBlock1Ptr->rivalName, rivalName); + ResetTrainerTowerResults(); +} + +static void ResetMiniGamesResults(void) +{ + CpuFill16(0, &gSaveBlock2Ptr->berryCrush, sizeof(struct BerryCrush)); + SetBerryPowder(&gSaveBlock2Ptr->berryCrush.berryPowderAmount, 0); + ResetPokeJumpResults(); + CpuFill16(0, &gSaveBlock2Ptr->berryPick, sizeof(struct BerryPickingResults)); +} diff --git a/src/quest_log.c b/src/quest_log.c index 8b9ee9395..065b42cef 100644 --- a/src/quest_log.c +++ b/src/quest_log.c @@ -986,7 +986,7 @@ void sub_8111368(void) { gUnknown_203ADFA = 2; sub_806E6FC(); - ClearItemSlotsInAllBagPockets(); + ClearBag(); ClearPCItemSlots(); if (sub_8110AC8() == 1) { 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; diff --git a/src/trainer_tower.c b/src/trainer_tower.c index da3cf6dda..17f6b9e09 100644 --- a/src/trainer_tower.c +++ b/src/trainer_tower.c @@ -1458,7 +1458,7 @@ void sub_815EDF4(u32 * counter, u32 value) *counter = value ^ gSaveBlock2Ptr->encryptionKey; } -void sub_815EE0C(void) +void ResetTrainerTowerResults(void) { s32 i; |