SourceMod SDK  1.7
vtable_hook_helper.h
1 
32 #ifndef _INCLUDE_VTABLE_HOOK_HELPER_H_
33 #define _INCLUDE_VTABLE_HOOK_HELPER_H_
34 
36 {
37 public:
38  CVTableHook(void *takenclass)
39  {
40  this->vtableptr = *reinterpret_cast<void ***>(takenclass);
41  this->hookid = 0;
42  }
43 
44  CVTableHook(void *vtable, int hook)
45  {
46  this->vtableptr = vtable;
47  this->hookid = hook;
48  }
49 
50  CVTableHook(CVTableHook &other)
51  {
52  this->vtableptr = other.vtableptr;
53  this->hookid = other.hookid;
54 
55  other.hookid = 0;
56  }
57 
58  CVTableHook(CVTableHook *other)
59  {
60  this->vtableptr = other->vtableptr;
61  this->hookid = other->hookid;
62 
63  other->hookid = 0;
64  }
65 
66  ~CVTableHook()
67  {
68  if (this->hookid)
69  {
70  SH_REMOVE_HOOK_ID(this->hookid);
71  this->hookid = 0;
72  }
73  }
74 public:
75  void *GetVTablePtr(void)
76  {
77  return this->vtableptr;
78  }
79 
80  void SetHookID(int hook)
81  {
82  this->hookid = hook;
83  }
84 
85  bool IsHooked(void)
86  {
87  return (this->hookid != 0);
88  }
89 public:
90  bool operator == (CVTableHook &other)
91  {
92  return (this->GetVTablePtr() == other.GetVTablePtr());
93  }
94 
95  bool operator == (CVTableHook *other)
96  {
97  return (this->GetVTablePtr() == other->GetVTablePtr());
98  }
99 
100  bool operator != (CVTableHook &other)
101  {
102  return (this->GetVTablePtr() != other.GetVTablePtr());
103  }
104 
105  bool operator != (CVTableHook *other)
106  {
107  return (this->GetVTablePtr() != other->GetVTablePtr());
108  }
109 private:
110  void *vtableptr;
111  int hookid;
112 };
113 
114 #endif //_INCLUDE_VTABLE_HOOK_HELPER_H_
Definition: vtable_hook_helper.h:35