summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPikalaxALT <pikalaxalt@gmail.com>2020-06-13 17:08:36 -0400
committerPikalaxALT <pikalaxalt@gmail.com>2020-06-13 17:08:36 -0400
commit1539bc21bce1ad6c80bd7ead5a9658ea6f2182e3 (patch)
tree5af20fd146a2ae003806d192bd146a70cf8a109a
parente8e76fcd320eea906d2746f0315bd0918bd40cb3 (diff)
GenerateShinyPersonality
-rw-r--r--arm9/asm/pokemon_s.s69
-rw-r--r--arm9/src/pokemon.c27
-rw-r--r--include/pokemon.h1
3 files changed, 28 insertions, 69 deletions
diff --git a/arm9/asm/pokemon_s.s b/arm9/asm/pokemon_s.s
index 82548f30..80eadfe8 100644
--- a/arm9/asm/pokemon_s.s
+++ b/arm9/asm/pokemon_s.s
@@ -23,75 +23,6 @@ __local_str_poketool_personal_pms_narc: ; 0x02105FC8
.extern BoxMonIsShiny
- thumb_func_start GenerateShinyPersonality
-GenerateShinyPersonality: ; 0x02068AD8
- push {r3-r7, lr}
- add r7, r0, #0x0
- ldr r0, _02068B64 ; =0xFFFF0000
- and r0, r7
- lsr r1, r0, #0x10
- lsl r0, r7, #0x10
- lsr r0, r0, #0x10
- eor r0, r1
- lsr r7, r0, #0x3
- bl rand_LC
- mov r1, #0x7
- and r0, r1
- lsl r0, r0, #0x10
- lsr r6, r0, #0x10
- bl rand_LC
- mov r1, #0x7
- and r0, r1
- lsl r0, r0, #0x10
- lsr r5, r0, #0x10
- mov r4, #0x0
-_02068B04:
- add r0, r4, #0x0
- bl MaskOfFlagNo
- tst r0, r7
- beq _02068B34
- bl rand_LC
- mov r1, #0x1
- tst r0, r1
- beq _02068B26
- add r0, r4, #0x3
- bl MaskOfFlagNo
- orr r0, r6
- lsl r0, r0, #0x10
- lsr r6, r0, #0x10
- b _02068B56
-_02068B26:
- add r0, r4, #0x3
- bl MaskOfFlagNo
- orr r0, r5
- lsl r0, r0, #0x10
- lsr r5, r0, #0x10
- b _02068B56
-_02068B34:
- bl rand_LC
- mov r1, #0x1
- tst r0, r1
- beq _02068B56
- add r0, r4, #0x3
- bl MaskOfFlagNo
- orr r0, r6
- lsl r0, r0, #0x10
- lsr r6, r0, #0x10
- add r0, r4, #0x3
- bl MaskOfFlagNo
- orr r0, r5
- lsl r0, r0, #0x10
- lsr r5, r0, #0x10
-_02068B56:
- add r4, r4, #0x1
- cmp r4, #0xd
- blt _02068B04
- lsl r0, r5, #0x10
- orr r0, r6
- pop {r3-r7, pc}
- nop
-_02068B64: .word 0xFFFF0000
-
thumb_func_start FUN_02068B68
FUN_02068B68: ; 0x02068B68
ldr r3, _02068B6C ; =FUN_02068B70
diff --git a/arm9/src/pokemon.c b/arm9/src/pokemon.c
index 99dea6d5..c253c709 100644
--- a/arm9/src/pokemon.c
+++ b/arm9/src/pokemon.c
@@ -25,6 +25,7 @@ u16 ModifyStatByNature(u8 nature, u16 statval, u8 statno);
u8 GetGenderBySpeciesAndPersonality_PreloadedPersonal(struct BaseStats * personal, u16 species, u32 pid);
u8 BoxMonIsShiny(struct BoxPokemon * boxmon);
u8 CalcShininessByOtIdAndPersonality(u32 otid, u32 pid);
+u32 MaskOfFlagNo(int flagno);
void LoadMonPersonal(int species, struct BaseStats * personal);
int ResolveMonForme(int species, int forme);
@@ -2117,3 +2118,29 @@ u8 CalcShininessByOtIdAndPersonality(u32 otid, u32 pid)
{
return SHINY_CHECK(otid, pid);
}
+
+u32 GenerateShinyPersonality(u32 otid)
+{
+ int r4;
+ u16 r6;
+ u16 r5;
+ otid = (u32)((((otid & 0xFFFF0000) >> 16) ^ (otid & 0xFFFF)) >> 3u);
+ r6 = (u16)(rand_LC() & 7);
+ r5 = (u16)(rand_LC() & 7);
+ for (r4 = 0; r4 < 13; r4++)
+ {
+ if (MaskOfFlagNo(r4) & otid)
+ {
+ if (rand_LC() & 1)
+ r6 |= MaskOfFlagNo(r4 + 3);
+ else
+ r5 |= MaskOfFlagNo(r4 + 3);
+ }
+ else if (rand_LC() & 1)
+ {
+ r6 |= MaskOfFlagNo(r4 + 3);
+ r5 |= MaskOfFlagNo(r4 + 3);
+ }
+ }
+ return (u32)((r5 << 16) | r6);
+}
diff --git a/include/pokemon.h b/include/pokemon.h
index 897b6731..6d2c8cf7 100644
--- a/include/pokemon.h
+++ b/include/pokemon.h
@@ -516,5 +516,6 @@ u8 GetMonGender(struct Pokemon * pokemon);
u8 GetBoxMonGender(struct BoxPokemon * boxmon);
u8 GetGenderBySpeciesAndPersonality(u16 species, u32 pid);
u8 MonIsShiny(struct Pokemon * pokemon);
+u32 GenerateShinyPersonality(u32 otid);
#endif //POKEDIAMOND_POKEMON_H