-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCheatMonitor.cpp
More file actions
134 lines (117 loc) · 3.34 KB
/
Copy pathCheatMonitor.cpp
File metadata and controls
134 lines (117 loc) · 3.34 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
#include "CheatMonitor.h"
#include "CheatMonitorEngine.h"
#include "utils/SystemUtils.h"
#include <memory>
#include <mutex>
#include <thread>
struct CheatMonitor::Pimpl : public CheatMonitorEngine
{
};
CheatMonitor &CheatMonitor::GetInstance()
{
static CheatMonitor instance;
return instance;
}
CheatMonitor::CheatMonitor() : m_pimpl(nullptr) {}
CheatMonitor::~CheatMonitor() { Shutdown(); }
bool CheatMonitor::Initialize()
{
if (!m_pimpl)
{
m_pimpl = std::make_unique<Pimpl>();
m_pimpl->m_isSystemActive = true;
m_pimpl->m_monitorThread = std::thread(&CheatMonitorEngine::MonitorLoop, m_pimpl.get());
}
return true;
}
void CheatMonitor::OnPlayerLogin(uint32_t user_id, const std::string &user_name)
{
if (m_pimpl)
{
std::lock_guard<std::mutex> lock(m_pimpl->m_sessionMutex);
m_pimpl->m_currentUserId = user_id;
m_pimpl->m_currentUserName = user_name;
m_pimpl->m_isSessionActive = true;
m_pimpl->m_hasServerConfig = true;
m_pimpl->WakeMonitor();
}
}
void CheatMonitor::OnPlayerLogout()
{
if (m_pimpl)
{
m_pimpl->m_isSessionActive = false;
m_pimpl->ResetSessionState();
}
}
void CheatMonitor::Shutdown()
{
if (m_pimpl && m_pimpl->m_isSystemActive.load())
{
m_pimpl->m_isSystemActive = false;
m_pimpl->WakeMonitor();
if (m_pimpl->m_monitorThread.joinable())
{
m_pimpl->m_monitorThread.join();
}
}
m_pimpl.reset();
}
void CheatMonitor::OnServerConfigUpdated()
{
if (m_pimpl)
{
m_pimpl->OnConfigUpdated();
m_pimpl->m_hasServerConfig = true;
m_pimpl->WakeMonitor();
}
}
void CheatMonitor::SetGameWindow(void *hwnd)
{
if (m_pimpl) m_pimpl->m_gameWindowHandle.store(reinterpret_cast<uintptr_t>(hwnd), std::memory_order_relaxed);
}
void CheatMonitor::SubmitTargetedSensorRequest(const std::string &request_id, const std::string &sensor_name)
{
if (m_pimpl) m_pimpl->SubmitTargetedScanRequest(request_id, sensor_name);
}
void CheatMonitor::SubmitTargetedSensorRequest(const anti_cheat::TargetedSensorCommand &command)
{
if (m_pimpl) m_pimpl->SubmitTargetedScanRequest(command.request_id(), command.sensor_name());
}
void CheatMonitor::UploadSnapshot()
{
if (m_pimpl) m_pimpl->UploadSnapshotReport();
}
bool CheatMonitor::IsCallerLegitimate()
{
if (!m_pimpl) return true;
return m_pimpl->IsAddressInLegitimateModule(_ReturnAddress());
}
CheatMonitorEngine::CheatMonitorEngine()
{
m_windowsVersion = SystemUtils::GetWindowsVersion();
// 动态获取反作弊模块句柄(支持静态编译到EXE或单独作为DLL)
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<LPCWSTR>(CheatMonitor::GetInstance), &m_hSelfModule);
// 生成会话 ID (类似 UUID 格式)
char session[37];
const char *chars = "abcdef0123456789";
for (int i = 0; i < 36; ++i)
{
if (i == 8 || i == 13 || i == 18 || i == 23)
session[i] = '-';
else
session[i] = chars[m_rng() % 16];
}
session[36] = 0;
m_sessionId = session;
}
CheatMonitorEngine::~CheatMonitorEngine()
{
if (m_wmiMonitor)
{
m_wmiMonitor->Shutdown();
m_wmiMonitor.reset();
}
UnregisterDllNotification();
}