From 8d9df7cc26ef86c7af1d4aa6fd4633667bb3a743 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 24 Sep 2017 19:54:16 -0400 Subject: Fixed Shedinja hash collision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A Shedinja will always have the same IVs, personality value, and original trainer as the Nincada that generated it, meaning that it is guaranteed to have the same hash as the Ninjask that the Nincada evolved into. To cirvument this, there is now a boolean field in the hash determiner that is set if and only if the Pokémon is a Shedinja. This allows the Ninjask to be considered the same Pokémon as the Nincada it evolved from, but for the Shedinja to be considered a new Pokémon. Because the hash determiner has changed, all old hashes are now invalid. --- gba/source/serialize.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'gba/source/serialize.c') 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 @@ #include "dexorder.h" #include "sha2.h" +// See pokemon.h for more information about this. +struct HashDeterminer { + u32 otId; + u32 personality; + u32 hpIV:5; + u32 attackIV:5; + u32 defenseIV:5; + u32 speedIV:5; + u32 spAttackIV:5; + u32 spDefenseIV:5; + u32 isShedinja:1; + u32 zero:1; +}; + u32 CalculateStat( u8 base, u32 iv, @@ -50,13 +64,20 @@ void PokemonIntermediateInit( struct PokemonSubstruct2* sub2 = GetBoxPokemonSubstruct2(bpkm); struct PokemonSubstruct3* sub3 = GetBoxPokemonSubstruct3(bpkm); - u32 identifier[3]; - identifier[0] = bpkm->otId; // original trainer - identifier[1] = bpkm->personality; // personality value - identifier[2] = ((const u32*)sub3)[1]; // IVs (plus two non-random bits) + struct HashDeterminer identifier; + identifier.otId = bpkm->otId; + identifier.personality = bpkm->personality; + identifier.hpIV = sub3->hpIV; + identifier.attackIV = sub3->attackIV; + identifier.defenseIV = sub3->defenseIV; + identifier.speedIV = sub3->speedIV; + identifier.spAttackIV = sub3->spAttackIV; + identifier.spDefenseIV = sub3->spDefenseIV; + identifier.isShedinja = (sub0->species == SHEDINJA_SPECIES_INDEX) ? 1 : 0; + identifier.zero = 0; sha224( - (const unsigned char*)identifier, + (const unsigned char*)&identifier, 12, (unsigned char*)pki->key); -- cgit 1.4.1