Fix code errors and comments

This commit is contained in:
Amos 2021-06-28 15:51:32 -07:00
parent 53721b2d69
commit 435c48695f
6 changed files with 108 additions and 133 deletions

View File

@ -10,15 +10,13 @@
#include "console.h"
#include "patterns.h"
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// Initialization
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#############################################################################
// INITIALIZATION
//#############################################################################
void SetupConsole()
{
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// Create the console window
if (AllocConsole() == FALSE)
{
@ -26,7 +24,7 @@ void SetupConsole()
return;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// Set the window title
FILE* sBuildTxt;
CHAR sBuildBuf[1024] = { 0 };
@ -41,14 +39,14 @@ void SetupConsole()
}
SetConsoleTitle(sBuildBuf);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// Open input/output streams
FILE* fDummy;
freopen_s(&fDummy, "CONIN$", "r", stdin);
freopen_s(&fDummy, "CONOUT$", "w", stdout);
freopen_s(&fDummy, "CONOUT$", "w", stderr);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// Create a worker thread to process console commands
DWORD threadId0;
DWORD __stdcall ProcessConsoleWorker(LPVOID);
@ -61,11 +59,9 @@ void SetupConsole()
}
}
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// Hooks
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#############################################################################
// CONSOLE HOOKS
//#############################################################################
bool HConVar_IsFlagSet(int** cvar, int flag)
{
@ -111,11 +107,9 @@ bool HConCommand_IsFlagSet(int* cmd, int flag)
else { return false; }
}
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// Worker
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#############################################################################
// WORKER THREAD
//#############################################################################
DWORD __stdcall ProcessConsoleWorker(LPVOID)
{
@ -124,31 +118,31 @@ DWORD __stdcall ProcessConsoleWorker(LPVOID)
{
std::string sCommand;
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Get the user input on the debug console
printf(">");
std::getline(std::cin, sCommand);
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Engine toggles
if (sCommand == "toggle net") { ToggleNetHooks(); continue; }
if (sCommand == "toggle dev") { ToggleDevCommands(); continue; }
if (sCommand == "toggle fal") { g_bReturnAllFalse = !g_bReturnAllFalse; continue; }
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Debug toggles
if (sCommand == "pattern test") { PrintHAddress(); PrintOAddress(); continue; }
if (sCommand == "console test") { g_bDebugConsole = !g_bDebugConsole; continue; }
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Exec toggles
if (sCommand == "1") { ToggleDevCommands(); CommandExecute(NULL, "exec autoexec_dev"); }
if (sCommand == "2") { g_bDebugLoading = !g_bDebugLoading; continue; }
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Execute the command in the r5 SQVM
CommandExecute(NULL, sCommand.c_str());
sCommand.clear();
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Sleep and loop
Sleep(50);
}
@ -156,34 +150,30 @@ DWORD __stdcall ProcessConsoleWorker(LPVOID)
return 0;
}
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// Management
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#############################################################################
// 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
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#############################################################################
// TOGGLES
//#############################################################################
void ToggleDevCommands()
{

View File

@ -9,11 +9,9 @@
#include "console.h"
#include "utility.h"
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// Initialization
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#############################################################################
// INITIALIZATION
//#############################################################################
void InitializeR5Dev()
{
@ -38,11 +36,9 @@ void TerminateR5Dev()
FreeConsole();
}
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// Entry
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#############################################################################
// ENTRYPOINT
//#############################################################################
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{

View File

@ -1,5 +1,4 @@
#include <string>
#include <stdarg.h>
#include <Windows.h>
#include <detours.h>
@ -10,11 +9,9 @@
#include "overlay.h"
#include "hooks.h"
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// Netchannel
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#################################################################################
// NETCHANNEL HOOKS
//#################################################################################
bool HNET_ReceiveDatagram(int sock, void* inpacket, bool raw)
{
@ -45,11 +42,9 @@ unsigned int HNET_SendDatagram(SOCKET s, const char* buf, int len, int flags)
return result;
}
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// SquirrelVM
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#################################################################################
// SQUIRRELVM HOOKS
//#################################################################################
void* HSQVM_Print(void* sqvm, char* fmt, ...)
{
@ -105,11 +100,9 @@ bool HSQVM_LoadScript(void* sqvm, const char* script_path, const char* script_na
return SQVM_LoadScript(sqvm, script_path, script_name, flag);
}
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// Management
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#################################################################################
// MANAGEMENT
//#################################################################################
void InstallENHooks()
{
@ -156,11 +149,9 @@ void RemoveENHooks()
DetourTransactionCommit();
}
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// Toggles
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#################################################################################
// TOGGLES
//#################################################################################
void ToggleNetHooks()
{

View File

@ -52,11 +52,9 @@ static ID3D11RenderTargetView* g_pRenderTargetView = nullptr;
static IPostMessageA g_oPostMessageA = nullptr;
static IPostMessageW g_oPostMessageW = nullptr;
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// Window
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#################################################################################
// WINDOW PROCEDURE
//#################################################################################
LRESULT CALLBACK DXGIMsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
@ -128,6 +126,10 @@ LRESULT CALLBACK HwndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return CallWindowProc(g_oWndProc, hWnd, uMsg, wParam, lParam);
}
//#################################################################################
// POST MESSAGE
//#################################################################################
BOOL WINAPI HPostMessageA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
if (g_bBlockInput && Msg == WM_MOUSEMOVE)
@ -148,21 +150,9 @@ BOOL WINAPI HPostMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
return g_oPostMessageW(hWnd, Msg, wParam, lParam);
}
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// Present
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
HRESULT GetDeviceAndCtxFromSwapchain(IDXGISwapChain* pSwapChain, ID3D11Device** ppDevice, ID3D11DeviceContext** ppContext)
{
HRESULT ret = pSwapChain->GetDevice(__uuidof(ID3D11Device), (PVOID*)ppDevice);
if (SUCCEEDED(ret))
{
(*ppDevice)->GetImmediateContext(ppContext);
}
return ret;
}
//#################################################################################
// IDXGI PRESENT
//#################################################################################
void GetPresent()
{
@ -246,11 +236,9 @@ void GetPresent()
g_bPresentHooked = true;
}
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// Initialization
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#################################################################################
// INITIALIZATION
//#################################################################################
void SetupImGui()
{
@ -265,6 +253,8 @@ void SetupImGui()
void DrawImGui()
{
bool bShowMenu = false;
ImGui_ImplWin32_NewFrame();
ImGui_ImplDX11_NewFrame();
@ -272,7 +262,7 @@ void DrawImGui()
if (g_bShowMenu)
{
bool bShowMenu = true;
bShowMenu = true;
if (!g_bInitMenu)
{
CommandExecute(NULL, "gameui_activate");
@ -326,12 +316,12 @@ void CreateViewPort( UINT nWidth, UINT nHeight)
D3D11_VIEWPORT vp;
///////////////////////////////////////////////////////////////////////////////
vp.Width = width;
vp.Height = height;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
vp.Width = width;
vp.Height = height;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
///////////////////////////////////////////////////////////////////////////////
g_pDeviceContext->RSSetViewports(1, &vp);
@ -350,6 +340,20 @@ void DestroyRenderTarget()
}
}
//#################################################################################
// INTERNALS
//#################################################################################
HRESULT GetDeviceAndCtxFromSwapchain(IDXGISwapChain* pSwapChain, ID3D11Device** ppDevice, ID3D11DeviceContext** ppContext)
{
HRESULT ret = pSwapChain->GetDevice(__uuidof(ID3D11Device), (PVOID*)ppDevice);
if (SUCCEEDED(ret))
{
(*ppDevice)->GetImmediateContext(ppContext);
}
return ret;
}
HRESULT __stdcall GetResizeBuffers(IDXGISwapChain* pSwapChain, UINT nBufferCount, UINT nWidth, UINT nHeight, DXGI_FORMAT dxFormat, UINT nSwapChainFlags)
{
g_bShowMenu = false;
@ -383,7 +387,7 @@ HRESULT __stdcall Present(IDXGISwapChain* pSwapChain, UINT nSyncInterval, UINT n
SetupImGui();
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);
}
@ -397,11 +401,9 @@ HRESULT __stdcall Present(IDXGISwapChain* pSwapChain, UINT nSyncInterval, UINT n
return g_fnIDXGISwapChainPresent(pSwapChain, nSyncInterval, nFlags);
}
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// Management
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#################################################################################
// MANAGEMENT
//#################################################################################
void InstallDXHooks()
{
@ -432,8 +434,8 @@ void RemoveDXHooks()
DetourUpdateThread(GetCurrentThread());
///////////////////////////////////////////////////////////////////////////////
// Unhook PostMessage
DetourAttach(&(LPVOID&)g_oPostMessageA, (PBYTE)HPostMessageA);
DetourAttach(&(LPVOID&)g_oPostMessageW, (PBYTE)HPostMessageW);
DetourDetach(&(LPVOID&)g_oPostMessageA, (PBYTE)HPostMessageA);
DetourDetach(&(LPVOID&)g_oPostMessageW, (PBYTE)HPostMessageW);
///////////////////////////////////////////////////////////////////////////////
// Unhook SwapChain
DetourDetach(&(LPVOID&)g_fnIDXGISwapChainPresent, (PBYTE)Present);
@ -459,11 +461,9 @@ void PrintDXAddress()
std::cout << "+--------------------------------------------------------+" << std::endl;
}
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------
// Entry
//---------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
//#################################################################################
// ENTRYPOINT
//#################################################################################
DWORD __stdcall DXSwapChainWorker(LPVOID)
{
@ -478,5 +478,8 @@ void SetupDXSwapChain()
DWORD __stdcall DXSwapChainWorker(LPVOID);
HANDLE hThread = CreateThread(NULL, 0, DXSwapChainWorker, NULL, 0, &g_dThreadId);
if (hThread) { CloseHandle(hThread); }
if (hThread)
{
CloseHandle(hThread);
}
}

View File

@ -1,5 +1,6 @@
#include <windows.h>
#include <cassert>
#include <windows.h>
#include <stdio.h>
#include "detours.h"
@ -25,11 +26,9 @@ static IShowCursor g_oShowCursor = nullptr;
static POINT g_pLastCursorPos { 0 };
extern BOOL g_bBlockInput = false;
///////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
// Initialization
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
//#############################################################################
// INITIALIZATION
//#############################################################################
void SetupIPHooks()
{
@ -39,11 +38,9 @@ void SetupIPHooks()
g_oShowCursor = (IShowCursor )DetourFindFunction("user32.dll", "ShowCursor" );
}
///////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
// Hooks
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
//#############################################################################
// INPUT HOOKS
//#############################################################################
BOOL WINAPI HGetCursorPos(LPPOINT lpPoint)
{
@ -89,11 +86,9 @@ BOOL WINAPI HShowCursor(BOOL bShow)
return g_oShowCursor(bShow);
}
///////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
// Management
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
//#############################################################################
// MANAGEMENT
//#############################################################################
void InstallIPHooks()
{

View File

@ -10,7 +10,7 @@
void PrintLastError()
{
///////////////////////////////////////////////////////////////////////////
//Get the error message, if any.
// Get the error message, if any.
DWORD errorMessageID = ::GetLastError();
if (errorMessageID == 0)
{
@ -118,7 +118,7 @@ bool LaunchR5Apex()
}
///////////////////////////////////////////////////////////////////////////////
// Entry point.
// Entrypoint.
int main(int argc, char* argv[], char* envp[])
{
LaunchR5Apex();