-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextension.cpp
More file actions
22637 lines (18434 loc) · 695 KB
/
extension.cpp
File metadata and controls
22637 lines (18434 loc) · 695 KB
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
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod Sample Extension
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#define swap V_swap
#include <string>
#include <vector>
#include <unordered_map>
#include <cstdint>
using namespace std::literals::string_literals;
#include <cxxabi.h>
#if __has_include(<tinfo.h>)
#include <tinfo.h>
#else
namespace __cxxabiv1
{
struct vtable_prefix
{
// Offset to most derived object.
ptrdiff_t whole_object;
// Additional padding if necessary.
#ifdef _GLIBCXX_VTABLE_PADDING
ptrdiff_t padding1;
#endif
// Pointer to most derived type_info.
const __class_type_info *whole_type;
// Additional padding if necessary.
#ifdef _GLIBCXX_VTABLE_PADDING
ptrdiff_t padding2;
#endif
// What a class's vptr points to.
const void *origin;
};
}
#endif
#if SOURCE_ENGINE == SE_TF2
#define TF_DLL
#define USES_ECON_ITEMS
#elif SOURCE_ENGINE == SE_LEFT4DEAD2
#define TERROR
#define LEFT4DEAD
#endif
#define BASEENTITY_H
#define NEXT_BOT
#define GLOWS_ENABLE
#define USE_NAV_MESH
#define RAD_TELEMETRY_DISABLED
#if SOURCE_ENGINE == SE_LEFT4DEAD2
#include <public/tier1/utlmemory.h>
#include <public/tier1/utlvector.h>
#endif
class IGameEventManager2 *gameeventmanager = nullptr;
#include "extension.h"
#include <ISDKTools.h>
#include <mathlib/vmatrix.h>
#include <toolframework/itoolentity.h>
#include <ehandle.h>
#include <GameEventListener.h>
#include <eiface.h>
#include <dt_common.h>
class IEngineTrace *enginetrace = nullptr;
class IStaticPropMgrServer *staticpropmgr = nullptr;
#include <public/networkvar.h>
#include <shared/shareddefs.h>
#include <shared/util_shared.h>
#ifndef FMTFUNCTION
#define FMTFUNCTION(...)
#endif
#include <util.h>
#include <variant_t.h>
#include <shared/predictioncopy.h>
#include <tier1/utldict.h>
#include <tier1/utlvector.h>
#include <CDetour/detours.h>
#include <takedamageinfo.h>
#include <vphysics_interface.h>
#ifdef __HAS_DAMAGERULES
#include <IDamageRules.h>
#include <public/damageinfo.cpp>
#else
#define BASE_DAMAGEINFO_STRUCT_SIZE ((sizeof(cell_t) * 3) * 3 + sizeof(cell_t) * 10)
#if SOURCE_ENGINE == SE_TF2
#define DAMAGEINFO_STRUCT_SIZE (BASE_DAMAGEINFO_STRUCT_SIZE + sizeof(cell_t) * 7)
#elif SOURCE_ENGINE == SE_LEFT4DEAD2
#define DAMAGEINFO_STRUCT_SIZE (BASE_DAMAGEINFO_STRUCT_SIZE + sizeof(cell_t) * 7)
#endif
#define DAMAGEINFO_STRUCT_SIZE_IN_CELL (DAMAGEINFO_STRUCT_SIZE / sizeof(cell_t))
#endif
#ifdef __HAS_ANIMHELPERS
#include <IAnimHelpers.h>
#endif
#include <toolframework/itoolentity.h>
/**
* @file extension.cpp
* @brief Implement extension code here.
*/
Sample g_Sample{}; /**< Global singleton for extension's main interface */
SMEXT_LINK(&g_Sample);
ICvar *icvar = nullptr;
CGlobalVars *gpGlobals = nullptr;
CBaseEntityList *g_pEntityList = nullptr;
IServerTools *servertools = nullptr;
ISDKTools *g_pSDKTools = nullptr;
enum MRESReturn
{
MRES_ChangedHandled = -2, // Use changed values and return MRES_Handled
MRES_ChangedOverride, // Use changed values and return MRES_Override
MRES_Ignored, // plugin didn't take any action
MRES_Handled, // plugin did something, but real function should still be called
MRES_Override, // call real function, but use my return value
MRES_Supercede // skip real function; use my return value
};
static_assert(sizeof(MRESReturn) == sizeof(cell_t), "");
META_RES mres_to_meta_res(MRESReturn res)
{
switch(res) {
case MRES_Ignored:
return MRES_IGNORED;
case MRES_ChangedHandled:
case MRES_Handled:
return MRES_HANDLED;
case MRES_ChangedOverride:
case MRES_Override:
return MRES_OVERRIDE;
case MRES_Supercede:
return MRES_SUPERCEDE;
}
}
class INextBot;
class CNavArea;
class CNavLadder;
class CFuncElevator;
class CBaseCombatCharacter;
class CNavMesh;
class INextBotComponent;
class PathFollower;
class ISave;
class IRestore;
CNavMesh *TheNavMesh = nullptr;
#if SOURCE_ENGINE == SE_TF2
ConVar nav_authorative("nav_authorative", "1");
#endif
ConVar path_expensive_optimize("path_expensive_optimize", "0");
#if SOURCE_ENGINE == SE_TF2
ConVar *tf_nav_combat_decay_rate = nullptr;
ConVar *tf_nav_combat_build_rate = nullptr;
ConVar *tf_select_ambush_areas_max_enemy_exposure_area = nullptr;
ConVar *tf_select_ambush_areas_close_range = nullptr;
#endif
int sizeofNextBotCombatCharacter = 0;
#if SOURCE_ENGINE == SE_LEFT4DEAD2
int sizeofInfected = 0;
#endif
void *PathCTOR = nullptr;
void *PathFollowerCTOR = nullptr;
void *NextBotCombatCharacterCTOR = nullptr;
void *INextBotCTOR = nullptr;
#if SOURCE_ENGINE == SE_TF2
void *CTFPathFollowerCTOR = nullptr;
#endif
#if SOURCE_ENGINE == SE_TF2
void *NextBotGroundLocomotionCTOR = nullptr;
void *ILocomotionCTOR = nullptr;
void *IVisionCTOR = nullptr;
#elif SOURCE_ENGINE == SE_LEFT4DEAD2
void *ZombieBotLocomotionCTOR = nullptr;
void *ZombieBotVisionCTOR = nullptr;
#endif
void *PathComputePathDetails = nullptr;
void *PathBuildTrivialPath = nullptr;
void *PathFindNextOccludedNode = nullptr;
void *PathPostProcess = nullptr;
void *CNavMeshGetGroundHeight = nullptr;
void *CNavMeshGetNearestNavArea = nullptr;
void *CBaseEntitySetAbsOrigin = nullptr;
void *INextBotBeginUpdatePtr = nullptr;
void *INextBotEndUpdatePtr = nullptr;
void *CBaseEntityCalcAbsoluteVelocity = nullptr;
#if SOURCE_ENGINE == SE_TF2
void *NextBotGroundLocomotionResolveCollision = nullptr;
#endif
void *CBaseEntitySetGroundEntity = nullptr;
void *CTraceFilterSimpleShouldHitEntity = nullptr;
#if SOURCE_ENGINE == SE_LEFT4DEAD2
void *PathComputeVector = nullptr;
void *PathComputeEntity = nullptr;
void *INextBotIsDebuggingPtr = nullptr;
void *InfectedChasePathComputeAreaCrossing = nullptr;
void *EntityFactoryDictionaryPtr = nullptr;
#endif
void *CBaseEntityCalcAbsolutePosition = nullptr;
void *CBaseCombatCharacterAllocateDefaultRelationships = nullptr;
void *CBaseCombatCharacterSetDefaultRelationship = nullptr;
int CBaseCombatCharacterIsHiddenByFogVec = -1;
int CBaseCombatCharacterIsHiddenByFogEnt = -1;
int CBaseCombatCharacterIsHiddenByFogR = -1;
int CBaseCombatCharacterGetFogObscuredRatioVec = -1;
int CBaseCombatCharacterGetFogObscuredRatioEnt = -1;
int CBaseCombatCharacterGetFogObscuredRatioR = -1;
int CBaseCombatCharacterIsLookingTowardsEnt = -1;
int CBaseCombatCharacterIsLookingTowardsVec = -1;
int CBaseCombatCharacterIsInFieldOfViewEnt = -1;
int CBaseCombatCharacterIsInFieldOfViewVec = -1;
int CBaseCombatCharacterIsLineOfSightClearEnt = -1;
int CBaseCombatCharacterIsLineOfSightClearVec = -1;
int CBaseEntityFVisibleVec = -1;
int CBaseEntityFVisibleEnt = -1;
int CBaseCombatCharacterFInViewConeVec = -1;
int CBaseCombatCharacterFInViewConeEnt = -1;
int CBaseCombatCharacterFInAimConeVec = -1;
int CBaseCombatCharacterFInAimConeEnt = -1;
int CBaseCombatCharacterIRelationType = -1;
int CBaseCombatCharacterOnPursuedBy = -1;
void *CBaseCombatCharacterIsAbleToSeeEnt = nullptr;
void *CBaseCombatCharacterIsAbleToSeeCC = nullptr;
void *NavAreaBuildPathPtr = nullptr;
int CBaseEntityMyNextBotPointer = -1;
int CBaseEntityMyCombatCharacterPointer = -1;
int CBaseEntityGetBaseAnimating = -1;
int CBaseEntityClassify = -1;
#if SOURCE_ENGINE == SE_TF2
int CBaseEntityIsBaseObject = -1;
#endif
int CBaseEntityIsNPC = -1;
#if SOURCE_ENGINE == SE_LEFT4DEAD2
int CBaseEntityMyInfectedPointer = -1;
#endif
int CBaseCombatCharacterGetLastKnownArea = -1;
int CBaseCombatCharacterUpdateLastKnownArea = -1;
int CBaseEntityWorldSpaceCenter = -1;
int CBaseEntityEyeAngles = -1;
#if SOURCE_ENGINE == SE_TF2
int CFuncNavCostGetCostMultiplier = -1;
#endif
#if SOURCE_ENGINE == SE_LEFT4DEAD2
int NextBotCombatCharacterGetNextBotCombatCharacter = -1;
int CBaseCombatCharacterCanBeA = -1;
#endif
int CBaseEntityEyePosition = -1;
int CBaseEntitySpawn = -1;
int m_vecAbsOriginOffset = -1;
int m_vecViewOffsetOffset = -1;
int m_iTeamNumOffset = -1;
int m_vecAbsVelocityOffset = -1;
int m_vecVelocityOffset = -1;
int m_iEFlagsOffset = -1;
int m_fFlagsOffset = -1;
int m_fEffectsOffset = -1;
int m_hGroundEntityOffset = -1;
int m_MoveTypeOffset = -1;
#if SOURCE_ENGINE == SE_LEFT4DEAD2
int m_isGhostOffset = -1;
#endif
int m_rgflCoordinateFrameOffset = -1;
int m_hMoveParentOffset = -1;
int m_hMoveChildOffset = -1;
int m_hMovePeerOffset = -1;
int m_iParentAttachmentOffset = -1;
int m_iClassnameOffset = -1;
int m_flSimulationTimeOffset = -1;
int m_angAbsRotationOffset = -1;
int m_angRotationOffset = -1;
int m_bloodColorOffset = -1;
int m_CollisionGroupOffset = -1;
int m_bSequenceFinishedOffset = -1;
int m_flPlaybackRateOffset = -1;
int m_nSequenceOffset = -1;
int m_flCycleOffset = -1;
int m_flGroundSpeedOffset = -1;
int m_flModelScaleOffset = -1;
ConVar *NextBotStop = nullptr;
ConVar *nb_head_aim_steady_max_rate = nullptr;
ConVar *nb_head_aim_settle_duration = nullptr;
ConVar *nb_saccade_speed = nullptr;
ConVar *nb_head_aim_resettle_angle = nullptr;
ConVar *nb_head_aim_resettle_time = nullptr;
template <typename T>
T void_to_func(void *ptr)
{
union { T f; void *p; };
p = ptr;
return f;
}
template <typename R, typename T>
R func_to_func(T ptr)
{
union { T f; R p; };
f = ptr;
return p;
}
template <typename T>
void *func_to_void(T ptr)
{
union { T f; void *p; };
f = ptr;
return p;
}
template <typename T>
int vfunc_index(T func)
{
SourceHook::MemFuncInfo info{};
SourceHook::GetFuncInfo<T>(func, info);
return info.vtblindex;
}
template <typename R, typename T, typename ...Args>
R call_mfunc(T *pThisPtr, void *offset, Args ...args)
{
class VEmptyClass {};
void **this_ptr = *reinterpret_cast<void ***>(&pThisPtr);
union
{
R (VEmptyClass::*mfpnew)(Args...);
#ifndef PLATFORM_POSIX
void *addr;
} u;
u.addr = offset;
#else
struct
{
void *addr;
intptr_t adjustor;
} s;
} u;
u.s.addr = offset;
u.s.adjustor = 0;
#endif
return (R)(reinterpret_cast<VEmptyClass *>(this_ptr)->*u.mfpnew)(args...);
}
template <typename R, typename T, typename ...Args>
R call_mfunc(const T *pThisPtr, void *offset, Args ...args)
{
return call_mfunc<R, T, Args...>(const_cast<T *>(pThisPtr), offset, args...);
}
template <typename R, typename T, typename ...Args>
R call_vfunc(T *pThisPtr, size_t offset, Args ...args)
{
void **vtable = *reinterpret_cast<void ***>(pThisPtr);
void *vfunc = vtable[offset];
return call_mfunc<R, T, Args...>(pThisPtr, vfunc, args...);
}
template <typename R, typename T, typename ...Args>
R call_vfunc(const T *pThisPtr, size_t offset, Args ...args)
{
return call_vfunc<R, T, Args...>(const_cast<T *>(pThisPtr), offset, args...);
}
extern "C"
{
__attribute__((__visibility__("default"), __cdecl__)) double __pow_finite(double a, double b)
{
return pow(a, b);
}
__attribute__((__visibility__("default"), __cdecl__)) double __log_finite(double a)
{
return log(a);
}
__attribute__((__visibility__("default"), __cdecl__)) double __exp_finite(double a)
{
return exp(a);
}
__attribute__((__visibility__("default"), __cdecl__)) double __atan2_finite(double a, double b)
{
return atan2(a, b);
}
__attribute__((__visibility__("default"), __cdecl__)) float __atan2f_finite(float a, float b)
{
return atan2f(a, b);
}
__attribute__((__visibility__("default"), __cdecl__)) float __powf_finite(float a, float b)
{
return powf(a, b);
}
__attribute__((__visibility__("default"), __cdecl__)) float __logf_finite(float a)
{
return logf(a);
}
__attribute__((__visibility__("default"), __cdecl__)) float __expf_finite(float a)
{
return expf(a);
}
__attribute__((__visibility__("default"), __cdecl__)) float __acosf_finite(float a)
{
return acosf(a);
}
__attribute__((__visibility__("default"), __cdecl__)) double __asin_finite(double a)
{
return asin(a);
}
__attribute__((__visibility__("default"), __cdecl__)) double __acos_finite(double a)
{
return acos(a);
}
}
#define DECLARE_PREDICTABLE()
#include <collisionproperty.h>
#include <ServerNetworkProperty.h>
void SetEdictStateChanged(CBaseEntity *pEntity, int offset);
class CBasePlayer;
enum InvalidatePhysicsBits_t
{
POSITION_CHANGED = 0x1,
ANGLES_CHANGED = 0x2,
VELOCITY_CHANGED = 0x4,
ANIMATION_CHANGED = 0x8,
};
float k_flMaxEntityEulerAngle = 360.0 * 1000.0f;
inline bool IsEntityQAngleReasonable( const QAngle &q )
{
float r = k_flMaxEntityEulerAngle;
return
q.x > -r && q.x < r &&
q.y > -r && q.y < r &&
q.z > -r && q.z < r;
}
float UTIL_VecToYaw( const Vector &vec )
{
if (vec.y == 0 && vec.x == 0)
return 0;
float yaw = atan2( vec.y, vec.x );
yaw = RAD2DEG(yaw);
if (yaw < 0)
yaw += 360;
return yaw;
}
float UTIL_VecToPitch( const Vector &vec )
{
if (vec.y == 0 && vec.x == 0)
{
if (vec.z < 0)
return 180.0;
else
return -180.0;
}
float dist = vec.Length2D();
float pitch = atan2( -vec.z, dist );
pitch = RAD2DEG(pitch);
return pitch;
}
int m_lifeStateOffset = -1;
int m_pPhysicsObjectOffset = -1;
int CBaseEntityPostConstructor = -1;
int CBaseEntityPhysicsSolidMaskForEntity = -1;
int CBaseEntityTouch = -1;
int CBaseEntityIsCombatItem = -1;
class CBaseEntity : public IServerEntity
{
public:
DECLARE_CLASS_NOBASE( CBaseEntity );
DECLARE_SERVERCLASS();
DECLARE_DATADESC();
void PostConstructor(const char *classname)
{
call_vfunc<void, CBaseEntity, const char *>(this, CBaseEntityPostConstructor, classname);
}
int entindex()
{
return gamehelpers->EntityToBCompatRef(this);
}
INextBot *MyNextBotPointer()
{
return call_vfunc<INextBot *>(this, CBaseEntityMyNextBotPointer);
}
CBaseCombatCharacter *MyCombatCharacterPointer()
{
return call_vfunc<CBaseCombatCharacter *>(this, CBaseEntityMyCombatCharacterPointer);
}
CBaseAnimating *GetBaseAnimating()
{
return call_vfunc<CBaseAnimating *>(this, CBaseEntityGetBaseAnimating);
}
Class_T Classify()
{
return call_vfunc<Class_T>(this, CBaseEntityClassify);
}
#if SOURCE_ENGINE == SE_TF2
bool IsBaseObject()
{
return call_vfunc<bool>(this, CBaseEntityIsBaseObject);
}
#endif
bool IsNPC()
{
return call_vfunc<bool>(this, CBaseEntityIsNPC);
}
Vector EyePosition()
{
return call_vfunc<Vector>(this, CBaseEntityEyePosition);
}
const Vector& GetViewOffset( void )
{
if(m_vecViewOffsetOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_vecViewOffset", &info);
m_vecViewOffsetOffset = info.actual_offset;
}
return *(Vector *)((unsigned char *)this + m_vecViewOffsetOffset);
}
Vector EyePosition_nonvirtual( void )
{
return GetAbsOrigin() + GetViewOffset();
}
CBasePlayer *GetPlayer()
{
int idx = gamehelpers->EntityToBCompatRef(this);
if(idx >= 1 && idx <= playerhelpers->GetMaxClients()) {
return (CBasePlayer *)this;
} else {
return nullptr;
}
}
bool IsPlayer()
{
int idx = gamehelpers->EntityToBCompatRef(this);
if(idx >= 1 && idx <= playerhelpers->GetMaxClients()) {
return true;
} else {
return false;
}
}
#if SOURCE_ENGINE == SE_LEFT4DEAD2
CBaseCombatCharacter *MyInfectedPointer()
{
return call_vfunc<CBaseCombatCharacter *>(this, CBaseEntityMyInfectedPointer);
}
#endif
const Vector &GetAbsOrigin()
{
if(m_vecAbsOriginOffset == -1) {
datamap_t *map = gamehelpers->GetDataMap(this);
sm_datatable_info_t info{};
gamehelpers->FindDataMapInfo(map, "m_vecAbsOrigin", &info);
m_vecAbsOriginOffset = info.actual_offset;
}
if(GetIEFlags() & EFL_DIRTY_ABSTRANSFORM) {
CalcAbsolutePosition();
}
return *(Vector *)(((unsigned char *)this) + m_vecAbsOriginOffset);
}
matrix3x4_t &EntityToWorldTransform()
{
if(m_rgflCoordinateFrameOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_rgflCoordinateFrame", &info);
m_rgflCoordinateFrameOffset = info.actual_offset;
}
if(GetIEFlags() & EFL_DIRTY_ABSTRANSFORM) {
CalcAbsolutePosition();
}
return *(matrix3x4_t *)((unsigned char *)this + m_rgflCoordinateFrameOffset);
}
void CalcAbsolutePosition()
{
call_mfunc<void, CBaseEntity>(this, CBaseEntityCalcAbsolutePosition);
}
int GetTeamNumber()
{
return *(int *)(((unsigned char *)this) + m_iTeamNumOffset);
}
const Vector &WorldSpaceCenter( ) const
{
return call_vfunc<const Vector &>(this, CBaseEntityWorldSpaceCenter);
}
const QAngle &EyeAngles( void )
{
return call_vfunc<const QAngle &>(this, CBaseEntityEyeAngles);
}
void SetAbsOrigin( const Vector& origin )
{
call_mfunc<void, CBaseEntity, const Vector &>(this, CBaseEntitySetAbsOrigin, origin);
}
void SetSimulationTime(float time)
{
if(m_flSimulationTimeOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_flSimulationTime", &info);
m_flSimulationTimeOffset = info.actual_offset;
}
*(float *)((unsigned char *)this + m_flSimulationTimeOffset) = time;
SetEdictStateChanged(this, m_flSimulationTimeOffset);
}
const QAngle& GetAbsAngles( void )
{
if(m_angAbsRotationOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_angAbsRotation", &info);
m_angAbsRotationOffset = info.actual_offset;
}
if (GetIEFlags() & EFL_DIRTY_ABSTRANSFORM)
{
CalcAbsolutePosition();
}
return *(QAngle *)((unsigned char *)this + m_angAbsRotationOffset);
}
const QAngle& GetLocalAngles( void )
{
if(m_angRotationOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_angRotation", &info);
m_angRotationOffset = info.actual_offset;
}
return *(QAngle *)((unsigned char *)this + m_angRotationOffset);
}
void SetLocalAngles( const QAngle& angles )
{
if(m_angRotationOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_angRotation", &info);
m_angRotationOffset = info.actual_offset;
}
// NOTE: The angle normalize is a little expensive, but we can save
// a bunch of time in interpolation if we don't have to invalidate everything
// and sometimes it's off by a normalization amount
// FIXME: The normalize caused problems in server code like momentary_rot_button that isn't
// handling things like +/-180 degrees properly. This should be revisited.
//QAngle angleNormalize( AngleNormalize( angles.x ), AngleNormalize( angles.y ), AngleNormalize( angles.z ) );
// Safety check against NaN's or really huge numbers
if ( !IsEntityQAngleReasonable( angles ) )
{
return;
}
if (*(QAngle *)((unsigned char *)this + m_angRotationOffset) != angles)
{
InvalidatePhysicsRecursive( ANGLES_CHANGED );
*(QAngle *)((unsigned char *)this + m_angRotationOffset) = angles;
SetEdictStateChanged(this, m_angRotationOffset);
SetSimulationTime( gpGlobals->curtime );
}
}
void SetAbsAngles( const QAngle& absAngles )
{
if(m_angAbsRotationOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_angAbsRotation", &info);
m_angAbsRotationOffset = info.actual_offset;
}
if(m_angRotationOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_angRotation", &info);
m_angRotationOffset = info.actual_offset;
}
if(m_rgflCoordinateFrameOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_rgflCoordinateFrame", &info);
m_rgflCoordinateFrameOffset = info.actual_offset;
}
if(m_vecAbsOriginOffset == -1) {
datamap_t *map = gamehelpers->GetDataMap(this);
sm_datatable_info_t info{};
gamehelpers->FindDataMapInfo(map, "m_vecAbsOrigin", &info);
m_vecAbsOriginOffset = info.actual_offset;
}
// This is necessary to get the other fields of m_rgflCoordinateFrame ok
CalcAbsolutePosition();
// FIXME: The normalize caused problems in server code like momentary_rot_button that isn't
// handling things like +/-180 degrees properly. This should be revisited.
//QAngle angleNormalize( AngleNormalize( absAngles.x ), AngleNormalize( absAngles.y ), AngleNormalize( absAngles.z ) );
if ( *(QAngle *)((unsigned char *)this + m_angAbsRotationOffset) == absAngles )
return;
// All children are invalid, but we are not
InvalidatePhysicsRecursive( ANGLES_CHANGED );
RemoveIEFlags( EFL_DIRTY_ABSTRANSFORM );
*(QAngle *)((unsigned char *)this + m_angAbsRotationOffset) = absAngles;
SetEdictStateChanged(this, m_angAbsRotationOffset);
AngleMatrix( absAngles, *(matrix3x4_t *)((unsigned char *)this + m_rgflCoordinateFrameOffset) );
MatrixSetColumn( *(Vector *)((unsigned char *)this + m_vecAbsOriginOffset), 3, *(matrix3x4_t *)((unsigned char *)this + m_rgflCoordinateFrameOffset) );
QAngle angNewRotation;
CBaseEntity *pMoveParent = GetMoveParent();
if (!pMoveParent)
{
angNewRotation = absAngles;
}
else
{
if ( *(QAngle *)((unsigned char *)this + m_angAbsRotationOffset) == pMoveParent->GetAbsAngles() )
{
angNewRotation.Init( );
}
else
{
// Moveparent case: transform the abs transform into local space
matrix3x4_t worldToParent, localMatrix;
MatrixInvert( pMoveParent->EntityToWorldTransform(), worldToParent );
ConcatTransforms( worldToParent, *(matrix3x4_t *)((unsigned char *)this + m_rgflCoordinateFrameOffset), localMatrix );
MatrixAngles( localMatrix, angNewRotation );
}
}
if (*(QAngle *)((unsigned char *)this + m_angRotationOffset) != angNewRotation)
{
*(QAngle *)((unsigned char *)this + m_angRotationOffset) = angNewRotation;
SetEdictStateChanged(this, m_angRotationOffset);
SetSimulationTime( gpGlobals->curtime );
}
}
int GetIEFlags()
{
if(m_iEFlagsOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_iEFlags", &info);
m_iEFlagsOffset = info.actual_offset;
}
return *(int *)((unsigned char *)this + m_iEFlagsOffset);
}
void DispatchUpdateTransmitState()
{
}
bool ClassMatches( const char *pszClassOrWildcard )
{
if(m_iClassnameOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_iClassname", &info);
m_iClassnameOffset = info.actual_offset;
}
if ( IDENT_STRINGS( *(string_t *)((unsigned char *)this + m_iClassnameOffset), pszClassOrWildcard ) )
return true;
return false;
}
bool ClassMatches( string_t nameStr )
{
if(m_iClassnameOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_iClassname", &info);
m_iClassnameOffset = info.actual_offset;
}
if ( IDENT_STRINGS( *(string_t *)((unsigned char *)this + m_iClassnameOffset), nameStr ) )
return true;
return false;
}
const char* GetClassname()
{
if(m_iClassnameOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_iClassname", &info);
m_iClassnameOffset = info.actual_offset;
}
return STRING( *(string_t *)((unsigned char *)this + m_iClassnameOffset) );
}
void AddIEFlags(int flags)
{
if(m_iEFlagsOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_iEFlags", &info);
m_iEFlagsOffset = info.actual_offset;
}
*(int *)((unsigned char *)this + m_iEFlagsOffset) |= flags;
if ( flags & ( EFL_FORCE_CHECK_TRANSMIT | EFL_IN_SKYBOX ) )
{
DispatchUpdateTransmitState();
}
}
void RemoveIEFlags(int flags)
{
if(m_iEFlagsOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_iEFlags", &info);
m_iEFlagsOffset = info.actual_offset;
}
*(int *)((unsigned char *)this + m_iEFlagsOffset) &= ~flags;
if ( flags & ( EFL_FORCE_CHECK_TRANSMIT | EFL_IN_SKYBOX ) )
{
DispatchUpdateTransmitState();
}
}
void SetMoveType(MoveType_t val)
{
if(m_MoveTypeOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_MoveType", &info);
m_MoveTypeOffset = info.actual_offset;
}
*(unsigned char *)((unsigned char *)this + m_MoveTypeOffset) = val;
}
int GetMoveType()
{
if(m_MoveTypeOffset == -1) {
datamap_t *map = gamehelpers->GetDataMap(this);
sm_datatable_info_t info{};
gamehelpers->FindDataMapInfo(map, "m_MoveType", &info);
m_MoveTypeOffset = info.actual_offset;
}
return *(unsigned char *)(((unsigned char *)this) + m_MoveTypeOffset);
}
int GetFlags()
{
if(m_fFlagsOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_fFlags", &info);
m_fFlagsOffset = info.actual_offset;
}
return *(int *)((unsigned char *)this + m_fFlagsOffset);
}