Always dump the bytes when an unknown chunk is skipped. An unknown chunk is always a bug.
MODIFY
src/lcf/reader_lcf.h
src/lcf/reader_lcf.h
#include "lcf/reader_util.h"
#include "lcf/encoder.h"
-/*
- * Calls SkipDebug() instead of Skip() for debug builds.
- */
-#ifdef _DEBUG
- #define Skip(x) SkipDebug(x, __FILE__)
-#endif
-
namespace lcf {
/**
@@ -189,17 +182,6 @@ public:
*/
int Peek();
-#ifdef _DEBUG
- /**
- * The skip-function for debug builds.
- * Same as Skip() but also dumps the content of the
- * skipped chunk to stderr.
- *
- * @param chunk_info chunk that will be skipped.
- * @param srclife name of the calling cpp-file.
- */
- void SkipDebug(const struct LcfReader::Chunk& chunk_info, const char* srcfile);
-#else
/**
* Skips a chunk (seeks chunk_info.length bytes from
* the current stream position).
@@ -207,9 +189,9 @@ public:
* skipped chunk to stderr.
*
* @param chunk_info chunk that will be skipped.
+ * @param where name of the caller that caused the skip, for finding unknown chunks
*/
- void Skip(const struct LcfReader::Chunk& chunk_info);
-#endif
+ void Skip(const struct LcfReader::Chunk& chunk_info, const char* where);
/**
* Encodes a string to UTF-8 using the set encoding

MODIFY
src/ldb_equipment.cpp
src/ldb_equipment.cpp
@@ -33,7 +33,7 @@ void RawStruct<rpg::Equipment>::ReadLcf(rpg::Equipment& ref, LcfReader& stream,
chunk_info.ID = 0x33;
chunk_info.length = length;
- stream.Skip(chunk_info);
+ stream.Skip(chunk_info, "Equipment");
return;
}

MODIFY
src/reader_lcf.cpp
src/reader_lcf.cpp
@@ -258,22 +258,10 @@ int LcfReader::Peek() {
return stream.peek();
}
-#ifdef _DEBUG
-void LcfReader::SkipDebug(const struct LcfReader::Chunk& chunk_info, const char* srcfile) {
- // Dump the Chunk Data in Debug Mode
-#ifdef _WIN32
- const char* srcfilename = strrchr(srcfile, '\\');
-#else
- const char* srcfilename = strrchr(srcfile, '/');
-#endif
- if (srcfilename == NULL) {
- srcfilename = srcfile;
- } else {
- srcfilename++;
- }
+void LcfReader::Skip(const struct LcfReader::Chunk& chunk_info, const char* where) {
fprintf(stderr, "Skipped Chunk %02X (%" PRIu32 " byte) in lcf at %" PRIX32 " (%s)\n",
- chunk_info.ID, chunk_info.length, Tell(),
- srcfilename);
+ chunk_info.ID, chunk_info.length, Tell(), where);
+
for (uint32_t i = 0; i < chunk_info.length; ++i) {
uint8_t byte;
LcfReader::Read(byte);
@@ -287,11 +275,6 @@ void LcfReader::SkipDebug(const struct LcfReader::Chunk& chunk_info, const char*
}
fprintf(stderr, "\n");
}
-#else
-void LcfReader::Skip(const struct LcfReader::Chunk& chunk_info) {
- Seek((size_t)chunk_info.length, FromCurrent);
-}
-#endif
void LcfReader::SetError(const char* fmt, ...) {
va_list args;

MODIFY
src/reader_struct_impl.h
src/reader_struct_impl.h
@@ -78,13 +78,13 @@ void Struct<S>::ReadLcf(S& obj, LcfReader& stream) {
it->second->ReadLcf(obj, stream, chunk_info.length);
const uint32_t bytes_read = stream.Tell() - off;
if (bytes_read != chunk_info.length) {
- fprintf(stderr, "Warning: Corrupted Chunk 0x%02" PRIx32 " (size: %" PRIu32 ", pos: 0x%" PRIx32 "): %s : Read %" PRIu32 " bytes! Reseting...\n",
- chunk_info.ID, chunk_info.length, off, it->second->name, bytes_read);
+ fprintf(stderr, "%s: Corrupted Chunk 0x%02" PRIx32 " (size: %" PRIu32 ", pos: 0x%" PRIx32 "): %s : Read %" PRIu32 " bytes! Reseting...\n",
+ Struct<S>::name, chunk_info.ID, chunk_info.length, off, it->second->name, bytes_read);
stream.Seek(off + chunk_info.length);
}
}
else {
- stream.Skip(chunk_info);
+ stream.Skip(chunk_info, Struct<S>::name);
}
}
}

Always dump the bytes when an unknown chunk is skipped. An unknown chunk is always a bug.