From ca0da2559d5a2e5803232a0d31a2000d1445eb5e Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 10 Nov 2007 05:46:09 +0000 Subject: [PATCH] fixed bugs in the external extension system import of external SDK that's been sitting around for a while --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401674 --- core/sourcemm_api.cpp | 2 +- core/systems/ExtensionSys.cpp | 11 +- public/IExtensionSys.h | 2 +- public/ISourceMod.h | 1 + public/mms_sample_ext/Makefile.ep2 | 73 ++++++++++++ public/mms_sample_ext/Makefile.orig | 73 ++++++++++++ public/mms_sample_ext/sm_ext.cpp | 146 +++++++++++++++++++++++ public/mms_sample_ext/sm_ext.h | 38 ++++++ public/mms_sample_ext/sm_sdk_config.cpp | 151 ++++++++++++++++++++++++ public/mms_sample_ext/sm_sdk_config.h | 128 ++++++++++++++++++++ public/mms_sample_ext/stub_mm.cpp | 142 ++++++++++++++++++++++ public/mms_sample_ext/stub_mm.h | 54 +++++++++ public/mms_sample_ext/stub_util.cpp | 22 ++++ public/mms_sample_ext/stub_util.h | 15 +++ 14 files changed, 854 insertions(+), 4 deletions(-) create mode 100644 public/mms_sample_ext/Makefile.ep2 create mode 100644 public/mms_sample_ext/Makefile.orig create mode 100644 public/mms_sample_ext/sm_ext.cpp create mode 100644 public/mms_sample_ext/sm_ext.h create mode 100644 public/mms_sample_ext/sm_sdk_config.cpp create mode 100644 public/mms_sample_ext/sm_sdk_config.h create mode 100644 public/mms_sample_ext/stub_mm.cpp create mode 100644 public/mms_sample_ext/stub_mm.h create mode 100644 public/mms_sample_ext/stub_util.cpp create mode 100644 public/mms_sample_ext/stub_util.h diff --git a/core/sourcemm_api.cpp b/core/sourcemm_api.cpp index 0ee04a95..d91168d8 100644 --- a/core/sourcemm_api.cpp +++ b/core/sourcemm_api.cpp @@ -235,6 +235,6 @@ void *SourceMod_Core::OnMetamodQuery(const char *iface, int *ret) *ret = (ptr == NULL) ? IFACE_FAILED : IFACE_OK; } - return NULL; + return ptr; } diff --git a/core/systems/ExtensionSys.cpp b/core/systems/ExtensionSys.cpp index cd110370..78df64ec 100644 --- a/core/systems/ExtensionSys.cpp +++ b/core/systems/ExtensionSys.cpp @@ -53,8 +53,8 @@ void CExtension::Initialize(const char *filename, const char *path) CRemoteExtension::CRemoteExtension(IExtensionInterface *pAPI, const char *filename, const char *path) { - m_pAPI = pAPI; Initialize(filename, path); + m_pAPI = pAPI; } CLocalExtension::CLocalExtension(const char *filename) @@ -200,7 +200,13 @@ CExtension::~CExtension() bool CExtension::PerformAPICheck(char *error, size_t maxlength) { - if (!m_pAPI || m_pAPI->GetExtensionVersion() > SMINTERFACE_EXTENSIONAPI_VERSION) + if (!m_pAPI) + { + snprintf(error, maxlength, "No IExtensionInterface instance provided"); + return false; + } + + if (m_pAPI->GetExtensionVersion() > SMINTERFACE_EXTENSIONAPI_VERSION) { snprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION); return false; @@ -1281,3 +1287,4 @@ IExtension *CExtensionManager::LoadExternal(IExtensionInterface *pInterface, return pExt; } + diff --git a/public/IExtensionSys.h b/public/IExtensionSys.h index a653f448..845cde25 100644 --- a/public/IExtensionSys.h +++ b/public/IExtensionSys.h @@ -400,7 +400,7 @@ namespace SourceMod SM_IFACEPAIR(prefix)); \ if (len >= errsize) \ { \ - buffer[errsize - 1] = '\0'; \ + errbuf[errsize - 1] = '\0'; \ } \ } \ return false; \ diff --git a/public/ISourceMod.h b/public/ISourceMod.h index bf1d4666..bddc33c4 100644 --- a/public/ISourceMod.h +++ b/public/ISourceMod.h @@ -40,6 +40,7 @@ #include #include #include +#include #define SMINTERFACE_SOURCEMOD_NAME "ISourceMod" #define SMINTERFACE_SOURCEMOD_VERSION 3 diff --git a/public/mms_sample_ext/Makefile.ep2 b/public/mms_sample_ext/Makefile.ep2 new file mode 100644 index 00000000..17adc6df --- /dev/null +++ b/public/mms_sample_ext/Makefile.ep2 @@ -0,0 +1,73 @@ +#(C)2004-2007 SourceMM Development Team +# Makefile written by David "BAILOPAN" Anderson + +HL2SDK = ../../../hl2sdk-ob +SMM_ROOT = ../../../sourcemm-1.6.0 +SRCDS = ~/srcds/orangebox +SMSDK = .. + +### EDIT BELOW FOR OTHER PROJECTS ### + +OPT_FLAGS = -O3 -funroll-loops -s -pipe +GCC4_FLAGS = -fvisibility=hidden -fvisibility-inlines-hidden +DEBUG_FLAGS = -g -ggdb3 +CPP = gcc-4.1 +BINARY = stub_mm_i486.so + +HL2PUB = $(HL2SDK)/public + +OBJECTS = stub_mm.cpp sm_ext.cpp sm_sdk_config.cpp stub_util.cpp + +LINK = vstdlib_i486.so tier0_i486.so -static-libgcc + +INCLUDE = -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/dlls -I$(HL2PUB)/engine -I$(HL2PUB)/tier0 \ + -I$(HL2PUB)/tier1 -I$(HL2PUB)/vstdlib -I$(HL2SDK)/tier1 -I$(SMM_ROOT) -I$(SMM_ROOT)/sourcehook \ + -I$(SMM_ROOT)/sourcemm -I$(SMSDK) -I$(SMSDK)/jit -I$(SMSDK)/jit/x86 -I$(SMSDK)/extensions \ + -I$(SMSDK)/sourcepawn + +ifeq "$(DEBUG)" "true" + BIN_DIR = Debug + CFLAGS = $(DEBUG_FLAGS) +else + BIN_DIR = Release + CFLAGS = $(OPT_FLAGS) +endif + +GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) + +CFLAGS += -D_LINUX -DNDEBUG -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \ + -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca \ + -Dstrcmpi=strcasecmp -Wall -Wno-non-virtual-dtor -Werror -fPIC -fno-exceptions -fno-rtti -msse \ + -fno-strict-aliasing -DORANGEBOX_BUILD + +ifeq "$(GCC_VERSION)" "4" + CFLAGS += $(GCC4_FLAGS) +endif + +OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) + +$(BIN_DIR)/%.o: %.cpp + $(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< + +all: + mkdir -p $(BIN_DIR) + rm -f vstdlib_i486.so + rm -f tier0_i486.so + ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so + ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so + $(MAKE) -f Makefile.orig stub_mm + rm -rf $(BINARY) + +stub_mm: $(OBJ_LINUX) + $(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + +debug: + $(MAKE) -f Makefile.orig all DEBUG=true + +default: all + +clean: + rm -rf Release/*.o + rm -rf Release/$(BINARY) + rm -rf Debug/*.o + rm -rf Debug/$(BINARY) diff --git a/public/mms_sample_ext/Makefile.orig b/public/mms_sample_ext/Makefile.orig new file mode 100644 index 00000000..c4b59b5a --- /dev/null +++ b/public/mms_sample_ext/Makefile.orig @@ -0,0 +1,73 @@ +#(C)2004-2007 SourceMM Development Team +# Makefile written by David "BAILOPAN" Anderson + +HL2SDK = ../../../hl2sdk +SMM_ROOT = ../../../sourcemm-1.4.2 +SRCDS = ~/srcds +SMSDK = .. + +### EDIT BELOW FOR OTHER PROJECTS ### + +OPT_FLAGS = -O3 -funroll-loops -s -pipe +GCC4_FLAGS = -fvisibility=hidden -fvisibility-inlines-hidden +DEBUG_FLAGS = -g -ggdb3 +CPP = gcc-4.1 +BINARY = stub_mm_i486.so + +HL2PUB = $(HL2SDK)/public + +OBJECTS = stub_mm.cpp sm_ext.cpp sm_sdk_config.cpp stub_util.cpp + +LINK = vstdlib_i486.so tier0_i486.so -static-libgcc + +INCLUDE = -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/dlls -I$(HL2PUB)/engine -I$(HL2PUB)/tier0 \ + -I$(HL2PUB)/tier1 -I$(HL2PUB)/vstdlib -I$(HL2SDK)/tier1 -I$(SMM_ROOT) -I$(SMM_ROOT)/sourcehook \ + -I$(SMM_ROOT)/sourcemm -I$(SMSDK) -I$(SMSDK)/jit -I$(SMSDK)/jit/x86 -I$(SMSDK)/extensions \ + -I$(SMSDK)/sourcepawn + +ifeq "$(DEBUG)" "true" + BIN_DIR = Debug + CFLAGS = $(DEBUG_FLAGS) +else + BIN_DIR = Release + CFLAGS = $(OPT_FLAGS) +endif + +GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) + +CFLAGS += -D_LINUX -DNDEBUG -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \ + -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca \ + -Dstrcmpi=strcasecmp -Wall -Wno-non-virtual-dtor -Werror -fPIC -fno-exceptions -fno-rtti -msse \ + -fno-strict-aliasing + +ifeq "$(GCC_VERSION)" "4" + CFLAGS += $(GCC4_FLAGS) +endif + +OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) + +$(BIN_DIR)/%.o: %.cpp + $(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< + +all: + mkdir -p $(BIN_DIR) + rm -f vstdlib_i486.so + rm -f tier0_i486.so + ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so + ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so + $(MAKE) -f Makefile.orig stub_mm + rm -rf $(BINARY) + +stub_mm: $(OBJ_LINUX) + $(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + +debug: + $(MAKE) -f Makefile.orig all DEBUG=true + +default: all + +clean: + rm -rf Release/*.o + rm -rf Release/$(BINARY) + rm -rf Debug/*.o + rm -rf Debug/$(BINARY) diff --git a/public/mms_sample_ext/sm_ext.cpp b/public/mms_sample_ext/sm_ext.cpp new file mode 100644 index 00000000..d9abdfb2 --- /dev/null +++ b/public/mms_sample_ext/sm_ext.cpp @@ -0,0 +1,146 @@ +#include +#include "stub_mm.h" +#include "stub_util.h" +#include "sm_ext.h" + +MyExtension g_SMExt; + +bool SM_LoadExtension(char *error, size_t maxlength) +{ + if ((smexts = (IExtensionManager *)g_SMAPI->MetaFactory( + SOURCEMOD_INTERFACE_EXTENSIONS, + NULL, + NULL)) + == NULL) + { + if (error && maxlength) + { + UTIL_Format(error, maxlength, SOURCEMOD_INTERFACE_EXTENSIONS " interface not found"); + } + return false; + } + + /* This could be more dynamic */ + char path[256]; + g_SMAPI->PathFormat(path, + sizeof(path), + "%s/addons/myplugin/bin/myplugin%s", + g_SMAPI->GetBaseDir(), +#if defined __linux__ + "_i486.so" +#else + ".dll" +#endif + ); + + if ((myself = smexts->LoadExternal(&g_SMExt, + path, + "myplugin_mm.ext", + error, + maxlength)) + == NULL) + { + SM_UnsetInterfaces(); + return false; + } + + return true; +} + +void SM_UnloadExtension() +{ + smexts->UnloadExtension(myself); +} + +bool MyExtension::OnExtensionLoad(IExtension *me, + IShareSys *sys, + char *error, + size_t maxlength, + bool late) +{ + sharesys = sys; + myself = me; + + /* Get the default interfaces from our configured SDK header */ + if (!SM_AcquireInterfaces(error, maxlength)) + { + return false; + } + + return true; +} + +void MyExtension::OnExtensionUnload() +{ + /* Clean up any resources here, and more importantly, make sure + * any listeners/hooks into SourceMod are totally removed, as well + * as data structures like handle types and forwards. + */ + + //... + + /* Make sure our pointers get NULL'd just in case */ + SM_UnsetInterfaces(); +} + +void MyExtension::OnExtensionsAllLoaded() +{ + /* Called once all extensions are marked as loaded. + * This always called, and always called only once. + */ +} + +void MyExtension::OnExtensionPauseChange(bool pause) +{ +} + +bool MyExtension::QueryRunning(char *error, size_t maxlength) +{ + /* if something is required that can't be determined during the initial + * load process, print a message here will show a helpful message to + * users when they view the extension's info. + */ + return true; +} + +bool MyExtension::IsMetamodExtension() +{ + /* Must return false! */ + return false; +} + +const char *MyExtension::GetExtensionName() +{ + return mmsplugin->GetName(); +} + +const char *MyExtension::GetExtensionURL() +{ + return mmsplugin->GetURL(); +} + +const char *MyExtension::GetExtensionTag() +{ + return mmsplugin->GetLogTag(); +} + +const char *MyExtension::GetExtensionAuthor() +{ + return mmsplugin->GetAuthor(); +} + +const char *MyExtension::GetExtensionVerString() +{ + return mmsplugin->GetVersion(); +} + +const char *MyExtension::GetExtensionDescription() +{ + return mmsplugin->GetDescription(); +} + +const char *MyExtension::GetExtensionDateString() +{ + return mmsplugin->GetDate(); +} + diff --git a/public/mms_sample_ext/sm_ext.h b/public/mms_sample_ext/sm_ext.h new file mode 100644 index 00000000..24569822 --- /dev/null +++ b/public/mms_sample_ext/sm_ext.h @@ -0,0 +1,38 @@ +#ifndef _INCLUDE_SAMPLE_MMS_SOURCEMOD_EXTENSION_ +#define _INCLUDE_SAMPLE_MMS_SOURCEMOD_EXTENSION_ + +#include "sm_sdk_config.h" + +using namespace SourceMod; + +class MyExtension : public IExtensionInterface +{ +public: + virtual bool OnExtensionLoad(IExtension *me, + IShareSys *sys, + char *error, + size_t maxlength, + bool late); + virtual void OnExtensionUnload(); + virtual void OnExtensionsAllLoaded(); + virtual void OnExtensionPauseChange(bool pause); + virtual bool QueryRunning(char *error, size_t maxlength); + virtual bool IsMetamodExtension(); + virtual const char *GetExtensionName(); + virtual const char *GetExtensionURL(); + virtual const char *GetExtensionTag(); + virtual const char *GetExtensionAuthor(); + virtual const char *GetExtensionVerString(); + virtual const char *GetExtensionDescription(); + virtual const char *GetExtensionDateString(); +}; + +bool SM_LoadExtension(char *error, size_t maxlength); +void SM_UnloadExtension(); + +extern IShareSys *sharesys; +extern IExtension *myself; +extern MyExtension g_SMExt; + +#endif //_INCLUDE_SAMPLE_MMS_SOURCEMOD_EXTENSION_ + diff --git a/public/mms_sample_ext/sm_sdk_config.cpp b/public/mms_sample_ext/sm_sdk_config.cpp new file mode 100644 index 00000000..26426c35 --- /dev/null +++ b/public/mms_sample_ext/sm_sdk_config.cpp @@ -0,0 +1,151 @@ +#include "sm_sdk_config.h" + +using namespace SourceMod; + +bool SM_AcquireInterfaces(char *error, size_t maxlength) +{ + SM_FIND_IFACE_OR_FAIL(SOURCEMOD, sm_main, error, maxlength); + +#if defined SMEXT_ENABLE_FORWARDSYS + SM_FIND_IFACE_OR_FAIL(FORWARDMANAGER, sm_forwards, error, maxlength); +#endif +#if defined SMEXT_ENABLE_HANDLESYS + SM_FIND_IFACE_OR_FAIL(HANDLESYSTEM, sm_handlesys, error, maxlength); +#endif +#if defined SMEXT_ENABLE_PLAYERHELPERS + SM_FIND_IFACE_OR_FAIL(PLAYERMANAGER, sm_players, error, maxlength); +#endif +#if defined SMEXT_ENABLE_DBMANAGER + SM_FIND_IFACE_OR_FAIL(DBI, sm_dbi, error, maxlength); +#endif +#if defined SMEXT_ENABLE_GAMECONF + SM_FIND_IFACE_OR_FAIL(GAMECONFIG, sm_gameconfs, error, maxlength); +#endif +#if defined SMEXT_ENABLE_MEMUTILS + SM_FIND_IFACE_OR_FAIL(MEMORYUTILS, sm_memutils, error, maxlength); +#endif +#if defined SMEXT_ENABLE_GAMEHELPERS + SM_FIND_IFACE_OR_FAIL(GAMEHELPERS, sm_gamehelpers, error, maxlength); +#endif +#if defined SMEXT_ENABLE_TIMERSYS + SM_FIND_IFACE_OR_FAIL(TIMERSYS, sm_timersys, error, maxlength); +#endif +#if defined SMEXT_ENABLE_THREADER + SM_FIND_IFACE_OR_FAIL(THREADER, sm_threader, error, maxlength); +#endif +#if defined SMEXT_ENABLE_LIBSYS + SM_FIND_IFACE_OR_FAIL(LIBRARYSYS, sm_libsys, error, maxlength); +#endif +#if defined SMEXT_ENABLE_PLUGINSYS + SM_FIND_IFACE_OR_FAIL(PLUGINSYSTEM, sm_plsys, error, maxlength); +#endif +#if defined SMEXT_ENABLE_MENUS + SM_FIND_IFACE_OR_FAIL(MENUMANAGER, sm_menus, error, maxlength); +#endif +#if defined SMEXT_ENABLE_ADMINSYS + SM_FIND_IFACE_OR_FAIL(ADMINSYS, sm_adminsys, error, maxlength); +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS + SM_FIND_IFACE_OR_FAIL(TEXTPARSERS, sm_text, error, maxlength); +#endif + + return true; +} + +void SM_UnsetInterfaces() +{ + myself = NULL; + smexts = NULL; + sharesys = NULL; + sm_main = NULL; +#if defined SMEXT_ENABLE_FORWARDSYS + sm_forwards = NULL; +#endif +#if defined SMEXT_ENABLE_HANDLESYS + sm_handlesys = NULL; +#endif +#if defined SMEXT_ENABLE_PLAYERHELPERS + sm_players = NULL; +#endif +#if defined SMEXT_ENABLE_DBMANAGER + sm_dbi = NULL; +#endif +#if defined SMEXT_ENABLE_GAMECONF + sm_gameconfs = NULL; +#endif +#if defined SMEXT_ENABLE_MEMUTILS + sm_memutils = NULL; +#endif +#if defined SMEXT_ENABLE_GAMEHELPERS + sm_gamehelpers = NULL; +#endif +#if defined SMEXT_ENABLE_TIMERSYS + sm_timersys = NULL; +#endif +#if defined SMEXT_ENABLE_THREADER + sm_threader = NULL; +#endif +#if defined SMEXT_ENABLE_LIBSYS + sm_libsys = NULL; +#endif +#if defined SMEXT_ENABLE_PLUGINSYS + sm_plsys = NULL; +#endif +#if defined SMEXT_ENABLE_MENUS + sm_menus = NULL; +#endif +#if defined SMEXT_ENABLE_ADMINSYS + sm_adminsys = NULL; +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS + sm_text = NULL; +#endif +} + +IExtension *myself = NULL; +IExtensionManager *smexts = NULL; +IShareSys *sharesys = NULL; +SourceMod::ISourceMod *sm_main = NULL; +#if defined SMEXT_ENABLE_FORWARDSYS +SourceMod::IForwardManager *sm_forwards = NULL; +#endif +#if defined SMEXT_ENABLE_HANDLESYS +SourceMod::IHandleSys *sm_handlesys = NULL; +#endif +#if defined SMEXT_ENABLE_PLAYERHELPERS +SourceMod::IPlayerManager *sm_players = NULL; +#endif +#if defined SMEXT_ENABLE_DBMANAGER +SourceMod::IDBManager *sm_dbi = NULL; +#endif +#if defined SMEXT_ENABLE_GAMECONF +SourceMod::IGameConfigManager *sm_gameconfs = NULL; +#endif +#if defined SMEXT_ENABLE_MEMUTILS +SourceMod::IMemoryUtils *sm_memutils = NULL; +#endif +#if defined SMEXT_ENABLE_GAMEHELPERS +SourceMod::IGameHelpers *sm_gamehelpers = NULL; +#endif +#if defined SMEXT_ENABLE_TIMERSYS +SourceMod::ITimerSystem *sm_timersys = NULL; +#endif +#if defined SMEXT_ENABLE_THREADER +SourceMod::IThreader *sm_threader = NULL; +#endif +#if defined SMEXT_ENABLE_LIBSYS +SourceMod::ILibrarySys *sm_libsys = NULL; +#endif +#if defined SMEXT_ENABLE_PLUGINSYS +SourceMod::IPluginManager *sm_plsys = NULL; +#endif +#if defined SMEXT_ENABLE_MENUS +SourceMod::IMenuManager *sm_menus = NULL; +#endif +#if defined SMEXT_ENABLE_ADMINSYS +SourceMod::IAdminSystem *sm_adminsys = NULL; +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS +SourceMod::ITextParsers *sm_text = NULL; +#endif + diff --git a/public/mms_sample_ext/sm_sdk_config.h b/public/mms_sample_ext/sm_sdk_config.h new file mode 100644 index 00000000..59f854b5 --- /dev/null +++ b/public/mms_sample_ext/sm_sdk_config.h @@ -0,0 +1,128 @@ +#ifndef _INCLUDE_SOURCEMOD_CONFIG_H_ +#define _INCLUDE_SOURCEMOD_CONFIG_H_ + +#include + +/** + * @brief Acquires the interfaces enabled at the bottom of this header. + * + * @param error Buffer to store error message. + * @param maxlength Maximum size of the error buffer. + * @return True on success, false on failure. + * On failure, a null-terminated string will be stored + * in the error buffer, if the buffer is non-NULL and + * greater than 0 bytes in size. + */ +bool SM_AcquireInterfaces(char *error, size_t maxlength); + +/** + * @brief Sets each acquired interface to NULL. + */ +void SM_UnsetInterfaces(); + +/** + * Enable interfaces you want to use here by uncommenting lines. + * These interfaces are all part of SourceMod's core. + */ +//#define SMEXT_ENABLE_FORWARDSYS +//#define SMEXT_ENABLE_HANDLESYS +//#define SMEXT_ENABLE_PLAYERHELPERS +//#define SMEXT_ENABLE_DBMANAGER +//#define SMEXT_ENABLE_GAMECONF +//#define SMEXT_ENABLE_MEMUTILS +//#define SMEXT_ENABLE_GAMEHELPERS +//#define SMEXT_ENABLE_TIMERSYS +//#define SMEXT_ENABLE_THREADER +//#define SMEXT_ENABLE_LIBSYS +//#define SMEXT_ENABLE_MENUS +//#define SMEXT_ENABLE_ADTFACTORY +//#define SMEXT_ENABLE_PLUGINSYS +//#define SMEXT_ENABLE_ADMINSYS +//#define SMEXT_ENABLE_TEXTPARSERS + + +/** + * There is no need to edit below. + */ + +#include +#include +extern SourceMod::IExtension *myself; +extern SourceMod::IExtensionManager *smexts; +extern SourceMod::IShareSys *sharesys; + +#include +extern SourceMod::ISourceMod *sm_main; + +#if defined SMEXT_ENABLE_FORWARDSYS +#include +extern SourceMod::IForwardManager *sm_forwards; +#endif + +#if defined SMEXT_ENABLE_HANDLESYS +#include +extern SourceMod::IHandleSys *sm_handlesys; +#endif + +#if defined SMEXT_ENABLE_PLAYERHELPERS +#include +extern SourceMod::IPlayerManager *sm_players; +#endif + +#if defined SMEXT_ENABLE_DBMANAGER +#include +extern SourceMod::IDBManager *sm_dbi; +#endif + +#if defined SMEXT_ENABLE_GAMECONF +#include +extern SourceMod::IGameConfigManager *sm_gameconfs; +#endif + +#if defined SMEXT_ENABLE_MEMUTILS +#include +extern SourceMod::IMemoryUtils *sm_memutils; +#endif + +#if defined SMEXT_ENABLE_GAMEHELPERS +#include +extern SourceMod::IGameHelpers *sm_gamehelpers; +#endif + +#if defined SMEXT_ENABLE_TIMERSYS +#include +extern SourceMod::ITimerSystem *sm_timersys; +#endif + +#if defined SMEXT_ENABLE_THREADER +#include +extern SourceMod::IThreader *sm_threader; +#endif + +#if defined SMEXT_ENABLE_LIBSYS +#include +extern SourceMod::ILibrarySys *sm_libsys; +#endif + +#if defined SMEXT_ENABLE_PLUGINSYS +#include +extern SourceMod::IPluginManager *sm_plsys; +#endif + +#if defined SMEXT_ENABLE_MENUS +#include +extern SourceMod::IMenuManager *sm_menus; +#endif + +#if defined SMEXT_ENABLE_ADMINSYS +#include +extern SourceMod::IAdminSystem *sm_adminsys; +#endif + +#if defined SMEXT_ENABLE_TEXTPARSERS +#include +extern SourceMod::ITextParsers *sm_text; +#endif + +#endif //_INCLUDE_SOURCEMOD_CONFIG_H_ + diff --git a/public/mms_sample_ext/stub_mm.cpp b/public/mms_sample_ext/stub_mm.cpp new file mode 100644 index 00000000..3a8fe81f --- /dev/null +++ b/public/mms_sample_ext/stub_mm.cpp @@ -0,0 +1,142 @@ +/** + * vim: set ts=4 : + * ====================================================== + * Metamod:Source Stub Plugin + * Written by AlliedModders LLC. + * ====================================================== + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from + * the use of this software. + * + * This stub plugin is public domain. + * + * Version: $Id: stub_mm.cpp 534 2007-10-30 18:22:12Z dvander $ + */ + +#include +#include "stub_mm.h" +#include "stub_util.h" +#include "sm_ext.h" + +SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int, int); + +StubPlugin g_StubPlugin; +IVEngineServer *engine = NULL; +IServerGameDLL *server = NULL; +ISmmPlugin *mmsplugin = &g_StubPlugin; + +PLUGIN_EXPOSE(StubPlugin, g_StubPlugin); +bool StubPlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late) +{ + PLUGIN_SAVEVARS(); + +#if defined METAMOD_PLAPI_VERSION + GET_V_IFACE_ANY(GetServerFactory, server, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); + GET_V_IFACE_ANY(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#else + GET_V_IFACE_ANY(serverFactory, server, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); + GET_V_IFACE_ANY(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#endif + + SH_ADD_HOOK_STATICFUNC(IServerGameDLL, ServerActivate, server, Hook_ServerActivate, true); + + return true; +} + +bool StubPlugin::Unload(char *error, size_t maxlen) +{ + SM_UnloadExtension(); + + SH_REMOVE_HOOK_STATICFUNC(IServerGameDLL, ServerActivate, server, Hook_ServerActivate, true); + + return true; +} + +void Hook_ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) +{ + META_LOG(g_PLAPI, "ServerActivate() called: edictCount = %d, clientMax = %d", edictCount, clientMax); +} + +void *StubPlugin::OnMetamodQuery(const char *iface, int *ret) +{ + if (strcmp(iface, SOURCEMOD_NOTICE_EXTENSIONS) == 0) + { + BindToSourcemod(); + } + + if (ret != NULL) + { + *ret = IFACE_OK; + } + + return NULL; +} + +void StubPlugin::AllPluginsLoaded() +{ + BindToSourcemod(); +} + +void StubPlugin::BindToSourcemod() +{ + char error[256]; + + if (!SM_LoadExtension(error, sizeof(error))) + { + char message[512]; + UTIL_Format(message, sizeof(message), "Could not load as a SourceMod extension: %s\n", error); + engine->LogPrint(message); + } +} + +bool StubPlugin::Pause(char *error, size_t maxlen) +{ + return true; +} + +bool StubPlugin::Unpause(char *error, size_t maxlen) +{ + return true; +} + +const char *StubPlugin::GetLicense() +{ + return "Public Domain"; +} + +const char *StubPlugin::GetVersion() +{ + return "1.0.0.0"; +} + +const char *StubPlugin::GetDate() +{ + return __DATE__; +} + +const char *StubPlugin::GetLogTag() +{ + return "STUB"; +} + +const char *StubPlugin::GetAuthor() +{ + return "AlliedModders LLC"; +} + +const char *StubPlugin::GetDescription() +{ + return "Sample empty plugin"; +} + +const char *StubPlugin::GetName() +{ + return "Stub Plugin"; +} + +const char *StubPlugin::GetURL() +{ + return "http://www.sourcemm.net/"; +} + diff --git a/public/mms_sample_ext/stub_mm.h b/public/mms_sample_ext/stub_mm.h new file mode 100644 index 00000000..b441a52b --- /dev/null +++ b/public/mms_sample_ext/stub_mm.h @@ -0,0 +1,54 @@ +/** + * vim: set ts=4 : + * ====================================================== + * Metamod:Source Stub Plugin + * Written by AlliedModders LLC. + * ====================================================== + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from + * the use of this software. + * + * This stub plugin is public domain. + * + * Version: $Id: stub_mm.h 463 2007-10-06 17:01:51Z dvander $ + */ + +#ifndef _INCLUDE_METAMOD_SOURCE_STUB_PLUGIN_H_ +#define _INCLUDE_METAMOD_SOURCE_STUB_PLUGIN_H_ + +#include + +class StubPlugin : + public ISmmPlugin, + public IMetamodListener +{ +public: + bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late); + bool Unload(char *error, size_t maxlen); + bool Pause(char *error, size_t maxlen); + bool Unpause(char *error, size_t maxlen); + void AllPluginsLoaded(); + const char *GetAuthor(); + const char *GetName(); + const char *GetDescription(); + const char *GetURL(); + const char *GetLicense(); + const char *GetVersion(); + const char *GetDate(); + const char *GetLogTag(); +public: //IMetamodListener + void *OnMetamodQuery(const char *iface, int *ret); +private: + void BindToSourcemod(); +}; + +void Hook_ServerActivate(edict_t *pEdictList, int edictCount, int clientMax); + +extern StubPlugin g_StubPlugin; +extern ISmmPlugin *mmsplugin; + +PLUGIN_GLOBALVARS(); + +#endif //_INCLUDE_METAMOD_SOURCE_STUB_PLUGIN_H_ + diff --git a/public/mms_sample_ext/stub_util.cpp b/public/mms_sample_ext/stub_util.cpp new file mode 100644 index 00000000..e62b4909 --- /dev/null +++ b/public/mms_sample_ext/stub_util.cpp @@ -0,0 +1,22 @@ +#include +#include +#include "stub_util.h" + +size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + size_t len = vsnprintf(buffer, maxlength, fmt, ap); + va_end(ap); + + if (len >= maxlength) + { + len = maxlength - 1; + buffer[len] = '\0'; + } + + return len; +} + + diff --git a/public/mms_sample_ext/stub_util.h b/public/mms_sample_ext/stub_util.h new file mode 100644 index 00000000..5e9cd3b1 --- /dev/null +++ b/public/mms_sample_ext/stub_util.h @@ -0,0 +1,15 @@ +#ifndef _INCLUDE_STUB_UTIL_FUNCTIONS_H_ +#define _INCLUDE_STUB_UTIL_FUNCTIONS_H_ + +#include + +/** + * This is a platform-safe function which fixes weird idiosyncracies + * in the null-termination and return value of snprintf(). It guarantees + * the terminator on overflow cases, and never returns -1 or a value + * not equal to the number of non-terminating bytes written. + */ +size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...); + +#endif //_INCLUDE_STUB_UTIL_FUNCTIONS_H_ +