Fixed MetamodVersionInfo::GetGameDir always returning NULL or garbage.
1 /* ======== SourceHook ========
2 * Copyright (C) 2004-2010 Metamod:Source Development Team
3 * No warranties of any kind
7 * Author(s): Pavol "PM OnoTo" Marko
8 * Contributors: Scott "Damaged Soul" Ehlert
9 * ============================
12 #include "sourcehook_impl.h"
18 CHookIDManager::CHookIDManager()
22 int CHookIDManager::New(const CProto &proto, int vtbl_offs, int vtbl_idx, void *vfnptr,
23 void *adjustediface, Plugin plug, int thisptr_offs, ISHDelegate *handler, bool post)
25 Entry tmp(proto, vtbl_offs, vtbl_idx, vfnptr, adjustediface, plug, thisptr_offs, handler, post);
27 size_t cursize = m_Entries.size();
28 for (size_t i = 0; i < cursize; ++i)
30 if (m_Entries[i].isfree)
33 return static_cast<int>(i) + 1;
37 m_Entries.push_back(tmp);
38 return static_cast<int>(m_Entries.size()); // return size() because hookid = id+1 anyway
41 bool CHookIDManager::Remove(int hookid)
43 int realid = hookid - 1;
44 if (realid < 0 || realid >= static_cast<int>(m_Entries.size()) || m_Entries[realid].isfree)
47 m_Entries[realid].isfree = true;
49 // :TODO: remove free ids from back sometimes ??
54 const CHookIDManager::Entry * CHookIDManager::QueryHook(int hookid)
56 int realid = hookid - 1;
57 if (realid < 0 || realid >= static_cast<int>(m_Entries.size()) || m_Entries[realid].isfree)
60 return &m_Entries[realid];
63 void CHookIDManager::FindAllHooks(CVector<int> &output, const CProto &proto, int vtbl_offs,
64 int vtbl_idx, void *adjustediface, Plugin plug, int thisptr_offs, ISHDelegate *handler, bool post)
66 // oh my god, a lot of parameters...
67 size_t cursize = m_Entries.size();
68 for (size_t i = 0; i < cursize; ++i)
70 if (!m_Entries[i].isfree && m_Entries[i].proto == proto && m_Entries[i].vtbl_offs == vtbl_offs &&
71 m_Entries[i].vtbl_idx == vtbl_idx && m_Entries[i].adjustediface == adjustediface && m_Entries[i].plug == plug &&
72 m_Entries[i].thisptr_offs == thisptr_offs && m_Entries[i].handler->IsEqual(handler) && m_Entries[i].post == post)
74 output.push_back(static_cast<int>(i) + 1);
79 void CHookIDManager::FindAllHooks(CVector<int> &output)
81 size_t cursize = m_Entries.size();
82 for (size_t i = 0; i < cursize; ++i)
84 if (!m_Entries[i].isfree)
85 output.push_back(static_cast<int>(i) + 1);
89 void CHookIDManager::FindAllHooks(CVector<int> &output, Plugin plug)
91 size_t cursize = m_Entries.size();
92 for (size_t i = 0; i < cursize; ++i)
94 if (!m_Entries[i].isfree && m_Entries[i].plug == plug)
95 output.push_back(static_cast<int>(i) + 1);
100 void CHookIDManager::RemoveAll(void *vfnptr)
102 size_t cursize = m_Entries.size();
103 for (size_t i = 0; i < cursize; ++i)
105 if (!m_Entries[i].isfree && m_Entries[i].vfnptr == vfnptr)
106 m_Entries[i].isfree = true;