-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathextension.cpp
More file actions
5818 lines (4742 loc) · 165 KB
/
extension.cpp
File metadata and controls
5818 lines (4742 loc) · 165 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$
*/
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <string>
#include <cstring>
#ifndef FMTFUNCTION
#define FMTFUNCTION(...)
#endif
#define TF_DLL
#define USES_ECON_ITEMS
#define BASEENTITY_H
#define NEXT_BOT
#define GLOWS_ENABLE
#define USE_NAV_MESH
#define RAD_TELEMETRY_DISABLED
#define protected public
#include <tier1/utlvector.h>
#undef protected
#include "extension.h"
#include <CDetour/detours.h>
#include <tier1/utlvector.h>
#include <ehandle.h>
#include <ICellArray.h>
using EHANDLE = CHandle<CBaseEntity>;
#include <takedamageinfo.h>
#include <toolframework/itoolentity.h>
typedef wchar_t locchar_t;
#include <tier1/utlmap.h>
#include <vstdlib/random.h>
#define TRACER_DONT_USE_ATTACHMENT -1
#include <util.h>
#include <shareddefs.h>
#include <ServerNetworkProperty.h>
#define DECLARE_PREDICTABLE()
#include <collisionproperty.h>
#include <tier1/fmtstr.h>
#include <filesystem.h>
/**
* @file extension.cpp
* @brief Implement extension code here.
*/
Sample g_Sample; /**< Global singleton for extension's main interface */
SMEXT_LINK(&g_Sample);
class CTFTeamSpawn;
typedef CUtlVector< CHandle< CBaseEntity > > EntityHandleVector_t;
typedef CUtlVector< CHandle< CTFTeamSpawn > > TFTeamSpawnVector_t;
void *AllocPooledStringPtr = nullptr;
void *IsSpaceToSpawnHerePtr = nullptr;
ICvar *icvar = nullptr;
CBaseEntityList *g_pEntityList = nullptr;
CGlobalVars *gpGlobals = nullptr;
IFileSystem *filesystem = nullptr;
IServerTools *servertools = nullptr;
IEntityFactoryDictionary *dictionary{nullptr};
size_t info_populator_size{-1};
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 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...);
}
template <typename T>
T void_to_func(void *ptr)
{
union { T f; void *p; };
p = ptr;
return f;
}
template <typename T>
int vfunc_index(T func)
{
SourceHook::MemFuncInfo info{};
SourceHook::GetFuncInfo<T>(func, info);
return info.vtblindex;
}
enum
{
TF_CLASS_UNDEFINED = 0,
TF_CLASS_SCOUT, // TF_FIRST_NORMAL_CLASS
TF_CLASS_SNIPER,
TF_CLASS_SOLDIER,
TF_CLASS_DEMOMAN,
TF_CLASS_MEDIC,
TF_CLASS_HEAVYWEAPONS,
TF_CLASS_PYRO,
TF_CLASS_SPY,
TF_CLASS_ENGINEER,
// Add any new classes after Engineer
TF_CLASS_CIVILIAN, // TF_LAST_NORMAL_CLASS
TF_CLASS_COUNT_ALL,
TF_CLASS_RANDOM
};
enum AttributeType
{
REMOVE_ON_DEATH = 1<<0, // kick bot from server when killed
AGGRESSIVE = 1<<1, // in MvM mode, push for the cap point
IS_NPC = 1<<2, // a non-player support character
SUPPRESS_FIRE = 1<<3,
DISABLE_DODGE = 1<<4,
BECOME_SPECTATOR_ON_DEATH = 1<<5, // move bot to spectator team when killed
QUOTA_MANANGED = 1<<6, // managed by the bot quota in CTFBotManager
RETAIN_BUILDINGS = 1<<7, // don't destroy this bot's buildings when it disconnects
SPAWN_WITH_FULL_CHARGE = 1<<8, // all weapons start with full charge (ie: uber)
ALWAYS_CRIT = 1<<9, // always fire critical hits
IGNORE_ENEMIES = 1<<10,
HOLD_FIRE_UNTIL_FULL_RELOAD = 1<<11, // don't fire our barrage weapon until it is full reloaded (rocket launcher, etc)
PRIORITIZE_DEFENSE = 1<<12, // bot prioritizes defending when possible
ALWAYS_FIRE_WEAPON = 1<<13, // constantly fire our weapon
TELEPORT_TO_HINT = 1<<14, // bot will teleport to hint target instead of walking out from the spawn point
MINIBOSS = 1<<15, // is miniboss?
USE_BOSS_HEALTH_BAR = 1<<16, // should I use boss health bar?
IGNORE_FLAG = 1<<17, // don't pick up flag/bomb
AUTO_JUMP = 1<<18, // auto jump
AIR_CHARGE_ONLY = 1<<19, // demo knight only charge in the air
PREFER_VACCINATOR_BULLETS = 1<<20, // When using the vaccinator, prefer to use the bullets shield
PREFER_VACCINATOR_BLAST = 1<<21, // When using the vaccinator, prefer to use the blast shield
PREFER_VACCINATOR_FIRE = 1<<22, // When using the vaccinator, prefer to use the fire shield
BULLET_IMMUNE = 1<<23, // Has a shield that makes the bot immune to bullets
BLAST_IMMUNE = 1<<24, // "" blast
FIRE_IMMUNE = 1<<25, // "" fire
PARACHUTE = 1<<26, // demo/soldier parachute when falling
PROJECTILE_SHIELD = 1<<27, // medic projectile shield
};
#define NUM_BOT_ATTRS 28
class CPopulationManager;
class IPopulationSpawner;
class CTFPlayer;
class CBaseCombatCharacter;
struct PlayerUpgradeHistory;
class IPopulator;
class CWave;
class CMannVsMachineStats;
class CWaveSpawnPopulator;
#define MAX_ATTRIBUTE_DESCRIPTION_LENGTH ( 256 / sizeof( locchar_t ) )
class CMvMBotUpgrade
{
public:
char szAttrib[ MAX_ATTRIBUTE_DESCRIPTION_LENGTH ]; // Debug
int iAttribIndex;
float flValue;
float flMax;
int nCost;
bool bIsBotAttr;
bool bIsSkillAttr; // Probably want to make these an enum or flag later
};
void *CPopulationManagerOnPlayerKilled = nullptr;
void **g_pPopulationManagerPtr{nullptr};
CBaseEntity *CreateEntityByName( const char *szName )
{
return servertools->CreateEntityByName(szName);
}
int DispatchSpawn( CBaseEntity *pEntity )
{
servertools->DispatchSpawn(pEntity);
return 0;
}
void RemoveEntity( CBaseEntity *pEntity )
{
servertools->RemoveEntity( pEntity );
}
int m_angRotationOffset = -1;
int m_iParentAttachmentOffset = -1;
int m_iEFlagsOffset = -1;
int m_flSimulationTimeOffset = -1;
int m_vecOriginOffset = -1;
int m_hMoveChildOffset = -1;
int m_hMoveParentOffset = -1;
int m_hMovePeerOffset = -1;
int CBaseEntitySetOwnerEntity = -1;
int CBaseEntityWorldSpaceCenter = -1;
int CBaseEntityAcceptInput = -1;
float k_flMaxEntityEulerAngle = 360.0 * 1000.0f;
float k_flMaxEntityPosCoord = MAX_COORD_FLOAT;
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;
}
inline bool IsEntityPositionReasonable( const Vector &v )
{
float r = k_flMaxEntityPosCoord;
return
v.x > -r && v.x < r &&
v.y > -r && v.y < r &&
v.z > -r && v.z < r;
}
enum InvalidatePhysicsBits_t
{
POSITION_CHANGED = 0x1,
ANGLES_CHANGED = 0x2,
VELOCITY_CHANGED = 0x4,
ANIMATION_CHANGED = 0x8,
};
void SetEdictStateChanged(CBaseEntity *pEntity, int offset);
class IEntityListener
{
public:
virtual void OnEntityCreated( CBaseEntity *pEntity ) {};
virtual void OnEntitySpawned( CBaseEntity *pEntity ) {};
virtual void OnEntityDeleted( CBaseEntity *pEntity ) {};
};
class CGlobalEntityList : public CBaseEntityList
{
public:
int m_iHighestEnt; // the topmost used array index
int m_iNumEnts;
int m_iNumEdicts;
bool m_bClearingEntities;
CUtlVector<IEntityListener *> m_entityListeners;
void NotifyCreateEntity( CBaseEntity *pEnt )
{
if ( !pEnt )
return;
//DevMsg(2,"Deleted %s\n", pBaseEnt->GetClassname() );
for ( int i = m_entityListeners.Count()-1; i >= 0; i-- )
{
m_entityListeners[i]->OnEntityCreated( pEnt );
}
}
};
int m_iNameOffset = -1;
void *CBaseEntitySetAbsOrigin = nullptr;
void *CBaseEntityCalcAbsolutePosition = nullptr;
int m_vecAbsOriginOffset = -1;
int m_iClassnameOffset = -1;
int m_iTeamNumOffset = -1;
class CBasePlayer;
struct variant_t
{
union
{
bool bVal;
string_t iszVal;
int iVal;
float flVal;
float vecVal[3];
color32 rgbaVal;
};
CHandle<CBaseEntity> eVal; // this can't be in the union because it has a constructor.
fieldtype_t fieldType;
void SetString( string_t str ) { iszVal = str, fieldType = FIELD_STRING; }
};
class CBaseEntity : public IServerEntity
{
public:
int entindex()
{
return gamehelpers->EntityToBCompatRef(this);
}
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;
}
}
int GetParentAttachment()
{
if(m_iParentAttachmentOffset == -1) {
datamap_t *map = gamehelpers->GetDataMap(this);
sm_datatable_info_t info{};
gamehelpers->FindDataMapInfo(map, "m_iParentAttachment", &info);
m_iParentAttachmentOffset = info.actual_offset;
}
return *(unsigned char *)(((unsigned char *)this) + m_iParentAttachmentOffset);
}
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 DispatchUpdateTransmitState()
{
}
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 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();
}
}
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 *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();
}
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();
}
CCollisionProperty *CollisionProp() { return (CCollisionProperty *)GetCollideable(); }
const CCollisionProperty*CollisionProp() const { return (const CCollisionProperty*)const_cast<CBaseEntity *>(this)->GetCollideable(); }
CServerNetworkProperty *NetworkProp() { return (CServerNetworkProperty *)GetNetworkable(); }
const CServerNetworkProperty *NetworkProp() const { return (const CServerNetworkProperty *)const_cast<CBaseEntity *>(this)->GetNetworkable(); }
void InvalidatePhysicsRecursive( int nChangeFlags )
{
// Main entry point for dirty flag setting for the 90% case
// 1) If the origin changes, then we have to update abstransform, Shadow projection, PVS, KD-tree,
// client-leaf system.
// 2) If the angles change, then we have to update abstransform, Shadow projection,
// shadow render-to-texture, client-leaf system, and surrounding bounds.
// Children have to additionally update absvelocity, KD-tree, and PVS.
// If the surrounding bounds actually update, when we also need to update the KD-tree and the PVS.
// 3) If it's due to attachment, then all children who are attached to an attachment point
// are assumed to have dirty origin + angles.
// Other stuff:
// 1) Marking the surrounding bounds dirty will automatically mark KD tree + PVS dirty.
int nDirtyFlags = 0;
if ( nChangeFlags & VELOCITY_CHANGED )
{
nDirtyFlags |= EFL_DIRTY_ABSVELOCITY;
}
if ( nChangeFlags & POSITION_CHANGED )
{
nDirtyFlags |= EFL_DIRTY_ABSTRANSFORM;
#ifndef CLIENT_DLL
NetworkProp()->MarkPVSInformationDirty();
#endif
// NOTE: This will also mark shadow projection + client leaf dirty
CollisionProp()->MarkPartitionHandleDirty();
}
// NOTE: This has to be done after velocity + position are changed
// because we change the nChangeFlags for the child entities
if ( nChangeFlags & ANGLES_CHANGED )
{
nDirtyFlags |= EFL_DIRTY_ABSTRANSFORM;
if ( CollisionProp()->DoesRotationInvalidateSurroundingBox() )
{
// NOTE: This will handle the KD-tree, surrounding bounds, PVS
// render-to-texture shadow, shadow projection, and client leaf dirty
CollisionProp()->MarkSurroundingBoundsDirty();
}
else
{
#ifdef CLIENT_DLL
MarkRenderHandleDirty();
g_pClientShadowMgr->AddToDirtyShadowList( this );
g_pClientShadowMgr->MarkRenderToTextureShadowDirty( GetShadowHandle() );
#endif
}
// This is going to be used for all children: children
// have position + velocity changed
nChangeFlags |= POSITION_CHANGED | VELOCITY_CHANGED;
}
AddIEFlags( nDirtyFlags );
// Set flags for children
bool bOnlyDueToAttachment = false;
if ( nChangeFlags & ANIMATION_CHANGED )
{
#ifdef CLIENT_DLL
g_pClientShadowMgr->MarkRenderToTextureShadowDirty( GetShadowHandle() );
#endif
// Only set this flag if the only thing that changed us was the animation.
// If position or something else changed us, then we must tell all children.
if ( !( nChangeFlags & (POSITION_CHANGED | VELOCITY_CHANGED | ANGLES_CHANGED) ) )
{
bOnlyDueToAttachment = true;
}
nChangeFlags = POSITION_CHANGED | ANGLES_CHANGED | VELOCITY_CHANGED;
}
for (CBaseEntity *pChild = FirstMoveChild(); pChild; pChild = pChild->NextMovePeer())
{
// If this is due to the parent animating, only invalidate children that are parented to an attachment
// Entities that are following also access attachments points on parents and must be invalidated.
if ( bOnlyDueToAttachment )
{
#ifdef CLIENT_DLL
if ( (pChild->GetParentAttachment() == 0) && !pChild->IsFollowingEntity() )
continue;
#else
if ( pChild->GetParentAttachment() == 0 )
continue;
#endif
}
pChild->InvalidatePhysicsRecursive( nChangeFlags );
}
//
// This code should really be in here, or the bone cache should not be in world space.
// Since the bone transforms are in world space, if we move or rotate the entity, its
// bones should be marked invalid.
//
// As it is, we're near ship, and don't have time to setup a good A/B test of how much
// overhead this fix would add. We've also only got one known case where the lack of
// this fix is screwing us, and I just fixed it, so I'm leaving this commented out for now.
//
// Hopefully, we'll put the bone cache in entity space and remove the need for this fix.
//
//#ifdef CLIENT_DLL
// if ( nChangeFlags & (POSITION_CHANGED | ANGLES_CHANGED | ANIMATION_CHANGED) )
// {
// C_BaseAnimating *pAnim = GetBaseAnimating();
// if ( pAnim )
// pAnim->InvalidateBoneCache();
// }
//#endif
}
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 SetAbsOrigin( const Vector& origin )
{
call_mfunc<void, CBaseEntity, const Vector &>(this, CBaseEntitySetAbsOrigin, origin);
}
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);
}
void CalcAbsolutePosition()
{
call_mfunc<void, CBaseEntity>(this, CBaseEntityCalcAbsolutePosition);
}
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);
}
void SetLocalOrigin( const Vector& origin )
{
if(m_vecOriginOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_vecOrigin", &info);
m_vecOriginOffset = info.actual_offset;
}
// Safety check against NaN's or really huge numbers
if ( !IsEntityPositionReasonable( origin ) )
{
return;
}
// if ( !origin.IsValid() )
// {
// AssertMsg( 0, "Bad origin set" );
// return;
// }
if (*(Vector *)((unsigned char *)this + m_vecOriginOffset) != origin)
{
InvalidatePhysicsRecursive( POSITION_CHANGED );
*(Vector *)((unsigned char *)this + m_vecOriginOffset) = origin;
SetEdictStateChanged(this, m_vecOriginOffset);
SetSimulationTime( gpGlobals->curtime );
}
}
void SetOwnerEntity( CBaseEntity* pOwner )
{
call_vfunc<void, CBaseEntity, CBaseEntity *>(this, CBaseEntitySetOwnerEntity, pOwner);
}
const Vector &WorldSpaceCenter( ) const
{
return call_vfunc<const Vector &>(this, CBaseEntityWorldSpaceCenter);
}
string_t GetEntityName()
{
if(m_iNameOffset == -1) {
sm_datatable_info_t info{};
datamap_t *pMap = gamehelpers->GetDataMap(this);
gamehelpers->FindDataMapInfo(pMap, "m_iName", &info);
m_iNameOffset = info.actual_offset;
}
return *(string_t *)((unsigned char *)this + m_iNameOffset);
}
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;
}
bool AcceptInput( const char *szInputName, CBaseEntity *pActivator, CBaseEntity *pCaller, variant_t Value, int outputID )
{
return call_vfunc<bool, CBaseEntity, const char *, CBaseEntity *, CBaseEntity *, variant_t, int>(this, CBaseEntityAcceptInput, szInputName, pActivator, pCaller, Value, outputID);
}
int GetTeamNumber()
{
return *(int *)(((unsigned char *)this) + m_iTeamNumOffset);
}
static CBaseEntity *CreateNoSpawn( const char *szName, const Vector &vecOrigin, const QAngle &vecAngles, CBaseEntity *pOwner = NULL )
{
CBaseEntity *pEntity{CreateEntityByName(szName)};
pEntity->SetLocalOrigin( vecOrigin );
pEntity->SetLocalAngles( vecAngles );
pEntity->SetOwnerEntity( pOwner );
((CGlobalEntityList *)g_pEntityList)->NotifyCreateEntity( pEntity );
return pEntity;
}
//GARBAGE
int GetHealth() { return 0; }
int m_takedamage;
void NetworkStateChanged() { }
void NetworkStateChanged( void *pVar ) { }
virtual bool ShouldBlockNav() const { return true; }
int ObjectCaps() { return 0; }
bool HasSpawnFlags(int) { return 0; }
};
inline bool FClassnameIs(CBaseEntity *pEntity, const char *szClassname)
{
return pEntity->ClassMatches(szClassname);
}
class CBaseCombatCharacter : public CBaseEntity
{
};
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
}
struct CPopulationManager_members_t
{
CUtlVector< IPopulator * > m_populatorVector;
char m_popfileFull[ MAX_PATH ];
char m_popfileShort[ MAX_PATH ];
KeyValues *m_pTemplates;
bool m_bIsInitialized;
bool m_bAllocatedBots;
bool m_bBonusRound;
CHandle< CBaseCombatCharacter > m_hBonusBoss;
int m_nStartingCurrency;
int m_nLobbyBonusCurrency;
int m_nMvMEventPopfileType;
int m_nRespawnWaveTime;
bool m_bFixedRespawnWaveTime;
bool m_canBotsAttackWhileInSpawnRoom;
int m_sentryBusterDamageDealtThreshold;
int m_sentryBusterKillThreshold;
uint32 m_iCurrentWaveIndex;
CUtlVector< CWave * > m_waveVector; // pointers to waves within m_populationVector
float m_flMapRestartTime; // Restart the Map if gameover and this time elapses
CUtlVector< PlayerUpgradeHistory * > m_playerUpgrades; // list of all players and their upgrades who have played on this MVM rotation
bool m_isRestoringCheckpoint;
bool m_bAdvancedPopFile;
bool m_bCheckForCurrencyAchievement;
CMannVsMachineStats *m_pMVMStats;
KeyValues *m_pKvpMvMMapCycle;
bool m_bSpawningPaused;
bool m_bIsWaveJumping;
bool m_bEndlessOn;
CUtlVector< CMvMBotUpgrade > m_BotUpgradesList;
CUtlVector< CMvMBotUpgrade > m_EndlessActiveBotUpgrades;
CUniformRandomStream m_randomizer;
CUtlVector< int > m_EndlessSeeds;
bool m_bShouldResetFlag;
CUtlVector< const CTFPlayer* > m_donePlayers;
CUtlString m_defaultEventChangeAttributesName;
// Respec
CUtlMap< uint64, int > m_PlayerRespecPoints; // The number of upgrade respecs players (steamID) have
int m_nRespecsAwarded;
int m_nRespecsAwardedInWave;
int m_nCurrencyCollectedForRespec;
// Buyback
CUtlMap< uint64, int > m_PlayerBuybackPoints; // The number of times a player can buyback
};
ConVar *tf_populator_health_multiplier{nullptr};
ConVar *tf_mvm_endless_tank_boost{nullptr};
ConVar *tf_mvm_endless_force_on{nullptr};
ConVar *tf_populator_damage_multiplier{nullptr};
ConVar *tf_mvm_endless_damage_boost_rate{nullptr};
ConVar *tf_mvm_endless_scale_rate{nullptr};
void *CPopulationManagerSetPopulationFilename{nullptr};
void *CPopulationManagerInitialize{nullptr};
void *CPopulationManagerUpdateObjectiveResource{nullptr};
class CPopulationManager;
static CPopulationManager *last_manager{nullptr};
class CPopulationManager : public CBaseEntity
{
public:
CPopulationManager_members_t &GetMembers()
{
return *(CPopulationManager_members_t *)(((unsigned char *)this) + ((info_populator_size - sizeof(CPopulationManager_members_t))));
}
bool DetourParse( void );
bool ParseAdditive( const char *populationFile );
bool ParseAdditive( KeyValues *values );
KeyValues *GetTemplate( const char *pszName )
{
CPopulationManager_members_t &members{GetMembers()};
KeyValues *pTemplate = nullptr;
if(members.m_pTemplates) {
pTemplate = members.m_pTemplates->FindKey( pszName );
}
return pTemplate;
}
void OnPlayerKilled( CTFPlayer *corpse )
{
call_mfunc<void, CPopulationManager, CTFPlayer *>(this, CPopulationManagerOnPlayerKilled, corpse);
}
float GetDamageMultiplier ()
{
CPopulationManager_members_t &members{GetMembers()};
//if ( !IsInEndlessWaves() )
return tf_populator_damage_multiplier->GetFloat();
// Find out how many times over t
// Floor of the result, ie 9 / 7 returns 1, 15 / 7 returns 2;
//int nRepeatCount = members.m_iCurrentWaveIndex / tf_mvm_endless_scale_rate->GetInt();
//return tf_populator_damage_multiplier->GetFloat() + tf_mvm_endless_damage_boost_rate->GetFloat() * nRepeatCount;
}
float GetHealthMultiplier ( bool bIsTank )
{
CPopulationManager_members_t &members{GetMembers()};
if ( !IsInEndlessWaves() || !bIsTank )
return tf_populator_health_multiplier->GetFloat();
// Calculate how much health the tank should get per wave
return tf_populator_health_multiplier->GetFloat() + members.m_iCurrentWaveIndex * tf_mvm_endless_tank_boost->GetFloat();
}
bool IsInEndlessWaves ( void )
{
CPopulationManager_members_t &members{GetMembers()};
return (members.m_bEndlessOn || tf_mvm_endless_force_on->GetBool() ) && members.m_waveVector.Count() > 0;
}
CWave * GetCurrentWave( void )
{
CPopulationManager_members_t &members{GetMembers()};
if ( !members.m_bIsInitialized || members.m_waveVector.Count() == 0 )
return NULL;
// Wrap for Infinite MVM
if ( IsInEndlessWaves() )
{
return members.m_waveVector[members.m_iCurrentWaveIndex % members.m_waveVector.Count() ];
}
else if ( (int)members.m_iCurrentWaveIndex < members.m_waveVector.Count() )
{
return members.m_waveVector[members.m_iCurrentWaveIndex];
}
return NULL;
}
int GetTotalPopFileCurrency( void );
void SetPopulationFilename( const char *populationFile )
{
last_manager = this;
call_mfunc<void, CPopulationManager, const char *>(this, CPopulationManagerSetPopulationFilename, populationFile);
last_manager = nullptr;
}
bool Initialize( void )
{
last_manager = this;
bool ret{call_mfunc<bool, CPopulationManager>(this, CPopulationManagerInitialize)};
last_manager = nullptr;