diff --git a/src/Components/Modules/ConnectProtocol.cpp b/src/Components/Modules/ConnectProtocol.cpp index 2de06338..f302b475 100644 --- a/src/Components/Modules/ConnectProtocol.cpp +++ b/src/Components/Modules/ConnectProtocol.cpp @@ -257,7 +257,7 @@ namespace Components *substr2 = 0; ////DBG(("Connecting to: %s", substr)); - Game::Cbuf_AddText(0, Utils::VA("connect %s;", substr)); + Command::Execute(Utils::VA("connect %s;", substr), false); } BOOL ConnectProtocol::InvokeConnect() @@ -321,12 +321,11 @@ namespace Components ConnectProtocol::ConnectProtocol() { ConnectProtocol::InstallProtocol(); - } //Send Connect Command to running iw4x instance - BOOL CALLBACK enumWindowsProc(__in HWND hWnd, __in LPARAM lParam) { + BOOL CALLBACK ConnectProtocol::EnumWindowsProc(__in HWND hWnd, __in LPARAM lParam) { DWORD id = GetWindowThreadProcessId(hWnd, &id); DWORD id2 = GetWindowThreadProcessId(FindWindowFromProcessId(proc_id), &id2); @@ -353,7 +352,7 @@ namespace Components return TRUE; } - BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) { + BOOL CALLBACK ConnectProtocol::EnumChildProc(HWND hwnd, LPARAM lParam) { char buffer[256]; GetClassName(hwnd, (LPSTR)buffer, 255); @@ -375,7 +374,7 @@ namespace Components HWND hWnd; }; - BOOL CALLBACK EnumProc(HWND hWnd, LPARAM lParam) { + BOOL CALLBACK ConnectProtocol::EnumProc(HWND hWnd, LPARAM lParam) { // Retrieve storage location for communication data EnumData& ed = *(EnumData*)lParam; DWORD dwProcessId = 0x0; @@ -395,7 +394,7 @@ namespace Components return TRUE; } - void FindEditHandle(__in_z LPCTSTR lpcszFileName) + void ConnectProtocol::FindEditHandle(__in_z LPCTSTR lpcszFileName) { LPDWORD lpdwProcessIds; LPTSTR lpszBaseName; @@ -425,7 +424,7 @@ namespace Components dwProcessId = lpdwProcessIds[i]; CloseHandle(hProcess); proc_id = dwProcessId; - EnumWindows(enumWindowsProc, NULL); + EnumWindows(EnumWindowsProc, NULL); if (con_in != NULL) { break; @@ -445,7 +444,7 @@ namespace Components //return dwProcessId; } // Main entry - HWND FindWindowFromProcessId(DWORD dwProcessId) { + HWND ConnectProtocol::FindWindowFromProcessId(DWORD dwProcessId) { EnumData ed = { dwProcessId }; if (!EnumWindows(EnumProc, (LPARAM)&ed) && (GetLastError() == ERROR_SUCCESS)) { @@ -454,7 +453,7 @@ namespace Components return NULL; } // Helper method for convenience - HWND FindWindowFromProcess(HANDLE hProcess) { + HWND ConnectProtocol::FindWindowFromProcess(HANDLE hProcess) { return FindWindowFromProcessId(GetProcessId(hProcess)); } } diff --git a/src/Components/Modules/ConnectProtocol.hpp b/src/Components/Modules/ConnectProtocol.hpp index de67afc3..b22dc00c 100644 --- a/src/Components/Modules/ConnectProtocol.hpp +++ b/src/Components/Modules/ConnectProtocol.hpp @@ -6,14 +6,16 @@ namespace Components ConnectProtocol(); void EvaluateProtocol(); static BOOL InvokeConnect(); + private: static bool InstallProtocol(); + //Additional Functions for InvokeConnect + static void FindEditHandle(__in_z LPCTSTR lpcszFileName); + static BOOL CALLBACK EnumProc(HWND hWnd, LPARAM lParam); + static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam); + static BOOL CALLBACK EnumWindowsProc(__in HWND hWnd, __in LPARAM lParam); + static HWND FindWindowFromProcessId(DWORD dwProcessId); + static HWND FindWindowFromProcess(HANDLE hProcess); }; - //Additional Functions for InvokeConnect - void FindEditHandle(__in_z LPCTSTR lpcszFileName); - BOOL CALLBACK EnumProc(HWND hWnd, LPARAM lParam); - BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam); - HWND FindWindowFromProcessId(DWORD dwProcessId); - HWND FindWindowFromProcess(HANDLE hProcess); } \ No newline at end of file diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index 6e99a93a..03a53795 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -57,6 +57,7 @@ namespace Components std::string rotation = Dvar::Var("sv_mapRotationCurrent").Get(); // Ignores " for now, too lazy to implement + // TODO: Implement! auto tokens = Utils::Explode(rotation, ' '); for (unsigned int i = 0; i < (tokens.size() - 1); i += 2) diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index f2afec22..52e8b05d 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -129,18 +129,6 @@ namespace Components { // TODO: Register string dvars here - // TODO: Support multiple languages here and find a better place for this. :/ - if (std::string(Game::Win_GetLanguage()) == "german") - { - Localization::Set("MP_SEARCHING_FOR_PLAYER", "Warte"); - Localization::Set("MENU_WAITING_FOR_MORE_PLAYERS_TEAMS", "Auf weitere Spieler zum Teamausgleich warten"); - } - else - { - Localization::Set("MP_SEARCHING_FOR_PLAYER", "Waiting"); - Localization::Set("MENU_WAITING_FOR_MORE_PLAYERS_TEAMS", "Waiting for more players to balance teams"); - } - return Dvar::Register(name, "Unknown Soldier", Dvar::Flag(flag | Game::dvar_flag::DVAR_FLAG_SAVED).val, description).Get(); } diff --git a/src/Components/Modules/Localization.cpp b/src/Components/Modules/Localization.cpp index ee5f9c2d..b2feb288 100644 --- a/src/Components/Modules/Localization.cpp +++ b/src/Components/Modules/Localization.cpp @@ -33,9 +33,13 @@ namespace Components { Utils::Hook(0x629B90, Localization::Get, HOOK_JUMP).Install()->Quick(); - //Localization::Set("MENU_MULTIPLAYER_CAPS", "^5Fotze"); - Localization::Set("MENU_SEARCHINGFORGAMES_100MS", ""); + Localization::Set("MP_SEARCHING_FOR_PLAYER", "Waiting"); + Localization::Set("MENU_WAITING_FOR_MORE_PLAYERS_TEAMS", "Waiting for more players to balance teams"); + + // Don't perform non-english localization here, do it in fastfiles instead + //Localization::Set("MP_SEARCHING_FOR_PLAYER", "Warte"); + //Localization::Set("MENU_WAITING_FOR_MORE_PLAYERS_TEAMS", "Auf weitere Spieler zum Teamausgleich warten"); Localization::UseLocalization = Dvar::Register("ui_localize", true, Game::dvar_flag::DVAR_FLAG_NONE, "Use localization strings"); } diff --git a/src/Components/Modules/Menus.cpp b/src/Components/Modules/Menus.cpp index e513b99b..feb7efa7 100644 --- a/src/Components/Modules/Menus.cpp +++ b/src/Components/Modules/Menus.cpp @@ -2,6 +2,7 @@ namespace Components { + std::vector Menus::CustomMenus; std::vector Menus::MenuList; std::vector Menus::MenuListList; @@ -181,12 +182,7 @@ namespace Components { Game::PC_ReadTokenHandle(handle, &token); - std::vector newMenus = Menus::LoadMenu(Utils::VA("ui_mp\\%s.menu", token.string)); - - for (auto newMenu : newMenus) - { - menus.push_back(newMenu); - } + Utils::Merge(menus, Menus::LoadMenu(Utils::VA("ui_mp\\%s.menu", token.string))); } if (!_stricmp(token.string, "menudef")) @@ -244,22 +240,16 @@ namespace Components continue; } - std::vector newMenus = Menus::LoadMenu(menuList->menus[i]); - - for (auto newMenu : newMenus) - { - menus.push_back(newMenu); - } + Utils::Merge(menus, Menus::LoadMenu(menuList->menus[i])); } - // TODO: beautify - if (!_stricmp(menuList->name, "ui_mp/code.txt")) + // Load custom menus + if (std::string(menuList->name) == "ui_mp/code.txt") { - std::vector _menus = Menus::LoadMenu("ui_mp/theater_menu.menu"); - std::vector _menus2 = Menus::LoadMenu("ui_mp/pc_options_multi.menu"); - - for (auto newMenu : _menus) { menus.push_back(newMenu); } - for (auto newMenu : _menus2) { menus.push_back(newMenu); } + for (auto menu : Menus::CustomMenus) + { + Utils::Merge(menus, Menus::LoadMenu(menu)); + } } // Allocate new menu list @@ -483,6 +473,11 @@ namespace Components return nullptr; } + void Menus::Add(std::string menu) + { + Menus::CustomMenus.push_back(menu); + } + Menus::Menus() { if (Dedicated::IsDedicated()) return; @@ -538,10 +533,15 @@ namespace Components Game::Menus_OpenByName(Game::uiContext, "main_text"); } }); + + // Define custom menus here + Menus::Add("ui_mp/theater_menu.menu"); + Menus::Add("ui_mp/pc_options_multi.menu"); } Menus::~Menus() { + Menus::CustomMenus.clear(); Menus::FreeEverything(); } } diff --git a/src/Components/Modules/Menus.hpp b/src/Components/Modules/Menus.hpp index c9288cb9..ed89b555 100644 --- a/src/Components/Modules/Menus.hpp +++ b/src/Components/Modules/Menus.hpp @@ -11,9 +11,12 @@ namespace Components static void FreeEverything(); + static void Add(std::string menu); + private: static std::vector MenuList; static std::vector MenuListList; + static std::vector CustomMenus; static Game::XAssetHeader MenuFileLoad(Game::XAssetType type, const char* filename); static Game::MenuList* LoadMenuList(Game::MenuList* menuList); diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index 3e6cb14f..27ac2292 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -139,15 +139,10 @@ namespace Components Network::Handle("getInfo", [] (Network::Address address, std::string data) { int clientCount = 0; + int maxclientCount = *Game::svs_numclients; + if (!maxclientCount) maxclientCount = Dvar::Var("sv_maxclients").Get(); - int maxClients = *Game::svs_numclients; - - if (!maxClients) - { - maxClients = Dvar::Var("sv_maxclients").Get(); - } - - for (int i = 0; i < maxClients; i++) + for (int i = 0; i < maxclientCount; i++) { if (Game::svs_clients[i].state >= 3) { @@ -155,6 +150,9 @@ namespace Components } } + // Ensure line break + data.append("\n"); + Utils::InfoString info; info.Set("challenge", data.substr(0, data.find_first_of("\n")).data()); info.Set("gamename", "IW4"); @@ -164,7 +162,7 @@ namespace Components info.Set("fs_game", Dvar::Var("fs_game").Get()); info.Set("xuid", Utils::VA("%llX", Steam::SteamUser()->GetSteamID().Bits)); info.Set("clients", Utils::VA("%i", clientCount)); - info.Set("sv_maxclients", Utils::VA("%i", maxClients)); + info.Set("sv_maxclients", Utils::VA("%i", maxclientCount)); info.Set("protocol", Utils::VA("%i", PROTOCOL)); info.Set("checksum", Utils::VA("%d", Game::Com_Milliseconds())); diff --git a/src/Utils/Utils.hpp b/src/Utils/Utils.hpp index 341d54c3..4435e863 100644 --- a/src/Utils/Utils.hpp +++ b/src/Utils/Utils.hpp @@ -25,4 +25,12 @@ namespace Utils std::map KeyValuePairs; void Parse(std::string buffer); }; + + template void Merge(std::vector &target, std::vector &source) + { + for (auto &entry : source) + { + target.push_back(entry); + } + } }