remove encryption key

This commit is contained in:
cawtds 2024-08-25 17:39:31 +02:00
parent 349badf759
commit e63dec5389
14 changed files with 12 additions and 96 deletions

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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)

View File

@ -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)

View File

@ -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;

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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)

View File

@ -116,7 +116,6 @@ void NewGameInitData(void)
StringCopy(rivalName, gSaveBlock1Ptr->rivalName);
gDifferentSaveFile = TRUE;
gSaveBlock2Ptr->encryptionKey = 0;
ZeroPlayerPartyMons();
ZeroEnemyPartyMons();
ClearBattleTower();

View File

@ -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

View File

@ -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)