-
-
Notifications
You must be signed in to change notification settings - Fork 181
Expand file tree
/
Copy pathPluginManager.cpp
More file actions
190 lines (168 loc) · 6.76 KB
/
PluginManager.cpp
File metadata and controls
190 lines (168 loc) · 6.76 KB
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
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
*
* The original code is copyright (c) 2022, open.mp team and contributors.
*/
#include <ghc/filesystem.hpp>
#include "PluginManager.hpp"
#include "../utils.hpp"
struct BrokenPluginMessageData
{
StringView name;
StringView message;
};
static const StaticArray<BrokenPluginMessageData, 25> BrokenPlugins = {
{
{ "YSF", "It requires memory hacking to run and is therefore broken on open.mp, we already added many built-in features from YSF to open.mp and the rest are coming" },
{ "YSF_DL", "It requires memory hacking to run and is therefore broken on open.mp, we already added many built-in features from YSF to open.mp and the rest are coming" },
{ "YSF_static", "It requires memory hacking to run and is therefore broken on open.mp, we already added many built-in features from YSF to open.mp and the rest are coming" },
{ "YSF_DL_static", "It requires memory hacking to run and is therefore broken on open.mp, we already added many built-in features from YSF to open.mp and the rest are coming" },
{ "fixes2", "It requires memory hacking to run and is therefore broken on open.mp. There should be a replacement component supported by open.mp" },
{ "FCNPC", "It requires memory hacking to run and is therefore broken on open.mp, we already have NPC component with many built-in features in open.mp" },
{ "FCNPC-DL", "It requires memory hacking to run and is therefore broken on open.mp, we already have NPC component with many built-in features in open.mp" },
{ "SKY", "It requires memory hacking to run and is therefore broken on open.mp. There should be a replacement component supported by open.mp" },
{ "sampcac_server", "It requires memory hacking to run and is therefore broken on open.mp. There should be a replacement component supported by open.mp" },
{ "ASAN", "It requires memory hacking to run and is therefore broken on open.mp. There should be a replacement component supported by open.mp" },
{ "samp-custom-query-flood-check", "It requires memory hacking to run and is therefore broken on open.mp. There should be a replacement component supported by open.mp" },
{ "AntiVehicleSpawn", "It requires memory hacking to run and is therefore broken on open.mp. There should be a replacement component supported by open.mp" },
{ "mcmd", "It requires memory hacking to run and is therefore broken on open.mp. There should be a replacement component supported by open.mp" },
{ "KeyListener", "It requires memory hacking to run and is therefore broken on open.mp. There should be a replacement component supported by open.mp" },
{ "chandlingsvr", "It requires memory hacking to run and is therefore broken on open.mp. There should be a replacement component supported by open.mp" },
{ "samp_akm", "It requires memory hacking to run and is therefore broken on open.mp. There should be a replacement component supported by open.mp" },
{ "pawnraknet", "There is an open.mp compatible version you can find here: https://github.com/katursis/Pawn.RakNet/releases , make sure to download x.x.x-omp version." },
{ "pawncmd", "There is an open.mp compatible version you can find here: https://github.com/katursis/Pawn.CMD/releases , make sure to download x.x.x-omp version." },
{ "sampvoice", "There is an open.mp compatible version you can find here: https://github.com/AmyrAhmady/sampvoice/releases , make sure to download x.x.x-omp version." },
{ "fmt", "It is not needed anymore since open.mp has support for formatted strings in various natives" },
{ "nativechecker", "It is not needed anymore since open.mp has built in native checking mechanism when a script is being loaded" },
{ "samp-compat", "It is not needed anymore since open.mp has built in compat mechanism between 0.3.7 and 0.3DL versions" },
{ "LFN", "It is not needed anymore since open.mp has support for longer function names, just compile your scripts with our compiler" },
{ "raktimefix", "It is not needed anymore since open.mp has no stability issues on the latest linux systems" },
{ "bscrashfix", "It is not needed anymore since open.mp has no raknet layer issues causing to crashes" },
}
};
PawnPluginManager::PawnPluginManager()
: pluginPath_("plugins/")
, basePath_("./")
{
}
PawnPluginManager::~PawnPluginManager()
{
for (auto& cur : plugins_)
{
cur.second->Unload();
}
}
void PawnPluginManager::Load(std::string const& name)
{
if (plugins_.count(name))
{
return;
}
String pluginName = ghc::filesystem::path(name).stem().string();
for (BrokenPluginMessageData brokenPlugin : BrokenPlugins)
{
if (pluginName == brokenPlugin.name)
{
core->logLn(LogLevel::Error,
"Skipping legacy plugin '%.*s'; %.*s",
PRINT_VIEW(brokenPlugin.name), PRINT_VIEW(brokenPlugin.message));
return;
}
}
Spawn(name);
}
void PawnPluginManager::Unload(std::string const& name)
{
auto
pos
= plugins_.find(name);
if (pos == plugins_.end())
{
return;
}
auto& plugin = *pos->second;
plugin.Unload();
plugins_.erase(pos);
}
void PawnPluginManager::Spawn(std::string const& name)
{
// if the user just supplied a script name, add the extension
// otherwise, don't, as they may have supplied a full abs/rel path.
// std::string ext = utils::endsWith(name, ".amx") ? "" : ".amx";
std::string canon;
#ifndef WIN32
size_t pos = name.rfind(".so");
// You would think this could be done in one comparison, but the path may
// only be two characters long.
if (pos == std::string::npos || pos + 3 != name.length())
{
// Append the extension.
utils::Canonicalise(basePath_ + pluginPath_ + name + ".so", canon);
}
else
#endif // WIN32
{
utils::Canonicalise(basePath_ + pluginPath_ + name, canon);
}
core->printLn("Loading plugin: %s", name.c_str());
std::unique_ptr<PawnPlugin> ptr = std::make_unique<PawnPlugin>(canon, core);
if (!ptr.get()->IsLoaded())
{
// core->printLn("Unable to load plugin %s\n\n", name.c_str());
return;
}
plugins_.emplace(name, std::move(ptr));
}
void PawnPluginManager::AmxLoad(AMX* amx)
{
for (auto& cur : plugins_)
{
cur.second->AmxLoad(amx);
}
}
void PawnPluginManager::AmxUnload(AMX* amx)
{
for (auto& cur : plugins_)
{
cur.second->AmxUnload(amx);
}
}
void PawnPluginManager::ProcessTick()
{
for (auto& cur : plugins_)
{
cur.second->ProcessTick();
}
}
void PawnPluginManager::SetBasePath(std::string const& path)
{
if (path.length() == 0)
{
basePath_ = "/";
}
else if (path.back() == '/')
{
basePath_ = path;
}
else
{
basePath_ = path + '/';
}
}
void PawnPluginManager::SetScriptPath(std::string const& path)
{
if (path.length() == 0)
{
pluginPath_ = "/";
}
else if (path.back() == '/')
{
pluginPath_ = path;
}
else
{
pluginPath_ = path + '/';
}
}