diff --git a/Source/Contents/SimpleStringMgr.cpp b/Source/Contents/SimpleStringMgr.cpp index ec56305c..a029201d 100644 --- a/Source/Contents/SimpleStringMgr.cpp +++ b/Source/Contents/SimpleStringMgr.cpp @@ -1,10 +1,16 @@ #include "Contents/SimpleStringMgr.h" +#include "File/CommonObject.h" +#include "Utility/Text/StringUtil.h" #include +#include // GLOBAL: gl_24840 CSimpleStringMgr* g_simpleStringMgr = nullptr; +// GLOBAL: gl_24863 +static CCommonObject g_simpleStringObject; + // OFFSET: 0x007A96A0 // FUNCTION: fn_09077 void CSimpleStringMgr::Destroy() { @@ -27,10 +33,65 @@ const char* CSimpleStringMgr::GetString(const char* key) { return nullptr; } - auto entry = table->second.find(std::string(key)); + auto entry = table->second.find(std::string(key, std::strlen(key))); if (entry == table->second.end()) { return nullptr; } return entry->second.c_str(); } + +// OFFSET: 0x007A9780 +std::vector CSimpleStringMgr::TransformFields(const std::vector& fields) { + std::vector result; + result.reserve(fields.size()); + for (std::string field : fields) { + if (field.empty()) { + field = "NO MSG"; + } else { + ReplaceAll(field, "\\r", "\r"); + ReplaceAll(field, "\\n", "\n"); + ReplaceAll(field, "\\t", "\t"); + ReplaceAll(field, "\\'", "'"); + ReplaceAll(field, "\\\"", "\""); + ReplaceAll(field, "\\\\", "\\"); + } + result.push_back(std::move(field)); + } + return result; +} + +// OFFSET: 0x007AA270 +void CSimpleStringMgr::Init() { + this->LoadCsv("simplemsg\\msg_emotion.csv", + [this](const std::vector& fields) { return this->TransformFields(fields); }, + [this](const std::vector& fields, std::any context) { + if (static_cast(fields.size()) >= 2) { + this->AddString(std::any_cast(context), fields.front(), fields.back()); + } + }, + STR_TYPE_EMOTION); +} + +// OFFSET: 0x007AA360 +void CSimpleStringMgr::LoadCsv(const char* name, std::function(std::vector&)> transform, + std::function&, std::any)> insert, std::any context) { + g_simpleStringObject.LoadCsv(name, transform, insert, context); +} + +// OFFSET: 0x007AA4A0 +// FUNCTION: fn_09082 +void CSimpleStringMgr::AddString(STR_TYPE type, const char* key, const char* value) { + if (IsNullOrEmpty(key) || IsNullOrEmpty(value)) { + return; + } + + auto table = this->m_tables.find(type); + if (table == this->m_tables.end()) { + std::unordered_map entries; + entries.emplace(key, value); + this->m_tables.emplace(type, std::move(entries)); + } else { + table->second.emplace(std::string(key), value); + } +} diff --git a/Source/Contents/SimpleStringMgr.h b/Source/Contents/SimpleStringMgr.h index 3382a00c..c1d636c0 100644 --- a/Source/Contents/SimpleStringMgr.h +++ b/Source/Contents/SimpleStringMgr.h @@ -1,9 +1,12 @@ #ifndef RAGNAROK_SOURCE_CONTENTS_SIMPLESTRINGMGR_H #define RAGNAROK_SOURCE_CONTENTS_SIMPLESTRINGMGR_H +#include #include +#include #include #include +#include // VTABLE: vt_00755 class CSimpleStringMgr { @@ -22,6 +25,11 @@ public: } static void Destroy(); + void Init(); + void LoadCsv(const char* name, std::function(std::vector&)> transform, + std::function&, std::any)> insert, std::any context); + std::vector TransformFields(const std::vector& fields); + void AddString(STR_TYPE type, const char* key, const char* value); const char* GetString(const char* key); /* 0004 */ bool m_initialized;