From 32977b448d91f420ba96b98714eabe9a2ce47a6c Mon Sep 17 00:00:00 2001 From: momo5502 Date: Mon, 4 Jan 2016 01:30:15 +0100 Subject: [PATCH] Fix server sorting. --- src/Components/Modules/ServerList.cpp | 42 +++++++++++++++++++++++++-- src/Components/Modules/ServerList.hpp | 5 ++++ src/Components/Modules/UIScript.cpp | 26 +++++++++++++++++ src/Components/Modules/UIScript.hpp | 5 +++- 4 files changed, 74 insertions(+), 4 deletions(-) diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index b476bd0e..972b3722 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -68,6 +68,11 @@ namespace Components return (server->Password ? "X" : ""); } + case Column::Matchtype: + { + return ((server->MatchType == 1) ? "L" : "D"); + } + case Column::Hostname: { return server->Hostname.data(); @@ -84,13 +89,18 @@ namespace Components } case Column::Gametype: + { + return Game::UI_LocalizeGameType(server->Gametype.data()); + } + + case Column::Mod: { if (server->Mod != "") { return (server->Mod.data() + 5); } - return Game::UI_LocalizeGameType(server->Gametype.data()); + return ""; } case Column::Ping: @@ -107,6 +117,12 @@ namespace Components ServerList::CurrentServer = (unsigned int)index; } + void ServerList::RefreshVisibleList() + { + // TODO: Update the list + ServerList::Refresh(); + } + void ServerList::Refresh() { // ServerList::OnlineList.clear(); @@ -255,8 +271,8 @@ namespace Components ServerInfo* info1 = nullptr; ServerInfo* info2 = nullptr; - if (ServerList::OnlineList.size() > (unsigned int)server1) info1 = &ServerList::OnlineList[server1]; - if (ServerList::OnlineList.size() > (unsigned int)server2) info2 = &ServerList::OnlineList[server2]; + if (ServerList::GetList().size() > (unsigned int)server1) info1 = &ServerList::GetList()[server1]; + if (ServerList::GetList().size() > (unsigned int)server2) info2 = &ServerList::GetList()[server2]; if (!info1) return 1; if (!info2) return -1; @@ -336,6 +352,22 @@ namespace Components ServerList::RefreshContainer.Mutex.unlock(); } + void ServerList::UpdateSource() + { + Dvar::Var netSource("ui_netSource"); + + int source = netSource.Get(); + + if (++source > netSource.Get()->max.i) + { + source = 0; + } + + netSource.Set(source); + + ServerList::RefreshVisibleList(); + } + ServerList::ServerList() { ServerList::OnlineList.clear(); @@ -412,6 +444,10 @@ namespace Components ServerList::SortList(); }); + // Add required ownerDraws + UIScript::AddOwnerDraw(220, ServerList::UpdateSource); + //UIScript::AddOwnerDraw(253, ServerList_ClickHandler_GameType); + // Add frame callback Renderer::OnFrame(ServerList::Frame); } diff --git a/src/Components/Modules/ServerList.hpp b/src/Components/Modules/ServerList.hpp index 24d1cdcf..ba04d128 100644 --- a/src/Components/Modules/ServerList.hpp +++ b/src/Components/Modules/ServerList.hpp @@ -26,6 +26,7 @@ namespace Components const char* GetName() { return "ServerList"; }; static void Refresh(); + static void RefreshVisibleList(); static void InsertRequest(Network::Address address, bool accquireMutex = true); static void Insert(Network::Address address, Utils::InfoString info); @@ -37,10 +38,12 @@ namespace Components enum Column { Password, + Matchtype, Hostname, Mapname, Players, Gametype, + Mod, Ping, }; @@ -93,6 +96,8 @@ namespace Components static const char* GetServerText(ServerInfo* server, int column); static void SelectServer(int index); + static void UpdateSource(); + static void Frame(); static void SortList(); diff --git a/src/Components/Modules/UIScript.cpp b/src/Components/Modules/UIScript.cpp index 44de86c3..7f15048e 100644 --- a/src/Components/Modules/UIScript.cpp +++ b/src/Components/Modules/UIScript.cpp @@ -3,6 +3,7 @@ namespace Components { std::map UIScript::UIScripts; + std::map UIScript::UIOwnerDraws; template<> int UIScript::Token::Get() { @@ -57,6 +58,11 @@ namespace Components UIScript::Add(name, reinterpret_cast(callback)); } + void UIScript::AddOwnerDraw(int ownerdraw, UIScript::CallbackRaw callback) + { + UIScript::UIOwnerDraws[ownerdraw] = callback; + } + bool UIScript::RunMenuScript(const char* name, const char** args) { if (UIScript::UIScripts.find(name) != UIScript::UIScripts.end()) @@ -68,6 +74,22 @@ namespace Components return false; } + void UIScript::OwnerDrawHandleKeyStub(int ownerDraw, int flags, float *special, int key) + { + if (key == 200 || key == 201) //mouse buttons + { + for (auto i = UIScript::UIOwnerDraws.begin(); i != UIScript::UIOwnerDraws.end(); i++) + { + if (i->first == ownerDraw) + { + i->second(); + } + } + } + + Utils::Hook::Call(0x4F58A0)(ownerDraw, flags, special, key); + } + void __declspec(naked) UIScript::RunMenuScriptStub() { __asm @@ -101,10 +123,14 @@ namespace Components { // Install handler Utils::Hook::Set(0x45EC5B, (DWORD)UIScript::RunMenuScriptStub - 0x45EC59 - 6); + + // Install ownerdraw handler + Utils::Hook(0x63D233, UIScript::OwnerDrawHandleKeyStub, HOOK_CALL).Install()->Quick(); } UIScript::~UIScript() { UIScript::UIScripts.clear(); + UIScript::UIOwnerDraws.clear(); } } diff --git a/src/Components/Modules/UIScript.hpp b/src/Components/Modules/UIScript.hpp index 49318195..d6641add 100644 --- a/src/Components/Modules/UIScript.hpp +++ b/src/Components/Modules/UIScript.hpp @@ -29,11 +29,14 @@ namespace Components static void Add(std::string name, Callback callback); static void Add(std::string name, CallbackRaw callback); - private: + static void AddOwnerDraw(int ownerdraw, CallbackRaw callback); + private: + static void OwnerDrawHandleKeyStub(int ownerDraw, int flags, float *special, int key); static bool RunMenuScript(const char* name, const char** args); static void RunMenuScriptStub(); static std::map UIScripts; + static std::map UIOwnerDraws; }; }