Encryption

This commit is contained in:
Eduardo Quezada 2025-12-24 14:19:36 -03:00
parent 3877709dd1
commit 448e2ddc2b
14 changed files with 52 additions and 51 deletions

View File

@ -1843,7 +1843,7 @@ sub_0207AB0C: ; 0x0207AB0C
add r7, r0, #0x0
add r0, r6, #0x0
add r5, r2, #0x0
bl AcquireMonLock
bl Pokemon_UnlockEncryption
str r0, [sp, #0x4]
add r0, r6, #0x0
mov r1, #0x5
@ -2308,7 +2308,7 @@ _0207AF04:
blo _0207AECC
ldr r1, [sp, #0x4]
add r0, r6, #0x0
bl ReleaseMonLock
bl Pokemon_LockEncryption
add sp, #0x8
pop {r3-r7, pc}
nop

View File

@ -4730,10 +4730,10 @@
.extern BoxPokemon_Init
.extern SizeOfStructPokemon
.extern Pokemon_New
.extern AcquireMonLock
.extern ReleaseMonLock
.extern Pokemon_UnlockEncryption
.extern Pokemon_LockEncryption
.extern AcquireBoxMonLock
.extern ReleaseBoxMonLock
.extern BoxPokemon_LockEncryption
.extern Pokemon_InitWithParams
.extern Pokemon_InitWithNature
.extern Pokemon_InitWithGenderNatureLetter

View File

@ -4713,7 +4713,7 @@ _021D9B9E:
add r1, r6, #0
bl Party_GetMonByIndex
add r4, r0, #0
bl AcquireMonLock
bl Pokemon_UnlockEncryption
add r7, r0, #0
add r0, r4, #0
mov r1, #0xac
@ -4731,7 +4731,7 @@ _021D9B9E:
_021D9BD2:
add r0, r4, #0
add r1, r7, #0
bl ReleaseMonLock
bl Pokemon_LockEncryption
cmp r5, #2
blt _021D9BE4
add sp, #8
@ -5483,7 +5483,7 @@ _021DA1A2:
_021DA1A8:
ldr r1, [sp]
add r0, r5, #0
bl ReleaseBoxMonLock
bl BoxPokemon_LockEncryption
ldr r0, [sp, #4]
add sp, #8
pop {r3, r4, r5, r6, r7, pc}
@ -9323,7 +9323,7 @@ _021DBFB8:
bl SpeciesData_Free
ldr r1, [sp]
add r0, r5, #0
bl ReleaseBoxMonLock
bl BoxPokemon_LockEncryption
pop {r3, r4, r5, r6, r7, pc}
thumb_func_start ov14_021DBFF4
@ -9371,7 +9371,7 @@ _021DC034:
mov r0, #0x1a
lsl r0, r0, #4
ldr r0, [r5, r0]
bl AcquireMonLock
bl Pokemon_UnlockEncryption
add r6, r0, #0
mov r0, #0x1a
lsl r0, r0, #4
@ -9489,7 +9489,7 @@ _021DC034:
lsl r0, r0, #4
ldr r0, [r5, r0]
add r1, r6, #0
bl ReleaseMonLock
bl Pokemon_LockEncryption
add r0, r7, #0
add r0, #0xa4
ldrb r0, [r0]
@ -18971,7 +18971,7 @@ _021E0A36:
bl ov14_021E0B54
ldr r1, [sp, #0x10]
add r0, r6, #0
bl ReleaseBoxMonLock
bl BoxPokemon_LockEncryption
add sp, #0x44
pop {r4, r5, r6, r7, pc}
.align 2, 0
@ -19079,7 +19079,7 @@ _021E0B28:
bl ov14_021E0B54
ldr r1, [sp, #0x14]
add r0, r6, #0
bl ReleaseBoxMonLock
bl BoxPokemon_LockEncryption
add sp, #0x40
pop {r3, r4, r5, r6, r7, pc}
nop
@ -21876,7 +21876,7 @@ _021E20AA:
_021E20C8:
ldr r1, [sp, #0x1c]
add r0, r5, #0
bl ReleaseBoxMonLock
bl BoxPokemon_LockEncryption
ldr r0, [sp, #0x24]
add r6, r6, #2
add r0, r0, #1

View File

@ -293,7 +293,7 @@ _02254A62:
add r1, r6, #0
bl Party_GetMonByIndex
add r4, r0, #0
bl AcquireMonLock
bl Pokemon_UnlockEncryption
add r7, r0, #0
add r0, r4, #0
bl sub_0206B688
@ -342,7 +342,7 @@ _02254ABE:
strb r0, [r5, #0x13]
add r0, r4, #0
add r1, r7, #0
bl ReleaseMonLock
bl Pokemon_LockEncryption
ldr r0, [sp]
add r6, r6, #1
ldr r0, [r0]

View File

@ -341,7 +341,7 @@ _02254A7A:
str r0, [r5, #0x14]
ldr r1, [sp, #0xc]
add r0, r4, #0
bl ReleaseBoxMonLock
bl BoxPokemon_LockEncryption
ldr r0, [sp]
add r7, r7, #1
ldrb r0, [r0]

View File

@ -4037,7 +4037,7 @@ HOF_MonGetMetLocationStringId: ; 0x0222F6C4
add r5, r0, #0
add r0, r4, #0
add r6, r2, #0
bl AcquireMonLock
bl Pokemon_UnlockEncryption
str r0, [sp]
add r0, r4, #0
mov r1, #0x79
@ -4124,7 +4124,7 @@ _0222F778:
_0222F77A:
ldr r1, [sp]
add r0, r4, #0
bl ReleaseMonLock
bl Pokemon_LockEncryption
add r0, r5, #0
pop {r3, r4, r5, r6, r7, pc}
nop

View File

@ -1343,7 +1343,7 @@ ov71_0222E118: ; 0x0222E118
push {r3, r4, r5, r6, r7, lr}
add r5, r0, #0
add r4, r1, #0
bl AcquireMonLock
bl Pokemon_UnlockEncryption
add r7, r0, #0
add r0, r5, #0
mov r1, #0x9a
@ -1382,7 +1382,7 @@ ov71_0222E118: ; 0x0222E118
add r6, r0, #0
add r0, r5, #0
add r1, r7, #0
bl ReleaseMonLock
bl Pokemon_LockEncryption
ldrh r0, [r4]
cmp r0, #0
beq _0222E18E

View File

@ -10874,7 +10874,7 @@ ov80_02232C88: ; 0x02232C88
_02232CF2:
add r0, r5, #0
mov r1, #1
bl ReleaseBoxMonLock
bl BoxPokemon_LockEncryption
ldr r0, [sp, #0x1c]
cmp r0, #0
beq _02232D60
@ -11282,7 +11282,7 @@ _02233028:
blt _02233028
ldr r1, [sp]
add r0, r7, #0
bl ReleaseBoxMonLock
bl BoxPokemon_LockEncryption
cmp r4, #0
beq _0223304C
mov r0, #1

View File

@ -1051,7 +1051,7 @@ _02238648:
bl BG_LoadCharTilesData
ldr r1, [sp, #0x20]
add r0, r4, #0
bl ReleaseBoxMonLock
bl BoxPokemon_LockEncryption
add r0, r7, #0
bl FreeToHeap
_02238690:

View File

@ -22593,7 +22593,7 @@ _0223853E:
bl BoxPokemon_SetData
ldr r1, [sp]
add r0, r4, #0
bl ReleaseBoxMonLock
bl BoxPokemon_LockEncryption
add sp, #0x30
pop {r3, r4, r5, r6, r7, pc}
nop

View File

@ -29,7 +29,7 @@ void Save_HOF_RecordParty(struct HallOfFame *hof, struct Party *party, RTCDate *
int i, j;
for (i = 0, j = 0; i < nmons; i++) {
struct Pokemon *mon = Party_GetMonByIndex(party, i);
BOOL lock = AcquireMonLock(mon);
BOOL lock = Pokemon_UnlockEncryption(mon);
if (!Pokemon_GetData(mon, MON_DATA_IS_EGG, NULL)) {
hof_party->party[j].species = (u16)Pokemon_GetData(mon, MON_DATA_SPECIES, NULL);
hof_party->party[j].level = (u8)Pokemon_GetData(mon, MON_DATA_LEVEL, NULL);
@ -51,7 +51,7 @@ void Save_HOF_RecordParty(struct HallOfFame *hof, struct Party *party, RTCDate *
}
j++;
}
ReleaseMonLock(mon, lock);
Pokemon_LockEncryption(mon, lock);
}
hof_party->year = (u16)date->year;
hof_party->month = (u8)date->month;

View File

@ -125,7 +125,7 @@ Pokemon *Pokemon_New(HeapID heapID) {
return mon;
}
BOOL AcquireMonLock(Pokemon *mon) {
BOOL Pokemon_UnlockEncryption(Pokemon *mon) {
BOOL ret = FALSE;
if (!mon->box.partyDecrypted) {
@ -139,7 +139,7 @@ BOOL AcquireMonLock(Pokemon *mon) {
return ret;
}
BOOL ReleaseMonLock(Pokemon *mon, BOOL decrypt_result) {
BOOL Pokemon_LockEncryption(Pokemon *mon, BOOL decrypt_result) {
BOOL ret = FALSE;
if (mon->box.partyDecrypted == TRUE && decrypt_result == TRUE) {
ret = TRUE;
@ -163,7 +163,7 @@ BOOL AcquireBoxMonLock(BoxPokemon *mon) {
return ret;
}
BOOL ReleaseBoxMonLock(BoxPokemon *mon, BOOL decrypt_result) {
BOOL BoxPokemon_LockEncryption(BoxPokemon *mon, BOOL decrypt_result) {
BOOL ret = FALSE;
if (mon->boxDecrypted == TRUE && decrypt_result == TRUE) {
ret = TRUE;
@ -268,7 +268,7 @@ void BoxPokemon_InitWithParams(BoxPokemon *boxMon, int species, int level, int i
var1 = BoxPokemon_GetGender(boxMon);
BoxPokemon_SetData(boxMon, MON_DATA_GENDER, &var1);
BoxPokemon_SetDefaultMoves(boxMon);
ReleaseBoxMonLock(boxMon, reencrypt);
BoxPokemon_LockEncryption(boxMon, reencrypt);
}
void Pokemon_InitWithNature(Pokemon *mon, u16 species, u8 level, u8 ivs, u8 nature) {
@ -321,11 +321,11 @@ void CreateMonWithFixedIVs(Pokemon *mon, int species, int level, int ivs, int pe
}
void Pokemon_CalcLevelAndStats(Pokemon *mon) {
BOOL reencrypt = AcquireMonLock(mon);
BOOL reencrypt = Pokemon_UnlockEncryption(mon);
int level = Pokemon_CalcLevel(mon);
Pokemon_SetData(mon, MON_DATA_LEVEL, &level);
Pokemon_CalcStats(mon);
ReleaseMonLock(mon, reencrypt);
Pokemon_LockEncryption(mon, reencrypt);
}
void Pokemon_CalcStats(Pokemon *mon) {
@ -334,7 +334,8 @@ void Pokemon_CalcStats(Pokemon *mon) {
int hpEV, atkEV, defEV, speedEV, spAtkEV, spDefEV;
int form, species;
int newMaxHp;
BOOL reencrypt = AcquireMonLock(mon);
BOOL reencrypt = Pokemon_UnlockEncryption(mon);
int level = Pokemon_GetData(mon, MON_DATA_LEVEL, NULL);
maxHp = Pokemon_GetData(mon, MON_DATA_MAX_HP, NULL);
@ -405,7 +406,7 @@ void Pokemon_CalcStats(Pokemon *mon) {
if (hp != 0) {
Pokemon_SetData(mon, MON_DATA_HP, &hp);
}
ReleaseMonLock(mon, reencrypt);
Pokemon_LockEncryption(mon, reencrypt);
}
u32 Pokemon_GetData(Pokemon *mon, int param, void *dest) {
@ -1777,14 +1778,14 @@ int Species_GetValue(int species, enum SpeciesDataParam param) {
}
u8 Pokemon_CalcPercentToNextLevel(Pokemon *mon) {
BOOL recrypt = AcquireMonLock(mon);
BOOL recrypt = Pokemon_UnlockEncryption(mon);
u16 species = Pokemon_GetData(mon, MON_DATA_SPECIES, NULL);
u8 level = Pokemon_GetData(mon, MON_DATA_LEVEL, NULL);
u32 curLevelExp = Species_GetExpAtLevel(species, level);
u32 nextLevelExp = Species_GetExpAtLevel(species, level + 1);
u32 curExp = Pokemon_GetData(mon, MON_DATA_EXPERIENCE, NULL);
ReleaseMonLock(mon, recrypt);
Pokemon_LockEncryption(mon, recrypt);
u8 percent = ((curExp - curLevelExp) * 100) / (nextLevelExp - curLevelExp);
return percent;
@ -1837,7 +1838,7 @@ int BoxPokemon_CalcLevel(BoxPokemon *boxMon) {
BOOL reencrypt = AcquireBoxMonLock(boxMon);
int species = BoxPokemon_GetData(boxMon, MON_DATA_SPECIES, NULL);
int exp = BoxPokemon_GetData(boxMon, MON_DATA_EXPERIENCE, NULL);
ReleaseBoxMonLock(boxMon, reencrypt);
BoxPokemon_LockEncryption(boxMon, reencrypt);
return Species_CalcLevelByExp(species, exp);
}
@ -1868,7 +1869,7 @@ u8 Pokemon_GetNature(Pokemon *mon) {
u8 BoxPokemon_GetNature(BoxPokemon *boxMon) {
BOOL reencrypt = AcquireBoxMonLock(boxMon);
u32 personality = BoxPokemon_GetData(boxMon, MON_DATA_PERSONALITY, NULL);
ReleaseBoxMonLock(boxMon, reencrypt);
BoxPokemon_LockEncryption(boxMon, reencrypt);
return Personality_GetNature(personality);
}
@ -1993,7 +1994,7 @@ u8 BoxPokemon_GetGender(BoxPokemon *boxMon) {
BOOL reencrypt = AcquireBoxMonLock(boxMon);
u16 species = BoxPokemon_GetData(boxMon, MON_DATA_SPECIES, NULL);
u32 personality = BoxPokemon_GetData(boxMon, MON_DATA_PERSONALITY, NULL);
ReleaseBoxMonLock(boxMon, reencrypt);
BoxPokemon_LockEncryption(boxMon, reencrypt);
return Species_GetGenderFromPersonality(species, personality);
}
@ -2092,7 +2093,7 @@ void sub_02068B70(struct SomeDrawPokemonStruct *spC, BoxPokemon *boxMon, u8 sp10
form = (u8)BoxPokemon_GetData(boxMon, MON_DATA_FORM, NULL);
}
sub_02068C00(spC, species, gender, sp10, shiny, form, personality);
ReleaseBoxMonLock(boxMon, decry);
BoxPokemon_LockEncryption(boxMon, decry);
}
void sub_02068C00(struct SomeDrawPokemonStruct *spC, int species, u8 gender, u8 sp10, u8 shiny, u8 form, u32 personality) {
@ -2669,7 +2670,7 @@ void BoxPokemon_SetDefaultMoves(BoxPokemon *boxMon) {
}
}
FreeToHeap(levelUpLearnset);
ReleaseBoxMonLock(boxMon, decry);
BoxPokemon_LockEncryption(boxMon, decry);
}
u32 sub_02069698(Pokemon *pokemon, u16 move) {
@ -2693,7 +2694,7 @@ u32 sub_020696A8(BoxPokemon *boxMon, u16 move) {
break;
}
}
ReleaseBoxMonLock(boxMon, decry);
BoxPokemon_LockEncryption(boxMon, decry);
return ret;
}
@ -2724,7 +2725,7 @@ void sub_02069718(BoxPokemon *boxMon, u16 move) {
BoxPokemon_SetData(boxMon, MON_DATA_MOVE1_PP_UPS + i, &ppUp[i]);
}
ReleaseBoxMonLock(boxMon, decry);
BoxPokemon_LockEncryption(boxMon, decry);
}
void MonSetMoveInSlot(Pokemon *pokemon, u16 move, u8 slot) {
@ -3221,7 +3222,7 @@ void sub_0206A1CC(BoxPokemon *boxMon) {
} else {
BoxPokemon_SetData(boxMon, MON_DATA_ABILITY, &ability1);
}
ReleaseBoxMonLock(boxMon, decry);
BoxPokemon_LockEncryption(boxMon, decry);
}
void sub_0206A23C(Pokemon *r5, u32 personality) {
@ -3520,5 +3521,5 @@ void RestoreBoxMonPP(BoxPokemon *boxMon) {
BoxPokemon_SetData(boxMon, MON_DATA_MOVE1_PP + i, &pp);
}
}
ReleaseBoxMonLock(boxMon, decry);
BoxPokemon_LockEncryption(boxMon, decry);
}

View File

@ -13,7 +13,7 @@ u32 sub_0206B688(struct BoxPokemon *boxmon) {
u32 is_egg = BoxPokemon_GetData(boxmon, MON_DATA_IS_EGG, NULL);
u32 form = BoxMon_GetAlternateForm(boxmon);
u32 ret = sub_0206B6D4(species, is_egg, form);
ReleaseBoxMonLock(boxmon, decry);
BoxPokemon_LockEncryption(boxmon, decry);
return ret;
}
@ -104,7 +104,7 @@ u32 sub_0206B83C(struct BoxPokemon *boxmon) {
u32 form = BoxMon_GetAlternateForm(boxmon);
u32 species = BoxPokemon_GetData(boxmon, MON_DATA_SPECIES, NULL);
u32 is_egg = BoxPokemon_GetData(boxmon, MON_DATA_IS_EGG, NULL);
ReleaseBoxMonLock(boxmon, decry);
BoxPokemon_LockEncryption(boxmon, decry);
return sub_0206B7BC(species, form, is_egg);
}

View File

@ -227,10 +227,10 @@ void Pokemon_Init(Pokemon *mon);
void BoxPokemon_Init(BoxPokemon *boxMon);
u32 SizeOfStructPokemon(void);
Pokemon *Pokemon_New(HeapID heapId);
BOOL AcquireMonLock(Pokemon *mon);
BOOL ReleaseMonLock(Pokemon *mon, BOOL decrypt_result);
BOOL Pokemon_UnlockEncryption(Pokemon *mon);
BOOL Pokemon_LockEncryption(Pokemon *mon, BOOL decrypt_result);
BOOL AcquireBoxMonLock(BoxPokemon *boxMon);
BOOL ReleaseBoxMonLock(BoxPokemon *boxMon, BOOL decrypt_result);
BOOL BoxPokemon_LockEncryption(BoxPokemon *boxMon, BOOL decrypt_result);
void Pokemon_InitWithParams(Pokemon *mon, int species, int level, int fixedIV, int hasFixedPersonality, int fixedPersonality, int otIdType, int fixedOtId);
void BoxPokemon_InitWithParams(BoxPokemon *boxMon, int species, int level, int ivs, BOOL hasFixedPersonality, int personality, int otIDType, int otID);
void Pokemon_InitWithNature(Pokemon *mon, u16 species, u8 level, u8 fixedIv, u8 nature);