From 34a28c6fa04c5888c4e687c5e11da185613caa85 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sun, 3 Dec 2023 20:56:17 +0100 Subject: stash: console hook --- src/CMakeLists.txt | 2 ++ src/hook.cpp | 17 +++++++++++++++++ src/hook.h | 6 ++++++ src/init.cpp | 10 ++++++++-- src/internal/engine/consoledialog.h | 16 ++++++++++++++++ src/internal/engine/gameconsole.h | 9 +++++++++ src/internal/engine/gameconsoledialog.h | 7 +++++++ src/internal/engine/public/icvar.h | 15 +++++++++++++++ 8 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/hook.cpp create mode 100644 src/hook.h create mode 100644 src/internal/engine/consoledialog.h create mode 100644 src/internal/engine/gameconsole.h create mode 100644 src/internal/engine/gameconsoledialog.h create mode 100644 src/internal/engine/public/icvar.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0cf8952..6ebae81 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,6 +17,8 @@ add_library(SouthRPC SHARED "${CMAKE_CURRENT_SOURCE_DIR}/handler.h" "${CMAKE_CURRENT_SOURCE_DIR}/helper.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/helper.h" + "${CMAKE_CURRENT_SOURCE_DIR}/hook.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/hook.h" "${CMAKE_CURRENT_SOURCE_DIR}/http_server.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/http_server.h" "${CMAKE_CURRENT_SOURCE_DIR}/rpc_server.cpp" diff --git a/src/hook.cpp b/src/hook.cpp new file mode 100644 index 0000000..484ea76 --- /dev/null +++ b/src/hook.cpp @@ -0,0 +1,17 @@ +#include "internal/engine/gameconsole.h" + +#include "ns_plugin.h" + +extern "C" { + typedef void* (*CreateInterface)(const char *pName, int *pReturnCode); +} + +void hook_console_print(HMODULE dllPtr) +{ + assert(dllPtr); + + CreateInterface pCreateInterface = (CreateInterface)GetProcAddress(dllPtr, "CreateInterface"); + assert(pCreateInterface); + + CGameConsole* pGameConsole = (CGameConsole*)pCreateInterface("GameConsole004", NULL); +} diff --git a/src/hook.h b/src/hook.h new file mode 100644 index 0000000..f05498c --- /dev/null +++ b/src/hook.h @@ -0,0 +1,6 @@ +#ifndef HOOK_H +#define HOOK_H + +void hook_console_print(HMODULE dllPtr); + +#endif \ No newline at end of file diff --git a/src/init.cpp b/src/init.cpp index 36aea76..08ce034 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2,6 +2,7 @@ #include "internal/logging.h" #include "plugin.h" +#include "hook.h" Plugin* plugin = nullptr; @@ -24,10 +25,15 @@ void PLUGIN_DEINIT() } extern "C" __declspec(dllexport) -void PLUGIN_INFORM_DLL_LOAD(const char* dll, PluginEngineData* data, void* dllPtr) { +void PLUGIN_INFORM_DLL_LOAD(const char* dll, PluginEngineData* data, void* dllPtr) +{ assert(plugin); - if (!strcmp(dll, "engine.dll")) + if (!strcmp(dll, "client.dll")) + { + hook_console_print((HMODULE)dllPtr); + } + else if (!strcmp(dll, "engine.dll")) { plugin->LoadEngineData(data, (HMODULE)dllPtr); plugin->StartServer(); diff --git a/src/internal/engine/consoledialog.h b/src/internal/engine/consoledialog.h new file mode 100644 index 0000000..b256c16 --- /dev/null +++ b/src/internal/engine/consoledialog.h @@ -0,0 +1,16 @@ + +#include "internal/engine/public/icvar.h" + +typedef struct CConsolePanel { + // has no own vtable + + char padding[0x2B4]; + IConsoleDisplayFunc* _derived2; +} CConsolePanel; + +typedef struct CConsoleDialog { + void* vtable; + + char padding[0x394]; // some vgui stuff we don't care about + CConsolePanel* m_pConsolePanel; +} CConsoleDialog; diff --git a/src/internal/engine/gameconsole.h b/src/internal/engine/gameconsole.h new file mode 100644 index 0000000..ce8f957 --- /dev/null +++ b/src/internal/engine/gameconsole.h @@ -0,0 +1,9 @@ + +#include "internal/engine/gameconsoledialog.h" + +typedef struct CGameConsole { + void* vtable; + + bool m_bInitialized; + CGameConsoleDialog* m_pConsole; +} CGameConsole; diff --git a/src/internal/engine/gameconsoledialog.h b/src/internal/engine/gameconsoledialog.h new file mode 100644 index 0000000..f179f22 --- /dev/null +++ b/src/internal/engine/gameconsoledialog.h @@ -0,0 +1,7 @@ + +#include "internal/engine/consoledialog.h" + +typedef struct CGameConsoleDialog { + void* vtable; + CConsoleDialog _derived; +} CGameConsoleDialog; diff --git a/src/internal/engine/public/icvar.h b/src/internal/engine/public/icvar.h new file mode 100644 index 0000000..e72c64b --- /dev/null +++ b/src/internal/engine/public/icvar.h @@ -0,0 +1,15 @@ +// derived from https://github.com/ValveSoftware/source-sdk-2013/blob/0d8dceea4310fde5706b3ce1c70609d72a38efdf/mp/src/public/icvar.h + +typedef struct IConsoleDisplayFunc { + struct { + //virtual void ColorPrint( const Color& clr, const char *pMessage ) = 0; + void* ColorPrint; + + //virtual void Print( const char *pMessage ) = 0; + void (*Print)(struct IConsoleDisplayFunc* instance, const char* pMessage); + + //virtual void DPrint( const char *pMessage ) = 0; + void (*DPrint)(struct IConsoleDisplayFunc* instance, const char* pMessage); + }* vtable; + +} IConsoleDisplayFunc; -- cgit v1.2.3