-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathgameservice.cpp
7581 lines (6440 loc) · 217 KB
/
gameservice.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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <Windows.h>
#include <Detours.h>
#include "gameservice.h"
#include "commandline.h"
#include <ddraw.h>
#include <boost/locale.hpp>
#include <rapidjson/document.h>
#include <rapidjson/writer.h>
#include <intrin.h>
#include "inject.h"
extern HWND g_MainHwnd;
extern HMODULE g_hCGAModule;
extern WCHAR g_szCGAModulePath[1024];
#pragma comment(lib, "ntdll.lib")
extern "C"
NTSYSCALLAPI
NTSTATUS
NTAPI
NtTerminateProcess(
_In_opt_ HANDLE ProcessHandle,
_In_ NTSTATUS ExitStatus
);
const int index2player_flags[] = {
PLAYER_ENABLE_FLAGS_PK,
PLAYER_ENABLE_FLAGS_TEAMCHAT,
PLAYER_ENABLE_FLAGS_JOINTEAM,
PLAYER_ENABLE_FLAGS_CARD,
PLAYER_ENABLE_FLAGS_TRADE,
PLAYER_ENABLE_FLAGS_FAMILY
};
void ANSIToUnicode(const std::string &str, std::wstring &out)
{
int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), NULL, 0);
out.resize(len);
MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), (LPWSTR)out.data(), len);
}
void WriteLog(LPCSTR fmt, ...)
{
#if 0
char buffer[4096];
va_list argptr;
int cnt;
va_start(argptr, fmt);
cnt = vsprintf(buffer, fmt, argptr);
va_end(argptr);
FILE *fp = fopen("cga_log.txt", "a+");
if (fp)
{
setlocale(LC_ALL, "chs");
SYSTEMTIME tm;
GetLocalTime(&tm);
fprintf(fp, "%02d:%02d:%02d.%03d\t", tm.wHour, tm.wMinute, tm.wSecond, tm.wMilliseconds);
fputs(buffer, fp);
fclose(fp);
}
#endif
}
void WriteLog2(LPCSTR buffer)
{
#if 0
FILE *fp = fopen("cga_log.txt", "a+");
if (fp)
{
setlocale(LC_ALL, "chs");
SYSTEMTIME tm;
GetLocalTime(&tm);
fprintf(fp, "%02d:%02d:%02d.%03d\t", tm.wHour, tm.wMinute, tm.wSecond, tm.wMilliseconds);
fputs(buffer, fp);
fclose(fp);
}
#endif
}
using namespace CGA;
CGAService g_CGAService;
CXorValue::CXorValue(int value)
{
int r = rand();
key2 = r;
refcount = 0;
key1 = value ^ r;
}
int CXorValue::decode()
{
return key1^key2;
}
void CXorValue::set(int value)
{
key1 = rand();
key2 = value ^ key1;
}
char *NET_FindDelimeter(const char *src, char deli)
{
char *p2;
for (auto p = (char *)src; ; p = p2 + 1)
{
while (1)
{
if (!*p)
return 0;
if ((UCHAR)*p >= 128 || (UCHAR)*p == 255)
break;
if (*p == deli)
return p + 1;
++p;
}
p2 = p + 1;
if (!*p2)
break;
}
return NULL;
}
int NET_SubStrDelimeter(const char *src, char deli, int len, char *buf)
{
int i;
for (i = 0; i < len; ++i)
{
if ((UCHAR)src[i] >= 128 || (UCHAR)src[i] == 255)
{
buf[i] = src[i];
++i;
if (i >= len)
break;
buf[i] = src[i];
if (!buf[i])
return 1;
}
else
{
if (src[i] == deli)
{
buf[i] = 0;
return 0;
}
buf[i] = src[i];
if (!buf[i])
return 1;
}
}
buf[i] = 0;
return 1;
}
int NET_ParseDelimeter(const char *src, char deli, int position, int buflen, char *buf)
{
auto p = (char *)src;
for (int i = 0; i < position - 1 && p; ++i)
p = NET_FindDelimeter(p, deli);
if (p)
return NET_SubStrDelimeter(p, deli, buflen, buf);
*buf = 0;
return 1;
}
int NET_ParseInteger(const char *src, char deli, int position)
{
char buf[128] = {0};
NET_ParseDelimeter(src, deli, position, 127, buf);
if (buf[0])
return atoi((const char *)buf);
return -1;
}
int NET_ParseHexInteger(const char *src, char deli, int position)
{
char buf[128] = { 0 };
NET_ParseDelimeter(src, deli, position, 127, buf);
if (buf[0]) {
int res;
if(1 == sscanf(buf, "%X", &res))
return res;
}
return -1;
}
char NET_EscapeCharFromTable(char ch)
{
static char table[] = "n\nc,z|y\\";
for (int i = 0; i < 4; ++i)
{
if (table[2 * i] == ch)
return table[2 * i + 1];
}
return ch;
}
char *NET_EscapeStringEx(char *src)
{
size_t len; // kr00_4@1
int v2; // ST18_4@4
int v4; // [sp+14h] [bp-8h]@1
len = strlen(src);
v4 = 0;
for (size_t i = 0; i < len; ++i)
{
if ((UCHAR)src[i] & 0x80)
{
src[v4] = src[i];
v2 = v4 + 1;
++i;
src[v2] = src[i];
v4 = v2 + 1;
}
else if (src[i] == '\\')
{
++i;
src[v4++] = NET_EscapeCharFromTable(src[i]);
}
else
{
src[v4++] = src[i];
}
}
src[v4] = 0;
return src;
}
char *NET_EscapeStringEx2(const char *str, char *dst, int maxlen)
{
int srclen;
int i;
int j;
char ch;
srclen = strlen(str);
for ( i = 0, j = 0; i < srclen && j < maxlen - 1; ++i)
{
if ((UCHAR)str[i] != (UCHAR)0xFF)
{
if (str[i] & 0x80)
{
if (j + 1 == maxlen - 1) break;
dst[j++] = str[i];
i++;
if ( i == srclen ) break;
dst[j++] = str[i];
}
else if (str[i] == '\\')
{
i++;
if ( i == srclen ) break;
ch = NET_EscapeCharFromTable(str[i]);
if (ch == '\\')
{
if (j + 1 == maxlen - 1) break;
dst[j++] = '\\';
dst[j++] = '\\';
}
else if (ch == '\n')
{
if (j + 1 == maxlen - 1) break;
dst[j++] = '\\';
dst[j++] = 'n';
}
else
{
dst[j++] = ch;
}
}
else
{
dst[j++] = str[i];
}
}
}
dst[j] = 0;
return dst;
}
void CGA_NotifyBattleAction(int flags);
void CGA_NotifyBattleMotionPacket(const std::string &buf);
void CGA_NotifyPlayerMenu(const cga_player_menu_items_t &players);
void CGA_NotifyUnitMenu(const cga_unit_menu_items_t &units);
void CGA_NotifyNPCDialog(const cga_npc_dialog_t &dlg);
void CGA_NotifyWorkingResult(const CGA::cga_working_result_t &result);
void CGA_NotifyChatMsg(const CGA::cga_chat_msg_t &msg);
void CGA_NotifyTradeStuffs(const CGA::cga_trade_stuff_info_t &msg);
void CGA_NotifyTradeDialog(const CGA::cga_trade_dialog_t &msg);
void CGA_NotifyTradeState(int state);
void CGA_NotifyDownloadMap(const CGA::cga_download_map_t &msg);
void CGA_NotifyConnectionState(const CGA::cga_conn_state_t &msg);
char *__cdecl NewV_strstr(char *a1, const char *a2)
{
if (!strcmp(a2, "gid:") && g_CGAService.m_fakeCGSharedMem[0])
{
strcpy(a1, g_CGAService.m_fakeCGSharedMem);
}
return g_CGAService.V_strstr(a1, a2);
}
double CGAService::GetNextAnimTickCount()
{
return *g_next_anim_tick;
}
int CGAService::GetCraftStatus()
{
return *g_craft_status;
}
bool CGAService::IsUIDialogPresent(int dialog)
{
if (dialog == UI_DIALOG_TRADE)
{
return *(DWORD *)g_ui_trade_dialog != 0;
}
if (dialog == UI_DIALOG_BATTLE_SKILL)
{
return *(DWORD *)g_ui_battle_skill_dialog != 0;
}
return false;
}
VOID CGAService::NewSleep(_In_ DWORD dwMilliseconds)
{
if (m_game_type == game_type::polcn)
{
}
else
{
if (*g_next_anim_tick >= 900000000.0)
*g_next_anim_tick -= (double)((int)(*g_next_anim_tick) - ((int)(*g_next_anim_tick) % 900000000));
if (dwMilliseconds == 1 && GetWorldStatus() == 1 && GetGameStatus() == 0 && !IsInGame())
{
*g_mouse_states |= 1;
}
}
pfnSleep(dwMilliseconds);
}
VOID WINAPI NewSleep(_In_ DWORD dwMilliseconds)
{
g_CGAService.NewSleep(dwMilliseconds);
}
BOOL WINAPI NewRegisterHotKey(
_In_opt_ HWND hWnd,
_In_ int id,
_In_ UINT fsModifiers,
_In_ UINT vk)
{
return TRUE;
}
HANDLE WINAPI NewCreateMutexA(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner, LPCSTR lpName)
{
if (lpName && !strcmp(lpName, "POLCN Mutex"))
{
SetLastError(0);
return NULL;
}
return g_CGAService.pfnCreateMutexA(lpMutexAttributes, bInitialOwner, lpName);
}
int __fastcall NewOnLoginResult(void *pthis, int dummy, int a1, int result, const char *glt, int gltlength, char **gid_array, int gid_count, int *gid_status_array, int gid_status_count, int *gid_unk1_array, int gid_unk1_count, int *gid_unk2_array, int gid_unk2_count, int *gid_unk3_array, int gid_unk3_count, int a15, int card_point)
{
using namespace rapidjson;
Document doc;
doc.SetObject();
Value result_s;
result_s.SetInt(result);
doc.AddMember("result", result_s, doc.GetAllocator());
if (result == 0)
{
Value glt_s;
glt_s.SetString(glt, gltlength, doc.GetAllocator());
doc.AddMember("glt", glt_s, doc.GetAllocator());
Value gid_array_s(kArrayType);
for (int i = 0; i < gid_count; ++i)
{
Value gid_object_s(kObjectType);
Value gid_name_s;
gid_name_s.SetString((const char *)gid_array[i], doc.GetAllocator());
gid_object_s.AddMember("name", gid_name_s, doc.GetAllocator());
Value gid_status_s;
gid_status_s.SetInt(gid_status_array[i]);
gid_object_s.AddMember("status", gid_status_s, doc.GetAllocator());
Value gid_unk1_s;
gid_unk1_s.SetInt(gid_unk1_array[i]);
gid_object_s.AddMember("unk1", gid_unk1_s, doc.GetAllocator());
Value gid_unk2_s;
gid_unk2_s.SetInt(gid_unk2_array[i]);
gid_object_s.AddMember("unk2", gid_unk2_s, doc.GetAllocator());
Value gid_unk3_s;
gid_unk3_s.SetInt(gid_unk3_array[i]);
gid_object_s.AddMember("unk3", gid_unk3_s, doc.GetAllocator());
gid_array_s.PushBack(gid_object_s, doc.GetAllocator());
}
doc.AddMember("gid", gid_array_s, doc.GetAllocator());
Value serverid_s;
serverid_s.SetInt(a15 + 0x80000000);
doc.AddMember("serverid", serverid_s, doc.GetAllocator());
Value card_point_s;
card_point_s.SetInt(card_point);
doc.AddMember("card_point", card_point_s, doc.GetAllocator());
int rungame = CommandLine()->ParmValue("-rungame", 0);
if (rungame >= 1)
{
int gametype = CommandLine()->ParmValue("-gametype", 4);
auto cwndbtn = ((*(char **)g_CGAService.g_MainCwnd) + 0x1F0);
auto page = *(int *)(cwndbtn + 0x968);
auto hwnd = *(HWND *)(cwndbtn + 0x164);
if (page == 0)
{
if (gametype == 4 || gametype == 40)
SendMessageA(hwnd, LB_SETCURSEL, 0, 0);
else if (gametype == 1)
SendMessageA(hwnd, LB_SETCURSEL, 1, 0);
else if (gametype == 11)
SendMessageA(hwnd, LB_SETCURSEL, 2, 0);
}
g_CGAService.GoNext(cwndbtn, 0);
page = *(int *)(cwndbtn + 0x968);
if (page == 1)
{
if (gametype == 4)
SendMessageA(hwnd, LB_SETCURSEL, 0, 0);
else if (gametype == 40)
SendMessageA(hwnd, LB_SETCURSEL, 1, 0);
else if (gametype == 1)
SendMessageA(hwnd, LB_SETCURSEL, 0, 0);
else if (gametype == 11)
SendMessageA(hwnd, LB_SETCURSEL, 0, 0);
}
g_CGAService.GoNext(cwndbtn, 0);
g_CGAService.OnLoginResult(pthis, dummy, a1, result, glt, gltlength, gid_array, gid_count, gid_status_array, gid_status_count, gid_unk1_array, gid_unk1_count, gid_unk2_array, gid_unk2_count, gid_unk3_array, gid_unk3_count, a15, card_point);
if (gid_count > 1)
g_CGAService.LaunchGame((*(char **)g_CGAService.g_MainCwnd) + 0xD4, 0);
Value game_pid_s;
game_pid_s.SetInt(g_CGAService.m_run_game_pid);
doc.AddMember("game_pid", game_pid_s, doc.GetAllocator());
Value game_tid_s;
game_tid_s.SetInt(g_CGAService.m_run_game_tid);
doc.AddMember("game_tid", game_tid_s, doc.GetAllocator());
}
}
StringBuffer sb;
Writer<StringBuffer> writer(sb);
doc.Accept(writer);
puts(sb.GetString());
fflush(stdout);
//WriteLog("NtTerminateProcess\n");
NtTerminateProcess((HANDLE)-1, 0);
return 0;
}
BOOL WINAPI NewShell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATAA lpData)
{
return TRUE;
}
int __fastcall NewCWnd_ShowWindow(void *pthis, int dummy, int sw)
{
return g_CGAService.CWnd_ShowWindow(pthis, dummy, SW_HIDE);
}
int __fastcall NewCWnd_MessageBoxA(void *pthis, int dummy, LPCSTR str, LPCSTR title, int icon)
{
using namespace rapidjson;
Document doc;
doc.SetObject();
Value result_s;
result_s.SetInt(-1);
doc.AddMember("result", result_s, doc.GetAllocator());
std::string msg = boost::locale::conv::to_utf<char>(str, "GBK");
Value msg_s;
msg_s.SetString(msg.c_str(), msg.length(), doc.GetAllocator());
doc.AddMember("message", msg_s, doc.GetAllocator());
StringBuffer sb;
Writer<StringBuffer> writer(sb);
doc.Accept(writer);
puts(sb.GetString());
fflush(stdout);
NtTerminateProcess((HANDLE)-1, 0);
return 0;
}
void *__fastcall NewCWnd_SetFocus(void *pthis, int dummy)
{
return 0;
}
int __fastcall NewCDialog_DoModal(void *pthis, int dummy)
{
return 1;
}
HWND WINAPI NewSetActiveWindow_NewSetFocus(HWND hWnd)
{
return NULL;
}
BOOL WINAPI NewSetForegroundWindow(HWND hWnd)
{
return TRUE;
}
extern "C"
{
NTSYSAPI ULONG NTAPI RtlWalkFrameChain(
OUT PVOID *Callers,
IN ULONG Count,
IN ULONG Flags
);
}
BOOL WINAPI NewCreateProcessA(
_In_opt_ LPCSTR lpApplicationName,
_Inout_opt_ LPSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles,
_In_ DWORD dwCreationFlags,
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCSTR lpCurrentDirectory,
_In_ LPSTARTUPINFOA lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInformation
)
{
dwCreationFlags |= CREATE_SUSPENDED;
auto r = g_CGAService.pfnCreateProcessA(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation);
if (r && lpProcessInformation->dwProcessId)
{
bool bLegitCaller = false;
PVOID callers[16];
ULONG caller_count = RtlWalkFrameChain(callers, _countof(callers), 0);
for (ULONG i = 0; i < caller_count; ++i)
{
if (callers[i] == (PVOID)(g_CGAService.m_ImageBase + 0x6CFF))
{
bLegitCaller = true;
break;
}
}
if (bLegitCaller)
{
g_CGAService.m_run_game_pid = lpProcessInformation->dwProcessId;
g_CGAService.m_run_game_tid = lpProcessInformation->dwThreadId;
if (g_szCGAModulePath[0])
{
CInject injector;
injector.Initialize();
injector.InjectByHookNtdll(lpProcessInformation->hProcess, g_szCGAModulePath);
}
}
ResumeThread(lpProcessInformation->hThread);
}
return r;
}
void *__cdecl NewConfigManager_GetConfig(void *a1, LPCSTR a2, void *a3, int a4)
{
DWORD pStringManager = *(DWORD *)a3;
if (pStringManager < 0x1000)
{
using namespace rapidjson;
Document doc;
doc.SetObject();
Value result_s;
result_s.SetInt(-1);
doc.AddMember("result", result_s, doc.GetAllocator());
std::string msg = "Config [";
msg += a2;
msg += "] not found";
Value msg_s;
msg_s.SetString(msg.c_str(), msg.length(), doc.GetAllocator());
doc.AddMember("message", msg_s, doc.GetAllocator());
StringBuffer sb;
Writer<StringBuffer> writer(sb);
doc.Accept(writer);
puts(sb.GetString());
fflush(stdout);
NtTerminateProcess((HANDLE)-1, 0);
return NULL;
}
return g_CGAService.ConfigManager_GetConfig(a1, a2, a3, a4);
}
int __fastcall NewCMainDialog_OnInitDialog(void *pthis, int dummy)
{
auto r = g_CGAService.CMainDialog_OnInitDialog(pthis, dummy);
void *LoginManager = *(void **)((char *)g_CGAService.g_AppInstance + 172);
void **vftable = *(void ***)LoginManager;
void **newvftable = new void *[6];
memcpy(newvftable, vftable, sizeof(void *) * 6);
*(void ***)LoginManager = newvftable;
g_CGAService.SendClientLogin = (decltype(g_CGAService.SendClientLogin))vftable[3];
g_CGAService.OnLoginResult = (decltype(g_CGAService.OnLoginResult))vftable[5];
newvftable[5] = NewOnLoginResult;
const char *account = CommandLine()->ParmValue("-account", "");
const char *pwd = CommandLine()->ParmValue("-pwd", "");
const char *bigserver = CommandLine()->ParmValue("-bigserver", "");
int gametype = CommandLine()->ParmValue("-gametype", 4);
g_CGAService.WM_SendClientLogin(account, pwd, gametype);
return r;
}
void CGAService::NewBATTLE_PlayerAction()
{
int prevPlayerStatus = *g_btl_player_status;
BATTLE_PlayerAction();
int playerStatus = *g_btl_player_status;
if (prevPlayerStatus == 2 && playerStatus == 0)
{
//Double action
m_btl_double_action = true;
}
if (prevPlayerStatus != 1 && playerStatus == 1)
{
//WriteLog("CGA_NotifyBattleAction player\n");
int flags = FL_BATTLE_ACTION_ISPLAYER;
if (m_btl_double_action)
flags |= FL_BATTLE_ACTION_ISDOUBLE;
if (*g_btl_skill_performed)
flags |= FL_BATTLE_ACTION_ISSKILLPERFORMED;
CGA_NotifyBattleAction(flags);
}
else if (prevPlayerStatus != 4 && playerStatus == 4)
{
if (m_btl_pet_skill_packet_send)
{
//WriteLog("m_btl_pet_skill_packet_send = true\n");
*g_btl_action_done = 1;
m_btl_pet_skill_packet_send = false;
return;
}
else
{
//WriteLog("CGA_NotifyBattleAction pet\n");
}
//Notify pet action
int flags = 0;
if (m_btl_double_action)
flags |= FL_BATTLE_ACTION_ISDOUBLE;
if (*g_btl_skill_performed)
flags |= FL_BATTLE_ACTION_ISSKILLPERFORMED;
CGA_NotifyBattleAction(flags);
}
}
void __cdecl NewBATTLE_PlayerAction()
{
g_CGAService.NewBATTLE_PlayerAction();
}
void __cdecl NewNET_WriteEndBattlePacket_cgitem(int a1, int a2)
{
g_CGAService.NET_WriteEndBattlePacket_cgitem(a1, a2);
//WriteLog("NewNET_WriteEndBattlePacket_cgitem\n");
CGA_NotifyBattleAction(FL_BATTLE_ACTION_END);
}
void CGAService::NewNET_ParseTradeItemsPackets(int a1, const char *buf)
{
//WriteLog("NewNET_ParseTradeItemsPackets\n");
//WriteLog(buf);
NET_ParseTradeItemsPackets(a1, buf);
cga_trade_stuff_info_t info(TRADE_STUFFS_ITEM);
char buffer[1024];
for (int i = 0; ; ++i)
{
int position = 14 * i + 1;
int itempos = NET_ParseInteger(buf, '|', position);
if (NET_ParseDelimeter(buf, '|', position + 1, 255, buffer) == 1)
break;
NET_EscapeStringEx(buffer);
std::string itemname = boost::locale::conv::to_utf<char>(buffer, "GBK");
NET_ParseDelimeter(buf, '|', position + 3, 767, buffer);
NET_EscapeStringEx(buffer);
std::string itemattr = boost::locale::conv::to_utf<char>(buffer, "GBK");
NET_ParseDelimeter(buf, '|', position + 13, 255, buffer);
NET_EscapeStringEx(buffer);
std::string itemattr2 = boost::locale::conv::to_utf<char>(buffer, "GBK");
int image_id = NET_ParseInteger(buf, '|', position + 4);
int level = NET_ParseInteger(buf, '|', position + 8);
int item_id = NET_ParseInteger(buf, '|', position + 10);
int type = NET_ParseInteger(buf, '|', position + 11);
int count = NET_ParseInteger(buf, '|', position + 12);
info.items.emplace_back(
itemname,
itemattr,
itemattr2,
item_id,
count,
itempos,
level,
type,
false,
0
);
}
CGA_NotifyTradeStuffs(info);
}
void __cdecl NewNET_ParseTradeItemsPackets(int a1, const char *buf)
{
g_CGAService.NewNET_ParseTradeItemsPackets(a1, buf);
}
void CGAService::NewNET_ParseTradePetPackets(int a1, int index, const char *buf)
{
NET_ParseTradePetPackets(a1, index, buf);
//WriteLog("NewNET_ParseTradePetPackets\n");
//WriteLog2(buf);
char name[256];
if (0 == NET_ParseDelimeter(buf, '|', 1, 255, name))
{
cga_trade_stuff_info_t info(TRADE_STUFFS_PET);
NET_EscapeStringEx(name);
info.pet.index = index;
info.pet.name = boost::locale::conv::to_utf<char>(name, "GBK");
info.pet.level = NET_ParseInteger(buf, '|', 2);
info.pet.detail.points_remain = NET_ParseInteger(buf, '|', 3);
info.pet.race = NET_ParseInteger(buf, '|', 4);
info.pet.maxhp = NET_ParseInteger(buf, '|', 5);
info.pet.maxmp = NET_ParseInteger(buf, '|', 6);
info.pet.detail.points_endurance = NET_ParseInteger(buf, '|', 7);
info.pet.detail.points_strength = NET_ParseInteger(buf, '|', 8);
info.pet.detail.points_defense = NET_ParseInteger(buf, '|', 9);
info.pet.detail.points_agility = NET_ParseInteger(buf, '|', 10);
info.pet.detail.points_magical = NET_ParseInteger(buf, '|', 11);
info.pet.loyality = NET_ParseInteger(buf, '|', 12);
info.pet.skill_count = NET_ParseInteger(buf, '|', 13);
if (0 == NET_ParseDelimeter(buf, '|', 14, 255, name))
{
NET_EscapeStringEx(name);
info.pet.realname = boost::locale::conv::to_utf<char>(name, "GBK");
}
info.pet.image_id = NET_ParseInteger(buf, '|', 15);
info.pet.detail.value_attack = NET_ParseInteger(buf, '|', 16);
info.pet.detail.value_defensive = NET_ParseInteger(buf, '|', 17);
info.pet.detail.value_agility = NET_ParseInteger(buf, '|', 18);
info.pet.detail.value_spirit = NET_ParseInteger(buf, '|', 19);
info.pet.detail.value_recovery = NET_ParseInteger(buf, '|', 20);
info.pet.detail.element_earth = NET_ParseInteger(buf, '|', 21);
info.pet.detail.element_water = NET_ParseInteger(buf, '|', 22);
info.pet.detail.element_fire = NET_ParseInteger(buf, '|', 23);
info.pet.detail.element_wind = NET_ParseInteger(buf, '|', 24);
CGA_NotifyTradeStuffs(info);
}
}
void __cdecl NewNET_ParseTradePetPackets(int a1, int index, const char *buf)
{
g_CGAService.NewNET_ParseTradePetPackets(a1, index, buf);
}
void CGAService::NewNET_ParseTradePetSkillPackets(int a1, int index, const char *buf)
{
NET_ParseTradePetSkillPackets(a1, index, buf);
//WriteLog("NewNET_ParseTradePetSkillPackets\n");
//WriteLog2(buf);
cga_trade_stuff_info_t info(TRADE_STUFFS_PETSKILL);
char name[256];
info.petskills.index = index;
for (int i = 0; i < 10; ++i)
{
if (1 != NET_ParseDelimeter(buf, '|', i + 1, 255, name))
{
NET_EscapeStringEx(name);
info.petskills.skills.emplace_back(boost::locale::conv::to_utf<char>(name, "GBK"));
}
}
CGA_NotifyTradeStuffs(info);
}
void __cdecl NewNET_ParseTradePetSkillPackets(int a1, int index, const char *buf)
{
g_CGAService.NewNET_ParseTradePetSkillPackets(a1, index, buf);
}
void CGAService::NewNET_ParseTradeGoldPackets(int a1, int gold)
{
//WriteLog("NewNET_ParseTradeGoldPackets\n");
NET_ParseTradeGoldPackets(a1, gold);
cga_trade_stuff_info_t info(TRADE_STUFFS_GOLD);
info.gold = gold;
CGA_NotifyTradeStuffs(info);
}
void __cdecl NewNET_ParseTradeGoldPackets(int a1, int gold)
{
g_CGAService.NewNET_ParseTradeGoldPackets(a1, gold);
}
void CGAService::NewNET_ParseTradePlayers(int a1, const char *src, char *src2)
{
//WriteLog("NewNET_ParseTradePlayers\n");
NET_ParseTradePlayers(a1, src, src2);
char buf[256];
int numplayers = 0;
int position = 1;
cga_player_menu_items_t players;
for (int i = 0; i < 10; ++i)
{
if (numplayers >= 10)
break;
if (NET_ParseDelimeter(src, '|', position, 255, buf) == 1)
break;
NET_EscapeStringEx(buf);
std::string playername = boost::locale::conv::to_utf<char>(buf, "GBK");
if (NET_ParseDelimeter(src2, '|', position, 255, buf) == 1)
break;
NET_EscapeStringEx(buf);
int playerlevel = atoi(buf);
players.emplace_back(
playername,
playerlevel,
i
);
++position;
++numplayers;
}
m_player_menu_type = PLAYER_MENU_TRADE;
CGA_NotifyPlayerMenu(players);
}
void __cdecl NewNET_ParseTradePlayers(int a1, const char *src, char *src2)
{
g_CGAService.NewNET_ParseTradePlayers(a1, src, src2);
}
void CGAService::NewNET_ParseHealPlayers(int a1, const char *src)
{
//WriteLog("NewNET_ParseHealPlayers %s\n", src);
NET_ParseHealPlayers(a1, src);
char buf[256];
int numplayers = 0;
int position = 1;
cga_player_menu_items_t players;
std::string playername;
playername = boost::locale::conv::to_utf<char>((*g_playerBase)->name, "GBK");
players.emplace_back(
playername,
0,
numplayers
);
numplayers++;
for (int i = 0; i < 5; ++i)
{
if (g_team_player_base[i].valid &&
g_team_player_base[i].unit_id != (*g_playerBase)->unitid)
{
playername = boost::locale::conv::to_utf<char>(g_team_player_base[i].name, "GBK");
if (playername.empty())