-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdetecting-games.cpp
89 lines (73 loc) · 2.23 KB
/
detecting-games.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
#include <xtl.h>
#include <cstdint>
#include <string>
// Get the address of a function from a module by its ordinal
void *ResolveFunction(const std::string &moduleName, uint32_t ordinal)
{
HMODULE moduleHandle = GetModuleHandle(moduleName.c_str());
if (moduleHandle == nullptr)
return nullptr;
return GetProcAddress(moduleHandle, reinterpret_cast<const char *>(ordinal));
}
// Create a pointer to XNotifyQueueUI in xam.xex
typedef void (*XNOTIFYQUEUEUI)(uint32_t type, uint32_t userIndex, uint64_t areas, const wchar_t *displayText, void *pContextData);
XNOTIFYQUEUEUI XNotifyQueueUI = static_cast<XNOTIFYQUEUEUI>(ResolveFunction("xam.xex", 656));
// Enum for game title IDs
typedef enum _TitleId
{
Title_Dashboard = 0xFFFE07D1,
Title_MW2 = 0x41560817,
} TitleId;
// Imports from the Xbox libraries
extern "C"
{
uint32_t XamGetCurrentTitleId();
uint32_t ExCreateThread(
HANDLE *pHandle,
uint32_t stackSize,
uint32_t *pThreadId,
void *pApiThreadStartup,
PTHREAD_START_ROUTINE pStartAddress,
void *pParameter,
uint32_t creationFlags
);
}
bool g_Running = true;
// Infinitely check the current game running
uint32_t MonitorTitleId(void *pThreadParameter)
{
uint32_t currentTitleId = 0;
while (g_Running)
{
uint32_t newTitleId = XamGetCurrentTitleId();
if (newTitleId == currentTitleId)
continue;
currentTitleId = newTitleId;
switch (newTitleId)
{
case Title_Dashboard:
XNotifyQueueUI(0, 0, XNOTIFY_SYSTEM, L"Dashboard", nullptr);
break;
case Title_MW2:
XNotifyQueueUI(0, 0, XNOTIFY_SYSTEM, L"MW2", nullptr);
break;
}
}
return 0;
}
int DllMain(HANDLE hModule, DWORD reason, void *pReserved)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
// Run MonitorTitleId in separate thread
ExCreateThread(nullptr, 0, nullptr, nullptr, reinterpret_cast<PTHREAD_START_ROUTINE>(MonitorTitleId), nullptr, 2);
break;
case DLL_PROCESS_DETACH:
g_Running = false;
// We give the system some time to clean up the thread before exiting
Sleep(250);
break;
}
return TRUE;
}