1
0
mirror of https://github.com/alliedmodders/metamod-source.git synced 2025-01-30 19:52:17 +01:00

Initial step towards no STL - added replacement for std::list

--HG--
extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%4097
This commit is contained in:
David Anderson 2005-08-12 17:33:31 +00:00
parent 0cf2776e7f
commit f73ef50b79
11 changed files with 784 additions and 42 deletions

244
sourcehook/smm_list.h Normal file
View File

@ -0,0 +1,244 @@
/* ======== SourceMM ========
* Copyright (C) 2004-2005 Metamod:Source Development Team
* No warranties of any kind
*
* License: zlib/libpng
*
* Author(s): David "BAILOPAN" Anderson
* ============================
*/
#ifndef _INCLUDE_SMM_LIST_H
#define _INCLUDE_SMM_LIST_H
//This class is from CSDM_amxx by BAILOPAN
//
template <class T>
class List
{
public:
class iterator;
friend class iterator;
class ListNode
{
public:
ListNode(const T & o) : obj(o) { };
ListNode() { };
T obj;
ListNode *next;
ListNode *prev;
};
private:
ListNode *_Initialize()
{
ListNode *n = (ListNode *)malloc(sizeof(ListNode));
n->next = NULL;
n->prev = NULL;
return n;
}
public:
List() : m_Head(_Initialize()), m_Size(0)
{
}
List(const List &src) : m_Head(_Initialize()), m_Size(0)
{
iterator iter;
for (iter=src.begin(); iter!=src.end(); iter++)
push_back( (*iter) );
}
~List()
{
clear();
if (m_Head)
{
free(m_Head);
m_Head = NULL;
}
}
void push_back(const T &obj)
{
ListNode *node = new ListNode(obj);
if (!m_Head->prev)
{
//link in the node as the first item
node->next = m_Head;
node->prev = m_Head;
m_Head->prev = node;
m_Head->next = node;
} else {
node->prev = m_Head->prev;
node->next = m_Head;
m_Head->prev->next = node;
m_Head->prev = node;
}
m_Size++;
}
size_t size()
{
return m_Size;
}
void clear()
{
ListNode *node = m_Head->next;
ListNode *temp;
m_Head->next = NULL;
m_Head->prev = NULL;
while (node && node != m_Head)
{
temp = node->next;
delete node;
node = temp;
}
m_Size = 0;
}
bool empty()
{
return (m_Head->next == NULL);
}
T & back()
{
return m_Head->prev->obj;
}
private:
ListNode *m_Head;
size_t m_Size;
public:
class iterator
{
friend class List;
public:
iterator()
{
m_This = NULL;
}
iterator(const List &src)
{
m_This = src.m_Head;
}
iterator(ListNode *n) : m_This(n)
{
}
iterator(const iterator &where)
{
m_This = where.m_This;
}
iterator & operator--()
{
if (m_This)
m_This = m_This->prev;
return *this;
}
//pre increment
iterator & operator++()
{
if (m_This)
m_This = m_This->next;
return *this;
}
iterator operator++(int)
{
iterator old(*this);
if (m_This)
m_This = m_This->next;
return old;
}
T & operator * () const
{
return m_This->obj;
}
T & operator * ()
{
return m_This->obj;
}
T * operator -> () const
{
return &(m_This->obj);
}
bool operator != (iterator &where)
{
return (m_This != where.m_This);
}
bool operator ==(iterator &where)
{
return (m_This == where.m_This);
}
private:
ListNode *m_This;
};
public:
iterator begin() const
{
if (m_Size)
return iterator(m_Head->next);
else
return iterator(m_Head);
}
iterator end() const
{
return iterator(m_Head);
}
iterator erase(iterator &where)
{
ListNode *pNode = where.m_This;
iterator iter(where);
iter++;
//If we are both the head and tail...
if (m_Head->next == pNode && m_Head->prev == pNode)
{
m_Head->next = NULL;
m_Head->prev = NULL;
} else if (m_Head->next == pNode) {
//we are only the first
pNode->next->prev = m_Head;
m_Head->next = pNode->next;
} else if (m_Head->prev == pNode) {
//we are the tail
pNode->prev->next = m_Head;
m_Head->prev = pNode->prev;
} else {
//middle unlink
pNode->prev->next = pNode->next;
pNode->next->prev = pNode->prev;
}
delete pNode;
m_Size--;
return iter;
}
public:
void remove(const T & obj)
{
iterator b;
for (b=begin(); b!=end(); b++)
{
if ( (*b) == obj )
{
erase( b );
break;
}
}
}
template <typename U>
iterator find(const U & equ)
{
iterator iter;
for (iter=begin(); iter!=end(); iter++)
{
if ( (*iter) == equ )
return iter;
}
return end();
}
List & operator =(List &src)
{
iterator iter;
for (iter=src.begin(); iter!=src.end(); iter++)
push_back( (*iter) );
return *this;
}
};
#endif //_INCLUDE_CSDM_LIST_H

364
sourcehook/smm_string.h Executable file
View File

@ -0,0 +1,364 @@
/* ======== SourceMM ========
* Copyright (C) 2004-2005 Metamod:Source Development Team
* No warranties of any kind
*
* License: zlib/libpng
*
* Author(s): David "BAILOPAN" Anderson
* ============================
*/
/* AMX Mod X
*
* by the AMX Mod X Development Team
* originally developed by OLO
*/
#ifndef _INCLUDE_CSTRING_H
#define _INCLUDE_CSTRING_H
#include <string.h>
#include <stdio.h>
class String
{
public:
String()
{
v = NULL;
a_size = 0;
//assign("");
}
~String()
{
if (v)
delete [] v;
}
String(const char *src)
{
v = NULL;
a_size = 0;
assign(src);
}
String(String &src)
{
v = NULL;
a_size = 0;
assign(src.c_str());
}
const char *c_str() { return v?v:""; }
const char *c_str() const { return v?v:""; }
void append(const char *t)
{
Grow(size() + strlen(t) + 1);
strcat(v, t);
}
void append(const char c)
{
size_t len = size();
Grow(len + 2);
v[len] = c;
v[len + 1] = '\0';
}
void append(String &d)
{
append(d.c_str());
}
void assign(const String &src)
{
assign(src.c_str());
}
void assign(const char *d)
{
if (!d)
{
clear();
} else {
Grow(strlen(d) + 1, false);
strcpy(v, d);
}
}
void clear()
{
if (v)
v[0] = '\0';
}
int compare (const char *d)
{
if (!v)
return strcmp("", d);
else
return strcmp(v, d);
}
//Added this for amxx inclusion
bool empty()
{
if (!v)
return true;
if (v[0] == '\0')
return true;
return false;
}
size_t size()
{
if (v)
return strlen(v);
else
return 0;
}
int find(const char c, int index = 0)
{
size_t len = size();
if (len < 1)
return npos;
if (index >= (int)len || index < 0)
return npos;
unsigned int i = 0;
for (i=index; i<(int)len; i++)
{
if (v[i] == c)
{
return i;
}
}
return npos;
}
bool is_space(int c)
{
if (c == '\f' || c == '\n' ||
c == '\t' || c == '\r' ||
c == '\v' || c == ' ')
{
return true;
}
return false;
}
void trim()
{
if (!v)
return;
unsigned int i = 0;
unsigned int j = 0;
size_t len = strlen(v);
if (len == 1)
{
if (is_space(v[i]))
{
clear();
return;
}
}
unsigned char c0 = v[0];
if (is_space(c0))
{
for (i=0; i<len; i++)
{
if (!is_space(v[i]) || (is_space(v[i]) && ((unsigned char)i==len-1)))
{
erase(0, i);
break;
}
}
}
len = strlen(v);
if (len < 1)
{
return;
}
if (is_space(v[len-1]))
{
for (i=len-1; i>=0; i--)
{
if (!is_space(v[i])
|| (is_space(v[i]) && i==0))
{
erase(i+1, j);
break;
}
j++;
}
}
if (len == 1)
{
if (is_space(v[0]))
{
clear();
return;
}
}
}
void erase(unsigned int start, int num = npos)
{
if (!v)
return;
unsigned int i = 0;
size_t len = size();
//check for bounds
if (num == npos || start+num > len-num+1)
num = len - start;
//do the erasing
bool copyflag = false;
for (i=0; i<len; i++)
{
if (i>=start && i<start+num)
{
if (i+num < len)
{
v[i] = v[i+num];
} else {
v[i] = 0;
}
copyflag = true;
} else if (copyflag) {
if (i+num < len)
{
v[i] = v[i+num];
} else {
v[i] = 0;
}
}
}
len -= num;
v[len] = 0;
}
String substr(unsigned int index, int num = npos)
{
if (!v)
{
String b("");
return b;
}
String ns;
size_t len = size();
if (index >= len || !v)
return ns;
if (num == npos)
{
num = len - index;
} else if (index+num >= len) {
num = len - index;
}
unsigned int i = 0, j=0;
unsigned int nslen = num + 2;
ns.Grow(nslen);
for (i=index; i<index+num; i++)
ns.append(v[i]);
return ns;
}
void toLower()
{
if (!v)
return;
unsigned int i = 0;
size_t len = strlen(v);
for (i=0; i<len; i++)
{
if (v[i] >= 65 && v[i] <= 90)
v[i] &= ~(1<<5);
}
}
String & operator = (const String &src)
{
assign(src);
return *this;
}
String & operator = (const char *src)
{
assign(src);
return *this;
}
char operator [] (unsigned int index)
{
if (index > size() || !v)
{
return -1;
} else {
return v[index];
}
}
int at(int a)
{
if (a < 0 || a >= (int)size() || !v)
return -1;
return v[a];
}
bool at(int at, char c)
{
if (at < 0 || at >= (int)size() || !v)
return false;
v[at] = c;
return true;
}
private:
void Grow(unsigned int d, bool copy=true)
{
if (d <= a_size)
return;
char *n = new char[d + 1];
if (copy && v)
strcpy(n, v);
if (v)
delete [] v;
else
strcpy(n, "");
v = n;
a_size = d + 1;
}
char *v;
unsigned int a_size;
public:
static const int npos = -1;
};
#endif //_INCLUDE_CSTRING_H

97
sourcehook/smm_vector.h Normal file
View File

@ -0,0 +1,97 @@
/* ======== SourceMM ========
* Copyright (C) 2004-2005 Metamod:Source Development Team
* No warranties of any kind
*
* License: zlib/libpng
*
* Author(s): David "BAILOPAN" Anderson
* ============================
*/
#ifndef _INCLUDE_SMMVECTOR_H
#define _INCLUDE_SMMVECTOR_H
template <class T>
class DynVector
{
public:
DynVector()
{
m_Data = NULL;
m_CurrentSize = 0;
m_UsedSize = 0;
}
~DynVector()
{
clear();
}
void clear()
{
if (m_Data)
{
delete [] m_Data;
m_Data = NULL;
}
m_UsedSize = 0;
m_CurrentSize = 0;
}
void resize(size_t size)
{
if (!size)
clear();
else
Grow(size);
m_UsedSize = size;
}
DynVector & operator =(DynVector &src)
{
Grow(src.m_UsedSize + 1);
for (size_t i=0; i<src.m_UsedSize; i++)
m_Data[i] = src.m_Data[i];
m_UsedSize = src.m_UsedSize;
return *this;
}
void push_back(const T & t)
{
GrowIfNeeded();
m_Data[m_UsedSize-1] = t;
}
size_t size()
{
return m_UsedSize;
}
T & at(size_t i)
{
return m_Data[i];
}
T & operator [](size_t i)
{
return at(i);
}
private:
void Grow(size_t size)
{
T * data = new T[size];
if (m_Data)
{
size_t copy = (m_UsedSize > size) ? size : m_UsedSize;
for (size_t i=0; i<copy; i++)
data[i] = m_Data[i];
delete [] m_Data;
}
m_Data = data;
m_CurrentSize = size;
}
void GrowIfNeeded()
{
if (m_UsedSize + 1 > m_CurrentSize)
Grow((m_UsedSize+1) * 2);
m_UsedSize++;
}
private:
T * m_Data;
size_t m_CurrentSize;
size_t m_UsedSize;
};
#endif //_INCLUDE_SMMVECTOR_H

View File

@ -14,7 +14,6 @@
* @brief Contains the implementation of the SourceHook API
*/
#include <algorithm>
#include "sourcehook_impl.h"
namespace SourceHook
@ -58,7 +57,7 @@ namespace SourceHook
for (HookManagerInfo::VfnPtr::IfaceListIter iface_iter = vfnptr_iter->ifaces.begin();
iface_iter != vfnptr_iter->ifaces.end(); ++iface_iter)
{
std::list<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hook_iter;
List<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hook_iter;
TMP_CHECK_LIST(hooks_pre);
TMP_CHECK_LIST(hooks_post);
}
@ -71,7 +70,7 @@ namespace SourceHook
void CSourceHookImpl::UnloadPlugin(Plugin plug)
{
// 1) Manually remove all hooks by this plugin
std::list<RemoveHookInfo> hookstoremove;
List<RemoveHookInfo> hookstoremove;
HookManInfoList::iterator hmil_iter;
#define TMP_CHECK_LIST(name, ispost) \
@ -87,7 +86,7 @@ namespace SourceHook
for (HookManagerInfo::VfnPtr::IfaceListIter iface_iter = vfnptr_iter->ifaces.begin();
iface_iter != vfnptr_iter->ifaces.end(); ++iface_iter)
{
std::list<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hook_iter;
List<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hook_iter;
TMP_CHECK_LIST(hooks_pre, false);
TMP_CHECK_LIST(hooks_post, true);
}
@ -95,7 +94,7 @@ namespace SourceHook
}
#undef TMP_CHECK_LIST
for (std::list<RemoveHookInfo>::iterator rmiter = hookstoremove.begin(); rmiter != hookstoremove.end(); ++rmiter)
for (List<RemoveHookInfo>::iterator rmiter = hookstoremove.begin(); rmiter != hookstoremove.end(); ++rmiter)
RemoveHook(*rmiter);
// 2) Other plugins may use hook managers in this plugin.
@ -164,7 +163,7 @@ namespace SourceHook
void CSourceHookImpl::CompleteShutdown()
{
std::list<RemoveHookInfo> hookstoremove;
List<RemoveHookInfo> hookstoremove;
#define TMP_CHECK_LIST(name, ispost) \
for (hook_iter = iface_iter->name.begin(); hook_iter != iface_iter->name.end(); ++hook_iter) \
hookstoremove.push_back(RemoveHookInfo(hook_iter->plug, iface_iter->ptr, \
@ -177,7 +176,7 @@ namespace SourceHook
for (HookManagerInfo::VfnPtr::IfaceListIter iface_iter = vfnptr_iter->ifaces.begin();
iface_iter != vfnptr_iter->ifaces.end(); ++iface_iter)
{
std::list<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hook_iter;
List<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hook_iter;
TMP_CHECK_LIST(hooks_pre, false);
TMP_CHECK_LIST(hooks_post, true);
}
@ -185,7 +184,7 @@ namespace SourceHook
}
#undef TMP_CHECK_LIST
for (std::list<RemoveHookInfo>::iterator rmiter = hookstoremove.begin(); rmiter != hookstoremove.end(); ++rmiter)
for (List<RemoveHookInfo>::iterator rmiter = hookstoremove.begin(); rmiter != hookstoremove.end(); ++rmiter)
RemoveHook(*rmiter);
m_HookMans.clear();
@ -227,8 +226,7 @@ namespace SourceHook
reinterpret_cast<char*>(adjustediface) + tmp.vtbl_offs);
void *cur_vfnptr = reinterpret_cast<void*>(cur_vtptr + tmp.vtbl_idx);
HookManagerInfo::VfnPtrListIter vfnptr_iter = std::find(
hookman->vfnptrs.begin(), hookman->vfnptrs.end(), cur_vfnptr);
HookManagerInfo::VfnPtrListIter vfnptr_iter = hookman->vfnptrs.find(cur_vfnptr);
if (vfnptr_iter == hookman->vfnptrs.end())
{
@ -253,8 +251,7 @@ namespace SourceHook
ApplyCallClassPatches(adjustediface, tmp.vtbl_offs, tmp.vtbl_idx, vfp.orig_entry);
}
HookManagerInfo::VfnPtr::IfaceListIter iface_iter = std::find(
vfnptr_iter->ifaces.begin(), vfnptr_iter->ifaces.end(), adjustediface);
HookManagerInfo::VfnPtr::IfaceListIter iface_iter = vfnptr_iter->ifaces.find(adjustediface);
if (iface_iter == vfnptr_iter->ifaces.end())
{
// Add a new one
@ -311,18 +308,19 @@ namespace SourceHook
reinterpret_cast<char*>(adjustediface) + tmp.vtbl_offs);
void *cur_vfnptr = reinterpret_cast<void*>(cur_vtptr + tmp.vtbl_idx);
HookManagerInfo::VfnPtrListIter vfnptr_iter = std::find(hookman->vfnptrs.begin(), hookman->vfnptrs.end(), cur_vfnptr);
HookManagerInfo::VfnPtrListIter vfnptr_iter = hookman->vfnptrs.find(cur_vfnptr);
if (vfnptr_iter == hookman->vfnptrs.end())
return false;
for (HookManagerInfo::VfnPtr::IfaceListIter iface_iter = vfnptr_iter->ifaces.begin();
iface_iter != vfnptr_iter->ifaces.end();)
{
std::list<HookManagerInfo::VfnPtr::Iface::Hook> &hooks =
List<HookManagerInfo::VfnPtr::Iface::Hook> &hooks =
post ? iface_iter->hooks_post : iface_iter->hooks_pre;
bool erase;
for (std::list<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hookiter = hooks.begin();
for (List<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hookiter = hooks.begin();
hookiter != hooks.end(); erase ? hookiter = hooks.erase(hookiter) : ++hookiter)
{
erase = hookiter->plug == plug && hookiter->handler->IsEqual(handler) &&
@ -386,7 +384,7 @@ namespace SourceHook
void CSourceHookImpl::ReleaseCallClass(GenericCallClass *ptr)
{
Impl_CallClassList::iterator iter = std::find(m_CallClasses.begin(), m_CallClasses.end(), ptr);
Impl_CallClassList::iterator iter = m_CallClasses.find(ptr);
if (iter == m_CallClasses.end())
return;
--iter->refcounter;
@ -495,12 +493,12 @@ namespace SourceHook
for (HookManagerInfo::VfnPtr::IfaceListIter ifaceiter = vfnptr_iter->ifaces.begin();
ifaceiter != vfnptr_iter->ifaces.end(); ++ifaceiter)
{
for (std::list<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hookiter = ifaceiter->hooks_pre.begin();
for (List<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hookiter = ifaceiter->hooks_pre.begin();
hookiter != ifaceiter->hooks_pre.end(); ++hookiter)
if (plug == hookiter->plug)
hookiter->paused = true;
for (std::list<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hookiter = ifaceiter->hooks_post.begin();
for (List<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hookiter = ifaceiter->hooks_post.begin();
hookiter != ifaceiter->hooks_post.end(); ++hookiter)
if (plug == hookiter->plug)
hookiter->paused = true;
@ -516,12 +514,12 @@ namespace SourceHook
for (HookManagerInfo::VfnPtr::IfaceListIter ifaceiter = vfnptr_iter->ifaces.begin();
ifaceiter != vfnptr_iter->ifaces.end(); ++ifaceiter)
{
for (std::list<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hookiter = ifaceiter->hooks_pre.begin();
for (List<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hookiter = ifaceiter->hooks_pre.begin();
hookiter != ifaceiter->hooks_pre.end(); ++hookiter)
if (plug == hookiter->plug)
hookiter->paused = false;
for (std::list<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hookiter = ifaceiter->hooks_post.begin();
for (List<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hookiter = ifaceiter->hooks_post.begin();
hookiter != ifaceiter->hooks_post.end(); ++hookiter)
if (plug == hookiter->plug)
hookiter->paused = false;

View File

@ -68,10 +68,9 @@
#include "FastDelegate.h"
#include "sh_memfuncinfo.h"
#include "sh_memory.h"
#include <list>
#include "smm_list.h"
#include <vector>
#include <map>
#include <algorithm>
// Good old metamod!
@ -185,8 +184,8 @@ namespace SourceHook
int thisptr_offs; //!< This pointer offset
};
void *ptr; //!< Pointer to the interface instance
std::list<Hook> hooks_pre; //!< A list of pre-hooks
std::list<Hook> hooks_post; //!< A list of post-hooks
List<Hook> hooks_pre; //!< A list of pre-hooks
List<Hook> hooks_post; //!< A list of post-hooks
bool operator ==(void *other) const
{
return ptr == other;
@ -196,7 +195,7 @@ namespace SourceHook
void *vfnptr; //!< Pointer to the function
void *orig_entry; //!< The original vtable entry
typedef std::list<Iface> IfaceList;
typedef List<Iface> IfaceList;
typedef IfaceList::iterator IfaceListIter;
IfaceList ifaces; //!< List of interface pointers
@ -214,7 +213,7 @@ namespace SourceHook
void *hookfunc_vfnptr; //!< Pointer to the hookfunc impl
typedef std::list<VfnPtr> VfnPtrList;
typedef List<VfnPtr> VfnPtrList;
typedef VfnPtrList::iterator VfnPtrListIter;
VfnPtrList vfnptrs; //!< List of hooked interfaces
};
@ -467,8 +466,7 @@ inline void SH_RELEASE_CALLCLASS_R(SourceHook::ISourceHook *shptr, SourceHook::C
void *ourvfnptr = reinterpret_cast<void*>( \
*reinterpret_cast<void***>(reinterpret_cast<char*>(this) + ms_HI->vtbl_offs) + ms_HI->vtbl_idx); \
\
HookManagerInfo::VfnPtrListIter vfptriter = std::find(ms_HI->vfnptrs.begin(), \
ms_HI->vfnptrs.end(), ourvfnptr); \
HookManagerInfo::VfnPtrListIter vfptriter = ms_HI->vfnptrs.find(ourvfnptr); \
if (vfptriter == ms_HI->vfnptrs.end()) \
{ \
/* Bleh? Should be impossible! */ \
@ -476,7 +474,7 @@ inline void SH_RELEASE_CALLCLASS_R(SourceHook::ISourceHook *shptr, SourceHook::C
} \
HookManagerInfo::VfnPtr &vfnptr = *vfptriter; \
/* 2) Find the iface */ \
HookManagerInfo::VfnPtr::IfaceListIter ifiter = std::find(vfnptr.ifaces.begin(), vfnptr.ifaces.end(), this); \
HookManagerInfo::VfnPtr::IfaceListIter ifiter = vfnptr.ifaces.find(this); \
if (ifiter == vfnptr.ifaces.end()) \
{ \
/* The iface info was not found. Redirect the call to the original function. */ \
@ -486,8 +484,8 @@ inline void SH_RELEASE_CALLCLASS_R(SourceHook::ISourceHook *shptr, SourceHook::C
} \
HookManagerInfo::VfnPtr::Iface &ci = *ifiter; \
/* 2) Declare some vars and set it up */ \
std::list<HookManagerInfo::VfnPtr::Iface::Hook> &prelist = ci.hooks_pre; \
std::list<HookManagerInfo::VfnPtr::Iface::Hook> &postlist = ci.hooks_post; \
List<HookManagerInfo::VfnPtr::Iface::Hook> &prelist = ci.hooks_pre; \
List<HookManagerInfo::VfnPtr::Iface::Hook> &postlist = ci.hooks_post; \
rettype orig_ret; \
rettype override_ret; \
rettype plugin_ret; \
@ -501,7 +499,7 @@ inline void SH_RELEASE_CALLCLASS_R(SourceHook::ISourceHook *shptr, SourceHook::C
#define SH_CALL_HOOKS(post, params) \
prev_res = MRES_IGNORED; \
for (std::list<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
for (List<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
{ \
if (hiter->paused) continue; \
cur_res = MRES_IGNORED; \
@ -544,8 +542,7 @@ inline void SH_RELEASE_CALLCLASS_R(SourceHook::ISourceHook *shptr, SourceHook::C
void *ourvfnptr = reinterpret_cast<void*>( \
*reinterpret_cast<void***>(reinterpret_cast<char*>(this) + ms_HI->vtbl_offs) + ms_HI->vtbl_idx); \
\
HookManagerInfo::VfnPtrListIter vfptriter = std::find(ms_HI->vfnptrs.begin(), \
ms_HI->vfnptrs.end(), ourvfnptr); \
HookManagerInfo::VfnPtrListIter vfptriter = ms_HI->vfnptrs.find(ourvfnptr); \
if (vfptriter == ms_HI->vfnptrs.end()) \
{ \
/* Bleh? Should be impossible! */ \
@ -553,7 +550,7 @@ inline void SH_RELEASE_CALLCLASS_R(SourceHook::ISourceHook *shptr, SourceHook::C
} \
HookManagerInfo::VfnPtr &vfnptr = *vfptriter; \
/* 2) Find the iface */ \
HookManagerInfo::VfnPtr::IfaceListIter ifiter = std::find(vfnptr.ifaces.begin(), vfnptr.ifaces.end(), this); \
HookManagerInfo::VfnPtr::IfaceListIter ifiter = vfnptr.ifaces.find(this); \
if (ifiter == vfnptr.ifaces.end()) \
{ \
/* The iface info was not found. Redirect the call to the original function. */ \
@ -564,8 +561,8 @@ inline void SH_RELEASE_CALLCLASS_R(SourceHook::ISourceHook *shptr, SourceHook::C
} \
HookManagerInfo::VfnPtr::Iface &ci = *ifiter; \
/* 2) Declare some vars and set it up */ \
std::list<HookManagerInfo::VfnPtr::Iface::Hook> &prelist = ci.hooks_pre; \
std::list<HookManagerInfo::VfnPtr::Iface::Hook> &postlist = ci.hooks_post; \
List<HookManagerInfo::VfnPtr::Iface::Hook> &prelist = ci.hooks_pre; \
List<HookManagerInfo::VfnPtr::Iface::Hook> &postlist = ci.hooks_post; \
META_RES &cur_res = SH_GLOB_SHPTR->GetCurResRef(); \
META_RES &prev_res = SH_GLOB_SHPTR->GetPrevResRef(); \
META_RES &status = SH_GLOB_SHPTR->GetStatusRef(); \
@ -575,7 +572,7 @@ inline void SH_RELEASE_CALLCLASS_R(SourceHook::ISourceHook *shptr, SourceHook::C
#define SH_CALL_HOOKS_void(post, params) \
prev_res = MRES_IGNORED; \
for (std::list<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
for (List<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
{ \
if (hiter->paused) continue; \
cur_res = MRES_IGNORED; \

View File

@ -51,7 +51,7 @@ namespace SourceHook
/**
* @brief A list of HookManagerInfo structures
*/
typedef std::list<HookManagerInfo> HookManInfoList;
typedef List<HookManagerInfo> HookManInfoList;
struct CallClassInfo
{
@ -65,7 +65,7 @@ namespace SourceHook
/**
* @brief A list of CallClass structures
*/
typedef std::list<CallClassInfo> Impl_CallClassList;
typedef List<CallClassInfo> Impl_CallClassList;
Impl_CallClassList m_CallClasses; //!< A list of already generated callclasses
HookManInfoList m_HookMans; //!< A list of hook managers

View File

@ -5,6 +5,8 @@
#include <iostream>
#include <string>
#include <list>
#include "sourcehook_impl.h"
#include "smm_list.h"
using namespace std;

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding = "Windows-1252"?>
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.00"
Version="7.10"
Name="test"
ProjectGUID="{456BBA64-FF14-4292-8443-3BA79E4D84CC}"
Keyword="Win32Proj">
@ -54,8 +54,14 @@
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
@ -107,8 +113,14 @@
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="DebugOpt|Win32"
@ -159,8 +171,14 @@
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Debug_NoDebugRuntimeLib|Win32"
@ -206,10 +224,18 @@
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
@ -232,10 +258,19 @@
<File
RelativePath="test4.cpp">
</File>
<File
RelativePath=".\testbail.cpp">
</File>
<File
RelativePath=".\testbail2.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc">
<File
RelativePath="..\..\sourcemm\smm_list.h">
</File>
<File
RelativePath="..\sourcehook.h">
</File>

View File

@ -395,6 +395,7 @@ bool TestBasic(std::string &error)
// 1) Get a call class and call the member through it and normally
SourceHook::CallClass<Test> *cc = SH_GET_CALLCLASS(pTest);
ADD_STATE(State_F1_CallClassGenerated);
SH_CALL(cc, &Test::F1)();
@ -445,6 +446,7 @@ bool TestBasic(std::string &error)
// 4) Rerequest the callclass
SH_RELEASE_CALLCLASS(cc);
ADD_STATE(State_F1_CallClassReleased);
cc2 = SH_GET_CALLCLASS(pTest);
ADD_STATE(State_F1_CallClassGenerated);

View File

@ -5,6 +5,8 @@
#include "sourcehook_impl.h"
#include "testevents.h"
#include <stdarg.h>
#include <list>
#include <algorithm>
void ___TestBail2();

View File

@ -14,6 +14,7 @@
#include <typeinfo>
#include <stdarg.h>
#include <iostream>
#include <list>
#include <string>
extern bool g_Verbose;