-
Notifications
You must be signed in to change notification settings - Fork 2
/
threads.cpp
1389 lines (1116 loc) · 47.2 KB
/
threads.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 <iostream>
#include <thread>
#include <cstdint>
#include "threads.h"
#include "../memory/extern.h"
#include "../math.hpp"
#define M_PI 3.14159265358979323846f
#define M_RADPI 57.295779513082f
#define M_PI_F ((float)(M_PI))
#define radiansToDegrees 57.29578f
#define RAD2DEG(x) ((float)(x) * (float)(180.f / M_PI_F))
#define DEG2RAD(x) ((float)(x) * (float)(M_PI_F / 180.f))
bool visorStatus = false; // flase = default state, true = modified state;
ULONG64 visorPtr = 0;
bool isAiming(uint64_t instance)
{
uint64_t m_pbreath = func->read_chain(instance, { 0x190, 0x28 });
return func->Readbool(m_pbreath + 0xA0); //0xA0 is aiming
}
bool operator==(const ContainerItem& elem, const ULONG64& url)
{
return elem.itemPtr == url;
}
bool operator==(const DiscoveredItem& elem, const ULONG64& url)
{
return elem.Entity == url;
}
bool operator==(const Threads::DiscoveredPlayer& elem, const ULONG64& url)
{
return elem.Entity == url;
}
threadData <Threads::DiscoveredPlayer> players = {};
threadData <DiscoveredItem> items = {};
uint64_t tablePlayerExperience[] = {
1000, 4017, 8432, 14256, 21477, 30023, 39936, 51204, 63723,
77563, 92713, 111881, 134674, 161139, 191417, 225194, 262366, 302484, 301534,
345751, 391649, 426190, 440444, 524580, 492366, 547896, 609066, 675913, 748474,
826786, 910885, 1000809, 1096593, 1198275, 1309251, 1429580, 1559321, 1698532, 1847272,
2005600, 2173575, 2351255, 2538699, 2735966, 2946585, 3170637, 3408202, 3659361, 3924195,
4202784, 4495210, 4801553, 5121894, 5456314, 5809667, 6182063, 6984426, 7414613, 7864284,
8333549, 8831052, 9360623, 9928578, 10541848, 11206300, 11946977, 12789143, 13820522, 15229487,
17206065, 19706065, 22706065
};
bool Threads::isMe(ULONG64 localPointer)
{
if (localPointer == 0)
return false;
return true;
}
std::vector<ContainerItem> Threads::updateContainerItem(ULONG64& Entries, int containerCount)
{
std::vector<ContainerItem> container;
for (int y = 0; y < containerCount; y++)
{
ULONG64 itemInCointainerPtr = func->Read<ULONG64>(Entries + 0x28 + y * 0x18);
if (itemInCointainerPtr != 0)
{
ContainerItem containerItem;
containerItem.itemPtr = itemInCointainerPtr;
LONG64 itemTemplate = func->Read<ULONG64>(itemInCointainerPtr + 0x40);
ULONG64 itemIdPtr = func->Read<ULONG64>(itemTemplate + 0x50);
containerItem.name = func->readString2(itemIdPtr + 0x14);
for (auto x = 0; x < trkMarketId.size(); x++)
{
if (trkMarketId[x] == containerItem.name)
{
containerItem.name = trkMarketName[x];
containerItem.price = trkMarketPrice[x];
}
}
container.push_back(containerItem);
}
}
return container;
}
DiscoveredItem Threads::updateItem(ULONG64& ent)
{
DiscoveredItem discoveredItem;
discoveredItem.Entity = ent;
ULONG64 loot = func->Read<ULONG64>(ent + 0x10);
ItemProfile* itemProfile = new ItemProfile[sizeof(ItemProfile)];
func->Read(loot, itemProfile, sizeof(ItemProfile));
Interactive* itemInteractive = new Interactive[sizeof(Interactive)];
func->Read(itemProfile->Interactive, itemInteractive, sizeof(Interactive));
GameObject* gameObject = new GameObject[sizeof(GameObject)];
func->Read(itemProfile->GameObject, gameObject, sizeof(GameObject));
TransformOne* transformOne = new TransformOne[sizeof(TransformOne)];
func->Read(gameObject->TransformOne, transformOne, sizeof(TransformOne));
TransformTwo* transformTwo = new TransformTwo[sizeof(TransformTwo)];
func->Read(transformOne->TransformTwo, transformTwo, sizeof(TransformTwo));
if (itemInteractive->RE_ItemOwner != 0)
{
discoveredItem.container = true;
discoveredItem.itemName = "";
TransformContainer* transformContainer = new TransformContainer[sizeof(TransformContainer)];
func->Read(transformTwo->TransformContainer, transformContainer, sizeof(TransformContainer));
discoveredItem.positionInWorld = this->GetPosition2(transformContainer->TransformData);
discoveredItem.containerGrid = func->Read<ULONG64>(itemInteractive->RE_ItemOwner + 0xA0);
discoveredItem.containerGrid = func->Read<ULONG64>(discoveredItem.containerGrid + 0x68);
discoveredItem.containerGrid = func->Read<ULONG64>(discoveredItem.containerGrid + 0x20);
discoveredItem.containerGrid = func->Read<ULONG64>(discoveredItem.containerGrid + 0x40);
discoveredItem.containerGrid = func->Read<ULONG64>(discoveredItem.containerGrid + 0x10);
discoveredItem.countContainerItems = func->Read<int>(discoveredItem.containerGrid + 0x40);
if (discoveredItem.countContainerItems == 0)
{
delete[] itemProfile;
delete[] itemInteractive;
delete[] gameObject;
delete[] transformOne;
delete[] transformTwo;
delete[] transformContainer;
return discoveredItem;
}
ULONG64 Entries = func->Read<ULONG64>(discoveredItem.containerGrid + 0x18);
if (Entries != 0)
discoveredItem.itemsInContainer = this->updateContainerItem(Entries, discoveredItem.countContainerItems);
delete[] transformContainer;
}
else
{
discoveredItem.container = false;
ULONG64 item = func->Read<ULONG64>(itemInteractive->Item + 0x40);
ULONG64 itemIdPtr = func->Read<ULONG64>(item + 0x50);
discoveredItem.itemName = func->readString2(itemIdPtr + 0x14);
for (auto x = 0; x < trkMarketId.size(); x++)
{
if (trkMarketId[x] == discoveredItem.itemName)
{
discoveredItem.itemName = trkMarketName[x];
discoveredItem.price = trkMarketPrice[x];
}
}
ULONG64 itemVectorPtr = func->Read<ULONG64>(transformOne->TransformTwo + 0x38);
discoveredItem.positionInWorld = func->ReadVector(itemVectorPtr + 0x90);
}
delete[] itemProfile;
delete[] itemInteractive;
delete[] gameObject;
delete[] transformOne;
delete[] transformTwo;
return discoveredItem;
}
D3DXVECTOR3 Threads::WorldToScreen(D3DXVECTOR3 input_coordinates, uint64_t opticreal, uint64_t optic, uint64_t fps)
{
auto isoptic = func->Readbool(optic + 0x39);
auto isaim1 = func->Read<ULONG64>(this->localPlayerPtr + 0x190);
isaim1 = func->Read<ULONG64>(isaim1 + 0x28);
auto isaim = func->Readbool(isaim1 + 0xA0);
D3DXMATRIX viewmatrix_transposed;
D3DXMATRIX matrix;
float fov;
float zfv;
float ratio;
if (isoptic && isaim) {
func->Read(opticreal + 0xDC, &matrix, sizeof(D3DXMATRIX));
this->MatrixTranspose(&viewmatrix_transposed, &matrix);
fov = func->ReadFloat(fps + 0x15C);
zfv = func->ReadFloat(opticreal + 0x15C);
ratio = func->ReadFloat(fps + 0x4C8);
}
else {
func->Read(fps + 0xDC, &matrix, sizeof(D3DXMATRIX));
this->MatrixTranspose(&viewmatrix_transposed, &matrix);
}
D3DXVECTOR3 translationVector = D3DXVECTOR3(viewmatrix_transposed._41, viewmatrix_transposed._42, viewmatrix_transposed._43);
D3DXVECTOR3 up = D3DXVECTOR3(viewmatrix_transposed._21, viewmatrix_transposed._22, viewmatrix_transposed._23);
D3DXVECTOR3 right = D3DXVECTOR3(viewmatrix_transposed._11, viewmatrix_transposed._12, viewmatrix_transposed._13);
D3DXVECTOR3 vector3;
float w = D3DXVec3Dot(&translationVector, &input_coordinates) + viewmatrix_transposed._44;
if (w < 0.098f)
w = 1;
float y = D3DXVec3Dot(&input_coordinates, &up) + viewmatrix_transposed._24;
float x = D3DXVec3Dot(&input_coordinates, &right) + viewmatrix_transposed._14;
if (isoptic && isaim) {
if (fov == 35 && zfv == 19.4f)
fov = 50;
auto angleRadHalf = (float)(M_PI / 180) * fov * 0.5f;
auto angleCtg = (float)(cos(angleRadHalf) / sin(angleRadHalf));
x /= angleCtg * ratio * 0.5f;
y /= angleCtg * 0.5f;
}
float ScreenX = (1920 / 2) * (1.f + x / w);
float ScreenY = (1080 / 2) * (1.f - y / w);
float ScreenZ = w;
vector3 = { ScreenX, ScreenY, ScreenZ };
return vector3;
};
D3DMATRIX* Threads::MatrixTranspose(D3DMATRIX* pOut, const D3DMATRIX* pM)
{
// Legacy Function
pOut->_11 = pM->_11;
pOut->_12 = pM->_21;
pOut->_13 = pM->_31;
pOut->_14 = pM->_41;
pOut->_21 = pM->_12;
pOut->_22 = pM->_22;
pOut->_23 = pM->_32;
pOut->_24 = pM->_42;
pOut->_31 = pM->_13;
pOut->_32 = pM->_23;
pOut->_33 = pM->_33;
pOut->_34 = pM->_43;
pOut->_41 = pM->_14;
pOut->_42 = pM->_24;
pOut->_43 = pM->_34;
pOut->_44 = pM->_44;
return pOut;
};
struct Matrix34
{
D3DXVECTOR4 vec0;
D3DXVECTOR4 vec1;
D3DXVECTOR4 vec2;
};
/* this is old transform function, used only for containers, since im lazy to adapt it, and it will be called once */
/* getTransform are overloaded in total */
D3DXVECTOR3 Threads::GetPosition2(ULONG64& bone)
{
__m128 result;
/* _m128 -> Vec4 */
const __m128 mulVec0 = { -2.000, 2.000, -2.000, 0.000 };
const __m128 mulVec1 = { 2.000, -2.000, -2.000, 0.000 };
const __m128 mulVec2 = { -2.000, -2.000, 2.000, 0.000 };
/* Read the transform index for this transform */
auto index = func->Read<int>(bone + 0x40);
/* Getting the transform data ptr */
TransformAccessReadOnly pTransformAccessReadOnly = func->Read<TransformAccessReadOnly>(bone + 0x38);
TransformData transformData = func->Read<TransformData>(pTransformAccessReadOnly.pTransformData + 0x18);
/* Set the size of the matricies & indicies buffers */
std::size_t size_matricies_buffer = sizeof(Matrix34) * index + sizeof(Matrix34);
std::size_t size_indices_buffer = sizeof(int) * index + sizeof(int);
/* Allocate memory for the matricies & indicies buffers */
void* pMatriciesBuf = malloc(size_matricies_buffer);
void* pIndicesBuf = malloc(size_indices_buffer);
/* count position with some magic mathematic*/
if (pMatriciesBuf && pIndicesBuf) {
/* read matricies data to buffer, copy to allocated memory */
func->Read(transformData.pTransformArray, pMatriciesBuf, size_matricies_buffer);
/* read indicies data to buffer, copy to allocated memory */
func->Read(transformData.pTransformIndices, pIndicesBuf, size_indices_buffer);
/* some magic mathematic here and downside */
result = *(__m128*)((uint64_t)pMatriciesBuf + 0x30 * index);
int transform_index = *(int*)((uint64_t)pIndicesBuf + 0x4 * index);
for (int i = 0; transform_index >= 0 && i < 30 && transform_index < size_indices_buffer; i++)
{
Matrix34 matrix34;
matrix34 = *(Matrix34*)((uint64_t)pMatriciesBuf + 0x30 * transform_index);
__m128 xxxx = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x00)); // xxxx
__m128 yyyy = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x55)); // yyyy
__m128 zwxy = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x8E)); // zwxy
__m128 wzyw = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0xDB)); // wzyw
__m128 zzzz = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0xAA)); // zzzz
__m128 yxwy = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x71)); // yxwy
__m128 tmp7 = _mm_mul_ps(*(__m128*)(&matrix34.vec2), result);
result = _mm_add_ps(
_mm_add_ps(
_mm_add_ps(
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(xxxx, mulVec1), zwxy),
_mm_mul_ps(_mm_mul_ps(yyyy, mulVec2), wzyw)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(tmp7), 0xAA))),
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(zzzz, mulVec2), wzyw),
_mm_mul_ps(_mm_mul_ps(xxxx, mulVec0), yxwy)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(tmp7), 0x55)))),
_mm_add_ps(
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(yyyy, mulVec0), yxwy),
_mm_mul_ps(_mm_mul_ps(zzzz, mulVec1), zwxy)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(tmp7), 0x00))),
tmp7)), _mm_load_ps(&matrix34.vec0.x));
transform_index = *(int*)((uint64_t)pIndicesBuf + 0x4 * transform_index);
}
}
free(pMatriciesBuf);
free(pIndicesBuf);
D3DXVECTOR3 vector3 = { result.m128_f32[0], result.m128_f32[1], result.m128_f32[2] };
return vector3;
}
FVector Threads::GetPosition3(ULONG64& bone)
{
__m128 result;
/* _m128 -> Vec4 */
const __m128 mulVec0 = { -2.000, 2.000, -2.000, 0.000 };
const __m128 mulVec1 = { 2.000, -2.000, -2.000, 0.000 };
const __m128 mulVec2 = { -2.000, -2.000, 2.000, 0.000 };
/* Read the transform index for this transform */
auto index = func->Read<int>(bone + 0x40);
/* Getting the transform data ptr */
TransformAccessReadOnly* pTransformAccessReadOnly = new TransformAccessReadOnly[sizeof(TransformAccessReadOnly)];
func->Read(bone + 0x38, pTransformAccessReadOnly, sizeof(TransformAccessReadOnly));
TransformData* transformData = new TransformData[sizeof(transformData)];
func->Read(pTransformAccessReadOnly->pTransformData + 0x18, transformData, sizeof(TransformData));
/* Set the size of the matricies & indicies buffers */
std::size_t size_matricies_buffer = sizeof(Matrix34) * index + sizeof(Matrix34);
std::size_t size_indices_buffer = sizeof(int) * index + sizeof(int);
/* Allocate memory for the matricies & indicies buffers */
void* pMatriciesBuf = malloc(size_matricies_buffer);
void* pIndicesBuf = malloc(size_indices_buffer);
/* count position with some magic mathematic*/
if (pMatriciesBuf && pIndicesBuf)
{
/* read matricies data to buffer, copy to allocated memory */
func->Read(transformData->pTransformArray, pMatriciesBuf, size_matricies_buffer);
/* read indicies data to buffer, copy to allocated memory */
func->Read(transformData->pTransformIndices, pIndicesBuf, size_indices_buffer);
/* some magic mathematic here and downside */
result = *(__m128*)((uint64_t)pMatriciesBuf + 0x30 * index);
int transform_index = *(int*)((uint64_t)pIndicesBuf + 0x4 * index);
for (int i = 0; transform_index >= 0 && i < 30 && transform_index < size_indices_buffer; i++)
{
Matrix34 matrix34 = *(Matrix34*)((uint64_t)pMatriciesBuf + 0x30 * transform_index);
__m128 xxxx = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x00)); // xxxx
__m128 yyyy = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x55)); // yyyy
__m128 zwxy = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x8E)); // zwxy
__m128 wzyw = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0xDB)); // wzyw
__m128 zzzz = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0xAA)); // zzzz
__m128 yxwy = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x71)); // yxwy
__m128 tmp7 = _mm_mul_ps(*(__m128*)(&matrix34.vec2), result);
result = _mm_add_ps(
_mm_add_ps(
_mm_add_ps(
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(xxxx, mulVec1), zwxy),
_mm_mul_ps(_mm_mul_ps(yyyy, mulVec2), wzyw)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(tmp7), 0xAA))),
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(zzzz, mulVec2), wzyw),
_mm_mul_ps(_mm_mul_ps(xxxx, mulVec0), yxwy)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(tmp7), 0x55)))),
_mm_add_ps(
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(yyyy, mulVec0), yxwy),
_mm_mul_ps(_mm_mul_ps(zzzz, mulVec1), zwxy)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(tmp7), 0x00))),
tmp7)), _mm_load_ps(&matrix34.vec0.x));
transform_index = *(int*)((uint64_t)pIndicesBuf + 0x4 * transform_index);
}
}
delete[] pTransformAccessReadOnly;
delete[] transformData;
free(pMatriciesBuf);
free(pIndicesBuf);
FVector vector3 = { result.m128_f32[0], result.m128_f32[1], result.m128_f32[2] };
return vector3;
}
struct Matrix3X4
{
D3DXVECTOR3 vec0;
D3DXVECTOR3 vec1;
D3DXVECTOR3 vec2;
D3DXVECTOR3 vec3;
};
/* this is new transform function for bones, will reduce read attempts on bone-updating*/
D3DXVECTOR3 Threads::GetPosition2(BonesStruct& bone)
{
__m128 result;
/* _m128 -> Vec4 */
const __m128 mulVec0 = { -2.000, 2.000, -2.000, 0.000 };
const __m128 mulVec1 = { 2.000, -2.000, -2.000, 0.000 };
const __m128 mulVec2 = { -2.000, -2.000, 2.000, 0.000 };
/* Read the transform index for this transform */
auto index = func->Read<int>(bone.bonePTR + 0x40);
/* Getting the transform data ptr */
TransformAccessReadOnly pTransformAccessReadOnly = func->Read<TransformAccessReadOnly>(bone.bonePTR + 0x38);
TransformData transformData = func->Read<TransformData>(pTransformAccessReadOnly.pTransformData + 0x18);
/* Set the size of the matricies & indicies buffers */
std::size_t size_matricies_buffer = sizeof(Matrix34) * index + sizeof(Matrix34);
std::size_t size_indices_buffer = sizeof(int) * index + sizeof(int);
/* Allocate memory for the matricies & indicies buffers */
void* pMatriciesBuf = malloc(size_matricies_buffer);
void* pIndicesBuf = malloc(size_indices_buffer);
/* count position with some magic mathematic*/
if (pMatriciesBuf && pIndicesBuf) {
/* read matricies data to buffer, copy to allocated memory */
func->Read(transformData.pTransformArray, pMatriciesBuf, size_matricies_buffer);
/* read indicies data to buffer, copy to allocated memory */
func->Read(transformData.pTransformIndices, pIndicesBuf, size_indices_buffer);
/* some magic mathematic here and downside */
result = *(__m128*)((uint64_t)pMatriciesBuf + 0x30 * index);
int transform_index = *(int*)((uint64_t)pIndicesBuf + 0x4 * index);
for (int i = 0; transform_index >= 0 && i < 30 && transform_index < size_indices_buffer; i++)
{
Matrix34 matrix34;
matrix34 = *(Matrix34*)((uint64_t)pMatriciesBuf + 0x30 * transform_index);
__m128 xxxx = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x00)); // xxxx
__m128 yyyy = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x55)); // yyyy
__m128 zwxy = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x8E)); // zwxy
__m128 wzyw = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0xDB)); // wzyw
__m128 zzzz = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0xAA)); // zzzz
__m128 yxwy = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x71)); // yxwy
__m128 tmp7 = _mm_mul_ps(*(__m128*)(&matrix34.vec2), result);
result = _mm_add_ps(
_mm_add_ps(
_mm_add_ps(
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(xxxx, mulVec1), zwxy),
_mm_mul_ps(_mm_mul_ps(yyyy, mulVec2), wzyw)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(tmp7), 0xAA))),
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(zzzz, mulVec2), wzyw),
_mm_mul_ps(_mm_mul_ps(xxxx, mulVec0), yxwy)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(tmp7), 0x55)))),
_mm_add_ps(
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(yyyy, mulVec0), yxwy),
_mm_mul_ps(_mm_mul_ps(zzzz, mulVec1), zwxy)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(tmp7), 0x00))),
tmp7)), _mm_load_ps(&matrix34.vec0.x));
transform_index = *(int*)((uint64_t)pIndicesBuf + 0x4 * transform_index);
}
}
free(pMatriciesBuf);
free(pIndicesBuf);
D3DXVECTOR3 vector3 = { result.m128_f32[0], result.m128_f32[1], result.m128_f32[2] };
return vector3;
}
FVector Threads::GetPosition4(BonesStruct& bone)
{
__m128 result;
/* _m128 -> Vec4 */
const __m128 mulVec0 = { -2.000, 2.000, -2.000, 0.000 };
const __m128 mulVec1 = { 2.000, -2.000, -2.000, 0.000 };
const __m128 mulVec2 = { -2.000, -2.000, 2.000, 0.000 };
/* Getting the transform data ptr */
if (bone.transformAccess.index == 0 && bone.transformAccess.pTransformData == 0)
{
func->Read(bone.bonePTR + 0x38, &bone.transformAccess, sizeof(TransformAccessReadOnly));
func->Read(bone.transformAccess.pTransformData + 0x18, &bone.transformData, sizeof(TransformData));
}
/* Set the size of the matricies & indicies buffers */
std::size_t size_matricies_buffer = sizeof(Matrix34) * bone.transformAccess.index + sizeof(Matrix34);
std::size_t size_indices_buffer = sizeof(int) * bone.transformAccess.index + sizeof(int);
/* Allocate memory for the matricies & indicies buffers */
void* pMatriciesBuf = malloc(size_matricies_buffer);
void* pIndicesBuf = malloc(size_indices_buffer);
/* count position with some magic mathematic*/
if (pMatriciesBuf && pIndicesBuf)
{
/* read matricies data to buffer, copy to allocated memory */
func->Read(bone.transformData.pTransformArray, pMatriciesBuf, size_matricies_buffer);
/* read indicies data to buffer, copy to allocated memory */
func->Read(bone.transformData.pTransformIndices, pIndicesBuf, size_indices_buffer);
/* some magic mathematic here and downside */
result = *(__m128*)((uint64_t)pMatriciesBuf + 0x30 * bone.transformAccess.index);
int transform_index = *(int*)((uint64_t)pIndicesBuf + 0x4 * bone.transformAccess.index);
for (int i = 0; transform_index >= 0 && i < 30 && transform_index < size_indices_buffer; i++)
{
Matrix34 matrix34 = *(Matrix34*)((uint64_t)pMatriciesBuf + 0x30 * transform_index);
__m128 xxxx = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x00)); // xxxx
__m128 yyyy = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x55)); // yyyy
__m128 zwxy = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x8E)); // zwxy
__m128 wzyw = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0xDB)); // wzyw
__m128 zzzz = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0xAA)); // zzzz
__m128 yxwy = _mm_castsi128_ps(_mm_shuffle_epi32(*(__m128i*)(&matrix34.vec1), 0x71)); // yxwy
__m128 tmp7 = _mm_mul_ps(*(__m128*)(&matrix34.vec2), result);
result = _mm_add_ps(
_mm_add_ps(
_mm_add_ps(
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(xxxx, mulVec1), zwxy),
_mm_mul_ps(_mm_mul_ps(yyyy, mulVec2), wzyw)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(tmp7), 0xAA))),
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(zzzz, mulVec2), wzyw),
_mm_mul_ps(_mm_mul_ps(xxxx, mulVec0), yxwy)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(tmp7), 0x55)))),
_mm_add_ps(
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(yyyy, mulVec0), yxwy),
_mm_mul_ps(_mm_mul_ps(zzzz, mulVec1), zwxy)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(tmp7), 0x00))),
tmp7)), _mm_load_ps(&matrix34.vec0.x));
transform_index = *(int*)((uint64_t)pIndicesBuf + 0x4 * transform_index);
}
}
free(pMatriciesBuf);
free(pIndicesBuf);
FVector vector3 = { result.m128_f32[0], result.m128_f32[1], result.m128_f32[2] };
return vector3;
}
FVector getAngle(const FVector& origin, const FVector& dest) {
FVector diff = origin - dest;
FVector ret;
float length = diff.GetLength();
ret.y = asinf(diff.y / length);
ret.x = -atan2f(diff.x, -diff.z);
return ret * radiansToDegrees;
}
float calcFov(const FVector& viewAngle, const FVector& aimAngle) {
FVector diff = viewAngle - aimAngle;
if (diff.x < -180.f)
diff.x += 360.f;
if (diff.x > 180.f)
diff.x -= 360.f;
return fabsf(diff.GetLength());
}
uint64_t matrix_list_base1;
uint64_t dependency_index_table_base1;
FVector Threads::GetPositionaim(uint64_t transform)
{
auto transform_internal = func->Read<uint64_t>(transform + 0x10);
auto matrices = func->Read<uint64_t>(transform_internal + 0x38);
auto index = func->Read<int>(transform_internal + 0x40);
func->Read((matrices + 0x18), &matrix_list_base1, sizeof(matrix_list_base1));
func->Read((matrices + 0x20), &dependency_index_table_base1, sizeof(dependency_index_table_base1));
static auto get_dependency_index = [this](uint64_t base, int32_t index)
{
func->Read((base + index * 4), &index, sizeof(index));
return index;
};
static auto get_matrix_blob = [this](uint64_t base, uint64_t offs, float* blob, uint32_t size) {
func->Read((base + offs), blob, size);
};
int32_t index_relation = get_dependency_index(dependency_index_table_base1, index);
FVector ret_value;
{
float* base_matrix3x4 = (float*)malloc(64),
* matrix3x4_buffer0 = (float*)((uint64_t)base_matrix3x4 + 16),
* matrix3x4_buffer1 = (float*)((uint64_t)base_matrix3x4 + 32),
* matrix3x4_buffer2 = (float*)((uint64_t)base_matrix3x4 + 48);
get_matrix_blob(matrix_list_base1, index * 48, base_matrix3x4, 16);
__m128 xmmword_1410D1340 = { -2.f, 2.f, -2.f, 0.f };
__m128 xmmword_1410D1350 = { 2.f, -2.f, -2.f, 0.f };
__m128 xmmword_1410D1360 = { -2.f, -2.f, 2.f, 0.f };
while (index_relation >= 0)
{
uint32_t matrix_relation_index = 6 * index_relation;
// paziuret kur tik 3 nureadina, ten translationas, kur 4 = quatas ir yra rotationas.
get_matrix_blob(matrix_list_base1, 8 * matrix_relation_index, matrix3x4_buffer2, 16);
__m128 v_0 = *(__m128*)matrix3x4_buffer2;
get_matrix_blob(matrix_list_base1, 8 * matrix_relation_index + 32, matrix3x4_buffer0, 16);
__m128 v_1 = *(__m128*)matrix3x4_buffer0;
get_matrix_blob(matrix_list_base1, 8 * matrix_relation_index + 16, matrix3x4_buffer1, 16);
__m128i v9 = *(__m128i*)matrix3x4_buffer1;
__m128* v3 = (__m128*)base_matrix3x4; // r10@1
__m128 v10; // xmm9@2
__m128 v11; // xmm3@2
__m128 v12; // xmm8@2
__m128 v13; // xmm4@2
__m128 v14; // xmm2@2
__m128 v15; // xmm5@2
__m128 v16; // xmm6@2
__m128 v17; // xmm7@2
v10 = _mm_mul_ps(v_1, *v3);
v11 = _mm_castsi128_ps(_mm_shuffle_epi32(v9, 0));
v12 = _mm_castsi128_ps(_mm_shuffle_epi32(v9, 85));
v13 = _mm_castsi128_ps(_mm_shuffle_epi32(v9, -114));
v14 = _mm_castsi128_ps(_mm_shuffle_epi32(v9, -37));
v15 = _mm_castsi128_ps(_mm_shuffle_epi32(v9, -86));
v16 = _mm_castsi128_ps(_mm_shuffle_epi32(v9, 113));
v17 = _mm_add_ps(
_mm_add_ps(
_mm_add_ps(
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(v11, (__m128)xmmword_1410D1350), v13),
_mm_mul_ps(_mm_mul_ps(v12, (__m128)xmmword_1410D1360), v14)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(v10), -86))),
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(v15, (__m128)xmmword_1410D1360), v14),
_mm_mul_ps(_mm_mul_ps(v11, (__m128)xmmword_1410D1340), v16)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(v10), 85)))),
_mm_add_ps(
_mm_mul_ps(
_mm_sub_ps(
_mm_mul_ps(_mm_mul_ps(v12, (__m128)xmmword_1410D1340), v16),
_mm_mul_ps(_mm_mul_ps(v15, (__m128)xmmword_1410D1350), v13)),
_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(v10), 0))),
v10)),
v_0);
*v3 = v17;
index_relation = get_dependency_index(dependency_index_table_base1, index_relation);
}
ret_value = *(FVector*)base_matrix3x4;
delete[] base_matrix3x4;
}
return ret_value;
}
/* getting info about new players in list */
Threads::DiscoveredPlayer Threads::updatePlayer(ULONG64& entity)
{
Threads::DiscoveredPlayer discoveredPlayer;
discoveredPlayer.Entity = entity;
/* create EFT_Player struct */
EFT_Player* player = new EFT_Player[sizeof(EFT_Player)];
/* create Player profile struct */
PlayerProfile* playerProfile = new PlayerProfile[sizeof(PlayerProfile)];
/* create playerInfo struct */
PlayerInfo* playerInfo = new PlayerInfo[sizeof(PlayerInfo)];
/* read all data to created structs above */
func->Read(entity, player, sizeof(EFT_Player));
func->Read(player->PlayerProfile, playerProfile, sizeof(PlayerProfile));
func->Read(playerProfile->PlayerInfo, playerInfo, sizeof(PlayerInfo));
/* get bones adresses */
std::vector<ULONG64> bonesChain{ this->SkeletonRootJoin, this->BoneEnumerator, this->TransformArray };
ULONG64 allBonesPTR = func->read_chain(player->PlayerBody, { bonesChain });
BOOL local = func->Readbool(entity + 0x7F3);
if (local)
{
this->localPlayerPtr = entity;
// get localPlayer HeadPTR
BonesStruct bone; bone.bonePTR = func->read_chain(allBonesPTR, { ULONG64(0x20 + (92 * 0x8)), 0x10 });
//get bone's transform's data
if (bone.transformAccess.index == 0 && bone.transformAccess.pTransformData == 0)
{
func->Read(bone.bonePTR + 0x38, &bone.transformAccess, sizeof(TransformAccessReadOnly));
func->Read(bone.transformAccess.pTransformData + 0x18, &bone.transformData, sizeof(TransformData));
}
discoveredPlayer.bones.push_back(bone);
discoveredPlayer.local = true;
delete[] player; delete[] playerProfile; delete[] playerInfo;
return discoveredPlayer;
}
/* special numbers for bones in EFT memory
* i give no shit how exactly they counted in EFT xD */
int bone_array[] = { 113, 112, 111, 132, 90, 91, 92, 133, 37, 36, 29, 14, 22, 23, 17,18 };
for (int i : bone_array)
{
// get player bonePtr
BonesStruct bone; bone.bonePTR = func->read_chain(allBonesPTR, { ULONG64(0x20 + (i * 0x8)), 0x10 });
//get bone's transform's data
if (bone.transformAccess.index == 0 && bone.transformAccess.pTransformData == 0)
{
func->Read(bone.bonePTR + 0x38, &bone.transformAccess, sizeof(TransformAccessReadOnly));
func->Read(bone.transformAccess.pTransformData + 0x18, &bone.transformData, sizeof(TransformData));
}
discoveredPlayer.bones.push_back(bone);
}
/* =============================== */
/* add inventory read here */
/* =============================== */
/* checking if it's real player or bot
* if not - grabbing botRole */
if (playerInfo->RegistrationDate <= 0)
{
// it's a bot!
discoveredPlayer.Side = func->Read<int>(playerInfo->RE_Settings + 0x10);
}
else
{
// it's a player!
// checking if it's BEAR or USEC
if (playerInfo->Side == 1 || playerInfo->Side == 2)
{
// using custom value, to not create new variable in class
if (playerInfo->Side == 1)
discoveredPlayer.Side = 55;
else
discoveredPlayer.Side = 56;
// get level
for (size_t currentlevel = 0; currentlevel < 71; currentlevel++)
{
auto currentLevelExp = tablePlayerExperience[currentlevel];
if (playerInfo->Experience < currentLevelExp)
{
discoveredPlayer.Level = currentlevel - 1;
break;
}
}
// get group ID
discoveredPlayer.GroupId = func->readString(playerInfo->UnityEngineString_GroupId + 0x14);
int nickSize = func->Read<int>(playerInfo->UnityEngineString_Nickname + 0x10);
// get nickname
discoveredPlayer.NickName = func->GetUnicodeString(playerInfo->UnityEngineString_Nickname + 0x14, nickSize);
/* get KDa */
/* =============================== */
/* UNFINISHED SHIT I HATE THIS KD RATIO FUCK THIS FUCK */
PlayerStats* playerStats = new PlayerStats[sizeof(PlayerStats)];
func->Read(playerProfile->Stats, playerStats, sizeof(PlayerStats));
delete[] playerStats;
/* count KDa ends */
/* =============================== */
}
/* it's a player Scav! we don't need any shit above */
else if (playerInfo->Side == 4)
{
discoveredPlayer.Side = 4;
/* get group ID*/
discoveredPlayer.GroupId = func->readString(playerInfo->UnityEngineString_GroupId + 0x14);
}
}
delete[] player; delete[] playerProfile; delete[] playerInfo;
return discoveredPlayer;
}
void Threads::GetPlayers2(ULONG64 oprl, ULONG64 viewMatrixPtr, ULONG64 opticptr)
{
//set delay
//std::this_thread::sleep_for(std::chrono::milliseconds(1));
// read current playerThread
this->playerCount = func->Read<int>(data.playerListPtr + 0x18);
// stupid check, does playerCount has right value
if (this->playerCount > 0 && this->playerCount < 50)
{
this->online = true;
}
// playerCount changed (+1 player, or -1 player, or we just started )
if (this->playerCount != data.playerCount)
{
/* allocating storage for players ptr */
ULONG64* entityBuffer = new ULONG64[this->playerCount * sizeof(ULONG64)];
/* grab all entities with readBuffer */
func->Read(data.playerListArray + offsets->firstPlayer, entityBuffer, this->playerCount * sizeof(ULONG64));
/* store all data in vector of ULONG64 */
std::vector<ULONG64> foundPlayers = std::vector<ULONG64>(entityBuffer, entityBuffer + this->playerCount);
/* stop memory leak */
delete[] entityBuffer;
// if we already have some players in vector == we search for changes
if (players.vector.size() != 0)
{
// players decreasedw
if (this->playerCount < data.playerCount)
{
for (auto x = 0; x < players.vector.size();)
{
if (std::find(foundPlayers.begin(), foundPlayers.end(), players.vector[x].Entity) != foundPlayers.end())
{
x++;
continue;
}
else
{
players.N.lock();
players.M.lock();
players.N.unlock();
players.vector.erase(players.vector.begin() + x);
players.M.unlock();
continue;
}
}
}
//players increased, adding new player
if (this->playerCount > data.playerCount)
{
for (auto x = 0; x < foundPlayers.size(); x++)
{
if (std::find(players.vector.begin(), players.vector.end(), foundPlayers[x]) != players.vector.end())
{
continue;
}
else
{
players.N.lock();
players.M.lock();
players.N.unlock();
players.vector.resize(players.vector.size() + 1);
players.vector[players.vector.size() - 1] = this->updatePlayer(foundPlayers[x]);
players.M.unlock();
continue;
}
}
}
}
else
{
// we have empty players storage = collect data on start
for (auto x = 0; x < foundPlayers.size(); x++)
{
players.N.lock();
players.M.lock();
players.N.unlock();
players.vector.push_back(this->updatePlayer(foundPlayers[x]));
players.M.unlock();
}
}
data.playerCount = this->playerCount;
}
else
{
// updating current bone-pos for each player;
std::vector<DrawPlayer> temporaryDrawStorage;
for (auto ent : players.vector)
{
/* collect all data to send it for draw-cycle */
DrawPlayer player;
if (ent.local == true)
{
this->localPlayerHead = this->GetPosition2(ent.bones[0]);
player.local = ent.local;
player.bonesVectors = ent.bonesVectors;