-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMetaHook.as
170 lines (132 loc) · 4.6 KB
/
MetaHook.as
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
const bool verbose = false;
const string bitskey = "$s_bits";
uint metachads = 0; // bitfield
int chadent = -1;
array<string> valid;
void PluginInit() {
g_Module.ScriptInfo.SetAuthor("incognico");
g_Module.ScriptInfo.SetContactInfo("https://discord.gg/qfZxWAd");
g_Hooks.RegisterHook(Hooks::Player::ClientPutInServer, @ClientPutInServer);
g_Hooks.RegisterHook(Hooks::Player::ClientDisconnect, @ClientDisconnect);
CBaseEntity@ oldchadent = g_EntityFuncs.FindEntityByTargetname(null, "_MetaChads");
if (oldchadent !is null && g_EntityFuncs.IsValidEntity(oldchadent.edict())) {
chadent = g_EntityFuncs.EntIndex(oldchadent.edict());
CustomKeyvalues@ chadkv = oldchadent.GetCustomKeyvalues();
if (chadkv.HasKeyvalue(bitskey)) {
metachads = atoui((chadkv.GetKeyvalue(bitskey)).GetString());
}
else {
CBaseEntity@ del = g_EntityFuncs.Instance(oldchadent.edict());
g_EntityFuncs.Remove(del);
MapInit();
}
}
else {
MapInit();
}
}
CClientCommand g_ReportMetahookPlugin("mh_reportplugin", "ReportPluginInfo", @ReportPluginInfo);
CClientCommand g_ListChads("chads", "ListChads", @ListChads);
void MapInit() {
metachads = 0;
valid.resize(0);
dictionary keys = {
{ "targetname", "_MetaChads" },
{ bitskey, "" + metachads }
};
CBaseEntity@ ent = g_EntityFuncs.CreateEntity("info_target", keys, true);
chadent = g_EntityFuncs.EntIndex(ent.edict());
}
HookReturnCode ClientPutInServer(CBasePlayer@ plr) {
NetworkMessage message(MSG_ONE, NetworkMessages::NetworkMessageType(39), plr.edict()); // svc_newusermsg
message.WriteByte(146); // 64 ~ 145 = SelAmmo ~ VModelPos, all of them are reserved or used by Sven Co-op
message.WriteByte(255); // 255 = variable length
message.WriteLong(0x6174654D); // 'ateM'
message.WriteLong(0x6B6F6F48); // 'kooH'
message.WriteLong(0);
message.WriteLong(0);
message.End();
RequestPlugins(EHandle(plr));
return HOOK_CONTINUE;
}
HookReturnCode ClientDisconnect(CBasePlayer@ plr) {
if (IsChad(plr)) {
ChadDisable(plr);
UpdateEnt();
}
return HOOK_CONTINUE;
}
void Invalid(const string szSteamId) {
const int idx = valid.find(szSteamId);
if (idx >= 0)
valid.removeAt(idx);
}
const bool IsValid(const string szSteamId) {
if (valid.find(szSteamId) >= 0)
return true;
return false;
}
void RequestPlugins(EHandle eplr) {
if (!eplr)
return;
CBasePlayer@ plr = cast<CBasePlayer@>(eplr.GetEntity());
const string szSteamId = g_EngineFuncs.GetPlayerAuthId(plr.edict());
valid.insertLast(szSteamId);
g_Scheduler.SetTimeout("Invalid", 2.0f, szSteamId);
NetworkMessage message(MSG_ONE, NetworkMessages::NetworkMessageType(146), plr.edict());
message.WriteLong(1); // Query plugin list
message.End();
}
void ReportPluginInfo(const CCommand@ args) {
CBasePlayer@ plr = g_ConCommandSystem.GetCurrentPlayer();
const string szSteamId = g_EngineFuncs.GetPlayerAuthId(plr.edict());
if (IsValid(szSteamId) && args.ArgC() >= 4) {
if (verbose)
g_EngineFuncs.ServerPrint("[MetaHookPlugins " + plr.pev.netname + "] #" + args[1] + " :: apiver: " + args[2] + " :: name: " + args[3] + " :: ver: " + args[4] + "\n");
if (!IsChad(plr)) {
ChadEnable(plr);
UpdateEnt();
}
}
}
void UpdateEnt() {
if (chadent != -1) {
CBaseEntity@ ent = g_EntityFuncs.Instance(chadent);
CustomKeyvalues@ chadkv = ent.GetCustomKeyvalues();
chadkv.SetKeyvalue(bitskey, string_t(string(metachads)));
}
}
void ListChads(const CCommand@ args) {
CBasePlayer@ plr = g_ConCommandSystem.GetCurrentPlayer();
g_PlayerFuncs.ClientPrint(plr, HUD_PRINTCONSOLE, "CHADS (MetaHookSv users)\n------------------------\n");
array<string> tmp;
for (int i = 1; i <= g_Engine.maxClients; i++) {
CBasePlayer@ chad = g_PlayerFuncs.FindPlayerByIndex(i);
if (chad is null || !chad.IsConnected())
continue;
if (IsChad(chad))
tmp.insertLast(string(chad.pev.netname));
}
if (tmp.length() > 0) {
tmp.sort(function(a,b) { return a.ICompareN(b, 64) < b.ICompareN(a, 64); });
for (uint i = 0; i < tmp.length(); i++) {
g_PlayerFuncs.ClientPrint(plr, HUD_PRINTCONSOLE, "- " + tmp[i] + "\n");
}
tmp.resize(0);
}
else {
g_PlayerFuncs.ClientPrint(plr, HUD_PRINTCONSOLE, "none\n");
}
}
void ChadEnable(CBasePlayer@ plr) {
const uint uiPlrBit = (1 << (plr.entindex() & 31));
metachads |= uiPlrBit;
}
void ChadDisable(CBasePlayer@ plr) {
const uint uiPlrBit = (1 << (plr.entindex() & 31));
metachads &= ~uiPlrBit;
}
const bool IsChad(CBasePlayer@ plr) {
const uint uiPlrBit = (1 << (plr.entindex() & 31));
return metachads & uiPlrBit == uiPlrBit;
}