1.1 --- a/extensions/regex/sdk/smsdk_ext.cpp Fri Mar 28 06:21:34 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,455 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod Base Extension Code
1.8 - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
1.9 - * =============================================================================
1.10 - *
1.11 - * This program is free software; you can redistribute it and/or modify it under
1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
1.13 - * Free Software Foundation.
1.14 - *
1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.18 - * details.
1.19 - *
1.20 - * You should have received a copy of the GNU General Public License along with
1.21 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.22 - *
1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.26 - * by the Valve Corporation. You must obey the GNU General Public License in
1.27 - * all respects for all other code used. Additionally, AlliedModders LLC grants
1.28 - * this exception to all derivative works. AlliedModders LLC defines further
1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.30 - * or <http://www.sourcemod.net/license.php>.
1.31 - *
1.32 - * Version: $Id: smsdk_ext.cpp 1699 2007-11-17 05:50:09Z dvander $
1.33 - */
1.34 -
1.35 -#include <stdio.h>
1.36 -#include <malloc.h>
1.37 -#include "smsdk_ext.h"
1.38 -
1.39 -/**
1.40 - * @file smsdk_ext.cpp
1.41 - * @brief Contains wrappers for making Extensions easier to write.
1.42 - */
1.43 -
1.44 -IExtension *myself = NULL; /**< Ourself */
1.45 -IShareSys *g_pShareSys = NULL; /**< Share system */
1.46 -IShareSys *sharesys = NULL; /**< Share system */
1.47 -ISourceMod *g_pSM = NULL; /**< SourceMod helpers */
1.48 -ISourceMod *smutils = NULL; /**< SourceMod helpers */
1.49 -
1.50 -#if defined SMEXT_ENABLE_FORWARDSYS
1.51 -IForwardManager *g_pForwards = NULL; /**< Forward system */
1.52 -IForwardManager *forwards = NULL; /**< Forward system */
1.53 -#endif
1.54 -#if defined SMEXT_ENABLE_HANDLESYS
1.55 -IHandleSys *g_pHandleSys = NULL; /**< Handle system */
1.56 -IHandleSys *handlesys = NULL; /**< Handle system */
1.57 -#endif
1.58 -#if defined SMEXT_ENABLE_PLAYERHELPERS
1.59 -IPlayerManager *playerhelpers = NULL; /**< Player helpers */
1.60 -#endif //SMEXT_ENABLE_PLAYERHELPERS
1.61 -#if defined SMEXT_ENABLE_DBMANAGER
1.62 -IDBManager *dbi = NULL; /**< DB Manager */
1.63 -#endif //SMEXT_ENABLE_DBMANAGER
1.64 -#if defined SMEXT_ENABLE_GAMECONF
1.65 -IGameConfigManager *gameconfs = NULL; /**< Game config manager */
1.66 -#endif //SMEXT_ENABLE_DBMANAGER
1.67 -#if defined SMEXT_ENABLE_MEMUTILS
1.68 -IMemoryUtils *memutils = NULL;
1.69 -#endif //SMEXT_ENABLE_DBMANAGER
1.70 -#if defined SMEXT_ENABLE_GAMEHELPERS
1.71 -IGameHelpers *gamehelpers = NULL;
1.72 -#endif
1.73 -#if defined SMEXT_ENABLE_TIMERSYS
1.74 -ITimerSystem *timersys = NULL;
1.75 -#endif
1.76 -#if defined SMEXT_ENABLE_ADTFACTORY
1.77 -IADTFactory *adtfactory = NULL;
1.78 -#endif
1.79 -#if defined SMEXT_ENABLE_THREADER
1.80 -IThreader *threader = NULL;
1.81 -#endif
1.82 -#if defined SMEXT_ENABLE_LIBSYS
1.83 -ILibrarySys *libsys = NULL;
1.84 -#endif
1.85 -#if defined SMEXT_ENABLE_PLUGINSYS
1.86 -SourceMod::IPluginManager *plsys;
1.87 -#endif
1.88 -#if defined SMEXT_ENABLE_MENUS
1.89 -IMenuManager *menus = NULL;
1.90 -#endif
1.91 -#if defined SMEXT_ENABLE_ADMINSYS
1.92 -IAdminSystem *adminsys = NULL;
1.93 -#endif
1.94 -#if defined SMEXT_ENABLE_TEXTPARSERS
1.95 -ITextParsers *textparsers = NULL;
1.96 -#endif
1.97 -#if defined SMEXT_ENABLE_USERMSGS
1.98 -IUserMessages *usermsgs = NULL;
1.99 -#endif
1.100 -
1.101 -/** Exports the main interface */
1.102 -PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI()
1.103 -{
1.104 - return g_pExtensionIface;
1.105 -}
1.106 -
1.107 -SDKExtension::SDKExtension()
1.108 -{
1.109 -#if defined SMEXT_CONF_METAMOD
1.110 - m_SourceMMLoaded = false;
1.111 - m_WeAreUnloaded = false;
1.112 - m_WeGotPauseChange = false;
1.113 -#endif
1.114 -}
1.115 -
1.116 -bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late)
1.117 -{
1.118 - g_pShareSys = sharesys = sys;
1.119 - myself = me;
1.120 -
1.121 -#if defined SMEXT_CONF_METAMOD
1.122 - m_WeAreUnloaded = true;
1.123 -
1.124 - if (!m_SourceMMLoaded)
1.125 - {
1.126 - if (error)
1.127 - {
1.128 - snprintf(error, maxlength, "Metamod attach failed");
1.129 - }
1.130 - return false;
1.131 - }
1.132 -#endif
1.133 - SM_GET_IFACE(SOURCEMOD, g_pSM);
1.134 - smutils = g_pSM;
1.135 -#if defined SMEXT_ENABLE_HANDLESYS
1.136 - SM_GET_IFACE(HANDLESYSTEM, g_pHandleSys);
1.137 - handlesys = g_pHandleSys;
1.138 -#endif
1.139 -#if defined SMEXT_ENABLE_FORWARDSYS
1.140 - SM_GET_IFACE(FORWARDMANAGER, g_pForwards);
1.141 - forwards = g_pForwards;
1.142 -#endif
1.143 -#if defined SMEXT_ENABLE_PLAYERHELPERS
1.144 - SM_GET_IFACE(PLAYERMANAGER, playerhelpers);
1.145 -#endif
1.146 -#if defined SMEXT_ENABLE_DBMANAGER
1.147 - SM_GET_IFACE(DBI, dbi);
1.148 -#endif
1.149 -#if defined SMEXT_ENABLE_GAMECONF
1.150 - SM_GET_IFACE(GAMECONFIG, gameconfs);
1.151 -#endif
1.152 -#if defined SMEXT_ENABLE_MEMUTILS
1.153 - SM_GET_IFACE(MEMORYUTILS, memutils);
1.154 -#endif
1.155 -#if defined SMEXT_ENABLE_GAMEHELPERS
1.156 - SM_GET_IFACE(GAMEHELPERS, gamehelpers);
1.157 -#endif
1.158 -#if defined SMEXT_ENABLE_TIMERSYS
1.159 - SM_GET_IFACE(TIMERSYS, timersys);
1.160 -#endif
1.161 -#if defined SMEXT_ENABLE_ADTFACTORY
1.162 - SM_GET_IFACE(ADTFACTORY, adtfactory);
1.163 -#endif
1.164 -#if defined SMEXT_ENABLE_THREADER
1.165 - SM_GET_IFACE(THREADER, threader);
1.166 -#endif
1.167 -#if defined SMEXT_ENABLE_LIBSYS
1.168 - SM_GET_IFACE(LIBRARYSYS, libsys);
1.169 -#endif
1.170 -#if defined SMEXT_ENABLE_PLUGINSYS
1.171 - SM_GET_IFACE(PLUGINSYSTEM, plsys);
1.172 -#endif
1.173 -#if defined SMEXT_ENABLE_MENUS
1.174 - SM_GET_IFACE(MENUMANAGER, menus);
1.175 -#endif
1.176 -#if defined SMEXT_ENABLE_ADMINSYS
1.177 - SM_GET_IFACE(ADMINSYS, adminsys);
1.178 -#endif
1.179 -#if defined SMEXT_ENABLE_TEXTPARSERS
1.180 - SM_GET_IFACE(TEXTPARSERS, textparsers);
1.181 -#endif
1.182 -#if defined SMEXT_ENABLE_USERMSGS
1.183 - SM_GET_IFACE(USERMSGS, usermsgs);
1.184 -#endif
1.185 -
1.186 - if (SDK_OnLoad(error, maxlength, late))
1.187 - {
1.188 -#if defined SMEXT_CONF_METAMOD
1.189 - m_WeAreUnloaded = true;
1.190 -#endif
1.191 - return true;
1.192 - }
1.193 -
1.194 - return false;
1.195 -}
1.196 -
1.197 -bool SDKExtension::IsMetamodExtension()
1.198 -{
1.199 -#if defined SMEXT_CONF_METAMOD
1.200 - return true;
1.201 -#else
1.202 - return false;
1.203 -#endif
1.204 -}
1.205 -
1.206 -void SDKExtension::OnExtensionPauseChange(bool state)
1.207 -{
1.208 -#if defined SMEXT_CONF_METAMOD
1.209 - m_WeGotPauseChange = true;
1.210 -#endif
1.211 - SDK_OnPauseChange(state);
1.212 -}
1.213 -
1.214 -void SDKExtension::OnExtensionsAllLoaded()
1.215 -{
1.216 - SDK_OnAllLoaded();
1.217 -}
1.218 -
1.219 -void SDKExtension::OnExtensionUnload()
1.220 -{
1.221 -#if defined SMEXT_CONF_METAMOD
1.222 - m_WeAreUnloaded = true;
1.223 -#endif
1.224 - SDK_OnUnload();
1.225 -}
1.226 -
1.227 -const char *SDKExtension::GetExtensionAuthor()
1.228 -{
1.229 - return SMEXT_CONF_AUTHOR;
1.230 -}
1.231 -
1.232 -const char *SDKExtension::GetExtensionDateString()
1.233 -{
1.234 - return SMEXT_CONF_DATESTRING;
1.235 -}
1.236 -
1.237 -const char *SDKExtension::GetExtensionDescription()
1.238 -{
1.239 - return SMEXT_CONF_DESCRIPTION;
1.240 -}
1.241 -
1.242 -const char *SDKExtension::GetExtensionVerString()
1.243 -{
1.244 - return SMEXT_CONF_VERSION;
1.245 -}
1.246 -
1.247 -const char *SDKExtension::GetExtensionName()
1.248 -{
1.249 - return SMEXT_CONF_NAME;
1.250 -}
1.251 -
1.252 -const char *SDKExtension::GetExtensionTag()
1.253 -{
1.254 - return SMEXT_CONF_LOGTAG;
1.255 -}
1.256 -
1.257 -const char *SDKExtension::GetExtensionURL()
1.258 -{
1.259 - return SMEXT_CONF_URL;
1.260 -}
1.261 -
1.262 -bool SDKExtension::SDK_OnLoad(char *error, size_t maxlength, bool late)
1.263 -{
1.264 - return true;
1.265 -}
1.266 -
1.267 -void SDKExtension::SDK_OnUnload()
1.268 -{
1.269 -}
1.270 -
1.271 -void SDKExtension::SDK_OnPauseChange(bool paused)
1.272 -{
1.273 -}
1.274 -
1.275 -void SDKExtension::SDK_OnAllLoaded()
1.276 -{
1.277 -}
1.278 -
1.279 -#if defined SMEXT_CONF_METAMOD
1.280 -
1.281 -PluginId g_PLID = 0; /**< Metamod plugin ID */
1.282 -ISmmPlugin *g_PLAPI = NULL; /**< Metamod plugin API */
1.283 -SourceHook::ISourceHook *g_SHPtr = NULL; /**< SourceHook pointer */
1.284 -ISmmAPI *g_SMAPI = NULL; /**< SourceMM API pointer */
1.285 -
1.286 -IVEngineServer *engine = NULL; /**< IVEngineServer pointer */
1.287 -IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */
1.288 -
1.289 -/** Exposes the extension to Metamod */
1.290 -SMM_API void *PL_EXPOSURE(const char *name, int *code)
1.291 -{
1.292 -#if defined METAMOD_PLAPI_VERSION
1.293 - if (name && !strcmp(name, METAMOD_PLAPI_NAME))
1.294 -#else
1.295 - if (name && !strcmp(name, PLAPI_NAME))
1.296 -#endif
1.297 - {
1.298 - if (code)
1.299 - {
1.300 - *code = IFACE_OK;
1.301 - }
1.302 - return static_cast<void *>(g_pExtensionIface);
1.303 - }
1.304 -
1.305 - if (code)
1.306 - {
1.307 - *code = IFACE_FAILED;
1.308 - }
1.309 -
1.310 - return NULL;
1.311 -}
1.312 -
1.313 -bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
1.314 -{
1.315 - PLUGIN_SAVEVARS();
1.316 -
1.317 -#if defined METAMOD_PLAPI_VERSION
1.318 - GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
1.319 - GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
1.320 -#else
1.321 - GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
1.322 - GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
1.323 -#endif
1.324 -
1.325 - m_SourceMMLoaded = true;
1.326 -
1.327 - return SDK_OnMetamodLoad(ismm, error, maxlen, late);
1.328 -}
1.329 -
1.330 -bool SDKExtension::Unload(char *error, size_t maxlen)
1.331 -{
1.332 - if (!m_WeAreUnloaded)
1.333 - {
1.334 - if (error)
1.335 - {
1.336 - snprintf(error, maxlen, "This extension must be unloaded by SourceMod.");
1.337 - }
1.338 - return false;
1.339 - }
1.340 -
1.341 - return SDK_OnMetamodUnload(error, maxlen);
1.342 -}
1.343 -
1.344 -bool SDKExtension::Pause(char *error, size_t maxlen)
1.345 -{
1.346 - if (!m_WeGotPauseChange)
1.347 - {
1.348 - if (error)
1.349 - {
1.350 - snprintf(error, maxlen, "This extension must be paused by SourceMod.");
1.351 - }
1.352 - return false;
1.353 - }
1.354 -
1.355 - m_WeGotPauseChange = false;
1.356 -
1.357 - return SDK_OnMetamodPauseChange(true, error, maxlen);
1.358 -}
1.359 -
1.360 -bool SDKExtension::Unpause(char *error, size_t maxlen)
1.361 -{
1.362 - if (!m_WeGotPauseChange)
1.363 - {
1.364 - if (error)
1.365 - {
1.366 - snprintf(error, maxlen, "This extension must be unpaused by SourceMod.");
1.367 - }
1.368 - return false;
1.369 - }
1.370 -
1.371 - m_WeGotPauseChange = false;
1.372 -
1.373 - return SDK_OnMetamodPauseChange(false, error, maxlen);
1.374 -}
1.375 -
1.376 -const char *SDKExtension::GetAuthor()
1.377 -{
1.378 - return GetExtensionAuthor();
1.379 -}
1.380 -
1.381 -const char *SDKExtension::GetDate()
1.382 -{
1.383 - return GetExtensionDateString();
1.384 -}
1.385 -
1.386 -const char *SDKExtension::GetDescription()
1.387 -{
1.388 - return GetExtensionDescription();
1.389 -}
1.390 -
1.391 -const char *SDKExtension::GetLicense()
1.392 -{
1.393 - return SMEXT_CONF_LICENSE;
1.394 -}
1.395 -
1.396 -const char *SDKExtension::GetLogTag()
1.397 -{
1.398 - return GetExtensionTag();
1.399 -}
1.400 -
1.401 -const char *SDKExtension::GetName()
1.402 -{
1.403 - return GetExtensionName();
1.404 -}
1.405 -
1.406 -const char *SDKExtension::GetURL()
1.407 -{
1.408 - return GetExtensionURL();
1.409 -}
1.410 -
1.411 -const char *SDKExtension::GetVersion()
1.412 -{
1.413 - return GetExtensionVerString();
1.414 -}
1.415 -
1.416 -bool SDKExtension::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late)
1.417 -{
1.418 - return true;
1.419 -}
1.420 -
1.421 -bool SDKExtension::SDK_OnMetamodUnload(char *error, size_t maxlength)
1.422 -{
1.423 - return true;
1.424 -}
1.425 -
1.426 -bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength)
1.427 -{
1.428 - return true;
1.429 -}
1.430 -
1.431 -#endif
1.432 -
1.433 -/* Overload a few things to prevent libstdc++ linking */
1.434 -#if defined __linux__
1.435 -extern "C" void __cxa_pure_virtual(void)
1.436 -{
1.437 -}
1.438 -
1.439 -void *operator new(size_t size)
1.440 -{
1.441 - return malloc(size);
1.442 -}
1.443 -
1.444 -void *operator new[](size_t size)
1.445 -{
1.446 - return malloc(size);
1.447 -}
1.448 -
1.449 -void operator delete(void *ptr)
1.450 -{
1.451 - free(ptr);
1.452 -}
1.453 -
1.454 -void operator delete[](void * ptr)
1.455 -{
1.456 - free(ptr);
1.457 -}
1.458 -#endif