From 4ebf3849ab7bf2a62535ca15a88e367e8c85c15e Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 1 Jan 2016 17:36:47 +0100 Subject: [PATCH] Some serverlist fixes. --- src/Components/Modules/Colors.cpp | 21 ++++++--------------- src/Components/Modules/Colors.hpp | 3 ++- src/Components/Modules/Party.cpp | 9 ++++++++- src/Components/Modules/ServerList.cpp | 9 +++++---- src/Components/Modules/ServerList.hpp | 1 + src/Game/Functions.cpp | 1 + src/Game/Functions.hpp | 3 +++ 7 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/Components/Modules/Colors.cpp b/src/Components/Modules/Colors.cpp index 5d62c25d..7d011921 100644 --- a/src/Components/Modules/Colors.cpp +++ b/src/Components/Modules/Colors.cpp @@ -45,25 +45,16 @@ namespace Components } } - char* Colors::CL_GetClientName(int a1, int a2, char* buffer, size_t _length) + char* Colors::GetClientName(int localClientNum, int index, char *buf, size_t size) { - __asm - { - push _length - push buffer - push a2 - push a1 - mov eax, 4563D0h - call eax - add esp, 10h - } + Game::CL_GetClientName(localClientNum, index, buf, size); // Remove the colors char tempBuffer[100] = { 0 }; - Colors::Strip(buffer, tempBuffer, _length); - strncpy(buffer, tempBuffer, _length); + Colors::Strip(buf, tempBuffer, size); + strncpy(buf, tempBuffer, size); - return buffer; + return buf; } void Colors::UpdateColorTable() @@ -103,7 +94,7 @@ namespace Components Utils::Hook(0x5D8B40, Colors::ClientUserinfoChanged, HOOK_JUMP).Install()->Quick(); // Though, don't apply that to overhead names. - Utils::Hook(0x581932, Colors::CL_GetClientName, HOOK_CALL).Install()->Quick(); + Utils::Hook(0x581932, Colors::GetClientName, HOOK_CALL).Install()->Quick(); // Set frame handler Renderer::OnFrame(Colors::UpdateColorTable); diff --git a/src/Components/Modules/Colors.hpp b/src/Components/Modules/Colors.hpp index 54392ac4..4ddca9da 100644 --- a/src/Components/Modules/Colors.hpp +++ b/src/Components/Modules/Colors.hpp @@ -8,10 +8,11 @@ namespace Components Colors(); const char* GetName() { return "Colors"; }; + private: static Dvar::Var NewColors; static void ClientUserinfoChanged(int length); - static char* CL_GetClientName(int a1, int a2, char* buffer, size_t _length); + static char* GetClientName(int localClientNum, int index, char *buf, size_t size); static void UpdateColorTable(); diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index 27ac2292..abbee067 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -157,14 +157,21 @@ namespace Components info.Set("challenge", data.substr(0, data.find_first_of("\n")).data()); info.Set("gamename", "IW4"); info.Set("hostname", Dvar::Var("sv_hostname").Get()); - info.Set("mapname", Dvar::Var("mapname").Get()); info.Set("gametype", Dvar::Var("g_gametype").Get()); 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", maxclientCount)); info.Set("protocol", Utils::VA("%i", PROTOCOL)); + info.Set("shortversion", VERSION_STR); info.Set("checksum", Utils::VA("%d", Game::Com_Milliseconds())); + info.Set("mapname", Dvar::Var("mapname").Get()); + + // Ensure mapname is set + if (!info.Get("mapname").size()) + { + info.Set("mapname", Dvar::Var("ui_mapname").Get()); + } // Set matchtype // 0 - No match, connecting not possible diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index 7e5458b7..072b2b14 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -106,11 +106,14 @@ namespace Components break; } - // TODO: Implement deeper check like version and game + // Remove server from queue + ServerList::RefreshContainer.Servers.erase(i); + ServerInfo server; server.Hostname = info.Get("hostname"); server.Mapname = info.Get("mapname"); server.Gametype = info.Get("gametype"); + server.Shortversion = info.Get("shortversion"); server.Mod = info.Get("fs_game"); server.MatchType = atoi(info.Get("matchtype").data()); server.Clients = atoi(info.Get("clients").data()); @@ -129,13 +132,11 @@ namespace Components } } - if (server.MatchType) + if (info.Get("gamename") == "IW4" && server.MatchType && server.Shortversion == VERSION_STR) { ServerList::OnlineList.push_back(server); } - ServerList::RefreshContainer.Servers.erase(i); - break; } } diff --git a/src/Components/Modules/ServerList.hpp b/src/Components/Modules/ServerList.hpp index 027959cc..65551fe0 100644 --- a/src/Components/Modules/ServerList.hpp +++ b/src/Components/Modules/ServerList.hpp @@ -11,6 +11,7 @@ namespace Components std::string Mapname; std::string Gametype; std::string Mod; + std::string Shortversion; int Clients; int MaxClients; bool Password; diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index e11253e9..46f91857 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -4,6 +4,7 @@ namespace Game { Cbuf_AddText_t Cbuf_AddText = (Cbuf_AddText_t)0x404B20; + CL_GetClientName_t CL_GetClientName = (CL_GetClientName_t)0x4563D0; CL_IsCgameInitialized_t CL_IsCgameInitialized = (CL_IsCgameInitialized_t)0x43EB20; CL_ConnectFromParty_t CL_ConnectFromParty = (CL_ConnectFromParty_t)0x433D30; diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 4e0d952e..c98a8bb7 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -3,6 +3,9 @@ namespace Game typedef void(__cdecl * Cbuf_AddText_t)(int a1, const char* cmd); extern Cbuf_AddText_t Cbuf_AddText; + typedef char*(__cdecl * CL_GetClientName_t)(int localClientNum, int index, char *buf, size_t size); + extern CL_GetClientName_t CL_GetClientName; + typedef int(__cdecl * CL_IsCgameInitialized_t)(); extern CL_IsCgameInitialized_t CL_IsCgameInitialized;