From 8037096789ace0c09e0bd7f8fe8a49d2b8a4590f Mon Sep 17 00:00:00 2001 From: Poggu Date: Wed, 9 Oct 2024 00:35:49 +0200 Subject: [PATCH] add a flat file containing strings to ignore --- src/main/dumpers/concommands/concommands.cpp | 30 ++++++++++++++++++-- src/main/dumpers/schemas/schemas.cpp | 4 +++ src/main/globalvariables.h | 2 ++ src/main/main.cpp | 2 ++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/main/dumpers/concommands/concommands.cpp b/src/main/dumpers/concommands/concommands.cpp index f5c3e0c..2e27455 100644 --- a/src/main/dumpers/concommands/concommands.cpp +++ b/src/main/dumpers/concommands/concommands.cpp @@ -212,7 +212,8 @@ void WriteValueLine(ConVar* pCvar, std::ofstream& stream) void FixNewlineTabbing(std::string& str) { auto it = str.begin(); - while ((it = std::find(it, str.end(), '\n')) != str.end()) { + while ((it = std::find(it, str.end(), '\n')) != str.end()) + { if (it + 1 == str.end() || *(it + 1) != '\t') it = str.insert(it + 1, '\t') + 1; else @@ -227,6 +228,25 @@ void FixNewlineTabbing(std::string& str) str.pop_back(); } +std::string EscapeDescription(std::string str) +{ + for (auto it = str.begin(); it != str.end(); it++) { + if (*it == '\n') + { + *it = '\\'; + it = str.insert(it + 1, 'n'); + } + else if (*it == '\t') + { + *it = '\\'; + it = str.insert(it + 1, 't'); + } + } + + return str; +} + + void DumpConVars() { ConVarHandle hCvarHandle; @@ -261,14 +281,16 @@ void DumpConVars() if (cvar->m_pszHelpString[0]) { helpString = cvar->m_pszHelpString; + Globals::stringsIgnoreStream << EscapeDescription(helpString) << "\n"; FixNewlineTabbing(helpString); } output << cvar->m_pszName; WriteValueLine(cvar, output); output << "\n\t" << helpString; - output << "\n" << std::endl; + + Globals::stringsIgnoreStream << cvar->m_pszName << "\n"; } } @@ -308,14 +330,16 @@ void DumpCommands() if (command->m_pszHelpString[0]) { helpString = command->m_pszHelpString; + Globals::stringsIgnoreStream << EscapeDescription(helpString) << "\n"; FixNewlineTabbing(helpString); } output << command->m_pszName << " ("; WriteFlags(command->m_nFlags, output); output << ")\n\t" << helpString; - output << "\n" << std::endl; + + Globals::stringsIgnoreStream << command->m_pszName << "\n"; } } diff --git a/src/main/dumpers/schemas/schemas.cpp b/src/main/dumpers/schemas/schemas.cpp index d6fd02e..d26c1ee 100644 --- a/src/main/dumpers/schemas/schemas.cpp +++ b/src/main/dumpers/schemas/schemas.cpp @@ -54,6 +54,7 @@ void DumpClasses(CSchemaSystemTypeScope* typeScope, std::filesystem::path schema std::ofstream output((schemaPath / classInfo->m_pszProjectName / sanitizedFileName).replace_extension(".h")); output << "class " << classInfo->m_pszName; + Globals::stringsIgnoreStream << classInfo->m_pszName << "\n"; if (classInfo->m_nBaseClassCount > 0) output << " : public " << classInfo->m_pBaseClasses[0].m_pClass->m_pszName; @@ -65,6 +66,7 @@ void DumpClasses(CSchemaSystemTypeScope* typeScope, std::filesystem::path schema const auto& field = classInfo->m_pFields[k]; output << "\t" << field.m_pType->m_sTypeName.String() << " " << field.m_pszName << ";\n"; + Globals::stringsIgnoreStream << field.m_pszName << "\n"; } output << "};\n"; @@ -95,6 +97,7 @@ void DumpEnums(CSchemaSystemTypeScope* typeScope, std::filesystem::path schemaPa std::ofstream output((schemaPath / enumInfo->m_pszProjectName / sanitizedFileName).replace_extension(".h")); output << "enum " << enumInfo->m_pszName << " : "; + Globals::stringsIgnoreStream << enumInfo->m_pszName << "\n"; switch (enumInfo->m_nAlignment) { @@ -121,6 +124,7 @@ void DumpEnums(CSchemaSystemTypeScope* typeScope, std::filesystem::path schemaPa const auto& field = enumInfo->m_pEnumerators[k]; output << "\t" << field.m_pszName << " = " << field.m_nValue << ",\n"; + Globals::stringsIgnoreStream << field.m_pszName << "\n"; } output << "};\n"; diff --git a/src/main/globalvariables.h b/src/main/globalvariables.h index 67c5cb4..ac7d0eb 100644 --- a/src/main/globalvariables.h +++ b/src/main/globalvariables.h @@ -20,10 +20,12 @@ #include #include +#include namespace Globals { inline std::string modName; inline std::filesystem::path outputPath; + inline std::ofstream stringsIgnoreStream; } // namespace Interfaces \ No newline at end of file diff --git a/src/main/main.cpp b/src/main/main.cpp index 62cca8f..976cbae 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -48,6 +48,8 @@ int main(int argc, char** argv) return 0; } + Globals::stringsIgnoreStream = std::ofstream(Globals::outputPath / ".stringsignore"); + InitializeCoreModules(); InitializeAppSystems();