forked from brewsterl/tibianic-dll
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
2034 lines (1618 loc) · 66.1 KB
/
main.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 "main.h"
#include "Sddl.h"
/* It is important for the library to be created on DS segment */
LIB g_dll;
// Global objects
RSA* g_rsa;
GUI* g_gui;
// Last caller of the event function
uint32_t g_lastCaller;
// Stack related variables
uint32_t g_lastEsp;
uint32_t g_lastEbp;
// Registers related variables
uint32_t g_lastTmp;
uint32_t g_lastEax;
uint32_t g_lastEbx;
uint32_t g_lastEcx;
uint32_t g_lastEdx;
uint32_t g_lastEsi;
uint32_t g_lastEdi;
// Event related variables
int g_lastEventId;
int g_lastPacketId;
// Input related variables
POINT g_lastMousePosition;
bool g_lastAlt;
bool g_lastControl;
/* Asembler functions */
extern "C" void _cdecl pushRegisters();
asm("_pushRegisters: \n\
.intel_syntax noprefix \n\
pop _g_lastTmp \n\
push eax \n\
push ebx \n\
push ecx \n\
push edx \n\
push edi \n\
push esi \n\
push ebp \n\
push esp \n\
push _g_lastTmp \n\
ret \n\
.att_syntax; \n\
");
extern "C" void _cdecl popRegisters();
asm("_popRegisters: \n\
.intel_syntax noprefix \n\
pop _g_lastTmp \n\
pop esp \n\
pop ebp \n\
pop esi \n\
pop edi \n\
pop edx \n\
pop ecx \n\
pop ebx \n\
pop eax \n\
push _g_lastTmp \n\
ret \n\
.att_syntax; \n\
");
/* Global functions */
LRESULT CALLBACK HookedMessageDispatcher(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
ScopedCriticalSection section(7);
// Save caller
/*
SAVE_STACK;
SAVE_REGISTERS;
asm(".intel_syntax noprefix \n\
mov esp, dword ptr ss:[ebp] \n\
pop ebp \n\
mov esp, dword ptr ss:[ebp] \n\
pop ebp \n\
mov eax, dword ptr ss:[ebp+4] \n\
mov _g_lastCaller, eax \n\
.att_syntax; \n\
");
LOAD_REGISTERS;
LOAD_STACK;
*/
// Mouse common variables
g_lastMousePosition.x = GET_X_LPARAM(lParam);
g_lastMousePosition.y = GET_Y_LPARAM(lParam);
// Keyboard common variables
g_lastAlt = GetKeyState(VK_MENU) & KEY_DOWN;
g_lastControl = GetKeyState(VK_CONTROL) & KEY_DOWN;
switch(uMsg){
case WM_MOUSEWHEEL: {
if(!ScreenToClient(hWnd, &g_lastMousePosition)){
break;
}
if(!g_gui->onMouseEvent(GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? EVENT_SCROLL_UP : EVENT_SCROLL_DOWN, g_lastMousePosition.x, g_lastMousePosition.y, wParam & MK_LBUTTON, wParam & MK_RBUTTON)){
if(!g_gui->hasDialog()){
return CallWindowProc(g_dll.m_wndProc, hWnd, uMsg, wParam, lParam);
}
}
break;
}
case WM_MOUSEMOVE: {
if(!g_gui->onMouseEvent(EVENT_MOVEMENT, g_lastMousePosition.x, g_lastMousePosition.y, wParam & MK_LBUTTON, wParam & MK_RBUTTON)){
if(!g_gui->hasDialog()){
return CallWindowProc(g_dll.m_wndProc, hWnd, uMsg, wParam, lParam);
}
}
break;
}
case WM_LBUTTONDBLCLK:
case WM_LBUTTONDOWN: {
// check whether the cursor is in the same position as reported mouse position
g_dll.checkCursorPos();
if(!g_gui->onMouseEvent(EVENT_BUTTON, g_lastMousePosition.x, g_lastMousePosition.y, true, wParam & MK_RBUTTON)){
if(!g_gui->hasDialog()){
return CallWindowProc(g_dll.m_wndProc, hWnd, uMsg, wParam, lParam);
}
}
break;
}
case WM_LBUTTONUP: {
// check whether the cursor is in the same position as reported mouse position
g_dll.checkCursorPos();
if(!g_gui->onMouseEvent(EVENT_BUTTON, g_lastMousePosition.x, g_lastMousePosition.y, false, wParam & MK_RBUTTON)){
if(!g_gui->hasDialog()){
return CallWindowProc(g_dll.m_wndProc, hWnd, uMsg, wParam, lParam);
}
}
break;
}
case WM_KEYUP: {
return CallWindowProc(g_dll.m_wndProc, hWnd, uMsg, wParam, lParam);
}
case WM_KEYDOWN: {
switch(wParam){
case VK_F8: {
if(g_lastAlt){ // Enable fps
g_dll.m_optionsDialog->setNfps(!g_dll.m_optionsDialog->getNfps());
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
break;
}
case VK_F9: {
if(g_lastAlt){ // Enable main menu
g_dll.m_optionsDialog->setInfo(!g_dll.m_optionsDialog->getInfo());
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
break;
}
case VK_A: { // A key
if(g_lastControl){ // Select all
if(g_gui->onKeyboardEvent(EVENT_KEY_DOWN, KEYBOARD_STATE_SELECTALL, 0)){
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
break;
}
case VK_X: { // X key
if(g_lastControl){ // Cut
if(g_gui->onKeyboardEvent(EVENT_KEY_DOWN, KEYBOARD_STATE_CUT, 0)){
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
break;
}
case VK_C: { // C key
if(g_lastControl){ // Copy
if(g_gui->onKeyboardEvent(EVENT_KEY_DOWN, KEYBOARD_STATE_COPY, 0)){
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
break;
}
case VK_V: { // V key
if(g_lastControl){ // Paste
if(g_gui->onKeyboardEvent(EVENT_KEY_DOWN, KEYBOARD_STATE_PASTE, 0)){
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
break;
}
case VK_LEFT: { // Arrow key left
if(g_gui->onKeyboardEvent(EVENT_KEY_DOWN, KEYBOARD_STATE_LEFT, 0)){
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
break;
}
case VK_RIGHT: { // Arrow key right
if(g_gui->onKeyboardEvent(EVENT_KEY_DOWN, KEYBOARD_STATE_RIGHT, 0)){
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
break;
}
case VK_UP: { // Arrow key up
if(g_gui->onKeyboardEvent(EVENT_KEY_DOWN, KEYBOARD_STATE_UP, 0)){
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
break;
}
case VK_DOWN: { // Arrow key down
if(g_gui->onKeyboardEvent(EVENT_KEY_DOWN, KEYBOARD_STATE_DOWN, 0)){
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
break;
}
case VK_TAB: { // Tab key
if(g_gui->onKeyboardEvent(EVENT_KEY_DOWN, KEYBOARD_STATE_TAB, 0)){
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
break;
}
case VK_RETURN: { // Enter key
if(g_gui->onKeyboardEvent(EVENT_KEY_DOWN, KEYBOARD_STATE_ENTER, 0)){
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
break;
}
case VK_ESCAPE: { // Escape key
if(g_gui->onKeyboardEvent(EVENT_KEY_DOWN, KEYBOARD_STATE_ESCAPE, 0)){
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
break;
}
case VK_BACK: { // Backspace key
if(g_gui->onKeyboardEvent(EVENT_KEY_DOWN, KEYBOARD_STATE_BACK, 0)){
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
break;
}
case VK_DELETE: { // Delete key
if(g_gui->onKeyboardEvent(EVENT_KEY_DOWN, KEYBOARD_STATE_DELETE, 0)){
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
break;
}
default: break;
}
if(g_gui->hasDialog()){
BYTE keyboardState[256];
GetKeyboardState(keyboardState);
WORD code;
if(ToAscii(wParam, 0, keyboardState, &code, 0) == 1){
if(code >= 32){
if(g_dll.onAsciiCharacter(code)){
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
if(Tibia::IsOnline()){
if(g_dll.m_escToggle){
if(wParam == VK_ESCAPE){
g_dll.m_optionsDialog->setWsad(!g_dll.m_wsad);
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
CAM* cam = g_dll.getCAM();
Player* player = cam->getPlayer();
if(cam->isPlayerEnabled()){
switch(wParam){
case VK_LEFT: {
player->decreaseSpeed();
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
case VK_RIGHT: {
player->increaseSpeed();
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
case VK_DOWN: {
player->setSpeed(1.0);
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
case VK_UP: {
player->setSpeed(256.0);
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
default: break;
}
}
if(g_dll.m_wsad){
if(!(GetKeyState(VK_CONTROL) & KEY_DOWN) && !(GetKeyState(VK_SHIFT) & KEY_DOWN)){
switch(wParam){
case LETTER_W: {
wParam = VK_UP;
break;
}
case LETTER_A: {
wParam = VK_LEFT;
break;
}
case LETTER_S: {
wParam = VK_DOWN;
break;
}
case LETTER_D: {
wParam = VK_RIGHT;
break;
}
case LETTER_Q: {
wParam = VK_HOME;
break;
}
case LETTER_E: {
wParam = VK_PRIOR;
break;
}
case LETTER_Z: {
wParam = VK_END;
break;
}
case LETTER_C: {
wParam = VK_NEXT;
break;
}
default: break;
}
}
}
}
return CallWindowProc(g_dll.m_wndProc, hWnd, uMsg, wParam, lParam);
}
case WM_SIZE: {
if(wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED){
g_dll.m_screenWidth = LOWORD(lParam);
g_dll.m_screenHeight = HIWORD(lParam);
// All GUI windows will be reinitialized and their position will be adjusted to the center
g_gui->onResolution();
}
return CallWindowProc(g_dll.m_wndProc, hWnd, uMsg, wParam, lParam);
}
case WM_DESTROY: {
// Take care of windows (release them all)
g_gui->releaseWindows();
// Take care of the pinger
if(g_dll.pinger){
delete g_dll.pinger;
}
// Take care of dialogs
delete g_dll.m_newsDialog;
delete g_dll.m_updateDialog;
delete g_dll.m_optionsDialog;
delete g_dll.m_questsDialog;
delete g_dll.m_questDialog;
delete g_dll.m_outfitDialog;
}
default: {
return CallWindowProc(g_dll.m_wndProc, hWnd, uMsg, wParam, lParam);
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
HWND WINAPI HookedCreateWindowEx(DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam){
HWND m_hWnd = CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
// If there is an error saved we need to show it now
if(!g_dll.m_error.empty()){
Tibia::FatalError(g_dll.m_error.c_str());
}
// Main window should be hooked
if(g_dll.m_screenWidth == 0 || g_dll.m_screenHeight == 0){
g_dll.m_screenWidth = nWidth;
g_dll.m_screenHeight = nHeight;
g_dll.m_hWnd = m_hWnd;
g_dll.m_wndProc = (WNDPROC)GetWindowLongPtr(m_hWnd, GWL_WNDPROC);
SetWindowLongPtr(m_hWnd, GWL_WNDPROC, (LONG_PTR)HookedMessageDispatcher);
}
return m_hWnd;
}
int APIENTRY HookedConnect(SOCKET s, const struct sockaddr* name, int namelen){
// Dispatch the event
g_dll.onConnectEvent(name);
// Return the real function
return connect(s, name, namelen);
}
int APIENTRY HookedSend(SOCKET s, char* buff, int len, int flags){
CAM* cam = g_dll.getCAM();
if(!Tibia::IsOnline()){
switch(buff[NetworkMessage::header_length]){
case 0x0A: { // Enter game packet
*(uint16_t*)(buff + NetworkMessage::header_length + 3) = PROTOCOL_VERSION;
g_dll.m_online = true;
g_dll.m_buffer = NULL;
break;
}
case 0x01: { // Login packet
*(uint16_t*)(buff + NetworkMessage::header_length + 3) = PROTOCOL_VERSION;
g_dll.m_online = false;
g_dll.m_buffer = NULL;
break;
}
default: break;
}
}
if(!cam->isPlayerEnabled()){
if(Tibia::IsOnline()){
if(g_dll.m_buffer == NULL){
g_dll.m_buffer = buff;
g_dll.m_validBuffer = true;
}
// The buffer does not match so it's a cheat
if(!(buff == g_dll.m_buffer)){
g_dll.m_validBuffer = false;
}
}
if(g_dll.m_socket != s){
g_dll.m_socket = s;
}
}
if(Tibia::IsOnline()){
// Lets encrypt the packet with the TSA
/* uint32_t pos = 0;
while(pos < len){
uint16_t plen = *(uint16_t*)(buff + pos);
uint32_t* buffer = (uint32_t*)(buff + 2 + pos);
for(int i = 0; i < plen / 4; i++){
buffer[i] ^= *(uint32_t*)PLAYER_ACCOUNT_NUMBER ^ 88;
}
pos = pos + plen + 2;
} */
}
return send(s, buff, len, flags);
}
int APIENTRY HookedRecv(SOCKET s, char* buff, int len, int flags){
int ret = recv(s, buff, len, flags);
CAM* cam = g_dll.getCAM();
if(!cam->isPlayerEnabled()){
if(Tibia::IsOnline()){
if(ret == 0){ // Connection in game has been closed - dispatch an event
g_dll.onLogoutEvent();
}
}
if(ret > 0){
if(g_dll.m_online){
if(cam->isRecorderEnabled()){
/* Connection related variables */
static char connectionBuffer[NETWORKMESSAGE_MAXSIZE << 2];
static int bufferLength = 0;
static int bufferPosition = 0;
static uint16_t& packetLength = *(uint16_t*)connectionBuffer;
/* Lets copy Tibia buffer to ours */
memcpy(&connectionBuffer[bufferLength], buff, ret);
bufferLength = bufferLength + ret;
/* Lets make sure we have at least one packet */
if(bufferLength >= NetworkMessage::header_length && bufferLength >= (packetLength + NetworkMessage::header_length)){
for(int bufferLocation = bufferPosition; bufferLocation < bufferLength;){
uint16_t& packetLength = *(uint16_t*)&connectionBuffer[bufferLocation];
/* There might be some packet which wasn't yet fully acquired */
if((packetLength + NetworkMessage::header_length) > (bufferLength - bufferLocation)){
bufferPosition = bufferLocation;
return ret;
}
NetworkMessage message((uint8_t*)&connectionBuffer[bufferLocation]);
if(!XTEA_decrypt(message, (uint32_t*)XTEA_KEY_ADDRESS)){
Tibia::FatalError("CAM Recorder: Failed to decrypt XTEA!");
}
/* Create new NetworkMessage class for the recorder */
NetworkMessage* msg = new NetworkMessage((uint8_t*)(message.getBuffer() + NetworkMessage::header_length));
Recorder* recorder = cam->getRecorder();
recorder->addPacket(msg);
bufferLocation = bufferLocation + packetLength + NetworkMessage::header_length;
}
bufferLength = 0;
bufferPosition = 0;
}
}
}
}
}
return ret;
}
void Render(int nSurface){
// Local variables for any use
static char messageBuffer[1024];
/*
// Sample skins
int start = 0;
for(int i = start; i <= start + 50; i++){
Painter::drawSkin(nSurface, 50 + (i - start) * 32, 150, 32, 32, i, 0, 0);
sprintf(messageBuffer, "%d", i);
Painter::drawText(nSurface, 50 + (i - start) * 32, 150, FONT_NORMAL_OUTLINED, 255, 255, 255, messageBuffer, 0);
}
// girder = 10, 41, 147 can be used
*/
//sprintf(messageBuffer, "caller = 0x%04x", g_lastCaller);
//Painter::drawText(nSurface, 40, 20, FONT_NORMAL_OUTLINED, 255, 255, 255, messageBuffer, 0);
if(g_dll.m_gameMenu){
static int height = 70;
static int x = 60;
static int y = 12 + 30;
Painter::drawSkin(nSurface, x + 3, y, 108, height, 60, 0, 0); //background for buttons
Painter::drawSkin(nSurface, x, y, 4, height, 56, 0, 0); // left line
Painter::drawSkin(nSurface, x + 112 - 1, y, 6, height + 1, 57, 0, 0); // right line
Painter::drawSkin(nSurface, x + 5, y - 5, 108, 5, 58, 0, 0); // top line
Painter::drawSkin(nSurface, x + 3, y + height, 108, 6, 59, 0, 0); // botom line
Painter::drawSkin(nSurface, x, y + height, 5, 6, 54, 0, 0); // bottom/left corner
Painter::drawSkin(nSurface, x + 2 + 112 - 3, y + height, 6, 6, 55, 0, 0); // bottom/right corner
Painter::drawSkin(nSurface, x, y - 5, 5, 5, 52, 0, 0); // upper/left corner
Painter::drawSkin(nSurface, x + 112 - 1, y - 5, 6, 5, 53, 0, 0); // upper/right corner
Painter::drawText(nSurface, x + 116 / 2, y , 2, 255, 255, 255, (char *)"CAM options:", 1);
Buttons* buttons = g_dll.getButtons();
buttons->draw(nSurface);
}
if(Tibia::IsOnline()){
CAM* cam = g_dll.getCAM();
Player* player = cam->getPlayer();
Pinger* pinger = g_dll.getPinger();
if(pinger && pinger->running()){
int ping = pinger->getPing();
std::string m_host = GLOBAL_HOST;
// Perhaps the host is not global one?
if(iequals(g_dll.m_pingHost, CAM_PLAYER_HOST)){
m_host = std::string("Local Host");
}
std::string m_status;
uint8_t red, green, blue;
getPingInfo(ping, m_status, red, green, blue);
sprintf(messageBuffer, "Ping to %s: ", m_host.c_str());
Painter::drawText(nSurface, 4, 18, FONT_NORMAL_OUTLINED, 199, 199, 199, messageBuffer, 0);
int textWidth = Tibia::TextMetric(FONT_NORMAL_OUTLINED, messageBuffer, strlen(messageBuffer));
sprintf(messageBuffer, "%d ms - %s", ping, m_status.c_str());
Painter::drawText(nSurface, 4 + textWidth, 18, FONT_NORMAL_OUTLINED, red, green, blue, messageBuffer, 0);
}
if(cam->isPlayerEnabled()){ // CAM player is enabled
if(iequals(g_dll.m_pingHost, CAM_PLAYER_HOST)){ // Lets make sure we are connected to local host since CAM player can be enabled in game
Tibia::GUI* gui = Tibia::GetGUIPointer();
Tibia::GUIHolder* bar = gui->m_resize;
sprintf(messageBuffer, "CAM Player speed: %.04lf", player->getSpeed());
Painter::drawText(nSurface, bar->m_offsetx + 4, bar->m_offsety - 16, FONT_NORMAL_OUTLINED, 80, 255, 0, messageBuffer, 0);
sprintf(messageBuffer, "Time: %s of %s", MilisecondsToStr(player->getNextPacket()).c_str(), MilisecondsToStr(player->getTimeTotal()).c_str());
Painter::drawText(nSurface, bar->m_offsetx + 4, bar->m_offsety - 30, FONT_NORMAL_OUTLINED, 95, 247, 247, messageBuffer, 0);
sprintf(messageBuffer, "Playing file: %s", player->getFileName().c_str());
Painter::drawText(nSurface, bar->m_offsetx + bar->m_width - 4, bar->m_offsety - 16, FONT_NORMAL_OUTLINED, 80, 255, 0, messageBuffer, 2);
}
} else if(cam->isRecorderEnabled()){
Tibia::GUI* gui = Tibia::GetGUIPointer();
Tibia::GUIHolder* bar = gui->m_resize;
uint64_t time = Timer::tickCount() % 900;
if(time <= 300){
sprintf(messageBuffer, "[*] Recording.");
} else if(time <= 600){
sprintf(messageBuffer, "[*] Recording..");
} else {
sprintf(messageBuffer, "[*] Recording...");
}
Painter::drawText(nSurface, bar->m_offsetx + 4, bar->m_offsety - 16, FONT_NORMAL_OUTLINED, 255, 45, 40, messageBuffer, 0);
}
}
g_gui->draw(nSurface);
}
void HookedTimer(){
// Dispatch idle message to Tibia
Tibia::Idle();
// First fame initialization
if(!g_dll.m_firstFrame){
g_dll.FirstTick();
}
// Tick whole GUI (each tick per 100-120 ms)
g_gui->tick(Tibia::GetPlayerInfo(PLAYER_INFO_TICKS));
// Tick auto trade, the dialog is in the background
if(g_gui->getDialog() != g_dll.m_tradeDialog){
g_dll.m_tradeDialog->tick(Tibia::GetPlayerInfo(PLAYER_INFO_TICKS));
}
}
/* This function is a this call, ecx contains GUIItem */
int _stdcall HookedGetIconSkin(int iconNumber){
SAVE_STACK;
SAVE_REGISTERS;
Creature_t* player = Tibia::GetCreatureEntry(Tibia::GetPlayerInfo(PLAYER_INFO_ID));
bool iconFound = false;
if(player->skull != SKULL_NONE){
if(iconNumber == 0){
switch(player->skull){
case SKULL_YELLOW: {
g_lastTmp = 0x0EC;
break;
}
case SKULL_GREEN: {
g_lastTmp = 0x0ED;
break;
}
case SKULL_WHITE: {
g_lastTmp = 0x0EE;
break;
}
case SKULL_RED: {
g_lastTmp = 0x0EF;
break;
}
}
iconFound = true;
} else {
iconNumber = iconNumber - 1;
}
}
for(uint32_t icon = 1; !iconFound && icon <= (1 << 30); icon <<= 1){
if((Tibia::GetPlayerInfo(PLAYER_INFO_ICONS) & icon) == icon){
switch(icon){
case FLAG_POISON: {
g_lastTmp = 0x0E4;
break;
}
case FLAG_FIRE: {
g_lastTmp = 0x0E5;
break;
}
case FLAG_ENERGY: {
g_lastTmp = 0x0E6;
break;
}
case FLAG_DRUNK: {
g_lastTmp = 0x0E7;
break;
}
case FLAG_MANA_SHIELD: {
g_lastTmp = 0x0E8;
break;
}
case FLAG_PARALYZE: {
g_lastTmp = 0x0E9;
break;
}
case FLAG_HASTE: {
g_lastTmp = 0x0EA;
break;
}
case FLAG_SWORDS: {
g_lastTmp = 0x0EB;
break;
}
default: break;
}
if(iconNumber == 0){
iconFound = true;
break;
}
iconNumber = iconNumber - 1;
}
}
LOAD_REGISTERS;
LOAD_STACK;
return g_lastTmp;
}
void HookedDrawCreatureName(int nSurface, int nX, int nY, int nFont, int nRed, int nGreen, int nBlue, char* lpText, int nAlign){
SAVE_STACK;
SAVE_REGISTERS;
// Buffer for various usage
static char messageBuffer[1024];
Creature_t* creature = (Creature_t*)(lpText - 4);
if(g_dll.m_manaBar && creature->id == Tibia::GetPlayerInfo(PLAYER_INFO_ID)){
// Print creature name with vertical displacement
Painter::drawText(nSurface, nX, nY - 5, nFont, nRed, nGreen, nBlue, lpText, nAlign);
// Calculate percentage of health and mana
uint32_t healthPercent;
uint32_t manaPercent;
if(healthPercent = Tibia::GetPlayerInfo(PLAYER_INFO_MAX_HEALTH)){
healthPercent = std::min((uint32_t)100, 1 + 100 * Tibia::GetPlayerInfo(PLAYER_INFO_HEALTH) / healthPercent);
} else {
healthPercent = 100;
}
if(manaPercent = Tibia::GetPlayerInfo(PLAYER_INFO_MAX_MANA)){
manaPercent = std::min((uint32_t)100, 1 + 100 * Tibia::GetPlayerInfo(PLAYER_INFO_MANA) / manaPercent);
} else {
manaPercent = 100;
}
Color_t healthColor = getHealthPercentColor(healthPercent);
Color_t manaColor(0, 87, 238);
// Choose mana color
if(manaPercent >= 80){
manaColor.green = 102;
manaColor.blue = 253;
} else if(manaPercent >= 60){
manaColor.green = 97;
manaColor.blue = 248;
} else if(manaPercent >= 40){
manaColor.green = 92;
manaColor.blue = 243;
}
// Calculate the displacement
int xOffset = getTotalMetric(nFont, lpText);
// Adjust colors according to lighting
if(healthColor.green != nGreen || healthColor.blue != nBlue){
manaColor.green = std::max(0, manaColor.green - (healthColor.green - nGreen));
manaColor.blue = std::max(0, manaColor.blue - (healthColor.blue - nBlue));
}
// Draw new health bar
Painter::drawRectangle(nSurface, nX + (xOffset >> 1) - 14, nY + 7, 27, 4, 0, 0, 0);
Painter::drawRectangle(nSurface, nX + (xOffset >> 1) - 14 + 1, nY + 7 + 1, 25 * healthPercent / 100, 2, nRed, nGreen, nBlue);
// Mana bar over old health bar
Painter::drawRectangle(nSurface, nX + (xOffset >> 1) - 14, nY + 12, 27, 4, 0, 0, 0);
Painter::drawRectangle(nSurface, nX + (xOffset >> 1) - 14 + 1, nY + 12 + 1, 25 * manaPercent / 100, 2, manaColor.red, manaColor.green, manaColor.blue);
} else {
Painter::drawText(nSurface, nX, nY, nFont, nRed, nGreen, nBlue, lpText, nAlign);
}
LOAD_REGISTERS;
LOAD_STACK;
}
void HookedParsePacketSwitch(){
SAVE_STACK;
SAVE_REGISTERS;
switch(g_lastEcx){
/* Quest log */
case 0xF0: {
int amount = Tibia::NetworkGetU16();
std::vector<std::string> questsNames;
std::vector<int> questsIds;
while(amount --> 0){
uint16_t questId = Tibia::NetworkGetU16();
std::string questName = Tibia::NetworkGetString();
uint8_t questCompleted = Tibia::NetworkGetU8();
if(questCompleted){
questName.append(" (Completed)");
}
questsNames.push_back(questName);
questsIds.push_back(questId);
}
g_dll.m_questsDialog->setQuests(questsNames, questsIds);
g_gui->setDialog(g_dll.m_questsDialog);
break;
}
/* Quest information */
case 0xF1: {
int questId = Tibia::NetworkGetU16();
int amount = Tibia::NetworkGetU8();
std::vector<std::string> missions;
std::vector<std::string> descriptions;
while(amount --> 0){
std::string missionName = Tibia::NetworkGetString();
std::string missionDescription = Tibia::NetworkGetString();
missions.push_back(missionName);
descriptions.push_back(missionDescription);
}
g_dll.m_questDialog->setMissions(missions, descriptions);;
g_gui->setDialog(g_dll.m_questDialog);
break;
}
/* Shared experience indicator */
case 0xA8: {
g_dll.m_sharedExperience = Tibia::NetworkGetU8();
break;
}
/* New outfit dialog */
case 0xC9: {
Outfit_t defaultOutfit;
defaultOutfit.type = Tibia::NetworkGetU16();
if(defaultOutfit.type != 0){
defaultOutfit.masks.head = Tibia::NetworkGetU8();
defaultOutfit.masks.body = Tibia::NetworkGetU8();
defaultOutfit.masks.legs = Tibia::NetworkGetU8();
defaultOutfit.masks.feet = Tibia::NetworkGetU8();
} else {
uint16_t itemId = Tibia::NetworkGetU16();
/* Split into two 8 bits variables */
defaultOutfit.masks.head = itemId >> 8;
defaultOutfit.masks.body = itemId >> 0;
}
uint16_t outfits = Tibia::NetworkGetU8();
std::vector< std::pair<uint32_t, std::string> > list;
for(int i = 0; i < outfits; i++){
uint16_t lookType = Tibia::NetworkGetU16();
std::string name = Tibia::NetworkGetString();
list.push_back(std::pair<uint32_t, std::string>(lookType, name));
}
g_dll.m_outfitDialog->setOutfits(list);
g_dll.m_outfitDialog->setOutfit(defaultOutfit);
g_gui->setDialog(g_dll.m_outfitDialog);
break;
}
default: {
char error[64];
sprintf(error, "Unknown packet received (%02X)", g_lastEcx);
Tibia::FatalError((const char*)error);
}
}
LOAD_REGISTERS;
LOAD_STACK;
}
void _stdcall HookedAddSetOutfitContextMenu(int id, char* text, char* hint){
SAVE_STACK;
SAVE_REGISTERS;
/* Replace set outfit event with our own */
Tibia::AddContextMenu(0x1001, text, hint);
/* Shared experience */
const char* _enableShared = "Enable Shared Experience";
const char* _disableShared = "Disable Shared Experience";
Creature_t* player = Tibia::GetCreatureEntry(Tibia::GetPlayerInfo(PLAYER_INFO_ID));
if(player->party == PARTY_LEADER){
LOAD_ESI;
MOV(ECX, ESI);
if(g_dll.m_sharedExperience){
Tibia::AddContextMenu(0x1000, _disableShared, NULL);
} else {
Tibia::AddContextMenu(0x1000, _enableShared, NULL);
}
}