1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#include "DLLMain.h"
#include <cstdio>
#include <d3d9.h>
#include <stdarg.h>
#include <windows.h>
#include <psapi.h>
#include <commctrl.h>
#include "Hook.h"
#include "D9DW.h"
#include "Game.h"
#define DXD9DEVICE_OFFSET 0x198298 + 0x44
typedef __int32 (__stdcall* EndScene_t)(LPDIRECT3DDEVICE9);
static LPDIRECT3DDEVICE9 pDevice = NULL;
static bool bActive = true;
static EndScene_t pEndScene = NULL;
static D9DW ddraw;
//static Game game;
__int32 __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice_t)
{
asm volatile ("nop; nop; nop");
int retOrigEndScene = D3D_OK;
if(pDevice == NULL)
{
pDevice = pDevice_t;
//DEBUG_LOG("D3D9 Device (%X): %p", (UINT32)((UINT32) game.m_shaderapi.lpBaseOfDll + DXD9DEVICE_OFFSET), pDevice);
DEBUG_LOG("EndScene Arg: %p", pDevice_t);
DEBUG_FLUSH;
ddraw.Create(pDevice);
}
else
{
HRESULT c_ret = ddraw.checkDxDevice();
if (c_ret == D3D_OK)
{
//game.ReadCVars();
ddraw.Render(/* &game */ NULL, /* game.ReadEntities() */ false);
}
else pEndScene = NULL;
retOrigEndScene = (pEndScene != NULL ? pEndScene(pDevice_t) : D3D_OK);
}
asm volatile ("nop; nop; nop");
return retOrigEndScene;
}
DWORD WINAPI MainThread(void *arg)
{
//game.Init();
Hook::hookEndScene(hkEndScene, &pEndScene, false);
while ( bActive )
{
Sleep(500);
if ( GetForegroundWindow() != FindWindow( 0, "Counter-Strike: Global Offensive" ) )
{
pDevice = NULL;
ddraw.Release();
}
}
return 0;
}
__declspec(dllexport) BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
DWORD dwThreadId;
DisableThreadLibraryCalls(hinstDLL);
CreateThread(NULL, 0, MainThread, NULL, 0, &dwThreadId);
}
return TRUE; // succesful
}
|