/
extension.cpp
5448 lines (4376 loc) · 150 KB
/
extension.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
/**
* 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
#if SOURCE_ENGINE == SE_TF2
#define TF_DLL
#define USES_ECON_ITEMS
#elif SOURCE_ENGINE == SE_LEFT4DEAD2
#define TERROR
#define LEFT4DEAD
#endif
#if SOURCE_ENGINE == SE_LEFT4DEAD2
#define PREDICTIONCOPY_H
#endif
#define BASEENTITY_H
#define BASEENTITY_SHARED_H
#define NEXT_BOT
#define GLOWS_ENABLE
#define USE_NAV_MESH
#define RAD_TELEMETRY_DISABLED
#define CBASE_H
#include "extension.h"
#include <CDetour/detours.h>
class IEngineTrace *enginetrace = nullptr;
class IStaticPropMgrServer *staticpropmgr = nullptr;
#include <public/const.h>
#include <public/dt_send.h>
#include <public/networkvar.h>
#include <shared/shareddefs.h>
#include <shared/util_shared.h>
#include <datacache/imdlcache.h>
#include <materialsystem/imaterial.h>
#include <materialsystem/imaterialsystem.h>
#include <bspfile.h>
#include <vphysics_interface.h>
#include <unordered_map>
#include <vector>
#include <string>
#include <functional>
#include <IForwardSys.h>
using namespace std::literals::string_literals;
int *g_nActivityListVersion = nullptr;
int *g_nEventListVersion = nullptr;
class IFileSystem;
IVModelInfo *modelinfo = nullptr;
IMDLCache *mdlcache = nullptr;
IFileSystem *filesystem = nullptr;
IMaterialSystem *materials = nullptr;
ISpatialPartition *partition{nullptr};
IPhysicsCollision *physcollision{nullptr};
#ifdef __HAS_PROXYSEND
class proxysend *proxysend = nullptr;
#endif
/**
* @file extension.cpp
* @brief Implement extension code here.
*/
Sample g_Sample; /**< Global singleton for extension's main interface */
SMEXT_LINK(&g_Sample);
CGlobalVars *gpGlobals = nullptr;
int m_pStudioHdrOffset = -1;
int m_nSequenceOffset = -1;
int m_flPoseParameterOffset = -1;
int m_AnimOverlayOffset = -1;
int m_nBodyOffset = -1;
int m_flEncodedControllerOffset = -1;
int m_flexWeightOffset = -1;
int m_rgflCoordinateFrameOffset = -1;
int m_iEFlagsOffset = -1;
int m_flPlaybackRateOffset = -1;
int m_flCycleOffset = -1;
int m_vecOriginOffset = -1;
int m_vecAbsOriginOffset = -1;
int m_angRotationOffset = -1;
int m_hMoveParentOffset = -1;
int touchStampOffset = -1;
int m_fDataObjectTypesOffset = -1;
int m_hMoveChildOffset = -1;
int m_hMovePeerOffset = -1;
int m_bSequenceLoopsOffset = -1;
int m_flAnimTimeOffset = -1;
int m_flPrevAnimTimeOffset = -1;
int CBaseAnimatingStudioFrameAdvance = -1;
int CBaseAnimatingDispatchAnimEvents = -1;
int CBaseAnimatingGetAttachment = -1;
int CBaseAnimatingGetBoneTransform = -1;
int CBaseEntityWorldSpaceCenter = -1;
int CBaseEntityEyePosition = -1;
int CBaseAnimatingHandleAnimEvent = -1;
void *CBaseAnimatingResetSequenceInfo = nullptr;
void *CBaseAnimatingLockStudioHdr = nullptr;
void *CBaseEntitySetAbsOrigin = nullptr;
void *CBaseEntityCalcAbsolutePosition = nullptr;
void *ActivityList_NameForIndexPtr = nullptr;
void *ActivityList_IndexForNamePtr = nullptr;
void *ActivityList_RegisterPrivateActivityPtr = nullptr;
void *EventList_NameForIndexPtr = nullptr;
void *EventList_IndexForNamePtr = nullptr;
void *EventList_RegisterPrivateEventPtr = nullptr;
void *EventList_GetEventTypePtr = nullptr;
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_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 T>
T void_to_func(void *ptr)
{
union { T f; void *p; };
p = ptr;
return f;
}
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);
}
}
class CStudioHdr;
enum TOGGLE_STATE : int;
struct AI_CriteriaSet;
#include <shared/shareddefs.h>
#define DECLARE_PREDICTABLE()
#ifndef FMTFUNCTION
#define FMTFUNCTION(...)
#endif
#include <collisionproperty.h>
#include <ehandle.h>
#include <shared/predictioncopy.h>
#include <util.h>
#include <ServerNetworkProperty.h>
#include <vcollide_parse.h>
CBaseEntityList *g_pEntityList = nullptr;
void *CBaseEntityCollisionRulesChanged{nullptr};
void *EntityTouch_AddPtr{nullptr};
void EntityTouch_Add( CBaseEntity *pEntity )
{
(void_to_func<void (*)(CBaseEntity *)>(EntityTouch_AddPtr))(pEntity);
}
class CBaseEntity : public IServerEntity
{
public:
int entindex()
{
return gamehelpers->EntityToBCompatRef(this);
}
model_t *GetModel( void )
{
return (model_t *)modelinfo->GetModel( GetModelIndex() );
}
void SetAbsOrigin( const Vector& origin )
{
call_mfunc<void, CBaseEntity, const Vector &>(this, CBaseEntitySetAbsOrigin, origin);
}
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);
}
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);
}
const Vector &GetLocalOrigin()
{
if(m_vecOriginOffset == -1) {
datamap_t *map = gamehelpers->GetDataMap(this);
sm_datatable_info_t info{};
gamehelpers->FindDataMapInfo(map, "m_vecOrigin", &info);
m_vecOriginOffset = info.actual_offset;
}
return *(Vector *)(((unsigned char *)this) + m_vecOriginOffset);
}
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);
}
const QAngle &GetLocalAngles()
{
if(m_angRotationOffset == -1) {
datamap_t *map = gamehelpers->GetDataMap(this);
sm_datatable_info_t info{};
gamehelpers->FindDataMapInfo(map, "m_angRotation", &info);
m_angRotationOffset = info.actual_offset;
}
return *(QAngle *)(((unsigned char *)this) + m_angRotationOffset);
}
void CalcAbsolutePosition()
{
call_mfunc<void, CBaseEntity>(this, CBaseEntityCalcAbsolutePosition);
}
const Vector &WorldSpaceCenter()
{
return call_vfunc<const Vector &>(this, CBaseEntityWorldSpaceCenter);
}
Vector EyePosition()
{
return call_vfunc<Vector>(this, CBaseEntityEyePosition);
}
inline edict_t *edict( void ) { return NetworkProp()->edict(); }
inline const edict_t *edict( void ) const { return NetworkProp()->edict(); }
CServerNetworkProperty *NetworkProp() { return (CServerNetworkProperty *)GetNetworkable(); }
const CServerNetworkProperty *NetworkProp() const { return (const CServerNetworkProperty *)const_cast<CBaseEntity *>(this)->GetNetworkable(); }
CCollisionProperty *CollisionProp() { return (CCollisionProperty *)GetCollideable(); }
const CCollisionProperty*CollisionProp() const { return (const CCollisionProperty*)const_cast<CBaseEntity *>(this)->GetCollideable(); }
CBaseEntity *GetRootMoveParent()
{
CBaseEntity *pEntity = this;
CBaseEntity *pParent = this->GetMoveParent();
while ( pParent )
{
pEntity = pParent;
pParent = pEntity->GetMoveParent();
}
return pEntity;
}
CBaseEntity *FirstMoveChild()
{
if(m_hMoveChildOffset == -1) {
datamap_t *map = gamehelpers->GetDataMap(this);
sm_datatable_info_t info{};
gamehelpers->FindDataMapInfo(map, "m_hMoveChild", &info);
m_hMoveChildOffset = info.actual_offset;
}
return (*(EHANDLE *)(((unsigned char *)this) + m_hMoveChildOffset)).Get();
}
CBaseEntity *NextMovePeer()
{
if(m_hMovePeerOffset == -1) {
datamap_t *map = gamehelpers->GetDataMap(this);
sm_datatable_info_t info{};
gamehelpers->FindDataMapInfo(map, "m_hMovePeer", &info);
m_hMovePeerOffset = info.actual_offset;
}
return (*(EHANDLE *)(((unsigned char *)this) + m_hMovePeerOffset)).Get();
}
CBaseEntity *GetMoveParent()
{
if(m_hMoveParentOffset == -1) {
datamap_t *map = gamehelpers->GetDataMap(this);
sm_datatable_info_t info{};
gamehelpers->FindDataMapInfo(map, "m_hMoveParent", &info);
m_hMoveParentOffset = info.actual_offset;
}
return (*(EHANDLE *)(((unsigned char *)this) + m_hMoveParentOffset)).Get();
}
SolidType_t GetSolid() const
{
return CollisionProp()->GetSolid();
}
void AddSolidFlags( int flags )
{
CollisionProp()->AddSolidFlags( flags );
}
void RemoveSolidFlags( int flags )
{
CollisionProp()->RemoveSolidFlags( flags );
}
bool HasDataObjectType( int type ) const
{
return ( *(int *)((unsigned char *)this + m_fDataObjectTypesOffset) & (1<<type) ) ? true : false;
}
bool IsCurrentlyTouching()
{
if ( HasDataObjectType( TOUCHLINK ) )
{
return true;
}
return false;
}
void SetCheckUntouch( bool check )
{
if(touchStampOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "touchStamp", &info);
touchStampOffset = info.actual_offset;
}
// Invalidate touchstamp
if ( check )
{
*(int *)((unsigned char *)this + touchStampOffset) += 1;
if ( !(GetIEFlags() & EFL_CHECK_UNTOUCH) )
{
AddIEFlags( EFL_CHECK_UNTOUCH );
EntityTouch_Add( this );
}
}
else
{
RemoveIEFlags( EFL_CHECK_UNTOUCH );
}
}
bool IsSolid()
{
return CollisionProp()->IsSolid( );
}
void SetSolid( SolidType_t val )
{
CollisionProp()->SetSolid( val );
}
void DispatchUpdateTransmitState()
{
}
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 CollisionRulesChanged()
{
call_mfunc<void, CBaseEntity>(this, CBaseEntityCollisionRulesChanged);
}
//GARBAGE!!!
bool KeyValue( const char *szKeyName, Vector vec ) { return false; }
bool KeyValue( const char *szKeyName, float flValue ) { return false; }
static void *GetPredictionPlayer() { return nullptr; }
};
static void GetAllChildren_r( CBaseEntity *pEntity, CUtlVector<CBaseEntity *> &list )
{
for ( ; pEntity != NULL; pEntity = pEntity->NextMovePeer() )
{
list.AddToTail( pEntity );
GetAllChildren_r( pEntity->FirstMoveChild(), list );
}
}
int GetAllChildren( CBaseEntity *pParent, CUtlVector<CBaseEntity *> &list )
{
if ( !pParent )
return 0;
GetAllChildren_r( pParent->FirstMoveChild(), list );
return list.Count();
}
void CCollisionProperty::MarkSurroundingBoundsDirty()
{
GetOuter()->AddIEFlags( EFL_DIRTY_SURROUNDING_COLLISION_BOUNDS );
MarkPartitionHandleDirty();
#ifdef CLIENT_DLL
g_pClientShadowMgr->MarkRenderToTextureShadowDirty( GetOuter()->GetShadowHandle() );
#else
GetOuter()->NetworkProp()->MarkPVSInformationDirty();
#endif
}
void CCollisionProperty::MarkPartitionHandleDirty()
{
// don't bother with the world
if ( m_pOuter->entindex() == 0 )
return;
if ( !(m_pOuter->GetIEFlags() & EFL_DIRTY_SPATIAL_PARTITION) )
{
m_pOuter->AddIEFlags( EFL_DIRTY_SPATIAL_PARTITION );
//s_DirtyKDTree.AddEntity( m_pOuter );
}
#ifdef CLIENT_DLL
GetOuter()->MarkRenderHandleDirty();
g_pClientShadowMgr->AddToDirtyShadowList( GetOuter() );
#endif
}
void CCollisionProperty::UpdateServerPartitionMask( )
{
#ifndef CLIENT_DLL
SpatialPartitionHandle_t handle = GetPartitionHandle();
if ( handle == PARTITION_INVALID_HANDLE )
return;
// Remove it from whatever lists it may be in at the moment
// We'll re-add it below if we need to.
::partition->Remove( handle );
// Don't bother with deleted things
if ( !m_pOuter->edict() )
return;
// don't add the world
if ( m_pOuter->entindex() == 0 )
return;
// Make sure it's in the list of all entities
bool bIsSolid = IsSolid() || IsSolidFlagSet(FSOLID_TRIGGER);
if ( bIsSolid || m_pOuter->GetIEFlags() & EFL_USE_PARTITION_WHEN_NOT_SOLID )
{
::partition->Insert( PARTITION_ENGINE_NON_STATIC_EDICTS, handle );
}
if ( !bIsSolid )
return;
// Insert it into the appropriate lists.
// We have to continually reinsert it because its solid type may have changed
SpatialPartitionListMask_t mask = 0;
if ( !IsSolidFlagSet(FSOLID_NOT_SOLID) )
{
mask |= PARTITION_ENGINE_SOLID_EDICTS;
}
if ( IsSolidFlagSet(FSOLID_TRIGGER) )
{
mask |= PARTITION_ENGINE_TRIGGER_EDICTS;
}
Assert( mask != 0 );
::partition->Insert( mask, handle );
#endif
}
void CCollisionProperty::CheckForUntouch()
{
#ifndef CLIENT_DLL
if ( !IsSolid() && !IsSolidFlagSet(FSOLID_TRIGGER))
{
// If this ent's touch list isn't empty, it's transitioning to not solid
if ( m_pOuter->IsCurrentlyTouching() )
{
// mark ent so that at the end of frame it will check to
// see if it's no longer touching ents
m_pOuter->SetCheckUntouch( true );
}
}
#endif
}
void CCollisionProperty::SetSolidFlags( int flags )
{
int oldFlags = m_usSolidFlags;
m_usSolidFlags = (unsigned short)(flags & 0xFFFF);
if ( oldFlags == m_usSolidFlags )
return;
// These two flags, if changed, can produce different surrounding bounds
if ( (oldFlags & (FSOLID_FORCE_WORLD_ALIGNED | FSOLID_USE_TRIGGER_BOUNDS)) !=
(m_usSolidFlags & (FSOLID_FORCE_WORLD_ALIGNED | FSOLID_USE_TRIGGER_BOUNDS)) )
{
MarkSurroundingBoundsDirty();
}
if ( (oldFlags & (FSOLID_NOT_SOLID|FSOLID_TRIGGER)) != (m_usSolidFlags & (FSOLID_NOT_SOLID|FSOLID_TRIGGER)) )
{
m_pOuter->CollisionRulesChanged();
}
#ifndef CLIENT_DLL
if ( (oldFlags & (FSOLID_NOT_SOLID | FSOLID_TRIGGER)) != (m_usSolidFlags & (FSOLID_NOT_SOLID | FSOLID_TRIGGER)) )
{
UpdateServerPartitionMask( );
CheckForUntouch();
}
#endif
}
void CCollisionProperty::SetSolid( SolidType_t val )
{
if ( m_nSolidType == val )
return;
#ifndef CLIENT_DLL
bool bWasNotSolid = IsSolid();
#endif
MarkSurroundingBoundsDirty();
// OBB is not yet implemented
if ( val == SOLID_BSP )
{
if ( GetOuter()->GetMoveParent() )
{
if ( GetOuter()->GetRootMoveParent()->GetSolid() != SOLID_BSP )
{
// must be SOLID_VPHYSICS because parent might rotate
val = SOLID_VPHYSICS;
}
}
#ifndef CLIENT_DLL
// UNDONE: This should be fine in the client DLL too. Move GetAllChildren() into shared code.
// If the root of the hierarchy is SOLID_BSP, then assume that the designer
// wants the collisions to rotate with this hierarchy so that the player can
// move while riding the hierarchy.
if ( !GetOuter()->GetMoveParent() )
{
// NOTE: This assumes things don't change back from SOLID_BSP
// NOTE: This is 100% true for HL2 - need to support removing the flag to support changing from SOLID_BSP
CUtlVector<CBaseEntity *> list;
GetAllChildren( GetOuter(), list );
for ( int i = list.Count()-1; i>=0; --i )
{
list[i]->AddSolidFlags( FSOLID_ROOT_PARENT_ALIGNED );
}
}
#endif
}
m_nSolidType = val;
#ifndef CLIENT_DLL
m_pOuter->CollisionRulesChanged();
UpdateServerPartitionMask( );
if ( bWasNotSolid != IsSolid() )
{
CheckForUntouch();
}
#endif
}
#if SOURCE_ENGINE == SE_LEFT4DEAD2
enum
{
kActivityLookup_Unknown = -2, // hasn't been searched for
kActivityLookup_Missing = -1, // has been searched for but wasn't found
};
#endif
#include <mathlib/vmatrix.h>
#include <ehandle.h>
#include <predictioncopy.h>
#include <shared/ai_activity.h>
#include <activitylist.h>
#include <eventlist.h>
#include <studio.h>
#include <engine/ivmodelinfo.h>
#include <filesystem.h>
#include "stringregistry.h"
#include "isaverestore.h"
#include <KeyValues.h>
#include "utldict.h"
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define typeof __typeof__
#if SOURCE_ENGINE == SE_LEFT4DEAD2
#undef stackalloc
#define stackalloc( _size ) alloca( ALIGN_VALUE( _size, 16 ) )
#endif
#ifndef FMTFUNCTION
#define FMTFUNCTION(...)
#endif
#include <animation.cpp>
#include <studio.cpp>
#include <studio_shared.cpp>
#include <bone_setup.cpp>
#include <stringregistry.cpp>
#define ListFromString ListFromStringEvent
//#include <eventlist.cpp>
#undef ListFromString
#define ListFromString ListFromStringActivity
//#include "activitylist.cpp"
#undef ListFromString
#include <collisionutils.cpp>
Activity ActivityList_RegisterPrivateActivity( const char *pszActivityName )
{
return ((Activity(*)(const char *))ActivityList_RegisterPrivateActivityPtr)(pszActivityName);
}
int ActivityList_IndexForName( const char *pszActivityName )
{
return ((int(*)(const char *))ActivityList_IndexForNamePtr)(pszActivityName);
}
const char *ActivityList_NameForIndex( int iActivityIndex )
{
return ((const char *(*)(int))ActivityList_NameForIndexPtr)(iActivityIndex);
}
Animevent EventList_RegisterPrivateEvent( const char *pszEventName )
{
return ((Animevent(*)(const char *))EventList_RegisterPrivateEventPtr)(pszEventName);
}
int EventList_IndexForName( const char *pszEventName )
{
return ((int(*)(const char *))EventList_IndexForNamePtr)(pszEventName);
}
const char *EventList_NameForIndex( int iEventIndex )
{
return ((const char *(*)(int))EventList_NameForIndexPtr)(iEventIndex);
}
int EventList_GetEventType( int eventIndex )
{
return ((int(*)(int))EventList_GetEventTypePtr)(eventIndex);
}
int SharedRandomInt( const char *sharedname, int iMinVal, int iMaxVal, int additionalSeed /*=0*/ )
{
return RandomInt( iMinVal, iMaxVal );
}
void SetEdictStateChanged(CBaseEntity *pEntity, int offset)
{
IServerNetworkable *pNet = pEntity->GetNetworkable();
edict_t *edict = pNet->GetEdict();
gamehelpers->SetEdictStateChanged(edict, offset);
}
class CBaseAnimating : public CBaseEntity
{
public:
CStudioHdr *GetModelPtr()
{
CStudioHdr *m_pStudioHdr = *(CStudioHdr **)((unsigned char *)this + m_pStudioHdrOffset);
if ( !m_pStudioHdr && GetModel() )
{
call_mfunc<void>(this, CBaseAnimatingLockStudioHdr);
m_pStudioHdr = *(CStudioHdr **)((unsigned char *)this + m_pStudioHdrOffset);
}
return ( m_pStudioHdr && m_pStudioHdr->IsValid() ) ? m_pStudioHdr : nullptr;
}
int GetSequence()
{
return *(int *)((unsigned char *)this + m_nSequenceOffset);
}
float GetPlaybackRate()
{
return *(float *)((unsigned char *)this + m_flPlaybackRateOffset);
}
float GetCycle()
{
return *(float *)((unsigned char *)this + m_flCycleOffset);
}
float GetAnimTime()
{
return *(int *)((unsigned char *)this + m_flAnimTimeOffset);
}
float GetPrevAnimTime()
{
if(m_flPrevAnimTimeOffset == -1) {
datamap_t *map = gamehelpers->GetDataMap(this);
sm_datatable_info_t info{};
gamehelpers->FindDataMapInfo(map, "m_flPrevAnimTime", &info);
m_flPrevAnimTimeOffset = info.actual_offset;
}
return *(float *)(((unsigned char *)this) + m_flPrevAnimTimeOffset);
}
float *GetPoseParameterArray()
{
return &*(float *)((unsigned char *)this + m_flPoseParameterOffset);
}
float *GetEncodedControllerArray()
{
return &*(float *)((unsigned char *)this + m_flEncodedControllerOffset);
}
bool SequenceLoops()
{
if(m_bSequenceLoopsOffset == -1) {
datamap_t *map = gamehelpers->GetDataMap(this);
sm_datatable_info_t info{};
gamehelpers->FindDataMapInfo(map, "m_bSequenceLoops", &info);
m_bSequenceLoopsOffset = info.actual_offset;
}
return *(bool *)(((unsigned char *)this) + m_bSequenceLoopsOffset);
}
void StudioFrameAdvance()
{
call_vfunc<void>(this, CBaseAnimatingStudioFrameAdvance);
}
void DispatchAnimEvents()
{
call_vfunc<void, CBaseAnimating, CBaseAnimating *>(this, CBaseAnimatingDispatchAnimEvents, this);
}
int FindBodygroupByName( const char *name );
bool GetAttachment( int iAttachment, matrix3x4_t &attachmentToWorld )
{
return call_vfunc<bool, CBaseAnimating, int, matrix3x4_t &>(this, CBaseAnimatingGetAttachment, iAttachment, attachmentToWorld);
}
void GetBoneTransform( int iAttachment, matrix3x4_t &attachmentToWorld )
{
call_vfunc<void, CBaseAnimating, int, matrix3x4_t &>(this, CBaseAnimatingGetBoneTransform, iAttachment, attachmentToWorld);
}
void ResetSequenceInfo()
{
call_mfunc<void>(this, CBaseAnimatingResetSequenceInfo);
}
int GetBody()
{
return *(int *)((unsigned char *)this + m_nBodyOffset);
}
void SetBody(int value)
{
*(int *)((unsigned char *)this + m_nBodyOffset) = value;
SetEdictStateChanged(this, m_nBodyOffset);
}
bool GetAttachment( const char *szName, Vector &absOrigin, QAngle &absAngles )
{
return GetAttachment( LookupAttachment( szName ), absOrigin, absAngles );
}
bool GetAttachment( int iAttachment, Vector &absOrigin, QAngle &absAngles )
{
matrix3x4_t attachmentToWorld;
bool bRet = GetAttachment( iAttachment, attachmentToWorld );
MatrixAngles( attachmentToWorld, absAngles, absOrigin );
return bRet;
}
bool GetAttachmentLocal( const char *szName, Vector &origin, QAngle &angles );
bool GetAttachmentLocal( int iAttachment, Vector &origin, QAngle &angles );
bool GetAttachmentLocal( int iAttachment, matrix3x4_t &attachmentToLocal );
bool GetBonePositionLocal( const char *szName, Vector &origin, QAngle &angles );
bool GetBonePositionLocal( int iAttachment, Vector &origin, QAngle &angles );
bool GetBonePositionLocal( int iAttachment, matrix3x4_t &attachmentToLocal );
void SetBodygroup( int iGroup, int iValue );
bool GetBonePosition ( int iBone, Vector &origin, QAngle &angles );
int LookupBone( const char *szName );
int LookupAttachment( const char *szName );
int SelectWeightedSequence(int activity);
int SelectWeightedSequence(int activity, int sequence);
int LookupSequence(const char *name);
int LookupActivity(const char *name);
float GetPoseParameter(int index);
void SetPoseParameter(int index, float value);
int LookupPoseParameter(const char *name);
float SequenceDuration(int sequence);
float SequenceDuration( CStudioHdr *pStudioHdr, int sequence);
int GetSequenceFlags(int sequence);
int SequenceNumFrames(int sequence);
float SequenceFPS(int sequence);
float SequenceCPS(int sequence);
void SetBoneController ( int iController, float flValue );
float GetBoneController ( int iController );