From e63dec5389757ef730d4f5eb3a5ff593cf2b8eab Mon Sep 17 00:00:00 2001 From: cawtds <38510667+cawtds@users.noreply.github.com> Date: Sun, 25 Aug 2024 17:39:31 +0200 Subject: [PATCH] remove encryption key --- include/berry_powder.h | 1 - include/global.h | 2 -- include/item.h | 1 - include/load_save.h | 4 ---- include/overworld.h | 1 - src/berry_powder.c | 9 ++------- src/coins.c | 4 ++-- src/item.c | 22 ++-------------------- src/load_save.c | 41 ----------------------------------------- src/main.c | 1 - src/money.c | 4 ++-- src/new_game.c | 1 - src/overworld.c | 13 ++----------- src/trainer_tower.c | 4 ++-- 14 files changed, 12 insertions(+), 96 deletions(-) diff --git a/include/berry_powder.h b/include/berry_powder.h index f34bb3bf5..c6f5f8e30 100644 --- a/include/berry_powder.h +++ b/include/berry_powder.h @@ -3,7 +3,6 @@ u32 GetBerryPowder(void); void SetBerryPowder(u32 *powder, u32 amount); -void ApplyNewEncryptionKeyToBerryPowder(u32 newKey); bool8 GiveBerryPowder(u32 amountToAdd); #endif //GUARD_BERRY_POWDER_H diff --git a/include/global.h b/include/global.h index 46efbcb76..3e6930539 100644 --- a/include/global.h +++ b/include/global.h @@ -386,8 +386,6 @@ struct SaveBlock2 /*0xAF0*/ struct BerryCrush berryCrush; /*0xB00*/ struct PokemonJumpRecords pokeJump; /*0xB10*/ struct BerryPickingResults berryPick; - // /*0xB20*/ u8 filler_B20[0x400]; - /*0xF20*/ u32 encryptionKey; }; // size: 0xF24 extern struct SaveBlock2 *gSaveBlock2Ptr; diff --git a/include/item.h b/include/item.h index 52e3533e6..74643532f 100644 --- a/include/item.h +++ b/include/item.h @@ -83,7 +83,6 @@ void ItemPcCompaction(void); void RemovePCItem(u16 itemId, u16 quantity); void SortAndCompactBagPocket(struct BagPocket * pocket); u8 CountItemsInPC(void); -void ApplyNewEncryptionKeyToBagItems_(u32 newKey); bool8 HasAtLeastOneBerry(void); bool8 HasAtLeastOnePokeBall(void); diff --git a/include/load_save.h b/include/load_save.h index c9c2514b8..50736edb4 100644 --- a/include/load_save.h +++ b/include/load_save.h @@ -49,10 +49,6 @@ void LoadPlayerBag(void); void SavePlayerBag(void); void SetSaveBlocksPointers(void); void MoveSaveBlocks_ResetHeap(void); -void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey); -void ApplyNewEncryptionKeyToBagItems(u32 encryptionKey); -void ApplyNewEncryptionKeyToWord(u32 * word, u32 encryptionKey); -void ApplyNewEncryptionKeyToHword(u16 * hword, u32 encryptionKey); void ClearContinueGameWarpStatus2(void); void SetContinueGameWarpStatusToDynamicWarp(void); void SetContinueGameWarpStatus(void); diff --git a/include/overworld.h b/include/overworld.h index f4312cf74..2a53f4113 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -157,7 +157,6 @@ bool32 IsSendingKeysOverCable(void); void CB2_ReturnToFieldWithOpenMenu(void); void CB2_WhiteOut(void); void CB2_ReturnToFieldFromMultiplayer(void); -void ApplyNewEncryptionKeyToGameStats(u32 newKey); void SetContinueGameWarpToDynamicWarp(int); void SetContinueGameWarpToHealLocation(u8 loc); diff --git a/src/berry_powder.c b/src/berry_powder.c index 1bc840e25..ac17c385b 100644 --- a/src/berry_powder.c +++ b/src/berry_powder.c @@ -16,17 +16,12 @@ static EWRAM_DATA u8 sBerryPowderVendorWindowId = 0; u32 DecryptBerryPowder(u32 *powder) { - return *powder ^ gSaveBlock2Ptr->encryptionKey; + return *powder; } void SetBerryPowder(u32 *powder, u32 amount) { - *powder = amount ^ gSaveBlock2Ptr->encryptionKey; -} - -void ApplyNewEncryptionKeyToBerryPowder(u32 encryptionKey) -{ - ApplyNewEncryptionKeyToWord(&gSaveBlock2Ptr->berryCrush.berryPowderAmount, encryptionKey); + *powder = amount; } static bool8 HasEnoughBerryPowder(u32 cost) diff --git a/src/coins.c b/src/coins.c index d08015c3f..07a76d7a3 100644 --- a/src/coins.c +++ b/src/coins.c @@ -10,12 +10,12 @@ EWRAM_DATA static u8 sCoinsWindowId = 0; u16 GetCoins(void) { - return gSaveBlock1Ptr->coins ^ gSaveBlock2Ptr->encryptionKey; + return gSaveBlock1Ptr->coins; } void SetCoins(u16 coinAmount) { - gSaveBlock1Ptr->coins = coinAmount ^ gSaveBlock2Ptr->encryptionKey; + gSaveBlock1Ptr->coins = coinAmount; } bool8 AddCoins(u16 toAdd) diff --git a/src/item.c b/src/item.c index 9ef815693..035b0df9e 100644 --- a/src/item.c +++ b/src/item.c @@ -29,12 +29,12 @@ static bool32 DoesItemHavePluralName(u16); u16 GetBagItemQuantity(u16 * ptr) { - return gSaveBlock2Ptr->encryptionKey ^ *ptr; + return *ptr; } void SetBagItemQuantity(u16 * ptr, u16 value) { - *ptr = value ^ gSaveBlock2Ptr->encryptionKey; + *ptr = value; } u16 GetPcItemQuantity(u16 * ptr) @@ -47,24 +47,6 @@ void SetPcItemQuantity(u16 * ptr, u16 value) *ptr = value ^ 0; } -void ApplyNewEncryptionKeyToBagItems(u32 key) -{ - u32 i, j; - - for (i = 0; i < NUM_BAG_POCKETS; i++) - { - for (j = 0; j < gBagPockets[i].capacity; j++) - { - ApplyNewEncryptionKeyToHword(&gBagPockets[i].itemSlots[j].quantity, key); - } - } -} - -void ApplyNewEncryptionKeyToBagItems_(u32 key) -{ - ApplyNewEncryptionKeyToBagItems(key); -} - void SetBagPocketsPointers(void) { gBagPockets[POCKET_ITEMS - 1].itemSlots = gSaveBlock1Ptr->bagPocket_Items; diff --git a/src/load_save.c b/src/load_save.c index e136aa959..ef53c6836 100644 --- a/src/load_save.c +++ b/src/load_save.c @@ -33,7 +33,6 @@ EWRAM_DATA struct SaveBlock1ASLR gSaveblock1 = {0}; EWRAM_DATA struct PokemonStorageASLR gPokemonStorage = {0}; EWRAM_DATA struct LoadedSaveData gLoadedSaveData = {0}; -EWRAM_DATA u32 gLastEncryptionKey = 0; // IWRAM common bool32 gFlashMemoryPresent; @@ -89,7 +88,6 @@ void SetSaveBlocksPointers(void) void MoveSaveBlocks_ResetHeap(void) { void *vblankCB, *hblankCB; - u32 encryptionKey; struct SaveBlock2 *saveBlock2Copy; struct SaveBlock1 *saveBlock1Copy; struct PokemonStorage *pokemonStorageCopy; @@ -125,11 +123,6 @@ void MoveSaveBlocks_ResetHeap(void) // restore interrupt functions gMain.hblankCallback = hblankCB; gMain.vblankCallback = vblankCB; - - // create a new encryption key - encryptionKey = (Random() << 0x10) + (Random()); - ApplyNewEncryptionKeyToAllEncryptedData(encryptionKey); - gSaveBlock2Ptr->encryptionKey = encryptionKey; } u32 UseContinueGameWarp(void) @@ -261,14 +254,11 @@ void LoadPlayerBag(void) // load mail. for (i = 0; i < MAIL_COUNT; i++) gLoadedSaveData.mail[i] = gSaveBlock1Ptr->mail[i]; - - gLastEncryptionKey = gSaveBlock2Ptr->encryptionKey; } void SavePlayerBag(void) { int i; - u32 encryptionKeyBackup; // save player items. for (i = 0; i < BAG_ITEMS_COUNT; i++) @@ -293,35 +283,4 @@ void SavePlayerBag(void) // save mail. for (i = 0; i < MAIL_COUNT; i++) gSaveBlock1Ptr->mail[i] = gLoadedSaveData.mail[i]; - - encryptionKeyBackup = gSaveBlock2Ptr->encryptionKey; - gSaveBlock2Ptr->encryptionKey = gLastEncryptionKey; - ApplyNewEncryptionKeyToBagItems(encryptionKeyBackup); - gSaveBlock2Ptr->encryptionKey = encryptionKeyBackup; -} - -void ApplyNewEncryptionKeyToHword(u16 *hWord, u32 newKey) -{ - *hWord ^= gSaveBlock2Ptr->encryptionKey; - *hWord ^= newKey; -} - -void ApplyNewEncryptionKeyToWord(u32 *word, u32 newKey) -{ - *word ^= gSaveBlock2Ptr->encryptionKey; - *word ^= newKey; -} - -void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey) -{ - int i; - - for(i = 0; i < NUM_TOWER_CHALLENGE_TYPES; i++) - ApplyNewEncryptionKeyToWord(&gSaveBlock1Ptr->trainerTower[i].bestTime, encryptionKey); - - ApplyNewEncryptionKeyToGameStats(encryptionKey); - ApplyNewEncryptionKeyToBagItems_(encryptionKey); - ApplyNewEncryptionKeyToBerryPowder(encryptionKey); - ApplyNewEncryptionKeyToWord(&gSaveBlock1Ptr->money, encryptionKey); - ApplyNewEncryptionKeyToHword(&gSaveBlock1Ptr->coins, encryptionKey); } diff --git a/src/main.c b/src/main.c index a4cbefb48..1f902f519 100644 --- a/src/main.c +++ b/src/main.c @@ -220,7 +220,6 @@ static void InitMainCallbacks(void) SetMainCallback2(gInitialMainCB2); gSaveBlock2Ptr = &gSaveblock2.block; gSaveBlock1Ptr = &gSaveblock1.block; - gSaveblock2.block.encryptionKey = 0; gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; } diff --git a/src/money.c b/src/money.c index f1dc3f6ba..ccf75be23 100644 --- a/src/money.c +++ b/src/money.c @@ -10,12 +10,12 @@ EWRAM_DATA static u8 sMoneyBoxWindowId = 0; u32 GetMoney(u32 *moneyPtr) { - return *moneyPtr ^ gSaveBlock2Ptr->encryptionKey; + return *moneyPtr; } void SetMoney(u32 *moneyPtr, u32 newValue) { - *moneyPtr = gSaveBlock2Ptr->encryptionKey ^ newValue; + *moneyPtr = newValue; } bool8 IsEnoughMoney(u32 *moneyPtr, u32 cost) diff --git a/src/new_game.c b/src/new_game.c index dc4c0debd..9683cbeaa 100644 --- a/src/new_game.c +++ b/src/new_game.c @@ -116,7 +116,6 @@ void NewGameInitData(void) StringCopy(rivalName, gSaveBlock1Ptr->rivalName); gDifferentSaveFile = TRUE; - gSaveBlock2Ptr->encryptionKey = 0; ZeroPlayerPartyMons(); ZeroEnemyPartyMons(); ClearBattleTower(); diff --git a/src/overworld.c b/src/overworld.c index 7678b0059..30dffb703 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -405,23 +405,14 @@ u32 GetGameStat(u8 statId) if (statId >= NUM_USED_GAME_STATS) return 0; else - return gSaveBlock1Ptr->gameStats[statId] ^ gSaveBlock2Ptr->encryptionKey; + return gSaveBlock1Ptr->gameStats[statId]; } void SetGameStat(u8 statId, u32 statVal) { if (statId >= NUM_USED_GAME_STATS) return; - gSaveBlock1Ptr->gameStats[statId] = statVal ^ gSaveBlock2Ptr->encryptionKey; -} - -void ApplyNewEncryptionKeyToGameStats(u32 newKey) -{ - u8 i; - for (i = 0; i < NUM_GAME_STATS; i++) - { - ApplyNewEncryptionKeyToWord(&gSaveBlock1Ptr->gameStats[i], newKey); - } + gSaveBlock1Ptr->gameStats[statId] = statVal; } // Routines related to object events diff --git a/src/trainer_tower.c b/src/trainer_tower.c index 4bf6ada63..d8319ddda 100644 --- a/src/trainer_tower.c +++ b/src/trainer_tower.c @@ -1076,12 +1076,12 @@ void PrintTrainerTowerRecords(void) static u32 GetTrainerTowerRecordTime(u32 *counter) { - return *counter ^ gSaveBlock2Ptr->encryptionKey; + return *counter; } static void SetTrainerTowerRecordTime(u32 *counter, u32 value) { - *counter = value ^ gSaveBlock2Ptr->encryptionKey; + *counter = value; } void ResetTrainerTowerResults(void)