-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_sysutils.h
More file actions
287 lines (228 loc) · 23.9 KB
/
Copy pathnew_sysutils.h
File metadata and controls
287 lines (228 loc) · 23.9 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#pragma once
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
// #define WIN32_NO_STATUS
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#include <Windows.h>
#include <string>
#include <stdint.h>
#include <libloaderapi.h>
#include <ranges>
#include <winternl.h>
#include <d3dkmthk.h>
#define NV_WINDOWS
#define NVSDK_NGX
#define NGX_ENABLE_DEPRECATED_GET_PARAMETERS
#define NGX_ENABLE_DEPRECATED_SHUTDOWN
#include <nvsdk_ngx.h>
#include <nvsdk_ngx_defs.h>
#define SPDLOG_USE_STD_FORMAT
#define SPDLOG_WCHAR_FILENAMES
#define SPDLOG_WCHAR_TO_UTF8_SUPPORT
#include "spdlog/spdlog.h"
#define VK_USE_PLATFORM_WIN32_KHR
#define BUFFER_COUNT 4
#define OPTI_GUID "0F71CA1E-5CA1-E42A-AC1E-5CA1E0A11E55"
// Enables logging of DLSS NV Parameters
// #define DLSS_PARAM_DUMP
// Enables async spdlog
// Have issues when closing
// #define LOG_ASYNC
// Enables LOG_DEBUG_ONLY logs
// #define DETAILED_DEBUG_LOGS
// Enables Vulkan validation layers
// #define VULKAN_DEBUG_LAYER
// Enable D3D12 Debug Layers
// #define ENABLE_DEBUG_LAYER_DX12
// Enable D3D11 Debug Layers
// #define ENABLE_DEBUG_LAYER_DX11
// Enable DXGI Debug Layers
// #define DXGI_DEBUG_ENABLED
#ifdef ENABLE_DEBUG_LAYER_DX12
// Enable GPUValidation
// #define ENABLE_GPU_VALIDATION
#include <d3d12sdklayers.h>
#endif
// Enables Low Latency inputs
// #define LOW_LATENCY_INPUTS
#ifdef LOW_LATENCY_INPUTS
#define XELL_EXPORT_API
#endif
// Use vkQueueSubmit2KHR instead of vkQueueSubmit for testing Linux issue
// #define USE_QUEUE_SUBMIT_2_KHR
// Don't skip spoofing for XeSS features
// Which would ONLY disable XMX when using spoofing
// #define DONT_USE_XMX
inline HMODULE dllModule = nullptr;
inline HMODULE exeModule = nullptr;
inline HMODULE originalModule = nullptr;
inline HMODULE skModule = nullptr;
inline HMODULE reshadeModule = nullptr;
inline HMODULE vulkanModule = nullptr;
inline HMODULE d3d11Module = nullptr;
inline HMODULE d3d12AgilityModule = nullptr;
inline HMODULE slInterposerModule = nullptr;
inline DWORD processId;
#define LOG_TRACE(msg, ...) \
do \
{ \
if (spdlog::should_log(spdlog::level::trace)) \
spdlog::trace(__FUNCTION__ " " msg, ##__VA_ARGS__); \
} while (0)
#define LOG_DEBUG(msg, ...) \
do \
{ \
if (spdlog::should_log(spdlog::level::debug)) \
spdlog::debug(__FUNCTION__ " " msg, ##__VA_ARGS__); \
} while (0)
#ifdef DETAILED_DEBUG_LOGS
#define LOG_DEBUG_ONLY(msg, ...) \
do \
{ \
if (spdlog::should_log(spdlog::level::debug)) \
spdlog::debug(__FUNCTION__ " " msg, ##__VA_ARGS__); \
} while (0)
#else
#define LOG_DEBUG_ONLY(msg, ...)
#endif
#ifdef LOG_ASYNC
#define LOG_DEBUG_ASYNC(msg, ...) \
do \
{ \
if (spdlog::should_log(spdlog::level::debug)) \
spdlog::debug(__FUNCTION__ " " msg, ##__VA_ARGS__); \
} while (0)
#else
#define LOG_DEBUG_ASYNC(msg, ...)
#endif
#define LOG_INFO(msg, ...) \
do \
{ \
if (spdlog::should_log(spdlog::level::info)) \
spdlog::info(__FUNCTION__ " " msg, ##__VA_ARGS__); \
} while (0)
#define LOG_WARN(msg, ...) \
do \
{ \
if (spdlog::should_log(spdlog::level::warn)) \
spdlog::warn(__FUNCTION__ " " msg, ##__VA_ARGS__); \
} while (0)
#define LOG_ERROR(msg, ...) \
do \
{ \
if (spdlog::should_log(spdlog::level::err)) \
spdlog::error(__FUNCTION__ " " msg, ##__VA_ARGS__); \
} while (0)
#define LOG_FUNC() spdlog::trace(__FUNCTION__)
#define LOG_FUNC_RESULT(result) spdlog::trace(__FUNCTION__ " result: {0:X}", (UINT64) result)
// #define TRACKING_LOGS
#ifdef TRACKING_LOGS
#define LOG_TRACK(msg, ...) spdlog::debug(__FUNCTION__ " [RT] " msg, ##__VA_ARGS__)
#else
#define LOG_TRACK(msg, ...)
#endif
#define SAFE_RELEASE(p) \
do \
{ \
if (p && p != nullptr) \
{ \
(p)->Release(); \
(p) = nullptr; \
} \
} while ((void) 0, 0);
#define SAFE_CLOSE_HANDLE(p) \
do \
{ \
if (p) \
{ \
CloseHandle(p); \
(p) = nullptr; \
} \
} while ((void) 0, 0)
struct feature_version
{
unsigned int major;
unsigned int minor;
unsigned int patch;
feature_version() : major(0), minor(0), patch(0) {}
explicit feature_version(const char* version_str) : major(0), minor(0), patch(0) { parse_version(version_str); }
constexpr feature_version(unsigned int maj, unsigned int min, unsigned int pat) : major(maj), minor(min), patch(pat)
{
}
bool operator==(const feature_version& other) const
{
return major == other.major && minor == other.minor && patch == other.patch;
}
bool operator!=(const feature_version& other) const { return !(*this == other); }
bool operator<(const feature_version& other) const
{
if (major != other.major)
return major < other.major;
if (minor != other.minor)
return minor < other.minor;
return patch < other.patch;
}
bool operator>(const feature_version& other) const { return other < *this; }
bool operator<=(const feature_version& other) const { return !(other < *this); }
bool operator>=(const feature_version& other) const { return !(*this < other); }
void parse_version(const char* version_str)
{
const char* p = version_str;
// Skip non-digits at front
while (*p)
{
if (isdigit((unsigned char) p[0]))
{
if (sscanf_s(p, "%u.%u.%u", &major, &minor, &patch) == 3)
return;
}
++p;
}
LOG_WARN("can't parse {0}", version_str);
}
};
namespace VendorId
{
enum Value : uint32_t
{
Invalid = 0,
Microsoft = 0x1414, // Software Render Adapter
Nvidia = 0x10DE,
AMD = 0x1002,
Intel = 0x8086,
};
};
inline static std::string wstring_to_string(const std::wstring& wide_str)
{
if (wide_str.empty())
return std::string();
int size_needed = WideCharToMultiByte(CP_UTF8, 0, wide_str.c_str(), static_cast<int>(wide_str.length()), nullptr, 0,
nullptr, nullptr);
if (size_needed <= 0)
return std::string();
std::string result(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, wide_str.c_str(), static_cast<int>(wide_str.length()), &result[0], size_needed,
nullptr, nullptr);
return result;
}
inline static std::wstring string_to_wstring(const std::string& str)
{
if (str.empty())
return std::wstring();
int size_needed = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), static_cast<int>(str.length()), nullptr, 0);
if (size_needed <= 0)
return std::wstring();
std::wstring result(size_needed, L'\0');
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), static_cast<int>(str.length()), &result[0], size_needed);
return result;
}
inline static void to_lower_in_place(std::string& string)
{
std::transform(string.begin(), string.end(), string.begin(), ::tolower);
}
inline static void to_lower_in_place(std::wstring& wstring)
{
std::transform(wstring.begin(), wstring.end(), wstring.begin(), ::tolower);
}
#include "OptiTypes.h"