-
Notifications
You must be signed in to change notification settings - Fork 2
/
AUTOHDR.cpp
99 lines (79 loc) · 2.8 KB
/
AUTOHDR.cpp
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
#include "stdafx.h"
#include "Windows.h"
#include <stdint.h>
#include <cstdlib>
#include <cstring>
#include <conio.h>
void HDR()
{
uint32_t pathCount, modeCount;
uint8_t set[] = { 0x0A, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x14, 0x81, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
uint8_t request[] = { 0x09, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x7C, 0x6F, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0xDB, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00 };
if (ERROR_SUCCESS == GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &pathCount, &modeCount))
{
DISPLAYCONFIG_PATH_INFO* pathsArray = nullptr;
DISPLAYCONFIG_MODE_INFO* modesArray = nullptr;
const size_t sizePathsArray = pathCount * sizeof(DISPLAYCONFIG_PATH_INFO);
const size_t sizeModesArray = modeCount * sizeof(DISPLAYCONFIG_MODE_INFO);
pathsArray = static_cast<DISPLAYCONFIG_PATH_INFO*>(std::malloc(sizePathsArray));
modesArray = static_cast<DISPLAYCONFIG_MODE_INFO*>(std::malloc(sizeModesArray));
if (pathsArray != nullptr && modesArray != nullptr)
{
std::memset(pathsArray, 0, sizePathsArray);
std::memset(modesArray, 0, sizeModesArray);
if (ERROR_SUCCESS == QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &pathCount, pathsArray,
&modeCount, modesArray, 0))
{
DISPLAYCONFIG_DEVICE_INFO_HEADER* setPacket =
reinterpret_cast<DISPLAYCONFIG_DEVICE_INFO_HEADER*>(set);
DISPLAYCONFIG_DEVICE_INFO_HEADER* requestPacket =
reinterpret_cast<DISPLAYCONFIG_DEVICE_INFO_HEADER*>(request);
for (int i = 0; i < modeCount; i++)
{
if (modesArray[i].infoType == DISPLAYCONFIG_MODE_INFO_TYPE_TARGET)
{
setPacket->adapterId.HighPart = modesArray[i].adapterId.HighPart;
setPacket->adapterId.LowPart = modesArray[i].adapterId.LowPart;
setPacket->id = modesArray[i].id;
requestPacket->adapterId.HighPart = modesArray[i].adapterId.HighPart;
requestPacket->adapterId.LowPart = modesArray[i].adapterId.LowPart;
requestPacket->id = modesArray[i].id;
}
}
if (ERROR_SUCCESS == DisplayConfigGetDeviceInfo(requestPacket))
{
if (request[20] == 0xD1) // HDR is OFF
{
set[20] = 1;
DisplayConfigSetDeviceInfo(setPacket);
}
else if (request[20] == 0xD3) // HDR is ON
{
set[20] = 0;
DisplayConfigSetDeviceInfo(setPacket);
}
}
}
std::free(pathsArray);
std::free(modesArray);
}
}
}
int main()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
HDR();
CreateProcess(L".\\kodi.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
HDR();
return 0;
}