diff options
| -rw-r--r-- | gba/source/serialize.c | 31 | ||||
| -rw-r--r-- | include/pokemon.h | 7 |
2 files changed, 33 insertions, 5 deletions
| diff --git a/gba/source/serialize.c b/gba/source/serialize.c index f5446ef..ddb156c 100644 --- a/gba/source/serialize.c +++ b/gba/source/serialize.c | |||
| @@ -12,6 +12,20 @@ | |||
| 12 | #include "dexorder.h" | 12 | #include "dexorder.h" |
| 13 | #include "sha2.h" | 13 | #include "sha2.h" |
| 14 | 14 | ||
| 15 | // See pokemon.h for more information about this. | ||
| 16 | struct HashDeterminer { | ||
| 17 | u32 otId; | ||
| 18 | u32 personality; | ||
| 19 | u32 hpIV:5; | ||
| 20 | u32 attackIV:5; | ||
| 21 | u32 defenseIV:5; | ||
| 22 | u32 speedIV:5; | ||
| 23 | u32 spAttackIV:5; | ||
| 24 | u32 spDefenseIV:5; | ||
| 25 | u32 isShedinja:1; | ||
| 26 | u32 zero:1; | ||
| 27 | }; | ||
| 28 | |||
| 15 | u32 CalculateStat( | 29 | u32 CalculateStat( |
| 16 | u8 base, | 30 | u8 base, |
| 17 | u32 iv, | 31 | u32 iv, |
| @@ -50,13 +64,20 @@ void PokemonIntermediateInit( | |||
| 50 | struct PokemonSubstruct2* sub2 = GetBoxPokemonSubstruct2(bpkm); | 64 | struct PokemonSubstruct2* sub2 = GetBoxPokemonSubstruct2(bpkm); |
| 51 | struct PokemonSubstruct3* sub3 = GetBoxPokemonSubstruct3(bpkm); | 65 | struct PokemonSubstruct3* sub3 = GetBoxPokemonSubstruct3(bpkm); |
| 52 | 66 | ||
| 53 | u32 identifier[3]; | 67 | struct HashDeterminer identifier; |
| 54 | identifier[0] = bpkm->otId; // original trainer | 68 | identifier.otId = bpkm->otId; |
| 55 | identifier[1] = bpkm->personality; // personality value | 69 | identifier.personality = bpkm->personality; |
| 56 | identifier[2] = ((const u32*)sub3)[1]; // IVs (plus two non-random bits) | 70 | identifier.hpIV = sub3->hpIV; |
| 71 | identifier.attackIV = sub3->attackIV; | ||
| 72 | identifier.defenseIV = sub3->defenseIV; | ||
| 73 | identifier.speedIV = sub3->speedIV; | ||
| 74 | identifier.spAttackIV = sub3->spAttackIV; | ||
| 75 | identifier.spDefenseIV = sub3->spDefenseIV; | ||
| 76 | identifier.isShedinja = (sub0->species == SHEDINJA_SPECIES_INDEX) ? 1 : 0; | ||
| 77 | identifier.zero = 0; | ||
| 57 | 78 | ||
| 58 | sha224( | 79 | sha224( |
| 59 | (const unsigned char*)identifier, | 80 | (const unsigned char*)&identifier, |
| 60 | 12, | 81 | 12, |
| 61 | (unsigned char*)pki->key); | 82 | (unsigned char*)pki->key); |
| 62 | 83 | ||
| diff --git a/include/pokemon.h b/include/pokemon.h index 95af35e..dbf0d41 100644 --- a/include/pokemon.h +++ b/include/pokemon.h | |||
| @@ -35,6 +35,13 @@ struct __attribute__((aligned(4))) PokemonIntermediate { | |||
| 35 | // while not uniformly random (amongst Pokémon), is included as a sort of | 35 | // while not uniformly random (amongst Pokémon), is included as a sort of |
| 36 | // "namespace", in that any Pokémon with matching PVs and IVs must also have | 36 | // "namespace", in that any Pokémon with matching PVs and IVs must also have |
| 37 | // the same OT, thus preventing collaboratively finding PV and IV collisions. | 37 | // the same OT, thus preventing collaboratively finding PV and IV collisions. |
| 38 | // there is one deterministic way that two Pokémon can have the same hash: | ||
| 39 | // when a Nincada evolves into a Ninjask and a Shedinja is generated, the | ||
| 40 | // Shedinja is guaranteed to have the same IVs and personality value as the | ||
| 41 | // Ninjask. we circumvent this by also including a boolean in the hash which | ||
| 42 | // is set to true if the Pokémon is a Shedinja, and false otherwise. this | ||
| 43 | // differentiates a Shedinja from the Ninjask it came from, but also allows | ||
| 44 | // the Ninjask to be associated with the Nincada it used to be. | ||
| 38 | u32 key[7]; | 45 | u32 key[7]; |
| 39 | 46 | ||
| 40 | u32 experience; | 47 | u32 experience; |
