Reverse CGame class

Class structure reversed.
This commit is contained in:
Kawe Mazidjatari 2023-09-11 20:38:18 +02:00
parent 0306d7788b
commit fdb4a4d429
5 changed files with 56 additions and 29 deletions

View File

@ -200,7 +200,6 @@ add_sources( SOURCE_GROUP "Public"
"${ENGINE_SOURCE_DIR}/public/idatablock.h"
"${ENGINE_SOURCE_DIR}/public/idebugoverlay.h"
"${ENGINE_SOURCE_DIR}/public/iengine.h"
"${ENGINE_SOURCE_DIR}/public/igame.h"
"${ENGINE_SOURCE_DIR}/public/iserver.h"
"${ENGINE_SOURCE_DIR}/public/isnapshotmgr.h"
"${ENGINE_SOURCE_DIR}/public/inetchannel.h"

View File

@ -94,6 +94,29 @@ int CGame::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return v_CGame__WindowProc(hWnd, uMsg, wParam, lParam);
}
//-----------------------------------------------------------------------------
// Purpose: gets the window rect
//-----------------------------------------------------------------------------
void CGame::GetWindowRect(int* x, int* y, int* w, int* h)
{
if (x)
{
*x = m_x;
}
if (y)
{
*y = m_y;
}
if (w)
{
*w = m_width;
}
if (h)
{
*h = m_height;
}
}
///////////////////////////////////////////////////////////////////////////////
void VGame::Attach() const
{

View File

@ -5,7 +5,6 @@
//===========================================================================//
#ifndef SYS_MAINWIND_H
#define SYS_MAINWIND_H
#include "public/igame.h"
inline CMemory p_CGame__AttachToWindow;
inline void (*v_CGame__AttachToWindow)(void);
@ -18,14 +17,38 @@ inline int(*v_CGame__WindowProc)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa
//-----------------------------------------------------------------------------
// Purpose: Main game interface, including message pump and window creation
//-----------------------------------------------------------------------------
class CGame : public IGame
class CGame
{
public:
static void PlayStartupVideos(void);
static int WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
};
inline HWND* g_pGameWindow = nullptr;
inline HWND GetWindow() const { return m_hWindow; }
void GetWindowRect(int* x, int* y, int* w, int* h);
inline int GetDesktopWidth() const { return m_iDesktopWidth; }
inline int GetDesktopHeight() const { return m_iDesktopHeight; }
inline int GetDesktopRefreshRate() const { return m_iDesktopRefreshRate; }
private:
HWND m_hWindow;
HINSTANCE m_hInstance;
WNDPROC m_ChainedWindowProc;
int m_x;
int m_y;
int m_width;
int m_height;
bool m_bUnk0;
bool m_bUnk1;
bool m_bExternallySuppliedWindow;
int m_iDesktopWidth;
int m_iDesktopHeight;
int m_iDesktopRefreshRate;
void* m_pInputContext_Maybe;
}; static_assert(sizeof(CGame) == 64);
inline CGame* g_pGame = nullptr;
///////////////////////////////////////////////////////////////////////////////
class VGame : public IDetour
@ -34,7 +57,7 @@ class VGame : public IDetour
{
LogFunAdr("CGame::AttachToWindow", p_CGame__AttachToWindow.GetPtr());
LogFunAdr("CGame::PlayStartupVideos", p_CGame__PlayStartupVideos.GetPtr());
LogVarAdr("g_GameWindow", reinterpret_cast<uintptr_t>(g_pGameWindow));
LogVarAdr("g_Game", reinterpret_cast<uintptr_t>(g_pGame));
}
virtual void GetFun(void) const
{
@ -54,7 +77,7 @@ class VGame : public IDetour
}
virtual void GetVar(void) const
{
g_pGameWindow = p_CGame__AttachToWindow.FindPattern("48 8B 0D").ResolveRelativeAddressSelf(0x3, 0x7).RCast<HWND*>();
g_pGame = p_CGame__AttachToWindow.FindPattern("48 8B 0D").ResolveRelativeAddressSelf(0x3, 0x7).RCast<CGame*>();
}
virtual void GetCon(void) const { }
virtual void Attach(void) const;

View File

@ -1,19 +0,0 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $Workfile: $
// $Date: $
// $NoKeywords: $
//===========================================================================//
#ifndef IGAME_H
#define IGAME_H
class IGame
{
public:
virtual ~IGame(void) { }
// TODO //
};
#endif // IGAME_H

View File

@ -86,10 +86,10 @@ void ImGui_Init()
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.ImeWindowHandle = *g_pGameWindow;
io.ImeWindowHandle = g_pGame->GetWindow();
io.ConfigFlags |= ImGuiConfigFlags_IsSRGB;
ImGui_ImplWin32_Init(*g_pGameWindow);
ImGui_ImplWin32_Init(g_pGame->GetWindow());
ImGui_ImplDX11_Init(D3D11Device(), D3D11DeviceContext());
}
@ -141,7 +141,8 @@ HRESULT __stdcall Present(IDXGISwapChain* pSwapChain, UINT nSyncInterval, UINT n
DrawImGui();
///////////////////////////////////////////////////////////////////////////////
return s_fnSwapChainPresent(pSwapChain, nSyncInterval, nFlags);
HRESULT result = s_fnSwapChainPresent(pSwapChain, nSyncInterval, nFlags);
return result;
}
HRESULT __stdcall ResizeBuffers(IDXGISwapChain* pSwapChain, UINT nBufferCount, UINT nWidth, UINT nHeight, DXGI_FORMAT dxFormat, UINT nSwapChainFlags)