-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamxxmodule.cpp
215 lines (198 loc) · 5.37 KB
/
amxxmodule.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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
// Parts Copyright (C) 2001-2003 Will Day <[email protected]>
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
//
// Module SDK
//
#include "precompiled.h"
// Module info
static amxx_module_info_s g_ModuleInfo =
{
Plugin_info.name,
Plugin_info.author,
Plugin_info.version,
FALSE,
Plugin_info.logtag,
"refsapi",
"refsapi"};
// Storage for the requested functions
amxxapi_t g_amxxapi;
static struct funcreq_t
{
const char *name;
size_t offset;
} g_funcrequests[] =
{
DECLARE_REQ(AddNatives),
// DECLARE_REQ(AddNewNatives),
// DECLARE_REQ(BuildPathname),
// DECLARE_REQ(BuildPathnameR),
DECLARE_REQ(GetAmxAddr),
// DECLARE_REQ(GetAmxVectorNull), // AMXX 1.8.3-dev
// DECLARE_REQ(PrintSrvConsole),
DECLARE_REQ(GetModname),
DECLARE_REQ(GetAmxScriptName),
// DECLARE_REQ(GetAmxScript),
DECLARE_REQ(FindAmxScriptByAmx),
// DECLARE_REQ(FindAmxScriptByName),
DECLARE_REQ(SetAmxString),
DECLARE_REQ(SetAmxStringUTF8Char), // AMXX 1.8.3-dev
DECLARE_REQ(SetAmxStringUTF8Cell), // AMXX 1.8.3-dev
DECLARE_REQ(GetAmxString),
// DECLARE_REQ(GetAmxStringNull), // AMXX 1.8.3-dev
// DECLARE_REQ(GetAmxStringLen),
DECLARE_REQ(FormatAmxString),
// DECLARE_REQ(CopyAmxMemory),
DECLARE_REQ(Log),
DECLARE_REQ(LogError),
// DECLARE_REQ(RaiseAmxError),
DECLARE_REQ(RegisterForward),
DECLARE_REQ(ExecuteForward),
DECLARE_REQ(PrepareCellArray),
DECLARE_REQ(PrepareCharArray),
DECLARE_REQ(PrepareCellArrayA),
DECLARE_REQ(PrepareCharArrayA),
// DECLARE_REQ(IsPlayerValid),
// DECLARE_REQ(GetPlayerName),
// DECLARE_REQ(GetPlayerIP),
// DECLARE_REQ(IsPlayerInGame),
// DECLARE_REQ(IsPlayerBot),
// DECLARE_REQ(IsPlayerAuthorized),
// DECLARE_REQ(GetPlayerTime),
// DECLARE_REQ(GetPlayerPlayTime),
// DECLARE_REQ(GetPlayerCurweapon),
// DECLARE_REQ(GetPlayerTeam),
// DECLARE_REQ(GetPlayerTeamID),
// DECLARE_REQ(GetPlayerDeaths),
// DECLARE_REQ(GetPlayerMenu),
// DECLARE_REQ(GetPlayerKeys),
// DECLARE_REQ(IsPlayerAlive),
// DECLARE_REQ(GetPlayerFrags),
// DECLARE_REQ(IsPlayerConnecting),
// DECLARE_REQ(IsPlayerHLTV),
// DECLARE_REQ(GetPlayerArmor),
// DECLARE_REQ(GetPlayerHealth),
// DECLARE_REQ(amx_Exec),
// DECLARE_REQ(amx_Execv),
DECLARE_REQ(amx_Allot),
DECLARE_REQ(amx_FindPublic),
// DECLARE_REQ(LoadAmxScript),
// DECLARE_REQ(UnloadAmxScript),
// DECLARE_REQ(RealToCell),
// DECLARE_REQ(CellToReal),
DECLARE_REQ(RegisterSPForward),
DECLARE_REQ(RegisterSPForwardByName),
DECLARE_REQ(UnregisterSPForward),
// DECLARE_REQ(MergeDefinitionFile),
// DECLARE_REQ(amx_FindNative),
DECLARE_REQ(GetPlayerFlags),
// DECLARE_REQ(GetPlayerEdict),
// DECLARE_REQ(Format),
// DECLARE_REQ(RegisterFunction),
// DECLARE_REQ(RequestFunction),
// DECLARE_REQ(amx_Push),
DECLARE_REQ(SetPlayerTeamInfo),
// DECLARE_REQ(PlayerPropAddr),
// DECLARE_REQ(RegAuthFunc),
// DECLARE_REQ(UnregAuthFunc),
// DECLARE_REQ(FindLibrary),
// DECLARE_REQ(AddLibraries),
// DECLARE_REQ(RemoveLibraries),
// DECLARE_REQ(OverrideNatives),
// DECLARE_REQ(GetLocalInfo),
// DECLARE_REQ(AmxReregister),
// DECLARE_REQ(RegisterFunctionEx),
// DECLARE_REQ(MessageBlock),
};
C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo)
{
// check parameters
if (!interfaceVersion || !moduleInfo)
return AMXX_PARAM;
// check interface version
if (*interfaceVersion != AMXX_INTERFACE_VERSION)
{
// Tell amxx core our interface version
*interfaceVersion = AMXX_INTERFACE_VERSION;
return AMXX_IFVERS;
}
// copy module info
memcpy(moduleInfo, &g_ModuleInfo, sizeof(amxx_module_info_s));
return AMXX_OK;
}
C_DLLEXPORT int AMXX_CheckGame(const char *game)
{
return AMXX_GAME_OK;
}
C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc)
{
// Check pointer
if (!reqFnptrFunc)
return AMXX_PARAM;
for (size_t i = 0; i < ARRAYSIZE(g_funcrequests); i++)
{
void *fptr = reqFnptrFunc(g_funcrequests[i].name);
if (fptr == NULL)
{
return AMXX_FUNC_NOT_PRESENT;
}
*(void **)((unsigned long)&g_amxxapi + g_funcrequests[i].offset) = fptr;
}
OnAmxxAttach();
RegisterNatives_Misc();
return AMXX_OK;
}
C_DLLEXPORT int AMXX_Detach()
{
return AMXX_OK;
}
C_DLLEXPORT int AMXX_PluginsLoaded()
{
return AMXX_OK;
}
C_DLLEXPORT void AMXX_PluginsUnloaded()
{
}
C_DLLEXPORT void AMXX_PluginsUnloading()
{
}
NOINLINE void AMXX_Log(const char *fmt, ...)
{
char msg[2048];
va_list arglst;
va_start(arglst, fmt);
vsnprintf(msg, sizeof msg, fmt, arglst);
va_end(arglst);
g_amxxapi.Log("[%s] %s", g_ModuleInfo.logtag, msg);
}
NOINLINE void AMXX_LogError(AMX *amx, int err, const char *fmt, ...)
{
char msg[2048];
va_list arglst;
va_start(arglst, fmt);
vsnprintf(msg, sizeof msg, fmt, arglst);
va_end(arglst);
g_amxxapi.LogError(amx, err, "[%s] %s", g_ModuleInfo.logtag, msg);
}
char *getAmxString(cell *src, char *dest, size_t max, size_t *len)
{
auto start = dest;
while (*src && --max)
*dest++ = (char)*src++;
*dest = 0;
if (len)
*len = dest - start;
return start;
}
void setAmxString(cell *dest, const char *src, size_t max)
{
while (*src && --max > 0)
*dest++ = (cell)*src++;
*dest = 0;
}