forked from jewalky/srvmgr
-
Notifications
You must be signed in to change notification settings - Fork 5
/
a2server_utils.cpp
399 lines (364 loc) · 9.26 KB
/
a2server_utils.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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#include "srvmgr.h"
void _stdcall say_all(const char *s)
{
_asm
{
mov eax, dword ptr [s]
push eax
call say_all2
add esp, 4
}
}
void _declspec(naked) say_all2(void)
{
__asm
{///TESTED100%
push ebp
mov ebp, esp
sub esp, 8
lea ecx, [ebp-0x08]
mov edx, 0x496DC0
call edx // ??0Iostream_init@@QAE@XZ
// doubtful name
mov ecx, 0x06CDB24
mov ecx, [ecx]
push ecx
lea ecx, [ebp-0x08]
mov edx, 0x496DD0
call edx
loc_50303D: // CODE XREF: sub_50301F+30j
test eax, eax
jz loc_503051
mov edx, [ebp + 8]
push edx
push eax
call send_to_player
// add esp, 8
lea ecx, [ebp-0x08]
mov edx, 0x496E20
call edx
jmp loc_50303D
// ---------------------------------------------------------------------------
loc_503051: // CODE XREF: sub_50301F+20j
mov esp, ebp
pop ebp
ret
}
}
void _declspec(naked) kick_all(void)
{
__asm
{///TESTED100%
push ebp
mov ebp, esp
sub esp, 8
lea ecx, [ebp-0x08]
mov edx, 0x496DC0
call edx // ??0Iostream_init@@QAE@XZ
// doubtful name
mov ecx, 0x06CDB24
mov ecx, [ecx]
push ecx
lea ecx, [ebp-0x08]
mov edx, 0x496DD0
call edx
loc_50303D: // CODE XREF: sub_50301F+30j
test eax, eax
jz loc_503051
push eax
call kick_char
add esp, 4
lea ecx, [ebp-0x08]
mov edx, 0x496E20
call edx
jmp loc_50303D
// ---------------------------------------------------------------------------
loc_503051: // CODE XREF: sub_50301F+20j
mov esp, ebp
pop ebp
ret
}
}
void _declspec(naked) upd_all(void)
{
__asm
{///TESTED100%
push ebp
mov ebp, esp
sub esp, 8
lea ecx, [ebp-0x08]
mov edx, 0x496DC0
call edx // ??0Iostream_init@@QAE@XZ
// doubtful name
mov ecx, 0x06CDB24
mov ecx, [ecx]
push ecx
lea ecx, [ebp-0x08]
mov edx, 0x496DD0
call edx
loc1_50303D: // CODE XREF: sub_50301F+30j
test eax, eax
jz loc1_503051
cmp dword ptr [eax+2Ch], 0
jnz loc_skip///AI
mov eax, [eax+0x38]
push eax
mov ecx, 0x642C2C
mov ecx, [ecx]
mov edx, 0x4EE028
call edx //// принудительное сохранение
loc_skip:
lea ecx, [ebp-0x08]
mov edx, 0x496E20
call edx
jmp loc1_50303D
// ---------------------------------------------------------------------------
loc1_503051: // CODE XREF: sub_50301F+20j
mov esp, ebp
pop ebp
retn
}
}
void _declspec(naked) map_exit(void)
{
__asm
{///// STDCALL TESTED100%
push ebp /// 04F94C0
mov ebp, esp
push ecx
mov [ebp-0x04], ecx
mov ecx, 0x06D1648 ///тип игры
cmp dword ptr [ecx], 1
jz loc_4F94D9
cmp dword ptr [ecx], 2
jnz loc_4F94E5 // обычная
loc_4F94D9: // CODE XREF: sub_4F94C0+Ej
push 0
mov ecx, 0x6C3A08
mov edx, 0x51D6B4
call edx
loc_4F94E5: // CODE XREF: sub_4F94C0+17j
call kick_all
mov ecx, [ebp-0x04]
mov dword ptr [ecx+208h], 1
//loc_4F9509: // CODE XREF: sub_4F94C0+37j
mov esp, ebp
pop ebp
retn 4
}
}
/*
void _declspec(naked) kick_char(void)
{
__asm
{////TESTED100%, CDECL
push ebp
mov ebp, esp
mov eax, [ebp+0x08]
test eax, eax
jz loc_502E48
cmp dword ptr [eax+2Ch], 0
jnz loc_502E48
mov eax, [eax+0x38]
push eax
mov ecx, 0x642C2C
mov ecx, [ecx]
mov edx, 0x4EE028
call edx //// принудительное сохранение
mov eax, [ebp+0x08]
xor ecx, ecx
mov cx, [eax+4]
push ecx
mov ecx, 0x6C3A08
mov edx, 0x518544
call edx
push eax
mov ecx, 0x6C3A08
mov edx, 0x5170B6
call edx
mov ecx, 0x6C3A08
mov edx, 0x51800F
call edx
mov eax, [ebp+0x08]
push eax
mov ecx, 0x6C3A08
mov edx, 0x51D49B
call edx
mov ecx, 0x0642C2C
mov ecx, [ecx]
mov edx, [ecx]
dec edx
mov eax, [ebp+0x08]
mov [eax+0A50h], edx
mov ecx, 0x06CDB24
mov ecx, [ecx]
mov edx, 0x534DDD
call edx
loc_502E48:
mov esp, ebp
pop ebp
retn
}
}
*/
void _declspec(naked) kick_char(void)
{
__asm
{////TESTED100%, CDECL
push ebp
mov ebp, esp
mov eax, [ebp+0x08]
test eax, eax
jz loc_502E48
cmp dword ptr [eax+2Ch], 0
jnz loc_502E48
mov eax, [eax+0x38]
push eax
mov ecx, 0x642C2C
mov ecx, [ecx]
mov edx, 0x4EE028
call edx //// принудительное сохранение
mov eax, [ebp+0x08]
xor ecx, ecx
mov cx, [eax+4]
push ecx
mov ecx, 0x6C3A08
mov edx, 0x518544
call edx
push eax
mov ecx, 0x6C3A08
mov edx, 0x5170B6
call edx
mov ecx, 0x6C3A08
mov edx, 0x51800F
call edx
/// уведомление "Игрок был выкикан с сервера
mov eax, [ebp+0x08]
mov eax, [eax+14h]
shr eax, 18h
cmp al, 3Fh
jnz k_c_c ///не админ, продолжаем
mov eax, [edx+14h]
test eax, 0x800 ///
jz k_c_c
jmp k_c_s
k_c_c:
mov eax, [ebp+0x08]
push eax
mov ecx, 0x6C3A08
mov edx, 0x51D49B
call edx
/// уведомление "Игрок был выкикан с сервера
k_c_s:
mov ecx, 0x0642C2C
mov ecx, [ecx]
mov edx, [ecx]
dec edx
mov eax, [ebp+0x08]
mov [eax+0A50h], edx
mov ecx, 0x06CDB24
mov ecx, [ecx]
mov edx, 0x534DDD
call edx
loc_502E48:
mov esp, ebp
pop ebp
retn
}
}
void kick_by_name(const char *s)
{
__asm
{
push dword ptr [s]
call kick_by_name_2
add esp, 4
}
}
void _declspec(naked) kick_by_name_2() /// doesnt work :(((
{
__asm
{///TESTED100%
push ebp
mov ebp, esp
sub esp, 0x0C
lea ecx, [ebp-0x08]
mov edx, 0x496DC0
call edx // ??0Iostream_init@@QAE@XZ
// doubtful name
mov ecx, 0x06CDB24
mov ecx, [ecx]
push ecx
lea ecx, [ebp-0x08]
mov edx, 0x496DD0
call edx
loc_50303D: // CODE XREF: sub_50301F+30j
test eax, eax
jz loc_503051
cmp dword ptr [eax+2Ch], 0
jnz loc_503051
mov [ebp-0x0c], eax // unit (?)
//mov eax, [eax + 0x14] // player
mov eax, [eax + 0x0A78] // вроде как имя логина
push eax
mov eax, [ebp+0x08]
push eax
mov edx, 0x05BEDB0
call edx
test eax, eax
jnz loc_503051
mov eax, [ebp-0x0C]
push eax
call kick_char
add esp, 4
lea ecx, [ebp-0x08]
mov edx, 0x496E20
call edx
jmp loc_50303D
// ---------------------------------------------------------------------------
loc_503051: // CODE XREF: sub_50301F+20j
mov esp, ebp
pop ebp
ret
}
}
void kick(const char *name) // nick name
{
_asm
{ ///TESTED100%
push dword ptr [name] // name (arg_0)
call get_player_by_name // get player by name
push eax
call kick_char
add esp, 4
}
}
void __stdcall send_to_player(void *p, const char *msg) {
__asm {///TESTED100%, STDCALL
mov ecx, dword ptr [p]
push ecx
lea edx, dword ptr [msg]
push edx
mov ecx, 0x6C3A08
mov edx, 0x51CD89
call edx
}
}
void * __stdcall get_player_by_name(const char *name)
{
__asm
{
sub esp, 4
mov ecx, esp
push dword ptr [name] // name (arg_0)
mov edx, 0x005DD8F8 // CString::CString()
call edx
mov eax, [eax]
push eax
mov ecx, 0x6CDB24
mov ecx, [ecx]
mov edx, 0x535D39 /// stdcall
call edx // get player by name
add esp, 4
}
}