MaKiPL / OpenVIII-monogame

Open source Final Fantasy VIII engine implementation in C# working on Windows and Linux (Android and iOS planned too!) [Monogame]
MIT License
630 stars 58 forks source link

Loading all saves at start and not checking each read for errors. #151

Open Sebanisu opened 4 years ago

Sebanisu commented 4 years ago

It was pointed out that a save could be corrupt. Causing crashes.

Two ways to avoid is to verify the reads for each variable. Or put the whole thing in try catch block.

Though might be good to use a try catch block. I worry about it masking problems that exist in the code.

We could also check each read making sure we aren't past the max length and that the value read is valid for each one. Max length could be checked up front. calculating the total bytes it should be and making sure at first the file is the right length. Though everything is lzss compressed which gives us the length the file should be after decompressing.

Loading all saves isn't required. We can move it to the load menu. Could just read the part we need for the menu, like the real game does even.

maybe related: https://github.com/MaKiPL/OpenVIII/issues/61

Sebanisu commented 4 years ago

I think loading of saves on demand will be useful as we won't need to clone the save into memory if we are reading from the drive Everytime we goto load. We can just assign the loaded save into memory and let the garage collector eat the rest. Probably will need to read only enough data to display what is on the save Lord screen. Though we still need to read the entire file because it is compressed. Maybe we can add a cutoff value to lzs. Saying we only need X bytes stop decompressing if past that point. Maybe I'll do this next week.