diff --git a/core/Database.cpp b/core/Database.cpp index 294f8c512..ae0e41b50 100644 --- a/core/Database.cpp +++ b/core/Database.cpp @@ -37,7 +37,7 @@ #include "Logger.h" #include "ExtensionSys.h" #include -#include "ThreadSupport.h" +#include #define DBPARSE_LEVEL_NONE 0 #define DBPARSE_LEVEL_MAIN 1 diff --git a/core/GameConfigs.h b/core/GameConfigs.h index 162a85f4d..6a1fb518b 100644 --- a/core/GameConfigs.h +++ b/core/GameConfigs.h @@ -39,7 +39,6 @@ #include "sm_globals.h" #include "sm_memtable.h" #include "sm_trie_tpl.h" -#include "ThreadSupport.h" using namespace SourceMod; using namespace SourceHook; diff --git a/core/Logger.cpp b/core/Logger.cpp index b22092589..f3a80f0db 100644 --- a/core/Logger.cpp +++ b/core/Logger.cpp @@ -1,8 +1,8 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 : * ============================================================================= * SourceMod - * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. + * Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved. * ============================================================================= * * This program is free software; you can redistribute it and/or modify it under @@ -378,6 +378,14 @@ print_error: } void Logger::LogError(const char *vafmt, ...) +{ + va_list ap; + va_start(ap, vafmt); + LogErrorEx(vafmt, ap); + va_end(ap); +} + +void Logger::LogErrorEx(const char *vafmt, va_list ap) { if (!m_Active) { @@ -408,10 +416,7 @@ void Logger::LogError(const char *vafmt, ...) fprintf(fp, "L %s: Info (map \"%s\") (file \"errors_%04d%02d%02d.log\")\n", date, m_CurMapName.c_str(), curtime->tm_year + 1900, curtime->tm_mon + 1, curtime->tm_mday); m_ErrMapStart = true; } - va_list ap; - va_start(ap, vafmt); LogToOpenFileEx(fp, vafmt, ap); - va_end(ap); fclose(fp); } else diff --git a/core/Logger.h b/core/Logger.h index a81d0daf2..86677e870 100644 --- a/core/Logger.h +++ b/core/Logger.h @@ -75,6 +75,7 @@ public: void DisableLogging(); void LogMessage(const char *msg, ...); void LogError(const char *msg, ...); + void LogErrorEx(const char *msg, va_list ap); void LogFatal(const char *msg, ...); void LogToOpenFile(FILE *fp, const char *msg, ...); void LogToOpenFileEx(FILE *fp, const char *msg, va_list ap); diff --git a/core/Makefile b/core/Makefile index 2ba4c8b89..9b0b36c69 100644 --- a/core/Makefile +++ b/core/Makefile @@ -14,19 +14,19 @@ MMSOURCE17 = ../../mmsource-1.7 OBJECTS = AdminCache.cpp CDataPack.cpp ConCmdManager.cpp ConVarManager.cpp CoreConfig.cpp \ Database.cpp DebugReporter.cpp EventManager.cpp GameConfigs.cpp HalfLife2.cpp Logger.cpp \ - MemoryUtils.cpp PlayerManager.cpp TextParsers.cpp TimerSys.cpp Translator.cpp UserMessages.cpp \ + MemoryUtils.cpp PlayerManager.cpp TimerSys.cpp Translator.cpp UserMessages.cpp \ sm_autonatives.cpp sm_memtable.cpp sm_srvcmds.cpp sm_stringutil.cpp sm_trie.cpp \ sourcemm_api.cpp sourcemod.cpp MenuStyle_Base.cpp MenuStyle_Valve.cpp MenuManager.cpp \ MenuStyle_Radio.cpp ChatTriggers.cpp ADTFactory.cpp MenuVoting.cpp sm_crc32.cpp \ frame_hooks.cpp concmd_cleaner.cpp Profiler.cpp PhraseCollection.cpp NextMap.cpp \ - NativeOwner.cpp + NativeOwner.cpp logic_bridge.cpp OBJECTS += smn_admin.cpp smn_bitbuffer.cpp smn_console.cpp smn_core.cpp \ smn_datapacks.cpp smn_entities.cpp smn_events.cpp smn_fakenatives.cpp \ - smn_filesystem.cpp smn_float.cpp smn_functions.cpp smn_gameconfigs.cpp smn_halflife.cpp \ - smn_handles.cpp smn_keyvalues.cpp smn_banning.cpp smn_maplists.cpp \ - smn_lang.cpp smn_player.cpp smn_string.cpp smn_sorting.cpp smn_textparse.cpp smn_timers.cpp \ - smn_usermsgs.cpp smn_menus.cpp smn_database.cpp smn_vector.cpp smn_adt_array.cpp \ - smn_adt_trie.cpp smn_hudtext.cpp smn_adt_stack.cpp smn_nextmap.cpp + smn_filesystem.cpp smn_functions.cpp smn_gameconfigs.cpp smn_halflife.cpp \ + smn_handles.cpp smn_keyvalues.cpp smn_banning.cpp \ + smn_lang.cpp smn_player.cpp smn_string.cpp smn_timers.cpp \ + smn_usermsgs.cpp smn_menus.cpp smn_database.cpp smn_vector.cpp \ + smn_adt_trie.cpp smn_hudtext.cpp smn_nextmap.cpp OBJECTS += ExtensionSys.cpp \ ForwardSys.cpp \ HandleSys.cpp \ @@ -35,7 +35,6 @@ OBJECTS += ExtensionSys.cpp \ PluginSys.cpp \ ShareSys.cpp \ NativeInvoker.cpp -OBJECTS += thread/ThreadWorker.cpp thread/BaseWorker.cpp thread/PosixThreads.cpp ThreadSupport.cpp ############################################## ### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ### @@ -85,7 +84,7 @@ endif CFLAGS += -DSE_EPISODEONE=1 -DSE_DARKMESSIAH=2 -DSE_ORANGEBOX=3 -DSE_LEFT4DEAD=4 LINK += $(HL2LIB)/tier1_i486.a $(HL2LIB)/mathlib_i486.a vstdlib_i486.so \ - tier0_i486.so -lpthread -static-libgcc + tier0_i486.so -static-libgcc INCLUDE += -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/mathlib -I$(HL2PUB)/vstdlib \ -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 -I$(METAMOD) -I$(METAMOD)/sourcehook \ @@ -124,8 +123,6 @@ $(BIN_DIR)/%.o: %.c $(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< all: check - mkdir -p $(BIN_DIR)/systems - mkdir -p $(BIN_DIR)/thread ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so; ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so; $(MAKE) -f Makefile sourcemod @@ -146,6 +143,5 @@ default: all clean: check rm -rf $(BIN_DIR)/*.o - rm -rf $(BIN_DIR)/systems/*.o rm -rf $(BIN_DIR)/thread/*.o rm -rf $(BIN_DIR)/$(BINARY) diff --git a/core/PluginSys.cpp b/core/PluginSys.cpp index 81bbd8321..453cae090 100644 --- a/core/PluginSys.cpp +++ b/core/PluginSys.cpp @@ -37,7 +37,6 @@ #include "ForwardSys.h" #include "sourcemm_api.h" #include "sourcemod.h" -#include "TextParsers.h" #include "Logger.h" #include "ExtensionSys.h" #include "sm_srvcmds.h" diff --git a/core/frame_hooks.cpp b/core/frame_hooks.cpp index 2410ca2f8..2c8c03a0f 100644 --- a/core/frame_hooks.cpp +++ b/core/frame_hooks.cpp @@ -37,7 +37,7 @@ #include "PlayerManager.h" #include "CoreConfig.h" #include -#include "ThreadSupport.h" +#include static IMutex *frame_mutex; static Queue *frame_queue; diff --git a/core/CellArray.h b/core/logic/CellArray.h similarity index 93% rename from core/CellArray.h rename to core/logic/CellArray.h index 5aa4332f5..ee9a1fc7e 100644 --- a/core/CellArray.h +++ b/core/logic/CellArray.h @@ -29,6 +29,9 @@ * Version: $Id$ */ +#ifndef _INCLUDE_SOURCEMOD_CELLARRAY_H_ +#define _INCLUDE_SOURCEMOD_CELLARRAY_H_ + #include #include @@ -204,3 +207,6 @@ private: size_t m_AllocSize; size_t m_Size; }; + +#endif /* _INCLUDE_SOURCEMOD_CELLARRAY_H_ */ + diff --git a/core/logic/Makefile b/core/logic/Makefile new file mode 100644 index 000000000..b235f975a --- /dev/null +++ b/core/logic/Makefile @@ -0,0 +1,89 @@ +# (C)2004-2008 SourceMod Development Team +# Makefile written by David "BAILOPAN" Anderson + +SMSDK = ../.. +MMSOURCE17 = ../../../mmsource-1.7 + +##################################### +### EDIT BELOW FOR OTHER PROJECTS ### +##################################### + +BINARY = sourcemod.logic.so + +OBJECTS = \ + common_logic.cpp \ + smn_adt_array.cpp \ + smn_sorting.cpp \ + smn_maplists.cpp \ + smn_adt_stack.cpp \ + thread/ThreadWorker.cpp \ + thread/BaseWorker.cpp \ + thread/PosixThreads.cpp \ + ThreadSupport.cpp \ + smn_float.cpp \ + TextParsers.cpp \ + smn_textparse.cpp + +############################################## +### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ### +############################################## + +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 + +LINK += -lpthread -static-libgcc + +INCLUDE += -I. -I$(MMSOURCE17)/core/sourcehook -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn + +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-uninitialized -mfpmath=sse -msse -DSOURCEMOD_BUILD -DHAVE_STDINT_H -DSM_DEFAULT_THREADER -m32 \ + -DSM_LOGIC +CPPFLAGS += -Wno-non-virtual-dtor -fno-exceptions -fno-rtti + +################################################ +### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ### +################################################ + +ifeq "$(DEBUG)" "true" + BIN_DIR = Debug + CFLAGS += $(C_DEBUG_FLAGS) +else + BIN_DIR = Release + CFLAGS += $(C_OPT_FLAGS) +endif + +GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) +ifeq "$(GCC_VERSION)" "4" + CFLAGS += $(C_GCC4_FLAGS) + CPPFLAGS += $(CPP_GCC4_FLAGS) +endif + +OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) +OBJ_LINUX := $(OBJ_LINUX:%.c=$(BIN_DIR)/%.o) + +$(BIN_DIR)/%.o: %.cpp + $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< + +$(BIN_DIR)/%.o: %.c + $(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< + +all: + mkdir -p $(BIN_DIR)/thread + $(MAKE) -f Makefile sourcemod + +sourcemod: $(OBJ_LINUX) + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o $(BIN_DIR)/$(BINARY) + +debug: + $(MAKE) -f Makefile all DEBUG=true + +default: all + +clean: + rm -rf $(BIN_DIR)/*.o + rm -rf $(BIN_DIR)/thread/*.o + rm -rf $(BIN_DIR)/$(BINARY) diff --git a/core/TextParsers.cpp b/core/logic/TextParsers.cpp similarity index 94% rename from core/TextParsers.cpp rename to core/logic/TextParsers.cpp index 87b683116..0be662456 100644 --- a/core/TextParsers.cpp +++ b/core/logic/TextParsers.cpp @@ -36,9 +36,7 @@ #include #include #include "TextParsers.h" -#include "ShareSys.h" -#include "sm_stringutil.h" -#include "LibrarySys.h" +#include TextParsers g_TextParser; ITextParsers *textparsers = &g_TextParser; @@ -71,7 +69,7 @@ TextParsers::TextParsers() void TextParsers::OnSourceModAllInitialized() { - g_ShareSys.AddInterface(NULL, this); + sharesys->AddInterface(NULL, this); } unsigned int TextParsers::GetUTF8CharBytes(const char *stream) @@ -135,8 +133,8 @@ SMCError TextParsers::ParseSMCFile(const char *file, states->line = 0; states->col = 0; } - g_LibSys.GetPlatformError(error, sizeof(error)); - UTIL_Format(buffer, maxsize, "File could not be opened: %s", error); + libsys->GetPlatformError(error, sizeof(error)); + smcore.Format(buffer, maxsize, "File could not be opened: %s", error); return SMCError_StreamOpen; } @@ -145,7 +143,7 @@ SMCError TextParsers::ParseSMCFile(const char *file, fclose(fp); errstr = GetSMCErrorString(result); - UTIL_Format(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error"); + smcore.Format(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error"); return result; } @@ -196,7 +194,7 @@ SMCError TextParsers::ParseSMCStream(const char *stream, result = ParseStream_SMC(&rs, RawStreamReader, smc_listener, states); const char *errstr = GetSMCErrorString(result); - UTIL_Format(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error"); + smcore.Format(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error"); return result; } diff --git a/core/TextParsers.h b/core/logic/TextParsers.h similarity index 96% rename from core/TextParsers.h rename to core/logic/TextParsers.h index ca8633957..99cecff7c 100644 --- a/core/TextParsers.h +++ b/core/logic/TextParsers.h @@ -33,7 +33,7 @@ #define _INCLUDE_SOURCEMOD_TEXTPARSERS_H_ #include -#include "sm_globals.h" +#include "common_logic.h" using namespace SourceMod; diff --git a/core/ThreadSupport.cpp b/core/logic/ThreadSupport.cpp similarity index 88% rename from core/ThreadSupport.cpp rename to core/logic/ThreadSupport.cpp index a8f1cc19e..55fd03275 100644 --- a/core/ThreadSupport.cpp +++ b/core/logic/ThreadSupport.cpp @@ -1,8 +1,8 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 : * ============================================================================= * SourceMod - * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. + * Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved. * ============================================================================= * * This program is free software; you can redistribute it and/or modify it under @@ -28,10 +28,9 @@ * * Version: $Id$ */ - +#include #include "ThreadSupport.h" -#include "sm_globals.h" -#include "ShareSys.h" +#include "common_logic.h" #if defined PLATFORM_POSIX #include "thread/PosixThreads.h" @@ -47,6 +46,7 @@ class RegThreadStuff : public SMGlobalClass public: void OnSourceModAllInitialized() { - g_ShareSys.AddInterface(NULL, g_pThreader); + sharesys->AddInterface(NULL, g_pThreader); } } s_RegThreadStuff; + diff --git a/core/ThreadSupport.h b/core/logic/ThreadSupport.h similarity index 100% rename from core/ThreadSupport.h rename to core/logic/ThreadSupport.h diff --git a/core/logic/common_logic.cpp b/core/logic/common_logic.cpp new file mode 100644 index 000000000..7a75fe739 --- /dev/null +++ b/core/logic/common_logic.cpp @@ -0,0 +1,116 @@ +/** + * vim: set ts=4 sw=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 +#include +#include +#include +#include "common_logic.h" +#include "ThreadSupport.h" +#include "TextParsers.h" + +sm_core_t smcore; +IHandleSys *handlesys; +IdentityToken_t *g_pCoreIdent; +SMGlobalClass *SMGlobalClass::head = NULL; +ISourceMod *g_pSM; +ILibrarySys *libsys; +ITextParsers *textparser = &g_TextParser; +IVEngineServer *engine; +IShareSys *sharesys; + +static sm_logic_t logic = +{ + NULL, + g_pThreader +}; + +static void logic_init(const sm_core_t* core, sm_logic_t* _logic) +{ + logic.head = SMGlobalClass::head; + + memcpy(&smcore, core, sizeof(sm_core_t)); + memcpy(_logic, &logic, sizeof(sm_logic_t)); + + handlesys = core->handlesys; + libsys = core->libsys; + engine = core->engine; + g_pCoreIdent = core->core_ident; + g_pSM = core->sm; + sharesys = core->sharesys; +} + +PLATFORM_EXTERN_C ITextParsers *get_textparsers() +{ + return &g_TextParser; +} + +PLATFORM_EXTERN_C LogicInitFunction logic_load(uint32_t magic) +{ + if (magic != SM_LOGIC_MAGIC) + { + return NULL; + } + + return logic_init; +} + +void CoreNativesToAdd::OnSourceModAllInitialized() +{ + smcore.AddNatives(m_NativeList); +} + +/* Overload a few things to prevent libstdc++ linking */ +#if defined __linux__ || defined __APPLE__ +extern "C" void __cxa_pure_virtual(void) +{ +} + +void *operator new(size_t size) +{ + return malloc(size); +} + +void *operator new[](size_t size) +{ + return malloc(size); +} + +void operator delete(void *ptr) +{ + free(ptr); +} + +void operator delete[](void * ptr) +{ + free(ptr); +} +#endif + diff --git a/core/logic/common_logic.h b/core/logic/common_logic.h new file mode 100644 index 000000000..5084acda2 --- /dev/null +++ b/core/logic/common_logic.h @@ -0,0 +1,49 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod + * Copyright (C) 2004-2009 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_COMMON_LOGIC_H_ +#define _INCLUDE_SOURCEMOD_COMMON_LOGIC_H_ + +#include + +#include "../sm_globals.h" +#include "intercom.h" + +extern sm_core_t smcore; +extern IHandleSys *handlesys; +extern ISourceMod *g_pSM; +extern ILibrarySys *libsys; +extern ITextParsers *textparser; +extern IVEngineServer *engine; +extern IShareSys *sharesys; + +#endif /* _INCLUDE_SOURCEMOD_COMMON_LOGIC_H_ */ + diff --git a/core/logic/intercom.h b/core/logic/intercom.h new file mode 100644 index 000000000..f9e805224 --- /dev/null +++ b/core/logic/intercom.h @@ -0,0 +1,98 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod + * Copyright (C) 2004-2009 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 +#include +#include + +#ifndef _INCLUDE_SOURCEMOD_INTERCOM_H_ +#define _INCLUDE_SOURCEMOD_INTERCOM_H_ + +using namespace SourceMod; + +/** + * Add 1 to the RHS of this expression to bump the intercom file + * This is to prevent mismatching core/logic binaries + */ +#define SM_LOGIC_MAGIC (0x0F47C0DE - 0) + +#if defined SM_LOGIC +class IVEngineServer +#else +class IVEngineServer_Logic +#endif +{ +public: + virtual bool IsMapValid(const char *map) = 0; +}; + +namespace SourceMod +{ + class ISourceMod; + class ILibrarySys; + class ITextParsers; + class IThreader; +} + +class IVEngineServer; +class ConVar; + +struct sm_core_t +{ + /* Objects */ + IHandleSys *handlesys; + IdentityToken_t *core_ident; + ISourceMod *sm; + ILibrarySys *libsys; + IVEngineServer *engine; + IShareSys *sharesys; + /* Functions */ + void (*AddNatives)(sp_nativeinfo_t* nlist); + ConVar * (*FindConVar)(const char*); + unsigned int (*strncopy)(char*, const char*, size_t); + char * (*TrimWhitespace)(char *, size_t &); + void (*LogError)(const char*, ...); + const char * (*GetCvarString)(ConVar*); + size_t (*Format)(char*, size_t, const char*, ...); +}; + +struct sm_logic_t +{ + SMGlobalClass *head; + IThreader *threader; +}; + +typedef void (*LogicInitFunction)(const sm_core_t *core, sm_logic_t *logic); +typedef LogicInitFunction (*LogicLoadFunction)(uint32_t magic); +typedef ITextParsers *(*GetITextParsers)(); + +#endif /* _INCLUDE_SOURCEMOD_INTERCOM_H_ */ + diff --git a/core/logic/msvc9/logic.sln b/core/logic/msvc9/logic.sln new file mode 100755 index 000000000..1977332d5 --- /dev/null +++ b/core/logic/msvc9/logic.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "logic", "logic.vcproj", "{6EF06E6E-0ED5-4E2D-A8F3-01DD1EC25BA7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6EF06E6E-0ED5-4E2D-A8F3-01DD1EC25BA7}.Debug|Win32.ActiveCfg = Debug|Win32 + {6EF06E6E-0ED5-4E2D-A8F3-01DD1EC25BA7}.Debug|Win32.Build.0 = Debug|Win32 + {6EF06E6E-0ED5-4E2D-A8F3-01DD1EC25BA7}.Release|Win32.ActiveCfg = Release|Win32 + {6EF06E6E-0ED5-4E2D-A8F3-01DD1EC25BA7}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/core/logic/msvc9/logic.vcproj b/core/logic/msvc9/logic.vcproj new file mode 100755 index 000000000..59367acb2 --- /dev/null +++ b/core/logic/msvc9/logic.vcproj @@ -0,0 +1,307 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/smn_adt_array.cpp b/core/logic/smn_adt_array.cpp similarity index 83% rename from core/smn_adt_array.cpp rename to core/logic/smn_adt_array.cpp index a03309bb3..3b367241e 100644 --- a/core/smn_adt_array.cpp +++ b/core/logic/smn_adt_array.cpp @@ -30,10 +30,8 @@ */ #include -#include "sm_globals.h" -#include "sm_stringutil.h" +#include "common_logic.h" #include "CellArray.h" -#include "HandleSys.h" HandleType_t htCellArray; @@ -44,11 +42,11 @@ class CellArrayHelpers : public: //SMGlobalClass void OnSourceModAllInitialized() { - htCellArray = g_HandleSys.CreateType("CellArray", this, 0, NULL, NULL, g_pCoreIdent, NULL); + htCellArray = handlesys->CreateType("CellArray", this, 0, NULL, NULL, g_pCoreIdent, NULL); } void OnSourceModShutdown() { - g_HandleSys.RemoveType(htCellArray, g_pCoreIdent); + handlesys->RemoveType(htCellArray, g_pCoreIdent); } public: //IHandleTypeDispatch void OnHandleDestroy(HandleType_t type, void *object) @@ -78,7 +76,7 @@ static cell_t CreateArray(IPluginContext *pContext, const cell_t *params) array->resize(params[2]); } - Handle_t hndl = g_HandleSys.CreateHandle(htCellArray, array, pContext->GetIdentity(), g_pCoreIdent, NULL); + Handle_t hndl = handlesys->CreateHandle(htCellArray, array, pContext->GetIdentity(), g_pCoreIdent, NULL); if (!hndl) { delete array; @@ -93,7 +91,7 @@ static cell_t ClearArray(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -110,7 +108,7 @@ static cell_t ResizeArray(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -130,7 +128,7 @@ static cell_t GetArraySize(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -145,7 +143,7 @@ static cell_t PushArrayCell(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -168,7 +166,7 @@ static cell_t PushArrayString(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -183,7 +181,7 @@ static cell_t PushArrayString(IPluginContext *pContext, const cell_t *params) char *str; pContext->LocalToString(params[2], &str); - strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t)); + smcore.strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t)); return (cell_t)(array->size() - 1); } @@ -194,7 +192,7 @@ static cell_t PushArrayArray(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -226,7 +224,7 @@ static cell_t GetArrayCell(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -265,7 +263,7 @@ static cell_t GetArrayString(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -291,7 +289,7 @@ static cell_t GetArrayArray(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -324,7 +322,7 @@ static cell_t SetArrayCell(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -363,7 +361,7 @@ static cell_t SetArrayString(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -380,7 +378,7 @@ static cell_t SetArrayString(IPluginContext *pContext, const cell_t *params) char *str; pContext->LocalToString(params[3], &str); - return strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t)); + return smcore.strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t)); } static cell_t SetArrayArray(IPluginContext *pContext, const cell_t *params) @@ -389,7 +387,7 @@ static cell_t SetArrayArray(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -422,7 +420,7 @@ static cell_t ShiftArrayUp(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -445,7 +443,7 @@ static cell_t RemoveFromArray(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -468,7 +466,7 @@ static cell_t SwapArrayItems(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -496,7 +494,7 @@ static cell_t CloneArray(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&oldArray)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&oldArray)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -504,7 +502,7 @@ static cell_t CloneArray(IPluginContext *pContext, const cell_t *params) CellArray *array = oldArray->clone(); - Handle_t hndl = g_HandleSys.CreateHandle(htCellArray, array, pContext->GetIdentity(), g_pCoreIdent, NULL); + Handle_t hndl = handlesys->CreateHandle(htCellArray, array, pContext->GetIdentity(), g_pCoreIdent, NULL); if (!hndl) { delete array; @@ -519,7 +517,7 @@ static cell_t FindStringInArray(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -546,7 +544,7 @@ static cell_t FindValueInArray(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); diff --git a/core/smn_adt_stack.cpp b/core/logic/smn_adt_stack.cpp similarity index 84% rename from core/smn_adt_stack.cpp rename to core/logic/smn_adt_stack.cpp index 5fd1db798..085b4b0f8 100644 --- a/core/smn_adt_stack.cpp +++ b/core/logic/smn_adt_stack.cpp @@ -30,10 +30,8 @@ */ #include -#include "sm_globals.h" -#include "sm_stringutil.h" +#include "common_logic.h" #include "CellArray.h" -#include "HandleSys.h" HandleType_t htCellStack; @@ -44,11 +42,11 @@ class CellStackHelpers : public: //SMGlobalClass void OnSourceModAllInitialized() { - htCellStack = g_HandleSys.CreateType("CellStack", this, 0, NULL, NULL, g_pCoreIdent, NULL); + htCellStack = handlesys->CreateType("CellStack", this, 0, NULL, NULL, g_pCoreIdent, NULL); } void OnSourceModShutdown() { - g_HandleSys.RemoveType(htCellStack, g_pCoreIdent); + handlesys->RemoveType(htCellStack, g_pCoreIdent); } public: //IHandleTypeDispatch void OnHandleDestroy(HandleType_t type, void *object) @@ -73,7 +71,7 @@ static cell_t CreateStack(IPluginContext *pContext, const cell_t *params) CellArray *array = new CellArray(params[1]); - Handle_t hndl = g_HandleSys.CreateHandle(htCellStack, array, pContext->GetIdentity(), g_pCoreIdent, NULL); + Handle_t hndl = handlesys->CreateHandle(htCellStack, array, pContext->GetIdentity(), g_pCoreIdent, NULL); if (!hndl) { delete array; @@ -88,7 +86,7 @@ static cell_t PushStackCell(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellStack, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -111,7 +109,7 @@ static cell_t PushStackString(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellStack, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -126,7 +124,7 @@ static cell_t PushStackString(IPluginContext *pContext, const cell_t *params) char *str; pContext->LocalToString(params[2], &str); - strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t)); + smcore.strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t)); return 1; } @@ -137,7 +135,7 @@ static cell_t PushStackArray(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellStack, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -171,7 +169,7 @@ static cell_t PopStackCell(IPluginContext *pContext, const cell_t *params) cell_t *blk, *buffer; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellStack, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -217,7 +215,7 @@ static cell_t PopStackString(IPluginContext *pContext, const cell_t *params) cell_t *blk, *pWritten; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellStack, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -248,7 +246,7 @@ static cell_t PopStackArray(IPluginContext *pContext, const cell_t *params) CellArray *array; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellStack, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -281,7 +279,7 @@ static cell_t IsStackEmpty(IPluginContext *pContext, const cell_t *params) CellArray *array; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellStack, &sec, (void **)&array)) + if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); diff --git a/core/smn_float.cpp b/core/logic/smn_float.cpp similarity index 95% rename from core/smn_float.cpp rename to core/logic/smn_float.cpp index a13cd26fa..8e95025c0 100644 --- a/core/smn_float.cpp +++ b/core/logic/smn_float.cpp @@ -32,7 +32,7 @@ #include #include #include -#include "sm_globals.h" +#include "common_logic.h" /**************************************** * * diff --git a/core/smn_maplists.cpp b/core/logic/smn_maplists.cpp similarity index 82% rename from core/smn_maplists.cpp rename to core/logic/smn_maplists.cpp index 39f7a51dc..a35c6e8c3 100644 --- a/core/smn_maplists.cpp +++ b/core/logic/smn_maplists.cpp @@ -30,17 +30,12 @@ */ #include -#include "sm_globals.h" -#include "sm_trie_tpl.h" +#include +#include "common_logic.h" #include "CellArray.h" -#include "convar.h" -#include "sourcemm_api.h" -#include "LibrarySys.h" -#include "TextParsers.h" -#include "sm_stringutil.h" -#include "sourcemod.h" -#include "Logger.h" -#include "HandleSys.h" +#include +#include +#include using namespace SourceHook; @@ -77,7 +72,7 @@ public: } void OnSourceModAllInitialized() { - g_SourceMod.BuildPath(Path_SM, m_ConfigFile, sizeof(m_ConfigFile), "configs/maplists.cfg"); + g_pSM->BuildPath(Path_SM, m_ConfigFile, sizeof(m_ConfigFile), "configs/maplists.cfg"); } void OnSourceModShutdown() { @@ -94,13 +89,9 @@ public: pMapList->bIsCompat = true; pMapList->bIsPath = true; pMapList->last_modified_time = 0; - strncopy(pMapList->name, name, sizeof(pMapList->name)); + smcore.strncopy(pMapList->name, name, sizeof(pMapList->name)); pMapList->pArray = NULL; - g_SourceMod.BuildPath(Path_Game, - pMapList->path, - sizeof(pMapList->path), - "%s", - file); + g_pSM->BuildPath(Path_Game, pMapList->path, sizeof(pMapList->path), "%s", file); pMapList->serial = 0; m_ListLookup.insert(name, pMapList); m_MapLists.push_back(pMapList); @@ -115,11 +106,7 @@ public: return; } - g_SourceMod.BuildPath(Path_Game, - path, - sizeof(path), - "%s", - file); + g_pSM->BuildPath(Path_Game, path, sizeof(path), "%s", file); /* If the path matches, don't reset the serial/time */ if (strcmp(path, pMapList->path) == 0) @@ -127,7 +114,7 @@ public: return; } - strncopy(pMapList->path, path, sizeof(pMapList->path)); + smcore.strncopy(pMapList->path, path, sizeof(pMapList->path)); pMapList->bIsPath = true; pMapList->last_modified_time = 0; pMapList->serial = 0; @@ -139,7 +126,7 @@ public: time_t fileTime; SMCStates states = {0, 0}; - fileFound = g_LibSys.FileTime(m_ConfigFile, FileTime_LastChange, &fileTime); + fileFound = libsys->FileTime(m_ConfigFile, FileTime_LastChange, &fileTime); /* If the file is found and hasn't changed, bail out now. */ if (fileFound && fileTime == m_ConfigLastChanged) @@ -156,7 +143,7 @@ public: return; } - m_pMapCycleFile = icvar->FindVar("mapcyclefile"); + m_pMapCycleFile = smcore.FindConVar("mapcyclefile"); /* Dump everything we know about. */ List compat; @@ -166,12 +153,12 @@ public: maplist_info_t *pDefList = new maplist_info_t; pDefList->bIsPath = true; - strncopy(pDefList->name, "mapcyclefile", sizeof(pDefList->name)); - g_SourceMod.BuildPath(Path_Game, + smcore.strncopy(pDefList->name, "mapcyclefile", sizeof(pDefList->name)); + g_pSM->BuildPath(Path_Game, pDefList->path, sizeof(pDefList->path), "%s", - m_pMapCycleFile ? m_pMapCycleFile->GetString() : "mapcycle.txt"); + m_pMapCycleFile ? smcore.GetCvarString(m_pMapCycleFile) : "mapcycle.txt"); pDefList->last_modified_time = 0; pDefList->pArray = NULL; pDefList->serial = 0; @@ -182,19 +169,16 @@ public: /* Now parse the config file even if we don't know about it. * This will give us a nice error message. */ - if ((error = g_TextParser.ParseFile_SMC(m_ConfigFile, this, &states)) + if ((error = textparser->ParseFile_SMC(m_ConfigFile, this, &states)) != SMCError_Okay) { - const char *errmsg = g_TextParser.GetSMCErrorString(error); + const char *errmsg = textparser->GetSMCErrorString(error); if (errmsg == NULL) { errmsg = "Unknown error"; } - g_Logger.LogError("[SM] Could not parse file \"%s\"", m_ConfigFile); - g_Logger.LogError("[SM] Error on line %d (col %d): %s", - states.line, - states.col, - errmsg); + smcore.LogError("[SM] Could not parse file \"%s\"", m_ConfigFile); + smcore.LogError("[SM] Error on line %d (col %d): %s", states.line, states.col, errmsg); } else { @@ -249,7 +233,7 @@ public: m_pCurMapList = new maplist_info_t; memset(m_pCurMapList, 0, sizeof(maplist_info_t)); - strncopy(m_pCurMapList->name, name, sizeof(m_pCurMapList->name)); + smcore.strncopy(m_pCurMapList->name, name, sizeof(m_pCurMapList->name)); m_CurState = MPS_MAPLIST; } @@ -269,7 +253,7 @@ public: if (strcmp(key, "file") == 0) { - g_SourceMod.BuildPath(Path_Game, + g_pSM->BuildPath(Path_Game, m_pCurMapList->path, sizeof(m_pCurMapList->path), "%s", @@ -278,7 +262,7 @@ public: } else if (strcmp(key, "target") == 0) { - strncopy(m_pCurMapList->path, value, sizeof(m_pCurMapList->path)); + smcore.strncopy(m_pCurMapList->path, value, sizeof(m_pCurMapList->path)); m_pCurMapList->bIsPath = false; } @@ -369,9 +353,9 @@ public: pNewArray = new CellArray(64); free_new_array = true; - g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "maps"); + g_pSM->BuildPath(Path_Game, path, sizeof(path), "maps"); - if ((pDir = g_LibSys.OpenDirectory(path)) != NULL) + if ((pDir = libsys->OpenDirectory(path)) != NULL) { char *ptr; cell_t *blk; @@ -386,7 +370,7 @@ public: pDir->NextEntry(); continue; } - strncopy(buffer, pDir->GetEntryName(), sizeof(buffer)); + smcore.strncopy(buffer, pDir->GetEntryName(), sizeof(buffer)); if ((ptr = strstr(buffer, ".bsp")) == NULL || ptr[4] != '\0') { pDir->NextEntry(); @@ -403,10 +387,10 @@ public: pDir->NextEntry(); continue; } - strncopy((char *)blk, buffer, 255); + smcore.strncopy((char *)blk, buffer, 255); pDir->NextEntry(); } - g_LibSys.CloseDirectory(pDir); + libsys->CloseDirectory(pDir); } /* Remove the array if there were no items. */ @@ -461,7 +445,7 @@ public: { blk_dst = pUseArray->push(); blk_src = pNewArray->at(i); - strncopy((char *)blk_dst, (char *)blk_src, pUseArray->blocksize() * sizeof(cell_t)); + smcore.strncopy((char *)blk_dst, (char *)blk_src, pUseArray->blocksize() * sizeof(cell_t)); } /* Free resources if necessary. */ @@ -501,20 +485,20 @@ private: if (m_pMapCycleFile != NULL && strcmp(name, "mapcyclefile") == 0) { char path[PLATFORM_MAX_PATH]; - g_SourceMod.BuildPath(Path_Game, + g_pSM->BuildPath(Path_Game, path, sizeof(path), "%s", - m_pMapCycleFile ? m_pMapCycleFile->GetString() : "mapcycle.txt"); + m_pMapCycleFile ? smcore.GetCvarString(m_pMapCycleFile) : "mapcycle.txt"); if (strcmp(path, pMapList->path) != 0) { - strncopy(pMapList->path, path, sizeof(pMapList->path)); + smcore.strncopy(pMapList->path, path, sizeof(pMapList->path)); pMapList->last_modified_time = 0; } } - if (!g_LibSys.FileTime(pMapList->path, FileTime_LastChange, &last_time) + if (!libsys->FileTime(pMapList->path, FileTime_LastChange, &last_time) || last_time > pMapList->last_modified_time) { /* Reparse */ @@ -533,7 +517,7 @@ private: while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL) { size_t len = strlen(buffer); - char *ptr = UTIL_TrimWhitespace(buffer, len); + char *ptr = smcore.TrimWhitespace(buffer, len); if (*ptr == '\0' || *ptr == ';' || strncmp(ptr, "//", 2) == 0) @@ -546,7 +530,7 @@ private: } if ((blk = pMapList->pArray->push()) != NULL) { - strncopy((char *)blk, ptr, 255); + smcore.strncopy((char *)blk, ptr, 255); } } @@ -616,7 +600,7 @@ static cell_t LoadMapList(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(hndl, htCellArray, &sec, (void **)&pArray)) + if ((err = handlesys->ReadHandle(hndl, htCellArray, &sec, (void **)&pArray)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); @@ -635,7 +619,7 @@ static cell_t LoadMapList(IPluginContext *pContext, const cell_t *params) /* If the user wanted a new array, create it now. */ if (hndl == BAD_HANDLE) { - if ((hndl = g_HandleSys.CreateHandle(htCellArray, pNewArray, pContext->GetIdentity(), g_pCoreIdent, NULL)) + if ((hndl = handlesys->CreateHandle(htCellArray, pNewArray, pContext->GetIdentity(), g_pCoreIdent, NULL)) == BAD_HANDLE) { *addr = -1; diff --git a/core/smn_sorting.cpp b/core/logic/smn_sorting.cpp similarity index 94% rename from core/smn_sorting.cpp rename to core/logic/smn_sorting.cpp index 7dcdb82bb..59856cf0d 100644 --- a/core/smn_sorting.cpp +++ b/core/logic/smn_sorting.cpp @@ -29,11 +29,10 @@ * Version: $Id$ */ -#include "sm_globals.h" -#include #include #include -#include "HandleSys.h" +#include +#include "common_logic.h" #include "CellArray.h" /*********************************** @@ -448,7 +447,7 @@ static cell_t sm_SortADTArray(IPluginContext *pContext, const cell_t *params) HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&cArray)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&cArray)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); @@ -535,7 +534,7 @@ static cell_t sm_SortADTArrayCustom(IPluginContext *pContext, const cell_t *para HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); - if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&cArray)) + if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&cArray)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); diff --git a/core/smn_textparse.cpp b/core/logic/smn_textparse.cpp similarity index 86% rename from core/smn_textparse.cpp rename to core/logic/smn_textparse.cpp index 2a989ed4a..78f043d84 100644 --- a/core/smn_textparse.cpp +++ b/core/logic/smn_textparse.cpp @@ -29,9 +29,9 @@ * Version: $Id$ */ -#include "sm_globals.h" +#include "common_logic.h" #include -#include "HandleSys.h" +#include HandleType_t g_TypeSMC = 0; @@ -152,16 +152,16 @@ public: /* These cannot be cloned, because they are locked to a specific plugin. * However, we let anyone read them because we don't care. */ - g_HandleSys.InitAccessDefaults(NULL, &sec); + handlesys->InitAccessDefaults(NULL, &sec); sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY; sec.access[HandleAccess_Read] = 0; - g_TypeSMC = g_HandleSys.CreateType("SMCParser", this, 0, NULL, &sec, g_pCoreIdent, NULL); + g_TypeSMC = handlesys->CreateType("SMCParser", this, 0, NULL, &sec, g_pCoreIdent, NULL); } void OnSourceModShutdown() { - g_HandleSys.RemoveType(g_TypeSMC, g_pCoreIdent); + handlesys->RemoveType(g_TypeSMC, g_pCoreIdent); } void OnHandleDestroy(HandleType_t type, void *object) @@ -183,7 +183,7 @@ static cell_t SMC_CreateParser(IPluginContext *pContext, const cell_t *params) { ParseInfo *pInfo = new ParseInfo(); - Handle_t hndl = g_HandleSys.CreateHandle(g_TypeSMC, pInfo, pContext->GetIdentity(), g_pCoreIdent, NULL); + Handle_t hndl = handlesys->CreateHandle(g_TypeSMC, pInfo, pContext->GetIdentity(), g_pCoreIdent, NULL); /* Should never happen */ if (!hndl) @@ -203,7 +203,7 @@ static cell_t SMC_SetParseStart(IPluginContext *pContext, const cell_t *params) HandleError err; ParseInfo *parse; - if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse)) + if ((err=handlesys->ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse)) != HandleError_None) { return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err); @@ -220,7 +220,7 @@ static cell_t SMC_SetParseEnd(IPluginContext *pContext, const cell_t *params) HandleError err; ParseInfo *parse; - if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse)) + if ((err=handlesys->ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse)) != HandleError_None) { return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err); @@ -237,7 +237,7 @@ static cell_t SMC_SetReaders(IPluginContext *pContext, const cell_t *params) HandleError err; ParseInfo *parse; - if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse)) + if ((err=handlesys->ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse)) != HandleError_None) { return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err); @@ -256,7 +256,7 @@ static cell_t SMC_SetRawLine(IPluginContext *pContext, const cell_t *params) HandleError err; ParseInfo *parse; - if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse)) + if ((err=handlesys->ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse)) != HandleError_None) { return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err); @@ -273,7 +273,7 @@ static cell_t SMC_ParseFile(IPluginContext *pContext, const cell_t *params) HandleError err; ParseInfo *parse; - if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse)) + if ((err=handlesys->ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse)) != HandleError_None) { return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err); @@ -283,7 +283,7 @@ static cell_t SMC_ParseFile(IPluginContext *pContext, const cell_t *params) pContext->LocalToString(params[2], &file); char path[PLATFORM_MAX_PATH]; - g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "%s", file); + g_pSM->BuildPath(Path_Game, path, sizeof(path), "%s", file); SMCStates states; SMCError p_err = textparsers->ParseFile_SMC(path, parse, &states); diff --git a/core/logic/svn_version.h b/core/logic/svn_version.h new file mode 100755 index 000000000..a94274a96 --- /dev/null +++ b/core/logic/svn_version.h @@ -0,0 +1,44 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod GeoIP Extension + * 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$ + */ + +/** + * Autogenerated by build scripts + */ + +#ifndef _INCLUDE_GEOIP_VERSION_H_ +#define _INCLUDE_GEOIP_VERSION_H_ + +#define SM_BUILD_STRING "-dev" +#define SM_BUILD_UNIQUEID "2650:5d34bc3edbfa" SM_BUILD_STRING +#define SVN_FULL_VERSION "1.3.0" SM_BUILD_STRING +#define SVN_FILE_VERSION 1,3,0,0 + +#endif //_INCLUDE_GEOIP_VERSION_H_ diff --git a/core/logic/svn_version.tpl b/core/logic/svn_version.tpl new file mode 100755 index 000000000..35da7293b --- /dev/null +++ b/core/logic/svn_version.tpl @@ -0,0 +1,44 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod GeoIP Extension + * 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$ + */ + +/** + * Autogenerated by build scripts + */ + +#ifndef _INCLUDE_LOGIC_VERSION_H_ +#define _INCLUDE_LOGIC_VERSION_H_ + +#define SM_BUILD_STRING "$BUILD_STRING$" +#define SM_BUILD_UNIQUEID "$BUILD_ID$" SM_BUILD_STRING +#define SVN_FULL_VERSION "$PMAJOR$.$PMINOR$.$PREVISION$" SM_BUILD_STRING +#define SVN_FILE_VERSION $PMAJOR$,$PMINOR$,$PREVISION$,0 + +#endif //_INCLUDE_LOGIC_VERSION_H_ diff --git a/core/thread/BaseWorker.cpp b/core/logic/thread/BaseWorker.cpp similarity index 100% rename from core/thread/BaseWorker.cpp rename to core/logic/thread/BaseWorker.cpp diff --git a/core/thread/BaseWorker.h b/core/logic/thread/BaseWorker.h similarity index 100% rename from core/thread/BaseWorker.h rename to core/logic/thread/BaseWorker.h diff --git a/core/thread/PosixThreads.cpp b/core/logic/thread/PosixThreads.cpp similarity index 100% rename from core/thread/PosixThreads.cpp rename to core/logic/thread/PosixThreads.cpp diff --git a/core/thread/PosixThreads.h b/core/logic/thread/PosixThreads.h similarity index 100% rename from core/thread/PosixThreads.h rename to core/logic/thread/PosixThreads.h diff --git a/core/thread/ThreadWorker.cpp b/core/logic/thread/ThreadWorker.cpp similarity index 100% rename from core/thread/ThreadWorker.cpp rename to core/logic/thread/ThreadWorker.cpp diff --git a/core/thread/ThreadWorker.h b/core/logic/thread/ThreadWorker.h similarity index 100% rename from core/thread/ThreadWorker.h rename to core/logic/thread/ThreadWorker.h diff --git a/core/thread/WinThreads.cpp b/core/logic/thread/WinThreads.cpp similarity index 100% rename from core/thread/WinThreads.cpp rename to core/logic/thread/WinThreads.cpp diff --git a/core/thread/WinThreads.h b/core/logic/thread/WinThreads.h similarity index 100% rename from core/thread/WinThreads.h rename to core/logic/thread/WinThreads.h diff --git a/core/logic/version.rc b/core/logic/version.rc new file mode 100755 index 000000000..bb5b594fd --- /dev/null +++ b/core/logic/version.rc @@ -0,0 +1,104 @@ +// Microsoft Visual C++ generated resource script. +// +//#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +#include "svn_version.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION SVN_FILE_VERSION + PRODUCTVERSION SVN_FILE_VERSION + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "Comments", "SourceMod" + VALUE "FileDescription", "SourceMod Core Logic" + VALUE "FileVersion", SVN_FULL_VERSION + VALUE "InternalName", "sourcemod" + VALUE "LegalCopyright", "Copyright (c) 2004-2009, AlliedModders LLC" + VALUE "OriginalFilename", "sourcemod.logic.dll" + VALUE "ProductName", "SourceMod" + VALUE "ProductVersion", SVN_FULL_VERSION + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/core/logic_bridge.cpp b/core/logic_bridge.cpp new file mode 100644 index 000000000..71440dfea --- /dev/null +++ b/core/logic_bridge.cpp @@ -0,0 +1,169 @@ +/** + * vim: set ts=4 sw=4 : + * ============================================================================= + * SourceMod + * Copyright (C) 2004-2009 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 +#include +#include "sourcemod.h" +#include "sourcemm_api.h" +#include "sm_globals.h" +#include "NativeOwner.h" +#include "sm_autonatives.h" +#include "logic/intercom.h" +#include "LibrarySys.h" +#include "HandleSys.h" +#include "sm_stringutil.h" +#include "Logger.h" +#include "ShareSys.h" + +static ILibrary *g_pLogic = NULL; +static LogicInitFunction logic_init_fn; + +IThreader *g_pThreader; +ITextParsers *textparsers; + +class VEngineServer_Logic : public IVEngineServer_Logic +{ +public: + virtual bool IsMapValid(const char *map) + { + return engine->IsMapValid(map); + } +}; + +static VEngineServer_Logic logic_engine; + +static void add_natives(sp_nativeinfo_t *natives) +{ + g_pCoreNatives->AddNatives(natives); +} + +static ConVar *find_convar(const char *name) +{ + return icvar->FindVar(name); +} + +static void log_error(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + g_Logger.LogErrorEx(fmt, ap); + va_end(ap); +} + +static const char *get_cvar_string(ConVar* cvar) +{ + return cvar->GetString(); +} + +static sm_core_t core_bridge = +{ + /* Objects */ + &g_HandleSys, + NULL, + &g_SourceMod, + &g_LibSys, + reinterpret_cast(&logic_engine), + &g_ShareSys, + /* Functions */ + add_natives, + find_convar, + strncopy, + UTIL_TrimWhitespace, + log_error, + get_cvar_string, + UTIL_Format +}; + +void InitLogicBridge() +{ + sm_logic_t logic; + + core_bridge.core_ident = g_pCoreIdent; + logic_init_fn(&core_bridge, &logic); + + /* Add SMGlobalClass instances */ + SMGlobalClass* glob = SMGlobalClass::head; + while (glob->m_pGlobalClassNext != NULL) + { + glob = glob->m_pGlobalClassNext; + } + assert(glob->m_pGlobalClassNext == NULL); + glob->m_pGlobalClassNext = logic.head; + + g_pThreader = logic.threader; +} + +bool StartLogicBridge(char *error, size_t maxlength) +{ + char file[PLATFORM_MAX_PATH]; + + /* Now it's time to load the logic binary */ + g_SMAPI->PathFormat(file, + sizeof(file), + "%s/bin/sourcemod.logic." PLATFORM_LIB_EXT, + g_SourceMod.GetSourceModPath()); + + char myerror[255]; + g_pLogic = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror)); + + if (!g_pLogic) + { + if (error && maxlength) + { + UTIL_Format(error, maxlength, "failed to load %s: %s", file, myerror); + } + return false; + } + + LogicLoadFunction llf = (LogicLoadFunction)g_pLogic->GetSymbolAddress("logic_load"); + if (llf == NULL) + { + g_pLogic->CloseLibrary(); + if (error && maxlength) + { + UTIL_Format(error, maxlength, "could not find logic_load function"); + } + return false; + } + + GetITextParsers getitxt = (GetITextParsers)g_pLogic->GetSymbolAddress("get_textparsers"); + textparsers = getitxt(); + + logic_init_fn = llf(SM_LOGIC_MAGIC); + + return true; +} + +void ShutdownLogicBridge() +{ + g_pLogic->CloseLibrary(); +} + diff --git a/core/logic_bridge.h b/core/logic_bridge.h new file mode 100644 index 000000000..e7d3785a3 --- /dev/null +++ b/core/logic_bridge.h @@ -0,0 +1,39 @@ +/** + * vim: set ts=4 sw=4 : + * ============================================================================= + * SourceMod + * Copyright (C) 2004-2009 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_LOGIC_BRIDGE_H_ +#define _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_ + +void InitLogicBridge(); +bool StartLogicBridge(char *error, size_t maxlength); +void ShutdownLogicBridge(); + +#endif /* _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_ */ + diff --git a/core/msvc9/sourcemod_mm.vcproj b/core/msvc9/sourcemod_mm.vcproj index 2f9396778..6f62e3573 100644 --- a/core/msvc9/sourcemod_mm.vcproj +++ b/core/msvc9/sourcemod_mm.vcproj @@ -1420,6 +1420,10 @@ RelativePath="..\Logger.cpp" > + + @@ -1512,14 +1516,6 @@ RelativePath="..\sourcemod.cpp" > - - - - @@ -1626,6 +1622,10 @@ RelativePath="..\Logger.h" > + + @@ -1750,14 +1750,6 @@ RelativePath="..\sourcemod.h" > - - - - @@ -1906,14 +1898,6 @@ RelativePath="..\smn_admin.cpp" > - - - - @@ -1958,10 +1942,6 @@ RelativePath="..\smn_filesystem.cpp" > - - @@ -1990,10 +1970,6 @@ RelativePath="..\smn_lang.cpp" > - - @@ -2010,18 +1986,10 @@ RelativePath="..\smn_profiler.cpp" > - - - - @@ -2045,42 +2013,6 @@ > - - - - - - - - - - - - - - - - - - diff --git a/core/sm_globals.h b/core/sm_globals.h index d13a71bfd..03e749cf3 100644 --- a/core/sm_globals.h +++ b/core/sm_globals.h @@ -1,8 +1,8 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 : * ============================================================================= * SourceMod - * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. + * Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved. * ============================================================================= * * This program is free software; you can redistribute it and/or modify it under @@ -76,7 +76,11 @@ class SMGlobalClass friend class CExtensionManager; friend class PlayerManager; public: - SMGlobalClass(); + SMGlobalClass() + { + m_pGlobalClassNext = SMGlobalClass::head; + SMGlobalClass::head = this; + } public: /** * @brief Called when SourceMod is initially loading @@ -184,7 +188,7 @@ public: virtual void OnSourceModMaxPlayersChanged(int newvalue) { } -private: +public: SMGlobalClass *m_pGlobalClassNext; static SMGlobalClass *head; }; @@ -193,6 +197,16 @@ extern ISourcePawnEngine *g_pSourcePawn; extern ISourcePawnEngine2 *g_pSourcePawn2; extern IdentityToken_t *g_pCoreIdent; +namespace SourceMod +{ + class IThreader; + class ITextParsers; +} + +extern IThreader *g_pThreader; +extern ITextParsers *textparsers; + #include "sm_autonatives.h" #endif //_INCLUDE_SOURCEMOD_GLOBALS_H_ + diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index e12d4f007..88dbb4f5d 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -1,8 +1,8 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 : * ============================================================================= * SourceMod - * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. + * Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved. * ============================================================================= * * This program is free software; you can redistribute it and/or modify it under @@ -49,6 +49,7 @@ #include "DebugReporter.h" #include "Profiler.h" #include "frame_hooks.h" +#include "logic_bridge.h" SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool); SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false); @@ -166,6 +167,11 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), basepath); g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), "%s", basepath); + if (!StartLogicBridge(error, maxlength)) + { + return false; + } + /* Initialize CoreConfig to get the SourceMod base path properly - this parses core.cfg */ g_CoreConfig.Initialize(); @@ -185,7 +191,7 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late { if (error && maxlength) { - snprintf(error, maxlength, "%s (failed to load bin/sourcepawn.jit.x86.%s)", + UTIL_Format(error, maxlength, "%s (failed to load bin/sourcepawn.jit.x86.%s)", myerror, PLATFORM_LIB_EXT); } @@ -265,6 +271,8 @@ void SourceModBase::StartSourceMod(bool late) /* Make the global core identity */ g_pCoreIdent = g_ShareSys.CreateCoreIdentity(); + InitLogicBridge(); + /* Notify! */ SMGlobalClass *pBase = SMGlobalClass::head; while (pBase) @@ -535,6 +543,7 @@ void SourceModBase::CloseSourceMod() } /* Rest In Peace */ + ShutdownLogicBridge(); ShutdownJIT(); } @@ -731,8 +740,3 @@ int SourceModBase::GetPluginId() SMGlobalClass *SMGlobalClass::head = NULL; -SMGlobalClass::SMGlobalClass() -{ - m_pGlobalClassNext = SMGlobalClass::head; - SMGlobalClass::head = this; -} diff --git a/tools/builder/PkgCore.cs b/tools/builder/PkgCore.cs index bafd5770a..24a1f1236 100644 --- a/tools/builder/PkgCore.cs +++ b/tools/builder/PkgCore.cs @@ -152,6 +152,13 @@ namespace builder lib.has_platform_ext = true; libraries.Add(lib); + lib = new Library(); + lib.package_path = "addons/sourcemod/bin"; + lib.source_path = "core/logic"; + lib.binary_name = "sourcemod.logic"; + lib.vcproj_name = "logic"; + libraries.Add(lib); + lib = new Library(); lib.package_path = "addons/sourcemod/bin"; lib.source_path = "core";