-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathextension.cpp
139 lines (109 loc) · 2.96 KB
/
extension.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
#if SOURCE_ENGINE == SE_CSGO
#include <netmessages.pb.h>
#endif
#include "extension.h"
#include "CDetour/detours.h"
AntiDLL antiDLL;
SMEXT_LINK(&antiDLL);
CDetour* pDetour = nullptr;
IGameConfig* pGameConfig = nullptr;
IForward* forwardCheatDetected = nullptr;
IGameEventManager2* gameevents = nullptr;
std::vector<std::string> events;
#if SOURCE_ENGINE == SE_CSGO
DETOUR_DECL_MEMBER1(ListenEvents, bool, CCLCMsg_ListenEvents*, msg)
#else
DETOUR_DECL_MEMBER1(ListenEvents, bool, CLC_ListenEvents*, msg)
#endif
{
auto client = (reinterpret_cast<CBaseClient*>(this))->GetPlayerSlot() + 1;
IGamePlayer* pClient = playerhelpers->GetGamePlayer(client);
if (pClient->IsFakeClient()) return DETOUR_MEMBER_CALL(ListenEvents)(msg);
auto detected = false;
#if SOURCE_ENGINE == SE_CSGO
IGameEventListener2* listener = reinterpret_cast<IGameEventListener2*>(this);
for (std::string iter : events)
{
if (gameevents->FindListener(listener, iter.c_str()))
{
detected = true;
break;
}
}
#else
auto counter = 0;
for (auto i = 0; i < MAX_EVENT_NUMBER; i++) {
if (msg->m_EventArray.Get(i))
{
counter++;
#if SOURCE_ENGINE == SE_CSS
if (counter > 48)
{
detected = true;
}
#else
if (counter > 25)
{
detected = true;
}
#endif
}
}
#endif
if (detected)
{
forwardCheatDetected->PushCell(client);
forwardCheatDetected->Execute();
}
return DETOUR_MEMBER_CALL(ListenEvents)(msg);
}
bool AntiDLL::SDK_OnLoad(char* error, size_t maxlen, bool late)
{
if (!gameconfs->LoadGameConfigFile("antidll.games", &pGameConfig, error, maxlen))
{
smutils->Format(error, maxlen - 1, "Failed to load gamedata");
return false;
}
#if SOURCE_ENGINE == SE_CSGO
char path[PLATFORM_MAX_PATH];
smutils->BuildPath(Path_SM, path, PLATFORM_MAX_PATH, "data/antidll/events_detection.txt");
if (!libsys->PathExists(path))
{
smutils->Format(error, maxlen - 1, "File %s not found", path);
return false;
}
std::string buffer;
std::ifstream file(path);
while (getline(file, buffer))
{
if (buffer[0] == ' ' || buffer[0] == '/')
{
continue;
}
events.push_back(buffer);
}
file.close();
#endif
CDetourManager::Init(smutils->GetScriptingEngine(), pGameConfig);
pDetour = DETOUR_CREATE_MEMBER(ListenEvents, "Signature");
if (pDetour == nullptr)
{
smutils->Format(error, maxlen - 1, "Failed to create interceptor");
return false;
}
pDetour->EnableDetour();
forwardCheatDetected = forwards->CreateForward("AD_OnCheatDetected", ET_Event, 1, nullptr, Param_Cell);
sharesys->RegisterLibrary(myself, "antidll");
return true;
}
void AntiDLL::SDK_OnUnload()
{
gameconfs->CloseGameConfigFile(pGameConfig);
forwards->ReleaseForward(forwardCheatDetected);
pDetour->DisableDetour();
}
bool AntiDLL::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
GET_V_IFACE_CURRENT(GetEngineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
return true;
}