committed two forgotten files and updated the linux makefile
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%402200
This commit is contained in:
parent
044ee841f2
commit
627e4fd115
@ -18,7 +18,8 @@ OBJECTS = AdminCache.cpp CDataPack.cpp ConCmdManager.cpp ConVarManager.cpp CoreC
|
|||||||
sm_autonatives.cpp sm_memtable.cpp sm_srvcmds.cpp sm_stringutil.cpp sm_trie.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 \
|
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 \
|
MenuStyle_Radio.cpp ChatTriggers.cpp ADTFactory.cpp MenuVoting.cpp sm_crc32.cpp \
|
||||||
frame_hooks.cpp concmd_cleaner.cpp Profiler.cpp PhraseCollection.cpp NextMap.cpp
|
frame_hooks.cpp concmd_cleaner.cpp Profiler.cpp PhraseCollection.cpp NextMap.cpp \
|
||||||
|
NativeOwner.cpp
|
||||||
OBJECTS += smn_admin.cpp smn_bitbuffer.cpp smn_console.cpp smn_core.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_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_filesystem.cpp smn_float.cpp smn_functions.cpp smn_gameconfigs.cpp smn_halflife.cpp \
|
||||||
|
140
core/NativeOwner.cpp
Normal file
140
core/NativeOwner.cpp
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
#include "NativeOwner.h"
|
||||||
|
#include "ShareSys.h"
|
||||||
|
#include "PluginSys.h"
|
||||||
|
|
||||||
|
void CNativeOwner::SetMarkSerial(unsigned int serial)
|
||||||
|
{
|
||||||
|
m_nMarkSerial = serial;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int CNativeOwner::GetMarkSerial()
|
||||||
|
{
|
||||||
|
return m_nMarkSerial;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::AddDependent(CPlugin *pPlugin)
|
||||||
|
{
|
||||||
|
m_Dependents.push_back(pPlugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::AddWeakRef(const WeakNative & ref)
|
||||||
|
{
|
||||||
|
m_WeakRefs.push_back(ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::AddNatives(const sp_nativeinfo_t *natives)
|
||||||
|
{
|
||||||
|
NativeEntry *pEntry;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; natives[i].func != NULL && natives[i].name != NULL; i++)
|
||||||
|
{
|
||||||
|
if ((pEntry = g_ShareSys.AddNativeToCache(this, &natives[i])) == NULL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Natives.push_back(pEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::PropogateMarkSerial(unsigned int serial)
|
||||||
|
{
|
||||||
|
CNativeOwner *pOwner;
|
||||||
|
List<CPlugin *>::iterator iter;
|
||||||
|
|
||||||
|
for (iter = m_Dependents.begin();
|
||||||
|
iter != m_Dependents.end();
|
||||||
|
iter++)
|
||||||
|
{
|
||||||
|
pOwner = (*iter);
|
||||||
|
pOwner->SetMarkSerial(serial);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::UnbindWeakRef(const WeakNative & ref)
|
||||||
|
{
|
||||||
|
sp_native_t *native;
|
||||||
|
IPluginContext *pContext;
|
||||||
|
|
||||||
|
pContext = ref.pl->GetBaseContext();
|
||||||
|
if ((pContext->GetNativeByIndex(ref.idx, &native)) == SP_ERROR_NONE)
|
||||||
|
{
|
||||||
|
/* If there is no reference, the native must be unbound */
|
||||||
|
if (ref.entry == NULL)
|
||||||
|
{
|
||||||
|
native->status = SP_NATIVE_UNBOUND;
|
||||||
|
native->pfn = NULL;
|
||||||
|
}
|
||||||
|
/* If we've cached a reference, it's a core native we can
|
||||||
|
* rebind back to its original (this was a replacement).
|
||||||
|
*/
|
||||||
|
else
|
||||||
|
{
|
||||||
|
native->pfn = ref.entry->func;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::DropEverything()
|
||||||
|
{
|
||||||
|
NativeEntry *pEntry;
|
||||||
|
List<WeakNative>::iterator iter;
|
||||||
|
List<NativeEntry *>::iterator ntv_iter;
|
||||||
|
|
||||||
|
/* Unbind and remove all weak references to us */
|
||||||
|
iter = m_WeakRefs.begin();
|
||||||
|
while (iter != m_WeakRefs.end())
|
||||||
|
{
|
||||||
|
UnbindWeakRef((*iter));
|
||||||
|
iter = m_WeakRefs.erase(iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Unmark our replacement natives */
|
||||||
|
ntv_iter = m_ReplacedNatives.begin();
|
||||||
|
while (ntv_iter != m_ReplacedNatives.end())
|
||||||
|
{
|
||||||
|
pEntry = (*ntv_iter);
|
||||||
|
pEntry->replacement.func = NULL;
|
||||||
|
pEntry->replacement.owner = NULL;
|
||||||
|
ntv_iter = m_ReplacedNatives.erase(ntv_iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Strip all of our natives from the cache */
|
||||||
|
ntv_iter = m_Natives.begin();
|
||||||
|
while (ntv_iter != m_Natives.end())
|
||||||
|
{
|
||||||
|
g_ShareSys.ClearNativeFromCache(this, (*ntv_iter)->name);
|
||||||
|
ntv_iter = m_Natives.erase(ntv_iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::DropWeakRefsTo(CPlugin *pPlugin)
|
||||||
|
{
|
||||||
|
List<WeakNative>::iterator iter;
|
||||||
|
|
||||||
|
iter = m_WeakRefs.begin();
|
||||||
|
while (iter != m_WeakRefs.end())
|
||||||
|
{
|
||||||
|
WeakNative & ref = (*iter);
|
||||||
|
|
||||||
|
if (ref.pl == pPlugin)
|
||||||
|
{
|
||||||
|
iter = m_WeakRefs.erase(iter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::DropRefsTo(CPlugin *pPlugin)
|
||||||
|
{
|
||||||
|
m_Dependents.remove(pPlugin);
|
||||||
|
DropWeakRefsTo(pPlugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNativeOwner::AddReplacedNative(NativeEntry *pEntry)
|
||||||
|
{
|
||||||
|
m_ReplacedNatives.push_back(pEntry);
|
||||||
|
}
|
57
core/NativeOwner.h
Normal file
57
core/NativeOwner.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#ifndef _INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
|
||||||
|
#define _INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
|
||||||
|
|
||||||
|
#include <sp_vm_types.h>
|
||||||
|
#include <sh_list.h>
|
||||||
|
|
||||||
|
class CPlugin;
|
||||||
|
struct NativeEntry;
|
||||||
|
|
||||||
|
struct WeakNative
|
||||||
|
{
|
||||||
|
WeakNative(CPlugin *plugin, uint32_t index) :
|
||||||
|
pl(plugin), idx(index), entry(NULL)
|
||||||
|
{
|
||||||
|
pl = plugin;
|
||||||
|
idx = index;
|
||||||
|
}
|
||||||
|
WeakNative(CPlugin *plugin, uint32_t index, NativeEntry *pEntry) :
|
||||||
|
pl(plugin), idx(index), entry(pEntry)
|
||||||
|
{
|
||||||
|
pl = plugin;
|
||||||
|
idx = index;
|
||||||
|
}
|
||||||
|
CPlugin *pl;
|
||||||
|
uint32_t idx;
|
||||||
|
NativeEntry *entry;
|
||||||
|
};
|
||||||
|
|
||||||
|
using namespace SourceHook;
|
||||||
|
|
||||||
|
class CNativeOwner
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void DropEverything();
|
||||||
|
public:
|
||||||
|
void AddNatives(const sp_nativeinfo_t *info);
|
||||||
|
public:
|
||||||
|
void SetMarkSerial(unsigned int serial);
|
||||||
|
unsigned int GetMarkSerial();
|
||||||
|
void PropogateMarkSerial(unsigned int serial);
|
||||||
|
public:
|
||||||
|
void AddDependent(CPlugin *pPlugin);
|
||||||
|
void AddWeakRef(const WeakNative & ref);
|
||||||
|
void DropRefsTo(CPlugin *pPlugin);
|
||||||
|
void AddReplacedNative(NativeEntry *pEntry);
|
||||||
|
private:
|
||||||
|
void DropWeakRefsTo(CPlugin *pPlugin);
|
||||||
|
void UnbindWeakRef(const WeakNative & ref);
|
||||||
|
protected:
|
||||||
|
List<CPlugin *> m_Dependents;
|
||||||
|
unsigned int m_nMarkSerial;
|
||||||
|
List<WeakNative> m_WeakRefs;
|
||||||
|
List<NativeEntry *> m_Natives;
|
||||||
|
List<NativeEntry *> m_ReplacedNatives;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //_INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
|
Loading…
Reference in New Issue
Block a user