-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign_func.cpp
2401 lines (2001 loc) · 62.1 KB
/
sign_func.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 "sign_func.h"
#include "CEntity.h"
#include "CDetour/detours.h"
#include "CAI_NPC.h"
#include "ai_namespaces.h"
#include "CAI_schedule.h"
#include "CAI_senses.h"
class CBasePlayer;
#include "soundenvelope.h"
#include "stringregistry.h"
#include "GameSystem.h"
#include "stringpool.h"
#include "gamemovement.h"
#include "CPlayer.h"
#include "ammodef.h"
#include "eventqueue.h"
#include "CAI_Hint.h"
#include "ai_waypoint.h"
#include "CAI_NetworkManager.h"
#include "MonsterConfig.h"
#include "CPathTrack.h"
// shared ammo definition
// JAY: Trying to make a more physical bullet response
#define BULLET_MASS_GRAINS_TO_LB(grains) (0.002285*(grains)/16.0f)
#define BULLET_MASS_GRAINS_TO_KG(grains) lbs2kg(BULLET_MASS_GRAINS_TO_LB(grains))
// exaggerate all of the forces, but use real numbers to keep them consistent
#define BULLET_IMPULSE_EXAGGERATION 3.5
// convert a velocity in ft/sec and a mass in grains to an impulse in kg in/s
#define BULLET_IMPULSE(grains, ftpersec) ((ftpersec)*12*BULLET_MASS_GRAINS_TO_KG(grains)*BULLET_IMPULSE_EXAGGERATION)
class CAI_SensedObjectsManager;
struct TemplateEntityData_t;
class CGameStringPool;
class CMemoryPool;
class CCallQueue;
class CCheckClient;
class CFlexSceneFileManager;
class CDefaultResponseSystem;
class CGlobalState;
class CPhysicsHook;
class CCollisionEvent;
HelperFunction g_helpfunc;
CGameMovement *g_CGameMovement = NULL;
Vector *g_vecAttackDir = NULL;
CSoundEnvelopeController *g_SoundController = NULL;
IPredictionSystem *IPredictionSystem::g_pPredictionSystems = NULL;
CAI_SensedObjectsManager *g_AI_SensedObjectsManager = NULL;
CCallQueue *g_PostSimulationQueue = NULL;
INotify *g_pNotify = NULL;
IPhysicsObject *g_PhysWorldObject = NULL;
CViewVectors *g_ViewVectors = NULL;
CViewVectors *g_DefaultViewVectors = NULL;
extern CMultiDamage *my_g_MultiDamage;
extern CUtlVector<TemplateEntityData_t *> *g_Templates;
extern CUtlMemoryPool *g_EntityListPool;
extern ConVar *ammo_hegrenade_max;
extern trace_t *g_TouchTrace;
extern INetworkStringTable *g_pStringTableParticleEffectNames;
extern INetworkStringTable *g_pStringTableMaterials;
extern CUtlVector<IValveGameSystem*> *s_GameSystems;
extern CCheckClient *g_CheckClient;
extern CFlexSceneFileManager *g_FlexSceneFileManager;
extern CUtlMap< int, CAIHintVector > *my_gm_TypedHints;
extern int *g_interactionHitByPlayerThrownPhysObj;
extern CAI_SquadManager *g_AI_SquadManager;
extern CGlobalState *gGlobalState;
extern CPhysicsHook *g_PhysicsHook;
extern CCollisionEvent *g_Collisions;
extern IMoveHelper **sm_pSingleton;
void InitDefaultAIRelationships();
bool SetResponseSystem();
SH_DECL_MANUALHOOK0(GameRules_FAllowNPCsHook, 0, 0, 0, bool);
SH_DECL_MANUALHOOK2(GameRules_ShouldCollideHook, 0, 0, 0, bool, int, int);
SH_DECL_MANUALHOOK1(CGameMovement_OnLadderHook, 0, 0, 0, bool, trace_t &);
SH_DECL_MANUALHOOK5_void(GameRules_RadiusDamageHook, 0, 0, 0, const CTakeDamageInfo &, const Vector &, float , int , CBaseEntity *);
class HelperSystem : public CBaseGameSystem
{
public:
HelperSystem(const char *name) : CBaseGameSystem(name)
{
}
void LevelInitPreEntity()
{
g_helpfunc.LevelInitPreEntity();
}
void LevelInitPostEntity()
{
g_helpfunc.LevelInitPostEntity();
}
void LevelShutdownPreEntity()
{
g_helpfunc.LevelShutdownPreEntity();
}
void LevelShutdownPostEntity()
{
g_helpfunc.LevelShutdownPostEntity();
}
void SDKShutdown()
{
g_helpfunc.Shutdown();
}
};
static HelperSystem g_helpersystem("HelperSystem");
string_t AllocPooledString( const char * pszValue )
{
return g_helpfunc.AllocPooledString(pszValue);
}
string_t FindPooledString( const char *pszValue )
{
return g_helpfunc.FindPooledString(pszValue);
}
HelperFunction::HelperFunction()
{
my_g_pGameRules = NULL;
g_SoundEmitterSystem = NULL;
USE_HL2_RADIUS_DAMAGE = false;
}
void HelperFunction::LevelInitPreEntity()
{
g_pStringTableParticleEffectNames = netstringtables->FindTable("ParticleEffectNames");
g_pStringTableMaterials = netstringtables->FindTable("Materials");
g_AI_SchedulesManager.CreateStringRegistries();
InitDefaultAIRelationships();
HookGameRules();
g_ViewVectors = GameRules_GetViewVectors();
META_CONPRINTF("[%s] Server may crash at this time!\n",g_Monster.GetLogTag());
IPhysicsObjectPairHash *g_EntityCollisionHash;
GET_VARIABLE_POINTER_NORET(g_EntityCollisionHash, IPhysicsObjectPairHash *);
my_g_EntityCollisionHash = g_EntityCollisionHash;
CBaseEntity *g_WorldEntity = NULL;
GET_VARIABLE_POINTER_NORET(g_WorldEntity, CBaseEntity *);
my_g_WorldEntity = CEntity::Instance(g_WorldEntity);
my_g_WorldEntity_cbase = g_WorldEntity;
GET_VARIABLE_POINTER_NORET(g_PhysWorldObject, IPhysicsObject *);
// "ACT_RESET"
CStringRegistry *m_pActivitySR = NULL;
GET_VARIABLE_POINTER_NORET(m_pActivitySR, CStringRegistry *);
CAI_NPC::m_pActivitySR = m_pActivitySR;
// above 2
int *m_iNumActivities = NULL;
GET_VARIABLE_NORET(m_iNumActivities, int *);
CAI_NPC::m_iNumActivities = m_iNumActivities;
// "ERROR: Mistake in default schedule def" above 2
CStringRegistry *m_pEventSR = NULL;
GET_VARIABLE_POINTER_NORET(m_pEventSR, CStringRegistry *);
CAI_NPC::m_pEventSR = m_pEventSR;
int m_iNumEvents_offset;
if(!g_pGameConf->GetOffset("m_iNumEvents", &m_iNumEvents_offset))
{
g_pSM->LogError(myself,"Unable getting %s","m_iNumEvents");
return;
}
char *m_iNumEvents_final_addr = reinterpret_cast<char *>(CAI_NPC::m_iNumActivities + m_iNumEvents_offset);
CAI_NPC::m_iNumEvents = (int *)m_iNumEvents_final_addr;
g_AI_SchedulesManager.LoadAllSchedules();
if(g_ViewVectors && g_DefaultViewVectors == NULL)
{
g_DefaultViewVectors = new CViewVectors();
memcpy(g_DefaultViewVectors, g_ViewVectors, sizeof(CViewVectors));
}
}
void HelperFunction::LevelInitPostEntity()
{
CEAI_NetworkManager::InitializeAINetworks();
}
void HelperFunction::LevelShutdownPreEntity()
{
UnHookGameRules();
}
void HelperFunction::LevelShutdownPostEntity()
{
g_AI_SchedulesManager.DeleteAllSchedules();
g_AI_SchedulesManager.DestroyStringRegistries();
}
void HelperFunction::Shutdown()
{
LevelShutdownPreEntity();
CCombatCharacter::Shutdown();
SH_REMOVE_MANUALHOOK_MEMFUNC(CGameMovement_OnLadderHook, g_CGameMovement, &g_helpfunc, &HelperFunction::CGameMovement_OnLadder, false);
if(g_DefaultViewVectors)
{
delete g_DefaultViewVectors;
g_DefaultViewVectors = NULL;
}
}
bool HelperFunction::FindAllValveGameSystem()
{
FindValveGameSystem(g_CheckClient, CCheckClient *, "CCheckClient");
FindValveGameSystem(g_PropDataSystem, CPropData *, "CPropData");
FindValveGameSystem(g_SoundEmitterSystem, void *, "CSoundEmitterSystem");
FindValveGameSystem(g_FlexSceneFileManager, CFlexSceneFileManager *, "CFlexSceneFileManager");
FindValveGameSystem(gGlobalState, CGlobalState *, "CGlobalState");
FindValveGameSystem(g_PhysicsHook, CPhysicsHook *, "CPhysicsHook");
if(!SetResponseSystem())
return false;
return true;
}
bool HelperFunction::Initialize()
{
char *addr = NULL;
int offset = 0;
RegisterHook("GameRules_FAllowNPCs",GameRules_FAllowNPCsHook);
RegisterHook("GameRules_ShouldCollide",GameRules_ShouldCollideHook);
RegisterHook("GameRules_RadiusDamage",GameRules_RadiusDamageHook);
RegisterHook("CGameMovement_OnLadder",CGameMovement_OnLadderHook);
if(!g_pGameConf->GetMemSig("CreateGameRulesObject", (void **)&addr) || !addr)
return false;
if(!g_pGameConf->GetOffset("g_pGameRules", &offset) || !offset)
return false;
my_g_pGameRules = *reinterpret_cast<void ***>(addr + offset);
/*
Script failed for %s\n
unnamed
*/
GET_VARIABLE(g_AI_SensedObjectsManager, CAI_SensedObjectsManager *);
/*
"Player.PlasmaDamage"
*/
GET_VARIABLE(g_vecAttackDir, Vector *);
// "ERROR: Attempting to give unknown ammo " above 1
Relationship_t ***m_DefaultRelationship;
GET_VARIABLE(m_DefaultRelationship, Relationship_t ** *);
CCombatCharacter::m_DefaultRelationship = m_DefaultRelationship;
// "CNavArea::IncrementPlayerCount: Underfl" retn 8 bellow 4
int *m_lastInteraction = NULL;
GET_VARIABLE(m_lastInteraction, int *);
CCombatCharacter::m_lastInteraction = m_lastInteraction;
// "Invalid starting duration value in env" bellow 2, first function
GET_VARIABLE(g_SoundController, CSoundEnvelopeController *);
// "Can't find decal %s\n"
GET_VARIABLE_POINTER(decalsystem, IDecalEmitterSystem *);
IPredictionSystem *g_pPredictionSystems = NULL;
GET_VARIABLE_POINTER(g_pPredictionSystems, IPredictionSystem *);
IPredictionSystem::g_pPredictionSystems = g_pPredictionSystems;
te = servertools->GetTempEntsSystem();
GET_VARIABLE(my_g_MultiDamage, CMultiDamage *);
GET_VARIABLE(g_Templates, CUtlVector<TemplateEntityData_t *> *);
GET_VARIABLE(g_EntityListPool, CUtlMemoryPool *);
GET_VARIABLE(g_CEventQueue, CEventQueue *);
GET_VARIABLE(g_TouchTrace, trace_t *);
GET_VARIABLE(g_PostSimulationQueue, CCallQueue *);
CUtlMemoryPool *EventQueuePrioritizedEvent_t_s_Allocator;
GET_VARIABLE(EventQueuePrioritizedEvent_t_s_Allocator, CUtlMemoryPool *);
EventQueuePrioritizedEvent_t::s_Allocator = EventQueuePrioritizedEvent_t_s_Allocator;
CAIHintVector *gm_AllHints = NULL;
GET_VARIABLE(gm_AllHints, CAIHintVector *);
CAI_HintManager::gm_AllHints = gm_AllHints;
GET_VARIABLE(s_GameSystems, CUtlVector<IValveGameSystem*> *);
CUtlMemoryPool *AI_Waypoint_t_s_Allocator;
GET_VARIABLE(AI_Waypoint_t_s_Allocator, CUtlMemoryPool *);
AI_Waypoint_t::s_Allocator = AI_Waypoint_t_s_Allocator;
GET_VARIABLE(g_AIFriendliesTalkSemaphore, CAI_TimedSemaphore *);
GET_VARIABLE(g_AIFoesTalkSemaphore, CAI_TimedSemaphore *);
GET_VARIABLE_POINTER(g_pNotify, INotify *);
typedef CUtlMap<int, CAIHintVector>* HINTS_TYPE;
HINTS_TYPE gm_TypedHints;
GET_VARIABLE(gm_TypedHints, HINTS_TYPE);
my_gm_TypedHints = gm_TypedHints;
GET_VARIABLE(g_interactionHitByPlayerThrownPhysObj, int *);
GET_VARIABLE(g_interactionScriptedTarget, int *);
GET_VARIABLE(g_AI_SquadManager, CAI_SquadManager *);
GET_VARIABLE(g_Collisions, CCollisionEvent *);
GET_VARIABLE(sm_pSingleton, IMoveHelper **);
int *s_nCurrIterVal;
GET_VARIABLE(s_nCurrIterVal, int *);
CE_CPathTrack::s_nCurrIterVal = s_nCurrIterVal;
bool *s_bIsIterating;
GET_VARIABLE(s_bIsIterating, bool *);
CE_CPathTrack::s_bIsIterating = s_bIsIterating;
g_CGameMovement = (CGameMovement *)g_pGameMovement;
SH_ADD_MANUALHOOK_MEMFUNC(CGameMovement_OnLadderHook, g_CGameMovement, &g_helpfunc, &HelperFunction::CGameMovement_OnLadder, false);
CAmmoDef *def = GetAmmoDef();
int grenade = def->Index("AMMO_TYPE_HEGRENADE");
if(grenade > 0)
{
Ammo_t *ammo = def->GetAmmoOfIndex(grenade);
if(ammo)
{
ammo->pMaxCarry = -1;
ammo->pMaxCarryCVar = ammo_hegrenade_max;
}
}
#ifdef HL2_EPISODIC
def->AddAmmoType("StriderMinigun", DMG_BULLET, TRACER_LINE, 5, 5, 15, 1.0 * 750 * 12, AMMO_FORCE_DROP_IF_CARRIED ); // hit like a 1.0kg weight at 750 ft/s
#else
def->AddAmmoType("StriderMinigun", DMG_BULLET, TRACER_LINE, 5, 15,15, 1.0 * 750 * 12, AMMO_FORCE_DROP_IF_CARRIED ); // hit like a 1.0kg weight at 750 ft/s
#endif//HL2_EPISODIC
def->AddAmmoType("StriderMinigunDirect", DMG_BULLET, TRACER_LINE, 2, 2, 15, 1.0 * 750 * 12, AMMO_FORCE_DROP_IF_CARRIED ); // hit like a 1.0kg weight at 750 ft/s
def->AddAmmoType("HelicopterGun", DMG_BULLET, TRACER_LINE_AND_WHIZ, "sk_npc_dmg_helicopter_to_plr", "sk_npc_dmg_helicopter", "sk_max_smg1", BULLET_IMPULSE(400, 1225), AMMO_FORCE_DROP_IF_CARRIED | AMMO_INTERPRET_PLRDAMAGE_AS_DAMAGE_TO_PLAYER );
def->AddAmmoType("CombineCannon", DMG_BULLET, TRACER_LINE, "sk_npc_dmg_gunship_to_plr", "sk_npc_dmg_gunship", NULL, 1.5 * 750 * 12, 0 ); // hit like a 1.5kg weight at 750 ft/s
def->AddAmmoType("SMG1", DMG_BULLET, TRACER_LINE_AND_WHIZ, "sk_plr_dmg_smg1", "sk_npc_dmg_smg1", "sk_max_smg1", BULLET_IMPULSE(200, 1225), 0 );
def->AddAmmoType("Buckshot", DMG_BULLET | DMG_BUCKSHOT, TRACER_LINE, "sk_plr_dmg_buckshot", "sk_npc_dmg_buckshot", "sk_max_buckshot", BULLET_IMPULSE(400, 1200), 0 );
def->AddAmmoType("RPG_Round", DMG_BURN, TRACER_NONE, "sk_plr_dmg_rpg_round", "sk_npc_dmg_rpg_round", "sk_max_rpg_round", 0, 0 );
def->AddAmmoType("SniperRound", DMG_BULLET | DMG_SNIPER, TRACER_NONE, "sk_plr_dmg_sniper_round", "sk_npc_dmg_sniper_round", "sk_max_sniper_round", BULLET_IMPULSE(650, 6000), 0 );
def->AddAmmoType("SniperPenetratedRound", DMG_BULLET | DMG_SNIPER, TRACER_NONE, "sk_dmg_sniper_penetrate_plr", "sk_dmg_sniper_penetrate_npc", "sk_max_sniper_round", BULLET_IMPULSE(150, 6000), 0 );
def->AddAmmoType("CombineCannon", DMG_BULLET, TRACER_LINE, "sk_npc_dmg_gunship_to_plr", "sk_npc_dmg_gunship", NULL, 1.5 * 750 * 12, 0 ); // hit like a 1.5kg weight at 750 ft/s
def->AddAmmoType("Pistol", DMG_BULLET, TRACER_LINE_AND_WHIZ, "sk_plr_dmg_pistol", "sk_npc_dmg_pistol", "sk_max_pistol", BULLET_IMPULSE(200, 1225), 0 );
def->AddAmmoType("GaussEnergy", DMG_SHOCK, TRACER_NONE, "sk_jeep_gauss_damage", "sk_jeep_gauss_damage", "sk_max_gauss_round", BULLET_IMPULSE(650, 8000), 0 ); // hit like a 10kg weight at 400 in/s
if(!FindAllValveGameSystem())
return false;
IGameSystem::HookValveSystem();
return true;
}
bool HelperFunction::CGameMovement_OnLadder( trace_t &trace )
{
CBaseEntity *cbase = (CBaseEntity *)g_CGameMovement->player;
CPlayer *pPlayer = (CPlayer *)CEntity::Instance(cbase);
if(pPlayer)
{
if(pPlayer->m_bOnLadder && pPlayer->GetGroundEntity() == NULL)
{
RETURN_META_VALUE(MRES_SUPERCEDE, true);
}
}
RETURN_META_VALUE(MRES_IGNORED, true);
}
bool HelperFunction::GameRules_FAllowNPCs()
{
RETURN_META_VALUE(MRES_SUPERCEDE, true);
}
void HelperFunction::HookGameRules()
{
if(my_g_pGameRules == NULL)
return;
void *rules = NULL;
memcpy(&rules, reinterpret_cast<void*>(my_g_pGameRules), sizeof(char*));
if(rules == NULL)
return;
SH_ADD_MANUALHOOK_MEMFUNC(GameRules_FAllowNPCsHook, rules, &g_helpfunc, &HelperFunction::GameRules_FAllowNPCs, false);
SH_ADD_MANUALHOOK_MEMFUNC(GameRules_ShouldCollideHook, rules, &g_helpfunc, &HelperFunction::GameRules_ShouldCollide_Hook, true);
SH_ADD_MANUALHOOK_MEMFUNC(GameRules_RadiusDamageHook, rules, &g_helpfunc, &HelperFunction::GameRules_RadiusDamage_Hook, false);
}
void HelperFunction::UnHookGameRules()
{
if(my_g_pGameRules == NULL)
return;
void *rules = NULL;
memcpy(&rules, reinterpret_cast<void*>(my_g_pGameRules), sizeof(char*));
if(rules == NULL)
return;
SH_REMOVE_MANUALHOOK_MEMFUNC(GameRules_FAllowNPCsHook, rules, &g_helpfunc, &HelperFunction::GameRules_FAllowNPCs, false);
SH_REMOVE_MANUALHOOK_MEMFUNC(GameRules_ShouldCollideHook, rules, &g_helpfunc, &HelperFunction::GameRules_ShouldCollide_Hook, true);
SH_REMOVE_MANUALHOOK_MEMFUNC(GameRules_RadiusDamageHook, rules, &g_helpfunc, &HelperFunction::GameRules_RadiusDamage_Hook, false);
}
bool HelperFunction::CGameRules_ShouldCollide( int collisionGroup0, int collisionGroup1 )
{
if ( collisionGroup0 > collisionGroup1 )
{
// swap so that lowest is always first
V_swap(collisionGroup0,collisionGroup1);
}
if ( collisionGroup0 == COLLISION_GROUP_DEBRIS && collisionGroup1 == COLLISION_GROUP_PUSHAWAY )
{
// let debris and multiplayer objects collide
return true;
}
// --------------------------------------------------------------------------
// NOTE: All of this code assumes the collision groups have been sorted!!!!
// NOTE: Don't change their order without rewriting this code !!!
// --------------------------------------------------------------------------
// Don't bother if either is in a vehicle...
if (( collisionGroup0 == COLLISION_GROUP_IN_VEHICLE ) || ( collisionGroup1 == COLLISION_GROUP_IN_VEHICLE ))
return false;
if ( ( collisionGroup1 == COLLISION_GROUP_DOOR_BLOCKER ) && ( collisionGroup0 != COLLISION_GROUP_NPC ) )
return false;
if ( ( collisionGroup0 == COLLISION_GROUP_PLAYER ) && ( collisionGroup1 == COLLISION_GROUP_PASSABLE_DOOR ) )
return false;
if ( collisionGroup0 == COLLISION_GROUP_DEBRIS || collisionGroup0 == COLLISION_GROUP_DEBRIS_TRIGGER )
{
// put exceptions here, right now this will only collide with COLLISION_GROUP_NONE
return false;
}
// Dissolving guys only collide with COLLISION_GROUP_NONE
if ( (collisionGroup0 == COLLISION_GROUP_DISSOLVING) || (collisionGroup1 == COLLISION_GROUP_DISSOLVING) )
{
if ( collisionGroup0 != COLLISION_GROUP_NONE )
return false;
}
// doesn't collide with other members of this group
// or debris, but that's handled above
if ( collisionGroup0 == COLLISION_GROUP_INTERACTIVE_DEBRIS && collisionGroup1 == COLLISION_GROUP_INTERACTIVE_DEBRIS )
return false;
if ( collisionGroup0 == COLLISION_GROUP_BREAKABLE_GLASS && collisionGroup1 == COLLISION_GROUP_BREAKABLE_GLASS )
return false;
// interactive objects collide with everything except debris & interactive debris
if ( collisionGroup1 == COLLISION_GROUP_INTERACTIVE && collisionGroup0 != COLLISION_GROUP_NONE )
return false;
// Projectiles hit everything but debris, weapons, + other projectiles
if ( collisionGroup1 == COLLISION_GROUP_PROJECTILE )
{
if ( collisionGroup0 == COLLISION_GROUP_DEBRIS ||
collisionGroup0 == COLLISION_GROUP_WEAPON ||
collisionGroup0 == COLLISION_GROUP_PROJECTILE )
{
return false;
}
}
// Don't let vehicles collide with weapons
// Don't let players collide with weapons...
// Don't let NPCs collide with weapons
// Weapons are triggers, too, so they should still touch because of that
if ( collisionGroup1 == COLLISION_GROUP_WEAPON )
{
if ( collisionGroup0 == COLLISION_GROUP_VEHICLE ||
collisionGroup0 == COLLISION_GROUP_PLAYER ||
collisionGroup0 == COLLISION_GROUP_NPC )
{
return false;
}
}
// collision with vehicle clip entity??
if ( collisionGroup0 == COLLISION_GROUP_VEHICLE_CLIP || collisionGroup1 == COLLISION_GROUP_VEHICLE_CLIP )
{
// yes then if it's a vehicle, collide, otherwise no collision
// vehicle sorts lower than vehicle clip, so must be in 0
if ( collisionGroup0 == COLLISION_GROUP_VEHICLE )
return true;
// vehicle clip against non-vehicle, no collision
return false;
}
return true;
}
bool HelperFunction::CHalfLife2_ShouldCollide( int collisionGroup0, int collisionGroup1)
{
// The smaller number is always first
if ( collisionGroup0 > collisionGroup1 )
{
// swap so that lowest is always first
int tmp = collisionGroup0;
collisionGroup0 = collisionGroup1;
collisionGroup1 = tmp;
}
// Prevent the player movement from colliding with spit globs (caused the player to jump on top of globs while in water)
if ( collisionGroup0 == COLLISION_GROUP_PLAYER_MOVEMENT && collisionGroup1 == HL2COLLISION_GROUP_SPIT )
return false;
// HL2 treats movement and tracing against players the same, so just remap here
if ( collisionGroup0 == COLLISION_GROUP_PLAYER_MOVEMENT )
{
collisionGroup0 = COLLISION_GROUP_PLAYER;
}
if( collisionGroup1 == COLLISION_GROUP_PLAYER_MOVEMENT )
{
collisionGroup1 = COLLISION_GROUP_PLAYER;
}
//If collisionGroup0 is not a player then NPC_ACTOR behaves just like an NPC.
if ( collisionGroup1 == COLLISION_GROUP_NPC_ACTOR && collisionGroup0 != COLLISION_GROUP_PLAYER )
{
collisionGroup1 = COLLISION_GROUP_NPC;
}
if ( collisionGroup0 == HL2COLLISION_GROUP_COMBINE_BALL )
{
if ( collisionGroup1 == HL2COLLISION_GROUP_COMBINE_BALL )
return false;
}
if ( collisionGroup0 == HL2COLLISION_GROUP_COMBINE_BALL && collisionGroup1 == HL2COLLISION_GROUP_COMBINE_BALL_NPC )
return false;
if ( ( collisionGroup0 == COLLISION_GROUP_WEAPON ) ||
( collisionGroup0 == COLLISION_GROUP_PLAYER ) ||
( collisionGroup0 == COLLISION_GROUP_PROJECTILE ) )
{
if ( collisionGroup1 == HL2COLLISION_GROUP_COMBINE_BALL )
return false;
}
if ( collisionGroup0 == COLLISION_GROUP_DEBRIS )
{
if ( collisionGroup1 == HL2COLLISION_GROUP_COMBINE_BALL )
return true;
}
if (collisionGroup0 == HL2COLLISION_GROUP_HOUNDEYE && collisionGroup1 == HL2COLLISION_GROUP_HOUNDEYE )
return false;
if (collisionGroup0 == HL2COLLISION_GROUP_HOMING_MISSILE && collisionGroup1 == HL2COLLISION_GROUP_HOMING_MISSILE )
return false;
if ( collisionGroup1 == HL2COLLISION_GROUP_CROW )
{
if ( collisionGroup0 == COLLISION_GROUP_PLAYER || collisionGroup0 == COLLISION_GROUP_NPC ||
collisionGroup0 == HL2COLLISION_GROUP_CROW )
return false;
}
if ( ( collisionGroup0 == HL2COLLISION_GROUP_HEADCRAB ) && ( collisionGroup1 == HL2COLLISION_GROUP_HEADCRAB ) )
return false;
// striders don't collide with other striders
if ( collisionGroup0 == HL2COLLISION_GROUP_STRIDER && collisionGroup1 == HL2COLLISION_GROUP_STRIDER )
return false;
// gunships don't collide with other gunships
if ( collisionGroup0 == HL2COLLISION_GROUP_GUNSHIP && collisionGroup1 == HL2COLLISION_GROUP_GUNSHIP )
return false;
// weapons and NPCs don't collide
if ( collisionGroup0 == COLLISION_GROUP_WEAPON && (collisionGroup1 >= HL2COLLISION_GROUP_FIRST_NPC && collisionGroup1 <= HL2COLLISION_GROUP_LAST_NPC ) )
return false;
//players don't collide against NPC Actors.
//I could've done this up where I check if collisionGroup0 is NOT a player but I decided to just
//do what the other checks are doing in this function for consistency sake.
if ( collisionGroup1 == COLLISION_GROUP_NPC_ACTOR && collisionGroup0 == COLLISION_GROUP_PLAYER )
return false;
// In cases where NPCs are playing a script which causes them to interpenetrate while riding on another entity,
// such as a train or elevator, you need to disable collisions between the actors so the mover can move them.
if ( collisionGroup0 == COLLISION_GROUP_NPC_SCRIPTED && collisionGroup1 == COLLISION_GROUP_NPC_SCRIPTED )
return false;
// Spit doesn't touch other spit
if ( collisionGroup0 == HL2COLLISION_GROUP_SPIT && collisionGroup1 == HL2COLLISION_GROUP_SPIT )
return false;
return CGameRules_ShouldCollide(collisionGroup0,collisionGroup1);
}
bool HelperFunction::GameRules_ShouldCollide_Hook(int collisionGroup0, int collisionGroup1)
{
if(collisionGroup0 >= LAST_SHARED_COLLISION_GROUP || collisionGroup1 >= LAST_SHARED_COLLISION_GROUP)
{
bool hl2_ret = CHalfLife2_ShouldCollide(collisionGroup0,collisionGroup1);
RETURN_META_VALUE(MRES_SUPERCEDE, hl2_ret);
} else {
RETURN_META_VALUE(MRES_IGNORED, true);
}
}
bool HelperFunction::GameRules_ShouldCollide(int collisionGroup0, int collisionGroup1)
{
static int offset = NULL;
if(!offset)
{
if(!g_pGameConf->GetOffset("GameRules_ShouldCollide", &offset))
{
assert(0);
return false;
}
}
unsigned char *rules = NULL;
memcpy(&rules, reinterpret_cast<void*>(my_g_pGameRules), sizeof(char*));
void **this_ptr = *reinterpret_cast<void ***>(&rules);
void **vtable = *reinterpret_cast<void ***>(rules);
void *vfunc = vtable[offset];
union
{
bool (VEmptyClass::*mfpnew)(int, int);
void *addr;
} u;
u.addr = vfunc;
return (reinterpret_cast<VEmptyClass *>(this_ptr)->*u.mfpnew)(collisionGroup0, collisionGroup1);
}
bool HelperFunction::GameRules_Damage_NoPhysicsForce(int iDmgType)
{
static int offset = NULL;
if(!offset)
{
if(!g_pGameConf->GetOffset("GameRules_Damage_NoPhysicsForce", &offset))
{
assert(0);
return false;
}
}
unsigned char *rules = NULL;
memcpy(&rules, reinterpret_cast<void*>(my_g_pGameRules), sizeof(char*));
void **this_ptr = *reinterpret_cast<void ***>(&rules);
void **vtable = *reinterpret_cast<void ***>(rules);
void *vfunc = vtable[offset];
union
{
bool (VEmptyClass::*mfpnew)(int);
void *addr;
} u;
u.addr = vfunc;
return (reinterpret_cast<VEmptyClass *>(this_ptr)->*u.mfpnew)(iDmgType);
}
bool HelperFunction::GameRules_IsSkillLevel(int iLevel)
{
static int offset = NULL;
if(!offset)
{
if(!g_pGameConf->GetOffset("GameRules_IsSkillLevel", &offset))
{
assert(0);
return false;
}
}
unsigned char *rules = NULL;
memcpy(&rules, reinterpret_cast<void*>(my_g_pGameRules), sizeof(char*));
void **this_ptr = *reinterpret_cast<void ***>(&rules);
void **vtable = *reinterpret_cast<void ***>(rules);
void *vfunc = vtable[offset];
union
{
bool (VEmptyClass::*mfpnew)(int);
void *addr;
} u;
u.addr = vfunc;
return (reinterpret_cast<VEmptyClass *>(this_ptr)->*u.mfpnew)(iLevel);
}
void HelperFunction::GameRules_RadiusDamage_Hook(const CTakeDamageInfo &info, const Vector &vecSrc, float flRadius, int iClassIgnore, CBaseEntity *pEntityIgnore)
{
if(USE_HL2_RADIUS_DAMAGE)
{
CGameRules_RadiusDamage(info, vecSrc, flRadius, iClassIgnore, pEntityIgnore);
RETURN_META(MRES_SUPERCEDE);
}
RETURN_META(MRES_IGNORED);
}
void HelperFunction::CGameRules_RadiusDamage(const CTakeDamageInfo &info, const Vector &vecSrc, float flRadius, int iClassIgnore, CBaseEntity *pEntityIgnore)
{
static void *func = NULL;
if(!func)
{
if(!g_pGameConf->GetMemSig("CGameRules::RadiusDamage", &func))
{
assert(0);
return;
}
}
unsigned char *rules = NULL;
memcpy(&rules, reinterpret_cast<void*>(my_g_pGameRules), sizeof(char*));
typedef void (__fastcall *_func)(void *, int, const CTakeDamageInfo &, const Vector &, float , int , CBaseEntity *);
_func thisfunc = (_func)func;
thisfunc(rules, 0, info, vecSrc, flRadius, iClassIgnore, pEntityIgnore);
}
void HelperFunction::GameRules_RadiusDamage(const CTakeDamageInfo &info, const Vector &vecSrc, float flRadius, int iClassIgnore, CBaseEntity *pEntityIgnore)
{
static int offset = NULL;
if(!offset)
{
if(!g_pGameConf->GetOffset("GameRules_RadiusDamage", &offset))
{
assert(0);
return;
}
}
unsigned char *rules = NULL;
memcpy(&rules, reinterpret_cast<void*>(my_g_pGameRules), sizeof(char*));
void **this_ptr = *reinterpret_cast<void ***>(&rules);
void **vtable = *reinterpret_cast<void ***>(rules);
void *vfunc = vtable[offset];
union
{
void (VEmptyClass::*mfpnew)(const CTakeDamageInfo &, const Vector &, float , int , CBaseEntity *);
void *addr;
} u;
u.addr = vfunc;
(reinterpret_cast<VEmptyClass *>(this_ptr)->*u.mfpnew)(info,vecSrc,flRadius,iClassIgnore,pEntityIgnore);
}
CCombatWeapon *HelperFunction::GameRules_GetNextBestWeapon(CBaseEntity *pPlayer, CBaseEntity *pCurrentWeapon)
{
static int offset = NULL;
if(!offset)
{
if(!g_pGameConf->GetOffset("GameRules_GetNextBestWeapon", &offset))
{
assert(0);
return NULL;
}
}
unsigned char *rules = NULL;
memcpy(&rules, reinterpret_cast<void*>(my_g_pGameRules), sizeof(char*));
void **this_ptr = *reinterpret_cast<void ***>(&rules);
void **vtable = *reinterpret_cast<void ***>(rules);
void *vfunc = vtable[offset];
union
{
CBaseEntity *(VEmptyClass::*mfpnew)(CBaseEntity *, CBaseEntity *);
void *addr;
} u;
u.addr = vfunc;
CBaseEntity *ret = (reinterpret_cast<VEmptyClass *>(this_ptr)->*u.mfpnew)(pPlayer, pCurrentWeapon);
return (CCombatWeapon*)CEntity::Instance(ret);
}
bool HelperFunction::GameRules_FPlayerCanTakeDamage(CBaseEntity *pPlayer, CBaseEntity *pAttacker, const CTakeDamageInfo &info)
{
static int offset = NULL;
if(!offset)
{
if(!g_pGameConf->GetOffset("GameRules_FPlayerCanTakeDamage", &offset))
{
assert(0);
return NULL;
}
}
unsigned char *rules = NULL;
memcpy(&rules, reinterpret_cast<void*>(my_g_pGameRules), sizeof(char*));
void **this_ptr = *reinterpret_cast<void ***>(&rules);
void **vtable = *reinterpret_cast<void ***>(rules);
void *vfunc = vtable[offset];
union
{
bool (VEmptyClass::*mfpnew)(CBaseEntity *, CBaseEntity *, const CTakeDamageInfo &);
void *addr;
} u;
u.addr = vfunc;
return (reinterpret_cast<VEmptyClass *>(this_ptr)->*u.mfpnew)(pPlayer, pAttacker, info);
}
void HelperFunction::GameRules_CleanUpMap()
{
static void *func = NULL;
if(!func)
{
if(!g_pGameConf->GetMemSig("CleanUpMap", &func))
{
assert(0);
return;
}
}
unsigned char *rules = NULL;
memcpy(&rules, reinterpret_cast<void*>(my_g_pGameRules), sizeof(char*));
typedef void (__fastcall *_func)(void *, int);
_func thisfunc = (_func)func;
thisfunc(rules, 0);
}
CViewVectors *HelperFunction::GameRules_GetViewVectors()
{
static int offset = NULL;
if(!offset)
{
if(!g_pGameConf->GetOffset("GameRules_GetViewVectors", &offset))
{
assert(0);
return NULL;
}
}
unsigned char *rules = NULL;
memcpy(&rules, reinterpret_cast<void*>(my_g_pGameRules), sizeof(char*));
void **this_ptr = *reinterpret_cast<void ***>(&rules);
void **vtable = *reinterpret_cast<void ***>(rules);
void *vfunc = vtable[offset];
union
{
CViewVectors *(VEmptyClass::*mfpnew)();
void *addr;
} u;
u.addr = vfunc;
return (reinterpret_cast<VEmptyClass *>(this_ptr)->*u.mfpnew)();
}
Activity HelperFunction::ActivityList_RegisterPrivateActivity( const char *pszActivityName )
{
static void *func = NULL;
if(!func)
{
if(!g_pGameConf->GetMemSig("ActivityList_RegisterPrivateActivity", &func))
{
assert(0);
return ACT_INVALID;
}
}
typedef Activity (*_func)(char const *);
_func thisfunc = (_func)func;
return thisfunc(pszActivityName);
}
Animevent HelperFunction::EventList_RegisterPrivateEvent( const char *pszEventName )
{
static void *func = NULL;
if(!func)
{
if(!g_pGameConf->GetMemSig("EventList_RegisterPrivateEvent", &func))
{
assert(0);
return AE_INVALID;
}
}
typedef Animevent (*_func)(char const *);
_func thisfunc = (_func)func;
return thisfunc(pszEventName);
}
CBaseEntity *HelperFunction::NPCPhysics_CreateSolver(CBaseEntity *pNPC, CBaseEntity *c, bool disableCollisions, float separationDuration)
{
static void *func = NULL;
if(!func)
{
if(!g_pGameConf->GetMemSig("NPCPhysics_CreateSolver", &func))
{
assert(0);
return NULL;
}
}
CBaseEntity *pEntity = NULL;
typedef CBaseEntity* (*_func)(CBaseEntity *, CBaseEntity *, bool, float);
_func thisfunc = (_func)func;
pEntity = (CBaseEntity*)thisfunc(pNPC, pNPC, disableCollisions, separationDuration);
return pEntity;
}
HSOUNDSCRIPTHANDLE HelperFunction::PrecacheScriptSound(const char *soundname)
{
static void *func = NULL;
if(!func)
{
if(!g_pGameConf->GetMemSig("PrecacheScriptSound", &func))
{
assert(0);
return SOUNDEMITTER_INVALID_HANDLE;
}
}
typedef HSOUNDSCRIPTHANDLE (__fastcall *_func)(void *, int , const char *);
_func thisfunc = (_func)func;
return thisfunc(g_SoundEmitterSystem, 0, soundname);
}
void HelperFunction::EmitSoundByHandle( IRecipientFilter& filter, int entindex, const EmitSound_t & ep, HSOUNDSCRIPTHANDLE& handle )
{
static void *func = NULL;
if(!func)
{
if(!g_pGameConf->GetMemSig("EmitSoundByHandle", &func))
{
assert(0);
return;
}
}