1.1 --- a/core/Makefile Mon May 26 07:51:36 2008 +0000
1.2 +++ b/core/Makefile Mon May 26 07:52:27 2008 +0000
1.3 @@ -1,147 +1,148 @@
1.4 -# (C)2004-2008 SourceMod Development Team
1.5 -# Makefile written by David "BAILOPAN" Anderson
1.6 -
1.7 -SMSDK = ..
1.8 -SRCDS_BASE = ~/srcds
1.9 -HL2SDK_ORIG = ../../hl2sdk
1.10 -HL2SDK_OB = ../../hl2sdk-ob
1.11 -SOURCEMM14 = ../../sourcemm-1.4
1.12 -SOURCEMM16 = ../../sourcemm-1.6
1.13 -
1.14 -#####################################
1.15 -### EDIT BELOW FOR OTHER PROJECTS ###
1.16 -#####################################
1.17 -
1.18 -OBJECTS = AdminCache.cpp CDataPack.cpp ConCmdManager.cpp ConVarManager.cpp CoreConfig.cpp \
1.19 - Database.cpp DebugReporter.cpp EventManager.cpp GameConfigs.cpp HalfLife2.cpp Logger.cpp \
1.20 - MemoryUtils.cpp PlayerManager.cpp TextParsers.cpp TimerSys.cpp Translator.cpp UserMessages.cpp \
1.21 - sm_autonatives.cpp sm_memtable.cpp sm_srvcmds.cpp sm_stringutil.cpp sm_trie.cpp \
1.22 - sourcemm_api.cpp sourcemod.cpp MenuStyle_Base.cpp MenuStyle_Valve.cpp MenuManager.cpp \
1.23 - MenuStyle_Radio.cpp ChatTriggers.cpp ADTFactory.cpp MenuVoting.cpp sm_crc32.cpp \
1.24 - frame_hooks.cpp concmd_cleaner.cpp Profiler.cpp PhraseCollection.cpp NextMap.cpp
1.25 -OBJECTS += smn_admin.cpp smn_bitbuffer.cpp smn_console.cpp smn_core.cpp \
1.26 - smn_datapacks.cpp smn_entities.cpp smn_events.cpp smn_fakenatives.cpp \
1.27 - smn_filesystem.cpp smn_float.cpp smn_functions.cpp smn_gameconfigs.cpp smn_halflife.cpp \
1.28 - smn_handles.cpp smn_keyvalues.cpp smn_banning.cpp smn_maplists.cpp \
1.29 - smn_lang.cpp smn_player.cpp smn_string.cpp smn_sorting.cpp smn_textparse.cpp smn_timers.cpp \
1.30 - smn_usermsgs.cpp smn_menus.cpp smn_database.cpp smn_vector.cpp smn_adt_array.cpp \
1.31 - smn_adt_trie.cpp smn_hudtext.cpp smn_adt_stack.cpp smn_nextmap.cpp
1.32 -OBJECTS += systems/ExtensionSys.cpp systems/ForwardSys.cpp systems/HandleSys.cpp \
1.33 - systems/LibrarySys.cpp systems/PluginInfoDatabase.cpp systems/PluginSys.cpp \
1.34 - systems/ShareSys.cpp vm/sp_vm_basecontext.cpp vm/sp_vm_engine.cpp \
1.35 - vm/sp_vm_function.cpp
1.36 -OBJECTS += thread/ThreadWorker.cpp thread/BaseWorker.cpp thread/PosixThreads.cpp ThreadSupport.cpp
1.37 -OBJECTS += zlib/adler32.c zlib/compress.c zlib/crc32.c zlib/deflate.c zlib/gzio.c \
1.38 - zlib/infback.c zlib/inffast.c zlib/inflate.c zlib/inftrees.c zlib/trees.c \
1.39 - zlib/uncompr.c zlib/zutil.c
1.40 -
1.41 -##############################################
1.42 -### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
1.43 -##############################################
1.44 -
1.45 -C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing
1.46 -C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3
1.47 -C_GCC4_FLAGS = -fvisibility=hidden
1.48 -CPP_GCC4_FLAGS = -fvisibility-inlines-hidden
1.49 -CPP = gcc-4.1
1.50 -
1.51 -override ENGSET = false
1.52 -ifeq "$(ENGINE)" "original"
1.53 - HL2SDK = $(HL2SDK_ORIG)
1.54 - HL2PUB = $(HL2SDK_ORIG)/public
1.55 - HL2LIB = $(HL2SDK_ORIG)/linux_sdk
1.56 - METAMOD = $(SOURCEMM14)
1.57 - INCLUDE += -I$(HL2SDK)/public/dlls
1.58 - SRCDS = $(SRCDS_BASE)
1.59 - BINARY = sourcemod.1.ep1.so
1.60 - override ENGSET = true
1.61 -endif
1.62 -ifeq "$(ENGINE)" "orangebox"
1.63 - HL2SDK = $(HL2SDK_OB)
1.64 - HL2PUB = $(HL2SDK_OB)/public
1.65 - HL2LIB = $(HL2SDK_OB)/linux_sdk
1.66 - CFLAGS += -DORANGEBOX_BUILD
1.67 - METAMOD = $(SOURCEMM16)
1.68 - INCLUDE += -I$(HL2SDK)/public/game/server
1.69 - SRCDS = $(SRCDS_BASE)/orangebox
1.70 - BINARY = sourcemod.2.ep2.so
1.71 - override ENGSET = true
1.72 -endif
1.73 -
1.74 -LINK += $(HL2LIB)/tier1_i486.a $(HL2LIB)/mathlib_i486.a vstdlib_i486.so \
1.75 - tier0_i486.so -lpthread -static-libgcc
1.76 -
1.77 -INCLUDE_SMSDK = -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn
1.78 -
1.79 -INCLUDE_SM16 = -I. -I.. -I$(SOURCEMM16)/sourcehook $(INCLUDE_SMSDK)
1.80 -
1.81 -INCLUDE += -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/mathlib -I$(HL2PUB)/vstdlib \
1.82 - -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 -I$(METAMOD) -I$(METAMOD)/sourcehook \
1.83 - -I$(METAMOD)/sourcemm -Isystems $(INCLUDE_SMSDK)
1.84 -
1.85 -CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \
1.86 - -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror \
1.87 - -Wno-uninitialized -mfpmath=sse -msse -DSOURCEMOD_BUILD -DHAVE_STDINT_H -DSM_DEFAULT_THREADER -m32
1.88 -CPPFLAGS += -Wno-non-virtual-dtor -fno-exceptions -fno-rtti
1.89 -
1.90 -################################################
1.91 -### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
1.92 -################################################
1.93 -
1.94 -ifeq "$(DEBUG)" "true"
1.95 - BIN_DIR = Debug.$(ENGINE)
1.96 - CFLAGS += $(C_DEBUG_FLAGS)
1.97 -else
1.98 - BIN_DIR = Release.$(ENGINE)
1.99 - CFLAGS += $(C_OPT_FLAGS)
1.100 -endif
1.101 -
1.102 -GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1)
1.103 -ifeq "$(GCC_VERSION)" "4"
1.104 - CFLAGS += $(C_GCC4_FLAGS)
1.105 - CPPFLAGS += $(CPP_GCC4_FLAGS)
1.106 -endif
1.107 -
1.108 -OBJ_LINUX := $(OBJECTS:%vm_engine.cpp=$(BIN_DIR)/%vm_engine.o)
1.109 -OBJ_LINUX := $(OBJ_LINUX:%.cpp=$(BIN_DIR)/%.o)
1.110 -OBJ_LINUX := $(OBJ_LINUX:%.c=$(BIN_DIR)/%.o)
1.111 -
1.112 -$(BIN_DIR)/%vm_engine.o: %vm_engine.cpp
1.113 - $(CPP) $(INCLUDE_SM16) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
1.114 -
1.115 -$(BIN_DIR)/%.o: %.cpp
1.116 - $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
1.117 -
1.118 -$(BIN_DIR)/%.o: %.c
1.119 - $(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $<
1.120 -
1.121 -all: check
1.122 - mkdir -p $(BIN_DIR)/systems
1.123 - mkdir -p $(BIN_DIR)/vm
1.124 - mkdir -p $(BIN_DIR)/zlib
1.125 - mkdir -p $(BIN_DIR)/thread
1.126 - ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so;
1.127 - ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so;
1.128 - $(MAKE) -f Makefile sourcemod
1.129 -
1.130 -check:
1.131 - if [ "$(ENGSET)" == "false" ]; then \
1.132 - echo "You must supply ENGINE=orangebox or ENGINE=original"; \
1.133 - exit 1; \
1.134 - fi
1.135 -
1.136 -sourcemod: check $(OBJ_LINUX)
1.137 - $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY)
1.138 -
1.139 -debug:
1.140 - $(MAKE) -f Makefile all DEBUG=true
1.141 -
1.142 -default: all
1.143 -
1.144 -clean: check
1.145 - rm -rf $(BIN_DIR)/*.o
1.146 - rm -rf $(BIN_DIR)/systems/*.o
1.147 - rm -rf $(BIN_DIR)/zlib/*.o
1.148 - rm -rf $(BIN_DIR)/vm/*.o
1.149 - rm -rf $(BIN_DIR)/thread/*.o
1.150 - rm -rf $(BIN_DIR)/$(BINARY)
1.151 +# (C)2004-2008 SourceMod Development Team
1.152 +# Makefile written by David "BAILOPAN" Anderson
1.153 +
1.154 +SMSDK = ..
1.155 +SRCDS_BASE = ~/srcds
1.156 +HL2SDK_ORIG = ../../hl2sdk
1.157 +HL2SDK_OB = ../../hl2sdk-ob
1.158 +SOURCEMM14 = ../../sourcemm-1.4
1.159 +SOURCEMM16 = ../../sourcemm-1.6
1.160 +
1.161 +#####################################
1.162 +### EDIT BELOW FOR OTHER PROJECTS ###
1.163 +#####################################
1.164 +
1.165 +OBJECTS = AdminCache.cpp CDataPack.cpp ConCmdManager.cpp ConVarManager.cpp CoreConfig.cpp \
1.166 + Database.cpp DebugReporter.cpp EventManager.cpp GameConfigs.cpp HalfLife2.cpp Logger.cpp \
1.167 + MemoryUtils.cpp PlayerManager.cpp TextParsers.cpp TimerSys.cpp Translator.cpp UserMessages.cpp \
1.168 + sm_autonatives.cpp sm_memtable.cpp sm_srvcmds.cpp sm_stringutil.cpp sm_trie.cpp \
1.169 + sourcemm_api.cpp sourcemod.cpp MenuStyle_Base.cpp MenuStyle_Valve.cpp MenuManager.cpp \
1.170 + MenuStyle_Radio.cpp ChatTriggers.cpp ADTFactory.cpp MenuVoting.cpp sm_crc32.cpp \
1.171 + frame_hooks.cpp concmd_cleaner.cpp Profiler.cpp PhraseCollection.cpp NextMap.cpp \
1.172 + NativeOwner.cpp
1.173 +OBJECTS += smn_admin.cpp smn_bitbuffer.cpp smn_console.cpp smn_core.cpp \
1.174 + smn_datapacks.cpp smn_entities.cpp smn_events.cpp smn_fakenatives.cpp \
1.175 + smn_filesystem.cpp smn_float.cpp smn_functions.cpp smn_gameconfigs.cpp smn_halflife.cpp \
1.176 + smn_handles.cpp smn_keyvalues.cpp smn_banning.cpp smn_maplists.cpp \
1.177 + smn_lang.cpp smn_player.cpp smn_string.cpp smn_sorting.cpp smn_textparse.cpp smn_timers.cpp \
1.178 + smn_usermsgs.cpp smn_menus.cpp smn_database.cpp smn_vector.cpp smn_adt_array.cpp \
1.179 + smn_adt_trie.cpp smn_hudtext.cpp smn_adt_stack.cpp smn_nextmap.cpp
1.180 +OBJECTS += systems/ExtensionSys.cpp systems/ForwardSys.cpp systems/HandleSys.cpp \
1.181 + systems/LibrarySys.cpp systems/PluginInfoDatabase.cpp systems/PluginSys.cpp \
1.182 + systems/ShareSys.cpp vm/sp_vm_basecontext.cpp vm/sp_vm_engine.cpp \
1.183 + vm/sp_vm_function.cpp
1.184 +OBJECTS += thread/ThreadWorker.cpp thread/BaseWorker.cpp thread/PosixThreads.cpp ThreadSupport.cpp
1.185 +OBJECTS += zlib/adler32.c zlib/compress.c zlib/crc32.c zlib/deflate.c zlib/gzio.c \
1.186 + zlib/infback.c zlib/inffast.c zlib/inflate.c zlib/inftrees.c zlib/trees.c \
1.187 + zlib/uncompr.c zlib/zutil.c
1.188 +
1.189 +##############################################
1.190 +### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
1.191 +##############################################
1.192 +
1.193 +C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing
1.194 +C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3
1.195 +C_GCC4_FLAGS = -fvisibility=hidden
1.196 +CPP_GCC4_FLAGS = -fvisibility-inlines-hidden
1.197 +CPP = gcc-4.1
1.198 +
1.199 +override ENGSET = false
1.200 +ifeq "$(ENGINE)" "original"
1.201 + HL2SDK = $(HL2SDK_ORIG)
1.202 + HL2PUB = $(HL2SDK_ORIG)/public
1.203 + HL2LIB = $(HL2SDK_ORIG)/linux_sdk
1.204 + METAMOD = $(SOURCEMM14)
1.205 + INCLUDE += -I$(HL2SDK)/public/dlls
1.206 + SRCDS = $(SRCDS_BASE)
1.207 + BINARY = sourcemod.1.ep1.so
1.208 + override ENGSET = true
1.209 +endif
1.210 +ifeq "$(ENGINE)" "orangebox"
1.211 + HL2SDK = $(HL2SDK_OB)
1.212 + HL2PUB = $(HL2SDK_OB)/public
1.213 + HL2LIB = $(HL2SDK_OB)/linux_sdk
1.214 + CFLAGS += -DORANGEBOX_BUILD
1.215 + METAMOD = $(SOURCEMM16)
1.216 + INCLUDE += -I$(HL2SDK)/public/game/server
1.217 + SRCDS = $(SRCDS_BASE)/orangebox
1.218 + BINARY = sourcemod.2.ep2.so
1.219 + override ENGSET = true
1.220 +endif
1.221 +
1.222 +LINK += $(HL2LIB)/tier1_i486.a $(HL2LIB)/mathlib_i486.a vstdlib_i486.so \
1.223 + tier0_i486.so -lpthread -static-libgcc
1.224 +
1.225 +INCLUDE_SMSDK = -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn
1.226 +
1.227 +INCLUDE_SM16 = -I. -I.. -I$(SOURCEMM16)/sourcehook $(INCLUDE_SMSDK)
1.228 +
1.229 +INCLUDE += -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/mathlib -I$(HL2PUB)/vstdlib \
1.230 + -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 -I$(METAMOD) -I$(METAMOD)/sourcehook \
1.231 + -I$(METAMOD)/sourcemm -Isystems $(INCLUDE_SMSDK)
1.232 +
1.233 +CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \
1.234 + -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror \
1.235 + -Wno-uninitialized -mfpmath=sse -msse -DSOURCEMOD_BUILD -DHAVE_STDINT_H -DSM_DEFAULT_THREADER -m32
1.236 +CPPFLAGS += -Wno-non-virtual-dtor -fno-exceptions -fno-rtti
1.237 +
1.238 +################################################
1.239 +### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
1.240 +################################################
1.241 +
1.242 +ifeq "$(DEBUG)" "true"
1.243 + BIN_DIR = Debug.$(ENGINE)
1.244 + CFLAGS += $(C_DEBUG_FLAGS)
1.245 +else
1.246 + BIN_DIR = Release.$(ENGINE)
1.247 + CFLAGS += $(C_OPT_FLAGS)
1.248 +endif
1.249 +
1.250 +GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1)
1.251 +ifeq "$(GCC_VERSION)" "4"
1.252 + CFLAGS += $(C_GCC4_FLAGS)
1.253 + CPPFLAGS += $(CPP_GCC4_FLAGS)
1.254 +endif
1.255 +
1.256 +OBJ_LINUX := $(OBJECTS:%vm_engine.cpp=$(BIN_DIR)/%vm_engine.o)
1.257 +OBJ_LINUX := $(OBJ_LINUX:%.cpp=$(BIN_DIR)/%.o)
1.258 +OBJ_LINUX := $(OBJ_LINUX:%.c=$(BIN_DIR)/%.o)
1.259 +
1.260 +$(BIN_DIR)/%vm_engine.o: %vm_engine.cpp
1.261 + $(CPP) $(INCLUDE_SM16) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
1.262 +
1.263 +$(BIN_DIR)/%.o: %.cpp
1.264 + $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
1.265 +
1.266 +$(BIN_DIR)/%.o: %.c
1.267 + $(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $<
1.268 +
1.269 +all: check
1.270 + mkdir -p $(BIN_DIR)/systems
1.271 + mkdir -p $(BIN_DIR)/vm
1.272 + mkdir -p $(BIN_DIR)/zlib
1.273 + mkdir -p $(BIN_DIR)/thread
1.274 + ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so;
1.275 + ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so;
1.276 + $(MAKE) -f Makefile sourcemod
1.277 +
1.278 +check:
1.279 + if [ "$(ENGSET)" == "false" ]; then \
1.280 + echo "You must supply ENGINE=orangebox or ENGINE=original"; \
1.281 + exit 1; \
1.282 + fi
1.283 +
1.284 +sourcemod: check $(OBJ_LINUX)
1.285 + $(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY)
1.286 +
1.287 +debug:
1.288 + $(MAKE) -f Makefile all DEBUG=true
1.289 +
1.290 +default: all
1.291 +
1.292 +clean: check
1.293 + rm -rf $(BIN_DIR)/*.o
1.294 + rm -rf $(BIN_DIR)/systems/*.o
1.295 + rm -rf $(BIN_DIR)/zlib/*.o
1.296 + rm -rf $(BIN_DIR)/vm/*.o
1.297 + rm -rf $(BIN_DIR)/thread/*.o
1.298 + rm -rf $(BIN_DIR)/$(BINARY)
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/core/NativeOwner.cpp Mon May 26 07:52:27 2008 +0000
2.3 @@ -0,0 +1,140 @@
2.4 +#include "NativeOwner.h"
2.5 +#include "ShareSys.h"
2.6 +#include "PluginSys.h"
2.7 +
2.8 +void CNativeOwner::SetMarkSerial(unsigned int serial)
2.9 +{
2.10 + m_nMarkSerial = serial;
2.11 +}
2.12 +
2.13 +unsigned int CNativeOwner::GetMarkSerial()
2.14 +{
2.15 + return m_nMarkSerial;
2.16 +}
2.17 +
2.18 +void CNativeOwner::AddDependent(CPlugin *pPlugin)
2.19 +{
2.20 + m_Dependents.push_back(pPlugin);
2.21 +}
2.22 +
2.23 +void CNativeOwner::AddWeakRef(const WeakNative & ref)
2.24 +{
2.25 + m_WeakRefs.push_back(ref);
2.26 +}
2.27 +
2.28 +void CNativeOwner::AddNatives(const sp_nativeinfo_t *natives)
2.29 +{
2.30 + NativeEntry *pEntry;
2.31 +
2.32 + for (unsigned int i = 0; natives[i].func != NULL && natives[i].name != NULL; i++)
2.33 + {
2.34 + if ((pEntry = g_ShareSys.AddNativeToCache(this, &natives[i])) == NULL)
2.35 + {
2.36 + continue;
2.37 + }
2.38 +
2.39 + m_Natives.push_back(pEntry);
2.40 + }
2.41 +}
2.42 +
2.43 +void CNativeOwner::PropogateMarkSerial(unsigned int serial)
2.44 +{
2.45 + CNativeOwner *pOwner;
2.46 + List<CPlugin *>::iterator iter;
2.47 +
2.48 + for (iter = m_Dependents.begin();
2.49 + iter != m_Dependents.end();
2.50 + iter++)
2.51 + {
2.52 + pOwner = (*iter);
2.53 + pOwner->SetMarkSerial(serial);
2.54 + }
2.55 +}
2.56 +
2.57 +void CNativeOwner::UnbindWeakRef(const WeakNative & ref)
2.58 +{
2.59 + sp_native_t *native;
2.60 + IPluginContext *pContext;
2.61 +
2.62 + pContext = ref.pl->GetBaseContext();
2.63 + if ((pContext->GetNativeByIndex(ref.idx, &native)) == SP_ERROR_NONE)
2.64 + {
2.65 + /* If there is no reference, the native must be unbound */
2.66 + if (ref.entry == NULL)
2.67 + {
2.68 + native->status = SP_NATIVE_UNBOUND;
2.69 + native->pfn = NULL;
2.70 + }
2.71 + /* If we've cached a reference, it's a core native we can
2.72 + * rebind back to its original (this was a replacement).
2.73 + */
2.74 + else
2.75 + {
2.76 + native->pfn = ref.entry->func;
2.77 + }
2.78 + }
2.79 +}
2.80 +
2.81 +void CNativeOwner::DropEverything()
2.82 +{
2.83 + NativeEntry *pEntry;
2.84 + List<WeakNative>::iterator iter;
2.85 + List<NativeEntry *>::iterator ntv_iter;
2.86 +
2.87 + /* Unbind and remove all weak references to us */
2.88 + iter = m_WeakRefs.begin();
2.89 + while (iter != m_WeakRefs.end())
2.90 + {
2.91 + UnbindWeakRef((*iter));
2.92 + iter = m_WeakRefs.erase(iter);
2.93 + }
2.94 +
2.95 + /* Unmark our replacement natives */
2.96 + ntv_iter = m_ReplacedNatives.begin();
2.97 + while (ntv_iter != m_ReplacedNatives.end())
2.98 + {
2.99 + pEntry = (*ntv_iter);
2.100 + pEntry->replacement.func = NULL;
2.101 + pEntry->replacement.owner = NULL;
2.102 + ntv_iter = m_ReplacedNatives.erase(ntv_iter);
2.103 + }
2.104 +
2.105 + /* Strip all of our natives from the cache */
2.106 + ntv_iter = m_Natives.begin();
2.107 + while (ntv_iter != m_Natives.end())
2.108 + {
2.109 + g_ShareSys.ClearNativeFromCache(this, (*ntv_iter)->name);
2.110 + ntv_iter = m_Natives.erase(ntv_iter);
2.111 + }
2.112 +}
2.113 +
2.114 +void CNativeOwner::DropWeakRefsTo(CPlugin *pPlugin)
2.115 +{
2.116 + List<WeakNative>::iterator iter;
2.117 +
2.118 + iter = m_WeakRefs.begin();
2.119 + while (iter != m_WeakRefs.end())
2.120 + {
2.121 + WeakNative & ref = (*iter);
2.122 +
2.123 + if (ref.pl == pPlugin)
2.124 + {
2.125 + iter = m_WeakRefs.erase(iter);
2.126 + }
2.127 + else
2.128 + {
2.129 + iter++;
2.130 + }
2.131 + }
2.132 +}
2.133 +
2.134 +void CNativeOwner::DropRefsTo(CPlugin *pPlugin)
2.135 +{
2.136 + m_Dependents.remove(pPlugin);
2.137 + DropWeakRefsTo(pPlugin);
2.138 +}
2.139 +
2.140 +void CNativeOwner::AddReplacedNative(NativeEntry *pEntry)
2.141 +{
2.142 + m_ReplacedNatives.push_back(pEntry);
2.143 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/core/NativeOwner.h Mon May 26 07:52:27 2008 +0000
3.3 @@ -0,0 +1,57 @@
3.4 +#ifndef _INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
3.5 +#define _INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
3.6 +
3.7 +#include <sp_vm_types.h>
3.8 +#include <sh_list.h>
3.9 +
3.10 +class CPlugin;
3.11 +struct NativeEntry;
3.12 +
3.13 +struct WeakNative
3.14 +{
3.15 + WeakNative(CPlugin *plugin, uint32_t index) :
3.16 + pl(plugin), idx(index), entry(NULL)
3.17 + {
3.18 + pl = plugin;
3.19 + idx = index;
3.20 + }
3.21 + WeakNative(CPlugin *plugin, uint32_t index, NativeEntry *pEntry) :
3.22 + pl(plugin), idx(index), entry(pEntry)
3.23 + {
3.24 + pl = plugin;
3.25 + idx = index;
3.26 + }
3.27 + CPlugin *pl;
3.28 + uint32_t idx;
3.29 + NativeEntry *entry;
3.30 +};
3.31 +
3.32 +using namespace SourceHook;
3.33 +
3.34 +class CNativeOwner
3.35 +{
3.36 +public:
3.37 + virtual void DropEverything();
3.38 +public:
3.39 + void AddNatives(const sp_nativeinfo_t *info);
3.40 +public:
3.41 + void SetMarkSerial(unsigned int serial);
3.42 + unsigned int GetMarkSerial();
3.43 + void PropogateMarkSerial(unsigned int serial);
3.44 +public:
3.45 + void AddDependent(CPlugin *pPlugin);
3.46 + void AddWeakRef(const WeakNative & ref);
3.47 + void DropRefsTo(CPlugin *pPlugin);
3.48 + void AddReplacedNative(NativeEntry *pEntry);
3.49 +private:
3.50 + void DropWeakRefsTo(CPlugin *pPlugin);
3.51 + void UnbindWeakRef(const WeakNative & ref);
3.52 +protected:
3.53 + List<CPlugin *> m_Dependents;
3.54 + unsigned int m_nMarkSerial;
3.55 + List<WeakNative> m_WeakRefs;
3.56 + List<NativeEntry *> m_Natives;
3.57 + List<NativeEntry *> m_ReplacedNatives;
3.58 +};
3.59 +
3.60 +#endif //_INCLUDE_SOURCEMOD_NATIVE_OWNER_H_