diff --git a/tools/decap/decap.cpp b/tools/decap/decap.cpp index 5d943ff..cba51f9 100644 --- a/tools/decap/decap.cpp +++ b/tools/decap/decap.cpp @@ -36,14 +36,16 @@ int main(int argc, char *argv[]) f.ProcessStringPointerArray(0x1e79b0, 2, 8); // Boy/Girl f.ProcessStringPointerArray(0x1e79c0, 5, 8); // Male preset names f.ProcessStringPointerArray(0x1e79e8, 5, 8); // Female preset names - f.ProcessStringPointerArray(0x376d04, 6); // Stat labels - f.ProcessStringPointerArray(0x3c5564 + 20, 349, 44); // Item descriptions f.ProcessStringPointerArray(0x3c1004, 25); // Nature names f.ProcessStringPointerArray(0x3c1068, 8); // Summary Screen headers f.ProcessStringPointerArray(0x39f494, 10, 8); // Party menu options f.ProcessStringPointerArray(0x376d24, 10, 8); // Start menu options - f.ProcessStringPointerArray(0x1fa110, 78); // Ability descriptions f.ProcessStringPointerArray(0x3e73c4 + 4, 88, 8); // Map names + + f.SetWhitelist(&WhitelistEntries); + f.ProcessStringPointerArray(0x376d04, 6); // Stat labels + f.ProcessStringPointerArray(0x3c5564 + 20, 349, 44); // Item descriptions + f.ProcessStringPointerArray(0x1fa110, 78); // Ability descriptions f.ProcessStringPointerArray(0x3c09d8, 354); // Move descriptions f.Save(argv[2]); diff --git a/tools/decap/file.cpp b/tools/decap/file.cpp index 51fbfa4..35714ee 100644 --- a/tools/decap/file.cpp +++ b/tools/decap/file.cpp @@ -36,30 +36,22 @@ void File::Save(const std::string &filename) fclose(fp); } -struct Word -{ - unsigned char text[10]; - unsigned int len; -}; - -static const Word sWhitelistEntries[] = { +const std::vector WhitelistEntries = { { {0xC2, 0xC7}, 2 }, // HM { {0xCE, 0xC7}, 2 }, // TM { {0xC2, 0xCA}, 2 }, // HP { {0xCA, 0xCA}, 2 }, // PP }; -bool CheckIfWhitelisted(unsigned char *buffer, unsigned int idx) +unsigned int CheckIfWhitelisted(const std::vector& whitelist, unsigned char *buffer, unsigned int idx) { - for (int i = 0; i < (int)(sizeof(sWhitelistEntries) / sizeof(*sWhitelistEntries)); ++i) + for (const auto &word : WhitelistEntries) { - if (memcmp(&buffer[idx], sWhitelistEntries[i].text, sWhitelistEntries[i].len) == 0) - { - return true; - } + if (memcmp(&buffer[idx], word.text, word.len) == 0) + return word.len; } - return false; + return 0; } // 0x0 is space @@ -81,8 +73,12 @@ void File::ProcessString(int location, int max_size) int idx = location + j; if (idx > m_Size) FATAL_ERROR("Index %d is greater than file size (%ld)\n", idx, m_Size); - if (CheckIfWhitelisted(m_Buffer, idx)) + unsigned int whitelistLength; + if (m_Whitelist != nullptr && (whitelistLength = CheckIfWhitelisted(*m_Whitelist, m_Buffer, idx)) > 0) + { + j += whitelistLength - 1; continue; + } unsigned char c = m_Buffer[idx]; diff --git a/tools/decap/file.h b/tools/decap/file.h index e470f20..6c429d1 100644 --- a/tools/decap/file.h +++ b/tools/decap/file.h @@ -1,6 +1,15 @@ #pragma once #include +#include + +struct Word +{ + unsigned char text[10]; + unsigned int len; +}; + +extern const std::vector WhitelistEntries; class File { @@ -14,7 +23,9 @@ class File void ProcessStringArray(int location, int size, int count); void ProcessStringArray(int location, int size, int count, int stride); void ProcessStringPointerArray(int location, int count, int stride = 4); + inline void SetWhitelist(const std::vector *whitelist) { m_Whitelist = whitelist; } private: unsigned char *m_Buffer; long m_Pos, m_Size; + const std::vector *m_Whitelist; }; \ No newline at end of file