From 1fe38c747347aae75cf7058eedb9f72583f3b3c6 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 23 Dec 2008 01:33:37 -0500 Subject: [PATCH 1/8] SourceMod can now be somewhat compiled on OS X for patch sanity testing (bug 3516, r=ds). This adds the ability for us to change the GCC version we use more flexibly. --- core/CDataPack.cpp | 2 +- core/CellArray.h | 2 +- core/CoreConfig.cpp | 4 +- core/GameConfigs.cpp | 3 ++ core/LibrarySys.cpp | 8 ++-- core/Makefile | 2 +- core/md5.cpp | 13 +----- core/sm_memtable.cpp | 2 +- core/sm_queue.h | 2 +- core/smn_adt_array.cpp | 2 +- core/smn_adt_stack.cpp | 2 +- core/smn_adt_trie.cpp | 2 +- core/smn_core.cpp | 3 ++ core/smn_string.cpp | 2 +- extensions/bintools/Makefile | 18 ++++++--- extensions/bintools/sdk/smsdk_ext.cpp | 50 ++++++++++++++++++++++- extensions/clientprefs/Makefile | 17 +++++--- extensions/clientprefs/sdk/smsdk_ext.cpp | 5 ++- extensions/cstrike/Makefile | 15 +++++-- extensions/cstrike/sdk/smsdk_ext.cpp | 44 +++++++++++++++++++- extensions/geoip/Makefile | 17 +++++--- extensions/geoip/sdk/smsdk_ext.cpp | 50 ++++++++++++++++++++++- extensions/mysql/Makefile | 15 +++++-- extensions/mysql/sdk/smsdk_ext.cpp | 50 ++++++++++++++++++++++- extensions/regex/Makefile | 17 +++++--- extensions/regex/sdk/smsdk_ext.cpp | 13 ++++-- extensions/sdktools/Makefile | 15 +++++-- extensions/sdktools/detours.h | 2 +- extensions/sdktools/sdk/smsdk_ext.cpp | 44 +++++++++++++++++++- extensions/sqlite/Makefile | 17 +++++--- extensions/sqlite/driver/SqDriver.cpp | 2 +- extensions/sqlite/driver/SqResults.cpp | 2 +- extensions/sqlite/sdk/sm_memtable.cpp | 2 +- extensions/sqlite/sdk/smsdk_ext.cpp | 51 +++++++++++++++++++++++- extensions/tf2/CDetour/detourhelpers.h | 4 +- extensions/tf2/Makefile | 17 +++++--- extensions/tf2/sdk/smsdk_ext.cpp | 44 +++++++++++++++++++- extensions/topmenus/Makefile | 17 +++++--- extensions/topmenus/sdk/sm_memtable.cpp | 2 +- extensions/topmenus/sdk/smsdk_ext.cpp | 26 +++++++++++- knight/shared/KePlatform.h | 2 + loader/Makefile | 17 +++++--- loader/loader.cpp | 6 +-- public/mms_sample_ext/Makefile | 17 +++++--- public/sample_ext/Makefile | 17 +++++--- public/sample_ext/sdk/smsdk_ext.cpp | 5 ++- public/sm_platform.h | 12 +++++- public/sm_trie_tpl.h | 2 +- public/sourcepawn/sp_file_headers.h | 2 +- sourcepawn/compiler/Makefile | 4 +- sourcepawn/compiler/libpawnc.c | 1 - sourcepawn/compiler/memfile.h | 2 +- sourcepawn/compiler/osdefs.h | 2 + sourcepawn/compiler/sclinux.h | 2 +- sourcepawn/compiler/sctracker.c | 2 +- sourcepawn/compiler/sp_file.c | 2 +- sourcepawn/jit/Makefile | 17 +++++--- sourcepawn/jit/dll_exports.cpp | 4 +- sourcepawn/jit/sp_vm_engine.cpp | 6 ++- sourcepawn/jit/x86/opcode_helpers.cpp | 2 +- tools/builder/LinuxBuilder.cs | 7 ++-- tools/crc32/build.sh | 2 +- tools/daemon/Makefile | 4 +- tools/gamedata_md5/Makefile | 4 +- tools/gamedata_md5/sm_memtable.cpp | 2 +- 65 files changed, 599 insertions(+), 149 deletions(-) diff --git a/core/CDataPack.cpp b/core/CDataPack.cpp index 99d15694..59352c92 100644 --- a/core/CDataPack.cpp +++ b/core/CDataPack.cpp @@ -29,7 +29,7 @@ * Version: $Id$ */ -#include +#include #include #include "CDataPack.h" diff --git a/core/CellArray.h b/core/CellArray.h index c5ec78b0..5aa4332f 100644 --- a/core/CellArray.h +++ b/core/CellArray.h @@ -29,7 +29,7 @@ * Version: $Id$ */ -#include +#include #include extern HandleType_t htCellArray; diff --git a/core/CoreConfig.cpp b/core/CoreConfig.cpp index 68aeccf8..4b79c29a 100644 --- a/core/CoreConfig.cpp +++ b/core/CoreConfig.cpp @@ -44,7 +44,7 @@ #ifdef PLATFORM_WINDOWS ConVar sm_corecfgfile("sm_corecfgfile", "addons\\sourcemod\\configs\\core.cfg", 0, "SourceMod core configuration file"); -#elif defined PLATFORM_LINUX +#elif defined PLATFORM_LINUX || defined PLATFORM_APPLE ConVar sm_corecfgfile("sm_corecfgfile", "addons/sourcemod/configs/core.cfg", 0, "SourceMod core configuration file"); #endif @@ -275,7 +275,7 @@ inline bool IsPathSepChar(char c) { #if defined PLATFORM_WINDOWS return (c == '\\' || c == '/'); -#elif defined PLATFORM_LINUX +#elif defined PLATFORM_LINUX || defined PLATFORM_POSIX return (c == '/'); #endif } diff --git a/core/GameConfigs.cpp b/core/GameConfigs.cpp index 788e31a9..726c1744 100644 --- a/core/GameConfigs.cpp +++ b/core/GameConfigs.cpp @@ -73,6 +73,9 @@ char g_GameName[256] = {'$', '\0'}; #elif defined PLATFORM_LINUX #define PLATFORM_NAME "linux" #define PLATFORM_SERVER_BINARY "server_i486.so" +#elif defined PLATFORM_APPLE +#define PLATFORM_NAME "undef" +#define PLATFORM_SERVER_BINARY "undef.dylib" #endif struct TempSigInfo diff --git a/core/LibrarySys.cpp b/core/LibrarySys.cpp index 7d33b918..b7395d7a 100644 --- a/core/LibrarySys.cpp +++ b/core/LibrarySys.cpp @@ -138,7 +138,7 @@ bool CDirectory::IsEntryDirectory() { #if defined PLATFORM_WINDOWS return ((m_fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY); -#elif defined PLATFORM_LINUX +#elif defined PLATFORM_POSIX char temppath[PLATFORM_MAX_PATH]; snprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName()); return g_LibSys.IsPathDirectory(temppath); @@ -160,7 +160,7 @@ const char *CDirectory::GetEntryName() { #if defined PLATFORM_WINDOWS return m_fd.cFileName; -#elif defined PLATFORM_LINUX +#elif defined PLATFORM_POSIX return ep ? ep->d_name : ""; #endif } @@ -174,7 +174,7 @@ bool CDirectory::IsValid() { #if defined PLATFORM_WINDOWS return (m_dir != INVALID_HANDLE_VALUE); -#elif defined PLATFORM_LINUX +#elif defined PLATFORM_POSIX return (m_dir != NULL); #endif } @@ -214,7 +214,7 @@ bool LibrarySystem::IsPathFile(const char *path) } return true; -#elif defined PLATFORM_LINUX +#elif defined PLATFORM_POSIX struct stat s; if (stat(path, &s) != 0) diff --git a/core/Makefile b/core/Makefile index 38ea2128..5d8fc20a 100644 --- a/core/Makefile +++ b/core/Makefile @@ -43,7 +43,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc override ENGSET = false ifeq "$(ENGINE)" "original" diff --git a/core/md5.cpp b/core/md5.cpp index a5c899ef..8738c6df 100644 --- a/core/md5.cpp +++ b/core/md5.cpp @@ -201,11 +201,7 @@ char *MD5::hex_digest(){ int i; char *s= new char[33]; - if (!finalized){ -/* cerr << "MD5::hex_digest: Can't get digest if you haven't "<< - "finalized the digest!" < -#include +#include #include "sm_memtable.h" BaseMemTable::BaseMemTable(unsigned int init_size) diff --git a/core/sm_queue.h b/core/sm_queue.h index 4d438ad5..ff46a583 100644 --- a/core/sm_queue.h +++ b/core/sm_queue.h @@ -33,7 +33,7 @@ #define _INCLUDE_SM_QUEUE_H #include -#include +#include #include using namespace SourceHook; diff --git a/core/smn_adt_array.cpp b/core/smn_adt_array.cpp index 08852eb0..a03309bb 100644 --- a/core/smn_adt_array.cpp +++ b/core/smn_adt_array.cpp @@ -29,7 +29,7 @@ * Version: $Id$ */ -#include +#include #include "sm_globals.h" #include "sm_stringutil.h" #include "CellArray.h" diff --git a/core/smn_adt_stack.cpp b/core/smn_adt_stack.cpp index 0bf4cb68..5fd1db79 100644 --- a/core/smn_adt_stack.cpp +++ b/core/smn_adt_stack.cpp @@ -29,7 +29,7 @@ * Version: $Id$ */ -#include +#include #include "sm_globals.h" #include "sm_stringutil.h" #include "CellArray.h" diff --git a/core/smn_adt_trie.cpp b/core/smn_adt_trie.cpp index 19ef31a3..623e2dd6 100644 --- a/core/smn_adt_trie.cpp +++ b/core/smn_adt_trie.cpp @@ -29,7 +29,7 @@ * Version: $Id$ */ -#include +#include #include "sm_globals.h" #include "sm_stringutil.h" #include "HandleSys.h" diff --git a/core/smn_core.cpp b/core/smn_core.cpp index e75ae368..91acfa66 100644 --- a/core/smn_core.cpp +++ b/core/smn_core.cpp @@ -418,6 +418,9 @@ static cell_t GetSysTickCount(IPluginContext *pContext, const cell_t *params) fticks -= r; } return (cell_t)fticks; +#elif defined PLATFORM_APPLE + assert(false); + return 0; #endif } diff --git a/core/smn_string.cpp b/core/smn_string.cpp index 3aa5dc6b..e708280b 100644 --- a/core/smn_string.cpp +++ b/core/smn_string.cpp @@ -40,7 +40,7 @@ inline const char *_strstr(const char *str, const char *substr) { #ifdef PLATFORM_WINDOWS return strstr(str, substr); -#elif defined PLATFORM_LINUX +#elif defined PLATFORM_LINUX || defined PLATFORM_APPLE return (const char *)strstr(str, substr); #endif } diff --git a/extensions/bintools/Makefile b/extensions/bintools/Makefile index bcd84c29..d7f69d0f 100644 --- a/extensions/bintools/Makefile +++ b/extensions/bintools/Makefile @@ -26,7 +26,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc override ENGSET = false ifeq "$(ENGINE)" "original" @@ -61,7 +61,7 @@ else -I$(SMSDK)/public/jit/x86 -I$(SMSDK)/public/sourcepawn endif -LINK += -static-libgcc +LINK += -m32 -ldl -lm CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \ -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror -mfpmath=sse \ @@ -84,14 +84,21 @@ ifeq "$(USEMETA)" "true" BIN_DIR := $(BIN_DIR).$(ENGINE) endif +OS := $(shell uname -s) +ifeq "$(OS)" "Darwin" + LINK += -dynamiclib + BINARY = $(PROJECT).ext.dylib +else + LINK += -static-libgcc -shared + BINARY = $(PROJECT).ext.so +endif + GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ifeq "$(GCC_VERSION)" "4" CFLAGS += $(C_GCC4_FLAGS) CPPFLAGS += $(CPP_GCC4_FLAGS) endif -BINARY = $(PROJECT).ext.so - OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) $(BIN_DIR)/%.o: %.cpp @@ -112,7 +119,7 @@ check: fi extension: check $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true @@ -123,3 +130,4 @@ clean: check rm -rf $(BIN_DIR)/*.o rm -rf $(BIN_DIR)/sdk/*.o rm -rf $(BIN_DIR)/$(BINARY) + diff --git a/extensions/bintools/sdk/smsdk_ext.cpp b/extensions/bintools/sdk/smsdk_ext.cpp index db14af69..6404a919 100644 --- a/extensions/bintools/sdk/smsdk_ext.cpp +++ b/extensions/bintools/sdk/smsdk_ext.cpp @@ -30,7 +30,7 @@ */ #include -#include +#include #include "smsdk_ext.h" /** @@ -79,6 +79,24 @@ IThreader *threader = NULL; #if defined SMEXT_ENABLE_LIBSYS ILibrarySys *libsys = NULL; #endif +#if defined SMEXT_ENABLE_PLUGINSYS +SourceMod::IPluginManager *plsys; +#endif +#if defined SMEXT_ENABLE_MENUS +IMenuManager *menus = NULL; +#endif +#if defined SMEXT_ENABLE_ADMINSYS +IAdminSystem *adminsys = NULL; +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS +ITextParsers *textparsers = NULL; +#endif +#if defined SMEXT_ENABLE_USERMSGS +IUserMessages *usermsgs = NULL; +#endif +#if defined SMEXT_ENABLE_TRANSLATOR +ITranslator *translator = NULL; +#endif /** Exports the main interface */ PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() @@ -149,6 +167,24 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, #if defined SMEXT_ENABLE_LIBSYS SM_GET_IFACE(LIBRARYSYS, libsys); #endif +#if defined SMEXT_ENABLE_PLUGINSYS + SM_GET_IFACE(PLUGINSYSTEM, plsys); +#endif +#if defined SMEXT_ENABLE_MENUS + SM_GET_IFACE(MENUMANAGER, menus); +#endif +#if defined SMEXT_ENABLE_ADMINSYS + SM_GET_IFACE(ADMINSYS, adminsys); +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS + SM_GET_IFACE(TEXTPARSERS, textparsers); +#endif +#if defined SMEXT_ENABLE_USERMSGS + SM_GET_IFACE(USERMSGS, usermsgs); +#endif +#if defined SMEXT_ENABLE_TRANSLATOR + SM_GET_IFACE(TRANSLATOR, translator); +#endif if (SDK_OnLoad(error, maxlength, late)) { @@ -256,7 +292,11 @@ IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */ /** Exposes the extension to Metamod */ SMM_API void *PL_EXPOSURE(const char *name, int *code) { +#if defined METAMOD_PLAPI_VERSION + if (name && !strcmp(name, METAMOD_PLAPI_NAME)) +#else if (name && !strcmp(name, PLAPI_NAME)) +#endif { if (code) { @@ -277,8 +317,13 @@ bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, { PLUGIN_SAVEVARS(); +#if !defined METAMOD_PLAPI_VERSION GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#else + GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); + GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#endif m_SourceMMLoaded = true; @@ -389,7 +434,7 @@ bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t max #endif /* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ extern "C" void __cxa_pure_virtual(void) { } @@ -414,3 +459,4 @@ void operator delete[](void * ptr) free(ptr); } #endif + diff --git a/extensions/clientprefs/Makefile b/extensions/clientprefs/Makefile index 74c1c915..6a25ab71 100644 --- a/extensions/clientprefs/Makefile +++ b/extensions/clientprefs/Makefile @@ -26,7 +26,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc override ENGSET = false ifeq "$(ENGINE)" "original" @@ -61,7 +61,7 @@ else -I$(MMSOURCE17)/core/sourcehook endif -LINK += -static-libgcc +LINK += -m32 -ldl -lm CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \ -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror -Wno-switch \ @@ -84,14 +84,21 @@ ifeq "$(USEMETA)" "true" BIN_DIR := $(BIN_DIR).$(ENGINE) endif +OS := $(shell uname -s) +ifeq "$(OS)" "Darwin" + LINK += -dynamiclib + BINARY = $(PROJECT).ext.dylib +else + LINK += -static-libgcc -shared + BINARY = $(PROJECT).ext.so +endif + GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ifeq "$(GCC_VERSION)" "4" CFLAGS += $(C_GCC4_FLAGS) CPPFLAGS += $(CPP_GCC4_FLAGS) endif -BINARY = $(PROJECT).ext.so - OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) $(BIN_DIR)/%.o: %.cpp @@ -112,7 +119,7 @@ check: fi extension: check $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/extensions/clientprefs/sdk/smsdk_ext.cpp b/extensions/clientprefs/sdk/smsdk_ext.cpp index 865f536e..6404a919 100644 --- a/extensions/clientprefs/sdk/smsdk_ext.cpp +++ b/extensions/clientprefs/sdk/smsdk_ext.cpp @@ -30,7 +30,7 @@ */ #include -#include +#include #include "smsdk_ext.h" /** @@ -434,7 +434,7 @@ bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t max #endif /* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ extern "C" void __cxa_pure_virtual(void) { } @@ -459,3 +459,4 @@ void operator delete[](void * ptr) free(ptr); } #endif + diff --git a/extensions/cstrike/Makefile b/extensions/cstrike/Makefile index df1fc6a2..8af4f349 100644 --- a/extensions/cstrike/Makefile +++ b/extensions/cstrike/Makefile @@ -26,7 +26,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc override ENGSET = false ifeq "$(ENGINE)" "original" @@ -61,7 +61,7 @@ else INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn endif -LINK += -static-libgcc +LINK += -m32 -ldl -lm CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \ -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror -mfpmath=sse \ @@ -84,6 +84,15 @@ ifeq "$(USEMETA)" "true" BIN_DIR := $(BIN_DIR).$(ENGINE) endif +OS := $(shell uname -s) +ifeq "$(OS)" "Darwin" + LINK += -dynamiclib + BINARY = $(PROJECT).ext.dylib +else + LINK += -static-libgcc -shared + BINARY = $(PROJECT).ext.so +endif + GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ifeq "$(GCC_VERSION)" "4" CFLAGS += $(C_GCC4_FLAGS) @@ -111,7 +120,7 @@ check: fi extension: check $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/extensions/cstrike/sdk/smsdk_ext.cpp b/extensions/cstrike/sdk/smsdk_ext.cpp index 37733333..6404a919 100644 --- a/extensions/cstrike/sdk/smsdk_ext.cpp +++ b/extensions/cstrike/sdk/smsdk_ext.cpp @@ -30,7 +30,7 @@ */ #include -#include +#include #include "smsdk_ext.h" /** @@ -79,9 +79,24 @@ IThreader *threader = NULL; #if defined SMEXT_ENABLE_LIBSYS ILibrarySys *libsys = NULL; #endif +#if defined SMEXT_ENABLE_PLUGINSYS +SourceMod::IPluginManager *plsys; +#endif +#if defined SMEXT_ENABLE_MENUS +IMenuManager *menus = NULL; +#endif +#if defined SMEXT_ENABLE_ADMINSYS +IAdminSystem *adminsys = NULL; +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS +ITextParsers *textparsers = NULL; +#endif #if defined SMEXT_ENABLE_USERMSGS IUserMessages *usermsgs = NULL; #endif +#if defined SMEXT_ENABLE_TRANSLATOR +ITranslator *translator = NULL; +#endif /** Exports the main interface */ PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() @@ -152,9 +167,24 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, #if defined SMEXT_ENABLE_LIBSYS SM_GET_IFACE(LIBRARYSYS, libsys); #endif +#if defined SMEXT_ENABLE_PLUGINSYS + SM_GET_IFACE(PLUGINSYSTEM, plsys); +#endif +#if defined SMEXT_ENABLE_MENUS + SM_GET_IFACE(MENUMANAGER, menus); +#endif +#if defined SMEXT_ENABLE_ADMINSYS + SM_GET_IFACE(ADMINSYS, adminsys); +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS + SM_GET_IFACE(TEXTPARSERS, textparsers); +#endif #if defined SMEXT_ENABLE_USERMSGS SM_GET_IFACE(USERMSGS, usermsgs); #endif +#if defined SMEXT_ENABLE_TRANSLATOR + SM_GET_IFACE(TRANSLATOR, translator); +#endif if (SDK_OnLoad(error, maxlength, late)) { @@ -262,7 +292,11 @@ IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */ /** Exposes the extension to Metamod */ SMM_API void *PL_EXPOSURE(const char *name, int *code) { +#if defined METAMOD_PLAPI_VERSION if (name && !strcmp(name, METAMOD_PLAPI_NAME)) +#else + if (name && !strcmp(name, PLAPI_NAME)) +#endif { if (code) { @@ -283,8 +317,13 @@ bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, { PLUGIN_SAVEVARS(); +#if !defined METAMOD_PLAPI_VERSION + GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); + GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#else GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#endif m_SourceMMLoaded = true; @@ -395,7 +434,7 @@ bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t max #endif /* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ extern "C" void __cxa_pure_virtual(void) { } @@ -420,3 +459,4 @@ void operator delete[](void * ptr) free(ptr); } #endif + diff --git a/extensions/geoip/Makefile b/extensions/geoip/Makefile index ff77b74c..131c5c03 100644 --- a/extensions/geoip/Makefile +++ b/extensions/geoip/Makefile @@ -26,7 +26,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc override ENGSET = false ifeq "$(ENGINE)" "original" @@ -60,7 +60,7 @@ else INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn endif -LINK += -static-libgcc +LINK += -m32 -ldl -lm CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \ -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror -mfpmath=sse \ @@ -83,14 +83,21 @@ ifeq "$(USEMETA)" "true" BIN_DIR := $(BIN_DIR).$(ENGINE) endif +OS := $(shell uname -s) +ifeq "$(OS)" "Darwin" + LINK += -dynamiclib + BINARY = $(PROJECT).ext.dylib +else + LINK += -static-libgcc -shared + BINARY = $(PROJECT).ext.so +endif + GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ifeq "$(GCC_VERSION)" "4" CFLAGS += $(C_GCC4_FLAGS) CPPFLAGS += $(CPP_GCC4_FLAGS) endif -BINARY = $(PROJECT).ext.so - OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) $(BIN_DIR)/%.o: %.cpp @@ -111,7 +118,7 @@ check: fi extension: check $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/extensions/geoip/sdk/smsdk_ext.cpp b/extensions/geoip/sdk/smsdk_ext.cpp index db14af69..6404a919 100644 --- a/extensions/geoip/sdk/smsdk_ext.cpp +++ b/extensions/geoip/sdk/smsdk_ext.cpp @@ -30,7 +30,7 @@ */ #include -#include +#include #include "smsdk_ext.h" /** @@ -79,6 +79,24 @@ IThreader *threader = NULL; #if defined SMEXT_ENABLE_LIBSYS ILibrarySys *libsys = NULL; #endif +#if defined SMEXT_ENABLE_PLUGINSYS +SourceMod::IPluginManager *plsys; +#endif +#if defined SMEXT_ENABLE_MENUS +IMenuManager *menus = NULL; +#endif +#if defined SMEXT_ENABLE_ADMINSYS +IAdminSystem *adminsys = NULL; +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS +ITextParsers *textparsers = NULL; +#endif +#if defined SMEXT_ENABLE_USERMSGS +IUserMessages *usermsgs = NULL; +#endif +#if defined SMEXT_ENABLE_TRANSLATOR +ITranslator *translator = NULL; +#endif /** Exports the main interface */ PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() @@ -149,6 +167,24 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, #if defined SMEXT_ENABLE_LIBSYS SM_GET_IFACE(LIBRARYSYS, libsys); #endif +#if defined SMEXT_ENABLE_PLUGINSYS + SM_GET_IFACE(PLUGINSYSTEM, plsys); +#endif +#if defined SMEXT_ENABLE_MENUS + SM_GET_IFACE(MENUMANAGER, menus); +#endif +#if defined SMEXT_ENABLE_ADMINSYS + SM_GET_IFACE(ADMINSYS, adminsys); +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS + SM_GET_IFACE(TEXTPARSERS, textparsers); +#endif +#if defined SMEXT_ENABLE_USERMSGS + SM_GET_IFACE(USERMSGS, usermsgs); +#endif +#if defined SMEXT_ENABLE_TRANSLATOR + SM_GET_IFACE(TRANSLATOR, translator); +#endif if (SDK_OnLoad(error, maxlength, late)) { @@ -256,7 +292,11 @@ IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */ /** Exposes the extension to Metamod */ SMM_API void *PL_EXPOSURE(const char *name, int *code) { +#if defined METAMOD_PLAPI_VERSION + if (name && !strcmp(name, METAMOD_PLAPI_NAME)) +#else if (name && !strcmp(name, PLAPI_NAME)) +#endif { if (code) { @@ -277,8 +317,13 @@ bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, { PLUGIN_SAVEVARS(); +#if !defined METAMOD_PLAPI_VERSION GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#else + GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); + GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#endif m_SourceMMLoaded = true; @@ -389,7 +434,7 @@ bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t max #endif /* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ extern "C" void __cxa_pure_virtual(void) { } @@ -414,3 +459,4 @@ void operator delete[](void * ptr) free(ptr); } #endif + diff --git a/extensions/mysql/Makefile b/extensions/mysql/Makefile index fc597251..7352f702 100644 --- a/extensions/mysql/Makefile +++ b/extensions/mysql/Makefile @@ -30,7 +30,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc override ENGSET = false ifeq "$(ENGINE)" "original" @@ -65,7 +65,7 @@ else -I$(MYSQL)/include endif -LINK += $(MYSQL)/lib/libmysqlclient_r.a -lz -static-libgcc -lpthread +LINK += $(MYSQL)/lib/libmysqlclient_r.a -lz -lpthread CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \ -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror -Wno-switch \ @@ -94,7 +94,14 @@ ifeq "$(GCC_VERSION)" "4" CPPFLAGS += $(CPP_GCC4_FLAGS) endif -BINARY = $(PROJECT).ext.so +OS := $(shell uname -s) +ifeq "$(OS)" "Darwin" + LINK += -dynamiclib + BINARY = $(PROJECT).ext.dylib +else + LINK += -static-libgcc -shared + BINARY = $(PROJECT).ext.so +endif OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) @@ -117,7 +124,7 @@ check: fi extension: check $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/extensions/mysql/sdk/smsdk_ext.cpp b/extensions/mysql/sdk/smsdk_ext.cpp index db14af69..6404a919 100644 --- a/extensions/mysql/sdk/smsdk_ext.cpp +++ b/extensions/mysql/sdk/smsdk_ext.cpp @@ -30,7 +30,7 @@ */ #include -#include +#include #include "smsdk_ext.h" /** @@ -79,6 +79,24 @@ IThreader *threader = NULL; #if defined SMEXT_ENABLE_LIBSYS ILibrarySys *libsys = NULL; #endif +#if defined SMEXT_ENABLE_PLUGINSYS +SourceMod::IPluginManager *plsys; +#endif +#if defined SMEXT_ENABLE_MENUS +IMenuManager *menus = NULL; +#endif +#if defined SMEXT_ENABLE_ADMINSYS +IAdminSystem *adminsys = NULL; +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS +ITextParsers *textparsers = NULL; +#endif +#if defined SMEXT_ENABLE_USERMSGS +IUserMessages *usermsgs = NULL; +#endif +#if defined SMEXT_ENABLE_TRANSLATOR +ITranslator *translator = NULL; +#endif /** Exports the main interface */ PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() @@ -149,6 +167,24 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, #if defined SMEXT_ENABLE_LIBSYS SM_GET_IFACE(LIBRARYSYS, libsys); #endif +#if defined SMEXT_ENABLE_PLUGINSYS + SM_GET_IFACE(PLUGINSYSTEM, plsys); +#endif +#if defined SMEXT_ENABLE_MENUS + SM_GET_IFACE(MENUMANAGER, menus); +#endif +#if defined SMEXT_ENABLE_ADMINSYS + SM_GET_IFACE(ADMINSYS, adminsys); +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS + SM_GET_IFACE(TEXTPARSERS, textparsers); +#endif +#if defined SMEXT_ENABLE_USERMSGS + SM_GET_IFACE(USERMSGS, usermsgs); +#endif +#if defined SMEXT_ENABLE_TRANSLATOR + SM_GET_IFACE(TRANSLATOR, translator); +#endif if (SDK_OnLoad(error, maxlength, late)) { @@ -256,7 +292,11 @@ IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */ /** Exposes the extension to Metamod */ SMM_API void *PL_EXPOSURE(const char *name, int *code) { +#if defined METAMOD_PLAPI_VERSION + if (name && !strcmp(name, METAMOD_PLAPI_NAME)) +#else if (name && !strcmp(name, PLAPI_NAME)) +#endif { if (code) { @@ -277,8 +317,13 @@ bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, { PLUGIN_SAVEVARS(); +#if !defined METAMOD_PLAPI_VERSION GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#else + GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); + GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#endif m_SourceMMLoaded = true; @@ -389,7 +434,7 @@ bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t max #endif /* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ extern "C" void __cxa_pure_virtual(void) { } @@ -414,3 +459,4 @@ void operator delete[](void * ptr) free(ptr); } #endif + diff --git a/extensions/regex/Makefile b/extensions/regex/Makefile index 39983d09..5b057128 100644 --- a/extensions/regex/Makefile +++ b/extensions/regex/Makefile @@ -26,7 +26,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc override ENGSET = false ifeq "$(ENGINE)" "original" @@ -60,7 +60,7 @@ else INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn -I$(MMSOURCE17)/core/sourcehook endif -LINK += lib_linux/libpcre.a -static-libgcc +LINK += -m32 -ldl -lm CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \ -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror -mfpmath=sse \ @@ -83,14 +83,21 @@ ifeq "$(USEMETA)" "true" BIN_DIR := $(BIN_DIR).$(ENGINE) endif +OS := $(shell uname -s) +ifeq "$(OS)" "Darwin" + LINK += lib_darwin_x86/libpcre.a -dynamiclib + BINARY = $(PROJECT).ext.dylib +else + LINK += lib_linux/libpcre.a -static-libgcc -shared + BINARY = $(PROJECT).ext.so +endif + GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ifeq "$(GCC_VERSION)" "4" CFLAGS += $(C_GCC4_FLAGS) CPPFLAGS += $(CPP_GCC4_FLAGS) endif -BINARY = $(PROJECT).ext.so - OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) $(BIN_DIR)/%.o: %.cpp @@ -111,7 +118,7 @@ check: fi extension: check $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/extensions/regex/sdk/smsdk_ext.cpp b/extensions/regex/sdk/smsdk_ext.cpp index bf027ac5..6404a919 100644 --- a/extensions/regex/sdk/smsdk_ext.cpp +++ b/extensions/regex/sdk/smsdk_ext.cpp @@ -30,7 +30,7 @@ */ #include -#include +#include #include "smsdk_ext.h" /** @@ -94,6 +94,9 @@ ITextParsers *textparsers = NULL; #if defined SMEXT_ENABLE_USERMSGS IUserMessages *usermsgs = NULL; #endif +#if defined SMEXT_ENABLE_TRANSLATOR +ITranslator *translator = NULL; +#endif /** Exports the main interface */ PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() @@ -179,6 +182,9 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, #if defined SMEXT_ENABLE_USERMSGS SM_GET_IFACE(USERMSGS, usermsgs); #endif +#if defined SMEXT_ENABLE_TRANSLATOR + SM_GET_IFACE(TRANSLATOR, translator); +#endif if (SDK_OnLoad(error, maxlength, late)) { @@ -311,7 +317,7 @@ bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, { PLUGIN_SAVEVARS(); -#if defined METAMOD_PLAPI_VERSION +#if !defined METAMOD_PLAPI_VERSION GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); #else @@ -428,7 +434,7 @@ bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t max #endif /* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ extern "C" void __cxa_pure_virtual(void) { } @@ -453,3 +459,4 @@ void operator delete[](void * ptr) free(ptr); } #endif + diff --git a/extensions/sdktools/Makefile b/extensions/sdktools/Makefile index 8ed4c6f0..125c2565 100644 --- a/extensions/sdktools/Makefile +++ b/extensions/sdktools/Makefile @@ -29,7 +29,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc override ENGSET = false ifeq "$(ENGINE)" "original" @@ -64,7 +64,7 @@ else INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn endif -LINK += -static-libgcc +LINK += -m32 -ldl -lm CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \ -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror -Wno-switch \ @@ -87,6 +87,15 @@ ifeq "$(USEMETA)" "true" BIN_DIR := $(BIN_DIR).$(ENGINE) endif +OS := $(shell uname -s) +ifeq "$(OS)" "Darwin" + LINK += -dynamiclib + BINARY = $(PROJECT).ext.dylib +else + LINK += -static-libgcc -shared + BINARY = $(PROJECT).ext.so +endif + GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ifeq "$(GCC_VERSION)" "4" CFLAGS += $(C_GCC4_FLAGS) @@ -115,7 +124,7 @@ check: fi extension: check $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/extensions/sdktools/detours.h b/extensions/sdktools/detours.h index ab7a30c6..a028e3a4 100644 --- a/extensions/sdktools/detours.h +++ b/extensions/sdktools/detours.h @@ -32,7 +32,7 @@ #ifndef _INCLUDE_SOURCEMOD_DETOURS_H_ #define _INCLUDE_SOURCEMOD_DETOURS_H_ -#if defined PLATFORM_LINUX +#if defined PLATFORM_POSIX #include #define PAGE_SIZE 4096 #define ALIGN(ar) ((long)ar & ~(PAGE_SIZE-1)) diff --git a/extensions/sdktools/sdk/smsdk_ext.cpp b/extensions/sdktools/sdk/smsdk_ext.cpp index a823d1b2..6404a919 100644 --- a/extensions/sdktools/sdk/smsdk_ext.cpp +++ b/extensions/sdktools/sdk/smsdk_ext.cpp @@ -30,7 +30,7 @@ */ #include -#include +#include #include "smsdk_ext.h" /** @@ -82,6 +82,21 @@ ILibrarySys *libsys = NULL; #if defined SMEXT_ENABLE_PLUGINSYS SourceMod::IPluginManager *plsys; #endif +#if defined SMEXT_ENABLE_MENUS +IMenuManager *menus = NULL; +#endif +#if defined SMEXT_ENABLE_ADMINSYS +IAdminSystem *adminsys = NULL; +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS +ITextParsers *textparsers = NULL; +#endif +#if defined SMEXT_ENABLE_USERMSGS +IUserMessages *usermsgs = NULL; +#endif +#if defined SMEXT_ENABLE_TRANSLATOR +ITranslator *translator = NULL; +#endif /** Exports the main interface */ PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() @@ -155,6 +170,21 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, #if defined SMEXT_ENABLE_PLUGINSYS SM_GET_IFACE(PLUGINSYSTEM, plsys); #endif +#if defined SMEXT_ENABLE_MENUS + SM_GET_IFACE(MENUMANAGER, menus); +#endif +#if defined SMEXT_ENABLE_ADMINSYS + SM_GET_IFACE(ADMINSYS, adminsys); +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS + SM_GET_IFACE(TEXTPARSERS, textparsers); +#endif +#if defined SMEXT_ENABLE_USERMSGS + SM_GET_IFACE(USERMSGS, usermsgs); +#endif +#if defined SMEXT_ENABLE_TRANSLATOR + SM_GET_IFACE(TRANSLATOR, translator); +#endif if (SDK_OnLoad(error, maxlength, late)) { @@ -262,7 +292,11 @@ IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */ /** Exposes the extension to Metamod */ SMM_API void *PL_EXPOSURE(const char *name, int *code) { +#if defined METAMOD_PLAPI_VERSION if (name && !strcmp(name, METAMOD_PLAPI_NAME)) +#else + if (name && !strcmp(name, PLAPI_NAME)) +#endif { if (code) { @@ -283,8 +317,13 @@ bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, { PLUGIN_SAVEVARS(); +#if !defined METAMOD_PLAPI_VERSION + GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); + GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#else GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#endif m_SourceMMLoaded = true; @@ -395,7 +434,7 @@ bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t max #endif /* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ extern "C" void __cxa_pure_virtual(void) { } @@ -420,3 +459,4 @@ void operator delete[](void * ptr) free(ptr); } #endif + diff --git a/extensions/sqlite/Makefile b/extensions/sqlite/Makefile index d492167b..260b3a06 100644 --- a/extensions/sqlite/Makefile +++ b/extensions/sqlite/Makefile @@ -46,7 +46,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc override ENGSET = false ifeq "$(ENGINE)" "original" @@ -80,7 +80,7 @@ else INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn -I$(MMSOURCE17)/core/sourcehook endif -LINK += -static-libgcc -lpthread +LINK += -lpthread -m32 -ldl -lm CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \ -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror \ @@ -104,14 +104,21 @@ ifeq "$(USEMETA)" "true" BIN_DIR := $(BIN_DIR).$(ENGINE) endif +OS := $(shell uname -s) +ifeq "$(OS)" "Darwin" + LINK += -dynamiclib + BINARY = $(PROJECT).ext.dylib +else + LINK += -static-libgcc -shared + BINARY = $(PROJECT).ext.so +endif + GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ifeq "$(GCC_VERSION)" "4" CFLAGS += $(C_GCC4_FLAGS) CPPFLAGS += $(CPP_GCC4_FLAGS) endif -BINARY = $(PROJECT).ext.so - OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) OBJ_LINUX := $(OBJ_LINUX:%.c=$(BIN_DIR)/%.o) @@ -138,7 +145,7 @@ check: fi extension: check $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/extensions/sqlite/driver/SqDriver.cpp b/extensions/sqlite/driver/SqDriver.cpp index 397fed5b..5380394b 100644 --- a/extensions/sqlite/driver/SqDriver.cpp +++ b/extensions/sqlite/driver/SqDriver.cpp @@ -151,7 +151,7 @@ inline bool IsPathSepChar(char c) { #if defined PLATFORM_WINDOWS return (c == '\\' || c == '/'); -#elif defined PLATFORM_LINUX +#elif defined PLATFORM_LINUX || defined PLATFORM_APPLE return (c == '/'); #endif } diff --git a/extensions/sqlite/driver/SqResults.cpp b/extensions/sqlite/driver/SqResults.cpp index 0809ab6a..f4c2215b 100644 --- a/extensions/sqlite/driver/SqResults.cpp +++ b/extensions/sqlite/driver/SqResults.cpp @@ -343,7 +343,7 @@ bool SqResults::IsNull(unsigned int columnId) return (field->type == SQLITE_NULL); } -unsigned int SqResults::GetDataSize(unsigned int columnId) +size_t SqResults::GetDataSize(unsigned int columnId) { SqField *field = GetField(columnId); if (!field) diff --git a/extensions/sqlite/sdk/sm_memtable.cpp b/extensions/sqlite/sdk/sm_memtable.cpp index 8f18b136..e13cd891 100644 --- a/extensions/sqlite/sdk/sm_memtable.cpp +++ b/extensions/sqlite/sdk/sm_memtable.cpp @@ -30,7 +30,7 @@ */ #include -#include +#include #include "sm_memtable.h" BaseMemTable::BaseMemTable(unsigned int init_size) diff --git a/extensions/sqlite/sdk/smsdk_ext.cpp b/extensions/sqlite/sdk/smsdk_ext.cpp index c504da48..6404a919 100644 --- a/extensions/sqlite/sdk/smsdk_ext.cpp +++ b/extensions/sqlite/sdk/smsdk_ext.cpp @@ -28,8 +28,9 @@ * * Version: $Id$ */ + #include -#include +#include #include "smsdk_ext.h" /** @@ -78,6 +79,24 @@ IThreader *threader = NULL; #if defined SMEXT_ENABLE_LIBSYS ILibrarySys *libsys = NULL; #endif +#if defined SMEXT_ENABLE_PLUGINSYS +SourceMod::IPluginManager *plsys; +#endif +#if defined SMEXT_ENABLE_MENUS +IMenuManager *menus = NULL; +#endif +#if defined SMEXT_ENABLE_ADMINSYS +IAdminSystem *adminsys = NULL; +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS +ITextParsers *textparsers = NULL; +#endif +#if defined SMEXT_ENABLE_USERMSGS +IUserMessages *usermsgs = NULL; +#endif +#if defined SMEXT_ENABLE_TRANSLATOR +ITranslator *translator = NULL; +#endif /** Exports the main interface */ PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() @@ -148,6 +167,24 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, #if defined SMEXT_ENABLE_LIBSYS SM_GET_IFACE(LIBRARYSYS, libsys); #endif +#if defined SMEXT_ENABLE_PLUGINSYS + SM_GET_IFACE(PLUGINSYSTEM, plsys); +#endif +#if defined SMEXT_ENABLE_MENUS + SM_GET_IFACE(MENUMANAGER, menus); +#endif +#if defined SMEXT_ENABLE_ADMINSYS + SM_GET_IFACE(ADMINSYS, adminsys); +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS + SM_GET_IFACE(TEXTPARSERS, textparsers); +#endif +#if defined SMEXT_ENABLE_USERMSGS + SM_GET_IFACE(USERMSGS, usermsgs); +#endif +#if defined SMEXT_ENABLE_TRANSLATOR + SM_GET_IFACE(TRANSLATOR, translator); +#endif if (SDK_OnLoad(error, maxlength, late)) { @@ -255,7 +292,11 @@ IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */ /** Exposes the extension to Metamod */ SMM_API void *PL_EXPOSURE(const char *name, int *code) { +#if defined METAMOD_PLAPI_VERSION + if (name && !strcmp(name, METAMOD_PLAPI_NAME)) +#else if (name && !strcmp(name, PLAPI_NAME)) +#endif { if (code) { @@ -276,8 +317,13 @@ bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, { PLUGIN_SAVEVARS(); +#if !defined METAMOD_PLAPI_VERSION GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#else + GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); + GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#endif m_SourceMMLoaded = true; @@ -388,7 +434,7 @@ bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t max #endif /* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ extern "C" void __cxa_pure_virtual(void) { } @@ -413,3 +459,4 @@ void operator delete[](void * ptr) free(ptr); } #endif + diff --git a/extensions/tf2/CDetour/detourhelpers.h b/extensions/tf2/CDetour/detourhelpers.h index c043cb2c..aea6faa0 100644 --- a/extensions/tf2/CDetour/detourhelpers.h +++ b/extensions/tf2/CDetour/detourhelpers.h @@ -32,7 +32,7 @@ #ifndef _INCLUDE_SOURCEMOD_DETOURHELPERS_H_ #define _INCLUDE_SOURCEMOD_DETOURHELPERS_H_ -#if defined PLATFORM_LINUX +#if defined PLATFORM_POSIX #include #define PAGE_SIZE 4096 #define ALIGN(ar) ((long)ar & ~(PAGE_SIZE-1)) @@ -52,7 +52,7 @@ struct patch_t inline void ProtectMemory(void *addr, int length, int prot) { -#if defined PLATFORM_LINUX +#if defined PLATFORM_POSIX void *addr2 = (void *)ALIGN(addr); mprotect(addr2, sysconf(_SC_PAGESIZE), prot); #elif defined PLATFORM_WINDOWS diff --git a/extensions/tf2/Makefile b/extensions/tf2/Makefile index deded0d7..88b3401b 100644 --- a/extensions/tf2/Makefile +++ b/extensions/tf2/Makefile @@ -27,7 +27,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc override ENGSET = false ifeq "$(ENGINE)" "original" @@ -62,7 +62,7 @@ else INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn endif -LINK += -static-libgcc +LINK += -m32 -ldl -lm CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \ -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror -Wno-switch \ @@ -85,14 +85,21 @@ ifeq "$(USEMETA)" "true" BIN_DIR := $(BIN_DIR).$(ENGINE) endif +OS := $(shell uname -s) +ifeq "$(OS)" "Darwin" + LINK += -dynamiclib + BINARY = $(PROJECT).ext.dylib +else + LINK += -static-libgcc -shared + BINARY = $(PROJECT).ext.so +endif + GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ifeq "$(GCC_VERSION)" "4" CFLAGS += $(C_GCC4_FLAGS) CPPFLAGS += $(CPP_GCC4_FLAGS) endif -BINARY = $(PROJECT).ext.so - OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) $(BIN_DIR)/%.o: %.cpp @@ -114,7 +121,7 @@ check: fi extension: check $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/extensions/tf2/sdk/smsdk_ext.cpp b/extensions/tf2/sdk/smsdk_ext.cpp index 37733333..6404a919 100644 --- a/extensions/tf2/sdk/smsdk_ext.cpp +++ b/extensions/tf2/sdk/smsdk_ext.cpp @@ -30,7 +30,7 @@ */ #include -#include +#include #include "smsdk_ext.h" /** @@ -79,9 +79,24 @@ IThreader *threader = NULL; #if defined SMEXT_ENABLE_LIBSYS ILibrarySys *libsys = NULL; #endif +#if defined SMEXT_ENABLE_PLUGINSYS +SourceMod::IPluginManager *plsys; +#endif +#if defined SMEXT_ENABLE_MENUS +IMenuManager *menus = NULL; +#endif +#if defined SMEXT_ENABLE_ADMINSYS +IAdminSystem *adminsys = NULL; +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS +ITextParsers *textparsers = NULL; +#endif #if defined SMEXT_ENABLE_USERMSGS IUserMessages *usermsgs = NULL; #endif +#if defined SMEXT_ENABLE_TRANSLATOR +ITranslator *translator = NULL; +#endif /** Exports the main interface */ PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() @@ -152,9 +167,24 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, #if defined SMEXT_ENABLE_LIBSYS SM_GET_IFACE(LIBRARYSYS, libsys); #endif +#if defined SMEXT_ENABLE_PLUGINSYS + SM_GET_IFACE(PLUGINSYSTEM, plsys); +#endif +#if defined SMEXT_ENABLE_MENUS + SM_GET_IFACE(MENUMANAGER, menus); +#endif +#if defined SMEXT_ENABLE_ADMINSYS + SM_GET_IFACE(ADMINSYS, adminsys); +#endif +#if defined SMEXT_ENABLE_TEXTPARSERS + SM_GET_IFACE(TEXTPARSERS, textparsers); +#endif #if defined SMEXT_ENABLE_USERMSGS SM_GET_IFACE(USERMSGS, usermsgs); #endif +#if defined SMEXT_ENABLE_TRANSLATOR + SM_GET_IFACE(TRANSLATOR, translator); +#endif if (SDK_OnLoad(error, maxlength, late)) { @@ -262,7 +292,11 @@ IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */ /** Exposes the extension to Metamod */ SMM_API void *PL_EXPOSURE(const char *name, int *code) { +#if defined METAMOD_PLAPI_VERSION if (name && !strcmp(name, METAMOD_PLAPI_NAME)) +#else + if (name && !strcmp(name, PLAPI_NAME)) +#endif { if (code) { @@ -283,8 +317,13 @@ bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, { PLUGIN_SAVEVARS(); +#if !defined METAMOD_PLAPI_VERSION + GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); + GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#else GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#endif m_SourceMMLoaded = true; @@ -395,7 +434,7 @@ bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t max #endif /* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ extern "C" void __cxa_pure_virtual(void) { } @@ -420,3 +459,4 @@ void operator delete[](void * ptr) free(ptr); } #endif + diff --git a/extensions/topmenus/Makefile b/extensions/topmenus/Makefile index 9f8635b8..711c0e0c 100644 --- a/extensions/topmenus/Makefile +++ b/extensions/topmenus/Makefile @@ -27,7 +27,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc override ENGSET = false ifeq "$(ENGINE)" "original" @@ -62,7 +62,7 @@ else -I$(MMSOURCE17)/core/sourcehook endif -LINK += -static-libgcc +LINK += -m32 -ldl -lm CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \ -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror -Wno-switch \ @@ -85,14 +85,21 @@ ifeq "$(USEMETA)" "true" BIN_DIR := $(BIN_DIR).$(ENGINE) endif +OS := $(shell uname -s) +ifeq "$(OS)" "Darwin" + LINK += -dynamiclib + BINARY = $(PROJECT).ext.dylib +else + LINK += -static-libgcc -shared + BINARY = $(PROJECT).ext.so +endif + GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ifeq "$(GCC_VERSION)" "4" CFLAGS += $(C_GCC4_FLAGS) CPPFLAGS += $(CPP_GCC4_FLAGS) endif -BINARY = $(PROJECT).ext.so - OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) $(BIN_DIR)/%.o: %.cpp @@ -113,7 +120,7 @@ check: fi extension: check $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/extensions/topmenus/sdk/sm_memtable.cpp b/extensions/topmenus/sdk/sm_memtable.cpp index 8f18b136..e13cd891 100644 --- a/extensions/topmenus/sdk/sm_memtable.cpp +++ b/extensions/topmenus/sdk/sm_memtable.cpp @@ -30,7 +30,7 @@ */ #include -#include +#include #include "sm_memtable.h" BaseMemTable::BaseMemTable(unsigned int init_size) diff --git a/extensions/topmenus/sdk/smsdk_ext.cpp b/extensions/topmenus/sdk/smsdk_ext.cpp index 852361b1..6404a919 100644 --- a/extensions/topmenus/sdk/smsdk_ext.cpp +++ b/extensions/topmenus/sdk/smsdk_ext.cpp @@ -30,7 +30,7 @@ */ #include -#include +#include #include "smsdk_ext.h" /** @@ -91,6 +91,12 @@ IAdminSystem *adminsys = NULL; #if defined SMEXT_ENABLE_TEXTPARSERS ITextParsers *textparsers = NULL; #endif +#if defined SMEXT_ENABLE_USERMSGS +IUserMessages *usermsgs = NULL; +#endif +#if defined SMEXT_ENABLE_TRANSLATOR +ITranslator *translator = NULL; +#endif /** Exports the main interface */ PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() @@ -173,6 +179,12 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, #if defined SMEXT_ENABLE_TEXTPARSERS SM_GET_IFACE(TEXTPARSERS, textparsers); #endif +#if defined SMEXT_ENABLE_USERMSGS + SM_GET_IFACE(USERMSGS, usermsgs); +#endif +#if defined SMEXT_ENABLE_TRANSLATOR + SM_GET_IFACE(TRANSLATOR, translator); +#endif if (SDK_OnLoad(error, maxlength, late)) { @@ -280,7 +292,11 @@ IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */ /** Exposes the extension to Metamod */ SMM_API void *PL_EXPOSURE(const char *name, int *code) { +#if defined METAMOD_PLAPI_VERSION + if (name && !strcmp(name, METAMOD_PLAPI_NAME)) +#else if (name && !strcmp(name, PLAPI_NAME)) +#endif { if (code) { @@ -301,8 +317,13 @@ bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, { PLUGIN_SAVEVARS(); +#if !defined METAMOD_PLAPI_VERSION GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#else + GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); + GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); +#endif m_SourceMMLoaded = true; @@ -413,7 +434,7 @@ bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t max #endif /* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ extern "C" void __cxa_pure_virtual(void) { } @@ -438,3 +459,4 @@ void operator delete[](void * ptr) free(ptr); } #endif + diff --git a/knight/shared/KePlatform.h b/knight/shared/KePlatform.h index 775355cb..a4a9f3cf 100644 --- a/knight/shared/KePlatform.h +++ b/knight/shared/KePlatform.h @@ -18,6 +18,8 @@ #if defined linux #define KE_PLATFORM_LINUX +#elif defined __APPLE__ +#define KE_PLATFORM_APPLE #else #error "TODO" #endif diff --git a/loader/Makefile b/loader/Makefile index 106368c2..23a1d276 100644 --- a/loader/Makefile +++ b/loader/Makefile @@ -19,9 +19,9 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc -LINK = -static-libgcc +LINK = -m32 -ldl -lm INCLUDE = -I$(MMSOURCE17)/core -I$(MMSOURCE17)/core/sourcehook @@ -42,14 +42,21 @@ else CFLAGS += $(C_OPT_FLAGS) endif +OS := $(shell uname -s) +ifeq "$(OS)" "Darwin" + LINK += -dynamiclib + BINARY = $(PROJECT).dylib +else + LINK += -static-libgcc -shared + BINARY = $(PROJECT)_i486.so +endif + GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ifeq "$(GCC_VERSION)" "4" CFLAGS += $(C_GCC4_FLAGS) CPPFLAGS += $(CPP_GCC4_FLAGS) endif -BINARY = $(PROJECT)_i486.so - OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) $(BIN_DIR)/%.o: %.cpp @@ -60,7 +67,7 @@ all: $(MAKE) -f Makefile loader loader: $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/loader/loader.cpp b/loader/loader.cpp index bb5f5ee9..b276d077 100644 --- a/loader/loader.cpp +++ b/loader/loader.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #if defined _MSC_VER #define DLL_EXPORT extern "C" __declspec(dllexport) @@ -119,7 +119,7 @@ METAMOD_PLUGIN *_GetPluginPtr(const char *path, int fail_api) if (!(g_hCore=openlib(path))) { -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ UTIL_Format(s_FailPlugin.error_buffer, sizeof(s_FailPlugin.error_buffer), "%s", @@ -289,7 +289,7 @@ __attribute__((destructor)) static void gcc_fini() #endif /* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ extern "C" void __cxa_pure_virtual(void) { } diff --git a/public/mms_sample_ext/Makefile b/public/mms_sample_ext/Makefile index 8d55d366..8f8328bc 100644 --- a/public/mms_sample_ext/Makefile +++ b/public/mms_sample_ext/Makefile @@ -23,7 +23,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc override ENGSET = false ifeq "$(ENGINE)" "original" @@ -46,7 +46,7 @@ ifeq "$(ENGINE)" "orangebox" override ENGSET = true endif -LINK = vstdlib_i486.so tier0_i486.so -static-libgcc +LINK = vstdlib_i486.so tier0_i486.so -m32 -ldl -lm INCLUDE += -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 \ -I$(METAMOD) -I$(METAMOD)/sourcehook -I$(SMSDK) -I$(SMSDK)/jit -I$(SMSDK)/jit/x86 \ @@ -69,14 +69,21 @@ else CFLAGS += $(C_OPT_FLAGS) endif +OS := $(shell uname -s) +ifeq "$(OS)" "Darwin" + LINK += -dynamiclib + BINARY = $(PROJECT).dylib +else + LINK += -static-libgcc -shared + BINARY = $(PROJECT)_i486.so +endif + GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ifeq "$(GCC_VERSION)" "4" CFLAGS += $(C_GCC4_FLAGS) CPPFLAGS += $(CPP_GCC4_FLAGS) endif -BINARY = $(PROJECT)_i486.so - OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) $(BIN_DIR)/%.o: %.cpp @@ -95,7 +102,7 @@ check: fi mms_ext: check $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/public/sample_ext/Makefile b/public/sample_ext/Makefile index ea256b8c..ff6d679f 100644 --- a/public/sample_ext/Makefile +++ b/public/sample_ext/Makefile @@ -26,7 +26,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc override ENGSET = false ifeq "$(ENGINE)" "original" @@ -60,7 +60,7 @@ else INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn endif -LINK += -static-libgcc +LINK += -m32 -lm -ldl CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \ -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror -Wno-switch \ @@ -83,14 +83,21 @@ ifeq "$(USEMETA)" "true" BIN_DIR := $(BIN_DIR).$(ENGINE) endif +OS := $(shell uname -s) +ifeq "$(OS)" "Darwin" + LINK += -dynamiclib + BINARY = $(PROJECT).ext.dylib +else + LINK += -static-libgcc -shared + BINARY = $(PROJECT).ext.so +endif + GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ifeq "$(GCC_VERSION)" "4" CFLAGS += $(C_GCC4_FLAGS) CPPFLAGS += $(CPP_GCC4_FLAGS) endif -BINARY = $(PROJECT).ext.so - OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) $(BIN_DIR)/%.o: %.cpp @@ -111,7 +118,7 @@ check: fi extension: check $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/public/sample_ext/sdk/smsdk_ext.cpp b/public/sample_ext/sdk/smsdk_ext.cpp index 865f536e..6404a919 100644 --- a/public/sample_ext/sdk/smsdk_ext.cpp +++ b/public/sample_ext/sdk/smsdk_ext.cpp @@ -30,7 +30,7 @@ */ #include -#include +#include #include "smsdk_ext.h" /** @@ -434,7 +434,7 @@ bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t max #endif /* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ extern "C" void __cxa_pure_virtual(void) { } @@ -459,3 +459,4 @@ void operator delete[](void * ptr) free(ptr); } #endif + diff --git a/public/sm_platform.h b/public/sm_platform.h index 50928e61..8f23b7a0 100644 --- a/public/sm_platform.h +++ b/public/sm_platform.h @@ -60,14 +60,21 @@ #if defined _MSC_VER && _MSC_VER >= 1400 #define SUBPLATFORM_SECURECRT #endif -#elif defined __linux__ -#define PLATFORM_LINUX +#elif defined __linux__ || defined __APPLE__ +#if defined __linux__ +# define PLATFORM_LINUX +#elif defined __APPLE__ +# define PLATFORM_APPLE +#endif #define PLATFORM_POSIX #include #include #include #include #include +#if defined PLATFORM_APPLE +#include +#endif #define PLATFORM_MAX_PATH PATH_MAX #define PLATFORM_LIB_EXT "so" #define PLATFORM_SEP_CHAR '/' @@ -80,3 +87,4 @@ #endif #endif //_INCLUDE_SOURCEMOD_PLATFORM_H_ + diff --git a/public/sm_trie_tpl.h b/public/sm_trie_tpl.h index 61b8f1e5..d0576929 100644 --- a/public/sm_trie_tpl.h +++ b/public/sm_trie_tpl.h @@ -34,7 +34,7 @@ #include #include -#include +#include #include enum NodeType diff --git a/public/sourcepawn/sp_file_headers.h b/public/sourcepawn/sp_file_headers.h index d1a411a8..151cc953 100644 --- a/public/sourcepawn/sp_file_headers.h +++ b/public/sourcepawn/sp_file_headers.h @@ -60,7 +60,7 @@ #define SPFILE_VERSION 0x0102 /**< File format version */ //:TODO: better compiler/nix support -#if defined __linux__ +#if defined __GNUC__ #pragma pack(1) /* structures must be packed (byte-aligned) */ #else #pragma pack(push) diff --git a/sourcepawn/compiler/Makefile b/sourcepawn/compiler/Makefile index 8e34d115..4524a374 100644 --- a/sourcepawn/compiler/Makefile +++ b/sourcepawn/compiler/Makefile @@ -24,7 +24,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing -fomit-fram C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc LINK = -lgcc -static-libgcc @@ -61,7 +61,7 @@ all: $(MAKE) -f Makefile compiler compiler: $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -ldl -lm -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/sourcepawn/compiler/libpawnc.c b/sourcepawn/compiler/libpawnc.c index ddaf7498..3331335b 100644 --- a/sourcepawn/compiler/libpawnc.c +++ b/sourcepawn/compiler/libpawnc.c @@ -26,7 +26,6 @@ #include #include #include -#include #include "sc.h" #include "memfile.h" diff --git a/sourcepawn/compiler/memfile.h b/sourcepawn/compiler/memfile.h index 7f953f20..8fbf38a7 100644 --- a/sourcepawn/compiler/memfile.h +++ b/sourcepawn/compiler/memfile.h @@ -1,7 +1,7 @@ #ifndef _INCLUDE_MEMFILE_H #define _INCLUDE_MEMFILE_H -#include +#include typedef struct memfile_s { diff --git a/sourcepawn/compiler/osdefs.h b/sourcepawn/compiler/osdefs.h index 7a6768c2..49ec2dca 100644 --- a/sourcepawn/compiler/osdefs.h +++ b/sourcepawn/compiler/osdefs.h @@ -48,6 +48,8 @@ #if defined __FreeBSD__ #include +#elif defined __APPLE__ + #include #elif defined LINUX #include #endif diff --git a/sourcepawn/compiler/sclinux.h b/sourcepawn/compiler/sclinux.h index f22497a8..868539ea 100644 --- a/sourcepawn/compiler/sclinux.h +++ b/sourcepawn/compiler/sclinux.h @@ -34,7 +34,7 @@ # include #endif -#if defined __OpenBSD__ || defined __FreeBSD__ +#if defined __OpenBSD__ || defined __FreeBSD__ || defined __APPLE__ # define __BYTE_ORDER BYTE_ORDER # define __LITTLE_ENDIAN LITTLE_ENDIAN # define __BIG_ENDIAN BIG_ENDIAN diff --git a/sourcepawn/compiler/sctracker.c b/sourcepawn/compiler/sctracker.c index e0617c47..7b20ab1b 100644 --- a/sourcepawn/compiler/sctracker.c +++ b/sourcepawn/compiler/sctracker.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include "sc.h" diff --git a/sourcepawn/compiler/sp_file.c b/sourcepawn/compiler/sp_file.c index a83d290d..e5d6addb 100644 --- a/sourcepawn/compiler/sp_file.c +++ b/sourcepawn/compiler/sp_file.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include "sp_file.h" #include "memfile.h" diff --git a/sourcepawn/jit/Makefile b/sourcepawn/jit/Makefile index e1c429f7..a26a48b8 100644 --- a/sourcepawn/jit/Makefile +++ b/sourcepawn/jit/Makefile @@ -42,9 +42,9 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc -LINK = -static-libgcc +LINK = -m32 -ldl -lm INCLUDE = -I. -I.. -I$(SMSDK)/public -I$(SMSDK)/public/jit -I$(SMSDK)/public/jit/x86 \ -I$(SMSDK)/public/sourcepawn -I$(MMSOURCE17)/core/sourcehook -I$(SMSDK)/knight/shared -Ix86 @@ -66,14 +66,21 @@ else CFLAGS += $(C_OPT_FLAGS) endif +OS := $(shell uname -s) +ifeq "$(OS)" "Darwin" + LINK += -dynamiclib + BINARY = $(PROJECT).dylib +else + LINK += -static-libgcc-shared + BINARY = $(PROJECT).so +endif + GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) ifeq "$(GCC_VERSION)" "4" CFLAGS += $(C_GCC4_FLAGS) CPPFLAGS += $(CPP_GCC4_FLAGS) endif -BINARY = $(PROJECT).so - OBJ_LINUX := $(OBJECTS:../../knight/shared/%.cpp=$(BIN_DIR)/knight/%.o) OBJ_LINUX := $(OBJ_LINUX:%.cpp=$(BIN_DIR)/%.o) OBJ_LINUX := $(OBJ_LINUX:%.c=$(BIN_DIR)/%.o) @@ -96,7 +103,7 @@ all: $(MAKE) -f Makefile jit jit: $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/sourcepawn/jit/dll_exports.cpp b/sourcepawn/jit/dll_exports.cpp index 91a80743..36305d9a 100644 --- a/sourcepawn/jit/dll_exports.cpp +++ b/sourcepawn/jit/dll_exports.cpp @@ -30,7 +30,7 @@ */ #include -#include +#include #include "x86/jit_x86.h" #include "dll_exports.h" #include "sp_vm_engine.h" @@ -48,7 +48,7 @@ EXPORTFUNC ISourcePawnEngine2 *GetSourcePawnEngine2() return &g_engine2; } -#if defined __linux__ +#if defined __linux__ || defined __APPLE__ extern "C" void __cxa_pure_virtual(void) { } diff --git a/sourcepawn/jit/sp_vm_engine.cpp b/sourcepawn/jit/sp_vm_engine.cpp index dc300d69..c1ed750f 100644 --- a/sourcepawn/jit/sp_vm_engine.cpp +++ b/sourcepawn/jit/sp_vm_engine.cpp @@ -29,7 +29,7 @@ * Version: $Id$ */ -#include +#include #include #include #include "sp_vm_types.h" @@ -111,7 +111,11 @@ void *SourcePawnEngine::ExecAlloc(size_t size) #if defined WIN32 return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); #elif defined __GNUC__ +# if defined __APPLE__ + void *base = valloc(size); +# else void *base = memalign(sysconf(_SC_PAGESIZE), size); +# endif if (mprotect(base, size, PROT_READ|PROT_WRITE|PROT_EXEC) != 0) { free(base); diff --git a/sourcepawn/jit/x86/opcode_helpers.cpp b/sourcepawn/jit/x86/opcode_helpers.cpp index 30311202..cf42433b 100644 --- a/sourcepawn/jit/x86/opcode_helpers.cpp +++ b/sourcepawn/jit/x86/opcode_helpers.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include "jit_x86.h" #include "opcode_helpers.h" #include "x86_macros.h" diff --git a/tools/builder/LinuxBuilder.cs b/tools/builder/LinuxBuilder.cs index 1fac9619..4e091020 100644 --- a/tools/builder/LinuxBuilder.cs +++ b/tools/builder/LinuxBuilder.cs @@ -60,19 +60,18 @@ namespace builder File.Delete(binpath); } - string makefile_args = ""; + string makefile_args = "CPP=gcc-4.1 "; if (lib.build_mode == BuildMode.BuildMode_Episode1) { - makefile_args = null; } else if (lib.build_mode == BuildMode.BuildMode_Episode2) { - makefile_args = "ENGINE=\"orangebox\""; + makefile_args += "ENGINE=\"orangebox\" "; } else if (lib.build_mode == BuildMode.BuildMode_OldMetamod) { - makefile_args = "ENGINE=\"original\""; + makefile_args += "ENGINE=\"original\" "; } /* Clean the project first */ diff --git a/tools/crc32/build.sh b/tools/crc32/build.sh index 62b2891c..91a988f5 100755 --- a/tools/crc32/build.sh +++ b/tools/crc32/build.sh @@ -1,2 +1,2 @@ -g++ -I../../core ../../core/sm_crc32.cpp main.cpp -ocrc32 +g++ -I../../core ../../core/sm_crc32.cpp main.cpp -o crc32 diff --git a/tools/daemon/Makefile b/tools/daemon/Makefile index 28ab2826..10259556 100644 --- a/tools/daemon/Makefile +++ b/tools/daemon/Makefile @@ -16,7 +16,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc BINARY = smupdated @@ -65,7 +65,7 @@ all: $(MAKE) -f Makefile sourcemod sourcemod: $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -lstdc++ -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -lstdc++ -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/tools/gamedata_md5/Makefile b/tools/gamedata_md5/Makefile index a73b8558..9a964388 100644 --- a/tools/gamedata_md5/Makefile +++ b/tools/gamedata_md5/Makefile @@ -16,7 +16,7 @@ C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 C_GCC4_FLAGS = -fvisibility=hidden CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc-4.1 +CPP = gcc BINARY = gamedatamd5 @@ -63,7 +63,7 @@ all: $(MAKE) -f Makefile sourcemod sourcemod: $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -lstdc++ -o$(BIN_DIR)/$(BINARY) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -lstdc++ -o $(BIN_DIR)/$(BINARY) debug: $(MAKE) -f Makefile all DEBUG=true diff --git a/tools/gamedata_md5/sm_memtable.cpp b/tools/gamedata_md5/sm_memtable.cpp index 8f18b136..e13cd891 100644 --- a/tools/gamedata_md5/sm_memtable.cpp +++ b/tools/gamedata_md5/sm_memtable.cpp @@ -30,7 +30,7 @@ */ #include -#include +#include #include "sm_memtable.h" BaseMemTable::BaseMemTable(unsigned int init_size) From dc758ead10678cc575df9ed48316958708c815cb Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 23 Dec 2008 01:55:20 -0500 Subject: [PATCH 2/8] Build fix for Linux. --- sourcepawn/jit/sp_vm_engine.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sourcepawn/jit/sp_vm_engine.cpp b/sourcepawn/jit/sp_vm_engine.cpp index c1ed750f..8241c825 100644 --- a/sourcepawn/jit/sp_vm_engine.cpp +++ b/sourcepawn/jit/sp_vm_engine.cpp @@ -52,6 +52,10 @@ SourcePawnEngine g_engine1; #include #endif +#if defined PLATFORM_LINUX +#include +#endif + using namespace SourcePawn; #define ERROR_MESSAGE_MAX 25 From cb41fa6de4aafb33489788cecd3f17c564a2cdea Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 22 Dec 2008 20:12:33 -0600 Subject: [PATCH 3/8] Fixed JIT build on Linux for real. --- sourcepawn/jit/Makefile | 2 +- sourcepawn/jit/sp_vm_engine.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sourcepawn/jit/Makefile b/sourcepawn/jit/Makefile index a26a48b8..5299aef5 100644 --- a/sourcepawn/jit/Makefile +++ b/sourcepawn/jit/Makefile @@ -71,7 +71,7 @@ ifeq "$(OS)" "Darwin" LINK += -dynamiclib BINARY = $(PROJECT).dylib else - LINK += -static-libgcc-shared + LINK += -static-libgcc -shared BINARY = $(PROJECT).so endif diff --git a/sourcepawn/jit/sp_vm_engine.cpp b/sourcepawn/jit/sp_vm_engine.cpp index 8241c825..80a685e3 100644 --- a/sourcepawn/jit/sp_vm_engine.cpp +++ b/sourcepawn/jit/sp_vm_engine.cpp @@ -52,7 +52,7 @@ SourcePawnEngine g_engine1; #include #endif -#if defined PLATFORM_LINUX +#if defined __linux__ #include #endif From 4daca3c5ba0e6d7b7d06f289e24cd010d536e9f7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 26 Dec 2008 23:26:21 -0500 Subject: [PATCH 4/8] Another gamedata cleanup sponsored by an r=pred (bug 3351). --- core/GameDataFetcher.cpp | 290 ++++++++++++++++++++++++--------------- core/GameDataFetcher.h | 113 ++------------- core/LibrarySys.cpp | 20 ++- core/LibrarySys.h | 1 + core/sourcemod.cpp | 7 + core/sourcemod.h | 12 ++ 6 files changed, 231 insertions(+), 212 deletions(-) diff --git a/core/GameDataFetcher.cpp b/core/GameDataFetcher.cpp index ca54bdb7..125615bd 100644 --- a/core/GameDataFetcher.cpp +++ b/core/GameDataFetcher.cpp @@ -42,8 +42,9 @@ #include #include -#define INVALID_SOCKET -1 -#define closesocket close +#define INVALID_SOCKET -1 +#define closesocket close +#define WSAGetLastError() errno #endif #include "sh_vector.h" @@ -61,6 +62,7 @@ #include "TimerSys.h" #include "compat_wrappers.h" #include "sm_stringutil.h" +#include "md5.h" #define QUERY_MAX_LENGTH 1024 @@ -73,9 +75,9 @@ bool g_disableGameDataUpdate = false; bool g_restartAfterUpdate = false; int g_serverPort = 6500; -char g_serverAddress[100] = "hayate.alliedmods.net"; +char g_serverAddress[100] = "smupdate.alliedmods.net"; -void FetcherThread::RunThread( IThreadHandle *pHandle ) +void FetcherThread::RunThread(IThreadHandle *pHandle) { char lock_path[PLATFORM_MAX_PATH]; g_SourceMod.BuildPath(Path_SM, lock_path, sizeof(lock_path), "data/temp"); @@ -127,9 +129,7 @@ void FetcherThread::RunThread( IThreadHandle *pHandle ) if (g_disableGameDataUpdate) { -#ifdef DEBUG g_Logger.LogMessage("Skipping GameData Query due to DisableAutoUpdate being set to true"); -#endif fclose(logfile); unlink(lock_path); @@ -148,13 +148,15 @@ void FetcherThread::RunThread( IThreadHandle *pHandle ) int sent = SendData(socketDescriptor, query, len); -#ifdef DEBUG - g_Logger.LogToOpenFile(logfile, "Sent Query!"); -#endif +IF_DEBUG_SPEW + g_Logger.LogToOpenFile(logfile, "Sent gamedata query"); +ENDIF_DEBUG_SPEW if (sent == 0) { +IF_DEBUG_SPEW g_Logger.LogToOpenFile(logfile, "Failed to send gamedata query data to remote host"); +ENDIF_DEBUG_SPEW closesocket(socketDescriptor); fclose(logfile); @@ -170,12 +172,12 @@ void FetcherThread::RunThread( IThreadHandle *pHandle ) unlink(lock_path); } -void FetcherThread::OnTerminate( IThreadHandle *pHandle, bool cancel ) +void FetcherThread::OnTerminate(IThreadHandle *pHandle, bool cancel) { g_blockGameDataLoad = false; } -int FetcherThread::BuildGameDataQuery( char *buffer, int maxlen ) +int FetcherThread::BuildGameDataQuery(char *buffer, int maxlen) { char gamedata_path[PLATFORM_MAX_PATH]; g_SourceMod.BuildPath(Path_SM, gamedata_path, sizeof(gamedata_path), "gamedata"); @@ -204,41 +206,39 @@ int FetcherThread::BuildGameDataQuery( char *buffer, int maxlen ) { const char *name = dir->GetEntryName(); size_t len = strlen(name); - if (len >= 4 - && strcmp(&name[len-4], ".txt") == 0) + if (len >= 4 && strcmp(&name[len-4], ".txt") == 0) { + MD5 md5; + SMCError err; + SMCStates states; + unsigned char raw[16]; char file[PLATFORM_MAX_PATH]; g_LibSys.PathFormat(file, sizeof(file), "%s/%s", gamedata_path, name); - SMCStates states; - if (g_TextParser.ParseFile_SMC(file, &g_MD5Builder, &states) == SMCError_Okay) + g_MD5Builder.checksum = &md5; + if ((err = g_TextParser.ParseFile_SMC(file, &g_MD5Builder, &states)) == SMCError_Okay) { - unsigned char *md5 = g_MD5Builder.GetMD5(); - if (md5 != NULL) - { - (uint8_t)buffer[10]++; //Increment the file counter - Writer.WriteBytes(md5, 16); + md5.raw_digest(raw); + (uint8_t)buffer[10]++; //Increment the file counter + Writer.WriteBytes(raw, 16); - g_Logger.LogToOpenFile(logfile, "%s - \"%s\"", file, g_MD5Builder.GetMD5String()); + FileData *data = new FileData(); + data->filename = new SourceHook::String(file); + md5.hex_digest(data->checksum); + filenames.push_back(data); + +IF_DEBUG_SPEW + g_Logger.LogToOpenFile(logfile, "Parsed file: %s as %s", file, data->checksum); +ENDIF_DEBUG_SPEW - FileData *data = new FileData(); - data->filename = new SourceHook::String(file); - memcpy(data->checksum, g_MD5Builder.GetMD5String(), 33); - filenames.push_back(data); - } - else - { -#ifdef DEBUG - g_Logger.LogToOpenFile(logfile, "%s no md5?", file); -#endif - } } else { -#ifdef DEBUG - g_Logger.LogToOpenFile(logfile, "%s failed!", file); -#endif +IF_DEBUG_SPEW + const char *error = g_TextParser.GetSMCErrorString(err); + g_Logger.LogToOpenFile(logfile, "Parsing of file %s failed: %s", file, error); +ENDIF_DEBUG_SPEW } } } @@ -251,17 +251,16 @@ int FetcherThread::BuildGameDataQuery( char *buffer, int maxlen ) int FetcherThread::ConnectSocket() { - struct protoent *ptrp; - ptrp = getprotobyname("tcp"); - -#ifdef WIN32 +#if defined PLATFORM_WINDOWS WSADATA wsaData; WSAStartup(0x0101, &wsaData); #endif - if (ptrp == NULL) + struct protoent *ptrp; + + if ((ptrp = getprotobyname("tcp")) == NULL) { - g_Logger.LogToOpenFile(logfile, "Failed to find TCP"); + g_Logger.LogToOpenFile(logfile, "Error: Failed to find TCP protocol"); return INVALID_SOCKET; } @@ -269,12 +268,9 @@ int FetcherThread::ConnectSocket() if (socketDescriptor == INVALID_SOCKET) { - //bugger aye? -#ifdef WIN32 - g_Logger.LogToOpenFile(logfile, "Failed to create a new socket - Error %i", WSAGetLastError()); -#else - g_Logger.LogToOpenFile(logfile, "Failed to create a new socket - Error %i", errno); -#endif + char error[255]; + g_LibSys.GetPlatformErrorEx(WSAGetLastError(), error, sizeof(error)); + g_Logger.LogToOpenFile(logfile, "Error: Failed to create socket: %s", error); closesocket(socketDescriptor); return INVALID_SOCKET; } @@ -291,7 +287,7 @@ int FetcherThread::ConnectSocket() { if ((local_addr.sin_addr.s_addr = inet_addr(g_serverAddress)) == INADDR_NONE) { - g_Logger.LogToOpenFile(logfile, "Couldn't locate address"); + g_Logger.LogToOpenFile(logfile, "Couldn't locate address: %s", g_serverAddress); closesocket(socketDescriptor); return INVALID_SOCKET; } @@ -303,11 +299,9 @@ int FetcherThread::ConnectSocket() if (connect(socketDescriptor, (struct sockaddr *) &local_addr, sizeof(local_addr)) < 0) { -#ifdef WIN32 - g_Logger.LogToOpenFile(logfile, "Couldn't connect - Error %i", WSAGetLastError()); -#else - g_Logger.LogToOpenFile(logfile, "Couldn't connect - Error %i", errno); -#endif + char error[255]; + g_LibSys.GetPlatformErrorEx(WSAGetLastError(), error, sizeof(error)); + g_Logger.LogToOpenFile(logfile, "Couldn't connect to %s: %s", g_serverAddress, error); closesocket(socketDescriptor); return INVALID_SOCKET; } @@ -318,35 +312,34 @@ int FetcherThread::ConnectSocket() void FetcherThread::ProcessGameDataQuery(int socketDescriptor) { char buffer[50]; -#ifdef DEBUG + +IF_DEBUG_SPEW g_Logger.LogToOpenFile(logfile, "Waiting for reply!"); -#endif +ENDIF_DEBUG_SPEW //Read in the header bytes int returnLen = RecvData(socketDescriptor, buffer, 12); -#ifdef DEBUG - g_Logger.LogToOpenFile(logfile, "Recv Completed"); -#endif if (returnLen == 0) { -#ifdef DEBUG - g_Logger.LogToOpenFile(logfile, ",but it failed."); -#endif - /* Timeout or fail? */ + char error[255]; + g_LibSys.GetPlatformErrorEx(WSAGetLastError(), error, sizeof(error)); + g_Logger.LogToOpenFile(logfile, "Did not receive reply: %s", error); return; } -#ifdef DEBUG +IF_DEBUG_SPEW g_Logger.LogToOpenFile(logfile, "Received Header!"); -#endif +ENDIF_DEBUG_SPEW bf_read Reader = bf_read("GameDataQuery", buffer, 12); if (Reader.ReadByte() != 'A' || Reader.ReadByte() != 'G') { +IF_DEBUG_SPEW g_Logger.LogToOpenFile(logfile, "Unknown Query Response"); +ENDIF_DEBUG_SPEW return; } @@ -359,17 +352,23 @@ void FetcherThread::ProcessGameDataQuery(int socketDescriptor) build[2] = Reader.ReadShort(); build[3] = Reader.ReadShort(); -#ifdef DEBUG - g_Logger.LogToOpenFile(logfile, "Update Status: %i - Latest %i.%i.%i.%i", updateStatus, build[0], build[1], build[2], build[3]); -#endif +IF_DEBUG_SPEW + g_Logger.LogToOpenFile(logfile, + "Update Status: %i - Latest %i.%i.%i.%i", + updateStatus, + build[0], + build[1], + build[2], + build[3]); +ENDIF_DEBUG_SPEW HandleUpdateStatus(updateStatus, build); int changedFiles = Reader.ReadByte(); -#ifdef DEBUG +IF_DEBUG_SPEW g_Logger.LogToOpenFile(logfile, "Files to download: %i", changedFiles); -#endif +ENDIF_DEBUG_SPEW for (int i=0; iCreateMem(tempLen+1, &memPtr); @@ -397,9 +396,9 @@ void FetcherThread::ProcessGameDataQuery(int socketDescriptor) //Read the contents of our file into the memtable returnLen = RecvData(socketDescriptor, (char *)memPtr, tempLen); -#ifdef DEBUG - g_Logger.LogToOpenFile(logfile, "Recieved %i bytes", returnLen); -#endif +IF_DEBUG_SPEW + g_Logger.LogToOpenFile(logfile, "Received %i bytes", returnLen); +ENDIF_DEBUG_SPEW if (returnLen == 0) { @@ -410,7 +409,7 @@ void FetcherThread::ProcessGameDataQuery(int socketDescriptor) ((unsigned char *)memPtr)[tempLen] = '\0'; FileData *data = filenames.at(index); - const char* filename; + const char *filename; if (data != NULL) { filename = data->filename->c_str(); @@ -419,12 +418,12 @@ void FetcherThread::ProcessGameDataQuery(int socketDescriptor) if (fp) { - fprintf(fp, (const char *)memPtr); + fprintf(fp, "%s", (const char *)memPtr); fclose(fp); } else { - g_Logger.LogToOpenFile(logfile, "Failed to open file \"%s\"", filename); + g_Logger.LogToOpenFile(logfile, "Failed to open file \"%s\" for writing", filename); } } else @@ -434,14 +433,13 @@ void FetcherThread::ProcessGameDataQuery(int socketDescriptor) memtable->Reset(); -#ifdef DEBUG - g_Logger.LogToOpenFile(logfile, "Updated File %s", filename); -#endif + + g_Logger.LogToOpenFile(logfile, "Updated file: %s", filename); } -#ifdef DEBUG +IF_DEBUG_SPEW g_Logger.LogToOpenFile(logfile, "File Downloads Completed!"); -#endif +ENDIF_DEBUG_SPEW bool needsRestart = false; @@ -456,8 +454,9 @@ void FetcherThread::ProcessGameDataQuery(int socketDescriptor) if (returnLen == 0) { - /* Timeout or fail? */ - g_Logger.LogToOpenFile(logfile, "Failed to receive unknown count"); + char error[255]; + g_LibSys.GetPlatformErrorEx(WSAGetLastError(), error, sizeof(error)); + g_Logger.LogToOpenFile(logfile, "Did not receive count reply: %s", error); return; } @@ -465,28 +464,27 @@ void FetcherThread::ProcessGameDataQuery(int socketDescriptor) changedFiles = Reader.ReadByte(); - if (changedFiles == 0) + if (changedFiles < 1) { -#ifdef DEBUG +IF_DEBUG_SPEW g_Logger.LogToOpenFile(logfile, "No unknown files. We're all done"); -#endif +ENDIF_DEBUG_SPEW return; } char *changedFileIndexes = new char[changedFiles]; -#ifdef DEBUG +IF_DEBUG_SPEW g_Logger.LogToOpenFile(logfile, "%i Files were unknown", changedFiles); -#endif +ENDIF_DEBUG_SPEW returnLen = RecvData(socketDescriptor, changedFileIndexes, changedFiles); if (returnLen == 0) { - /* Timeout or fail? */ -#ifdef DEBUG - g_Logger.LogToOpenFile(logfile, "Failed to receive unknown list"); -#endif + char error[255]; + g_LibSys.GetPlatformErrorEx(WSAGetLastError(), error, sizeof(error)); + g_Logger.LogToOpenFile(logfile, "Did not receive list reply: %s", error); return; } @@ -509,21 +507,22 @@ void FetcherThread::ProcessGameDataQuery(int socketDescriptor) } g_LibSys.GetFileFromPath(fileName, sizeof(fileName), pathname); -#ifdef DEBUG +IF_DEBUG_SPEW g_Logger.LogToOpenFile(logfile, "Unknown File %i : %s", index, fileName); -#endif +ENDIF_DEBUG_SPEW } delete [] changedFileIndexes; if (needsRestart && g_restartAfterUpdate) { + /* :TODO: none of this is thread safe. */ g_Logger.LogMessage("Automatically restarting server after a successful gamedata update!"); engine->ServerCommand("quit\n"); } } -int FetcherThread::RecvData( int socketDescriptor, char *buffer, int len ) +int FetcherThread::RecvData(int socketDescriptor, char *buffer, int len) { fd_set fds; struct timeval tv; @@ -562,7 +561,7 @@ int FetcherThread::RecvData( int socketDescriptor, char *buffer, int len ) return bytesReceivedTotal; } -int FetcherThread::SendData( int socketDescriptor, char *buffer, int len ) +int FetcherThread::SendData(int socketDescriptor, char *buffer, int len) { fd_set fds; struct timeval tv; @@ -597,7 +596,7 @@ int FetcherThread::SendData( int socketDescriptor, char *buffer, int len ) return sentBytesTotal; } -void FetcherThread::HandleUpdateStatus( UpdateStatus status, short version[4] ) +void FetcherThread::HandleUpdateStatus(UpdateStatus status, short version[4]) { switch (status) { @@ -609,14 +608,12 @@ void FetcherThread::HandleUpdateStatus( UpdateStatus status, short version[4] ) case Update_NewBuild: { - g_Logger.LogMessage("SourceMod Update: A new Mercurial build is available from sourcemod.net"); - g_Logger.LogMessage("Current Version: %i.%i.%i.%i Available: %i.%i.%i.%i", version[0], version[1], version[2], version[3], version[0], version[1], version[2], version[3]); break; } case Update_MinorAvailable: { - g_Logger.LogMessage("SourceMod Update: An incremental minor release of SourceMod is now available from sourcemod.net"); + g_Logger.LogMessage("SourceMod Update: A new release of SourceMod is now available from sourcemod.net"); g_Logger.LogMessage("Current Version: %i.%i.%i Available: %i.%i.%i", version[0], version[1], version[2], version[0], version[1], version[2]); break; } @@ -630,8 +627,8 @@ void FetcherThread::HandleUpdateStatus( UpdateStatus status, short version[4] ) case Update_CriticalAvailable: { - g_Logger.LogError("SourceMod Update: A new critical release of SourceMod is now available from sourcemod.net. It is strongly recommended that you update"); - g_Logger.LogMessage("Current Version: %i.%i.%i.%i Available: %i.%i.%i.%i", version[0], version[1], version[2], version[3], version[0], version[1], version[2], version[3]); + g_Logger.LogError("SourceMod Update: A critical SourceMod release is available from sourcemod.net. It is strongly recommended that you update!"); + g_Logger.LogMessage("Current Version: %i.%i.%i Available: %i.%i.%i", version[0], version[1], version[2], version[0], version[1], version[2]); break; } } @@ -665,14 +662,14 @@ public: char *error, size_t maxlength) { - if (strcmp(key, "DisableAutoUpdate") == 0) + if (strcasecmp(key, "DisableAutoUpdate") == 0) { - if (strcmp(value, "yes") == 0) + if (strcasecmp(value, "yes") == 0) { g_disableGameDataUpdate = true; return ConfigResult_Accept; } - else if (strcmp(value, "no") == 0) + else if (strcasecmp(value, "no") == 0) { g_disableGameDataUpdate = false; return ConfigResult_Accept; @@ -681,14 +678,14 @@ public: return ConfigResult_Reject; } - if (strcmp(key, "ForceRestartAfterUpdate") == 0) + if (strcasecmp(key, "ForceRestartAfterUpdate") == 0) { - if (strcmp(value, "yes") == 0) + if (strcasecmp(value, "yes") == 0) { g_restartAfterUpdate = true; return ConfigResult_Accept; } - else if (strcmp(value, "no") == 0) + else if (strcasecmp(value, "no") == 0) { g_restartAfterUpdate = false; return ConfigResult_Accept; @@ -697,14 +694,14 @@ public: return ConfigResult_Reject; } - if (strcmp(key, "AutoUpdateServer") == 0) + if (strcasecmp(key, "AutoUpdateServer") == 0) { UTIL_Format(g_serverAddress, sizeof(g_serverAddress), "%s", value); return ConfigResult_Accept; } - if (strcmp(key, "AutoUpdatePort") == 0) + if (strcasecmp(key, "AutoUpdatePort") == 0) { int port = atoi(value); @@ -722,6 +719,55 @@ public: } } g_InitFetch; +BuildMD5ableBuffer::BuildMD5ableBuffer() +{ + stringTable = new BaseStringTable(2048); +} + +BuildMD5ableBuffer::~BuildMD5ableBuffer() +{ + delete stringTable; +} + +void BuildMD5ableBuffer::ReadSMC_ParseStart() +{ + stringTable->Reset(); +} + +SMCResult BuildMD5ableBuffer::ReadSMC_KeyValue(const SMCStates *states, + const char *key, + const char *value) +{ + stringTable->AddString(key); + stringTable->AddString(value); + + return SMCResult_Continue; +} + +SMCResult BuildMD5ableBuffer::ReadSMC_NewSection(const SMCStates *states, const char *name) +{ + stringTable->AddString(name); + + return SMCResult_Continue; +} + +void BuildMD5ableBuffer::ReadSMC_ParseEnd(bool halted, bool failed) +{ + if (halted || failed) + { + return; + } + + void *data = stringTable->GetMemTable()->GetAddress(0); + + if (data != NULL) + { + checksum->update((unsigned char *)data, stringTable->GetMemTable()->GetActualMemUsed()); + } + + checksum->finalize(); +} + CON_COMMAND(sm_gamedata_md5, "Checks the MD5 sum for a given gamedata file") { #if !defined ORANGEBOX_BUILD @@ -764,3 +810,25 @@ CON_COMMAND(sm_gamedata_md5, "Checks the MD5 sum for a given gamedata file") g_SMAPI->ConPrint("File not found!\n"); } + +FetcherThread::~FetcherThread() +{ + //delete filenames; + SourceHook::CVector::iterator iter = filenames.begin(); + + FileData *curData; + + while (iter != filenames.end()) + { + curData = (*iter); + delete curData->filename; + delete curData; + iter = filenames.erase(iter); + } +} + +FetcherThread::FetcherThread() +{ + memtable = new BaseMemTable(4096); +} + diff --git a/core/GameDataFetcher.h b/core/GameDataFetcher.h index 320db058..8c6103b4 100644 --- a/core/GameDataFetcher.h +++ b/core/GameDataFetcher.h @@ -38,7 +38,6 @@ #include "Logger.h" #include "LibrarySys.h" #include "ThreadSupport.h" -#include "md5.h" #include "sm_memtable.h" enum UpdateStatus @@ -51,127 +50,44 @@ enum UpdateStatus Update_CriticalAvailable = 5, /* A critical update has been released (security fixes etc) */ }; +class MD5; + class BuildMD5ableBuffer : public ITextListener_SMC { public: - - BuildMD5ableBuffer() - { - stringTable = new BaseStringTable(2048); - md5[0] = 0; - md5String[0] = 0; - } - - ~BuildMD5ableBuffer() - { - delete stringTable; - } - - void ReadSMC_ParseStart() - { - checksum = MD5(); - } - - SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value) - { - stringTable->AddString(key); - stringTable->AddString(value); - - return SMCResult_Continue; - } - - SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name) - { - stringTable->AddString(name); - - return SMCResult_Continue; - } - - void ReadSMC_ParseEnd(bool halted, bool failed) - { - if (halted || failed) - { - return; - } - - void *data = stringTable->GetMemTable()->GetAddress(0); - - if (data != NULL) - { - checksum.update((unsigned char *)data, stringTable->GetMemTable()->GetActualMemUsed()); - } - - checksum.finalize(); - - checksum.hex_digest(md5String); - checksum.raw_digest(md5); - - stringTable->Reset(); - } - - unsigned char * GetMD5() - { - return md5; - } - - unsigned char * GetMD5String() - { - return (unsigned char *)&md5String[0]; - } - + BuildMD5ableBuffer(); + ~BuildMD5ableBuffer(); + void ReadSMC_ParseStart(); + SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value); + SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name); + void ReadSMC_ParseEnd(bool halted, bool failed); +public: + MD5 *checksum; private: - MD5 checksum; - unsigned char md5[16]; - char md5String[33]; BaseStringTable *stringTable; }; struct FileData { SourceHook::String *filename; - unsigned char checksum[33]; + char checksum[33]; }; - class FetcherThread : public IThread { public: - FetcherThread() - { - //filenames = new BaseStringTable(200); - memtable = new BaseMemTable(4096); - } - - ~FetcherThread() - { - //delete filenames; - SourceHook::CVector::iterator iter = filenames.begin(); - - FileData *curData; - - while (iter != filenames.end()) - { - curData = (*iter); - delete curData->filename; - delete curData; - iter = filenames.erase(iter); - } - } - + FetcherThread(); + ~FetcherThread(); +public: void RunThread(IThreadHandle *pHandle); void OnTerminate(IThreadHandle *pHandle, bool cancel); - private: int BuildGameDataQuery(char *buffer, int maxlen); void ProcessGameDataQuery(int SocketDescriptor); - int RecvData(int socketDescriptor, char *buffer, int len); int SendData(int socketDescriptor, char *buffer, int len); - int ConnectSocket(); - void HandleUpdateStatus(UpdateStatus status, short version[4]); - public: SourceHook::CVector filenames; private: @@ -182,3 +98,4 @@ extern BuildMD5ableBuffer g_MD5Builder; extern bool g_blockGameDataLoad; #endif // _INCLUDE_SOURCEMOD_GAMEDATAFETCHER_H_ + diff --git a/core/LibrarySys.cpp b/core/LibrarySys.cpp index b7395d7a..3615298f 100644 --- a/core/LibrarySys.cpp +++ b/core/LibrarySys.cpp @@ -272,21 +272,35 @@ IDirectory *LibrarySystem::OpenDirectory(const char *path) } void LibrarySystem::GetPlatformError(char *error, size_t maxlength) +{ +#if defined PLATFORM_WINDOWS + return GetPlatformErrorEx(GetLastError(), error, maxlength); +#elif defined PLATFORM_POSIX + return GetPlatformErrorEx(errno, error, maxlength); +#endif +} + +void LibrarySystem::GetPlatformErrorEx(int code, char *error, size_t maxlength) { if (error && maxlength) { #if defined PLATFORM_WINDOWS - DWORD dw = GetLastError(); FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, - dw, + (DWORD)code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)error, maxlength, NULL); +#elif defined PLATFORM_LINUX + const char *ae = strerror_r(code, error, maxlength); + if (ae != error) + { + UTIL_Format(error, maxlength, "%s", ae); + } #elif defined PLATFORM_POSIX - UTIL_Format(error, maxlength, "%s", strerror(errno)); + strerror_r(code, error, maxlength); #endif } } diff --git a/core/LibrarySys.h b/core/LibrarySys.h index 45a94921..3eebd1c7 100644 --- a/core/LibrarySys.h +++ b/core/LibrarySys.h @@ -90,6 +90,7 @@ public: bool IsPathFile(const char *path); bool IsPathDirectory(const char *path); void GetPlatformError(char *error, size_t maxlength); + void GetPlatformErrorEx(int code, char *error, size_t maxlength); size_t PathFormat(char *buffer, size_t len, const char *fmt, ...); const char *GetFileExtension(const char *filename); bool CreateFolder(const char *path); diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index 19ed9d92..20a4cd36 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -63,6 +63,7 @@ ISourcePawnEngine2 *g_pSourcePawn2 = NULL; IdentityToken_t *g_pCoreIdent = NULL; IForward *g_pOnMapEnd = NULL; bool g_Loaded = false; +bool sm_show_debug_spew = false; typedef ISourcePawnEngine *(*GET_SP_V1)(); typedef ISourcePawnEngine2 *(*GET_SP_V2)(); @@ -115,6 +116,12 @@ ConfigResult SourceModBase::OnSourceModConfigChanged(const char *key, return ConfigResult_Accept; } + else if (strcasecmp(key, "DebugSpew") == 0) + { + sm_show_debug_spew = (strcasecmp(value, "yes") == 0) ? true : false; + + return ConfigResult_Accept; + } return ConfigResult_Ignore; } diff --git a/core/sourcemod.h b/core/sourcemod.h index 3948b44a..ac826be6 100644 --- a/core/sourcemod.h +++ b/core/sourcemod.h @@ -40,6 +40,17 @@ using namespace SourceHook; +#if defined _DEBUG +# define IF_DEBUG_SPEW +# define ENDIF_DEBUG_SPEW +#else +# define IF_DEBUG_SPEW \ + if (sm_show_debug_spew) \ + { +# define ENDIF_DEBUG_SPEW \ + } +#endif + /** * @brief Implements SourceMod's global overall management, API, and logic */ @@ -132,6 +143,7 @@ private: }; extern bool g_Loaded; +extern bool sm_show_debug_spew; extern SourceModBase g_SourceMod; extern HandleType_t g_WrBitBufType; //:TODO: find a better place for this extern HandleType_t g_RdBitBufType; //:TODO: find a better place for this From e69ed4b0dad0dea8eef492ff41c7ef620d73dc2a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 27 Dec 2008 19:50:13 -0500 Subject: [PATCH 5/8] Removed unsafe calls from gamedata threader (bug 3351, r=pred). --- core/GameDataFetcher.cpp | 100 +++++++++++++++++++++------------------ core/GameDataFetcher.h | 6 +++ core/Logger.cpp | 33 +++++++++++++ core/Logger.h | 3 ++ 4 files changed, 96 insertions(+), 46 deletions(-) diff --git a/core/GameDataFetcher.cpp b/core/GameDataFetcher.cpp index 125615bd..578ae5b9 100644 --- a/core/GameDataFetcher.cpp +++ b/core/GameDataFetcher.cpp @@ -85,8 +85,6 @@ void FetcherThread::RunThread(IThreadHandle *pHandle) g_SourceMod.BuildPath(Path_SM, lock_path, sizeof(lock_path), "data/temp/gamedata.lock"); - g_Logger.LogMessage("Starting Gamedata update fetcher... please report problems to bugs.alliedmods.net"); - char log_path[PLATFORM_MAX_PATH]; g_SourceMod.BuildPath(Path_SM, log_path, sizeof(log_path), "logs/gamedata"); @@ -102,7 +100,7 @@ void FetcherThread::RunThread(IThreadHandle *pHandle) if (!logfile) { - g_Logger.LogError("Failed to create GameData log file"); + /* :( */ return; } @@ -120,17 +118,16 @@ void FetcherThread::RunThread(IThreadHandle *pHandle) if (len == 0) { - g_Logger.LogToOpenFile(logfile, "Query Writing failed"); - + g_Logger.LogToFileOnly(logfile, "Could not build gamedata query!"); fclose(logfile); unlink(lock_path); return; } + /* We check this late so we have the MD5 sums available. This may change in the future. */ if (g_disableGameDataUpdate) { - g_Logger.LogMessage("Skipping GameData Query due to DisableAutoUpdate being set to true"); - + g_Logger.LogToFileOnly(logfile, "Skipping gamedata fetcher (DisableAutoUpdate set)"); fclose(logfile); unlink(lock_path); return; @@ -149,13 +146,13 @@ void FetcherThread::RunThread(IThreadHandle *pHandle) int sent = SendData(socketDescriptor, query, len); IF_DEBUG_SPEW - g_Logger.LogToOpenFile(logfile, "Sent gamedata query"); + g_Logger.LogToFileOnly(logfile, "Sent gamedata query"); ENDIF_DEBUG_SPEW if (sent == 0) { IF_DEBUG_SPEW - g_Logger.LogToOpenFile(logfile, "Failed to send gamedata query data to remote host"); + g_Logger.LogToFileOnly(logfile, "Failed to send gamedata query data to remote host"); ENDIF_DEBUG_SPEW closesocket(socketDescriptor); @@ -175,6 +172,28 @@ ENDIF_DEBUG_SPEW void FetcherThread::OnTerminate(IThreadHandle *pHandle, bool cancel) { g_blockGameDataLoad = false; + + if (wasSuccess) + { + HandleUpdateStatus(updateStatus, build); + + if (needsRestart) + { + if (g_restartAfterUpdate) + { + g_Logger.LogMessage("Automatically restarting server after a successful gamedata update!"); + engine->ServerCommand("quit\n"); + } + else + { + g_Logger.LogMessage("Your gamedata files have been updated, please restart your server."); + } + } + } + else if (!g_disableGameDataUpdate) + { + g_Logger.LogError("An error occurred in the gamedata fetcher, see your gamedata log files for more information."); + } } int FetcherThread::BuildGameDataQuery(char *buffer, int maxlen) @@ -229,7 +248,7 @@ int FetcherThread::BuildGameDataQuery(char *buffer, int maxlen) filenames.push_back(data); IF_DEBUG_SPEW - g_Logger.LogToOpenFile(logfile, "Parsed file: %s as %s", file, data->checksum); + g_Logger.LogToFileOnly(logfile, "Parsed file: %s as %s", file, data->checksum); ENDIF_DEBUG_SPEW } @@ -237,12 +256,11 @@ ENDIF_DEBUG_SPEW { IF_DEBUG_SPEW const char *error = g_TextParser.GetSMCErrorString(err); - g_Logger.LogToOpenFile(logfile, "Parsing of file %s failed: %s", file, error); + g_Logger.LogToFileOnly(logfile, "Parsing of file %s failed: %s", file, error); ENDIF_DEBUG_SPEW } } } - dir->NextEntry(); } @@ -260,7 +278,7 @@ int FetcherThread::ConnectSocket() if ((ptrp = getprotobyname("tcp")) == NULL) { - g_Logger.LogToOpenFile(logfile, "Error: Failed to find TCP protocol"); + g_Logger.LogToFileOnly(logfile, "Error: Failed to find TCP protocol"); return INVALID_SOCKET; } @@ -270,7 +288,7 @@ int FetcherThread::ConnectSocket() { char error[255]; g_LibSys.GetPlatformErrorEx(WSAGetLastError(), error, sizeof(error)); - g_Logger.LogToOpenFile(logfile, "Error: Failed to create socket: %s", error); + g_Logger.LogToFileOnly(logfile, "Error: Failed to create socket: %s", error); closesocket(socketDescriptor); return INVALID_SOCKET; } @@ -287,7 +305,7 @@ int FetcherThread::ConnectSocket() { if ((local_addr.sin_addr.s_addr = inet_addr(g_serverAddress)) == INADDR_NONE) { - g_Logger.LogToOpenFile(logfile, "Couldn't locate address: %s", g_serverAddress); + g_Logger.LogToFileOnly(logfile, "Couldn't locate address: %s", g_serverAddress); closesocket(socketDescriptor); return INVALID_SOCKET; } @@ -301,7 +319,7 @@ int FetcherThread::ConnectSocket() { char error[255]; g_LibSys.GetPlatformErrorEx(WSAGetLastError(), error, sizeof(error)); - g_Logger.LogToOpenFile(logfile, "Couldn't connect to %s: %s", g_serverAddress, error); + g_Logger.LogToFileOnly(logfile, "Couldn't connect to %s: %s", g_serverAddress, error); closesocket(socketDescriptor); return INVALID_SOCKET; } @@ -314,7 +332,7 @@ void FetcherThread::ProcessGameDataQuery(int socketDescriptor) char buffer[50]; IF_DEBUG_SPEW - g_Logger.LogToOpenFile(logfile, "Waiting for reply!"); + g_Logger.LogToFileOnly(logfile, "Waiting for reply!"); ENDIF_DEBUG_SPEW //Read in the header bytes @@ -325,12 +343,12 @@ ENDIF_DEBUG_SPEW { char error[255]; g_LibSys.GetPlatformErrorEx(WSAGetLastError(), error, sizeof(error)); - g_Logger.LogToOpenFile(logfile, "Did not receive reply: %s", error); + g_Logger.LogToFileOnly(logfile, "Did not receive reply: %s", error); return; } IF_DEBUG_SPEW - g_Logger.LogToOpenFile(logfile, "Received Header!"); + g_Logger.LogToFileOnly(logfile, "Received Header!"); ENDIF_DEBUG_SPEW bf_read Reader = bf_read("GameDataQuery", buffer, 12); @@ -338,14 +356,12 @@ ENDIF_DEBUG_SPEW if (Reader.ReadByte() != 'A' || Reader.ReadByte() != 'G') { IF_DEBUG_SPEW - g_Logger.LogToOpenFile(logfile, "Unknown Query Response"); + g_Logger.LogToFileOnly(logfile, "Unknown Query Response"); ENDIF_DEBUG_SPEW return; } - UpdateStatus updateStatus = (UpdateStatus)Reader.ReadByte(); - - short build[4] = {0,0,0,0}; + updateStatus = (UpdateStatus)Reader.ReadByte(); build[0] = Reader.ReadShort(); build[1] = Reader.ReadShort(); @@ -353,7 +369,7 @@ ENDIF_DEBUG_SPEW build[3] = Reader.ReadShort(); IF_DEBUG_SPEW - g_Logger.LogToOpenFile(logfile, + g_Logger.LogToFileOnly(logfile, "Update Status: %i - Latest %i.%i.%i.%i", updateStatus, build[0], @@ -362,12 +378,10 @@ IF_DEBUG_SPEW build[3]); ENDIF_DEBUG_SPEW - HandleUpdateStatus(updateStatus, build); - int changedFiles = Reader.ReadByte(); IF_DEBUG_SPEW - g_Logger.LogToOpenFile(logfile, "Files to download: %i", changedFiles); + g_Logger.LogToFileOnly(logfile, "Files to download: %i", changedFiles); ENDIF_DEBUG_SPEW for (int i=0; iReset(); - - g_Logger.LogToOpenFile(logfile, "Updated file: %s", filename); + g_Logger.LogToFileOnly(logfile, "Updated file: %s", filename); } IF_DEBUG_SPEW - g_Logger.LogToOpenFile(logfile, "File Downloads Completed!"); + g_Logger.LogToFileOnly(logfile, "File Downloads Completed!"); ENDIF_DEBUG_SPEW - bool needsRestart = false; + needsRestart = false; if (changedFiles > 0) { needsRestart = true; - g_Logger.LogMessage("New GameData Files have been downloaded to your gamedata directory. Please restart your server for these to take effect"); } //Read changed file count @@ -456,7 +468,7 @@ ENDIF_DEBUG_SPEW { char error[255]; g_LibSys.GetPlatformErrorEx(WSAGetLastError(), error, sizeof(error)); - g_Logger.LogToOpenFile(logfile, "Did not receive count reply: %s", error); + g_Logger.LogToFileOnly(logfile, "Did not receive count reply: %s", error); return; } @@ -467,7 +479,7 @@ ENDIF_DEBUG_SPEW if (changedFiles < 1) { IF_DEBUG_SPEW - g_Logger.LogToOpenFile(logfile, "No unknown files. We're all done"); + g_Logger.LogToFileOnly(logfile, "No unknown files. We're all done"); ENDIF_DEBUG_SPEW return; } @@ -475,7 +487,7 @@ ENDIF_DEBUG_SPEW char *changedFileIndexes = new char[changedFiles]; IF_DEBUG_SPEW - g_Logger.LogToOpenFile(logfile, "%i Files were unknown", changedFiles); + g_Logger.LogToFileOnly(logfile, "%i files were unknown", changedFiles); ENDIF_DEBUG_SPEW returnLen = RecvData(socketDescriptor, changedFileIndexes, changedFiles); @@ -484,7 +496,7 @@ ENDIF_DEBUG_SPEW { char error[255]; g_LibSys.GetPlatformErrorEx(WSAGetLastError(), error, sizeof(error)); - g_Logger.LogToOpenFile(logfile, "Did not receive list reply: %s", error); + g_Logger.LogToFileOnly(logfile, "Did not receive list reply: %s", error); return; } @@ -508,18 +520,13 @@ ENDIF_DEBUG_SPEW g_LibSys.GetFileFromPath(fileName, sizeof(fileName), pathname); IF_DEBUG_SPEW - g_Logger.LogToOpenFile(logfile, "Unknown File %i : %s", index, fileName); + g_Logger.LogToFileOnly(logfile, "Unknown File %i : %s", index, fileName); ENDIF_DEBUG_SPEW } delete [] changedFileIndexes; - if (needsRestart && g_restartAfterUpdate) - { - /* :TODO: none of this is thread safe. */ - g_Logger.LogMessage("Automatically restarting server after a successful gamedata update!"); - engine->ServerCommand("quit\n"); - } + wasSuccess = true; } int FetcherThread::RecvData(int socketDescriptor, char *buffer, int len) @@ -830,5 +837,6 @@ FetcherThread::~FetcherThread() FetcherThread::FetcherThread() { memtable = new BaseMemTable(4096); + wasSuccess = false; } diff --git a/core/GameDataFetcher.h b/core/GameDataFetcher.h index 8c6103b4..72cb0c76 100644 --- a/core/GameDataFetcher.h +++ b/core/GameDataFetcher.h @@ -39,6 +39,8 @@ #include "LibrarySys.h" #include "ThreadSupport.h" #include "sm_memtable.h" +#include +#include enum UpdateStatus { @@ -91,7 +93,11 @@ private: public: SourceHook::CVector filenames; private: + bool wasSuccess; + bool needsRestart; + UpdateStatus updateStatus; BaseMemTable *memtable; + short build[4]; }; extern BuildMD5ableBuffer g_MD5Builder; diff --git a/core/Logger.cpp b/core/Logger.cpp index 977bf732..b2209258 100644 --- a/core/Logger.cpp +++ b/core/Logger.cpp @@ -245,6 +245,19 @@ void Logger::LogToOpenFile(FILE *fp, const char *msg, ...) va_end(ap); } +void Logger::LogToFileOnly(FILE *fp, const char *msg, ...) +{ + if (!m_Active) + { + return; + } + + va_list ap; + va_start(ap, msg); + LogToFileOnlyEx(fp, msg, ap); + va_end(ap); +} + void Logger::LogToOpenFileEx(FILE *fp, const char *msg, va_list ap) { if (!m_Active) @@ -265,6 +278,26 @@ void Logger::LogToOpenFileEx(FILE *fp, const char *msg, va_list ap) g_SMAPI->ConPrintf("L %s: %s\n", date, buffer); } +void Logger::LogToFileOnlyEx(FILE *fp, const char *msg, va_list ap) +{ + if (!m_Active) + { + return; + } + + char buffer[3072]; + UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap); + + char date[32]; + time_t t; + GetAdjustedTime(&t); + tm *curtime = localtime(&t); + strftime(date, sizeof(date), "%m/%d/%Y - %H:%M:%S", curtime); + + fprintf(fp, "L %s: %s\n", date, buffer); + fflush(fp); +} + void Logger::LogMessage(const char *vafmt, ...) { if (!m_Active) diff --git a/core/Logger.h b/core/Logger.h index 7d9cc57d..a81d0daf 100644 --- a/core/Logger.h +++ b/core/Logger.h @@ -78,6 +78,9 @@ public: void LogFatal(const char *msg, ...); void LogToOpenFile(FILE *fp, const char *msg, ...); void LogToOpenFileEx(FILE *fp, const char *msg, va_list ap); + /* This version does not print to console, and is thus thread-safe */ + void LogToFileOnly(FILE *fp, const char *msg, ...); + void LogToFileOnlyEx(FILE *fp, const char *msg, va_list ap); void MapChange(const char *mapname); const char *GetLogFileName(LogType type) const; LoggingMode GetLoggingMode() const; From d3c279fd057be98273d0e09e749c6632f3dab2a2 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 28 Dec 2008 01:02:05 -0500 Subject: [PATCH 6/8] Fixed threading issues in gamedata fetcher, new restart mechanism (bug 3351, r=pred). --- configs/core.cfg | 19 ++++-- core/GameDataFetcher.cpp | 137 ++++++++++++++++++++++++++++----------- core/GameDataFetcher.h | 62 +++++++++--------- core/PlayerManager.cpp | 7 ++ core/frame_hooks.cpp | 55 +++++++++++++++- core/frame_hooks.h | 9 +++ core/sm_globals.h | 7 ++ 7 files changed, 219 insertions(+), 77 deletions(-) diff --git a/configs/core.cfg b/configs/core.cfg index 86163810..02889b7c 100644 --- a/configs/core.cfg +++ b/configs/core.cfg @@ -94,22 +94,29 @@ * * The default value is "no". A value of "yes" will block the Auto Updater. */ - "DisableAutoUpdate" "no" + "DisableAutoUpdate" "no" /** - * Enables or disables automatic restarting of the server after a successful update. - * - * The default value is "no". A value of "yes" will let the server automatically restart. + * If set to yes, a successful gamedata update will attempt to restart SourceMod. + * SourceMod is unloaded and reloaded, and the map is changed to the current map. + * Since gamedata updates occur when the server loads, impact should be minimal. + * But to be safe, this option is disabled by default. */ - "ForceRestartAfterUpdate" "no" + "ForceRestartAfterUpdate" "no" /** * Sets the server to connect to for auotmatic gamedata updates. */ - "AutoUpdateServer" "smupdate.alliedmods.net" + "AutoUpdateServer" "smupdate.alliedmods.net" /** * Sets the port to connect to on the AutoUpdateServer server */ "AutoUpdatePort" "6500" + + /** + * Whether to show debug spew. + * Currently this will log details about the gamedata updating process. + */ + "DebugSpew" "no" } diff --git a/core/GameDataFetcher.cpp b/core/GameDataFetcher.cpp index 578ae5b9..371bb905 100644 --- a/core/GameDataFetcher.cpp +++ b/core/GameDataFetcher.cpp @@ -1,33 +1,33 @@ /** -* vim: set ts=4 : -* ============================================================================= -* SourceMod -* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. -* ============================================================================= -* -* This program is free software; you can redistribute it and/or modify it under -* the terms of the GNU General Public License, version 3.0, as published by the -* Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -* details. -* -* You should have received a copy of the GNU General Public License along with -* this program. If not, see . -* -* As a special exception, AlliedModders LLC gives you permission to link the -* code of this program (as well as its derivative works) to "Half-Life 2," the -* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software -* by the Valve Corporation. You must obey the GNU General Public License in -* all respects for all other code used. Additionally, AlliedModders LLC grants -* this exception to all derivative works. AlliedModders LLC defines further -* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), -* or . -* -* Version: $Id$ -*/ + * vim: set ts=4 : + * ============================================================================= + * SourceMod + * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. + * ============================================================================= + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, version 3.0, as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + * + * As a special exception, AlliedModders LLC gives you permission to link the + * code of this program (as well as its derivative works) to "Half-Life 2," the + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software + * by the Valve Corporation. You must obey the GNU General Public License in + * all respects for all other code used. Additionally, AlliedModders LLC grants + * this exception to all derivative works. AlliedModders LLC defines further + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), + * or . + * + * Version: $Id$ + */ #include "GameDataFetcher.h" #include "bitbuf.h" @@ -63,19 +63,49 @@ #include "compat_wrappers.h" #include "sm_stringutil.h" #include "md5.h" +#include "frame_hooks.h" #define QUERY_MAX_LENGTH 1024 -BuildMD5ableBuffer g_MD5Builder; -FetcherThread g_FetchThread; +static BuildMD5ableBuffer g_MD5Builder; +static FetcherThread g_FetchThread; -FILE *logfile = NULL; +static FILE *logfile = NULL; bool g_disableGameDataUpdate = false; + +/** + * Note on this. If we issue a reload and changelevel, my srcds.exe will emit + * Assertion Failed: !m_bServiceStarted + * on quit. This seems like a non-issue, because before we just terminated the + * server anyway. If anyone notices and files a bug, we can look into it further. + */ bool g_restartAfterUpdate = false; -int g_serverPort = 6500; -char g_serverAddress[100] = "smupdate.alliedmods.net"; +static bool was_level_started = false; +static int g_serverPort = 6500; +static char g_serverAddress[100] = "smupdate.alliedmods.net"; + +static void _ForceRestart(void *data) +{ + char cmd[300]; + g_Logger.LogMessage("Automatically restarting SourceMod after a successful gamedata update."); + UTIL_Format(cmd, sizeof(cmd), "meta unload %d\n", g_PLID); + engine->ServerCommand(cmd); + UTIL_Format(cmd, sizeof(cmd), "changelevel \"%s\"\n", STRING(gpGlobals->mapname)); + engine->ServerCommand(cmd); + UTIL_Format(cmd, sizeof(cmd), "echo SourceMod restarted after gamedata update.\n"); + engine->ServerCommand(cmd); +} + +static void ForceRestart() +{ + FrameAction action; + + action.action = _ForceRestart; + action.data = NULL; + AddFrameAction(action); +} void FetcherThread::RunThread(IThreadHandle *pHandle) { @@ -173,6 +203,11 @@ void FetcherThread::OnTerminate(IThreadHandle *pHandle, bool cancel) { g_blockGameDataLoad = false; + if (cancel) + { + return; + } + if (wasSuccess) { HandleUpdateStatus(updateStatus, build); @@ -181,8 +216,10 @@ void FetcherThread::OnTerminate(IThreadHandle *pHandle, bool cancel) { if (g_restartAfterUpdate) { - g_Logger.LogMessage("Automatically restarting server after a successful gamedata update!"); - engine->ServerCommand("quit\n"); + if (was_level_started) + { + ForceRestart(); + } } else { @@ -642,6 +679,7 @@ void FetcherThread::HandleUpdateStatus(UpdateStatus status, short version[4]) } bool g_blockGameDataLoad = false; +static IThreadHandle *fetch_thread_hndl; class InitFetch : public SMGlobalClass { @@ -660,7 +698,30 @@ public: ThreadParams fetchThreadParams = ThreadParams(); fetchThreadParams.prio = ThreadPrio_Low; - g_pThreader->MakeThread(&g_FetchThread, &fetchThreadParams); + fetch_thread_hndl = g_pThreader->MakeThread(&g_FetchThread, &fetchThreadParams); + } + + void OnSourceModShutdown() + { + fetch_thread_hndl->WaitForThread(); + fetch_thread_hndl->DestroyThis(); + } + + void OnSourceModLevelActivated() + { + was_level_started = true; + + if (g_restartAfterUpdate && + g_FetchThread.wasSuccess && + g_FetchThread.needsRestart) + { + ForceRestart(); + } + } + + void OnSourceModLevelEnd() + { + was_level_started = false; } ConfigResult OnSourceModConfigChanged(const char *key, @@ -820,7 +881,6 @@ CON_COMMAND(sm_gamedata_md5, "Checks the MD5 sum for a given gamedata file") FetcherThread::~FetcherThread() { - //delete filenames; SourceHook::CVector::iterator iter = filenames.begin(); FileData *curData; @@ -838,5 +898,6 @@ FetcherThread::FetcherThread() { memtable = new BaseMemTable(4096); wasSuccess = false; + needsRestart = false; } diff --git a/core/GameDataFetcher.h b/core/GameDataFetcher.h index 72cb0c76..e8a4a0b0 100644 --- a/core/GameDataFetcher.h +++ b/core/GameDataFetcher.h @@ -1,33 +1,33 @@ /** -* vim: set ts=4 : -* ============================================================================= -* SourceMod -* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. -* ============================================================================= -* -* This program is free software; you can redistribute it and/or modify it under -* the terms of the GNU General Public License, version 3.0, as published by the -* Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -* details. -* -* You should have received a copy of the GNU General Public License along with -* this program. If not, see . -* -* As a special exception, AlliedModders LLC gives you permission to link the -* code of this program (as well as its derivative works) to "Half-Life 2," the -* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software -* by the Valve Corporation. You must obey the GNU General Public License in -* all respects for all other code used. Additionally, AlliedModders LLC grants -* this exception to all derivative works. AlliedModders LLC defines further -* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), -* or . -* -* Version: $Id$ -*/ + * vim: set ts=4 : + * ============================================================================= + * SourceMod + * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. + * ============================================================================= + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, version 3.0, as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + * + * As a special exception, AlliedModders LLC gives you permission to link the + * code of this program (as well as its derivative works) to "Half-Life 2," the + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software + * by the Valve Corporation. You must obey the GNU General Public License in + * all respects for all other code used. Additionally, AlliedModders LLC grants + * this exception to all derivative works. AlliedModders LLC defines further + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), + * or . + * + * Version: $Id$ + */ #ifndef _INCLUDE_SOURCEMOD_GAMEDATAFETCHER_H_ #define _INCLUDE_SOURCEMOD_GAMEDATAFETCHER_H_ @@ -92,9 +92,9 @@ private: void HandleUpdateStatus(UpdateStatus status, short version[4]); public: SourceHook::CVector filenames; -private: - bool wasSuccess; bool needsRestart; + bool wasSuccess; +private: UpdateStatus updateStatus; BaseMemTable *memtable; short build[4]; diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 657741d7..95b9f292 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -272,6 +272,13 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl g_OnMapStarted = true; + SMGlobalClass *cls = SMGlobalClass::head; + while (cls) + { + cls->OnSourceModLevelActivated(); + cls = cls->m_pGlobalClassNext; + } + SM_ExecuteAllConfigs(); } diff --git a/core/frame_hooks.cpp b/core/frame_hooks.cpp index fa7a98f4..2410ca2f 100644 --- a/core/frame_hooks.cpp +++ b/core/frame_hooks.cpp @@ -36,13 +36,64 @@ #include "MenuStyle_Radio.h" #include "PlayerManager.h" #include "CoreConfig.h" +#include +#include "ThreadSupport.h" -float g_LastMenuTime = 0.0f; -float g_LastAuthCheck = 0.0f; +static IMutex *frame_mutex; +static Queue *frame_queue; +static Queue *frame_actions; +static float g_LastMenuTime = 0.0f; +static float g_LastAuthCheck = 0.0f; bool g_PendingInternalPush = false; +class FrameActionInit : public SMGlobalClass +{ +public: + void OnSourceModAllInitialized() + { + frame_queue = new Queue(); + frame_actions = new Queue(); + frame_mutex = g_pThreader->MakeMutex(); + } + + void OnSourceModShutdown() + { + delete frame_queue; + delete frame_actions; + frame_mutex->DestroyThis(); + } +} s_FrameActionInit; + +void AddFrameAction(const FrameAction & action) +{ + frame_mutex->Lock(); + frame_queue->push(action); + frame_mutex->Unlock(); +} + void RunFrameHooks(bool simulating) { + /* It's okay if this check races. */ + if (frame_queue->size()) + { + Queue *temp; + + /* Very quick lock to move queue/actions back and forth */ + frame_mutex->Lock(); + temp = frame_queue; + frame_queue = frame_actions; + frame_actions = temp; + frame_mutex->Unlock(); + + /* The server will now be adding to the other queue, so we can process events. */ + while (!frame_actions->empty()) + { + FrameAction &item = frame_actions->first(); + frame_actions->pop(); + item.action(item.data); + } + } + /* Frame based hooks */ g_DBMan.RunFrame(); g_HL2.ProcessFakeCliCmdQueue(); diff --git a/core/frame_hooks.h b/core/frame_hooks.h index 8e27acd5..23a6ad26 100644 --- a/core/frame_hooks.h +++ b/core/frame_hooks.h @@ -32,8 +32,17 @@ #ifndef _INCLUDE_SOURCEMOD_FRAME_HOOKS_H_ #define _INCLUDE_SOURCEMOD_FRAME_HOOKS_H_ +typedef void (*FRAMEACTION)(void *data); + +struct FrameAction +{ + void *data; + FRAMEACTION action; +}; + extern bool g_PendingInternalPush; +void AddFrameAction(const FrameAction & action); void RunFrameHooks(bool simulating); #endif //_INCLUDE_SOURCEMOD_FRAME_HOOKS_H_ diff --git a/core/sm_globals.h b/core/sm_globals.h index 3365c25b..d13a71bf 100644 --- a/core/sm_globals.h +++ b/core/sm_globals.h @@ -134,6 +134,13 @@ public: { } + /** + * @brief Called when the level has activated. + */ + virtual void OnSourceModLevelActivated() + { + } + /** * @brief Called when the level ends. */ From ebed45a0f675f0460e1de77ab7d21d87bc2fa68d Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 28 Dec 2008 01:10:20 -0500 Subject: [PATCH 7/8] Fixed Linux build. --- core/GameDataFetcher.h | 1 - 1 file changed, 1 deletion(-) diff --git a/core/GameDataFetcher.h b/core/GameDataFetcher.h index e8a4a0b0..c397642f 100644 --- a/core/GameDataFetcher.h +++ b/core/GameDataFetcher.h @@ -100,7 +100,6 @@ private: short build[4]; }; -extern BuildMD5ableBuffer g_MD5Builder; extern bool g_blockGameDataLoad; #endif // _INCLUDE_SOURCEMOD_GAMEDATAFETCHER_H_ From 08e2fc8debb363388780e25d9b674aeb44f98ccb Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 28 Dec 2008 02:38:53 -0500 Subject: [PATCH 8/8] Support for 3-letter language codes (bug 3526, r=ds). --- core/Translator.cpp | 8 +++----- core/Translator.h | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/core/Translator.cpp b/core/Translator.cpp index 8aad2eeb..49f1e271 100644 --- a/core/Translator.cpp +++ b/core/Translator.cpp @@ -487,7 +487,7 @@ SMCResult CPhraseFile::ReadSMC_KeyValue(const SMCStates *states, const char *key else { size_t len = strlen(key); - if (len != 2) + if (len < 2 || len > 3) { ParseWarning("Ignoring translation to invalid language \"%s\" on line %d.", key, states->line); return SMCResult_Continue; @@ -936,7 +936,7 @@ SMCResult Translator::ReadSMC_KeyValue(const SMCStates *states, const char *key, { size_t len = strlen(key); - if (len != 2) + if (len < 2 || len > 3) { g_Logger.LogError("[SM] Warning encountered parsing languages.cfg file."); g_Logger.LogError("[SM] Invalid language code \"%s\" is being ignored.", key); @@ -957,9 +957,7 @@ bool Translator::AddLanguage(const char *langcode, const char *description) Language *pLanguage = new Language; unsigned int idx = m_Languages.size(); - pLanguage->m_code2[0] = langcode[0]; - pLanguage->m_code2[1] = langcode[1]; - pLanguage->m_code2[2] = langcode[2]; + UTIL_Format(pLanguage->m_code2, sizeof(pLanguage->m_code2), "%s", langcode); pLanguage->m_FullName = m_pStringTab->AddString(description); sm_trie_insert(m_pLCodeLookup, langcode, reinterpret_cast(idx)); diff --git a/core/Translator.h b/core/Translator.h index c003cf6a..25573918 100644 --- a/core/Translator.h +++ b/core/Translator.h @@ -57,7 +57,7 @@ enum PhraseParseState struct Language { - char m_code2[3]; + char m_code2[4]; int m_FullName; }; @@ -159,7 +159,7 @@ private: bool m_InLanguageSection; String m_CustomError; unsigned int m_ServerLang; - char m_InitialLang[3]; + char m_InitialLang[4]; }; /* Nice little wrapper to handle error logging and whatnot */