From 3150950507986ae26cd99445bd94795d32eacda1 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 21 Jan 2017 22:14:23 +0100 Subject: [PATCH] [UIFeeder] Add select function and use feeder 5 for maps --- src/Components/Modules/ServerList.cpp | 8 +- src/Components/Modules/ServerList.hpp | 2 +- src/Components/Modules/UIFeeder.cpp | 121 ++++++++++++++++++++------ src/Components/Modules/UIFeeder.hpp | 15 ++-- src/Game/Functions.cpp | 1 + src/Game/Functions.hpp | 3 + 6 files changed, 113 insertions(+), 37 deletions(-) diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index dd743405..e9f58bc5 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -58,13 +58,13 @@ namespace Components if (info) { - return ServerList::GetServerText(info, column); + return ServerList::GetServerInfoText(info, column); } return ""; } - const char* ServerList::GetServerText(ServerList::ServerInfo* server, int column) + const char* ServerList::GetServerInfoText(ServerList::ServerInfo* server, int column) { if (!server) return ""; @@ -547,8 +547,8 @@ namespace Components return ((info1->clients - info2->clients) * (ServerList::SortAsc ? 1 : -1)); } - std::string text1 = Colors::Strip(ServerList::GetServerText(info1, ServerList::SortKey)); - std::string text2 = Colors::Strip(ServerList::GetServerText(info2, ServerList::SortKey)); + std::string text1 = Colors::Strip(ServerList::GetServerInfoText(info1, ServerList::SortKey)); + std::string text2 = Colors::Strip(ServerList::GetServerInfoText(info2, ServerList::SortKey)); // ASCII-based comparison return (text1.compare(text2) * (ServerList::SortAsc ? 1 : -1)); diff --git a/src/Components/Modules/ServerList.hpp b/src/Components/Modules/ServerList.hpp index 49f0e7cb..2af541ea 100644 --- a/src/Components/Modules/ServerList.hpp +++ b/src/Components/Modules/ServerList.hpp @@ -106,7 +106,7 @@ namespace Components static unsigned int GetServerCount(); static const char* GetServerText(unsigned int index, int column); - static const char* GetServerText(ServerInfo* server, int column); + static const char* GetServerInfoText(ServerInfo* server, int column); static void SelectServer(unsigned int index); static void UpdateSource(); diff --git a/src/Components/Modules/UIFeeder.cpp b/src/Components/Modules/UIFeeder.cpp index 44b96046..7823b942 100644 --- a/src/Components/Modules/UIFeeder.cpp +++ b/src/Components/Modules/UIFeeder.cpp @@ -32,7 +32,11 @@ namespace Components bool UIFeeder::SetItemSelection() { - if (UIFeeder::Feeders.find(UIFeeder::Current.feeder) != UIFeeder::Feeders.end()) + if(UIFeeder::Current.feeder == 4.0f) + { + return true; + } + else if (UIFeeder::Feeders.find(UIFeeder::Current.feeder) != UIFeeder::Feeders.end()) { UIFeeder::Feeders[UIFeeder::Current.feeder].select(UIFeeder::Current.index); return true; @@ -251,43 +255,105 @@ namespace Components } } - void UIFeeder::ApplyMapFeeder(Game::dvar_t* dvar, int num) + void UIFeeder::Select(float feeder, unsigned int index) { - Dvar::Var(dvar).set(num); - - if (num < 0 || num >= *Game::arenaCount) + if(Game::uiContext->openMenuCount > 0) { - num = 0; + Game::menuDef_t* menu = Game::uiContext->menuStack[Game::uiContext->openMenuCount - 1]; + + if (menu && menu->items) + { + for (int i = 0; i < menu->itemCount; ++i) + { + Game::itemDef_t* item = menu->items[i]; + if (item && item->type == 6 && item->special == feeder) + { + item->cursorPos = static_cast(index); + break; + } + } + } } - - // UI_SortArenas - Utils::Hook::Call(0x630AE0)(); - - int index = reinterpret_cast(0x633E934)[num]; - const char* mapname = ArenaLength::NewArenas[index].mapName; - const char* description = ArenaLength::NewArenas[index].description; - - Dvar::Var("ui_mapname").set(mapname); - Dvar::Var("ui_map_desc").set(Game::SEH_StringEd_GetString(description)); - - // Party_SetDisplayMapName - Utils::Hook::Call(0x503B50)(mapname); } - void UIFeeder::DoubleClickMapFeeder(const char* /*dvar_name*/, const char* /*name*/) + unsigned int UIFeeder::GetMapCount() { - //Game::Dvar_SetStringByName(dvar_name, name); + Game::UI_UpdateArenas(); + Game::UI_SortArenas(); + return *Game::arenaCount; + } - // Party_SetDisplayMapName - //Utils::Hook::Call(0x503B50)(name); + const char* UIFeeder::GetMapText(unsigned int index, int /*column*/) + { + Game::UI_UpdateArenas(); + Game::UI_SortArenas(); - Command::Execute("closemenu settings_map", false); + if (index < static_cast(*Game::arenaCount)) + { + return Game::SEH_StringEd_GetString(ArenaLength::NewArenas[reinterpret_cast(0x633E934)[index]].uiName); + } + + return ""; + } + + void UIFeeder::SelectMap(unsigned int index) + { + Game::UI_UpdateArenas(); + Game::UI_SortArenas(); + + if (index < static_cast(*Game::arenaCount)) + { + index = reinterpret_cast(0x633E934)[index]; + const char* mapname = ArenaLength::NewArenas[index].mapName; + const char* longname = ArenaLength::NewArenas[index].uiName; + const char* description = ArenaLength::NewArenas[index].description; + + Dvar::Var("ui_map_name").set(mapname); + Dvar::Var("ui_map_long").set(Game::SEH_StringEd_GetString(longname)); + Dvar::Var("ui_map_desc").set(Game::SEH_StringEd_GetString(description)); + } + } + + void UIFeeder::ApplyMap(UIScript::Token) + { + std::string mapname = Dvar::Var("ui_map_name").get(); + + Dvar::Var("ui_mapname").set(mapname); + Utils::Hook::Call(0x503B50)(mapname.data()); // Party_SetDisplayMapName + } + + void UIFeeder::ApplyInitialMap(UIScript::Token) + { + std::string mapname = Dvar::Var("ui_mapname").get(); + + Game::UI_UpdateArenas(); + Game::UI_SortArenas(); + + for(unsigned int i = 0; i < static_cast(*Game::arenaCount); ++i) + { + if(ArenaLength::NewArenas[i].mapName == mapname) + { + for (unsigned int j = 0; j < static_cast(*Game::arenaCount); ++j) + { + if (reinterpret_cast(0x633E934)[j] == i) + { + UIFeeder::SelectMap(j); + UIFeeder::Select(5.0f, j); + break; + } + } + + break; + } + } } UIFeeder::UIFeeder() { Dvar::OnInit([]() { + Dvar::Register("ui_map_long", "Afghan", Game::dvar_flag::DVAR_FLAG_NONE, ""); + Dvar::Register("ui_map_name", "mp_afghan", Game::dvar_flag::DVAR_FLAG_NONE, ""); Dvar::Register("ui_map_desc", "", Game::dvar_flag::DVAR_FLAG_NONE, ""); }); @@ -315,9 +381,10 @@ namespace Components // some thing overwriting feeder 2's data Utils::Hook::Set(0x4A06A9, 0xEB); - // correct feeder 4 - Utils::Hook(0x4C260E, UIFeeder::ApplyMapFeeder, HOOK_CALL).install()->quick(); - Utils::Hook(0x4E304D, UIFeeder::DoubleClickMapFeeder, HOOK_CALL).install()->quick(); + // Use feeder 5 for maps, as feeder 4 selects on mouse over + UIFeeder::Add(5.0f, UIFeeder::GetMapCount, UIFeeder::GetMapText, UIFeeder::SelectMap); + UIScript::Add("ApplyMap", UIFeeder::ApplyMap); + UIScript::Add("ApplyInitialMap", UIFeeder::ApplyInitialMap); // Fix feeder focus //Utils::Hook::Nop(0x63B1DD, 2); // Flag 4 check (WINDOW_VISIBLE) diff --git a/src/Components/Modules/UIFeeder.hpp b/src/Components/Modules/UIFeeder.hpp index 8e26cffe..b459b94b 100644 --- a/src/Components/Modules/UIFeeder.hpp +++ b/src/Components/Modules/UIFeeder.hpp @@ -5,9 +5,9 @@ namespace Components class UIFeeder : public Component { public: - typedef unsigned int(__cdecl * GetItemCount_t)(); - typedef const char* (__cdecl * GetItemText_t)(unsigned int index, int column); - typedef void(__cdecl * Select_t)(unsigned int index); + typedef Utils::Slot GetItemCount_t; + typedef Utils::Slot GetItemText_t; + typedef Utils::Slot Select_t; struct Callbacks { @@ -51,9 +51,14 @@ namespace Components static void HandleKeyStub(); static void PlaySoundStub(); + static void Select(float feeder, unsigned int index); + static std::unordered_map Feeders; - static void ApplyMapFeeder(Game::dvar_t* dvar, int num); - static void DoubleClickMapFeeder(const char* dvar_name, const char* name); + static unsigned int GetMapCount(); + static const char* GetMapText(unsigned int index, int column); + static void SelectMap(unsigned int index); + static void ApplyMap(UIScript::Token token); + static void ApplyInitialMap(UIScript::Token token); }; } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index cca81570..48b7ab5c 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -244,6 +244,7 @@ namespace Game UI_CheckStringTranslation_t UI_CheckStringTranslation = UI_CheckStringTranslation_t(0x4FB010); UI_LoadMenus_t UI_LoadMenus = UI_LoadMenus_t(0x641460); UI_UpdateArenas_t UI_UpdateArenas = UI_UpdateArenas_t(0x4A95B0); + UI_SortArenas_t UI_SortArenas = UI_SortArenas_t(0x630AE0); UI_DrawHandlePic_t UI_DrawHandlePic = UI_DrawHandlePic_t(0x4D0EA0); UI_GetContext_t UI_GetContext = UI_GetContext_t(0x4F8940); UI_TextWidth_t UI_TextWidth = UI_TextWidth_t(0x6315C0); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 714cd06a..053e5414 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -583,6 +583,9 @@ namespace Game typedef void(__cdecl * UI_UpdateArenas_t)(); extern UI_UpdateArenas_t UI_UpdateArenas; + typedef void(__cdecl * UI_SortArenas_t)(); + extern UI_SortArenas_t UI_SortArenas; + typedef void(__cdecl * UI_DrawHandlePic_t)(/*ScreenPlacement*/void *scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float *color, Material *material); extern UI_DrawHandlePic_t UI_DrawHandlePic;