-
Notifications
You must be signed in to change notification settings - Fork 18
Shiny PID Calculation
Well, we know that the shininess is computed this way:
S = TID xor SID xor PID_HIGH xor PID_LOW
where PID_HIGH are the first 16bits of the PID and PID_LOW the last 16bits.
If S < 16 then the pokemon is shiny. The xor is commutative and associative so :
S = (TID xor SID xor PID_LOW) xor PID_HIGH
We know that for any number Y, Y xor Y = 0. Then if we want S = 0 we can modify the PID_HIGH.
NEW_PID_HIGH = (TID xor SID xor PID_LOW)
But well, S is always equal to 0 then, and this is not very "natural". We want S <16 and we know that 0xY, for any hex cipher Y is always less than 16. And we know that for any hex ciphers W, X, Y, Z :
0xWXYZ xor 0xWXY0 = 0x000Z
because Z xor 0 = Z
So if we get rid of the last 4bits of the NEW_PID_HIGH, then S would be equal to the last 4bits of (TID xor SID xor PID_LOW). Another time, it is not "natural", but we know that for any hex ciphers X and Y, X xor Y = Z and Z <16. So we can just get rid of the last 4bits of the NEW_PID_HIGH and replace them with the last 4bits of the base PID_HIGH. Then we would have :
NEW_PID_HIGH = ((TID xor SID xor PID_LOW) and 0xFFF0) or (PID_HIGH and 0x000F)
So if we want to compute the new PID we jus have to replace the first 12bits.
NEW_PID_HIGH = (TID xor SID xor PID_LOW) and 0xFFF0
NEW_PID = (PID and 0x000FFFFF) or (NEW_PID_HIGH << 16)