-
Notifications
You must be signed in to change notification settings - Fork 9
/
left4dhooks.sp
1656 lines (1291 loc) · 54.1 KB
/
left4dhooks.sp
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
/*
* Left 4 DHooks Direct
* Copyright (C) 2024 Silvers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 <https://www.gnu.org/licenses/>.
*/
#define PLUGIN_VERSION "1.150"
#define PLUGIN_VERLONG 1150
#define DEBUG 0
// #define DEBUG 1 // Prints addresses + detour info (only use for debugging, slows server down).
#define DETOUR_ALL 0 // Only enable required detours, for public release.
// #define DETOUR_ALL 1 // Enable all detours, for testing.
#define KILL_VSCRIPT 0 // 0=Keep VScript entity after using for "GetVScriptOutput". 1=Kill the entity after use (more resourceful to keep recreating, use if you're maxing out entities and reaching the limit regularly).
#define ALLOW_UPDATER 1 // 0=Off. 1=Allow the plugin to auto-update using the "Updater" plugin by "GoD-Tony". 2=Allow updating and reloading after update.
/*======================================================================================
Plugin Info:
* Name : [L4D & L4D2] Left 4 DHooks Direct
* Author : SilverShot
* Descrp : Left 4 Downtown and L4D Direct conversion and merger.
* Link : https://forums.alliedmods.net/showthread.php?t=321696
* Plugins : https://sourcemod.net/plugins.php?exact=exact&sortby=title&search=1&author=Silvers
========================================================================================
Change Log:
- See forum thread: https://forums.alliedmods.net/showthread.php?t=321696
- OR: See the "scripting/l4dd/left4dhooks_changelog.txt" file.
========================================================================================
To Do:
Re-write dynamic detour enabler?
- All working but looks ugly. Could be cleaner?
- Optional extra-api.ext support
========================================================================================
Thanks:
This plugin was made using source code from the following plugins.
If I have used your code and not credited you, please let me know.
* Original Left4Downtown extension: https://forums.alliedmods.net/showthread.php?t=91132
"Downtown1" and "XBetaAlpha" - authors of the original Left4Downtown.
"pRED*" for his TF2 tools code, I looked at it a lot . and for answering questions on IRC
"Fyren" for being so awesome and inspiring me from his sdktools patch to do custom |this| calls.
"ivailosp" for providing the Windows addresses that needed to be patched to get player slot unlocking to work.
"dvander" for making sourcemod and teaching me about the mod r/m bytes.
"DDRKhat" for letting me use his Linux server to test this.
"Frustian" for being a champ and poking around random Linux sigs so I could the one native I actually needed.
"XBetaAlpha" for making this a team effort rather than one guy writing all the code.
* Original Left4Downtown2 extension: https://forums.alliedmods.net/showthread.php?t=134032
"Downtown1" and "XBetaAlpha" - authors of the original Left4Downtown.
"ProdigySim" - Confogl developer interested in expanding and updating Left4Downtown.
"AtomicStryker" - Sourcemod plugin developer, and part of the original Left4Downtown team.
"psychonic" - Resident Sourcemod insider, started Left4Downtown2.
"asherkin" - Hosting the autobuild server.
"CanadaRox", "vintik", "rochellecrab", and anyone else who has submitted code in any way.
* Left 4 Downtown 2 Extension updates: https://forums.alliedmods.net/showpost.php?p=1970730&postcount=397?p=1970730&postcount=397
"Visor" for "l4d2_addons_eclipse" cvar and new forwards.
* Left 4 Downtown 2 Extension updates
"Attano" for various github commits.
* Left 4 Downtown 2 Extension updates
"Accelerator74" for various github commits.
* "ProdigySim" and the "ConfoglTeam" for "L4D2Direct" plugin:
https://forums.alliedmods.net/showthread.php?t=180028
* "raziEiL" for "L4D_Direct Port" offsets and addresses:
https://github.com/raziEiL/l4d_direct-port
* "AtomicStryker" and whoever else contributed to "l4d2addresses.txt" gamedata file.
* "Dragokas" for "String Tables Dumper" some code used to get melee weapon IDs.
https://forums.alliedmods.net/showthread.php?t=322674
* "Dysphie" for "ReadMemoryString" function code.
===================================================================================================*/
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdkhooks>
#include <dhooks>
#include <left4dhooks>
// ====================================================================================================
// UPDATER
#define UPDATE_URL "https://raw.githubusercontent.com/SilvDev/Left4DHooks/main/sourcemod/updater.txt"
native void Updater_AddPlugin(const char[] url);
// ====================================================================================================
// PROFILER
#if DEBUG
#include <profiler>
Profiler g_vProf;
float g_fProf;
#endif
// NEW SOURCEMOD ONLY
#if SOURCEMOD_V_MINOR < 11
#error Plugin "Left 4 DHooks" only supports SourceMod version 1.11 and newer
#endif
// Plugin
#define GAMEDATA_1 "left4dhooks.l4d1"
#define GAMEDATA_2 "left4dhooks.l4d2"
#define GAMEDATA_TEMP "left4dhooks.temp"
#define NATIVE_UNSUPPORTED1 "\n==========\nThis Native is only supported in L4D1.\nPlease fix the code to avoid calling this native from L4D2.\n=========="
#define NATIVE_UNSUPPORTED2 "\n==========\nThis Native is only supported in L4D2.\nPlease fix the code to avoid calling this native from L4D1.\n=========="
#define NATIVE_TOO_EARLY "\n==========\nNative '%s' should not be used before OnMapStart, please report to 3rd party plugin author.\n=========="
#define COMPILE_FROM_MAIN true
// Tank animations
#define L4D2_ACT_HULK_THROW 761
#define L4D2_ACT_TANK_OVERHEAD_THROW 762
#define L4D2_ACT_HULK_ATTACK_LOW 763
#define L4D2_ACT_TERROR_ATTACK_MOVING 790
#define L4D2_SEQ_PUNCH_UPPERCUT 40
#define L4D2_SEQ_PUNCH_RIGHT_HOOK 43
#define L4D2_SEQ_PUNCH_LEFT_HOOK 45
#define L4D2_SEQ_PUNCH_POUND_GROUND1 46
#define L4D2_SEQ_PUNCH_POUND_GROUND2 47
#define L4D2_SEQ_THROW_UNDERCUT 48
#define L4D2_SEQ_THROW_1HAND_OVER 49
#define L4D2_SEQ_THROW_FROM_HIP 50
#define L4D2_SEQ_THROW_2HAND_OVER 51
#define L4D1_ACT_HULK_THROW 1254
#define L4D1_ACT_TANK_OVERHEAD_THROW 1255
#define L4D1_ACT_HULK_ATTACK_LOW 1256
#define L4D1_ACT_TERROR_ATTACK_MOVING 1282
#define L4D1_SEQ_PUNCH_UPPERCUT 38
#define L4D1_SEQ_PUNCH_RIGHT_HOOK 41
#define L4D1_SEQ_PUNCH_LEFT_HOOK 43
#define L4D1_SEQ_PUNCH_POUND_GROUND1 44
#define L4D1_SEQ_PUNCH_POUND_GROUND2 45
#define L4D1_SEQ_THROW_UNDERCUT 46
#define L4D1_SEQ_THROW_1HAND_OVER 47
#define L4D1_SEQ_THROW_FROM_HIP 48
#define L4D1_SEQ_THROW_2HAND_OVER 49
// Dissolver
#define SPRITE_GLOW "sprites/blueglow1.vmt"
// GasCan model for damage hook
#define MODEL_GASCAN "models/props_junk/gascan001a.mdl"
// PipeBomb particles
#define PARTICLE_FUSE "weapon_pipebomb_fuse"
#define PARTICLE_LIGHT "weapon_pipebomb_blinking_light"
// Precache models for spawning
static const char g_sModels1[][] =
{
"models/infected/witch.mdl",
"models/infected/hulk.mdl",
"models/infected/smoker.mdl",
"models/infected/boomer.mdl",
"models/infected/hunter.mdl"
};
static const char g_sModels2[][] =
{
"models/infected/witch_bride.mdl",
"models/infected/spitter.mdl",
"models/infected/jockey.mdl",
"models/infected/charger.mdl"
};
// Dynamic Detours:
#define MAX_FWD_LEN 64 // Maximum string length of forward and signature names, used for ArrayList
// ToDo: When using extra-api.ext (or hopefully one day native SM forwards), g_aDetoursHooked will store the number of plugins using each forward
// so we can disable when the value is 0 and not have to check all plugins just to determine if still required
ArrayList g_aDetoursHooked; // Identifies if the detour hook is enabled or disabled
ArrayList g_aDetourHandles; // Stores detour handles to enable/disable as required
ArrayList g_aGameDataSigs; // Stores Signature names
ArrayList g_aForwardNames; // Stores Forward names
ArrayList g_aUseLastIndex; // Use last index
ArrayList g_aForwardIndex; // Stores Detour indexes
ArrayList g_aForceDetours; // Determines if a detour should be forced on without any forward using it
ArrayList g_aDetourHookIDsPre; // Hook IDs created by DynamicHook type detours
ArrayList g_aDetourHookIDsPost; // Hook IDs created by DynamicHook type detours
int g_iSmallIndex; // Index for each detour while created
int g_iLargeIndex; // Index for each detour while created
bool g_bCreatedDetours; // To determine first time creation of detours, or if enabling or disabling
float g_fLoadTime; // When the plugin was loaded, to ignore when "AP_OnPluginUpdate" fires
Handle g_hThisPlugin; // Ignore checking this plugin
GameData g_hGameData; // GameData file - to speed up loading
GameData g_hTempGameData; // TempGameData file
int g_iScriptVMDetourIndex;
float g_fCvar_Adrenaline, g_fCvar_PillsDecay;
int g_iCvar_AddonsEclipse, g_iCvar_RescueDeadTime;
// Animation Hook
int g_iAnimationDetourIndex;
bool g_bAnimationRemoveHook;
ArrayList g_iAnimationHookedClients;
ArrayList g_iAnimationHookedPlugins;
ArrayList g_hAnimationActivityList;
PrivateForward g_hAnimationCallbackPre[MAXPLAYERS+1];
PrivateForward g_hAnimationCallbackPost[MAXPLAYERS+1];
// Weapons
StringMap g_aWeaponPtrs; // Stores weapon pointers to retrieve CCSWeaponInfo and CTerrorWeaponInfo data
StringMap g_aWeaponIDs; // Store weapon IDs to get above pointers
StringMap g_aMeleeIDs; // Store melee IDs
ArrayList g_aMeleePtrs; // Stores melee pointers
// Offsets - Addons Eclipse
int g_iOff_AddonEclipse1;
int g_iOff_AddonEclipse2;
int g_iOff_VanillaModeOffset;
Address g_pVanillaModeAddress;
// Various offsets
int g_iOff_LobbyReservation;
int g_iOff_VersusStartTimer;
int g_iOff_m_rescueCheckTimer;
int g_iOff_m_iszScriptId;
int g_iOff_m_flBecomeGhostAt;
int g_iOff_MobSpawnTimer;
int g_iOff_m_iSetupNotifyTime;
int g_iOff_VersusMaxCompletionScore;
int g_iOff_OnBeginRoundSetupTime;
int g_iOff_m_iTankCount;
int g_iOff_m_iWitchCount;
int g_iOff_m_PlayerAnimState;
int g_iOff_m_eCurrentMainSequenceActivity;
int g_iOff_m_bIsCustomSequence;
int g_iOff_m_iCampaignScores;
int g_iOff_m_fTankSpawnFlowPercent;
int g_iOff_m_fWitchSpawnFlowPercent;
int g_iOff_m_iTankPassedCount;
int g_iOff_m_bTankThisRound;
int g_iOff_m_bWitchThisRound;
int g_iOff_OvertimeGraceTimer;
int g_iOff_InvulnerabilityTimer;
int g_iOff_m_iTankTickets;
int g_iOff_m_iSurvivorHealthBonus;
int g_iOff_m_bFirstSurvivorLeftStartArea;
// int g_iOff_m_iShovePenalty;
// int g_iOff_m_fNextShoveTime;
int g_iOff_m_preIncapacitatedHealth;
int g_iOff_m_preIncapacitatedHealthBuffer;
int g_iOff_m_maxFlames;
int g_iOff_m_flow;
int g_iOff_m_PendingMobCount;
int g_iOff_m_nFirstClassIndex;
int g_iOff_m_fMapMaxFlowDistance;
int g_iOff_m_chapter;
int g_iOff_m_attributeFlags;
int g_iOff_m_spawnAttributes;
int g_iOff_NavAreaID;
// int g_iOff_m_iClrRender; // NULL PTR - METHOD (kept for demonstration)
// int ClearTeamScore_A;
// int ClearTeamScore_B;
// Address TeamScoresAddress;
// l4d2timers.inc
int L4D2CountdownTimer_Offsets[10];
int L4D2IntervalTimer_Offsets[6];
// l4d2weapons.inc
int L4D2IntWeapon_Offsets[7];
int L4D2FloatWeapon_Offsets[21];
int L4D2BoolMeleeWeapon_Offsets[1];
int L4D2IntMeleeWeapon_Offsets[2];
int L4D2FloatMeleeWeapon_Offsets[3];
// Pointers
int g_pScriptedEventManager;
int g_pVersusMode;
int g_pSurvivalMode;
int g_pScavengeMode;
Address g_pServer;
Address g_pAmmoDef;
Address g_pDirector;
Address g_pGameRules;
Address g_pTheNavAreas;
Address g_pTheNavAreas_List;
Address g_pTheNavAreas_Size;
Address g_pNavMesh;
Address g_pZombieManager;
Address g_pMeleeWeaponInfoStore;
Address g_pWeaponInfoDatabase;
Address g_pScriptVM;
Address g_pCTerrorPlayer_CanBecomeGhost;
// CanBecomeGhost patch
ArrayList g_hCanBecomeGhost;
int g_iCanBecomeGhostOffset;
// Other
Address g_pScriptId;
int g_iCancelStagger[MAXPLAYERS+1];
int g_iPlayerResourceRef;
int g_iOffsetAmmo;
int g_iPrimaryAmmoType;
int g_iCurrentMode;
int g_iMaxChapters;
int g_iClassTank;
int g_iGasCanModel;
char g_sSystem[16];
bool g_bLinuxOS;
bool g_bLeft4Dead2;
bool g_bFinalCheck;
bool g_bMapStarted;
bool g_bRoundEnded;
bool g_bCheckpointFirst[MAXPLAYERS+1];
bool g_bCheckpointLast[MAXPLAYERS+1];
ConVar g_hCvar_VScriptBuffer;
ConVar g_hCvar_AddonsEclipse;
ConVar g_hCvar_RescueDeadTime;
ConVar g_hCvar_PillsDecay;
ConVar g_hCvar_Adrenaline;
ConVar g_hCvar_Revives;
ConVar g_hCvar_MPGameMode;
DynamicHook g_hScriptHook;
#if DEBUG
bool g_bLateLoad;
#endif
// TARGET FILTERS
#include "l4dd/l4dd_targetfilters.sp"
// NATIVES
#include "l4dd/l4dd_natives.sp"
// DETOURS - FORWARDS
#include "l4dd/l4dd_forwards.sp"
// GAMEDATA
#include "l4dd/l4dd_gamedata.sp"
// SETUP FORWARDS AND NATIVES
#include "l4dd/l4dd_setup.sp"
// ====================================================================================================
// PLUGIN INFO / START
// ====================================================================================================
public Plugin myinfo =
{
name = "[L4D & L4D2] Left 4 DHooks Direct",
author = "SilverShot",
description = "Left 4 Downtown and L4D Direct conversion and merger.",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=321696"
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
EngineVersion test = GetEngineVersion();
if( test == Engine_Left4Dead ) g_bLeft4Dead2 = false;
else if( test == Engine_Left4Dead2 ) g_bLeft4Dead2 = true;
else
{
strcopy(error, err_max, "Plugin only supports Left 4 Dead 1 & 2.");
return APLRes_SilentFailure;
}
#if DEBUG
g_bLateLoad = late;
#endif
g_hThisPlugin = myself;
// =================
// UPDATER
// =================
MarkNativeAsOptional("Updater_AddPlugin");
// =================
// DUPLICATE PLUGIN RUNNING
// =================
if( GetFeatureStatus(FeatureType_Native, "L4D_BecomeGhost") == FeatureStatus_Available )
{
strcopy(error, err_max, "\n====================\nPlugin \"Left 4 DHooks\" is already running. Please remove the duplicate plugin.\n====================");
return APLRes_SilentFailure;
}
// =================
// EXTENSION BLOCK
// =================
if( GetFeatureStatus(FeatureType_Native, "L4D_RestartScenarioFromVote") != FeatureStatus_Unknown )
{
strcopy(error, err_max, "\n====================\nThis plugin replaces Left4Downtown. Delete the extension to run.\n====================");
return APLRes_SilentFailure;
}
// =================
// SETUP FORWARDS AND NATIVES
// =================
SetupForwardsNatives(); // From: "l4dd/l4dd_setup.sp"
// =================
// END SETUP
// =================
RegPluginLibrary("left4dhooks");
return APLRes_Success;
}
// ====================================================================================================
// UPDATER
// ====================================================================================================
#if ALLOW_UPDATER
public void OnLibraryAdded(const char[] name)
{
if( strcmp(name, "updater") == 0 )
{
Updater_AddPlugin(UPDATE_URL);
}
}
#endif
#if ALLOW_UPDATER == 2
public void Updater_OnPluginUpdated()
{
char filename[64];
GetPluginFilename(null, filename, sizeof(filename));
ServerCommand("sm plugins reload %s", filename);
}
#endif
// ====================================================================================================
// SETUP
// ====================================================================================================
public void OnPluginStart()
{
g_fLoadTime = GetEngineTime();
g_iClassTank = g_bLeft4Dead2 ? 8 : 5;
g_hCanBecomeGhost = new ArrayList();
g_iOffsetAmmo = FindSendPropInfo("CTerrorPlayer", "m_iAmmo");
g_iPrimaryAmmoType = FindSendPropInfo("CBaseCombatWeapon", "m_iPrimaryAmmoType");
// NULL PTR - METHOD (kept for demonstration)
// Null pointer - by Dragokas
/*
g_iOff_m_iClrRender = FindSendPropInfo("CBaseEntity", "m_clrRender");
if( g_iOff_m_iClrRender == -1 )
{
SetFailState("Error: m_clrRender not found.");
}
*/
// ====================================================================================================
// LOAD GAMEDATA
// ====================================================================================================
LoadGameData();
// ====================================================================================================
// TARGET FILTERS
// ====================================================================================================
LoadTargetFilters();
// ====================================================================================================
// ANIMMATION HOOK
// ====================================================================================================
g_hAnimationActivityList = new ArrayList(ByteCountToCells(48));
ParseActivityConfig();
g_iAnimationHookedClients = new ArrayList();
g_iAnimationHookedPlugins = new ArrayList(2);
for( int i = 1; i <= MaxClients; i++ )
{
g_hAnimationCallbackPre[i] = new PrivateForward(ET_Event, Param_Cell, Param_CellByRef);
g_hAnimationCallbackPost[i] = new PrivateForward(ET_Event, Param_Cell, Param_CellByRef);
}
// ====================================================================================================
// WEAPON IDS
// ====================================================================================================
g_aWeaponPtrs = new StringMap();
g_aWeaponIDs = new StringMap();
if( !g_bLeft4Dead2 )
{
g_aWeaponIDs.SetValue("weapon_none", 0);
g_aWeaponIDs.SetValue("weapon_pistol", 1);
g_aWeaponIDs.SetValue("weapon_smg", 2);
g_aWeaponIDs.SetValue("weapon_pumpshotgun", 3);
g_aWeaponIDs.SetValue("weapon_autoshotgun", 4);
g_aWeaponIDs.SetValue("weapon_rifle", 5);
g_aWeaponIDs.SetValue("weapon_hunting_rifle", 6);
g_aWeaponIDs.SetValue("weapon_first_aid_kit", 8);
g_aWeaponIDs.SetValue("weapon_molotov", 9);
g_aWeaponIDs.SetValue("weapon_pipe_bomb", 10);
g_aWeaponIDs.SetValue("weapon_pain_pills", 12);
g_aWeaponIDs.SetValue("weapon_gascan", 14);
g_aWeaponIDs.SetValue("weapon_propanetank", 15);
g_aWeaponIDs.SetValue("weapon_oxygentank", 16);
g_aWeaponIDs.SetValue("weapon_tank_claw", 17);
g_aWeaponIDs.SetValue("weapon_hunter_claw", 18);
g_aWeaponIDs.SetValue("weapon_boomer_claw", 19);
g_aWeaponIDs.SetValue("weapon_smoker_claw", 20);
g_aWeaponIDs.SetValue("weapon_ammo_spawn", 29);
} else {
g_aWeaponIDs.SetValue("weapon_none", 0);
g_aWeaponIDs.SetValue("weapon_pistol", 1);
g_aWeaponIDs.SetValue("weapon_smg", 2);
g_aWeaponIDs.SetValue("weapon_pumpshotgun", 3);
g_aWeaponIDs.SetValue("weapon_autoshotgun", 4);
g_aWeaponIDs.SetValue("weapon_rifle", 5);
g_aWeaponIDs.SetValue("weapon_hunting_rifle", 6);
g_aWeaponIDs.SetValue("weapon_smg_silenced", 7);
g_aWeaponIDs.SetValue("weapon_shotgun_chrome", 8);
g_aWeaponIDs.SetValue("weapon_rifle_desert", 9);
g_aWeaponIDs.SetValue("weapon_sniper_military", 10);
g_aWeaponIDs.SetValue("weapon_shotgun_spas", 11);
g_aWeaponIDs.SetValue("weapon_first_aid_kit", 12);
g_aWeaponIDs.SetValue("weapon_molotov", 13);
g_aWeaponIDs.SetValue("weapon_pipe_bomb", 14);
g_aWeaponIDs.SetValue("weapon_pain_pills", 15);
g_aWeaponIDs.SetValue("weapon_gascan", 16);
g_aWeaponIDs.SetValue("weapon_propanetank", 17);
g_aWeaponIDs.SetValue("weapon_oxygentank", 18);
g_aWeaponIDs.SetValue("weapon_melee", 19);
g_aWeaponIDs.SetValue("weapon_chainsaw", 20);
g_aWeaponIDs.SetValue("weapon_grenade_launcher", 21);
// g_aWeaponIDs.SetValue("weapon_ammo_pack", 22); // Unavailable
g_aWeaponIDs.SetValue("weapon_adrenaline", 23);
g_aWeaponIDs.SetValue("weapon_defibrillator", 24);
g_aWeaponIDs.SetValue("weapon_vomitjar", 25);
g_aWeaponIDs.SetValue("weapon_rifle_ak47", 26);
g_aWeaponIDs.SetValue("weapon_gnome", 27);
g_aWeaponIDs.SetValue("weapon_cola_bottles", 28);
g_aWeaponIDs.SetValue("weapon_fireworkcrate", 29);
g_aWeaponIDs.SetValue("weapon_upgradepack_incendiary", 30);
g_aWeaponIDs.SetValue("weapon_upgradepack_explosive", 31);
g_aWeaponIDs.SetValue("weapon_pistol_magnum", 32);
g_aWeaponIDs.SetValue("weapon_smg_mp5", 33);
g_aWeaponIDs.SetValue("weapon_rifle_sg552", 34);
g_aWeaponIDs.SetValue("weapon_sniper_awp", 35);
g_aWeaponIDs.SetValue("weapon_sniper_scout", 36);
g_aWeaponIDs.SetValue("weapon_rifle_m60", 37);
g_aWeaponIDs.SetValue("weapon_tank_claw", 38);
g_aWeaponIDs.SetValue("weapon_hunter_claw", 39);
g_aWeaponIDs.SetValue("weapon_charger_claw", 40);
g_aWeaponIDs.SetValue("weapon_boomer_claw", 41);
g_aWeaponIDs.SetValue("weapon_smoker_claw", 42);
g_aWeaponIDs.SetValue("weapon_spitter_claw", 43);
g_aWeaponIDs.SetValue("weapon_jockey_claw", 44);
g_aWeaponIDs.SetValue("weapon_ammo_spawn", 54);
g_aMeleePtrs = new ArrayList(2);
g_aMeleeIDs = new StringMap();
g_aMeleeIDs.SetValue("fireaxe", 0);
g_aMeleeIDs.SetValue("frying_pan", 1);
g_aMeleeIDs.SetValue("machete", 2);
g_aMeleeIDs.SetValue("baseball_bat", 3);
g_aMeleeIDs.SetValue("crowbar", 4);
g_aMeleeIDs.SetValue("cricket_bat", 5);
g_aMeleeIDs.SetValue("tonfa", 6);
g_aMeleeIDs.SetValue("katana", 7);
g_aMeleeIDs.SetValue("electric_guitar", 8);
g_aMeleeIDs.SetValue("knife", 9);
g_aMeleeIDs.SetValue("golfclub", 10);
g_aMeleeIDs.SetValue("pitchfork", 11);
g_aMeleeIDs.SetValue("shovel", 12);
}
// ====================================================================================================
// COMMANDS
// ====================================================================================================
// When adding or removing plugins that use any detours during gameplay. To optimize forwards by disabling unused or enabling required functions that were previously unused. TODO: Not needed when using extra-api.ext
RegAdminCmd("sm_l4dd_unreserve", CmdLobby, ADMFLAG_ROOT, "Removes lobby reservation.");
RegAdminCmd("sm_l4dd_reload", CmdReload, ADMFLAG_ROOT, "Reloads the detour hooks, enabling or disabling depending if they're required by other plugins.");
RegAdminCmd("sm_l4dd_detours", CmdDetours, ADMFLAG_ROOT, "Lists the currently active forwards and the plugins using them.");
RegAdminCmd("sm_l4dhooks_reload", CmdReload, ADMFLAG_ROOT, "Reloads the detour hooks, enabling or disabling depending if they're required by other plugins.");
RegAdminCmd("sm_l4dhooks_detours", CmdDetours, ADMFLAG_ROOT, "Lists the currently active forwards and the plugins using them.");
// ====================================================================================================
// CVARS
// ====================================================================================================
ConVar hVersion = CreateConVar("left4dhooks_version", PLUGIN_VERSION, "Left 4 DHooks Direct plugin version.", FCVAR_NOTIFY|FCVAR_DONTRECORD);
hVersion.SetString(PLUGIN_VERSION); // Force version cvar to update if server updates the plugin but doesn't reboot, so it's reporting the current version in use
if( g_bLeft4Dead2 )
{
g_hCvar_VScriptBuffer = CreateConVar("l4d2_vscript_return", "", "Buffer used to return VScript values. Do not use.", FCVAR_DONTRECORD);
g_hCvar_AddonsEclipse = CreateConVar("l4d2_addons_eclipse", "-1", "Addons Manager (-1: use addonconfig; 0: disable addons; 1: enable addons.)", FCVAR_NOTIFY);
AutoExecConfig(true, "left4dhooks");
g_hCvar_AddonsEclipse.AddChangeHook(ConVarChanged_Addons);
g_iCvar_AddonsEclipse = g_hCvar_AddonsEclipse.IntValue;
g_hCvar_Adrenaline = FindConVar("adrenaline_health_buffer");
g_hCvar_Adrenaline.AddChangeHook(ConVarChanged_Cvars);
g_fCvar_Adrenaline = g_hCvar_Adrenaline.FloatValue;
} else {
g_hCvar_Revives = FindConVar("survivor_max_incapacitated_count");
}
g_hCvar_PillsDecay = FindConVar("pain_pills_decay_rate");
g_hCvar_PillsDecay.AddChangeHook(ConVarChanged_Cvars);
g_fCvar_PillsDecay = g_hCvar_PillsDecay.FloatValue;
g_hCvar_RescueDeadTime = FindConVar("rescue_min_dead_time");
g_hCvar_RescueDeadTime.AddChangeHook(ConVarChanged_Cvars);
g_iCvar_RescueDeadTime = g_hCvar_RescueDeadTime.IntValue;
g_hCvar_MPGameMode = FindConVar("mp_gamemode");
g_hCvar_MPGameMode.AddChangeHook(ConVarChanged_Mode);
// ====================================================================================================
// EVENTS
// ====================================================================================================
HookEvent("round_start", Event_RoundStart);
if( !g_bLeft4Dead2 )
{
HookEvent("round_end", Event_RoundEnd);
HookEvent("player_entered_start_area", Event_EnteredStartArea);
HookEvent("player_left_start_area", Event_LeftStartArea);
HookEvent("player_entered_checkpoint", Event_EnteredCheckpoint);
HookEvent("player_left_checkpoint", Event_LeftCheckpoint);
}
}
void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
g_bRoundEnded = false;
}
void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
ResetVars();
}
void Event_EnteredStartArea(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
g_bCheckpointFirst[client] = true;
}
void Event_LeftStartArea(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
g_bCheckpointFirst[client] = false;
}
void Event_EnteredCheckpoint(Event event, const char[] name, bool dontBroadcast)
{
int client = event.GetInt("userid");
if( client )
{
client = GetClientOfUserId(client);
if( client )
{
int door = event.GetInt("door");
if( door == GetCheckpointFirst() )
{
g_bCheckpointFirst[client] = true;
}
else if( door == GetCheckpointLast() )
{
g_bCheckpointLast[client] = true;
}
}
}
}
void Event_LeftCheckpoint(Event event, const char[] name, bool dontBroadcast)
{
int client = event.GetInt("userid");
if( client )
{
client = GetClientOfUserId(client);
if( client )
{
g_bCheckpointFirst[client] = false;
g_bCheckpointLast[client] = false;
}
}
}
// ====================================================================================================
// CLEAN UP
// ====================================================================================================
public void OnPluginEnd()
{
// Unpatch AddonsDisabler
if( g_bLeft4Dead2 )
AddonsDisabler_Unpatch();
// Unpatch CanBecomeGhost
int count = g_hCanBecomeGhost.Length;
for( int i = 0; i < count; i++ )
{
StoreToAddress(g_pCTerrorPlayer_CanBecomeGhost + view_as<Address>(g_iCanBecomeGhostOffset + i), g_hCanBecomeGhost.Get(i), NumberType_Int8, true);
}
// Target Filters
UnloadTargetFilters();
}
void ResetVars()
{
// Reset L4D1 variables
if( !g_bLeft4Dead2 )
{
for( int i = 1; i <= MaxClients; i++ )
{
// Reset checkpoints
g_bCheckpointFirst[i] = false;
g_bCheckpointLast[i] = false;
// Reset stagger hooks
if( g_iCancelStagger[i] )
SDKUnhook(i, SDKHook_PostThinkPost, OnThinkCancelStagger);
g_iCancelStagger[i] = 0;
}
}
}
// ====================================================================================================
// GAME MODE
// ====================================================================================================
void ConVarChanged_Mode(Handle convar, const char[] oldValue, const char[] newValue)
{
// Want to rescan max chapters on mode change
g_iMaxChapters = 0;
// For game mode native/forward
GetGameMode();
}
void GetGameMode() // Forward "L4D_OnGameModeChange"
{
g_iCurrentMode = 0;
static char sMode[10];
if( g_bLeft4Dead2 )
{
ValidateAddress(g_pDirector, "g_pDirector");
ValidateNatives(g_hSDK_CDirector_GetGameModeBase, "CDirector::GetGameModeBase");
//PrintToServer("#### CALL g_hSDK_CDirector_GetGameModeBase");
SDKCall(g_hSDK_CDirector_GetGameModeBase, g_pDirector, sMode, sizeof(sMode));
if( strcmp(sMode, "coop") == 0 ) g_iCurrentMode = GAMEMODE_COOP;
else if( strcmp(sMode, "realism") == 0 ) g_iCurrentMode = GAMEMODE_COOP;
else if( strcmp(sMode, "survival") == 0 ) g_iCurrentMode = GAMEMODE_SURVIVAL;
else if( strcmp(sMode, "versus") == 0 ) g_iCurrentMode = GAMEMODE_VERSUS;
else if( strcmp(sMode, "scavenge") == 0 ) g_iCurrentMode = GAMEMODE_SCAVENGE;
} else {
g_hCvar_MPGameMode.GetString(sMode, sizeof(sMode));
if( strcmp(sMode, "coop") == 0 ) g_iCurrentMode = GAMEMODE_COOP;
else if( strcmp(sMode, "survival") == 0 ) g_iCurrentMode = GAMEMODE_SURVIVAL;
else if( strcmp(sMode, "versus") == 0 ) g_iCurrentMode = GAMEMODE_VERSUS;
}
// Forward
static int mode;
if( mode != g_iCurrentMode )
{
mode = g_iCurrentMode;
Call_StartForward(g_hFWD_GameModeChange);
Call_PushCell(mode);
Call_Finish();
}
}
int Native_Internal_GetGameMode(Handle plugin, int numParams) // Native "L4D_GetGameModeType"
{
return g_iCurrentMode;
}
int Native_CTerrorGameRules_IsGenericCooperativeMode(Handle plugin, int numParams) // Native "L4D2_IsGenericCooperativeMode"
{
if( !g_bLeft4Dead2 ) ThrowNativeError(SP_ERROR_NOT_RUNNABLE, NATIVE_UNSUPPORTED2);
if( !g_bMapStarted )
{
ThrowNativeError(SP_ERROR_NOT_RUNNABLE, NATIVE_TOO_EARLY, "L4D2_IsGenericCooperativeMode");
return false;
}
ValidateAddress(g_pGameRules, "g_pGameRules");
ValidateNatives(g_hSDK_CTerrorGameRules_IsGenericCooperativeMode, "CTerrorGameRules::IsGenericCooperativeMode");
//PrintToServer("#### CALL g_hSDK_CTerrorGameRules_IsGenericCooperativeMode");
return SDKCall(g_hSDK_CTerrorGameRules_IsGenericCooperativeMode, g_pGameRules);
}
int Native_Internal_IsCoopMode(Handle plugin, int numParams) // Native "L4D_IsCoopMode"
{
if( g_iCurrentMode == GAMEMODE_COOP && g_bLeft4Dead2 )
{
if( !g_bMapStarted )
{
ThrowNativeError(SP_ERROR_NOT_RUNNABLE, NATIVE_TOO_EARLY, "L4D_IsCoopMode");
return false;
}
ValidateAddress(g_pGameRules, "g_pGameRules");
ValidateNatives(g_hSDK_CTerrorGameRules_IsRealismMode, "CTerrorGameRules::IsRealismMode");
//PrintToServer("#### CALL g_hSDK_CTerrorGameRules_IsRealismMode");
return SDKCall(g_hSDK_CTerrorGameRules_IsRealismMode, g_pGameRules) == false;
}
return g_iCurrentMode == GAMEMODE_COOP;
}
int Native_Internal_IsRealismMode(Handle plugin, int numParams) // Native "L4D2_IsRealismMode"
{
if( !g_bLeft4Dead2 ) ThrowNativeError(SP_ERROR_NOT_RUNNABLE, NATIVE_UNSUPPORTED2);
if( !g_bMapStarted )
{
ThrowNativeError(SP_ERROR_NOT_RUNNABLE, NATIVE_TOO_EARLY, "L4D2_IsRealismMode");
return false;
}
ValidateAddress(g_pGameRules, "g_pGameRules");
ValidateNatives(g_hSDK_CTerrorGameRules_IsRealismMode, "CTerrorGameRules::IsRealismMode");
//PrintToServer("#### CALL g_hSDK_CTerrorGameRules_IsRealismMode");
return SDKCall(g_hSDK_CTerrorGameRules_IsRealismMode, g_pGameRules);
}
int Native_Internal_IsSurvivalMode(Handle plugin, int numParams) // Native "L4D_IsSurvivalMode"
{
return g_iCurrentMode == GAMEMODE_SURVIVAL;
}
int Native_Internal_IsScavengeMode(Handle plugin, int numParams) // Native "L4D2_IsScavengeMode"
{
return g_iCurrentMode == GAMEMODE_SCAVENGE;
}
int Native_Internal_IsVersusMode(Handle plugin, int numParams) // Native "L4D_IsVersusMode"
{
return g_iCurrentMode == GAMEMODE_VERSUS;
}
// ====================================================================================================
// ANIMATION HOOK
// ====================================================================================================
public void OnMapEnd()
{
// Reset vars
g_bMapStarted = false;
g_bFinalCheck = false;
g_iMaxChapters = 0;
ResetVars();
// Reset hooks - Clear causes memory leaks, delete and re-create
// g_iAnimationHookedClients.Clear();
// g_iAnimationHookedPlugins.Clear();
delete g_iAnimationHookedClients;
delete g_iAnimationHookedPlugins;
g_iAnimationHookedClients = new ArrayList();
g_iAnimationHookedPlugins = new ArrayList(2);
// Remove all hooked functions from private forward
Handle hIter = GetPluginIterator();
Handle hPlug;
// Iterate plugins - remove animation hooks
while( MorePlugins(hIter) )
{
hPlug = ReadPlugin(hIter);
for( int i = 1; i <= MaxClients; i++ )
{
g_hAnimationCallbackPre[i].RemoveAllFunctions(hPlug);
g_hAnimationCallbackPost[i].RemoveAllFunctions(hPlug);
}
}
delete hIter;
}
public void OnClientDisconnect(int client)
{
g_bCheckpointFirst[client] = false;
g_bCheckpointLast[client] = false;
// Remove client from hooked list