Pkhex: HGSS save issue

Created on 11 Feb 2020  路  10Comments  路  Source: kwsch/PKHeX

Describe the bug
Hard to describe with just one line for title, but I've been having an issue from time to time with HGSS and narrowed it down to PKHeX likely being the culprit. What happens is, after editing something in PKHeX (usually something in the PC), the save file loads and plays just fine, but after saving in-game and turning off the game/resetting, the game usually gives a corrupted save file error the next time you try to load the save file again.

Saving multiple times can avoid the problem, but not always. I'm not sure what causes this inconsistency, but I've had it earlier where the error still happened even after saving four times, yet sometimes simply saving twice avoids it. Either way, after the error happens, you can load the previous save file, and after saving again once or twice (you get the "Saving a lot of data..." message), the game fixes itself, and the error doesn't occurs again (until you edit it again in PKHeX, that is.)

Doesn't seem to affect DPPt, only HGSS. Happens the same way on both emu and real hardware (flashcart.) Not sure about retail carts, I guess I could check, but I doubt it would really make a difference given that saving normally works just fine, as long as I didn't edit the save in PKHeX. I also give it 5-10 seconds after saving when on emu or flashcart, before I reset or shut off the game, just in case it needed more time to finish writing to the .sav or something. So I doubt that would be the problem.

To Reproduce
Steps to reproduce the behavior:

  1. Load save file in PKHeX
  2. Edit stuff in the PC
  3. Save the file
  4. Load the save in-game
  5. Save
  6. Soft-reset, or close and re-open the game
  7. Save file is corrupted

Expected behavior
Being able to use the save file and save in-game after editing in PKHeX, without it resulting in a corrupted save error.

Screenshots
https://gfycat.com/insignificantseveralcirriped

Additional context
Here's a save where it happens, in case you aren't able to reproduce (there are cases where the error might not happen, I don't know the details though.) Just have to load it and save, then soft-reset once it's done saving.
Pok茅mon - HeartGold Version (USA).zip

bug

All 10 comments

Before saving: Checksums valid.
After saving: Large block checksum is invalid
Reloaded after dismissing "corrupt", and saved: Checksums valid.

Needs more investigation, but PKHeX is able to recognize something is afoot too 馃槙

Re-saving the original file in PokeGen doesn't fix any issues, still causes corruption when saved in-game and reloaded.

Gonna assume there's some spooky undocumented behavior, which can't really be resolved now (unless there's a ton of investigation).

I think PKHeX may not be handling box stuff properly for Gen 4 as a whole... and I wonder if this could be related to our problem here.

Take this Platinum save file, for example... load it in PKHeX latest stable, clear the first box and save it. Then load the edited save back back up. It ends up loading the backup storage block instead of the current one. Same thing happens on DP and HGSS, too.

I'm assuming that it's something related to the currently-active save block detection. PKHeX bases it off the save-counter that keeps track of how many times the block has been saved; I don't know how the game would be picking the lower-counter block :\

The game picks the correct one, PKHeX doesn't.

People have been complaining for a while from time to time about box edits in Gen 4 not sticking, this may be the culprit.

clear the first box

https://github.com/kwsch/PKHeX/blame/afd4ff25a5a9c677a8ee263bce4f7fb7b99fd1da/PKHeX.Core/Saves/SAV4.cs#L159

            if (IsRangeAll(0x00000, 10, 0) || IsRangeAll(0x00000, 10, 0xFF))
                return 1;

What is an empty-encrypted-pk4? First 10 bytes are zeroes. An empty b1s1 will cause the logic to use the latter block!

Hi, I see that this issue is closed, but I got this issue yesterday, so I just wanted to share a workaround that I discovered. Upon getting the corrupted save message, close the game, open the save file in PKHeX, and move a party Pok茅mon to a different party slot to fix the checksum and allow you back into the game. Export the save back to the game, then open the game. Once you're in the game, you'll need to use the PC in game to move a Pok茅mon around, which seems to permanently undo whatever PKHeX is doing wrong here (until you use PKHeX to change something in boxes again, then you'll need to repeat this workaround).

@md842 this issue has been fixed since the latest release a few weeks ago. The latest download does not have the issue you describe since the block detection logic has been corrected in the linked commit.

I see, sorry about that! Turns out my copy is indeed not the latest version.

Just got the same issue today, I'm using PKHex version 20201031

Was this page helpful?
0 / 5 - 0 ratings

Related issues

natubis picture natubis  路  3Comments

B1gM1k3 picture B1gM1k3  路  4Comments

ijuintekka picture ijuintekka  路  4Comments

EmilyLove26 picture EmilyLove26  路  3Comments

Monkfishy picture Monkfishy  路  4Comments