-
Notifications
You must be signed in to change notification settings - Fork 1
/
ETS2Hook.h
188 lines (150 loc) · 5.08 KB
/
ETS2Hook.h
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#pragma once
#include "globals.h"
#include "readerwriterqueue/readerwriterqueue.h"
#include <sstream>
#include "ets2dc_dx11hook.h"
class Config;
class AppSettings;
class TelemetryFile;
class SnapshotData
{
public:
TextureBuffer* image;
TextureBuffer* depth;
ets2dc_telemetry::telemetry_state* telemetry;
snapshot_stats frame_stats;
std::wstring fileName;
~SnapshotData()
{
if (image != nullptr) delete image;
if (depth != nullptr) delete depth;
if (telemetry != nullptr) delete telemetry;
}
};
/// <summary>
/// Hook class for Euro Truck Simulator 2
/// </summary>
class ETS2Hook
{
typedef std::chrono::duration<float> duration;
typedef std::chrono::high_resolution_clock clock;
// Pointers to useful objects
ID3D11Device* pDevice = nullptr;
ID3D11DeviceContext* pDeviceContext = nullptr;
ID3D11Texture2D* pSwapchainImageTexture = nullptr;
ID3D11Texture2D *pScreenshotTexture = nullptr, *pLastScreenshotTexture = nullptr;
ID3D11Texture2D *pDepthTexture = nullptr, *pLastDepthTexture = nullptr;
HWND outputWindow;
bool simulate;
bool inputCaptured;
std::atomic<int> capturing;
snapshot_stats stats;
bool IsCapturing();
// Configuration vars
int consecutiveFramesCapture;
int secondsBetweenCaptures;
int captureDepth;
bool captureTelemetry;
std::wstring imageFolder;
std::wstring imageFileFormat;
std::wstring imageFileName;
std::wstring formatString;
std::wstring snapshotId;
// ImGui Stuff
bool imGuiDrawEnabled;
void initImGui(IDXGISwapChain* pSwapChain, ID3D11Device* pDevice, ID3D11DeviceContext* pDeviceContext);
void shutdownImGui();
void renderImGui();
// Input handling stuff
void initInput();
void shutdownInput();
static WNDPROC ETS2_hWndProc;
static ETS2Hook* pThis;
static LRESULT CALLBACK hWndProcWrapper(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK hWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// Raw input hooking
RAWINPUTDEVICE ETS2RidMouse;
void getRawMouseDevice();
void startRawInputCapture();
void endRawInputCapture();
void processRawMouse(RAWMOUSE rawMouse);
// Mouse hook stuff
HHOOK mouseHookHandle;
static LRESULT CALLBACK mouseHookWrapper(int nCode, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK mouseHook(int nCode, WPARAM wParam, LPARAM lParam);
// Some util functions
HRESULT TakeScreenshot1(IDXGISwapChain* swapChain);
HRESULT TakeScreenshot2();
void CaptureBlock(float deltaTime);
void PauseBlock(float deltaTime);
const std::wstring GenerateFileName();
void GenerateFileFormatString();
// Settings change update
void updateSettings();
AppSettings* appSettings;
// Telemetry file
TelemetryFile* telemetryFile;
void InitTelemetryFile();
void CloseTelemetryFile();
// Writing thread
moodycamel::ReaderWriterQueue<SnapshotData*> queue;
std::atomic_bool captureThreadRunning = true;
void saveBuffer();
// To control pipelane stages
bool frameStart = true;
public:
ETS2Hook();
~ETS2Hook();
bool Initialized;
/// <summary>
/// Called to initialize usefull DX11 stuff
/// </summary>
/// <param name="swapChain"></param>
/// <returns></returns>
HRESULT Init(IDXGISwapChain* swapChain);
/// <summary>
/// Called before DX11 present call
/// </summary>
/// <param name="swapChain"></param>
/// <returns></returns>
HRESULT PresentHook(ets2dc_dx11hook::Present oPresent, IDXGISwapChain* swapChain,
UINT SyncInterval, UINT Flags);
/// <summary>
/// Called before draw
/// </summary>
/// <param name="VertexCount"></param>
/// <param name="StartVertexLocation"></param>
void DrawHook(ets2dc_dx11hook::Draw oDraw, ID3D11DeviceContext* context,
UINT VertexCount, UINT StartVertexLocation);
/// <summary>
/// Called before DX11 CreateTexture2D
/// </summary>
/// <param name="oCreateTexture2D"></param>
/// <param name="device"></param>
/// <param name="pDesc"></param>
/// <param name="pInitialData"></param>
/// <param name="ppTexture2D"></param>
/// <returns></returns>
HRESULT CreateTexture2DHook(ets2dc_dx11hook::CreateTexture2D oCreateTexture2D, ID3D11Device* device,
D3D11_TEXTURE2D_DESC* pDesc, D3D11_SUBRESOURCE_DATA* pInitialData, ID3D11Texture2D** ppTexture2D);
/// <summary>
/// Called before DX11 ClearDepthStencilView
/// </summary>
/// <param name="oClearDepthStencilView"></param>
/// <param name="deviceContext"></param>
/// <param name="pDepthStencilView"></param>
/// <param name="ClearFlags"></param>
/// <param name="Depth"></param>
/// <param name="Stencil"></param>
void ClearDepthStencilViewHook(ets2dc_dx11hook::ClearDepthStencilView oClearDepthStencilView, ID3D11DeviceContext* deviceContext,
ID3D11DepthStencilView* pDepthStencilView, UINT ClearFlags, FLOAT Depth, UINT8 Stencil);
/// <summary>
/// Called when a render view is cleared
/// </summary>
/// <param name="oClearRenderTargetView"></param>
/// <param name="deviceContext"></param>
/// <param name="pRenderTargetView"></param>
/// <param name=""></param>
void ClearRenderTargetViewHook(ets2dc_dx11hook::ClearRenderTargetView oClearRenderTargetView, ID3D11DeviceContext* deviceContext,
ID3D11RenderTargetView* pRenderTargetView, const FLOAT ColorRGBA[4]);
};