-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
232 lines (204 loc) · 8.54 KB
/
Copy pathmain.cpp
File metadata and controls
232 lines (204 loc) · 8.54 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
#include <iostream>
#include <string>
#include <csignal>
#include <atomic>
#include <conio.h>
#include "Core/Process/ProcessManager.h"
#include "Core/Controller/MonsterController.h"
#include "Core/Controller/PlayerController.h"
// 全局运行标志
std::atomic<bool> g_running{ true };
// 信号处理函数
void SignalHandler(int signal)
{
if (signal == SIGINT || signal == SIGTERM)
{
std::wcout << L"\n[Main] Received shutdown signal..." << std::endl;
g_running = false;
}
}
// 打印菜单
void PrintMenu()
{
std::wcout << L"\n========================================" << std::endl;
std::wcout << L" Hunter Trainer - MHW Trainer" << std::endl;
std::wcout << L"========================================" << std::endl;
std::wcout << L"Commands:" << std::endl;
std::wcout << L" [S] - Show current status" << std::endl;
std::wcout << L" [R] - Refresh / Retry attach" << std::endl;
std::wcout << L" [T] - Test catch movement(bushi gemen)" << std::endl;
std::wcout << L" [\\] - Face monster to player" << std::endl;
std::wcout << L" [W] - Write action ID" << std::endl;
std::wcout << L" [Q] - Quit" << std::endl;
std::wcout << L"========================================" << std::endl;
}
// 状态转字符串
const wchar_t* StatusToString(ProcessStatus status)
{
switch (status)
{
case ProcessStatus::Waiting: return L"Waiting";
case ProcessStatus::Hooked: return L"Hooked";
case ProcessStatus::Paused: return L"Paused";
case ProcessStatus::Exited: return L"Exited";
default: return L"Unknown";
}
}
int main()
{
// 设置控制台为 UTF-8
SetConsoleOutputCP(CP_UTF8);
SetConsoleCP(CP_UTF8);
// 设置信号处理
std::signal(SIGINT, SignalHandler);
std::signal(SIGTERM, SignalHandler);
std::wcout << L"========================================" << std::endl;
std::wcout << L" Hunter Trainer - Starting up..." << std::endl;
std::wcout << L"========================================" << std::endl;
std::wcout << L"[Debug] sizeof(uintptr_t) = " << sizeof(uintptr_t) << std::endl;
// 创建进程管理器
ProcessManager processManager;
// 设置事件回调
processManager.SetOnProcessStart([](const ProcessEventArgs& args) {
std::wcout << L"\n[Event] Process started!" << std::endl;
std::wcout << L" Process ID: " << args.processInfo.processId << std::endl;
std::wcout << L" Version: " << args.processInfo.version << std::endl;
std::wcout << L" Base Address: 0x" << std::hex << args.processInfo.baseAddress << std::dec << std::endl;
std::wcout << L" Window: " << args.processInfo.windowTitle << std::endl;
});
processManager.SetOnProcessExit([]() {
std::wcout << L"\n[Event] Process exited!" << std::endl;
std::wcout << L"[Event] Waiting for process to restart..." << std::endl;
});
processManager.SetOnStatusChange([](ProcessStatus oldStatus, ProcessStatus newStatus) {
std::wcout << L"\n[Event] Status changed: "
<< StatusToString(oldStatus) << L" -> "
<< StatusToString(newStatus) << std::endl;
});
// 启动进程监视
processManager.Start();
PrintMenu();
// 主循环
while (g_running)
{
// 检查是否有键盘输入
if (_kbhit())
{
int ch = _getch();
char cmd = static_cast<char>(toupper(ch));
switch (cmd)
{
case 'S': // 显示状态
{
std::wcout << L"\n--- Current Status ---" << std::endl;
std::wcout << L"Status: " << StatusToString(processManager.GetStatus()) << std::endl;
auto process = processManager.GetCurrentProcess();
if (process.has_value())
{
std::wcout << L"Process ID: " << process->processId << std::endl;
std::wcout << L"Version: " << process->version << std::endl;
std::wcout << L"Base Address: 0x" << std::hex << process->baseAddress << std::dec << std::endl;
std::wcout << L"Window: " << process->windowTitle << std::endl;
}
else
{
std::wcout << L"No process attached" << std::endl;
}
break;
}
case 'T':
{
std::wcout << L"\n[Main] Testing catch mode,enter test ID" << std::endl;
int testId;
std::wcin >> testId;
switch(testId){
case 1:{
uintptr_t monsterAddr = processManager.FindFirstBigMonster();
if(monsterAddr != 0){
MonsterController monsterController(&processManager);
monsterController.TestCatchMovement(monsterAddr);
std::wcout << L"Tested catch movement on monster at address 0x" << std::hex << monsterAddr << std::dec << std::endl;
} else {
std::wcout << L"No big monster found to test catch movement." << std::endl;
}
break;
}
default:
std::wcout << L"Invalid test ID." << std::endl;
break;
}
break;
}
case 'R': // 刷新
std::wcout << L"\n[Main] Refreshing..." << std::endl;
break;
case 'Q': // 退出
std::wcout << L"\n[Main] Quitting..." << std::endl;
g_running = false;
break;
case 'K': {
uintptr_t ptr = processManager.FindFirstBigMonster();
if(ptr!=0){
std::wcout << L"Found big monster at address: 0x" << std::hex << ptr << std::dec << std::endl;
} else {
std::wcout << L"No big monster found." << std::endl;
}
break;
}
case 'W': {
std::wcout<< L"action id = " << std::endl;
int actionId;
std::wcin >> actionId;
uintptr_t monsterAddr = processManager.FindFirstBigMonster();
if(monsterAddr != 0){
MonsterController monsterController(&processManager);
monsterController.WriteData(monsterAddr, actionId);
std::wcout << L"Wrote action ID " << actionId << L" to monster at address 0x" << std::hex << monsterAddr << std::dec << std::endl;
} else {
std::wcout << L"No big monster found to write action ID." << std::endl;
}
break;
}
case '\\': {
uintptr_t monsterAddr = processManager.FindFirstBigMonster();
if (monsterAddr != 0) {
MonsterController monsterController(&processManager);
if (monsterController.FaceMonsterToPlayer(monsterAddr)) {
std::wcout << L"Turned monster toward player at address 0x"
<< std::hex << monsterAddr << std::dec << std::endl;
} else {
std::wcout << L"Failed to turn monster toward player." << std::endl;
}
} else {
std::wcout << L"No big monster found to face toward player." << std::endl;
}
break;
}
case 'P':{
uintptr_t monsterAddr = processManager.FindFirstBigMonster();
if(monsterAddr != 0){
auto frame = processManager.GetEntityAnimFrame(monsterAddr);
std::wcout << L"Monster Animation Frame: " << frame.current << L" / " << frame.end << std::endl;
} else {
std::wcout << L"No big monster found to get animation frame." << std::endl;
}
break;
}
case '\r':
case '\n':
// 忽略回车
break;
default:
PrintMenu();
break;
}
}
// 短暂休眠以降低 CPU 使用率
Sleep(100);
}
// 停止进程监视
std::wcout << L"[Main] Stopping process manager..." << std::endl;
processManager.Stop();
std::wcout << L"[Main] Goodbye!" << std::endl;
return 0;
}