forked from jewalky/a2mgr
-
Notifications
You must be signed in to change notification settings - Fork 3
/
chat_history.cpp
363 lines (307 loc) · 6.3 KB
/
chat_history.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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#include <vector>
#include <string>
#include "client_cmd.h"
#include "utils.h"
#include "zxmgr.h"
#include "lib\utils.hpp"
using namespace std;
vector< vector<string> > __chat_history;
unsigned long __chat_history_index = 0;
void __declspec(naked) __cdecl str_empty(char** cstr)
{
__asm
{
push ebp
mov ebp, esp
mov ecx, [ebp+0x08]
mov edx, 0x005AB7D5
call edx
mov esp, ebp
pop ebp
ret
}
}
void __declspec(naked) __cdecl str_assign(char** cstr, const char* str)
{
__asm
{
push ebp
mov ebp, esp
mov ecx, [ebp+0x08]
push dword ptr [ebp+0x0C]
mov edx, 0x005AB9E0
call edx
mov esp, ebp
pop ebp
ret
}
}
void __declspec(naked) __cdecl str_array_resize(char* pthis, unsigned long size)
{
__asm
{
push ebp
mov ebp, esp
mov ecx, [ebp+0x08]
push 0xFFFFFFFF
push dword ptr [ebp+0x0C]
mov edx, 0x005A8C4A
call edx
mov esp, ebp
pop ebp
ret
}
}
void addString(char* pthis)
{
if(!pthis) return;
char* arrptr = (char*)(pthis+0x70);
if(!arrptr) return;
unsigned long str_count = *(unsigned long*)(arrptr+0x08);
if(str_count)
{
vector<string> strings;
unsigned long* stringsa = *(unsigned long**)(arrptr+0x04);
for(int i = 0; i < str_count; i++)
{
char* stringc = (char*)stringsa[i];
strings.push_back(stringc);
}
__chat_history.push_back(strings);
__chat_history_index = __chat_history.size();
}
}
unsigned long setString(char* pthis)
{
if(!pthis) return 0;
char* arrptr = (char*)(pthis+0x70);
if(!arrptr) return 0;
vector<string> &strings = __chat_history[__chat_history_index];
unsigned long str_count = strings.size();
if(str_count)
{
str_array_resize(arrptr, str_count-1);
unsigned long* stringsa = *(unsigned long**)(arrptr+0x04);
for(int i = 0; i < str_count-1; i++)
stringsa[i] = (unsigned long)_strdup(strings[i].c_str());
char** cstr = (char**)(pthis+0x84);
str_empty(cstr);
str_assign(cstr, _strdup(strings[strings.size()-1].c_str()));
}
return str_count;
}
unsigned long _stdcall consoleDown(char* pthis)
{
if(!pthis) return 0;
char* arrtptr = *(char**)(pthis+0x168);
if(!arrtptr) return 0;
char** cstr = (char**)(pthis+0x84);
if(!cstr) return 0;
if(__chat_history_index < __chat_history.size()-1)
{
__chat_history_index++;
return setString(arrtptr);
}
return 0;
}
unsigned long _stdcall consoleUp(char* pthis)
{
if(!pthis) return 0;
char* arrtptr = *(char**)(pthis+0x168);
if(!arrtptr) return 0;
char** cstr = (char**)(pthis+0x84);
if(!cstr) return 0;
if(__chat_history_index)
{
__chat_history_index--;
return setString(arrtptr);
}
return 0;
}
string _stdcall getStringLastT()
{
vector<string> vec = __chat_history[__chat_history.size()-1];
string retv = "";
for(vector<string>::iterator i = vec.begin(); i != vec.end(); ++i)
{
string &stra = (*i);
retv += stra;
}
return retv;
}
void _stdcall getStringLast(char** cstr)
{
string last = getStringLastT();
char* asto = (char*)last.c_str();
if(strlen(asto) && asto[0] == '/')
{
CCMD_processCommand(asto);
asto[0] = 0;
}
str_empty(cstr);
str_assign(cstr, asto);
}
unsigned long _stdcall consoleEnter(char* pthis)
{
if(!pthis) return 0;
char* arrtptr = *(char**)(pthis+0x168);
if(!arrtptr) return 0;
unsigned long cnt = *(unsigned long*)(arrtptr+0x78);
if(cnt) addString(arrtptr);
return cnt;
}
void _stdcall consoleTab(void* pthis)
{
}
void _declspec(naked) CHAT_keyDown()
{ // 0043E1FB
__asm
{
push ebp
mov ebp, esp
sub esp, 8
mov [ebp-4], ecx
mov eax, [ebp+8]
cmp eax, 0x26
jz c_up
cmp eax, 0x28
jz c_down
cmp eax, 0x0D
jz c_enter
push dword ptr [ebp+8]
mov ecx, [ebp-4]
call sub_43E1FB
jmp c_exit
c_down:
push dword ptr [ebp-4]
call consoleDown
jmp c_exit
c_up:
push dword ptr [ebp-4]
call consoleUp
jmp c_exit
c_tab:
push dword ptr [ebp-4]
call consoleTab
jmp c_exit_1
c_enter:
push dword ptr [ebp-4]
call consoleEnter
test eax, eax
jnz c_msg_send
push 0
push 0
push 0x0446
mov ecx, [ebp-0x04]
mov edx, [ecx]
call [edx+0x48]
jmp c_exit_1
c_msg_send:
push 0
push 0
push 0x0445
mov ecx, [ebp-0x04]
mov edx, [ecx]
call [edx+0x48]
c_exit_1:
mov eax, 1
c_exit:
mov esp, ebp
pop ebp
retn 4
sub_43E1FB:
push ebp
mov ebp, esp
sub esp, 8
mov edx, 0x0043E201
jmp edx
}
}
void __declspec(naked) CHAT_getMessageLast()
{ // 48F167
__asm
{
lea eax, [ebp-0x10]
push eax
call getStringLast
mov edx, 0x0048F188
jmp edx
}
}
void _stdcall logOpen(unsigned long addr)
{
log_format("window open: %08X\n", addr);
}
void _stdcall logEscape(unsigned long addr, unsigned char ch)
{
/*SYSTEMTIME tm;
GetLocalTime(&tm);
std::string strf = Format("AfxGetMainWnd_%02u-%02u-%04u_%02u-%02u-%02u.dat", tm.wDay, tm.wMonth, tm.wYear, tm.wHour, tm.wMinute, tm.wSecond);
FILE* fil = fopen(strf.c_str(), "wb");
if(!fil) return;
const char* ch2 = (const char*)zxmgr::AfxGetMainWnd();
for(int i = 0; i < 0x400; i++)
fwrite(&ch2[i], 1, 1, fil);
fclose(fil);*/
}
bool _stdcall ConsoleProc(unsigned char ch, int unk);
void __declspec(naked) CHAT_fixEscape()
{ // 48A0F7
__asm
{
mov [ebp-0x30], edx
mov eax, [ebp-0x2C]
mov eax, [eax+0xCC]
mov eax, [eax]
push [ebp+0x08]
push eax
call logEscape
push [ebp-0x30] // key?
push [ebp+0x08] // key
call ConsoleProc
and eax, 0xFF
test eax, eax
jnz cfe_skipall
cmp [ebp-0x30], 0xB8
ja loc_48A5BC
cmp [ebp+0x08], 0x1B
jz cfe_skipesc
cfe_continue:
mov edx, 0x0048A107
jmp edx
loc_48A5BC:
mov edx, 0x0048A5BC
jmp edx
cfe_skipesc:
mov edx, 0x00401870
call edx
mov ebx, [eax+0xC0]
test ebx, ebx
jz cfe_continue
mov ecx, [eax+0xCC] // chat object
test ecx, ecx
jz cfe_continue
push 0
push 0
push 0x446
mov edx, [ecx]
call [edx+0x48]
jmp loc_48A5BC
cfe_skipall:
jmp loc_48A5BC
}
}
void __declspec(naked) CHAT_dbg()
{
__asm
{
push ebp
mov ebp, esp
push ecx
mov [ebp-0x04], ecx
push [ebp+0x08]
call logOpen
mov edx, 0x004913F2
jmp edx
}
}