From 81c049e192a5c4a1bb917e8ab3634dd3effce3ef Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 25 Dec 2015 23:17:29 +0100 Subject: [PATCH] Localization stuff. --- iw4/Components/Loader.cpp | 1 + iw4/Components/Loader.hpp | 1 + iw4/Components/Localization.cpp | 40 +++++++++++++++++++++++++++++++++ iw4/Components/Localization.hpp | 16 +++++++++++++ iw4/Game/Structs.hpp | 7 ++++++ iw4/iw4.vcxproj | 2 ++ iw4/iw4.vcxproj.filters | 6 +++++ 7 files changed, 73 insertions(+) create mode 100644 iw4/Components/Localization.cpp create mode 100644 iw4/Components/Localization.hpp diff --git a/iw4/Components/Loader.cpp b/iw4/Components/Loader.cpp index 6e7a83af..5ca42f3a 100644 --- a/iw4/Components/Loader.cpp +++ b/iw4/Components/Loader.cpp @@ -22,6 +22,7 @@ namespace Components Loader::Register(new FileSystem()); Loader::Register(new QuickPatch()); Loader::Register(new AssetHandler()); + Loader::Register(new Localization()); Loader::Register(new MusicalTalent()); } diff --git a/iw4/Components/Loader.hpp b/iw4/Components/Loader.hpp index 57220501..be8dcbc7 100644 --- a/iw4/Components/Loader.hpp +++ b/iw4/Components/Loader.hpp @@ -36,4 +36,5 @@ namespace Components #include "FileSystem.hpp" #include "QuickPatch.hpp" #include "AssetHandler.hpp" +#include "Localization.hpp" #include "MusicalTalent.hpp" diff --git a/iw4/Components/Localization.cpp b/iw4/Components/Localization.cpp new file mode 100644 index 00000000..94c45279 --- /dev/null +++ b/iw4/Components/Localization.cpp @@ -0,0 +1,40 @@ +#include "..\STDInclude.hpp" + +namespace Components +{ + std::map Localization::LocalizeMap; + + void Localization::Set(const char* key, const char* value) + { + Localization::LocalizeMap[key] = value; + } + + const char* Localization::Get(const char* key) + { + if (Localization::LocalizeMap.find(key) != Localization::LocalizeMap.end()) + { + return Localization::LocalizeMap[key].data(); + } + + Game::localizedEntry_s* entry = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_LOCALIZE, key).localize; + + if (entry) + { + return entry->value; + } + + return key; + } + + Localization::Localization() + { + Utils::Hook(0x629B90, Localization::Get, HOOK_JUMP).Install()->Quick(); + + Localization::Set("MENU_MULTIPLAYER_CAPS", "^5Fotze"); + } + + Localization::~Localization() + { + Localization::LocalizeMap.clear(); + } +} diff --git a/iw4/Components/Localization.hpp b/iw4/Components/Localization.hpp new file mode 100644 index 00000000..4f199c73 --- /dev/null +++ b/iw4/Components/Localization.hpp @@ -0,0 +1,16 @@ +namespace Components +{ + class Localization : public Component + { + public: + Localization(); + ~Localization(); + const char* GetName() { return "Localization"; }; + + static void Set(const char* key, const char* value); + static const char* Get(const char* key); + + private: + static std::map LocalizeMap; + }; +} diff --git a/iw4/Game/Structs.hpp b/iw4/Game/Structs.hpp index 4747a051..1f5a57f8 100644 --- a/iw4/Game/Structs.hpp +++ b/iw4/Game/Structs.hpp @@ -852,6 +852,12 @@ namespace Game UILocalVarContext localVars; }; + struct localizedEntry_s + { + const char* value; + const char* name; + }; + union XAssetHeader { void *data; @@ -859,5 +865,6 @@ namespace Game menuDef_t *menu; Material *material; snd_alias_list_t *aliasList; + localizedEntry_s *localize; }; } diff --git a/iw4/iw4.vcxproj b/iw4/iw4.vcxproj index ef23a1de..2bb8f626 100644 --- a/iw4/iw4.vcxproj +++ b/iw4/iw4.vcxproj @@ -59,6 +59,7 @@ + @@ -93,6 +94,7 @@ + diff --git a/iw4/iw4.vcxproj.filters b/iw4/iw4.vcxproj.filters index a48432ab..c17b0a50 100644 --- a/iw4/iw4.vcxproj.filters +++ b/iw4/iw4.vcxproj.filters @@ -122,6 +122,9 @@ Source\Components\Modules + + Source\Components\Modules + @@ -220,5 +223,8 @@ Source\Components\Modules + + Source\Components\Modules + \ No newline at end of file