-
Notifications
You must be signed in to change notification settings - Fork 7
/
RtssInterface.cpp
114 lines (91 loc) · 3.12 KB
/
RtssInterface.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "RtssInterface.h"
#include "StdAfx.h"
#include "RTSSSharedMemory.h"
#include "GroupedString.h"
RtssInterface::RtssInterface() {
}
void RtssInterface::showDot() {
UpdateOSD(".");
}
void RtssInterface::hideDot() {
ReleaseOSD();
}
/////////////////////////////////////////////////////////////////////////////
bool RtssInterface::UpdateOSD(char* lpText)
{
bool bResult = false;
HANDLE hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, "RTSSSharedMemoryV2");
if (hMapFile)
{
LPVOID pMapAddr = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
LPRTSS_SHARED_MEMORY pMem = (LPRTSS_SHARED_MEMORY)pMapAddr;
if (pMem)
{
if ((pMem->dwSignature == 'RTSS') &&
(pMem->dwVersion >= 0x00020000))
{
for (DWORD dwPass = 0; dwPass<2; dwPass++)
//1st pass : find previously captured OSD slot
//2nd pass : otherwise find the first unused OSD slot and capture it
{
for (DWORD dwEntry = 1; dwEntry<pMem->dwOSDArrSize; dwEntry++)
//allow primary OSD clients (i.e. EVGA Precision / MSI Afterburner) to use the first slot exclusively, so third party
//applications start scanning the slots from the second one
{
RTSS_SHARED_MEMORY::LPRTSS_SHARED_MEMORY_OSD_ENTRY pEntry = (RTSS_SHARED_MEMORY::LPRTSS_SHARED_MEMORY_OSD_ENTRY)((LPBYTE)pMem + pMem->dwOSDArrOffset + dwEntry * pMem->dwOSDEntrySize);
if (dwPass)
{
if (!strlen(pEntry->szOSDOwner))
strcpy_s(pEntry->szOSDOwner, "RTSSSharedMemorySample");
}
if (!strcmp(pEntry->szOSDOwner, "RTSSSharedMemorySample"))
{
if (pMem->dwVersion >= 0x00020007)
//use extended text slot for v2.7 and higher shared memory, it allows displaying 4096 symbols
//instead of 256 for regular text slot
strncpy_s(pEntry->szOSDEx, lpText, sizeof(pEntry->szOSDEx) - 1);
else
strncpy_s(pEntry->szOSD, lpText, sizeof(pEntry->szOSD) - 1);
pMem->dwOSDFrame++;
bResult = TRUE;
break;
}
}
if (bResult)
break;
}
}
UnmapViewOfFile(pMapAddr);
}
CloseHandle(hMapFile);
}
return bResult;
}
/////////////////////////////////////////////////////////////////////////////
void RtssInterface::ReleaseOSD()
{
HANDLE hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, "RTSSSharedMemoryV2");
if (hMapFile)
{
LPVOID pMapAddr = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
LPRTSS_SHARED_MEMORY pMem = (LPRTSS_SHARED_MEMORY)pMapAddr;
if (pMem)
{
if ((pMem->dwSignature == 'RTSS') &&
(pMem->dwVersion >= 0x00020000))
{
for (DWORD dwEntry = 1; dwEntry<pMem->dwOSDArrSize; dwEntry++)
{
RTSS_SHARED_MEMORY::LPRTSS_SHARED_MEMORY_OSD_ENTRY pEntry = (RTSS_SHARED_MEMORY::LPRTSS_SHARED_MEMORY_OSD_ENTRY)((LPBYTE)pMem + pMem->dwOSDArrOffset + dwEntry * pMem->dwOSDEntrySize);
if (!strcmp(pEntry->szOSDOwner, "RTSSSharedMemorySample"))
{
memset(pEntry, 0, pMem->dwOSDEntrySize);
pMem->dwOSDFrame++;
}
}
}
UnmapViewOfFile(pMapAddr);
}
CloseHandle(hMapFile);
}
}