mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Move console hook management to own implementation
+ Function renaming
This commit is contained in:
parent
48766c23d9
commit
7495f1b4fa
@ -3,11 +3,12 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Initialization
|
// Initialization
|
||||||
void SetupConsole();
|
void SetupConsole();
|
||||||
|
void RemoveCMHooks();
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Hooks
|
// Hooks
|
||||||
bool Hook_ConVar_IsFlagSet(int** cvar, int flag);
|
bool HConVar_IsFlagSet(int** cvar, int flag);
|
||||||
bool Hook_ConCommand_IsFlagSet(int* cmd, int flag);
|
bool HConCommand_IsFlagSet(int* cmd, int flag);
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Globals
|
// Globals
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Initialization
|
// Initialization
|
||||||
void InstallHooks();
|
void InstallENHooks();
|
||||||
void RemoveHooks();
|
void RemoveENHooks();
|
||||||
void ToggleDevCommands();
|
void ToggleDevCommands();
|
||||||
void ToggleNetHooks();
|
void ToggleNetHooks();
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ void SetupConsole()
|
|||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool Hook_ConVar_IsFlagSet(int** cvar, int flag)
|
bool HConVar_IsFlagSet(int** cvar, int flag)
|
||||||
{
|
{
|
||||||
int real_flags = *(*(cvar + (72 / (sizeof(void*)))) + (56 / sizeof(int)));
|
int real_flags = *(*(cvar + (72 / (sizeof(void*)))) + (56 / sizeof(int)));
|
||||||
if (g_bDebugConsole)
|
if (g_bDebugConsole)
|
||||||
@ -89,7 +89,7 @@ bool Hook_ConVar_IsFlagSet(int** cvar, int flag)
|
|||||||
else { return false; }
|
else { return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Hook_ConCommand_IsFlagSet(int* cmd, int flag)
|
bool HConCommand_IsFlagSet(int* cmd, int flag)
|
||||||
{
|
{
|
||||||
int real_flags = *((cmd + (56 / sizeof(int))));
|
int real_flags = *((cmd + (56 / sizeof(int))));
|
||||||
if (g_bDebugConsole)
|
if (g_bDebugConsole)
|
||||||
@ -155,3 +155,69 @@ DWORD __stdcall ProcessConsoleWorker(LPVOID)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
// Management
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void RemoveCMHooks()
|
||||||
|
{
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Begin the detour transaction, to unhook the the process
|
||||||
|
DetourTransactionBegin();
|
||||||
|
DetourUpdateThread(GetCurrentThread());
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Unhook Console functions
|
||||||
|
DetourDetach((LPVOID*)&ConVar_IsFlagSet, &HConVar_IsFlagSet);
|
||||||
|
DetourDetach((LPVOID*)&ConCommand_IsFlagSet, &HConCommand_IsFlagSet);
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Commit the transaction
|
||||||
|
DetourTransactionCommit();
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
// Toggles
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void ToggleDevCommands()
|
||||||
|
{
|
||||||
|
static bool g_dev = false;
|
||||||
|
|
||||||
|
DetourTransactionBegin();
|
||||||
|
DetourUpdateThread(GetCurrentThread());
|
||||||
|
|
||||||
|
if (!g_dev)
|
||||||
|
{
|
||||||
|
DetourAttach((LPVOID*)&ConVar_IsFlagSet, &HConVar_IsFlagSet);
|
||||||
|
DetourAttach((LPVOID*)&ConCommand_IsFlagSet, &HConCommand_IsFlagSet);
|
||||||
|
printf("\n");
|
||||||
|
printf("+--------------------------------------------------------+\n");
|
||||||
|
printf("|>>>>>>>>>>>>>| DEVONLY COMMANDS ACTIVATED |<<<<<<<<<<<<<|\n");
|
||||||
|
printf("+--------------------------------------------------------+\n");
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DetourDetach((LPVOID*)&ConVar_IsFlagSet, &HConVar_IsFlagSet);
|
||||||
|
DetourDetach((LPVOID*)&ConCommand_IsFlagSet, &HConCommand_IsFlagSet);
|
||||||
|
printf("\n");
|
||||||
|
printf("+--------------------------------------------------------+\n");
|
||||||
|
printf("|>>>>>>>>>>>>| DEVONLY COMMANDS DEACTIVATED |<<<<<<<<<<<<|\n");
|
||||||
|
printf("+--------------------------------------------------------+\n");
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DetourTransactionCommit() != NO_ERROR)
|
||||||
|
{
|
||||||
|
TerminateProcess(GetCurrentProcess(), 0xBAD0C0DE);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_dev = !g_dev;
|
||||||
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
void InitializeR5Dev()
|
void InitializeR5Dev()
|
||||||
{
|
{
|
||||||
SetupConsole();
|
SetupConsole();
|
||||||
InstallHooks();
|
InstallENHooks();
|
||||||
InstallIPHooks();
|
InstallIPHooks();
|
||||||
InstallDXHooks();
|
InstallDXHooks();
|
||||||
InstallOpcodes();
|
InstallOpcodes();
|
||||||
@ -31,7 +31,8 @@ void InitializeR5Dev()
|
|||||||
|
|
||||||
void TerminateR5Dev()
|
void TerminateR5Dev()
|
||||||
{
|
{
|
||||||
RemoveHooks();
|
RemoveCMHooks();
|
||||||
|
RemoveENHooks();
|
||||||
RemoveIPHooks();
|
RemoveIPHooks();
|
||||||
RemoveDXHooks();
|
RemoveDXHooks();
|
||||||
FreeConsole();
|
FreeConsole();
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include "patterns.h"
|
#include "patterns.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
#include "structs.h"
|
#include "structs.h"
|
||||||
#include "console.h"
|
|
||||||
#include "overlay.h"
|
#include "overlay.h"
|
||||||
#include "hooks.h"
|
#include "hooks.h"
|
||||||
|
|
||||||
@ -17,7 +16,7 @@
|
|||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool Hook_NET_ReceiveDatagram(int sock, void* inpacket, bool raw)
|
bool HNET_ReceiveDatagram(int sock, void* inpacket, bool raw)
|
||||||
{
|
{
|
||||||
bool result = NET_ReceiveDatagram(sock, inpacket, raw);
|
bool result = NET_ReceiveDatagram(sock, inpacket, raw);
|
||||||
if (result)
|
if (result)
|
||||||
@ -33,7 +32,7 @@ bool Hook_NET_ReceiveDatagram(int sock, void* inpacket, bool raw)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int Hook_NET_SendDatagram(SOCKET s, const char* buf, int len, int flags)
|
unsigned int HNET_SendDatagram(SOCKET s, const char* buf, int len, int flags)
|
||||||
{
|
{
|
||||||
unsigned int result = NET_SendDatagram(s, buf, len, flags);
|
unsigned int result = NET_SendDatagram(s, buf, len, flags);
|
||||||
if (result)
|
if (result)
|
||||||
@ -52,7 +51,7 @@ unsigned int Hook_NET_SendDatagram(SOCKET s, const char* buf, int len, int flags
|
|||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void* Hook_SQVM_Print(void* sqvm, char* fmt, ...)
|
void* HSQVM_Print(void* sqvm, char* fmt, ...)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
va_list args;
|
va_list args;
|
||||||
@ -65,7 +64,7 @@ void* Hook_SQVM_Print(void* sqvm, char* fmt, ...)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
__int64 Hook_SQVM_LoadRson(const char* rson_name)
|
__int64 HSQVM_LoadRson(const char* rson_name)
|
||||||
{
|
{
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("##################################################\n");
|
printf("##################################################\n");
|
||||||
@ -75,7 +74,7 @@ __int64 Hook_SQVM_LoadRson(const char* rson_name)
|
|||||||
return SQVM_LoadRson(rson_name);
|
return SQVM_LoadRson(rson_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Hook_SQVM_LoadScript(void* sqvm, const char* script_path, const char* script_name, int flag)
|
bool HSQVM_LoadScript(void* sqvm, const char* script_path, const char* script_name, int flag)
|
||||||
{
|
{
|
||||||
char filepath[MAX_PATH] = { 0 };
|
char filepath[MAX_PATH] = { 0 };
|
||||||
sprintf_s(filepath, MAX_PATH, "platform\\%s", script_path);
|
sprintf_s(filepath, MAX_PATH, "platform\\%s", script_path);
|
||||||
@ -112,17 +111,19 @@ bool Hook_SQVM_LoadScript(void* sqvm, const char* script_path, const char* scrip
|
|||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void InstallHooks()
|
void InstallENHooks()
|
||||||
{
|
{
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Begin the detour transaction
|
// Begin the detour transaction
|
||||||
DetourTransactionBegin();
|
DetourTransactionBegin();
|
||||||
DetourUpdateThread(GetCurrentThread());
|
DetourUpdateThread(GetCurrentThread());
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Hook Engine functions
|
// Hook Engine functions
|
||||||
DetourAttach((LPVOID*)&SQVM_Print, &Hook_SQVM_Print);
|
DetourAttach((LPVOID*)&SQVM_Print, &HSQVM_Print);
|
||||||
DetourAttach((LPVOID*)&SQVM_LoadRson, &Hook_SQVM_LoadRson);
|
DetourAttach((LPVOID*)&SQVM_LoadRson, &HSQVM_LoadRson);
|
||||||
DetourAttach((LPVOID*)&SQVM_LoadScript, &Hook_SQVM_LoadScript);
|
DetourAttach((LPVOID*)&SQVM_LoadScript, &HSQVM_LoadScript);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Commit the transaction
|
// Commit the transaction
|
||||||
if (DetourTransactionCommit() != NO_ERROR)
|
if (DetourTransactionCommit() != NO_ERROR)
|
||||||
@ -132,25 +133,24 @@ void InstallHooks()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveHooks()
|
void RemoveENHooks()
|
||||||
{
|
{
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Begin the detour transaction, to unhook the the process
|
// Begin the detour transaction, to unhook the the process
|
||||||
DetourTransactionBegin();
|
DetourTransactionBegin();
|
||||||
DetourUpdateThread(GetCurrentThread());
|
DetourUpdateThread(GetCurrentThread());
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Unhook Squirrel functions
|
// Unhook Squirrel functions
|
||||||
DetourDetach((LPVOID*)&SQVM_Print, &Hook_SQVM_Print);
|
DetourDetach((LPVOID*)&SQVM_Print, &HSQVM_Print);
|
||||||
DetourDetach((LPVOID*)&SQVM_LoadRson, &Hook_SQVM_LoadRson);
|
DetourDetach((LPVOID*)&SQVM_LoadRson, &HSQVM_LoadRson);
|
||||||
DetourDetach((LPVOID*)&SQVM_LoadScript, &Hook_SQVM_LoadScript);
|
DetourDetach((LPVOID*)&SQVM_LoadScript, &HSQVM_LoadScript);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Unhook Netchan functions
|
// Unhook Netchan functions
|
||||||
DetourDetach((LPVOID*)&NET_SendDatagram, &Hook_NET_SendDatagram);
|
DetourDetach((LPVOID*)&NET_SendDatagram, &HNET_SendDatagram);
|
||||||
DetourDetach((LPVOID*)&NET_ReceiveDatagram, &Hook_NET_ReceiveDatagram);
|
DetourDetach((LPVOID*)&NET_ReceiveDatagram, &HNET_ReceiveDatagram);
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Unhook Console functions
|
|
||||||
DetourDetach((LPVOID*)&ConVar_IsFlagSet, &Hook_ConVar_IsFlagSet);
|
|
||||||
DetourDetach((LPVOID*)&ConCommand_IsFlagSet, &Hook_ConCommand_IsFlagSet);
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Commit the transaction
|
// Commit the transaction
|
||||||
DetourTransactionCommit();
|
DetourTransactionCommit();
|
||||||
@ -171,8 +171,8 @@ void ToggleNetHooks()
|
|||||||
|
|
||||||
if (!g_net)
|
if (!g_net)
|
||||||
{
|
{
|
||||||
DetourAttach((LPVOID*)&NET_SendDatagram, &Hook_NET_SendDatagram);
|
DetourAttach((LPVOID*)&NET_SendDatagram, &HNET_SendDatagram);
|
||||||
DetourAttach((LPVOID*)&NET_ReceiveDatagram, &Hook_NET_ReceiveDatagram);
|
DetourAttach((LPVOID*)&NET_ReceiveDatagram, &HNET_ReceiveDatagram);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("+--------------------------------------------------------+\n");
|
printf("+--------------------------------------------------------+\n");
|
||||||
printf("|>>>>>>>>>>>>>| NETCHANNEL TRACE ACTIVATED |<<<<<<<<<<<<<|\n");
|
printf("|>>>>>>>>>>>>>| NETCHANNEL TRACE ACTIVATED |<<<<<<<<<<<<<|\n");
|
||||||
@ -181,8 +181,8 @@ void ToggleNetHooks()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DetourDetach((LPVOID*)&NET_SendDatagram, &Hook_NET_SendDatagram);
|
DetourDetach((LPVOID*)&NET_SendDatagram, &HNET_SendDatagram);
|
||||||
DetourDetach((LPVOID*)&NET_ReceiveDatagram, &Hook_NET_ReceiveDatagram);
|
DetourDetach((LPVOID*)&NET_ReceiveDatagram, &HNET_ReceiveDatagram);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("+--------------------------------------------------------+\n");
|
printf("+--------------------------------------------------------+\n");
|
||||||
printf("|>>>>>>>>>>>>| NETCHANNEL TRACE DEACTIVATED |<<<<<<<<<<<<|\n");
|
printf("|>>>>>>>>>>>>| NETCHANNEL TRACE DEACTIVATED |<<<<<<<<<<<<|\n");
|
||||||
@ -197,40 +197,3 @@ void ToggleNetHooks()
|
|||||||
|
|
||||||
g_net = !g_net;
|
g_net = !g_net;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToggleDevCommands()
|
|
||||||
{
|
|
||||||
static bool g_dev = false;
|
|
||||||
|
|
||||||
DetourTransactionBegin();
|
|
||||||
DetourUpdateThread(GetCurrentThread());
|
|
||||||
|
|
||||||
if (!g_dev)
|
|
||||||
{
|
|
||||||
DetourAttach((LPVOID*)&ConVar_IsFlagSet, &Hook_ConVar_IsFlagSet);
|
|
||||||
DetourAttach((LPVOID*)&ConCommand_IsFlagSet, &Hook_ConCommand_IsFlagSet);
|
|
||||||
printf("\n");
|
|
||||||
printf("+--------------------------------------------------------+\n");
|
|
||||||
printf("|>>>>>>>>>>>>>| DEVONLY COMMANDS ACTIVATED |<<<<<<<<<<<<<|\n");
|
|
||||||
printf("+--------------------------------------------------------+\n");
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DetourDetach((LPVOID*)&ConVar_IsFlagSet, &Hook_ConVar_IsFlagSet);
|
|
||||||
DetourDetach((LPVOID*)&ConCommand_IsFlagSet, &Hook_ConCommand_IsFlagSet);
|
|
||||||
printf("\n");
|
|
||||||
printf("+--------------------------------------------------------+\n");
|
|
||||||
printf("|>>>>>>>>>>>>| DEVONLY COMMANDS DEACTIVATED |<<<<<<<<<<<<|\n");
|
|
||||||
printf("+--------------------------------------------------------+\n");
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DetourTransactionCommit() != NO_ERROR)
|
|
||||||
{
|
|
||||||
TerminateProcess(GetCurrentProcess(), 0xBAD0C0DE);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_dev = !g_dev;
|
|
||||||
}
|
|
||||||
|
@ -61,7 +61,7 @@ LRESULT CALLBACK DXGIMsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK hWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK HWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
if (uMsg == WM_KEYDOWN)
|
if (uMsg == WM_KEYDOWN)
|
||||||
{
|
{
|
||||||
@ -370,7 +370,7 @@ HRESULT __stdcall Present(IDXGISwapChain* pSwapChain, UINT nSyncInterval, UINT n
|
|||||||
|
|
||||||
if (g_oWndProc == nullptr)
|
if (g_oWndProc == nullptr)
|
||||||
{ // Only initialize hWndProc pointer once to avoid stack overflow during ResizeBuffers(..)
|
{ // Only initialize hWndProc pointer once to avoid stack overflow during ResizeBuffers(..)
|
||||||
g_oWndProc = (WNDPROC)SetWindowLongPtr(g_hGameWindow, GWLP_WNDPROC, (LONG_PTR)hWndProc);
|
g_oWndProc = (WNDPROC)SetWindowLongPtr(g_hGameWindow, GWLP_WNDPROC, (LONG_PTR)HWndProc);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_bInitialized = true;
|
g_bInitialized = true;
|
||||||
|
@ -369,7 +369,6 @@ public:
|
|||||||
for (int i = first > 0 ? first : 0; i < History.Size; i++) { AddLog("%3d: %s\n", i, History[i]); }
|
for (int i = first > 0 ? first : 0; i < History.Size; i++) { AddLog("%3d: %s\n", i, History[i]); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// On command input, we scroll to bottom even if AutoScroll==false
|
|
||||||
ScrollToBottom = true;
|
ScrollToBottom = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user