about summary refs log tree commit diff stats
path: root/gba/source/serialize.c
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-09-10 22:12:47 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-09-10 22:12:47 -0400
commit6ceeb199181d64031f4173cfbffa066f5b9796b8 (patch)
treeabda49c65817f58de5c0cb884e8848aae5723dea /gba/source/serialize.c
parent1d82e3affd42c2336702af4a644baa8eec249ead (diff)
downloadgen3uploader-6ceeb199181d64031f4173cfbffa066f5b9796b8.tar.gz
gen3uploader-6ceeb199181d64031f4173cfbffa066f5b9796b8.tar.bz2
gen3uploader-6ceeb199181d64031f4173cfbffa066f5b9796b8.zip
Added identifying hash to Pokémon data structure
The purpose of this hash is described in detail in pokemon.h. The hash
is computed using an implementation of SHA-224. To allow the GBA
sufficient time to compute this hash, a delay of 5 milliseconds was
introduced on the GC side before reading a Pokémon.
Diffstat (limited to 'gba/source/serialize.c')
-rw-r--r--gba/source/serialize.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/gba/source/serialize.c b/gba/source/serialize.c index c5e8570..ddd3ef2 100644 --- a/gba/source/serialize.c +++ b/gba/source/serialize.c
@@ -10,6 +10,7 @@
10#include "basestats.h" 10#include "basestats.h"
11#include "exptables.h" 11#include "exptables.h"
12#include "dexorder.h" 12#include "dexorder.h"
13#include "sha2.h"
13 14
14u32 CalculateStat( 15u32 CalculateStat(
15 u8 base, 16 u8 base,
@@ -51,6 +52,16 @@ void PokemonIntermediateInit(
51 struct PokemonSubstruct2* sub2 = GetBoxPokemonSubstruct2(bpkm); 52 struct PokemonSubstruct2* sub2 = GetBoxPokemonSubstruct2(bpkm);
52 struct PokemonSubstruct3* sub3 = GetBoxPokemonSubstruct3(bpkm); 53 struct PokemonSubstruct3* sub3 = GetBoxPokemonSubstruct3(bpkm);
53 54
55 u32 identifier[3];
56 identifier[0] = bpkm->otId; // original trainer
57 identifier[1] = bpkm->personality; // personality value
58 identifier[2] = ((const u32*)sub3)[1]; // IVs (plus two non-random bits)
59
60 sha224(
61 (const unsigned char*)identifier,
62 12,
63 (unsigned char*)pki->key);
64
54 const struct SmallBaseStats* baseStats = BaseStatsForSpecies(sub0->species); 65 const struct SmallBaseStats* baseStats = BaseStatsForSpecies(sub0->species);
55 66
56 for (int i=0; i<POKEMON_NAME_LENGTH; i++) 67 for (int i=0; i<POKEMON_NAME_LENGTH; i++)
@@ -63,7 +74,7 @@ void PokemonIntermediateInit(
63 pki->otName[i] = bpkm->otName[i]; 74 pki->otName[i] = bpkm->otName[i];
64 } 75 }
65 76
66 pki->otId = bpkm->otId; 77 pki->otId = bpkm->otId & 0x0000FFFF;
67 pki->otGender = sub3->otGender; 78 pki->otGender = sub3->otGender;
68 pki->species = gSpeciesToNationalPokedexNum[sub0->species - 1]; 79 pki->species = gSpeciesToNationalPokedexNum[sub0->species - 1];
69 pki->heldItem = sub0->heldItem; 80 pki->heldItem = sub0->heldItem;