diff --git a/r5dev/include/patterns.h b/r5dev/include/patterns.h index f2da1744..53d28bd7 100644 --- a/r5dev/include/patterns.h +++ b/r5dev/include/patterns.h @@ -38,22 +38,29 @@ namespace DWORD64 p_NET_SendDatagram = FindPattern("r5apex.exe", (const unsigned char*)"\x48\x89\x5C\x24\x08\x48\x89\x6C\x24\x10\x48\x89\x74\x24\x18\x57\x41\x56\x41\x57\x48\x81\xEC\x00\x05\x00\x00", "xxxxxxxxxxxxxxxxxxxxxxx?xxx"); int (*NET_SendDatagram)(SOCKET s, const char* buf, int len, int flags) = (int (*)(SOCKET, const char*, int, int))p_NET_SendDatagram; /*48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 41 56 41 57 48 81 EC ?? 05 00 00*/ + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /* ==== UTILITY ========================================================================================================================================================= */ + DWORD64 p_MSG_EngineError = FindPattern("r5apex.exe", (const unsigned char*)"\x48\x89\x5C\x24\x08\x48\x89\x74\x24\x10\x57\x48\x81\xEC\x30\x08\x00\x00\x48\x8B\xDA\x48\x8B\xF9\xE8\x00\x00\x00\xFF\x33\xF6\x48", "xxxxxxxxxxxxxxxxxxxxxxxxx???xxxx"); + int (*MSG_EngineError)(char* fmt, va_list args) = (int (*)(char*, va_list))p_MSG_EngineError; /*48 89 5C 24 08 48 89 74 24 10 57 48 81 EC 30 08 00 00 48 8B DA 48 8B F9 E8 ?? ?? ?? FF 33 F6 48*/ + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* ==== ------- ========================================================================================================================================================= */ void PrintHAddress() // Test the sigscan results { std::cout << "+--------------------------------------------------------+" << std::endl; - std::cout << "| p_CommandExecute : " << std::hex << p_CommandExecute << std::setw(20) << " |" << std::endl; - std::cout << "| p_ConVar_IsFlagSet : " << std::hex << p_ConVar_IsFlagSet << std::setw(20) << " |" << std::endl; - std::cout << "| p_ConCommand_IsFlagSet : " << std::hex << p_ConCommand_IsFlagSet << std::setw(20) << " |" << std::endl; + std::cout << "| CommandExecute : " << std::hex << p_CommandExecute << std::setw(20) << " |" << std::endl; + std::cout << "| ConVar_IsFlagSet : " << std::hex << p_ConVar_IsFlagSet << std::setw(20) << " |" << std::endl; + std::cout << "| ConCommand_IsFlagSet : " << std::hex << p_ConCommand_IsFlagSet << std::setw(20) << " |" << std::endl; std::cout << "+--------------------------------------------------------+" << std::endl; - std::cout << "| p_SQVM_Print : " << std::hex << p_SQVM_Print << std::setw(20) << " |" << std::endl; - std::cout << "| p_SQVM_LoadScript : " << std::hex << p_SQVM_LoadScript << std::setw(20) << " |" << std::endl; - std::cout << "| p_SQVM_LoadRson : " << std::hex << p_SQVM_LoadRson << std::setw(20) << " |" << std::endl; + std::cout << "| SQVM_Print : " << std::hex << p_SQVM_Print << std::setw(20) << " |" << std::endl; + std::cout << "| SQVM_LoadScript : " << std::hex << p_SQVM_LoadScript << std::setw(20) << " |" << std::endl; + std::cout << "| SQVM_LoadRson : " << std::hex << p_SQVM_LoadRson << std::setw(20) << " |" << std::endl; std::cout << "+--------------------------------------------------------+" << std::endl; - std::cout << "| p_NET_ReceiveDatagram : " << std::hex << p_NET_ReceiveDatagram << std::setw(20) << " |" << std::endl; - std::cout << "| p_NET_SendDatagram : " << std::hex << p_NET_SendDatagram << std::setw(20) << " |" << std::endl; + std::cout << "| NET_ReceiveDatagram : " << std::hex << p_NET_ReceiveDatagram << std::setw(20) << " |" << std::endl; + std::cout << "| NET_SendDatagram : " << std::hex << p_NET_SendDatagram << std::setw(20) << " |" << std::endl; + std::cout << "+--------------------------------------------------------+" << std::endl; + std::cout << "| MSG_EngineError : " << std::hex << p_NET_SendDatagram << std::setw(20) << " |" << std::endl; std::cout << "+--------------------------------------------------------+" << std::endl; // TODO implement error handling when sigscan fails or result is 0 diff --git a/r5dev/src/console.cpp b/r5dev/src/console.cpp index bbb861cc..e322b91e 100644 --- a/r5dev/src/console.cpp +++ b/r5dev/src/console.cpp @@ -5,6 +5,7 @@ #include <Windows.h> #include <detours.h> +#include "id3dx.h" #include "hooks.h" #include "opcptc.h" #include "console.h" @@ -131,6 +132,7 @@ DWORD __stdcall ProcessConsoleWorker(LPVOID) /////////////////////////////////////////////////////////////////////// // Debug toggles if (sCommand == "pattern test") { PrintHAddress(); PrintOAddress(); continue; } + if (sCommand == "directx test") { PrintDXAddress(); continue; } if (sCommand == "console test") { g_bDebugConsole = !g_bDebugConsole; continue; } /////////////////////////////////////////////////////////////////////// // Exec toggles diff --git a/r5dev/src/hooks.cpp b/r5dev/src/hooks.cpp index 31a76e3d..81042f2e 100644 --- a/r5dev/src/hooks.cpp +++ b/r5dev/src/hooks.cpp @@ -127,6 +127,20 @@ bool HSQVM_LoadScript(void* sqvm, const char* script_path, const char* script_na return SQVM_LoadScript(sqvm, script_path, script_name, flag); } +//################################################################################# +// UTILITY HOOKS +//################################################################################# + +int HMSG_EngineError(char* fmt, va_list args) +{ + char buf[1024]; + vprintf(fmt, args); + vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args); + buf[IM_ARRAYSIZE(buf) - 1] = 0; + Items.push_back(Strdup(buf)); + return MSG_EngineError(fmt, args); +} + //################################################################################# // MANAGEMENT //################################################################################# @@ -139,11 +153,15 @@ void InstallENHooks() DetourUpdateThread(GetCurrentThread()); /////////////////////////////////////////////////////////////////////////////// - // Hook Engine functions + // Hook Squirrel functions DetourAttach((LPVOID*)&SQVM_Print, &HSQVM_Print); DetourAttach((LPVOID*)&SQVM_LoadRson, &HSQVM_LoadRson); DetourAttach((LPVOID*)&SQVM_LoadScript, &HSQVM_LoadScript); + /////////////////////////////////////////////////////////////////////////////// + // Hook Utility functions + DetourAttach((LPVOID*)&MSG_EngineError, &HMSG_EngineError); + /////////////////////////////////////////////////////////////////////////////// // Commit the transaction if (DetourTransactionCommit() != NO_ERROR) @@ -171,6 +189,10 @@ void RemoveENHooks() DetourDetach((LPVOID*)&NET_SendDatagram, &HNET_SendDatagram); DetourDetach((LPVOID*)&NET_ReceiveDatagram, &HNET_ReceiveDatagram); + /////////////////////////////////////////////////////////////////////////////// + // Unhook Utility functions + DetourDetach((LPVOID*)&MSG_EngineError, &HMSG_EngineError); + /////////////////////////////////////////////////////////////////////////////// // Commit the transaction DetourTransactionCommit(); diff --git a/r5dev/src/id3dx.cpp b/r5dev/src/id3dx.cpp index 66aa03cc..ae3ad859 100644 --- a/r5dev/src/id3dx.cpp +++ b/r5dev/src/id3dx.cpp @@ -453,11 +453,11 @@ void RemoveDXHooks() void PrintDXAddress() { std::cout << "+--------------------------------------------------------+" << std::endl; - std::cout << "| ID3D11DeviceContext : " << std::hex << g_pDeviceContext << std::endl; - std::cout << "| ID3D11Device : " << std::hex << g_pDevice << std::endl; - std::cout << "| ID3D11RenderTargetView : " << std::hex << g_pRenderTargetView << std::endl; - std::cout << "| IDXGISwapChain : " << std::hex << g_pSwapChain << std::endl; - std::cout << "| IDXGISwapChainPresent : " << std::hex << g_fnIDXGISwapChainPresent << std::endl; + std::cout << "| ID3D11DeviceContext : " << std::hex << g_pDeviceContext << std::setw(13) << " |" << std::endl; + std::cout << "| ID3D11Device : " << std::hex << g_pDevice << std::setw(13) << " |" << std::endl; + std::cout << "| ID3D11RenderTargetView : " << std::hex << g_pRenderTargetView << std::setw(13) << " |" << std::endl; + std::cout << "| IDXGISwapChain : " << std::hex << g_pSwapChain << std::setw(13) << " |" << std::endl; + std::cout << "| IDXGISwapChainPresent : " << std::hex << g_fnIDXGISwapChainPresent << std::setw(13) << " |" << std::endl; std::cout << "+--------------------------------------------------------+" << std::endl; } diff --git a/r5launcher/main.cpp b/r5launcher/main.cpp index 84b885ec..e8d60650 100644 --- a/r5launcher/main.cpp +++ b/r5launcher/main.cpp @@ -119,6 +119,7 @@ bool LaunchR5Apex() /////////////////////////////////////////////////////////////////////////////// // Entrypoint. +/////////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[], char* envp[]) { LaunchR5Apex();