-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseEntity.cpp
8818 lines (7383 loc) · 245 KB
/
BaseEntity.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 "precompiled.h"
#include <Windows.h>
#include "BaseEntity.h"
#include "Offsets.h"
#include "VTHook.h"
#include "Trace.h"
#include "Math.h"
#include "Interfaces.h"
#include "Overlay.h"
#include "BaseAnimating.h"
#include "Interpolation.h"
#include "Animation.h"
#include "LocalPlayer.h"
#include "ThirdPerson.h"
#include "ConVar.h"
#include <intrin.h>
#include "CBaseHandle.h"
#include "CPlayerResource.h"
#include "VMProtectDefs.h"
#include "ErrorCodes.h"
#include "NetworkedVariables.h"
#include "CPlayerrecord.h"
#include <atomic>
#include "utlvectorsimple.h"
#include "IClientUnknown.h"
#include "IModelInfoClient.h"
#include "IClientRenderable.h"
#include "IClientNetworkable.h"
#include "CViewModel.h"
#include "UsedConvars.h"
#include "bone_setup.h"
#include "utlbuffer.h"
#include "utlsymbol.h"
#include "GetValveAllocator.h"
#include <Psapi.h>
HookedEntity::~HookedEntity()
{
if (phook)
{
phook->ClearClassBase();
//can't do this in the header or else it doesn't call destructor
delete phook;
phook = nullptr;
}
}
IKInitFn IKInit;
UpdateTargetsFn UpdateTargets;
SolveDependenciesFn SolveDependencies;
AttachmentHelperFn AttachmentHelper;
ConstructIKFn ConstructIK;
TeleportedFn Teleported;
bool AllowShouldSkipAnimationFrame = true;
ShouldSkipAnimationFrameFn ShouldSkipAnimationFrame;
DWORD ShouldSkipAnimationFrameIsPlayerReturnAdr;
MDLCacheCriticalSectionCallFn MDLCacheCriticalSectionCall;
MarkForThreadedBoneSetupFn MarkForThreadedBoneSetupCall;
GetSequenceNameFn GetSequenceName;
GetSequenceActivityFn GetSequenceActivity;
GetSequenceActivityNameForModelFn GetSequenceActivityNameForModel;
ActivityList_NameForIndexFn ActivityList_NameForIndex;
SequencesAvailableCallFn SequencesAvailableCall;
ReevaluateAnimLodFn ReevaluateAnimLod;
LockStudioHdrFn oLockStudioHdr;
GetFirstSequenceAnimTagFn oGetFirstSequenceAnimTag;
SurpressLadderChecksFn oSurpressLadderChecks;
SetPunchVMTFn oSetPunchVMT;
IsInAVehicleFn oIsInAVehicle;
IsCarryingHostageFn oIsCarryingHostage;
EyeVectorsFn oEyeVectors;
GetBonePositionFn oGetBonePosition;
LookupBoneFn oLookupBone;
bool* s_bEnableInvalidateBoneCache;
bool* bAllowBoneAccessForViewModels;
bool* bAllowBoneAccessForNormalModels;
unsigned long* g_iModelBoneCounter;
bool* g_bInThreadedBoneSetup;
bool* s_bAbsRecomputationEnabled;
bool* s_bAbsQueriesValid;
extern bool bIsSettingUpBones;
bool AllowSetupBonesToUpdateAttachments = false;
UpdateClientSideAnimationFn oUpdateClientSideAnimation;
std::unordered_map< int, HookedEntity* > HookedNonPlayerEntities;
std::list<CBaseEntity*> g_Infernos;
void __fastcall HookedUpdateClientSideAnimation(CBaseEntity* me)
{
return;
#if 0
if (g_Convars.Compatibility.disable_all->GetBool() || m_bAnimationUpdateAllowed)
oUpdateClientSideAnimation(me);
#endif
}
INetChannelInfo* GetPlayerNetInfoServer(int entindex)
{
static DWORD EngineInterfaceServer = NULL;
const char* sig = "8B 0D ?? ?? ?? ?? 52 8B 01 8B 40 54";
if (!EngineInterfaceServer)
{
EngineInterfaceServer = FindMemoryPattern(GetModuleHandleA("server.dll"), (char*)sig, strlen(sig));
if (!EngineInterfaceServer)
DebugBreak();
EngineInterfaceServer = *(DWORD*)(EngineInterfaceServer + 2);
}
DWORD table = *(DWORD*)EngineInterfaceServer;
return ((INetChannelInfo * (__thiscall*)(DWORD, int)) * (DWORD*)(*(DWORD*)table + 0x54))(table, entindex);
}
IClientUnknown* CBaseEntity::GetClientUnknown() const
{
return (IClientUnknown*)this;
}
IClientNetworkable* CBaseEntity::GetClientNetworkable()
{
return GetClientUnknown()->GetClientNetworkable();
}; //this+8
IClientRenderable* CBaseEntity::GetClientRenderable()
{
return GetClientUnknown()->GetClientRenderable();
}; //this+4
void CBaseEntity::PreDataUpdate(DataUpdateType_t updateType)
{
GetClientNetworkable()->PreDataUpdate(updateType);
//auto networkable = GetClientNetworkable();
//GetVFunc<void(__thiscall*)(IClientNetworkable*)>(networkable, m_dwPreDataUpdate)(networkable);
}
void CBaseEntity::PostDataUpdate(DataUpdateType_t updateType)
{
GetClientNetworkable()->PostDataUpdate(updateType);
//auto networkable = GetClientNetworkable();
//GetVFunc<void(__thiscall*)(IClientNetworkable*)>(networkable, m_dwPostDataUpdate)(networkable);
}
// This event is triggered during the simulation phase if an entity's data has changed. It is
// better to hook this instead of PostDataUpdate() because in PostDataUpdate(), server entity origins
// are incorrect and attachment points can't be used.
void CBaseEntity::OnDataChanged(DataUpdateType_t type)
{
GetClientNetworkable()->OnDataChanged(type);
}
// This is called once per frame before any data is read in from the server.
void CBaseEntity::OnPreDataChanged(DataUpdateType_t type)
{
GetClientNetworkable()->OnPreDataChanged(type);
}
//-----------------------------------------------------------------------------
// Global methods related to when abs data is correct
//-----------------------------------------------------------------------------
void CBaseEntity::SetAbsQueriesValid(bool bValid)
{
// @MULTICORE: Always allow in worker threads, assume higher level code is handling correctly
if (!ThreadInMainThread())
return;
if (!bValid)
{
*s_bAbsQueriesValid = false;
}
else
{
*s_bAbsQueriesValid = true;
}
}
bool CBaseEntity::IsAbsQueriesValid(void)
{
if (!ThreadInMainThread())
return true;
return *s_bAbsQueriesValid;
}
void CBaseEntity::PushEnableAbsRecomputations(bool bEnable)
{
#ifdef FIXED
if (!ThreadInMainThread())
return;
if (*g_iAbsRecomputationStackPos < ARRAYSIZE(g_bAbsRecomputationStack))
{
g_bAbsRecomputationStack[g_iAbsRecomputationStackPos] = s_bAbsRecomputationEnabled;
*g_iAbsRecomputationStackPos = *g_iAbsRecomputationStackPos + 1;
*s_bAbsRecomputationEnabled = bEnable;
}
else
{
//Assert(false);
}
#endif
}
void CBaseEntity::PopEnableAbsRecomputations()
{
#ifdef FIXED
if (!ThreadInMainThread())
return;
if (*g_iAbsRecomputationStackPos > 0)
{
*g_iAbsRecomputationStackPos = *g_iAbsRecomputationStackPos - 1;
s_bAbsRecomputationEnabled = g_bAbsRecomputationStack[*g_iAbsRecomputationStackPos];
}
else
{
//Assert(false);
}
#endif
}
void CBaseEntity::EnableAbsRecomputations(bool bEnable)
{
if (!ThreadInMainThread())
return;
// This should only be called at the frame level. Use PushEnableAbsRecomputations
// if you're blocking out a section of code.
//Assert(g_iAbsRecomputationStackPos == 0);
*s_bAbsRecomputationEnabled = bEnable;
}
bool CBaseEntity::IsAbsRecomputationsEnabled()
{
if (!ThreadInMainThread())
return true;
return *s_bAbsRecomputationEnabled;
}
CPlayerrecord* CBaseEntity::ToPlayerRecord()
{
return g_LagCompensation.GetPlayerrecord(index);
}
bool CBaseEntity::LockBones()
{
CThreadFastMutex* pBoneSetupLock = GetBoneSetupLock();
if (*g_bInThreadedBoneSetup)
{
if (!pBoneSetupLock->TryLock())
{
// someone else is handling
#ifdef _DEBUG
DebugBreak();
#endif
return false;
}
// else, we have the lock
}
else
{
pBoneSetupLock->Lock();
}
return true;
}
void CBaseEntity::UnlockBones()
{
CThreadFastMutex* pBoneSetupLock = GetBoneSetupLock();
pBoneSetupLock->Unlock();
}
int CBaseEntity::GetForceBone()
{
return *(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_nForceBone);
}
void CBaseEntity::SetForceBone(int bone)
{
*(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_nForceBone) = bone;
}
QAngle CBaseEntity::GetAngleFromHitbox(int hitboxid)
{
CBoneAccessor* accessor = GetBoneAccessor();
mstudiohitboxset_t* set = Interfaces::ModelInfoClient->GetStudioModel(GetModel())->pHitboxSet(GetHitboxSet());
mstudiobbox_t* hitbox = set->pHitbox(hitboxid);
Vector vMin, vMax;
TransformAABB(accessor->GetBone(hitbox->bone), hitbox->bbmin, hitbox->bbmax, vMin, vMax);
QAngle AngleFromMinsMaxs = CalcAngle(vMin, vMax);
return AngleFromMinsMaxs;
#ifdef _DEBUG
Vector vecForward, vecRight, vecUp;
AngleVectors(AngleFromMinsMaxs, &vecForward, &vecRight, &vecUp);
VectorNormalizeFast(vecForward);
Vector topofhitbox = vMax + vecForward * hitbox->radius;
Vector bottomofhitbox = vMin - vecForward * hitbox->radius;
Vector newcenter = (bottomofhitbox + topofhitbox) * 0.5f;
/*
//front of skull top left
TargetBonePos = { vMax.x + radius * 0.5f, vMax.y + radius * 0.5f, vCenter.z + radius };
//front of skull top right
TargetBonePos = { vMax.x + radius * 0.5f, vMax.y - radius * 0.5f, vCenter.z + radius };
//front of skull bottom left
TargetBonePos = { vMin.x + radius * 0.5f, vMin.y + radius * 0.5f, vCenter.z - radius };
//front of skull bottom right
TargetBonePos = { vMin.x + radius * 0.5f, vMin.y - radius * 0.5f, vCenter.z - radius };
//back of skull bottom left
TargetBonePos = { vMin.x - radius * 0.5f, vMin.y + radius * 0.5f, vCenter.z - radius };
//back of skull bottom right
TargetBonePos = { vMin.x - radius * 0.5f, vMin.y - radius * 0.5f, vCenter.z - radius };
//back of skull top left
TargetBonePos = { vMax.x - radius * 0.5f, vMax.y + radius * 0.5f, vCenter.z + radius };
//back of skull top right
TargetBonePos = { vMax.x - radius * 0.5f, vMax.y - radius * 0.5f, vCenter.z + radius };
*/
//Interfaces::DebugOverlay->AddLineOverlay(newcenter, newcenter + vecForward * (hitbox->radius * 50), 0, 255, 0, 0, Interfaces::Globals->interval_per_tick * 2);
//Interfaces::DebugOverlay->AddBoxOverlay(topofhitbox, Vector(-0.5, -0.5, -0.5), Vector(0.5, 0.5, 0.5), AngleFromMinsMaxs, 0, 0, 255, 255, Interfaces::Globals->interval_per_tick * 2);
//Interfaces::DebugOverlay->AddBoxOverlay(bottomofhitbox, Vector(-0.5, -0.5, -0.5), Vector(0.5, 0.5, 0.5), AngleFromMinsMaxs, 0, 0, 255, 255, Interfaces::Globals->interval_per_tick * 2);
//float rotation = (5 * M_PI) / 3;
//Vector rotated;
//rotated.x = cos(rotation) * ((topofhitbox.x + hitbox->radius) - vCenter.x) - sin(rotation) * ((topofhitbox.y + hitbox->radius) - vCenter.y) + vCenter.x;
//rotated.y = sin(rotation) * ((topofhitbox.x + hitbox->radius) - vCenter.x) + cos(rotation) * ((topofhitbox.y + hitbox->radius) - vCenter.y) + vCenter.y; //math for y is fucked
//rotated.z = vCenter.z;
//Interfaces::DebugOverlay->AddBoxOverlay(rotated, Vector(-0.5, -0.5, -0.5), Vector(0.5, 0.5, 0.5), AngleFromMinsMaxs, 255, 0, 255, 255, Interfaces::Globals->interval_per_tick * 2);
return AngleFromMinsMaxs;
#endif
}
void CBaseEntity::GetDirectionFromHitbox(Vector* vForward, Vector* vRight, Vector* vUp, int hitboxid)
{
QAngle AngleFromMinsMaxs = GetAngleFromHitbox(hitboxid);
AngleVectors(AngleFromMinsMaxs, vForward, vRight, vUp);
if (vForward)
vForward->NormalizeInPlace();
if (vRight)
vRight->NormalizeInPlace();
if (vUp)
vUp->NormalizeInPlace();
}
bool CBaseEntity::IsStrafing()
{
return *(bool*)((DWORD)this + g_NetworkedVariables.Offsets.m_bStrafing);
}
void CBaseEntity::SetIsStrafing(bool strafing)
{
*(bool*)((DWORD)this + g_NetworkedVariables.Offsets.m_bStrafing) = strafing;
}
int CBaseEntity::GetHealth()
{
return *(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_iHealth); //*(int*)((DWORD)this + m_iHealth);
}
void CBaseEntity::SetHealth(int health)
{
*(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_iHealth) = health;
}
int CBaseEntity::GetTeam()
{
return *(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_iTeamNum); //*(int*)((DWORD)this + m_iTeamNum);
}
int CBaseEntity::GetMoney()
{
return *(int*)((DWORD)this + 0xB354);
}
void CBaseEntity::Simulate()
{
StaticOffsets.GetVFuncByType<void(__thiscall*)(CBaseEntity*)>(_Simulate, this)(this);
}
eEntityType CBaseEntity::GetEntityType()
{
ClassID iClassID = (ClassID)this->GetClientClass()->m_ClassID;
if (iClassID == _CChicken)
return chicken;
if (iClassID == _CCSPlayer)
return player;
if (iClassID == _CC4)
return c4;
if (iClassID == _CPlantedC4)
return plantedc4;
if (iClassID == _CInferno || iClassID == _CBaseCSGrenadeProjectile || iClassID == _CDecoyProjectile || iClassID == _CMolotovProjectile || iClassID == _CSmokeGrenadeProjectile || iClassID == _CSensorGrenadeProjectile)
return projectile;
if (this->IsWeapon() && !this->GetOwner())
return weapon;
return none;
}
int CBaseEntity::GetFlags()
{
return *(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_fFlags); //*(int*)((DWORD)this + m_fFlags);
}
void CBaseEntity::SetFlags(int flags)
{
*(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_fFlags) = flags;
}
void CBaseEntity::AddFlag(int flag)
{
*(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_fFlags) |= flag;
}
void CBaseEntity::RemoveFlag(int flag)
{
*(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_fFlags) &= ~flag;
}
int CBaseEntity::HasFlag(int flag)
{
return GetFlags() & flag;
}
int CBaseEntity::IsOnGround()
{
return HasFlag(FL_ONGROUND);
}
int CBaseEntity::IsInAir()
{
return !HasFlag(FL_ONGROUND);
}
int CBaseEntity::HasEFlag(int flag)
{
return *StaticOffsets.GetOffsetValueByType< int* >(_m_iEFlags, this) & flag;
}
int CBaseEntity::GetEFlags()
{
return *StaticOffsets.GetOffsetValueByType< int* >(_m_iEFlags, this);
}
void CBaseEntity::SetEFlags(int flags)
{
*StaticOffsets.GetOffsetValueByType< int* >(_m_iEFlags, this) = flags;
}
void CBaseEntity::AddEFlag(int flag)
{
*StaticOffsets.GetOffsetValueByType< int* >(_m_iEFlags, this) |= flag;
}
void CBaseEntity::RemoveEFlag(int flag)
{
*StaticOffsets.GetOffsetValueByType< int* >(_m_iEFlags, this) &= ~flag;
}
bool CBaseEntity::IsScoped()
{
return *(bool*)((DWORD)this + g_NetworkedVariables.Offsets.m_bIsScoped); // 0x387C);
}
int CBaseEntity::GetTickBase()
{
return *(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_nTickBase); //*(int*)((DWORD)this + m_nTickBase);
}
float CBaseEntity::GetThirdPersonRecoil()
{
return *(float*)((DWORD)this + g_NetworkedVariables.Offsets.m_flThirdpersonRecoil);
}
void CBaseEntity::SetThirdPersonRecoil(float recoil)
{
*(float*)((DWORD)this + g_NetworkedVariables.Offsets.m_flThirdpersonRecoil) = recoil;
}
void CBaseEntity::SetTickBase(int base)
{
*(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_nTickBase) = base;
}
int CBaseEntity::GetShotsFired()
{
return *(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_iShotsFired); //*(int*)((DWORD)this + m_iShotsFired);
}
int CBaseEntity::GetMoveType()
{
return *StaticOffsets.GetOffsetValueByType< int* >(_MoveType, this);
}
void CBaseEntity::SetMoveType(int type)
{
*StaticOffsets.GetOffsetValueByType< int* >(_MoveType, this) = type;
}
int CBaseEntity::GetModelIndex()
{
return *(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_nModelIndex); // *(int*)((DWORD)this + m_nModelIndex);
}
void CBaseEntity::SetModelIndex(int index)
{
*(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_nModelIndex) = index;
}
int CBaseEntity::GetHitboxSet()
{
return *(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_nHitboxSet); //*(int*)((DWORD)this + m_nHitboxSet);
}
int CBaseEntity::GetHitboxSetServer()
{
return *(DWORD*)((DWORD)this + m_nHitboxSetServer);
}
void CBaseEntity::SetHitboxSet(int set)
{
*(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_nHitboxSet) = set;
}
int CBaseEntity::GetUserID()
{
player_info_t info;
GetPlayerInfo(&info);
return info.userid; //this->GetPlayerInfo().userid; //DYLAN FIX
}
int CBaseEntity::GetArmor()
{
return *(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_ArmorValue); //*(int*)((DWORD)this + m_ArmorValue);
}
void CBaseEntity::SetArmor(int armor)
{
*(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_ArmorValue) = armor;
}
unsigned CBaseEntity::PhysicsSolidMaskForEntity()
{
typedef unsigned int(__thiscall * OriginalFn)(void*);
return StaticOffsets.GetVFuncByType< OriginalFn >(_PhysicsSolidMaskForEntityVMT, this)(this); //154 //8B 06 8B CE FF 90 ?? ?? 00 00 A9 00 00 01 00 74 27
}
CBaseEntity* CBaseEntity::GetOwner()
{
DWORD Handle = *(DWORD*)((DWORD)this + g_NetworkedVariables.Offsets.m_hOwnerEntity);
return Interfaces::ClientEntList->GetBaseEntityFromHandle(Handle);
}
void CBaseEntity::SetOwnerHandle(EHANDLE handle)
{
*(EHANDLE*)((DWORD)this + g_NetworkedVariables.Offsets.m_hOwnerEntity) = handle;
}
int CBaseEntity::GetGlowIndex()
{
return *(int*)((DWORD)this + m_iGlowIndex); //*(int*)((DWORD)this + m_iGlowIndex);
}
float CBaseEntity::GetBombTimer()
{
float bombTime = *(float*)((DWORD)this + g_NetworkedVariables.Offsets.m_flC4Blow);
float returnValue = bombTime - Interfaces::Globals->curtime;
return (returnValue < 0) ? 0.f : returnValue;
}
bool CBaseEntity::GetBombDefused()
{
return *(bool*)((DWORD)this + g_NetworkedVariables.Offsets.m_bBombDefused);
}
float CBaseEntity::GetFlashDuration()
{
return *(float*)((DWORD)this + g_NetworkedVariables.Offsets.m_flFlashDuration); //*(float*)((DWORD)this + m_flFlashDuration);
}
void CBaseEntity::SetFlashDuration(float dur)
{
*(float*)((DWORD)this + g_NetworkedVariables.Offsets.m_flFlashDuration) = dur;
}
void CBaseEntity::SetFlashMaxAlpha(float a)
{
*(float*)((DWORD)this + g_NetworkedVariables.Offsets.m_flFlashMaxAlpha) = a;
}
BOOLEAN CBaseEntity::IsFlashed()
{
return (BOOLEAN)GetFlashDuration() > 0 ? true : false;
}
bool CBaseEntity::IsSpectating()
{
if (GetTeam() == TEAM_GOTV)
return true;
CBaseEntity* hObserverTarget = GetObserverTarget(); // &0xFFF;
if (hObserverTarget && hObserverTarget != this)
{
auto packet = IsPlayer() ? ToPlayerRecord()->GetFarESPPacket() : nullptr;
if (packet)
return false;
return true;
}
return false;
}
void CBaseEntity::SetMoveCollide(MoveCollide_t c)
{
*StaticOffsets.GetOffsetValueByType< MoveCollide_t* >(_MoveCollide, this) = c;
}
MoveCollide_t CBaseEntity::GetMoveCollide()
{
return *StaticOffsets.GetOffsetValueByType< MoveCollide_t* >(_MoveCollide, this);
}
bool CBaseEntity::GetDeadFlag()
{
return *(bool*)((DWORD)this + g_NetworkedVariables.Offsets.deadflag);
}
void CBaseEntity::SetDeadFlag(bool flag)
{
*(bool*)((DWORD)this + g_NetworkedVariables.Offsets.deadflag) = flag;
}
int CBaseEntity::GetLifeState()
{
return *(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_lifeState);
}
void CBaseEntity::SetLifeState(int state)
{
*(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_lifeState) = state;
}
int CBaseEntity::m_lifeState()
{
return *(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_lifeState);
}
BOOL CBaseEntity::GetAlive()
{
if (!this)
return false;
if (GetHealth() == 0)
return false;
return true;
//return (bool)(*(int*)((DWORD)this + m_lifeState) == 0);
///return *(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_lifeState) == LIFE_ALIVE ? TRUE : FALSE;
}
BOOLEAN CBaseEntity::GetAliveServer()
{
typedef BOOLEAN(__thiscall * OriginalFn)(CBaseEntity*);
return GetVFunc< OriginalFn >(this, (0x114 / 4))(this);
}
void CBaseEntity::CalcAbsolutePosition()
{
((void(__thiscall*)(CBaseEntity*))AdrOf_CalcAbsolutePosition)(this);
}
void CBaseEntity::CalcAbsolutePositionServer()
{
#ifdef HOOK_LAG_COMPENSATION
static DWORD absposfunc = NULL;
if (!absposfunc)
{
const char* sig = "55 8B EC 83 E4 F0 83 EC 68 56 8B F1 57 8B 8E D0 00 00 00";
absposfunc = FindMemoryPattern(GetModuleHandleA("server.dll"), (char*)sig, strlen(sig));
if (!absposfunc)
DebugBreak();
}
((void(__thiscall*)(CBaseEntity*))absposfunc)(this);
#endif
}
bool CBaseEntity::GetDormant()
{
return *(bool*)((DWORD)this + m_bDormant_); //*(bool*)((DWORD)this + m_bDormant);
}
void CBaseEntity::SetDormant(bool dormant)
{
*(bool*)((DWORD)this + m_bDormant_) = dormant;
}
void CBaseEntity::SetDormantVMT(bool dormant)
{
((void (*)(CBaseEntity*, bool))OffsetOf_SetDormant)(this, dormant);
}
int CBaseEntity::GetvphysicsCollisionState()
{
return *(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_vphysicsCollisionState);
}
void CBaseEntity::SetvphysicsCollisionState(int state)
{
*(int*)((DWORD)this + g_NetworkedVariables.Offsets.m_vphysicsCollisionState) = state;
}
bool CBaseEntity::GetImmune()
{
return *(bool*)((DWORD)this + g_NetworkedVariables.Offsets.m_bGunGameImmunity); //*(bool*)((DWORD)this + m_bGunGameImmunity);
}
BOOLEAN CBaseEntity::HasHelmet()
{
return (BOOLEAN) * (BOOLEAN*)((DWORD)this + g_NetworkedVariables.Offsets.m_bHasHelmet); //*(bool*)((DWORD)this + m_bHasHelmet);
}
void CBaseEntity::SetHasHelmet(BOOLEAN helmet)
{
*(BOOLEAN*)((DWORD)this + g_NetworkedVariables.Offsets.m_bHasHelmet) = helmet; //*(bool*)((DWORD)this + m_bHasHelmet);
}
BOOLEAN CBaseEntity::HasDefuseKit()
{
return (BOOLEAN) * (BOOLEAN*)((DWORD)this + g_NetworkedVariables.Offsets.m_bHasDefuser);
}
BOOLEAN CBaseEntity::IsDefusing()
{
return (BOOLEAN) * (BOOLEAN*)((DWORD)this + g_NetworkedVariables.Offsets.m_bIsDefusing);
}
Vector CBaseEntity::GetVehicleViewOrigin()
{
return *StaticOffsets.GetOffsetValueByType< Vector* >(_VehicleViewOrigin, this);
}
void CBaseEntity::LockStudioHdr()
{
oLockStudioHdr(this);
}
model_t* CBaseEntity::GetModel()
{
#if 1
if (!this)
return nullptr;
IClientUnknown* unk = GetClientUnknown();
auto renderable = unk->GetClientRenderable();
if (renderable)
return (model_t*)renderable->GetModel();
return nullptr;
#else
CBaseEntity* renderable = (CBaseEntity*)((DWORD)this + 4);
typedef model_t*(__thiscall * OriginalFn)(CBaseEntity*);
#ifdef _DEBUG
model_t* ret = GetVFunc< OriginalFn >(renderable, 8)(renderable);
return ret;
#else
return GetVFunc< OriginalFn >(renderable, 8)(renderable);
#endif
//return (model_t*)*(DWORD*)((DWORD)this + 0x6C); //DYLAN TEST THIS //*(model_t**)((DWORD)this + 0x6C);
#endif
}
uint64_t zFindSignature(const char* szModule, const char* szSignature)
{
#define INRANGE(x, a, b) (x >= a && x <= b) //-V1003
#define GETBITS(x) (INRANGE((x & (~0x20)),'A','F') ? ((x & (~0x20)) - 'A' + 0xA) : (INRANGE(x, '0', '9') ? x - '0' : 0)) //-V1003
#define GETBYTE(x) (GETBITS(x[0]) << 4 | GETBITS(x[1]))
MODULEINFO modInfo;
GetModuleInformation(GetCurrentProcess(), GetModuleHandleA(szModule), &modInfo, sizeof(MODULEINFO));
uintptr_t startAddress = (DWORD)modInfo.lpBaseOfDll; //-V101 //-V220
uintptr_t endAddress = startAddress + modInfo.SizeOfImage;
const char* pat = szSignature;
uintptr_t firstMatch = 0;
for (auto pCur = startAddress; pCur < endAddress; pCur++)
{
if (!*pat)
return firstMatch;
if (*(PBYTE)pat == '\?' || *(BYTE*)pCur == GETBYTE(pat))
{
if (!firstMatch)
firstMatch = pCur;
if (!pat[2])
return firstMatch;
if (*(PWORD)pat == '\?\?' || *(PBYTE)pat != '\?')
pat += 3;
else
pat += 2;
}
else
{
pat = szSignature;
firstMatch = 0;
}
}
MessageBoxA(NULL, szSignature, szModule, 64);
return 0;
}
CStudioHdr* CBaseEntity::GetModelPtr()
{
//static auto studio_hdr = zFindSignature("client.dll", ("8B B7 ?? ?? ?? ?? 89 74 24 20"));
//return *(CStudioHdr**)((uintptr_t)this + *(uintptr_t*)(studio_hdr + 0x2) + 0x4);
CStudioHdr* hdr = *StaticOffsets.GetOffsetValueByType< CStudioHdr** >(_m_pStudioHdr, this);
//CStudioHdr* hdr = *(CStudioHdr**)((uintptr_t)this + *(uintptr_t*)(studio_hdr + 0x2) + 0x4);
if (!hdr && GetModel())
{
LockStudioHdr();
}
return (hdr && hdr->IsValid()) ? hdr : NULL;
}
CStudioHdr* CBaseEntity::GetStudioHdr()
{
return GetModelPtr();
//return (studiohdr_t*)*(DWORD*)((DWORD)this + m_pStudioHdr2);
}
mstudioseqdesc_t* CBaseEntity::pSeqdesc(int seq)
{
return opSeqdesc((studiohdr_t*)GetModelPtr(), seq);
}
void CBaseEntity::SetModel(model_t* mod)
{
*(DWORD*) ((DWORD)this + 0x6C) = (DWORD)mod;
}
BOOLEAN CBaseEntity::IsBroken()
{
return (BOOLEAN) * (BOOLEAN*)((DWORD)this + g_NetworkedVariables.Offsets.m_bIsBroken); //*(bool*)((DWORD)this + m_bIsBroken);
}
QAngle* CBaseEntity::GetViewPunchAdr()
{
return (QAngle*)((DWORD)this + g_NetworkedVariables.Offsets.m_viewPunchAngle);
}
QAngle CBaseEntity::GetViewPunch()
{
return *(QAngle*)((DWORD)this + g_NetworkedVariables.Offsets.m_viewPunchAngle);
}
void CBaseEntity::SetViewPunch(QAngle& punch)
{
*(QAngle*)((DWORD)this + g_NetworkedVariables.Offsets.m_viewPunchAngle) = punch;
}
QAngle CBaseEntity::GetPunch()
{
return *(QAngle*)((DWORD)this + g_NetworkedVariables.Offsets.m_aimPunchAngle);
}
QAngle* CBaseEntity::GetPunchAdr()
{
return (QAngle*)((DWORD)this + g_NetworkedVariables.Offsets.m_aimPunchAngle);
}
void CBaseEntity::GetPunchVMT(QAngle& dest)
{
typedef void(__thiscall * OriginalFn)(CBaseEntity*, QAngle&);
StaticOffsets.GetVFuncByType< OriginalFn >(_GetPunchAngleVMT, this)(this, dest);
}
void CBaseEntity::SetPunchVMT(QAngle& punch)
{
oSetPunchVMT(this, punch);
}
void CBaseEntity::SetPunch(QAngle& punch)
{
*(QAngle*)((DWORD)this + g_NetworkedVariables.Offsets.m_aimPunchAngle) = punch;
}
Vector CBaseEntity::GetPunchVel()
{
return *(Vector*)((DWORD)this + g_NetworkedVariables.Offsets.m_aimPunchAngleVel);
}
void CBaseEntity::SetPunchVel(Vector& vel)
{
*(Vector*)((DWORD)this + g_NetworkedVariables.Offsets.m_aimPunchAngleVel) = vel;
}
QAngle CBaseEntity::GetEyeAngles()
{
return *(QAngle*)((DWORD)this + g_NetworkedVariables.Offsets.m_angEyeAngles);
}
QAngle CBaseEntity::GetEyeAnglesServer()
{
return *(QAngle*)((DWORD)this + m_angEyeAnglesServer);
}
QAngle* CBaseEntity::EyeAngles()
{
typedef QAngle*(__thiscall * OriginalFn)(CBaseEntity*);
return StaticOffsets.GetVFuncByType< OriginalFn >(_EyeAnglesVMT, this)(this);
}
void CBaseEntity::SetEyeAngles(QAngle &angles)
{
*(QAngle*)((DWORD)this + g_NetworkedVariables.Offsets.m_angEyeAngles) = angles;
}
/*
QAngle CBaseEntity::GetRenderAngles()
{
return *(QAngle*)((DWORD)this + g_NetworkedVariables.Offsets.deadflag + 0x4);
}
void CBaseEntity::SetRenderAngles(QAngle angles)
{
*(QAngle*)((DWORD)this + g_NetworkedVariables.Offsets.deadflag + 0x4) = angles;
}
*/
Vector* CBaseEntity::GetLocalOriginVMT()
{
IClientRenderable* renderable = GetClientRenderable();
typedef Vector*(__thiscall * OriginalFn)(IClientRenderable*);
return GetVFunc< OriginalFn >(renderable, 1)(renderable);
}
QAngle* CBaseEntity::GetLocalAnglesVMT()
{
IClientRenderable* renderable = GetClientRenderable();
typedef QAngle*(__thiscall * OriginalFn)(IClientRenderable*);
return GetVFunc< OriginalFn >(renderable, 2)(renderable);
}
// Prevent these for now until hierarchy is properly networked
void CBaseEntity::SetLocalOrigin(const Vector& origin)
{
Vector* dest = StaticOffsets.GetOffsetValueByType< Vector* >(_LocalOrigin, this);
if (*dest != origin)
{
// This will cause the velocities of all children to need recomputation
InvalidatePhysicsRecursive(POSITION_CHANGED);
*dest = origin;
}
}
void CBaseEntity::SetLocalOriginDirect(const Vector& origin)
{
*StaticOffsets.GetOffsetValueByType< Vector* >(_LocalOrigin, this) = origin;
}
Vector CBaseEntity::GetLocalOriginDirect()
{
return *StaticOffsets.GetOffsetValueByType< Vector* >(_LocalOrigin, this);
}
Vector CBaseEntity::GetLocalOrigin()
{
return GetLocalOriginDirect();
}
// Prevent these for now until hierarchy is properly networked
void CBaseEntity::SetLocalAngles(const QAngle& angles)
{
QAngle* dest = StaticOffsets.GetOffsetValueByType< QAngle* >(_LocalAngles, this);
if (*dest != angles)
{
// This will cause the velocities of all children to need recomputation
InvalidatePhysicsRecursive(ANGLES_CHANGED);