forked from fdxx/l4d2_plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aggresive_specials_patch.sp
147 lines (114 loc) · 4.3 KB
/
aggresive_specials_patch.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
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#define VERSION "1.3"
#define MAX_PATCH_LEN 64
#define WINDOWS 1
ArrayList g_aRevert;
ConVar g_cvEnable;
enum struct RevertInfo
{
Address address;
int bytes[MAX_PATCH_LEN];
int numBytes;
}
public Plugin myinfo =
{
name = "Aggresive Specials Patch",
author = "sorallll, fdxx",
version = VERSION,
};
public void OnPluginStart()
{
CreateConVar("aggresive_specials_patch_version", VERSION, "version", FCVAR_NOTIFY | FCVAR_DONTRECORD);
g_cvEnable = CreateConVar("aggresive_specials_patch_enable", "1");
OnConVarChanged(null, "", "");
g_cvEnable.AddChangeHook(OnConVarChanged);
}
void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
OnPluginEnd();
if (g_cvEnable.BoolValue)
EnablePatch();
}
void EnablePatch()
{
delete g_aRevert;
g_aRevert = new ArrayList(sizeof(RevertInfo));
GameData hGameData = new GameData("aggresive_specials_patch");
if (hGameData == null)
SetFailState("Failed to load \"aggresive_specials_patch.txt\" gamedata.");
Address pTargetFunc;
int verify[MAX_PATCH_LEN], patch[MAX_PATCH_LEN];
int numVerify, numPatch;
pTargetFunc = GetTargetFuncAddress(hGameData, "AggresiveSpecials");
numVerify = GetBytesByGameDataKey(hGameData, "AggresiveSpecials_Verify", verify);
numPatch = GetBytesByGameDataKey(hGameData, "AggresiveSpecials_Patch", patch);
SetupPatch(verify, numVerify, patch, numPatch, "AggresiveSpecials", pTargetFunc);
pTargetFunc = GetTargetFuncAddress(hGameData, "SpecialsShouldAssault");
numVerify = GetBytesByGameDataKey(hGameData, "SpecialsShouldAssault_Verify", verify);
numPatch = GetBytesByGameDataKey(hGameData, "SpecialsShouldAssault_Patch", patch);
SetupPatch(verify, numVerify, patch, numPatch, "SpecialsShouldAssault", pTargetFunc);
delete hGameData;
}
Address GetTargetFuncAddress(GameData hGameData, const char[] name)
{
Address pAdr = hGameData.GetAddress(name);
if (pAdr == Address_Null)
SetFailState("Failed to GetAddress: %s", name);
int os = hGameData.GetOffset("os");
if (os == -1)
SetFailState("Failed to GetOffset: os");
if (os == WINDOWS)
{
Address pRelativeOffset = LoadFromAddress(pAdr + view_as<Address>(1), NumberType_Int32);
return pAdr + view_as<Address>(5) + pRelativeOffset;
}
return pAdr;
}
int GetBytesByGameDataKey(GameData hGameData, const char[] key, int[] bytes)
{
char sBuffer[MAX_PATCH_LEN*4+1];
char sBytes[MAX_PATCH_LEN][4];
int num;
if (!hGameData.GetKeyValue(key, sBuffer, sizeof(sBuffer)))
SetFailState("Failed to GetKeyValue: %s", key);
num = ExplodeString(sBuffer[2], "\\x", sBytes, sizeof(sBytes), sizeof(sBytes[]));
for (int i = 0; i < num; i++)
bytes[i] = StringToInt(sBytes[i], 16);
return num;
}
void SetupPatch(const int[] verify, int numVerify, const int[] patch, int numPatch, const char[] name, Address pBase, int offset = 0)
{
Address address = pBase + view_as<Address>(offset);
for (int i = 0; i < numVerify; i++)
{
if (verify[i] != LoadFromAddress(address + view_as<Address>(i), NumberType_Int8))
SetFailState("Failed to verify patch: %s", name);
}
RevertInfo revert;
for (int i = 0; i < numPatch; i++)
{
revert.bytes[i] = LoadFromAddress(address + view_as<Address>(i), NumberType_Int8);
StoreToAddress(address + view_as<Address>(i), patch[i], NumberType_Int8);
}
revert.address = address;
revert.numBytes = numPatch;
g_aRevert.PushArray(revert);
}
public void OnPluginEnd()
{
if (g_aRevert == null)
return;
RevertInfo revert;
for (int i = 0; i < g_aRevert.Length; i++)
{
g_aRevert.GetArray(i, revert);
for (int num = 0; num < revert.numBytes; num++)
StoreToAddress(revert.address + view_as<Address>(num), revert.bytes[num], NumberType_Int8);
}
delete g_aRevert;
}
// server_srv.so!Action<Jockey>::InvokeUpdate -> BossZombiePlayerBot::ShouldAdvanceOnSurvivors() -> CDirector::SpecialsShouldAdvanceOnSurvivors -> CDirectorChallengeMode::AggresiveSpecials -> CDirector::GetScriptValue(TheDirector, "cm_AggressiveSpecials", 0) != 0
// JockeyBehavior::InitialContainedAction -> CDirector::SpecialsShouldAssault -> CDirectorChallengeMode::SpecialsShouldAssault -> CDirector::GetScriptValue(TheDirector, "SpecialInfectedAssault", 0) > 0