/
l4d2_dominatorscontrol.sp
96 lines (86 loc) · 2.58 KB
/
l4d2_dominatorscontrol.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
#include <sourcemod>
#define DEBUG 0
#define NUM_SI_CLASSES 6
#define DOMINATORS_DEFAULT 53
static g_iDominators = DOMINATORS_DEFAULT;
static Address:g_pDominatorsAddress = Address_Null;
static Handle:g_hCvarDominators = INVALID_HANDLE;
public Plugin:myinfo =
{
name = "Dominators Control",
author = "vintik",
description = "Changes bIsDominator flag for infected classes. Allows to have native-order quad-caps.",
version = "1.1",
url = "https://bitbucket.org/vintik/various-plugins"
}
public OnPluginStart()
{
decl String:sGame[256];
GetGameFolderName(sGame, sizeof(sGame));
if (!StrEqual(sGame, "left4dead2", false))
{
SetFailState("Plugin 'Dominators Control' supports Left 4 Dead 2 only!");
}
new Handle:hGConf = LoadGameConfigFile("l4d2_dominators");
if ((hGConf == INVALID_HANDLE)
|| (g_pDominatorsAddress = GameConfGetAddress(hGConf, "bIsDominator")) == Address_Null)
{
SetFailState("Can't find 'bIsDominator' signature!");
}
#if DEBUG
PrintToServer("[DEBUG] bIsDominator's signature is found. Address: %08x", g_pDominatorsAddress);
#endif
g_hCvarDominators = CreateConVar("l4d2_dominators", "53",
"Which infected class is considered as dominator (bitmask: 1 - smoker, 2 - boomer, 4 - hunter, 8 - spitter, 16 - jockey, 32 - charger)");
new iCvarValue = GetConVarInt(g_hCvarDominators);
if (!IsValidCvarValue(iCvarValue))
{
SetConVarInt(g_hCvarDominators, DOMINATORS_DEFAULT);
iCvarValue = DOMINATORS_DEFAULT;
}
if (g_iDominators != iCvarValue)
{
g_iDominators = iCvarValue;
SetDominators();
}
HookConVarChange(g_hCvarDominators, OnCvarDominatorsChange);
}
public OnPluginEnd()
{
g_iDominators = DOMINATORS_DEFAULT;
SetDominators();
}
public OnCvarDominatorsChange(Handle:hCvar, const String:sOldVal[], const String:sNewVal[])
{
new iNewVal = StringToInt(sNewVal);
if (iNewVal == g_iDominators) return;
if (IsValidCvarValue(iNewVal))
{
g_iDominators = iNewVal;
#if DEBUG
PrintToServer("[DEBUG] sm_dominators changed to %d", g_iDominators);
#endif
SetDominators();
}
else
{
PrintToChatAll("[SM] Incorrect value of 'sm_dominators'! min: 0, max: %d", (1 << NUM_SI_CLASSES) - 1);
SetConVarString(hCvar, sOldVal);
}
}
stock bool:IsValidCvarValue(iValue)
{
return ((iValue >= 0) && (iValue < (1 << NUM_SI_CLASSES)));
}
stock SetDominators()
{
new bool:bIsDominator;
for (new i = 0; i < NUM_SI_CLASSES; i++)
{
bIsDominator = (((1 << i) & g_iDominators) != 0);
#if DEBUG
PrintToServer("[DEBUG] Class %d is %sdominator now", i, bIsDominator ? "" : "NOT ");
#endif
StoreToAddress(g_pDominatorsAddress + Address:i, _:bIsDominator, NumberType_Int8);
}
}