kwsch / PKHeX

Pokémon Save File Editor
https://projectpokemon.org/pkhex/
Other
3.74k stars 702 forks source link

Gen 1 legendary respawn flag not working #3030

Closed q8yshadow closed 4 years ago

q8yshadow commented 4 years ago

Describe the bug i tried respawning moltres and other legendaries and it doesn't seem to reset them on pkhex (i haven't tried other flags yet but i left them untouched on my saved game except the fossil thing and ghost maroark and snorlax on the right side cuz it's part of the story)

To Reproduce Steps to reproduce the behavior: SAV -> Event Flags -> (pressing one of the pokemons to reset)

Expected behavior The legendary should've respawned after resetting on pkhex.

Additional context these save files of pokemon red are from before and after encountering moltres (standing in front of it) pokemon red savefiles.zip

kwsch commented 4 years ago
    const HS_ARTICUNO                      ; E3 X
    const HS_ZAPDOS                        ; 55 X
    const HS_MOLTRES                       ; 5B X

wEventFlags:: ; d747
    ds 320
wMissableObjectFlags:: ; d5a6
; bit array of missable objects. set = removed
    ds 32

Articuno (flag 0x9DA): https://github.com/pret/pokered/blob/676a35f76f93dfe18678a832fa63d8b684c34c45/constants/event_constants.asm#L2524 Zapdos (flag 0x469): https://github.com/pret/pokered/blob/676a35f76f93dfe18678a832fa63d8b684c34c45/constants/event_constants.asm#L1131 Moltres (flag 0x53E): https://github.com/pret/pokered/blob/676a35f76f93dfe18678a832fa63d8b684c34c45/constants/event_constants.asm#L1344

            FlagArticuno = new FlagPairG1(0x9DA, 0xE3);
            FlagZapdos = new FlagPairG1(0x469, 0x55);
            FlagMoltres = new FlagPairG1(0x53E, 0x5B);

Respawn Cheats

Articuno  
010082D8  
0100D3D5  

Zapdos  
0100D4D7  
0100B0D5  

Moltres  
0100EED7  
0100B1D5 

Respawn cheats are little-endian offsets (need to flip them to get the RAM offset); they write 0 to the Event Flag (overwriting a bunch more than needed). Same for the object flags.

kwsch commented 4 years ago

Script to compare save files:

var p1 = @"D:\respawn\before.sav";
var p2 = @"D:\respawn\leave.sav";

var s1 = new SAV1(File.ReadAllBytes(p1));
var s2 = new SAV1(File.ReadAllBytes(p2));

var ef1 = s1.EventFlags;
var ef2 = s2.EventFlags;
var es1 = s1.EventSpawnFlags;
var es2 = s2.EventSpawnFlags;

if (ef1.SequenceEqual(ef2))
    Console.WriteLine("Flags same");
else
for (int i = 0; i < ef1.Length; i++)
    if (ef1[i] != ef2[i])
        Console.WriteLine($"{i:X}: {ef1[i]} -> {ef2[i]}");

if (es1.SequenceEqual(es2))
    Console.WriteLine("Spawn same");
else
for (int i = 0; i < es1.Length; i++)
    if (es1[i] != es2[i])
        Console.WriteLine($"{i:X}: {es1[i]} -> {es2[i]}");