Encyprtion

This commit is contained in:
ProjectRevoTPP
2017-11-27 15:20:10 -05:00
parent 9644f44982
commit e6bcfee668
4 changed files with 29 additions and 29 deletions

View File

@@ -52672,8 +52672,8 @@ SetBerryPowder: @ 802467C
.pool .pool
thumb_func_end SetBerryPowder thumb_func_end SetBerryPowder
thumb_func_start ApplyNewEncyprtionKeyToBerryPowder thumb_func_start ApplyNewEncryptionKeyToBerryPowder
ApplyNewEncyprtionKeyToBerryPowder: @ 8024690 ApplyNewEncryptionKeyToBerryPowder: @ 8024690
push {lr} push {lr}
adds r1, r0, 0 adds r1, r0, 0
ldr r0, =gSaveBlock2Ptr ldr r0, =gSaveBlock2Ptr
@@ -52681,11 +52681,11 @@ ApplyNewEncyprtionKeyToBerryPowder: @ 8024690
movs r2, 0xFA movs r2, 0xFA
lsls r2, 1 lsls r2, 1
adds r0, r2 adds r0, r2
bl ApplyNewEncyprtionKeyToWord bl ApplyNewEncryptionKeyToWord
pop {r0} pop {r0}
bx r0 bx r0
.pool .pool
thumb_func_end ApplyNewEncyprtionKeyToBerryPowder thumb_func_end ApplyNewEncryptionKeyToBerryPowder
thumb_func_start sub_80246AC thumb_func_start sub_80246AC
sub_80246AC: @ 80246AC sub_80246AC: @ 80246AC

View File

@@ -238,8 +238,8 @@ _08084854:
.pool .pool
thumb_func_end sav12_xor_set thumb_func_end sav12_xor_set
thumb_func_start ApplyNewEncyprtionKeyToGameStats thumb_func_start ApplyNewEncryptionKeyToGameStats
ApplyNewEncyprtionKeyToGameStats: @ 8084864 ApplyNewEncryptionKeyToGameStats: @ 8084864
push {r4-r6,lr} push {r4-r6,lr}
adds r5, r0, 0 adds r5, r0, 0
movs r4, 0 movs r4, 0
@@ -251,7 +251,7 @@ _0808486C:
ldr r0, [r6] ldr r0, [r6]
adds r0, r1 adds r0, r1
adds r1, r5, 0 adds r1, r5, 0
bl ApplyNewEncyprtionKeyToWord bl ApplyNewEncryptionKeyToWord
adds r0, r4, 0x1 adds r0, r4, 0x1
lsls r0, 24 lsls r0, 24
lsrs r4, r0, 24 lsrs r4, r0, 24
@@ -261,7 +261,7 @@ _0808486C:
pop {r0} pop {r0}
bx r0 bx r0
.pool .pool
thumb_func_end ApplyNewEncyprtionKeyToGameStats thumb_func_end ApplyNewEncryptionKeyToGameStats
thumb_func_start CopyFieldObjectTemplatesToSav1 thumb_func_start CopyFieldObjectTemplatesToSav1
@ void CopyFieldObjectTemplatesToSav1() @ void CopyFieldObjectTemplatesToSav1()

View File

@@ -5,7 +5,7 @@
#include "text.h" #include "text.h"
#include "event_data.h" #include "event_data.h"
extern void ApplyNewEncyprtionKeyToHword(u16* hword, u32 newKey); extern void ApplyNewEncryptionKeyToHword(u16* hword, u32 newKey);
extern bool8 InBattlePyramid(void); extern bool8 InBattlePyramid(void);
extern const u8 gText_PokeBalls[]; extern const u8 gText_PokeBalls[];
@@ -45,19 +45,19 @@ void SetBagItemId(u16* slot, u16 newItemId)
*slot = newItemId; *slot = newItemId;
} }
void ApplyNewEncyprtionKeyToBagItems(u32 newKey) void ApplyNewEncryptionKeyToBagItems(u32 newKey)
{ {
u32 pocket, item; u32 pocket, item;
for (pocket = 0; pocket < 5; pocket++) for (pocket = 0; pocket < 5; pocket++)
{ {
for (item = 0; item < gBagPockets[pocket].capacity; item++) for (item = 0; item < gBagPockets[pocket].capacity; item++)
ApplyNewEncyprtionKeyToHword(&(gBagPockets[pocket].itemSlots[item].quantity), newKey); ApplyNewEncryptionKeyToHword(&(gBagPockets[pocket].itemSlots[item].quantity), newKey);
} }
} }
void ApplyNewEncyprtionKeyToBagItems_(u32 newKey) // really GF? void ApplyNewEncryptionKeyToBagItems_(u32 newKey) // really GF?
{ {
ApplyNewEncyprtionKeyToBagItems(newKey); ApplyNewEncryptionKeyToBagItems(newKey);
} }
// TODO: move those max values to defines // TODO: move those max values to defines

View File

@@ -10,10 +10,10 @@ extern void* gUnknown_0203CF5C;
extern bool16 IdentifyFlash(void); extern bool16 IdentifyFlash(void);
extern void SetBagItemsPointers(void); extern void SetBagItemsPointers(void);
extern void SetDecorationInventoriesPointers(void); extern void SetDecorationInventoriesPointers(void);
extern void ApplyNewEncyprtionKeyToGameStats(u32 key); extern void ApplyNewEncryptionKeyToGameStats(u32 key);
extern void ApplyNewEncyprtionKeyToBagItems(u32 newKey); extern void ApplyNewEncryptionKeyToBagItems(u32 newKey);
extern void ApplyNewEncyprtionKeyToBagItems_(u32 key); extern void ApplyNewEncryptionKeyToBagItems_(u32 key);
extern void ApplyNewEncyprtionKeyToBerryPowder(u32 key); extern void ApplyNewEncryptionKeyToBerryPowder(u32 key);
extern void sub_8084FAC(int unused); extern void sub_8084FAC(int unused);
// this is probably wrong or misleading due to it being used in ResetHeap... // this is probably wrong or misleading due to it being used in ResetHeap...
@@ -43,7 +43,7 @@ EWRAM_DATA u8 gSaveblock3_DMA[SAVEBLOCK_MOVE_RANGE] = {0};
EWRAM_DATA struct LoadedSaveData gLoadedSaveData = {0}; EWRAM_DATA struct LoadedSaveData gLoadedSaveData = {0};
EWRAM_DATA u32 gLastEncryptionKey = {0}; EWRAM_DATA u32 gLastEncryptionKey = {0};
void ApplyNewEncyprtionKeyToAllEncryptedData(u32 encryptionKey); void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey);
void CheckForFlashMemory(void) void CheckForFlashMemory(void)
{ {
@@ -150,7 +150,7 @@ void MoveSaveBlocks_ResetHeap(void)
// create a new encryption key // create a new encryption key
encryptionKey = (Random() << 0x10) + (Random()); encryptionKey = (Random() << 0x10) + (Random());
ApplyNewEncyprtionKeyToAllEncryptedData(encryptionKey); ApplyNewEncryptionKeyToAllEncryptedData(encryptionKey);
gSaveBlock2Ptr->encryptionKey = encryptionKey; gSaveBlock2Ptr->encryptionKey = encryptionKey;
} }
#else #else
@@ -235,7 +235,7 @@ void MoveSaveBlocks_ResetHeap(void)
lsrs r0, 16\n\ lsrs r0, 16\n\
adds r4, r0\n\ adds r4, r0\n\
adds r0, r4, 0\n\ adds r0, r4, 0\n\
bl ApplyNewEncyprtionKeyToAllEncryptedData\n\ bl ApplyNewEncryptionKeyToAllEncryptedData\n\
ldr r1, =gSaveBlock2Ptr\n\ ldr r1, =gSaveBlock2Ptr\n\
ldr r0, [r1]\n\ ldr r0, [r1]\n\
adds r0, 0xAC\n\ adds r0, 0xAC\n\
@@ -389,27 +389,27 @@ void copy_bags_and_unk_data_to_save_blocks(void)
encryptionKeyBackup = gSaveBlock2Ptr->encryptionKey; encryptionKeyBackup = gSaveBlock2Ptr->encryptionKey;
gSaveBlock2Ptr->encryptionKey = gLastEncryptionKey; gSaveBlock2Ptr->encryptionKey = gLastEncryptionKey;
ApplyNewEncyprtionKeyToBagItems(encryptionKeyBackup); ApplyNewEncryptionKeyToBagItems(encryptionKeyBackup);
gSaveBlock2Ptr->encryptionKey = encryptionKeyBackup; // updated twice? gSaveBlock2Ptr->encryptionKey = encryptionKeyBackup; // updated twice?
} }
void ApplyNewEncyprtionKeyToHword(u16 *hWord, u32 newKey) void ApplyNewEncryptionKeyToHword(u16 *hWord, u32 newKey)
{ {
*hWord ^= gSaveBlock2Ptr->encryptionKey; *hWord ^= gSaveBlock2Ptr->encryptionKey;
*hWord ^= newKey; *hWord ^= newKey;
} }
void ApplyNewEncyprtionKeyToWord(u32 *word, u32 newKey) void ApplyNewEncryptionKeyToWord(u32 *word, u32 newKey)
{ {
*word ^= gSaveBlock2Ptr->encryptionKey; *word ^= gSaveBlock2Ptr->encryptionKey;
*word ^= newKey; *word ^= newKey;
} }
void ApplyNewEncyprtionKeyToAllEncryptedData(u32 encryptionKey) void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey)
{ {
ApplyNewEncyprtionKeyToGameStats(encryptionKey); ApplyNewEncryptionKeyToGameStats(encryptionKey);
ApplyNewEncyprtionKeyToBagItems_(encryptionKey); ApplyNewEncryptionKeyToBagItems_(encryptionKey);
ApplyNewEncyprtionKeyToBerryPowder(encryptionKey); ApplyNewEncryptionKeyToBerryPowder(encryptionKey);
ApplyNewEncyprtionKeyToWord(&gSaveBlock1Ptr->money, encryptionKey); ApplyNewEncryptionKeyToWord(&gSaveBlock1Ptr->money, encryptionKey);
ApplyNewEncyprtionKeyToHword(&gSaveBlock1Ptr->coins, encryptionKey); ApplyNewEncryptionKeyToHword(&gSaveBlock1Ptr->coins, encryptionKey);
} }