2022-09-25 13:36:55 +02:00
|
|
|
|
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
|
|
|
|
//
|
|
|
|
|
// Purpose:
|
|
|
|
|
//
|
|
|
|
|
//===========================================================================//
|
2023-01-30 20:18:11 +01:00
|
|
|
|
#ifndef SYS_MAINWIND_H
|
|
|
|
|
#define SYS_MAINWIND_H
|
2023-12-24 16:29:42 +01:00
|
|
|
|
#include "inputsystem/iinputsystem.h"
|
2022-09-25 13:36:55 +02:00
|
|
|
|
|
2023-01-30 20:18:11 +01:00
|
|
|
|
inline CMemory p_CGame__AttachToWindow;
|
2023-07-03 00:02:08 +02:00
|
|
|
|
inline void (*v_CGame__AttachToWindow)(void);
|
2023-01-30 20:18:11 +01:00
|
|
|
|
|
2022-09-25 13:36:55 +02:00
|
|
|
|
inline CMemory p_CGame__PlayStartupVideos;
|
2023-07-02 23:01:29 +02:00
|
|
|
|
inline void(*v_CGame__PlayStartupVideos)(void);
|
2023-01-30 20:18:11 +01:00
|
|
|
|
|
|
|
|
|
inline CMemory p_CGame__WindowProc;
|
2023-07-02 23:01:29 +02:00
|
|
|
|
inline int(*v_CGame__WindowProc)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
2022-09-25 13:36:55 +02:00
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Purpose: Main game interface, including message pump and window creation
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-09-11 20:38:18 +02:00
|
|
|
|
class CGame
|
2022-09-25 13:36:55 +02:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static void PlayStartupVideos(void);
|
2023-01-30 20:18:11 +01:00
|
|
|
|
static int WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
2022-09-25 13:36:55 +02:00
|
|
|
|
|
2023-09-11 20:38:18 +02:00
|
|
|
|
|
|
|
|
|
inline HWND GetWindow() const { return m_hWindow; }
|
2023-12-24 16:29:42 +01:00
|
|
|
|
void GetWindowRect(int* const x, int* const y, int* const w, int* const h) const;
|
2023-09-11 20:38:18 +02:00
|
|
|
|
|
|
|
|
|
inline int GetDesktopWidth() const { return m_iDesktopWidth; }
|
|
|
|
|
inline int GetDesktopHeight() const { return m_iDesktopHeight; }
|
|
|
|
|
inline int GetDesktopRefreshRate() const { return m_iDesktopRefreshRate; }
|
2023-09-11 22:48:28 +02:00
|
|
|
|
inline float GetTVRefreshRate() const // Avoid stutter on TV's running on broadcast frame rates.
|
|
|
|
|
{ return ((float)m_iDesktopRefreshRate == 59.0f || (float)m_iDesktopRefreshRate == 60.0f) ? 59.939999f : (float)m_iDesktopRefreshRate; }
|
2023-09-11 20:38:18 +02:00
|
|
|
|
|
2023-12-24 16:29:42 +01:00
|
|
|
|
void DispatchKeyEvent(const uint64_t msTime, const ButtonCode_t buttonCode) const;
|
|
|
|
|
void DispatchAllStoredGameMessages() const;
|
|
|
|
|
|
2023-09-11 20:38:18 +02:00
|
|
|
|
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;
|
2023-01-30 20:18:11 +01:00
|
|
|
|
|
2022-09-25 13:36:55 +02:00
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
class VGame : public IDetour
|
|
|
|
|
{
|
|
|
|
|
virtual void GetAdr(void) const
|
|
|
|
|
{
|
2023-01-30 20:18:11 +01:00
|
|
|
|
LogFunAdr("CGame::AttachToWindow", p_CGame__AttachToWindow.GetPtr());
|
2023-01-25 02:26:52 +01:00
|
|
|
|
LogFunAdr("CGame::PlayStartupVideos", p_CGame__PlayStartupVideos.GetPtr());
|
2023-09-11 20:38:18 +02:00
|
|
|
|
LogVarAdr("g_Game", reinterpret_cast<uintptr_t>(g_pGame));
|
2022-09-25 13:36:55 +02:00
|
|
|
|
}
|
|
|
|
|
virtual void GetFun(void) const
|
|
|
|
|
{
|
|
|
|
|
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
|
2023-01-30 20:18:11 +01:00
|
|
|
|
p_CGame__AttachToWindow = g_GameDll.FindPatternSIMD("48 83 EC 38 48 8B 0D ?? ?? ?? ?? 48 85 C9 0F 84 ?? ?? ?? ??");
|
2022-12-01 22:44:55 +01:00
|
|
|
|
p_CGame__PlayStartupVideos = g_GameDll.FindPatternSIMD("48 8B C4 48 81 EC ?? ?? ?? ?? 80 3D ?? ?? ?? ?? ?? 0F 85 ?? ?? ?? ?? 48 8B 0D ?? ?? ?? ??");
|
2023-01-30 20:18:11 +01:00
|
|
|
|
p_CGame__WindowProc = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 74 24 ?? 57 41 54 41 56 48 81 EC ?? ?? ?? ??");
|
2022-09-25 13:36:55 +02:00
|
|
|
|
#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
|
2023-01-30 20:18:11 +01:00
|
|
|
|
p_CGame__AttachToWindow = g_GameDll.FindPatternSIMD("48 83 EC 28 48 8B 0D ?? ?? ?? ?? 48 85 C9 0F 84 ?? ?? ?? ?? BA ?? ?? ?? ??");
|
2022-12-01 22:44:55 +01:00
|
|
|
|
p_CGame__PlayStartupVideos = g_GameDll.FindPatternSIMD("48 8B C4 55 48 8D A8 ?? ?? ?? ?? 48 81 EC ?? ?? ?? ?? 80 3D ?? ?? ?? ?? ??");
|
2023-01-30 20:18:11 +01:00
|
|
|
|
p_CGame__WindowProc = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 74 24 ?? 48 89 7C 24 ?? 55 41 56 41 57 48 8D 6C 24 ?? 48 81 EC ?? ?? ?? ?? 33 F6");
|
2022-09-25 13:36:55 +02:00
|
|
|
|
#endif
|
2023-01-30 20:18:11 +01:00
|
|
|
|
|
|
|
|
|
v_CGame__AttachToWindow = p_CGame__AttachToWindow.RCast<void (*)(void)>();
|
2022-09-25 13:36:55 +02:00
|
|
|
|
v_CGame__PlayStartupVideos = p_CGame__PlayStartupVideos.RCast<void (*)(void)>();
|
2023-01-30 20:18:11 +01:00
|
|
|
|
v_CGame__WindowProc = p_CGame__WindowProc.RCast<int (*)(HWND, UINT, WPARAM, LPARAM)>();
|
|
|
|
|
}
|
|
|
|
|
virtual void GetVar(void) const
|
|
|
|
|
{
|
2023-09-11 20:38:18 +02:00
|
|
|
|
g_pGame = p_CGame__AttachToWindow.FindPattern("48 8B 0D").ResolveRelativeAddressSelf(0x3, 0x7).RCast<CGame*>();
|
2022-09-25 13:36:55 +02:00
|
|
|
|
}
|
|
|
|
|
virtual void GetCon(void) const { }
|
2023-11-26 13:21:20 +01:00
|
|
|
|
virtual void Detour(const bool bAttach) const;
|
2022-09-25 13:36:55 +02:00
|
|
|
|
};
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2023-01-30 20:18:11 +01:00
|
|
|
|
|
|
|
|
|
#endif // SYS_MAINWIND_H
|