This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
/
vaultmp.cpp
1330 lines (1080 loc) · 39.3 KB
/
vaultmp.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
/*
* Very hacky weekend code from 2010. Basically unmaintainable and bullshit. It works though :(
* Note: completely scrap and re-engineer
* More note: be careful. here be pointers to pointers to pointers and dragons
*/
#include <winsock2.h>
#include <cstdio>
#include <vector>
#include <string>
#include <mutex>
#include <queue>
#include <cmath>
#include "vaultmp.hpp"
using namespace std;
struct remotePlayers
{
char name[64];
bool player;
double health;
double pos[3];
double rot[3];
long int pid;
};
static remotePlayers players[10];
typedef void (*CallCommand)(void*, void*, void*, void*, void*, void*, void*, void*);
mutex mInput;
queue<string> qGUI_OnChat;
queue<bool> qGUI_OnMode;
queue<string> qGUI_OnClick;
queue<pair<string, string>> qGUI_OnText;
queue<pair<string, bool>> qGUI_OnCheckbox;
queue<vector<string>> qGUI_OnSelect;
queue<string> qGUI_OnReturn;
queue<unsigned int> qActivate;
unsigned int qFire;
static HANDLE hProc;
static PipeServer pipeServer;
static PipeClient pipeClient;
static unsigned int (*FormLookup)(unsigned int);
static unsigned int (*FuncLookup)(unsigned int);
static void (*Chatbox_AddToChat)(const char*);
static void (*GUI_CreateFrameWindow)(const char*);
static void (*GUI_AddStaticText)(const char*, const char*);
static void (*GUI_AddTextbox)(const char*, const char*);
static void (*GUI_AddButton)(const char*, const char*);
static void (*GUI_SetVisible)(const char*, bool);
static void (*GUI_AllowDrag)(const char*, bool);
static void (*GUI_SetPosition)(const char*, float, float, float, float);
static void (*GUI_SetSize)(const char*, float, float, float, float);
static void (*GUI_SetText)(const char*, const char*);
static void (*GUI_RemoveWindow)(const char*);
static void (*GUI_ForceGUI)(bool);
static void (*GUI_SetClickCallback)(void (*)(const char*));
static void (*GUI_SetTextChangedCallback)(void (*)(const char*, const char*));
static void (*GUI_Textbox_SetMaxLength)(const char*, unsigned int);
static void (*GUI_Textbox_SetValidationString)(const char*, const char*);
static void (*GUI_AddCheckbox)(const char*, const char*);
static void (*GUI_AddRadioButton)(const char*, const char*, unsigned long int);
static void (*GUI_SetChecked)(const char*, bool);
static void (*GUI_Radio_SetGroupID)(const char*, int);
static void (*GUI_SetCheckboxChangedCallback)(void (*)(const char*, bool));
static void (*GUI_AddListbox)(const char*, const char*);
static void (*GUI_Listbox_AddItem)(const char*, const char*, const char*);
static void (*GUI_Listbox_RemoveItem)(const char*, const char*);
static void (*GUI_Listbox_SetItemText)(const char*, const char*, const char*);
static void (*GUI_Listbox_SetItemSelected)(const char*, const char*, bool);
static void (*GUI_Listbox_EnableMultiSelect)(const char*, bool);
static void (*GUI_SetListboxSelectionChangedCallback)(void (*)(const char*, const char**));
static void (*GUI_SetReturnKeyDownCallback)(void (*)(const char*));
static void (*SetPlayersDataPointer)(remotePlayers*);
static bool (*QueueUIMessage)(const char* msg, unsigned int emotion, const char* ddsPath, const char* soundName, float msgTime);
static void (*SetPos)(unsigned int unk, unsigned short opcode, void* reference, unsigned char axis, double pos);
static void PatchGame(HINSTANCE& silverlock);
static void BethesdaDelegator();
static void ToggleRespawn();
static void RespawnDetour();
static void AnimDetour();
static void PlayIdleDetour();
static void AVFix();
static void GetActivate();
static void PlaceAtMe();
static void FireWeapon();
static vector<void*> delegated;
static HINSTANCE silverlock = NULL;
static HINSTANCE vaultgui = NULL;
static bool delegate = false;
static bool respawn = true;
static bool DLLerror = false;
static unsigned int anim = 0x00;
static unsigned int* _anim = NULL;
static float PlaceAtMe_data[6];
static const unsigned pluginsVMP = 0x00E10FF1;
static const unsigned PlayGroup = 0x0045F704;
static const unsigned delegator_src = 0x006EEC86;
static const unsigned delegator_dest = 0x006EDBD9;
static const unsigned delegatorCall_src = 0x006EDBDA;
static const unsigned delegatorCall_dest = (unsigned)& BethesdaDelegator;
static const unsigned noRespawn_NOP = 0x006D5965; // 2x NOP
static const unsigned noRespawn_jmp_src = 0x0078B230;
static const unsigned noRespawn_jmp_dest = 0x0078B2B9;
static const unsigned noRespawn_jmp_detour = (unsigned)& RespawnDetour;
static const unsigned playIdle_call_src = 0x0073BB20;
static const unsigned playIdle_call_dest = (unsigned)& AnimDetour;
static const unsigned playIdle_fix_src = 0x00534D8D;
static const unsigned playIdle_fix_dest = (unsigned)& PlayIdleDetour;
static const unsigned matchRace_NOP1 = 0x0052F4DD;
static const unsigned matchRace_NOP2 = 0x0052F50F;
static const unsigned matchRace_patch = 0x0052F513;
static const unsigned matchRace_param = 0x00F51ADC;
static const unsigned LockFix = 0x00527F33;
static const unsigned aiFix1 = 0x0072051E;
static const unsigned aiFix2 = 0x006FAEE8;
static const unsigned aiFix3 = 0x006FAF19;
static const unsigned aiFix4 = 0x0042FBDC;
static const unsigned playGroup_fix = 0x0049DD6A;
static const unsigned playGroup_fix_src = 0x0049DD8E;
static const unsigned playGroup_fix_dest = 0x0049DCF1;
static unsigned AVFix_src = 0x00473D35;
static unsigned AVFix_dest = (unsigned)& AVFix;
static unsigned AVFix_ret = 0x00473D3B;
static unsigned AVFix_term = 0x00473E85;
static unsigned FireFix_jmp = 0x0079236C;
static unsigned FireFix_patch = 0x007923C5;
static unsigned GetActivate_jmp = 0x0078A68D;
static unsigned GetActivate_dest = (unsigned)& GetActivate;
static unsigned GetActivate_ret = 0x0078A995;
static unsigned PlaceAtMe_jmp = 0x00539785;
static unsigned PlaceAtMe_dest = (unsigned)& PlaceAtMe;
static unsigned PlaceAtMe_call = 0x0043DEF0;
static unsigned PlaceAtMe_ret = PlaceAtMe_jmp + 5;
static unsigned PlaceAtMe_fix = 0x006F1CB6;
static unsigned PlaceAtMe_fix_dest = 0x006F1F6E;
static unsigned FireWeapon_jmp = 0x0071F05F;
static unsigned FireWeapon_dest = (unsigned)& FireWeapon;
static unsigned FireWeapon_call = 0x004BE1A0;
static unsigned FireWeapon_ret = FireWeapon_jmp + 5;
// Those snippets / functions are from FOSE / NVSE, thanks
void SafeWrite8(unsigned int addr, unsigned int data)
{
unsigned int oldProtect;
VirtualProtect((void*) addr, 4, PAGE_EXECUTE_READWRITE, (DWORD*) &oldProtect);
*((unsigned char*) addr) = data;
VirtualProtect((void*) addr, 4, oldProtect, (DWORD*) &oldProtect);
}
void SafeWrite16(unsigned int addr, unsigned int data)
{
unsigned int oldProtect;
VirtualProtect((void*) addr, 4, PAGE_EXECUTE_READWRITE, (DWORD*) &oldProtect);
*((unsigned short*)addr) = data;
VirtualProtect((void*) addr, 4, oldProtect, (DWORD*) &oldProtect);
}
void SafeWrite32(unsigned int addr, unsigned int data)
{
unsigned int oldProtect;
VirtualProtect((void*) addr, 4, PAGE_EXECUTE_READWRITE, (DWORD*) &oldProtect);
*((unsigned int*) addr) = data;
VirtualProtect((void*) addr, 4, oldProtect, (DWORD*) &oldProtect);
}
void SafeWriteBuf(unsigned int addr, void* data, unsigned int len)
{
unsigned int oldProtect;
VirtualProtect((void*) addr, len, PAGE_EXECUTE_READWRITE, (DWORD*) &oldProtect);
memcpy((void*) addr, data, len);
VirtualProtect((void*) addr, len, oldProtect, (DWORD*) &oldProtect);
}
void WriteRelJump(unsigned int jumpSrc, unsigned int jumpTgt)
{
SafeWrite8(jumpSrc, 0xE9);
SafeWrite32(jumpSrc + 1, jumpTgt - jumpSrc - 1 - 4);
}
void WriteRelCall(unsigned int jumpSrc, unsigned int jumpTgt)
{
SafeWrite8(jumpSrc, 0xE8);
SafeWrite32(jumpSrc + 1, jumpTgt - jumpSrc - 1 - 4);
}
void BethesdaDelegator()
{
if (delegate)
{
CallCommand Call = (CallCommand) delegated[8];
Call(delegated[0], delegated[1], delegated[2], delegated[3], delegated[4], delegated[5], delegated[6], delegated[7]);
delegate = false;
}
}
void RespawnDetour()
{
ToggleRespawn();
}
void AnimDetour()
{
asm volatile(
"PUSH EAX\n"
"LEA EAX,[ECX+0x414]\n"
"CMP EAX,%2\n"
"JNE _nopatch\n"
"MOV EAX,%1\n"
"MOV %0,0\n"
"JMP _patch\n"
"_nopatch:\n"
"XOR EAX,EAX\n"
"_patch:\n"
"MOV [ECX+0x414],EAX\n"
"POP EAX\n"
: "=m"(anim)
: "m"(anim), "m"(_anim)
:
);
}
void PlayIdleDetour()
{
asm volatile(
"CMP DWORD PTR [EBP+0xC],0x14\n"
"JNE _push1\n"
"MOV %0,0x80\n"
"MOV %1,ECX\n"
"ADD %1,0x414\n"
"_push1:\n"
"PUSH 0x80\n"
"CALL EAX\n"
: "=m"(anim), "=m"(_anim)
:
:
);
}
void AVFix()
{
asm volatile(
"TEST ECX,ECX\n"
"JNE _doit\n"
"JMP %1\n"
"_doit:\n"
"MOV EDX,[ECX]\n"
"MOV [ESP+0x34],EAX\n"
"JMP %0\n"
:
: "m"(AVFix_ret), "m"(AVFix_term)
:
);
}
void GetActivate()
{
void* object;
asm volatile(
"PUSHAD\n"
"MOV %0,EAX\n"
: "=m"(object)
:
: "eax"
);
if (object)
{
unsigned int refID = *(unsigned int*)(((unsigned) object) + 0x0C);
mInput.lock();
qActivate.push(refID);
mInput.unlock();
}
asm volatile(
"POPAD\n"
:
:
:
);
}
void PlaceAtMe()
{
asm volatile(
"CALL %0\n"
"PUSH ECX\n"
"MOV ECX,%1\n"
"MOV [EAX+0x20],ECX\n"
"MOV ECX,%2\n"
"MOV [EAX+0x24],ECX\n"
"MOV ECX,%3\n"
"MOV [EAX+0x28],ECX\n"
"MOV ECX,%4\n"
"MOV [EAX+0x2C],ECX\n"
"MOV ECX,%5\n"
"MOV [EAX+0x30],ECX\n"
"MOV ECX,%6\n"
"MOV [EAX+0x34],ECX\n"
"POP ECX\n"
"JMP %7\n"
:
: "m"(PlaceAtMe_call), "m"(PlaceAtMe_data[0]), "m"(PlaceAtMe_data[1]), "m"(PlaceAtMe_data[2]), "m"(PlaceAtMe_data[3]), "m"(PlaceAtMe_data[4]), "m"(PlaceAtMe_data[5]), "m"(PlaceAtMe_ret)
:
);
}
void FireWeapon()
{
asm volatile(
"LOCK INC %0\n"
"CALL %1\n"
"JMP %2\n"
:
: "m"(qFire), "m"(FireWeapon_call), "m"(FireWeapon_ret)
:
);
}
bool vaultfunction(void* reference, void* result, void* args, unsigned short opcode)
{
switch (opcode)
{
case 0x0001 | VAULTFUNCTION: // GetActorState - returns the actors animations, alerted / sneaking state
{
ZeroMemory(result, sizeof(double));
unsigned char* data;
// thiscall convention
asm(
"MOV ECX,%1\n"
"CALL %2\n"
"MOV %0,EAX\n"
: "=m"(data)
: "m"(reference), "r"(*((unsigned int*)((unsigned) *((unsigned int*) reference) + (unsigned) 0x01E4)))
: "eax", "ecx"
);
if (data != NULL)
{
unsigned char sneaking, moving, weapon;
unsigned int idle = 0x00000000;
unsigned char* anim = data;
moving = *(anim + 0x4E);
weapon = *(anim + 0x54);
asm(
"MOV ECX,%1\n"
"CALL %2\n"
"MOV %0,EAX\n"
: "=m"(data)
: "m"(reference), "r"(SNEAKING_STATE)
: "eax", "ecx", "edx"
);
sneaking = (bool)((unsigned) data & 0x00000400);
unsigned int data = *(unsigned int*) (anim + 0x118);
if (data)
{
data = *(unsigned int*)(data + 0x2C);
idle = *(unsigned int*)(data + 0x0C);
}
// This detection is unreliable; i.e. what when the player holds Forward/Backward/Left/Right all together for some reason?
unsigned char* _args = (unsigned char*) args;
unsigned char flags = 0x00;
if (*_args == 0x6E) // Forward, Backward, Left, Right unsigned char scan codes stored in Integer, optional
{
++_args;
unsigned char forward = *_args;
unsigned char backward = *(_args + 1);
unsigned char left = *(_args + 2);
unsigned char right = *(_args + 3);
if (!(forward && backward && left && right))
break;
// MAPVK_VSC_TO_VK
if (((GetAsyncKeyState(MapVirtualKey(forward, 1)) & 0x8000) && (GetAsyncKeyState(MapVirtualKey(left, 1)) & 0x8000))
|| ((GetAsyncKeyState(MapVirtualKey(backward, 1)) & 0x8000) && (GetAsyncKeyState(MapVirtualKey(right, 1)) & 0x8000)))
{
flags |= 0x01; // that equals to a Z-angle correction of -45²
}
else if (((GetAsyncKeyState(MapVirtualKey(forward, 1)) & 0x8000) && (GetAsyncKeyState(MapVirtualKey(right, 1)) & 0x8000))
|| ((GetAsyncKeyState(MapVirtualKey(backward, 1)) & 0x8000) && (GetAsyncKeyState(MapVirtualKey(left, 1)) & 0x8000)))
{
flags |= 0x02; // that equals to a Z-angle correction of 45²
}
}
memcpy(result, &idle, 4);
memcpy((void*)((unsigned) result + 4), &moving, 1);
memcpy((void*)((unsigned) result + 5), &flags, 1);
memcpy((void*)((unsigned) result + 6), &weapon, 1);
memcpy((void*)((unsigned) result + 7), &sneaking, 1);
}
break;
}
case 0x0003 | VAULTFUNCTION: // GetPosAngle - Get pos and angle
{
ZeroMemory(result, sizeof(double));
if (!reference)
return false;
float* data = (float*) result;
data[0] = (*(float*)((unsigned char*) reference + 0x20)) * 180 / M_PI;
data[1] = (*(float*)((unsigned char*) reference + 0x24)) * 180 / M_PI;
data[2] = (*(float*)((unsigned char*) reference + 0x28)) * 180 / M_PI;
data[3] = *(float*)((unsigned char*) reference + 0x2C);
data[4] = *(float*)((unsigned char*) reference + 0x30);
data[5] = *(float*)((unsigned char*) reference + 0x34);
return true;
}
case 0x0004 | VAULTFUNCTION: // UIMessage - Queue UI message
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
unsigned int emoticon = *(unsigned int*)(data + strlen(data) + 2);
QueueUIMessage(data, emoticon, NULL, NULL, 2.0); // add more later
break;
}
case 0x0005 | VAULTFUNCTION: // PlaceAtMePrepare - prepares pos / angle data
{
ZeroMemory(result, sizeof(double));
unsigned char* _args = (unsigned char*) args;
PlaceAtMe_data[0] = (*(double*)(_args + 1)) * M_PI / 180;
PlaceAtMe_data[1] = (*(double*)(_args + 10)) * M_PI / 180;
PlaceAtMe_data[2] = (*(double*)(_args + 19)) * M_PI / 180;
PlaceAtMe_data[3] = *(double*)(_args + 28);
PlaceAtMe_data[4] = *(double*)(_args + 37);
PlaceAtMe_data[5] = *(double*)(_args + 46);
break;
}
case 0x0006 | VAULTFUNCTION: // ForceRespawn - returns to the main screen
{
ToggleRespawn();
while (respawn)
Sleep(1);
break;
}
case 0x0007 | VAULTFUNCTION: // SetGlobalValue - sets a global value
{
if (!reference)
return false;
unsigned char* global_value = (unsigned char*) reference + 0x24;
unsigned char* _args = (unsigned char*) args;
if (*_args == 0x6E) // just using int (stored as 4-byte float) so far
*(float*) global_value = (float) *(signed int*) (_args + 1);
break;
}
case 0x0008 | VAULTFUNCTION: // GUIChat - Print chat message
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
Chatbox_AddToChat(data);
break;
}
case 0x0009 | VAULTFUNCTION: // GUIMode - Force in / out of GUI mode
{
ZeroMemory(result, sizeof(double));
unsigned char* _args = (unsigned char*) args;
if (*_args == 0x6E)
GUI_ForceGUI(*(unsigned int*) (_args + 1));
break;
}
case 0x0010 | VAULTFUNCTION: // GUICreateWindow - Create new frame window
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
GUI_CreateFrameWindow(data);
break;
}
case 0x0011 | VAULTFUNCTION: // GUICreateButton - Create new button
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
GUI_AddButton(data, data + strlen(data) + 3);
break;
}
case 0x0012 | VAULTFUNCTION: // GUICreateText - Create new text
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
GUI_AddStaticText(data, data + strlen(data) + 3);
break;
}
case 0x0013 | VAULTFUNCTION: // GUICreateEdit - Create new edit box
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
GUI_AddTextbox(data, data + strlen(data) + 3);
break;
}
case 0x0014 | VAULTFUNCTION: // GUIRemoveWindow - Remove window
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
GUI_RemoveWindow(data);
break;
}
case 0x0015 | VAULTFUNCTION: // GUIPos - Update window
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
unsigned char* _args = (unsigned char*) (data + strlen(data) + 1);
float pos_X = *(double*)(_args + 1);
float pos_Y = *(double*)(_args + 10);
float offset_X = *(double*)(_args + 19);
float offset_Y = *(double*)(_args + 28);
GUI_SetPosition(data, pos_X, pos_Y, offset_X, offset_Y);
break;
}
case 0x0016 | VAULTFUNCTION: // GUISize - Update window
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
unsigned char* _args = (unsigned char*) (data + strlen(data) + 1);
float size_X = *(double*)(_args + 1);
float size_Y = *(double*)(_args + 10);
float offset_X = *(double*)(_args + 19);
float offset_Y = *(double*)(_args + 28);
GUI_SetSize(data, size_X, size_Y, offset_X, offset_Y);
break;
}
case 0x0017 | VAULTFUNCTION: // GUIVisible - Update window
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
unsigned char* _args = (unsigned char*) (data + strlen(data) + 1);
bool visible = (bool) *(unsigned int*)(_args + 1);
GUI_SetVisible(data, visible);
break;
}
case 0x0018 | VAULTFUNCTION: // GUILocked - Update window
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
unsigned char* _args = (unsigned char*) (data + strlen(data) + 1);
bool locked = (bool) *(unsigned int*)(_args + 1);
GUI_AllowDrag(data, !locked);
break;
}
case 0x0019 | VAULTFUNCTION: // GUIText - Update text
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
GUI_SetText(data, data + strlen(data) + 3);
break;
}
case 0x0021 | VAULTFUNCTION: // GUIMaxLen - Update max length
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
unsigned char* _args = (unsigned char*) (data + strlen(data) + 1);
unsigned int length = *(unsigned int*)(_args + 1);
GUI_Textbox_SetMaxLength(data, length);
break;
}
case 0x0022 | VAULTFUNCTION: // GUIValid - Update validation
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
GUI_Textbox_SetValidationString(data, data + strlen(data) + 3);
break;
}
case 0x0023 | VAULTFUNCTION: // GUICreateCheckbox - Create checkbox
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
GUI_AddCheckbox(data, data + strlen(data) + 3);
break;
}
case 0x0024 | VAULTFUNCTION: // GUICheckbox - Update checkbox
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
unsigned char* _args = (unsigned char*) (data + strlen(data) + 1);
bool selected = (bool) *(unsigned int*)(_args + 1);
GUI_SetChecked(data, selected);
break;
}
case 0x0026 | VAULTFUNCTION: // GUICreateRadio - Create radio button
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
const char* str2 = data + strlen(data) + 3;
GUI_AddRadioButton(data, str2, *(unsigned int*) (str2 + strlen(str2) + 2));
break;
}
case 0x0027 | VAULTFUNCTION: // GUIRadioGroup - Set radio group
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
GUI_Radio_SetGroupID(data, *(unsigned int*)(data + strlen(data) + 2));
break;
}
case 0x0028 | VAULTFUNCTION: // GUICreateListbox - Create listbox
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
GUI_AddListbox(data, data + strlen(data) + 3);
break;
}
case 0x0029 | VAULTFUNCTION: // GUICreateItem - Create item
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
const char* str2 = data + strlen(data) + 3;
GUI_Listbox_AddItem(data, str2, str2 + strlen(str2) + 3);
break;
}
case 0x0030 | VAULTFUNCTION: // GUIRemoveItem - Remove item
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
GUI_Listbox_RemoveItem(data, data + strlen(data) + 3);
break;
}
case 0x0032 | VAULTFUNCTION: // GUISelectChange - Change select state
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
const char* str2 = data + strlen(data) + 3;
GUI_Listbox_SetItemSelected(data, str2, *(unsigned int*)(str2 + strlen(str2) + 2));
break;
}
case 0x0033 | VAULTFUNCTION: // GUISelectText - Change text
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
const char* str2 = data + strlen(data) + 3;
GUI_Listbox_SetItemText(data, str2, str2 + strlen(str2) + 3);
break;
}
case 0x0034 | VAULTFUNCTION: // GUISelectMulti - Toggle multi select
{
ZeroMemory(result, sizeof(double));
const char* data = ((char*) args) + 2; // skip length
GUI_Listbox_EnableMultiSelect(data, *(unsigned int*)(data + strlen(data) + 2));
break;
}
case 0x0035 | VAULTFUNCTION: // SetPosFast - set position
{
ZeroMemory(result, sizeof(double));
double X = *(double*) ((char*) args + 1);
double Y = *(double*) ((char*) args + 10);
double Z = *(double*) ((char*) args + 19);
unsigned int unk = *(unsigned int*) 0x0107A79C;
SetPos(unk, 0x1007, reference, 'X', X);
SetPos(unk, 0x1007, reference, 'Y', Y);
SetPos(unk, 0x1007, reference, 'Z', Z);
break;
}
default:
break;
}
return false;
}
void GUI_OnClick(const char* name)
{
mInput.lock();
qGUI_OnClick.push(name);
mInput.unlock();
}
void GUI_OnText(const char* name, const char* text)
{
mInput.lock();
qGUI_OnText.emplace(name, text);
mInput.unlock();
}
void GUI_OnCheckbox(const char* name, bool selected)
{
mInput.lock();
qGUI_OnCheckbox.emplace(name, selected);
mInput.unlock();
}
void GUI_OnSelection(const char* name, const char** selections)
{
mInput.lock();
vector<string> select{name};
while (*selections)
{
select.emplace_back(*selections);
++selections;
}
qGUI_OnSelect.emplace(move(select));
mInput.unlock();
}
void GUI_OnReturn(const char* name)
{
mInput.lock();
qGUI_OnReturn.emplace(name);
mInput.unlock();
}
void ExecuteCommand(vector<void*>& args, unsigned int r, bool delegate_flag)
{
if (args.size() != 8)
return;
unsigned int reference = *((unsigned int*) args[2]);
unsigned short opcode;
void* _args;
if (*((unsigned int*) args[1]) == 0x0001001C)
{
opcode = *((unsigned short*)(((unsigned) args[1]) + 4));
_args = (void*)(((unsigned) args[1]) + 4 + 2 + 2 + 2); // skip 0001001C, opcode, unk2, numargs
}
else
{
opcode = *((unsigned short*) args[1]);
_args = (void*)(((unsigned) args[1]) + 2 + 2 + 2); // skip opcode, unk2, numargs
}
if (opcode == 0x00)
return;
if (reference != 0x00)
{
reference = FormLookup(reference);
if (reference == 0x00)
return;
}
void* arg4 = args[4];
unsigned int base = (unsigned) arg4;
unsigned int** param1 = (unsigned int**)(base + 0x44);
unsigned int*** param2 = (unsigned int***)(base + 0x48);
if (*param2 == 0x00000000)
{
param1 = (unsigned int**)(base + 0x40);
param2 = (unsigned int***)(base + 0x44);
}
*param1 = (unsigned int*)((unsigned) *param1 + base);
*param2 = (unsigned int**)((unsigned) *param2 + base);
**param2 = (unsigned int*)((unsigned) **param2 + base);
unsigned int param1_ref = *((unsigned int*)(((unsigned) *param1) + 0x08));
unsigned int param2_ref = *((unsigned int*)(((unsigned) **param2) + 0x08));
if (param1_ref != 0x00)
{
param1_ref = FormLookup(param1_ref);
if (param1_ref == 0x00)
return;
*((unsigned int*)(((unsigned) *param1) + 0x08)) = param1_ref;
}
if (param2_ref != 0x00)
{
param2_ref = FormLookup(param2_ref);
if (param2_ref == 0x00)
return;
*((unsigned int*)(((unsigned)** param2) + 0x08)) = param2_ref;
}
unsigned char result[PIPE_LENGTH];
ZeroMemory(result, sizeof(result));
*((unsigned int*)((unsigned) result + 1)) = r;
bool bigresult = false;
if ((opcode & VAULTFUNCTION) == VAULTFUNCTION)
bigresult = vaultfunction((void*) reference, result + 5, _args, opcode);
else
{
unsigned int function = FuncLookup((unsigned int) opcode);
if (function == 0x00)
return;
void* callAddr = (void*) *((unsigned int*)(function + 0x18));
if (callAddr == 0x00)
return;
if (delegate_flag)
{
delegated.clear();
delegated.reserve(9);
delegated.push_back(args[0]);
delegated.push_back(args[1]);
delegated.push_back((void*) reference);
delegated.push_back((void*) *((unsigned int*) args[3]));
delegated.push_back(args[4]);
delegated.push_back((void*) &arg4);
delegated.push_back(args[6]);
delegated.push_back(args[7]);
delegated.push_back(callAddr);
delegate = true;
while (delegate)
Sleep(1);
}
else
{
CallCommand Call = (CallCommand) callAddr;
Call(args[0], args[1], (void*) reference, (void*) * ((unsigned int*) args[3]), args[4], (void*) &arg4, args[6], args[7]);
}
memcpy(result + 5, args[6], sizeof(double));
}
if (!bigresult)
result[0] = PIPE_OP_RETURN;
else
result[0] = PIPE_OP_RETURN_BIG;
pipeClient.Send(result);
}
DWORD WINAPI vaultmp_pipe(LPVOID data)
{
/* Loading and initalizing vaultgui.dll */
vaultgui = LoadLibrary("vaultgui.dll");
if (vaultgui == NULL)
DLLerror = true;
else
{
LoadLibrary("CEGUIBase.dll");
LoadLibrary("CEGUIDevILImageCodec.dll");
LoadLibrary("CEGUIDirect3D9Renderer.dll");
LoadLibrary("CEGUIExpatParser.dll");
LoadLibrary("CEGUIFalagardWRBase.dll");
LoadLibrary("CEGUIFreeImageImageCodec.dll");
LoadLibrary("CEGUIOpenGLRenderer.dll");
LoadLibrary("CEGUISILLYImageCodec.dll");
LoadLibrary("CEGUISTBImageCodec.dll");
LoadLibrary("CEGUITGAImageCodec.dll");
Chatbox_AddToChat = reinterpret_cast<decltype(Chatbox_AddToChat)>(GetProcAddress(vaultgui, "Chatbox_AddToChat"));
GUI_CreateFrameWindow = reinterpret_cast<decltype(GUI_CreateFrameWindow)>(GetProcAddress(vaultgui, "GUI_CreateFrameWindow"));
GUI_AddStaticText = reinterpret_cast<decltype(GUI_AddStaticText)>(GetProcAddress(vaultgui, "GUI_AddStaticText"));
GUI_AddTextbox = reinterpret_cast<decltype(GUI_AddTextbox)>(GetProcAddress(vaultgui, "GUI_AddTextbox"));
GUI_AddButton = reinterpret_cast<decltype(GUI_AddButton)>(GetProcAddress(vaultgui, "GUI_AddButton"));
GUI_SetVisible = reinterpret_cast<decltype(GUI_SetVisible)>(GetProcAddress(vaultgui, "GUI_SetVisible"));
GUI_AllowDrag = reinterpret_cast<decltype(GUI_AllowDrag)>(GetProcAddress(vaultgui, "GUI_AllowDrag"));
GUI_SetPosition = reinterpret_cast<decltype(GUI_SetPosition)>(GetProcAddress(vaultgui, "GUI_SetPosition"));
GUI_SetSize = reinterpret_cast<decltype(GUI_SetSize)>(GetProcAddress(vaultgui, "GUI_SetSize"));
GUI_SetText = reinterpret_cast<decltype(GUI_SetText)>(GetProcAddress(vaultgui, "GUI_SetText"));
GUI_RemoveWindow = reinterpret_cast<decltype(GUI_RemoveWindow)>(GetProcAddress(vaultgui, "GUI_RemoveWindow"));
GUI_ForceGUI = reinterpret_cast<decltype(GUI_ForceGUI)>(GetProcAddress(vaultgui, "GUI_ForceGUI"));
GUI_SetClickCallback = reinterpret_cast<decltype(GUI_SetClickCallback)>(GetProcAddress(vaultgui, "GUI_SetClickCallback"));
GUI_SetTextChangedCallback = reinterpret_cast<decltype(GUI_SetTextChangedCallback)>(GetProcAddress(vaultgui, "GUI_SetTextChangedCallback"));
GUI_Textbox_SetMaxLength = reinterpret_cast<decltype(GUI_Textbox_SetMaxLength)>(GetProcAddress(vaultgui, "GUI_Textbox_SetMaxLength"));
GUI_Textbox_SetValidationString = reinterpret_cast<decltype(GUI_Textbox_SetValidationString)>(GetProcAddress(vaultgui, "GUI_Textbox_SetValidationString"));
GUI_AddCheckbox = reinterpret_cast<decltype(GUI_AddCheckbox)>(GetProcAddress(vaultgui, "GUI_AddCheckbox"));
GUI_AddRadioButton = reinterpret_cast<decltype(GUI_AddRadioButton)>(GetProcAddress(vaultgui, "GUI_AddRadioButton"));
GUI_SetChecked = reinterpret_cast<decltype(GUI_SetChecked)>(GetProcAddress(vaultgui, "GUI_SetChecked"));
GUI_Radio_SetGroupID = reinterpret_cast<decltype(GUI_Radio_SetGroupID)>(GetProcAddress(vaultgui, "GUI_Radio_SetGroupID"));
GUI_SetCheckboxChangedCallback = reinterpret_cast<decltype(GUI_SetCheckboxChangedCallback)>(GetProcAddress(vaultgui, "GUI_SetCheckboxChangedCallback"));
GUI_AddListbox = reinterpret_cast<decltype(GUI_AddListbox)>(GetProcAddress(vaultgui, "GUI_AddListbox"));
GUI_Listbox_AddItem = reinterpret_cast<decltype(GUI_Listbox_AddItem)>(GetProcAddress(vaultgui, "GUI_Listbox_AddItem"));
GUI_Listbox_RemoveItem = reinterpret_cast<decltype(GUI_Listbox_RemoveItem)>(GetProcAddress(vaultgui, "GUI_Listbox_RemoveItem"));
GUI_Listbox_SetItemText = reinterpret_cast<decltype(GUI_Listbox_SetItemText)>(GetProcAddress(vaultgui, "GUI_Listbox_SetItemText"));
GUI_Listbox_SetItemSelected = reinterpret_cast<decltype(GUI_Listbox_SetItemSelected)>(GetProcAddress(vaultgui, "GUI_Listbox_SetItemSelected"));
GUI_Listbox_EnableMultiSelect = reinterpret_cast<decltype(GUI_Listbox_EnableMultiSelect)>(GetProcAddress(vaultgui, "GUI_Listbox_EnableMultiSelect"));
GUI_SetListboxSelectionChangedCallback = reinterpret_cast<decltype(GUI_SetListboxSelectionChangedCallback)>(GetProcAddress(vaultgui, "GUI_SetListboxSelectionChangedCallback"));
GUI_SetReturnKeyDownCallback = reinterpret_cast<decltype(GUI_SetReturnKeyDownCallback)>(GetProcAddress(vaultgui, "GUI_SetReturnKeyDownCallback"));
SetPlayersDataPointer = reinterpret_cast<decltype(SetPlayersDataPointer)>(GetProcAddress(vaultgui, "SetPlayersDataPointer"));
if (!Chatbox_AddToChat || !GUI_CreateFrameWindow || !GUI_AddStaticText || !GUI_AddTextbox || !GUI_AddButton || !GUI_SetVisible || !GUI_AllowDrag ||
!GUI_SetPosition || !GUI_SetSize || !GUI_SetText || !GUI_RemoveWindow || !GUI_ForceGUI || !GUI_SetClickCallback || !GUI_SetTextChangedCallback ||
!GUI_Textbox_SetMaxLength || !GUI_Textbox_SetValidationString || !SetPlayersDataPointer || !GUI_AddCheckbox || !GUI_AddRadioButton || !GUI_SetChecked ||
!GUI_Radio_SetGroupID || !GUI_AddListbox || !GUI_Listbox_AddItem || !GUI_Listbox_RemoveItem || !GUI_Listbox_SetItemText || !GUI_Listbox_SetItemSelected ||
!GUI_Listbox_EnableMultiSelect || !GUI_SetListboxSelectionChangedCallback || !GUI_SetCheckboxChangedCallback || !GUI_SetReturnKeyDownCallback)
DLLerror = true;
GUI_SetClickCallback(GUI_OnClick);
GUI_SetTextChangedCallback(GUI_OnText);
GUI_SetCheckboxChangedCallback(GUI_OnCheckbox);
GUI_SetListboxSelectionChangedCallback(GUI_OnSelection);
GUI_SetReturnKeyDownCallback(GUI_OnReturn);
/*
players[0].health = 80.0;
sprintf(players[0].name, "asdf");
players[0].pos[0] = 995.0;
players[0].pos[1] = 7157.0;
players[0].pos[2] = 6802.0;
players[0].pid = 1;
players[0].player = true;
players[1].health = 80.0;
sprintf(players[1].name, "asdf123");
players[1].pos[0] = 985.0;
players[1].pos[1] = 7357.0;
players[1].pos[2] = 6802.0;
players[1].pid = 2;
players[1].player = false;
SetPlayersDataPointer(players);