From 8d18788208f081db9e57d51cf2b1ea349192acb8 Mon Sep 17 00:00:00 2001 From: Ray1235 Date: Mon, 2 Jan 2017 11:26:52 +0100 Subject: [PATCH 1/5] Basic mod specific frontend support --- components/game_mod/dllmain.cpp | 8 +++ components/game_mod/game_mod.vcxproj | 2 + components/game_mod/mod_frontend.cpp | 75 ++++++++++++++++++++++++++++ components/game_mod/mod_frontend.h | 17 +++++++ components/game_mod/stdafx.h | 2 + 5 files changed, 104 insertions(+) create mode 100644 components/game_mod/mod_frontend.cpp create mode 100644 components/game_mod/mod_frontend.h diff --git a/components/game_mod/dllmain.cpp b/components/game_mod/dllmain.cpp index 24fd2a3a..5a01379e 100644 --- a/components/game_mod/dllmain.cpp +++ b/components/game_mod/dllmain.cpp @@ -268,6 +268,14 @@ BOOL GameMod_Init() // Detours::X86::DetourFunction((PBYTE)0x006D98F0, (PBYTE)&hk_R_Cinematic_BinkOpen); + // Ray + // Add Support for Mod Specific Frontend + // + Detours::X86::DetourFunction((PBYTE)0x00406B32, (PBYTE)&Com_RunFrontend, Detours::X86Option::USE_CALL); + Detours::X86::DetourFunction((PBYTE)0x005A6C32, (PBYTE)&Com_RunFrontend, Detours::X86Option::USE_JUMP); + Detours::X86::DetourFunction((PBYTE)0x00679018, (PBYTE)&Com_RunFrontend, Detours::X86Option::USE_JUMP); + // 005A6C32 - jmp + // 00679018 - jmp // // Enable Custom Dvars // diff --git a/components/game_mod/game_mod.vcxproj b/components/game_mod/game_mod.vcxproj index 8985ca20..382c2fbe 100644 --- a/components/game_mod/game_mod.vcxproj +++ b/components/game_mod/game_mod.vcxproj @@ -100,6 +100,7 @@ + @@ -132,6 +133,7 @@ + diff --git a/components/game_mod/mod_frontend.cpp b/components/game_mod/mod_frontend.cpp new file mode 100644 index 00000000..4c0cdf2e --- /dev/null +++ b/components/game_mod/mod_frontend.cpp @@ -0,0 +1,75 @@ +#include "stdafx.h" + +void Com_RunFrontend() +{ + int v0; // esi@2 + char v1; // al@9 + int v2; // esi@9 + int v3; // eax@11 + XZoneInfo zoneInfo; // [sp+408h] [bp-Ch]@6 + // 0x38789A0 - xblive_matchEndingSoon + Dvar_SetBool((dvar_s *)0x38789A0, false); + func_41FEE0(); +#if 0 + Dvar_SetBool((dvar_s *)0x38789A0, false); + func_41FEE0(); + dvar_s *mapname = (dvar_s *)0x2899CEC; + dvar_s *sv_running = (dvar_s *)0x243FD3C; + char *currentMapname = (char *)Dvar_GetString("mapname"); + if (!mapname + || (!sv_running->current.enabled) + || I_strnicmp(currentMapname, "menu_", 5) && I_strcmp(currentMapname, "frontend")) + { +#endif + /* + sub_51D1C0(localClientNum, 0.0); + if (useFastFile->current.enabled) + { + zoneInfo.name = 0; + zoneInfo.allocFlags = 0; + zoneInfo.freeFlags = 256; + DB_LoadXAssets(&zoneInfo, 1u, 0); + } + + if (wierd_var) + memset(wierd_var, 0, 263872 * com_maxclients->current.integer); + v1 = sub_569EE0(); + Dvar_SetInt(com_desiredMenu, v1); + */ + //Dvar_SetBool(systemlink_warning, 0); + //Dvar_SetBool(onlinegame, 0); + //Dvar_SetBool(zombiemode, 0); + //Dvar_SetBool(zombietron, 0); + //Dvar_SetBool(blackopsmode, 0); + //Dvar_SetBool(spmode, 0); + //Dvar_SetBool(arcademode, 0); + /* + v2 = sub_5BEE40(); + if (!Com_LocalClients_GetUsedControllerCount()) + sub_5B4CB0(v2, 1); + v3 = UI_UIContext_GetInfo(v2); + */ + + Com_Printf(1, "Getting sub_5BEE40 value\nsub_5BEE40() = "); + v2 = sub_5BEE40(); // why is localClientNum being this huge, I dont get it + // 1703388 + Com_Printf(1, "%d\nGetting UIContext Info\nUI_UIContext_GetInfo() = "); + v3 = UI_UIContext_GetInfo(v2); + Com_Printf(1, "%d\n", v3); + Com_Printf(1, "Checking for mod_frontend\n"); + if (PartyClient_CheckMapExists("mod_frontend")) + { + Com_Printf(1, "mod_frontend exists. Loading mod_frontend...\n"); + Cmd_ExecuteSingleCommandInternal(v2, v3, NULL, "map mod_frontend", false); // doing this until I find a better alternative + //Cbuf_ExecuteBuffer(v2, v3, "map mod_frontend\n"); + } + else + { + Com_Printf(1, "Loading frontend...\n"); + Cmd_ExecuteSingleCommandInternal(v2, v3, NULL, "map frontend", false); // doing this until I find a better alternative + //Cbuf_ExecuteBuffer(v2, v3, "map frontend\n"); + } +#if 0 + } +#endif +} \ No newline at end of file diff --git a/components/game_mod/mod_frontend.h b/components/game_mod/mod_frontend.h new file mode 100644 index 00000000..26abebb8 --- /dev/null +++ b/components/game_mod/mod_frontend.h @@ -0,0 +1,17 @@ +#pragma once + +typedef void __cdecl voidFunc(); +typedef void __cdecl voidFunc2(int a1, float a2); + +typedef void __cdecl Cbuf_ExecuteBuffer_t(int localClientNum, int controllerIndex, const char* buf); +static Cbuf_ExecuteBuffer_t *Cbuf_ExecuteBuffer = (Cbuf_ExecuteBuffer_t *)0x408A00; + +typedef int __cdecl UI_UIContext_GetInfo_t(int a1); +static UI_UIContext_GetInfo_t *UI_UIContext_GetInfo = (UI_UIContext_GetInfo_t *)0x4F3C70; + +static voidFunc *func_41FEE0 = (voidFunc *)0x41FEE0; + +typedef int __cdecl sub_5BEE40_t(); +static sub_5BEE40_t *sub_5BEE40 = (sub_5BEE40_t *)0x5BEE40; + +void Com_RunFrontend(); \ No newline at end of file diff --git a/components/game_mod/stdafx.h b/components/game_mod/stdafx.h index c4f7c59b..532a82e0 100644 --- a/components/game_mod/stdafx.h +++ b/components/game_mod/stdafx.h @@ -59,5 +59,7 @@ #include "reshade.h" +#include "mod_frontend.h" + #define GM_NET_VERSION 0x01 #define _USE_COM_DPRINTF 0 From 0ece11e329bb94dc511de4634fa1a00607d2ec01 Mon Sep 17 00:00:00 2001 From: Ray1235 Date: Wed, 5 Jul 2017 14:37:43 +0100 Subject: [PATCH 2/5] Added support for mod specific frontend levels --- components/game_mod/dllmain.cpp | 5 ++ components/game_mod/game_mod.vcxproj | 2 + components/game_mod/mod_frontend.cpp | 113 ++++++++++++--------------- components/game_mod/mod_frontend.h | 20 +++-- 4 files changed, 73 insertions(+), 67 deletions(-) diff --git a/components/game_mod/dllmain.cpp b/components/game_mod/dllmain.cpp index 2c850008..6974f8da 100644 --- a/components/game_mod/dllmain.cpp +++ b/components/game_mod/dllmain.cpp @@ -395,6 +395,11 @@ BOOL GameMod_Init() // PatchMemory_WithNOP(0x0068ABFA, 6); + // + // Add support for mod specific frontend levels (needs to be tested if coop lobbies work!) + // + Mod_Frontend_Init(); + // // Add Game_Mod Version info to the 'version' dvar // can be viewed via 'cg_drawVersion 1' diff --git a/components/game_mod/game_mod.vcxproj b/components/game_mod/game_mod.vcxproj index a583e1b3..678365c6 100644 --- a/components/game_mod/game_mod.vcxproj +++ b/components/game_mod/game_mod.vcxproj @@ -119,6 +119,7 @@ + @@ -187,6 +188,7 @@ + diff --git a/components/game_mod/mod_frontend.cpp b/components/game_mod/mod_frontend.cpp index 4c0cdf2e..fb4957e6 100644 --- a/components/game_mod/mod_frontend.cpp +++ b/components/game_mod/mod_frontend.cpp @@ -4,72 +4,63 @@ void Com_RunFrontend() { int v0; // esi@2 char v1; // al@9 - int v2; // esi@9 - int v3; // eax@11 + int localClientNum; // esi@9 + int controllerIndex; // eax@11 XZoneInfo zoneInfo; // [sp+408h] [bp-Ch]@6 // 0x38789A0 - xblive_matchEndingSoon Dvar_SetBool((dvar_s *)0x38789A0, false); func_41FEE0(); -#if 0 - Dvar_SetBool((dvar_s *)0x38789A0, false); - func_41FEE0(); - dvar_s *mapname = (dvar_s *)0x2899CEC; - dvar_s *sv_running = (dvar_s *)0x243FD3C; + char *currentMapname = (char *)Dvar_GetString("mapname"); - if (!mapname - || (!sv_running->current.enabled) - || I_strnicmp(currentMapname, "menu_", 5) && I_strcmp(currentMapname, "frontend")) + localClientNum = GetLocalClientNum(); + controllerIndex = UI_UIContext_GetInfo(localClientNum); + + Com_Printf(1, "Checking for mod_frontend\n"); + if (PartyClient_CheckMapExists("mod_frontend") && I_strcmp(currentMapname, "mod_frontend") != 0) { -#endif - /* - sub_51D1C0(localClientNum, 0.0); - if (useFastFile->current.enabled) - { - zoneInfo.name = 0; - zoneInfo.allocFlags = 0; - zoneInfo.freeFlags = 256; - DB_LoadXAssets(&zoneInfo, 1u, 0); - } - - if (wierd_var) - memset(wierd_var, 0, 263872 * com_maxclients->current.integer); - v1 = sub_569EE0(); - Dvar_SetInt(com_desiredMenu, v1); - */ - //Dvar_SetBool(systemlink_warning, 0); - //Dvar_SetBool(onlinegame, 0); - //Dvar_SetBool(zombiemode, 0); - //Dvar_SetBool(zombietron, 0); - //Dvar_SetBool(blackopsmode, 0); - //Dvar_SetBool(spmode, 0); - //Dvar_SetBool(arcademode, 0); - /* - v2 = sub_5BEE40(); - if (!Com_LocalClients_GetUsedControllerCount()) - sub_5B4CB0(v2, 1); - v3 = UI_UIContext_GetInfo(v2); - */ + Com_Printf(1, "mod_frontend exists. Loading mod_frontend...\n"); + Cmd_ExecuteSingleCommandInternal(localClientNum, controllerIndex, NULL, "map mod_frontend", false); // doing this until I find a better alternative + //Cbuf_ExecuteBuffer(localClientNum, controllerIndex, "map mod_frontend\n"); + } + else if (!PartyClient_CheckMapExists("mod_frontend") && I_strcmp(currentMapname, "frontend") != 0) + { + Com_Printf(1, "Loading frontend...\n"); + Cmd_ExecuteSingleCommandInternal(localClientNum, controllerIndex, NULL, "map frontend", false); // doing this until I find a better alternative + //Cbuf_ExecuteBuffer(localClientNum, controllerIndex, "map frontend\n"); + } +} - Com_Printf(1, "Getting sub_5BEE40 value\nsub_5BEE40() = "); - v2 = sub_5BEE40(); // why is localClientNum being this huge, I dont get it - // 1703388 - Com_Printf(1, "%d\nGetting UIContext Info\nUI_UIContext_GetInfo() = "); - v3 = UI_UIContext_GetInfo(v2); - Com_Printf(1, "%d\n", v3); - Com_Printf(1, "Checking for mod_frontend\n"); - if (PartyClient_CheckMapExists("mod_frontend")) - { - Com_Printf(1, "mod_frontend exists. Loading mod_frontend...\n"); - Cmd_ExecuteSingleCommandInternal(v2, v3, NULL, "map mod_frontend", false); // doing this until I find a better alternative - //Cbuf_ExecuteBuffer(v2, v3, "map mod_frontend\n"); - } - else - { - Com_Printf(1, "Loading frontend...\n"); - Cmd_ExecuteSingleCommandInternal(v2, v3, NULL, "map frontend", false); // doing this until I find a better alternative - //Cbuf_ExecuteBuffer(v2, v3, "map frontend\n"); - } -#if 0 +void UI_RunMod_HandleFrontend() +{ + int localClientNum; // esi@9 + int controllerIndex; // eax@11 + Com_Printf(1, "Getting GetLocalClientNum value\nsub_5BEE40() = "); + localClientNum = GetLocalClientNum(); // why is localClientNum being this huge, I dont get it + // 1703388 + Com_Printf(1, "%d\nGetting UIContext Info\nUI_UIContext_GetInfo() = "); + controllerIndex = UI_UIContext_GetInfo(localClientNum); + Cmd_ExecuteSingleCommandInternal(localClientNum, controllerIndex, NULL, "vid_restart_complete", false); + Cmd_ExecuteSingleCommandInternal(localClientNum, controllerIndex, NULL, "wait", false); + if (PartyClient_CheckMapExists("mod_frontend")) + { + Com_Printf(1, "mod_frontend exists. Loading mod_frontend...\n"); + Cmd_ExecuteSingleCommandInternal(localClientNum, controllerIndex, NULL, "map mod_frontend", false); // doing this until I find a better alternative + //Cbuf_ExecuteBuffer(localClientNum, controllerIndex, "map mod_frontend\n"); + } + else + { + Com_Printf(1, "Loading frontend...\n"); + Cmd_ExecuteSingleCommandInternal(localClientNum, controllerIndex, NULL, "map frontend", false); // doing this until I find a better alternative + //Cbuf_ExecuteBuffer(localClientNum, controllerIndex, "map frontend\n"); } -#endif -} \ No newline at end of file +} + +void Mod_Frontend_Init() +{ +#define PatchRunFrontend(addr, jmp) Detours::X86::DetourFunction((PBYTE)&Com_RunFrontend, (PBYTE)addr, jmp ? Detours::X86Option::USE_JUMP : Detours::X86Option::USE_CALL) + PatchRunFrontend(0x406B32, 0); + PatchRunFrontend(0x5A6C32, 1); + PatchRunFrontend(0x679018, 1); + + Detours::X86::DetourFunction((PBYTE)&UI_RunMod_HandleFrontend, (PBYTE)0x45CD7D, Detours::X86Option::USE_CALL); +} diff --git a/components/game_mod/mod_frontend.h b/components/game_mod/mod_frontend.h index 26abebb8..8a2605e4 100644 --- a/components/game_mod/mod_frontend.h +++ b/components/game_mod/mod_frontend.h @@ -3,15 +3,23 @@ typedef void __cdecl voidFunc(); typedef void __cdecl voidFunc2(int a1, float a2); -typedef void __cdecl Cbuf_ExecuteBuffer_t(int localClientNum, int controllerIndex, const char* buf); -static Cbuf_ExecuteBuffer_t *Cbuf_ExecuteBuffer = (Cbuf_ExecuteBuffer_t *)0x408A00; - -typedef int __cdecl UI_UIContext_GetInfo_t(int a1); +typedef int __cdecl UI_UIContext_GetInfo_t(int localClientNum); static UI_UIContext_GetInfo_t *UI_UIContext_GetInfo = (UI_UIContext_GetInfo_t *)0x4F3C70; static voidFunc *func_41FEE0 = (voidFunc *)0x41FEE0; typedef int __cdecl sub_5BEE40_t(); -static sub_5BEE40_t *sub_5BEE40 = (sub_5BEE40_t *)0x5BEE40; +static sub_5BEE40_t *GetLocalClientNum = (sub_5BEE40_t *)0x5BEE40; + +// XREFS +// call at 406B32 +// jmp at 5A6C32 +// jmp at 679018 +void Com_RunFrontend(); + +// XREFS +// replace the Cbuf_AddText call in UI_RunMenuScript +// call at 45CD7D +void UI_RunMod_HandleFrontend(); -void Com_RunFrontend(); \ No newline at end of file +void Mod_Frontend_Init(); From ad0ea27ff8de2b192cd74cf0c65ed4b371a414bc Mon Sep 17 00:00:00 2001 From: Ray1235 Date: Wed, 5 Jul 2017 15:26:38 +0100 Subject: [PATCH 3/5] needs to somehow fix game not being able to find mod frontend map --- components/game_mod/mod_frontend.cpp | 20 ++++++++++++++++---- components/game_mod/mod_frontend.h | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/components/game_mod/mod_frontend.cpp b/components/game_mod/mod_frontend.cpp index fb4957e6..fab768c0 100644 --- a/components/game_mod/mod_frontend.cpp +++ b/components/game_mod/mod_frontend.cpp @@ -9,6 +9,18 @@ void Com_RunFrontend() XZoneInfo zoneInfo; // [sp+408h] [bp-Ch]@6 // 0x38789A0 - xblive_matchEndingSoon Dvar_SetBool((dvar_s *)0x38789A0, false); + int desiredMenu = GetDesiredMenu(); + char desiredMenuStr[8]; + char falseStr[] = "0"; + itoa(desiredMenu, desiredMenuStr, 10); + Dvar_SetFromStringByName("com_desiredMenu", desiredMenuStr); + Dvar_SetFromStringByName("systemlink_warning", falseStr); + Dvar_SetFromStringByName("onlinegame", falseStr); + Dvar_SetFromStringByName("zombiemode", falseStr); + Dvar_SetFromStringByName("zombietron", falseStr); + Dvar_SetFromStringByName("blackopsmode", falseStr); + Dvar_SetFromStringByName("spmode", falseStr); + Dvar_SetFromStringByName("arcademode", falseStr); func_41FEE0(); char *currentMapname = (char *)Dvar_GetString("mapname"); @@ -19,14 +31,14 @@ void Com_RunFrontend() if (PartyClient_CheckMapExists("mod_frontend") && I_strcmp(currentMapname, "mod_frontend") != 0) { Com_Printf(1, "mod_frontend exists. Loading mod_frontend...\n"); - Cmd_ExecuteSingleCommandInternal(localClientNum, controllerIndex, NULL, "map mod_frontend", false); // doing this until I find a better alternative - //Cbuf_ExecuteBuffer(localClientNum, controllerIndex, "map mod_frontend\n"); + //Cmd_ExecuteSingleCommandInternal(localClientNum, controllerIndex, NULL, "map mod_frontend", false); // doing this until I find a better alternative + Cbuf_ExecuteBuffer(localClientNum, controllerIndex, "map mod_frontend\n"); } else if (!PartyClient_CheckMapExists("mod_frontend") && I_strcmp(currentMapname, "frontend") != 0) { Com_Printf(1, "Loading frontend...\n"); - Cmd_ExecuteSingleCommandInternal(localClientNum, controllerIndex, NULL, "map frontend", false); // doing this until I find a better alternative - //Cbuf_ExecuteBuffer(localClientNum, controllerIndex, "map frontend\n"); + //Cmd_ExecuteSingleCommandInternal(localClientNum, controllerIndex, NULL, "map frontend", false); // doing this until I find a better alternative + Cbuf_ExecuteBuffer(localClientNum, controllerIndex, "map frontend\n"); } } diff --git a/components/game_mod/mod_frontend.h b/components/game_mod/mod_frontend.h index 8a2605e4..df0baa89 100644 --- a/components/game_mod/mod_frontend.h +++ b/components/game_mod/mod_frontend.h @@ -11,6 +11,8 @@ static voidFunc *func_41FEE0 = (voidFunc *)0x41FEE0; typedef int __cdecl sub_5BEE40_t(); static sub_5BEE40_t *GetLocalClientNum = (sub_5BEE40_t *)0x5BEE40; +VANILLA_FUNC(GetDesiredMenu, int(__cdecl*)(), 0x569EE0); + // XREFS // call at 406B32 // jmp at 5A6C32 From e1e2d1cfa9b579b96aeabf977c8828f1daf30707 Mon Sep 17 00:00:00 2001 From: Maciej Zaremba Date: Thu, 28 Sep 2017 13:02:56 +0200 Subject: [PATCH 4/5] Cleanup --- components/game_mod/dllmain.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/components/game_mod/dllmain.cpp b/components/game_mod/dllmain.cpp index 9e0ad1cb..e8fb9652 100644 --- a/components/game_mod/dllmain.cpp +++ b/components/game_mod/dllmain.cpp @@ -380,13 +380,10 @@ BOOL GameMod_Init() Detours::X86::DetourFunction((PBYTE)0x006D98F0, (PBYTE)&hk_R_Cinematic_BinkOpen); // Ray - // Add Support for Mod Specific Frontend + // Add support for mod specific frontend levels (needs to be tested if coop lobbies work!) // - Detours::X86::DetourFunction((PBYTE)0x00406B32, (PBYTE)&Com_RunFrontend, Detours::X86Option::USE_CALL); - Detours::X86::DetourFunction((PBYTE)0x005A6C32, (PBYTE)&Com_RunFrontend, Detours::X86Option::USE_JUMP); - Detours::X86::DetourFunction((PBYTE)0x00679018, (PBYTE)&Com_RunFrontend, Detours::X86Option::USE_JUMP); - // 005A6C32 - jmp - // 00679018 - jmp + Mod_Frontend_Init(); + // // Enable Custom / Updated Commands // @@ -411,11 +408,6 @@ BOOL GameMod_Init() // PatchMemory_WithNOP(0x0068ABFA, 6); - // - // Add support for mod specific frontend levels (needs to be tested if coop lobbies work!) - // - Mod_Frontend_Init(); - // // Add Game_Mod Version info to the 'version' dvar // can be viewed via 'cg_drawVersion 1' @@ -656,4 +648,4 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv } return TRUE; -} \ No newline at end of file +} From 2af5d5b346f6c21f6ca13d525c3df3a860060187 Mon Sep 17 00:00:00 2001 From: Maciej Zaremba Date: Thu, 28 Sep 2017 13:03:01 +0200 Subject: [PATCH 5/5] Cleanup --- components/game_mod/mod_frontend.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/components/game_mod/mod_frontend.cpp b/components/game_mod/mod_frontend.cpp index fab768c0..422762de 100644 --- a/components/game_mod/mod_frontend.cpp +++ b/components/game_mod/mod_frontend.cpp @@ -69,10 +69,9 @@ void UI_RunMod_HandleFrontend() void Mod_Frontend_Init() { -#define PatchRunFrontend(addr, jmp) Detours::X86::DetourFunction((PBYTE)&Com_RunFrontend, (PBYTE)addr, jmp ? Detours::X86Option::USE_JUMP : Detours::X86Option::USE_CALL) - PatchRunFrontend(0x406B32, 0); - PatchRunFrontend(0x5A6C32, 1); - PatchRunFrontend(0x679018, 1); - + Detours::X86::DetourFunction((PBYTE)0x00406B32, (PBYTE)&Com_RunFrontend, Detours::X86Option::USE_CALL); + Detours::X86::DetourFunction((PBYTE)0x005A6C32, (PBYTE)&Com_RunFrontend, Detours::X86Option::USE_JUMP); + Detours::X86::DetourFunction((PBYTE)0x00679018, (PBYTE)&Com_RunFrontend, Detours::X86Option::USE_JUMP); + Detours::X86::DetourFunction((PBYTE)&UI_RunMod_HandleFrontend, (PBYTE)0x45CD7D, Detours::X86Option::USE_CALL); }