Make the parser more tolerant because trying to parse these corrupted savegames triggers an assert in Scene_Load in EasyRPG, breaking the scene completely.
MODIFY
src/ldb_eventcommand.cpp
src/ldb_eventcommand.cpp
@@ -139,6 +139,7 @@ void RawStruct<std::vector<RPG::EventCommand> >::ReadLcf(
// Has no size information. Is terminated by 4 times 0x00.
unsigned long startpos = stream.Tell();
unsigned long endpos = startpos + length;
+
for (;;) {
uint8_t ch;
stream.Read(ch);
@@ -146,12 +147,34 @@ void RawStruct<std::vector<RPG::EventCommand> >::ReadLcf(
stream.Seek(3, LcfReader::FromCurrent);
break;
}
+
+ if (stream.Tell() >= endpos) {
+ stream.Seek(endpos, LcfReader::FromStart);
+ fprintf(stderr, "Event command corrupted at %d\n", stream.Tell());
+ for (;;) {
+ // Try finding the real end of the event command (4 0-bytes)
+ int i = 0;
+ for (; i < 4; ++i) {
+ stream.Read(ch);
+
+ if (ch != 0) {
+ break;
+ }
+ }
+
+ if (i == 4 || stream.Eof()) {
+ break;
+ }
+ }
+
+ break;
+ }
+
stream.Ungetch(ch);
RPG::EventCommand command;
RawStruct<RPG::EventCommand>::ReadLcf(command, stream, 0);
event_commands.push_back(command);
}
- assert(stream.Tell() == endpos);
}
void RawStruct<std::vector<RPG::EventCommand> >::WriteLcf(const std::vector<RPG::EventCommand>& event_commands, LcfWriter& stream) {

MODIFY
src/reader_lcf.cpp
src/reader_lcf.cpp
@@ -56,7 +56,9 @@ void LcfReader::Read(void *ptr, size_t size, size_t nmemb) {
#ifdef NDEBUG
Read0(ptr, size, nmemb);
#else
- assert(Read0(ptr, size, nmemb) == nmemb);
+ if (Read0(ptr, size, nmemb) != nmemb) {
+ fprintf(stderr, "Read error at %d. The file is probably corrupted\n", Tell());
+ }
#endif
}

Make the parser more tolerant because trying to parse these corrupted savegames triggers an assert in Scene_Load in EasyRPG, breaking the scene completely.