From 1cd31494d5d85f6acbbe4e9e00628e2c24b6a8ac Mon Sep 17 00:00:00 2001 From: m Date: Sun, 29 Aug 2021 13:50:23 -0500 Subject: [PATCH] localized string overriding --- src/component/localized_strings.cpp | 54 +++++++++++++++++++++++++++++ src/component/localized_strings.hpp | 6 ++++ 2 files changed, 60 insertions(+) create mode 100644 src/component/localized_strings.cpp create mode 100644 src/component/localized_strings.hpp diff --git a/src/component/localized_strings.cpp b/src/component/localized_strings.cpp new file mode 100644 index 00000000..01e2253d --- /dev/null +++ b/src/component/localized_strings.cpp @@ -0,0 +1,54 @@ +#include +#include "loader/component_loader.hpp" +#include "localized_strings.hpp" +#include +#include +#include +#include "game/game.hpp" + +#include "game_console.hpp" + +namespace localized_strings +{ + namespace + { + utils::hook::detour seh_string_ed_get_string_hook; + + using localized_map = std::unordered_map; + utils::concurrency::container localized_overrides; + + const char* seh_string_ed_get_string(const char* reference) + { + return localized_overrides.access([&](const localized_map& map) + { + const auto entry = map.find(reference); + if (entry != map.end()) + { + return utils::string::va("%s", entry->second.data()); + } + + return seh_string_ed_get_string_hook.invoke(reference); + }); + } + } + + void override(const std::string& key, const std::string& value) + { + localized_overrides.access([&](localized_map& map) + { + map[key] = value; + }); + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + // Change some localized strings + seh_string_ed_get_string_hook.create(game::base_address + 0x5E5FD0, &seh_string_ed_get_string); + } + }; +} + +REGISTER_COMPONENT(localized_strings::component) \ No newline at end of file diff --git a/src/component/localized_strings.hpp b/src/component/localized_strings.hpp new file mode 100644 index 00000000..01d15907 --- /dev/null +++ b/src/component/localized_strings.hpp @@ -0,0 +1,6 @@ +#pragma once + +namespace localized_strings +{ + void override(const std::string& key, const std::string& value); +} \ No newline at end of file