diff --git a/iw4/Components/Menus.cpp b/iw4/Components/Menus.cpp index 274c85cb..aca628e9 100644 --- a/iw4/Components/Menus.cpp +++ b/iw4/Components/Menus.cpp @@ -413,7 +413,7 @@ namespace Components return header; } - void Menus::AddMenuListHook(int dc, Game::MenuList *menuList, int close) + void Menus::AddMenuListHook(Game::UiContext *dc, Game::MenuList *menuList, int close) { Game::MenuList* menus = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MENUFILE, "ui_mp/menus.txt").menuList; @@ -421,13 +421,37 @@ namespace Components Game::UI_AddMenuList(dc, menuList, close); } + Game::menuDef_t* Menus::FindMenuByName(Game::UiContext* dc, const char* name) + { + for (int i = 0; i < dc->menuCount; i++) + { + Game::menuDef_t* menu = dc->Menus[i]; + if (menu && menu->window.name && !IsBadReadPtr(menu->window.name, 1)) // Sanity checks + { + if (!_strnicmp(name, menu->window.name, 0x7FFFFFFF)) + { + return menu; + } + } + else + { + // TODO: Remove menu from stack and free if custom menu + } + } + + return nullptr; + } + Menus::Menus() { AssetHandler::On(Game::XAssetType::ASSET_TYPE_MENUFILE, Menus::MenuFileLoad); //Utils::Hook(0x63FE80, Menus::MenuFileLoad, HOOK_JUMP).Install()->Quick(); + // Custom Menus_FindByName + Utils::Hook(0x487240, Menus::FindMenuByName, HOOK_JUMP).Install()->Quick(); + // Load menus ingame - //Utils::Hook(0x41C178, Menus::AddMenuListHook, HOOK_CALL).Install()->Quick(); + Utils::Hook(0x41C178, Menus::AddMenuListHook, HOOK_CALL).Install()->Quick(); // disable the 2 new tokens in ItemParse_rect Utils::Hook::Set(0x640693, 0xEB); @@ -446,13 +470,13 @@ namespace Components return; } - Game::Menus_OpenByName(0x62E2858, params[1]); + Game::Menus_OpenByName(Game::uiContext, params[1]); }); Command::Add("reloadmenus", [] (Command::Params params) { // Close all menus - Game::Menus_CloseAll(0x62E2858); + Game::Menus_CloseAll(Game::uiContext); // Free custom menus Menus::FreeEverything(); @@ -468,7 +492,7 @@ namespace Components ((void(*)())0x401700)(); // Reopen main menu - Game::Menus_OpenByName(0x62E2858, "main_text"); + Game::Menus_OpenByName(Game::uiContext, "main_text"); } }); } diff --git a/iw4/Components/Menus.hpp b/iw4/Components/Menus.hpp index a30457c1..28edabff 100644 --- a/iw4/Components/Menus.hpp +++ b/iw4/Components/Menus.hpp @@ -35,7 +35,9 @@ namespace Components static void RemoveMenu(Game::menuDef_t* menudef); static void RemoveMenuList(Game::MenuList* menuList); - static void AddMenuListHook(int dc, Game::MenuList *menuList, int close); + static void AddMenuListHook(Game::UiContext *dc, Game::MenuList *menuList, int close); + + static Game::menuDef_t* FindMenuByName(Game::UiContext* dc, const char* name); // Ugly! static int KeywordHash(char* key); diff --git a/iw4/Components/Party.cpp b/iw4/Components/Party.cpp index 5f881f2d..5b4f0f87 100644 --- a/iw4/Components/Party.cpp +++ b/iw4/Components/Party.cpp @@ -116,7 +116,7 @@ namespace Components else { Dvar::Var("xblive_privatematch").Set(1); - Game::Menus_CloseAll(0x62E2858); + Game::Menus_CloseAll(Game::uiContext); char xnaddr[32]; Game::CL_ConnectFromParty(0, xnaddr, *address.Get(), 0, 0, info.Get("mapname").data(), info.Get("gametype").data()); diff --git a/iw4/Game/Functions.cpp b/iw4/Game/Functions.cpp index 654b8d6c..57042c7e 100644 --- a/iw4/Game/Functions.cpp +++ b/iw4/Game/Functions.cpp @@ -91,6 +91,8 @@ namespace Game int* svs_numclients = (int*)0x31D938C; client_t* svs_clients = (client_t*)0x31D9390; + UiContext *uiContext = (UiContext *)0x62E2858; + void* ReallocateAssetPool(XAssetType type, unsigned int newSize) { int elSize = DB_GetXAssetSizeHandlers[type](); diff --git a/iw4/Game/Functions.hpp b/iw4/Game/Functions.hpp index b97116bc..a1b12845 100644 --- a/iw4/Game/Functions.hpp +++ b/iw4/Game/Functions.hpp @@ -121,10 +121,10 @@ namespace Game typedef int(__cdecl * FS_BuildPathToFile_t)(const char*, const char*, const char*, char**); extern FS_BuildPathToFile_t FS_BuildPathToFile; - typedef void(__cdecl * Menus_CloseAll_t)(/*UiContext **/int dc); + typedef void(__cdecl * Menus_CloseAll_t)(UiContext *dc); extern Menus_CloseAll_t Menus_CloseAll; - typedef int(__cdecl * Menus_OpenByName_t)(/*UiContext **/int dc, const char *p); + typedef int(__cdecl * Menus_OpenByName_t)(UiContext *dc, const char *p); extern Menus_OpenByName_t Menus_OpenByName; typedef const char* (__cdecl * NET_AdrToString_t)(netadr_t adr); @@ -163,7 +163,7 @@ namespace Game typedef void(__cdecl * SetConsole_t)(const char* cvar, const char* value); extern SetConsole_t SetConsole; - typedef void(__cdecl * UI_AddMenuList_t)(/*UiContext **/int dc, MenuList *menuList, int close); + typedef void(__cdecl * UI_AddMenuList_t)(UiContext *dc, MenuList *menuList, int close); extern UI_AddMenuList_t UI_AddMenuList; typedef const char * (__cdecl * Win_GetLanguage_t)(); @@ -182,6 +182,8 @@ namespace Game extern source_t **sourceFiles; extern keywordHash_t **menuParseKeywordHash; + extern UiContext *uiContext; + void* ReallocateAssetPool(XAssetType type, unsigned int newSize); void Menu_FreeItemMemory(Game::itemDef_t* item); void OOBPrintT(int type, netadr_t netadr, const char* message); diff --git a/iw4/Game/Structs.hpp b/iw4/Game/Structs.hpp index 691e49fc..4747a051 100644 --- a/iw4/Game/Structs.hpp +++ b/iw4/Game/Structs.hpp @@ -804,6 +804,54 @@ namespace Game //struct keywordHash_s *next; } keywordHash_t; + enum UILocalVarType + { + UILOCALVAR_INT = 0x0, + UILOCALVAR_FLOAT = 0x1, + UILOCALVAR_STRING = 0x2, + }; + + struct UILocalVar + { + UILocalVarType type; + const char *name; + union + { + int integer; + float value; + const char *string; + }; + }; + + struct UILocalVarContext + { + UILocalVar table[256]; + }; + + struct UiContext + { +// int localClientNum; +// float bias; +// int realTime; +// int frameTime; +// int cursorx; +// int cursory; +// int debug; +// int screenWidth; +// int screenHeight; +// float screenAspect; +// float FPS; +// float blurRadiusOut; + char pad[56]; + menuDef_t *Menus[512]; + char pad2[512]; + int menuCount; + // Unsure if below is correct + menuDef_t *menuStack[16]; + int openMenuCount; + UILocalVarContext localVars; + }; + union XAssetHeader { void *data; diff --git a/iw4/Steam/Interfaces/SteamUser.cpp b/iw4/Steam/Interfaces/SteamUser.cpp index e15d00a6..9f7f112a 100644 --- a/iw4/Steam/Interfaces/SteamUser.cpp +++ b/iw4/Steam/Interfaces/SteamUser.cpp @@ -20,7 +20,13 @@ namespace Steam if (!subId) { - subId = (Game::Com_Milliseconds() + timeGetTime()); + DATA_BLOB Data[2]; + Data[0].pbData = (BYTE *)"AAAAAAAAAA"; + Data[0].cbData = 10; + + CryptProtectData(&Data[0], NULL, NULL, NULL, NULL, CRYPTPROTECT_LOCAL_MACHINE, &Data[1]); + + subId = ::Utils::OneAtATime((char*)Data[1].pbData, 52); //(Game::Com_Milliseconds() + timeGetTime()); } id.m_Bits = 0x110000100000000 | subId;