h1-mod/src/client/component/localized_strings.cpp

52 lines
1.3 KiB
C++
Raw Normal View History

2022-02-03 14:05:24 -05:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "localized_strings.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>
2022-02-17 00:11:35 -05:00
#include <utils/concurrency.hpp>
2022-02-03 14:05:24 -05:00
#include "game/game.hpp"
namespace localized_strings
{
namespace
{
utils::hook::detour seh_string_ed_get_string_hook;
2022-02-17 00:11:35 -05:00
using localized_map = std::unordered_map<std::string, std::string>;
utils::concurrency::container<localized_map> localized_overrides;
2022-02-03 14:05:24 -05:00
const char* seh_string_ed_get_string(const char* reference)
{
2022-02-17 00:11:35 -05:00
return localized_overrides.access<const char*>([&](const localized_map& map)
2022-02-23 15:23:00 -05:00
{
const auto entry = map.find(reference);
if (entry != map.end())
2022-02-17 00:11:35 -05:00
{
2022-02-23 15:23:00 -05:00
return utils::string::va("%s", entry->second.data());
}
2022-02-17 00:11:35 -05:00
2022-02-23 15:23:00 -05:00
return seh_string_ed_get_string_hook.invoke<const char*>(reference);
});
2022-02-03 14:05:24 -05:00
}
}
void override(const std::string& key, const std::string& value)
{
2022-02-17 00:11:35 -05:00
localized_overrides.access([&](localized_map& map)
2022-02-23 15:23:00 -05:00
{
map[key] = value;
});
2022-02-03 14:05:24 -05:00
}
class component final : public component_interface
{
public:
void post_unpack() override
{
// Change some localized strings
seh_string_ed_get_string_hook.create(SELECT_VALUE(0x3E6CE0_b, 0x585DA0_b), &seh_string_ed_get_string);
2022-02-03 14:05:24 -05:00
}
};
}
2022-05-18 18:32:00 -04:00
REGISTER_COMPONENT(localized_strings::component)