~shimon/thd3d8mitigation

ref: 73e1b176f1a04e97cfd83a3fb41835b996960b4a thd3d8mitigation/thd3d8mitigation.h -rw-r--r-- 3.0 KiB
73e1b176Itoh Shimon 7 months ago
                                                                                
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#pragma once

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#define CINTERFACE
#include <d3d8.h>

#include "thd3d8mitigationversion.h"

#ifdef __cplusplus
extern "C" {
#endif

/* thd3d8mitigation.c */

/* type of Direct3DCreate8 */
typedef IDirect3D8*(WINAPI* Direct3DCreate8_t)(UINT);

/* type of IDirect3D8::CreateDevice */
typedef HRESULT(__stdcall* IDirect3D8CreateDevice_t)(IDirect3D8*, UINT, D3DDEVTYPE, HWND, DWORD,
	D3DPRESENT_PARAMETERS*, IDirect3DDevice8**);

/* type of IDirect3D8::Release (inherit from IUnknown::Release) */
typedef ULONG(__stdcall* IDirect3D8Release_t)(IDirect3D8*);

/* type of IDirect3DDevice8::Present */
typedef HRESULT(__stdcall* IDirect3DDevice8Present_t)(IDirect3DDevice8*, CONST RECT*, CONST RECT*, HWND,
	CONST RGNDATA*);

/* type of IDirect3DDevice8::Release (inherit from IUnknown::Release) */
typedef ULONG(__stdcall* IDirect3DDevice8Release_t)(IDirect3DDevice8*);

/* type of IDirect3DDevice8::Reset */
typedef HRESULT(__stdcall* IDirect3DDevice8Reset_t)(IDirect3DDevice8*, D3DPRESENT_PARAMETERS*);

typedef HRESULT (*ModIDirect3DDevice8Present_t)(IDirect3DDevice8*, struct IDirect3DDevice8ExtraData*,
	CONST RECT*, CONST RECT*, HWND, CONST RGNDATA*);

enum ConfigWaitFor {
	CONFIG_WAITFOR_VSYNC,
	CONFIG_WAITFOR_NORMAL,
	CONFIG_WAITFOR_AUTO
};

struct IDirect3D8ExtraData {
	IDirect3D8CreateDevice_t VanillaCreateDevice;
	IDirect3D8Release_t VanillaRelease;
};

struct IDirect3DDevice8ExtraData {
	IDirect3DDevice8Present_t VanillaPresent;
	IDirect3DDevice8Release_t VanillaRelease;
	IDirect3DDevice8Reset_t VanillaReset;
	ModIDirect3DDevice8Present_t ModPresent;
	D3DPRESENT_PARAMETERS pp;
};

extern CRITICAL_SECTION g_CS;
extern const char* const ConfigWaitForNameTable[3];

/* util.c */

#define LOG_PREFIX "[thd3d8mitigation]"

/* nullable */
extern HANDLE g_LogFile;

int myasprintf(char**, const char*, ...);
void Log(const char*, ...);
void LogWithErrorCode(DWORD, const char*, ...);
__declspec(noreturn) void Fatal(int, const char*, ...);

/* extradatatable.cpp */

struct IDirect3D8ExtraDataTable;
struct IDirect3DDevice8ExtraDataTable;

struct IDirect3D8ExtraDataTable* IDirect3D8ExtraDataTableNew(void);
BOOL IDirect3D8ExtraDataTableInsert(struct IDirect3D8ExtraDataTable*, IDirect3D8*, struct IDirect3D8ExtraData);
void IDirect3D8ExtraDataTableErase(struct IDirect3D8ExtraDataTable*, IDirect3D8*);
struct IDirect3D8ExtraData* IDirect3D8ExtraDataTableGet(struct IDirect3D8ExtraDataTable*, IDirect3D8*);
void IDirect3D8ExtraDataTableShrinkToFit(struct IDirect3D8ExtraDataTable*);

struct IDirect3DDevice8ExtraDataTable* IDirect3DDevice8ExtraDataTableNew(void);
BOOL IDirect3DDevice8ExtraDataTableInsert(struct IDirect3DDevice8ExtraDataTable*, IDirect3DDevice8*,
	struct IDirect3DDevice8ExtraData);
void IDirect3DDevice8ExtraDataTableErase(struct IDirect3DDevice8ExtraDataTable*, IDirect3DDevice8*);
struct IDirect3DDevice8ExtraData* IDirect3DDevice8ExtraDataTableGet(struct IDirect3DDevice8ExtraDataTable*,
	IDirect3DDevice8*);
void IDirect3DDevice8ExtraDataTableShrinkToFit(struct IDirect3DDevice8ExtraDataTable*);

#ifdef __cplusplus
}
#endif