- added AddTargetsToMenu2() for using COMMAND_FILTER flags
- fixed
amb1350 - sm_voteban/menu ban on fake clients would crash
- fake clients can no longer be banned and do not appear on ban menus
3 * =============================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include <ISmmPluginExt.h>
38 #define DLL_EXPORT extern "C" __declspec(dllexport)
39 #define openlib(lib) LoadLibrary(lib)
40 #define closelib(lib) FreeLibrary(lib)
41 #define findsym(lib, sym) GetProcAddress(lib, sym)
42 #define PLATFORM_EXT ".dll"
43 #define vsnprintf _vsnprintf
44 #define PATH_SEP_CHAR "\\"
45 inline bool IsPathSepChar(char c)
47 return (c == '/' || c == '\\');
51 #define DLL_EXPORT extern "C" __attribute__((visibility("default")))
52 #define openlib(lib) dlopen(lib, RTLD_NOW)
53 #define closelib(lib) dlclose(lib)
54 #define findsym(lib, sym) dlsym(lib, sym)
55 #define PLATFORM_EXT ".so"
56 typedef void * HINSTANCE;
57 #define PATH_SEP_CHAR "/"
58 inline bool IsPathSepChar(char c)
65 #define METAMOD_API_MAJOR 2
66 #define FILENAME_1_4_EP1 "sourcemod.1.ep1" PLATFORM_EXT
67 #define FILENAME_1_6_EP2 "sourcemod.2.ep2" PLATFORM_EXT
68 #define FILENAME_1_6_EP1 "sourcemod.2.ep1" PLATFORM_EXT
70 HINSTANCE g_hCore = NULL;
71 bool load_attempted = false;
73 size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...)
78 size_t len = vsnprintf(buffer, maxlength, fmt, ap);
90 METAMOD_PLUGIN *_GetPluginPtr(const char *path)
92 METAMOD_FN_ORIG_LOAD fn;
96 if (!(g_hCore=openlib(path)))
101 if (!(fn=(METAMOD_FN_ORIG_LOAD)findsym(g_hCore, "CreateInterface")))
106 pl = (METAMOD_PLUGIN *)fn(METAMOD_PLAPI_NAME, &ret);
119 bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength)
122 MEMORY_BASIC_INFORMATION mem;
123 if (!VirtualQuery(pAddr, &mem, sizeof(mem)))
125 if (mem.AllocationBase == NULL)
127 HMODULE dll = (HMODULE)mem.AllocationBase;
128 GetModuleFileName(dll, (LPTSTR)buffer, maxlength);
131 if (!dladdr(pAddr, &info))
133 if (!info.dli_fbase || !info.dli_fname)
135 const char *dllpath = info.dli_fname;
136 snprintf(buffer, maxlength, "%s", dllpath);
141 DLL_EXPORT METAMOD_PLUGIN *CreateInterface_MMS(const MetamodVersionInfo *mvi, const MetamodLoaderInfo *mli)
145 load_attempted = true;
147 if (mvi->api_major > METAMOD_API_MAJOR)
152 switch (mvi->source_engine)
154 case SOURCE_ENGINE_ORANGEBOX:
156 filename = FILENAME_1_6_EP2;
159 case SOURCE_ENGINE_EPISODEONE:
160 case SOURCE_ENGINE_ORIGINAL:
162 filename = FILENAME_1_6_EP1;
172 UTIL_Format(abspath, sizeof(abspath), "%s" PATH_SEP_CHAR "%s", mli->pl_path, filename);
174 return _GetPluginPtr(abspath);
177 DLL_EXPORT void UnloadInterface_MMS()
186 DLL_EXPORT void *CreateInterface(const char *iface, int *ret)
189 * If a load has already been attempted, bail out immediately.
196 if (strcmp(iface, METAMOD_PLAPI_NAME) == 0)
199 char targetfile[256];
201 if (!GetFileOfAddress((void *)CreateInterface_MMS, thisfile, sizeof(thisfile)))
206 size_t len = strlen(thisfile);
207 for (size_t iter=len-1; iter>=0 && iter<len; iter--)
209 if (IsPathSepChar(thisfile[iter]))
211 thisfile[iter] = '\0';
216 UTIL_Format(targetfile, sizeof(targetfile), "%s" PATH_SEP_CHAR FILENAME_1_4_EP1, thisfile);
218 return _GetPluginPtr(targetfile);
225 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
227 if (fdwReason == DLL_PROCESS_DETACH)
229 UnloadInterface_MMS();
234 __attribute__((destructor)) static void gcc_fini()
236 UnloadInterface_MMS();