From 3ae5e7aea8887ee18e67fc07a62d5367eb612bae Mon Sep 17 00:00:00 2001 From: Edo Date: Wed, 22 Mar 2023 18:47:13 +0000 Subject: [PATCH] [Loc]: Put function here (#868) --- src/Components/Loader.cpp | 1 + src/Components/Loader.hpp | 1 - src/Components/Modules/ArenaLength.cpp | 1 + src/Components/Modules/Friends.cpp | 2 +- src/Components/Modules/Localization.cpp | 20 ++++++++++++++++++++ src/Components/Modules/Localization.hpp | 2 ++ src/Components/Modules/Maps.cpp | 3 ++- src/Components/Modules/ServerInfo.cpp | 4 ++-- src/Components/Modules/ServerList.cpp | 6 +++--- src/Components/Modules/Theatre.cpp | 4 ++-- src/Components/Modules/UIFeeder.cpp | 2 +- src/Game/Functions.cpp | 19 ------------------- src/Game/Functions.hpp | 1 - 13 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 42189495..de0f2420 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -1,6 +1,7 @@ #include #include +#include "Modules/ArenaLength.hpp" #include "Modules/Bans.hpp" #include "Modules/Bots.hpp" #include "Modules/Branding.hpp" diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 7fc7d59c..dee129b3 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -73,7 +73,6 @@ namespace Components #include "Modules/UIScript.hpp" #include "Modules/ZoneBuilder.hpp" -#include "Modules/ArenaLength.hpp" #include "Modules/AssetHandler.hpp" #include "Modules/Dedicated.hpp" #include "Modules/Events.hpp" diff --git a/src/Components/Modules/ArenaLength.cpp b/src/Components/Modules/ArenaLength.cpp index 3c0c2a93..077ee65f 100644 --- a/src/Components/Modules/ArenaLength.cpp +++ b/src/Components/Modules/ArenaLength.cpp @@ -1,4 +1,5 @@ #include +#include "ArenaLength.hpp" namespace Components { diff --git a/src/Components/Modules/Friends.cpp b/src/Components/Modules/Friends.cpp index b222ef40..900c2111 100644 --- a/src/Components/Modules/Friends.cpp +++ b/src/Components/Modules/Friends.cpp @@ -438,7 +438,7 @@ namespace Components if (!Friends::IsOnline(user.lastTime)) return "Online"; if (user.server.getType() == Game::NA_BAD) return "Playing IW4x"; if (user.serverName.empty()) return Utils::String::VA("Playing on %s", user.server.getCString()); - return Utils::String::VA("Playing %s on %s", Game::UI_LocalizeMapName(user.mapname.data()), user.serverName.data()); + return Utils::String::VA("Playing %s on %s", Localization::LocalizeMapName(user.mapname.data()), user.serverName.data()); } default: diff --git a/src/Components/Modules/Localization.cpp b/src/Components/Modules/Localization.cpp index cdf8d8d8..413203d8 100644 --- a/src/Components/Modules/Localization.cpp +++ b/src/Components/Modules/Localization.cpp @@ -1,4 +1,5 @@ #include +#include "ArenaLength.hpp" namespace Components { @@ -330,6 +331,25 @@ namespace Components return pszString; } + const char* Localization::LocalizeMapName(const char* mapName) + { + for (int i = 0; i < *Game::arenaCount; ++i) + { + if (!_stricmp(ArenaLength::NewArenas[i].mapName, mapName)) + { + auto* uiName = &ArenaLength::NewArenas[i].uiName[0]; + if ((uiName[0] == 'M' && uiName[1] == 'P') || (uiName[0] == 'P' && uiName[1] == 'A')) // MPUI/PATCH + { + return Get(uiName); + } + + return uiName; + } + } + + return mapName; + } + Localization::Localization() { SetCredits(); diff --git a/src/Components/Modules/Localization.hpp b/src/Components/Modules/Localization.hpp index c4c6951e..fa345621 100644 --- a/src/Components/Modules/Localization.hpp +++ b/src/Components/Modules/Localization.hpp @@ -14,6 +14,8 @@ namespace Components static std::optional PrefixOverride; static void ParseOutput(const std::function& callback); + static const char* LocalizeMapName(const char* mapName); + private: static std::recursive_mutex LocalizeMutex; static std::unordered_map LocalizeMap; diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index 9a2c3ae1..da0ffdbc 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -1,5 +1,6 @@ #include +#include "ArenaLength.hpp" #include "FastFiles.hpp" #include "RawFiles.hpp" #include "StartupMessages.hpp" @@ -659,7 +660,7 @@ namespace Components if (error) { Logger::Error(Game::ERR_DISCONNECT, "Missing DLC pack {} ({}) containing map {} ({}).\nPlease download it to play this map.", - pack.name, pack.index, Game::UI_LocalizeMapName(mapname.data()), mapname); + pack.name, pack.index, Localization::LocalizeMapName(mapname.data()), mapname); } return dlcIsTrue; diff --git a/src/Components/Modules/ServerInfo.cpp b/src/Components/Modules/ServerInfo.cpp index 55ef91e3..7dd1ede3 100644 --- a/src/Components/Modules/ServerInfo.cpp +++ b/src/Components/Modules/ServerInfo.cpp @@ -64,7 +64,7 @@ namespace Components Dvar::Var("uiSi_KillCam").set("@MENU_NO"); Dvar::Var("uiSi_ffType").set("@MENU_DISABLED"); Dvar::Var("uiSi_MapName").set(serverInfo->mapname); - Dvar::Var("uiSi_MapNameLoc").set(Game::UI_LocalizeMapName(serverInfo->mapname.data())); + Dvar::Var("uiSi_MapNameLoc").set(Localization::LocalizeMapName(serverInfo->mapname.data())); Dvar::Var("uiSi_GameType").set(Game::UI_LocalizeGameType(serverInfo->gametype.data())); Dvar::Var("uiSi_ModName").set(""); Dvar::Var("uiSi_aimAssist").set(serverInfo->aimassist ? "@MENU_YES" : "@MENU_NO"); @@ -261,7 +261,7 @@ namespace Components Dvar::Var("uiSi_Hardcore").set(info.get("g_hardcore") == "0" ? "@MENU_DISABLED" : "@MENU_ENABLED"); Dvar::Var("uiSi_KillCam").set(info.get("scr_game_allowkillcam") == "0" ? "@MENU_NO" : "@MENU_YES"); Dvar::Var("uiSi_MapName").set(info.get("mapname")); - Dvar::Var("uiSi_MapNameLoc").set(Game::UI_LocalizeMapName(info.get("mapname").data())); + Dvar::Var("uiSi_MapNameLoc").set(Localization::LocalizeMapName(info.get("mapname").data())); Dvar::Var("uiSi_GameType").set(Game::UI_LocalizeGameType(info.get("g_gametype").data())); Dvar::Var("uiSi_ModName").set(""); Dvar::Var("uiSi_aimAssist").set(info.get("aimAssist") == "0" ? "@MENU_DISABLED" : "@MENU_ENABLED"); diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index ba51b830..2900c1ba 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -118,13 +118,13 @@ namespace Components { if (!sorting && !Maps::CheckMapInstalled(server->mapname)) { - return Utils::String::VA("^1%s", Game::UI_LocalizeMapName(server->mapname.data())); + return Utils::String::VA("^1%s", Localization::LocalizeMapName(server->mapname.data())); } - return Game::UI_LocalizeMapName(server->mapname.data()); + return Localization::LocalizeMapName(server->mapname.data()); } - return Utils::String::VA("^3%s", Game::UI_LocalizeMapName(server->mapname.data())); + return Utils::String::VA("^3%s", Localization::LocalizeMapName(server->mapname.data())); } case Column::Players: diff --git a/src/Components/Modules/Theatre.cpp b/src/Components/Modules/Theatre.cpp index 4d89eb19..e8250bfb 100644 --- a/src/Components/Modules/Theatre.cpp +++ b/src/Components/Modules/Theatre.cpp @@ -311,7 +311,7 @@ namespace Components if (item < Demos.size()) { auto info = Demos.at(item); - return Utils::String::VA("%s on %s", Game::UI_LocalizeGameType(info.gametype.data()), Game::UI_LocalizeMapName(info.mapname.data())); + return Utils::String::VA("%s on %s", Game::UI_LocalizeGameType(info.gametype.data()), Localization::LocalizeMapName(info.mapname.data())); } return ""; @@ -330,7 +330,7 @@ namespace Components asctime_s(buffer, sizeof buffer, &time); Dvar::Var("ui_demo_mapname").set(info.mapname); - Dvar::Var("ui_demo_mapname_localized").set(Game::UI_LocalizeMapName(info.mapname.data())); + Dvar::Var("ui_demo_mapname_localized").set(Localization::LocalizeMapName(info.mapname.data())); Dvar::Var("ui_demo_gametype").set(Game::UI_LocalizeGameType(info.gametype.data())); Dvar::Var("ui_demo_length").set(Utils::String::FormatTimeSpan(info.length)); Dvar::Var("ui_demo_author").set(info.author); diff --git a/src/Components/Modules/UIFeeder.cpp b/src/Components/Modules/UIFeeder.cpp index 526f745a..e7d43c38 100644 --- a/src/Components/Modules/UIFeeder.cpp +++ b/src/Components/Modules/UIFeeder.cpp @@ -290,7 +290,7 @@ namespace Components return maps.at(index).data(); } -#ifdef DEBUG +#ifdef _DEBUG if (IsDebuggerPresent()) { __debugbreak(); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 5cc612ed..07a5fc59 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -399,25 +399,6 @@ namespace Game return value; } - const char* UI_LocalizeMapName(const char* mapName) - { - for (int i = 0; i < *arenaCount; ++i) - { - if (!_stricmp(Components::ArenaLength::NewArenas[i].mapName, mapName)) - { - char* uiName = &Components::ArenaLength::NewArenas[i].uiName[0]; - if ((uiName[0] == 'M' && uiName[1] == 'P') || (uiName[0] == 'P' && uiName[1] == 'A')) // MPUI/PATCH - { - return SEH_StringEd_GetString(uiName); - } - - return uiName; - } - } - - return mapName; - } - const char* UI_LocalizeGameType(const char* gameType) { if (!gameType || !*gameType) diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 53f65385..d99e8113 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -737,7 +737,6 @@ namespace Game void Menu_SetNextCursorItem(UiContext* ctx, menuDef_t* currentMenu, int unk = 1); void Menu_SetPrevCursorItem(UiContext* ctx, menuDef_t* currentMenu, int unk = 1); const char* TableLookup(StringTable* stringtable, int row, int column); - const char* UI_LocalizeMapName(const char* mapName); const char* UI_LocalizeGameType(const char* gameType); float UI_GetScoreboardLeft(void*);