rodecomp/Source/Contents/SimpleStringMgr.cpp
ragnarok-clanker 76aae30e2a Decompile 4 functions in Source/Contents/SimpleStringMgr.cpp, Source/Contents/SimpleStringMgr.h
Batch #3698 by ragnarok-clanker: 0 byte-identical, 4 confirmed by peer review.

- fn_09078 CSimpleStringMgr::TransformFields: logic confirmed by peer review (annotation added to existing code)
- fn_09079 CSimpleStringMgr::GetString: logic confirmed by peer review (already on main)
- fn_09080 CSimpleStringMgr::Init: logic confirmed by peer review (annotation added to existing code)
- fn_09081 CSimpleStringMgr::LoadCsv: logic confirmed by peer review (annotation added to existing code)

Peer-reviewed-by: eAthena, Yommy, Gravity
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-10-30 00:07:33 +00:00

100 lines
2.9 KiB
C++

#include "Contents/SimpleStringMgr.h"
#include "File/CommonObject.h"
#include "Utility/Text/StringUtil.h"
#include <cstring>
#include <utility>
// GLOBAL: gl_24840
CSimpleStringMgr* g_simpleStringMgr = nullptr;
// GLOBAL: gl_24863
static CCommonObject g_simpleStringObject;
// OFFSET: 0x007A96A0
// FUNCTION: fn_09077
void CSimpleStringMgr::Destroy() {
if (g_simpleStringMgr) {
delete g_simpleStringMgr;
g_simpleStringMgr = nullptr;
}
}
// OFFSET: 0x007A9DA0
// FUNCTION: fn_09079
const char* CSimpleStringMgr::GetString(const char* key) {
STR_TYPE type = STR_TYPE_EMOTION;
if (key == nullptr || std::strlen(key) == 0) {
return nullptr;
}
auto table = this->m_tables.find(type);
if (table == this->m_tables.end()) {
return nullptr;
}
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
// FUNCTION: fn_09078
std::vector<std::string> CSimpleStringMgr::TransformFields(const std::vector<std::string>& fields) {
std::vector<std::string> 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
// FUNCTION: fn_09080
void CSimpleStringMgr::Init() {
this->LoadCsv("simplemsg\\msg_emotion.csv",
[this](const std::vector<std::string>& fields) { return this->TransformFields(fields); },
[this](const std::vector<const char*>& fields, std::any context) {
if (static_cast<int>(fields.size()) >= 2) {
this->AddString(std::any_cast<STR_TYPE>(context), fields.front(), fields.back());
}
},
STR_TYPE_EMOTION);
}
// OFFSET: 0x007AA360
// FUNCTION: fn_09081
void CSimpleStringMgr::LoadCsv(const char* name, std::function<std::vector<std::string>(std::vector<std::string>&)> transform,
std::function<void(std::vector<const char*>&, 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<std::string, std::string> entries;
entries.emplace(key, value);
this->m_tables.emplace(type, std::move(entries));
} else {
table->second.emplace(std::string(key), value);
}
}