FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Source.Python/src/core/modules/memory/memory_hooks.cpp at master · servers-tf/Source.Python · GitHub
servers-tf
Source.Python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Source.Python
/
src
/
core
/
modules
/
memory
/
memory_hooks.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
234 lines (210 loc) · 9.82 KB
Breadcrumbs
Source.Python
/
src
/
core
/
modules
/
memory
/
memory_hooks.cpp
Copy path
File metadata and controls
234 lines (210 loc) · 9.82 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
*
* =============================================================================
* Source Python
* Copyright (C) 2012-2015 Source Python Development Team. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the Source Python Team gives you permission
* to link the code of this program (as well as its derivative works) to
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, the Source.Python
* Development Team grants this exception to all derivative works.
*/
// ============================================================================
//
>> INCLUDES
// ============================================================================
#
include
"
memory_hooks.h
"
#
include
"
memory_utilities.h
"
#
include
"
memory_pointer.h
"
#
include
"
utilities/wrap_macros.h
"
#
include
"
utilities/sp_util.h
"
#
include
"
boost/python.hpp
"
using
namespace
boost
::python
;
// ============================================================================
//
>> GLOBAL VARIABLES
// ============================================================================
//
g_mapCallbacks[<CHook *>][<HookType_t>] -> [<object>, <object>, ...]
std::map<CHook *, std::map<HookType_t, std::list<object> > > g_mapCallbacks;
bool
g_HooksDisabled;
// ============================================================================
//
>> HELPER FUNCTIONS
// ============================================================================
template
<
class
T
>
void
SetReturnValue
(CHook* pHook, object value)
{
T val = extract<T>(value);
pHook->
SetReturnValue
<T>(val);
}
template
<
class
T
>
object
GetReturnValue
(CHook* pHook)
{
return
object
(pHook->
GetReturnValue
<T>());
}
template
<
class
T
>
void
SetArgument
(CHook* pHook,
int
iIndex, object value)
{
T val = extract<T>(value);
pHook->
SetArgument
<T>(iIndex, val);
}
template
<
class
T
>
object
GetArgument
(CHook* pHook,
int
iIndex)
{
return
object
(pHook->
GetArgument
<T>(iIndex));
}
// ============================================================================
//
>> SP_HookHandler
// ============================================================================
bool
SP_HookHandler
(HookType_t eHookType, CHook* pHook)
{
if
(g_HooksDisabled)
return
false
;
std::list<object> callbacks = g_mapCallbacks[pHook][eHookType];
//
No need to do all this stuff, if there is no callback registered
if
(callbacks.
empty
())
return
false
;
object retval;
if
(eHookType ==
HOOKTYPE_POST
)
{
switch
(pHook->
m_pCallingConvention
->
m_returnType
)
{
case
DATA_TYPE_VOID
: retval =
object
();
break
;
case
DATA_TYPE_BOOL
: retval = GetReturnValue<
bool
>(pHook);
break
;
case
DATA_TYPE_CHAR
: retval = GetReturnValue<
char
>(pHook);
break
;
case
DATA_TYPE_UCHAR
: retval = GetReturnValue<
unsigned
char
>(pHook);
break
;
case
DATA_TYPE_SHORT
: retval = GetReturnValue<
short
>(pHook);
break
;
case
DATA_TYPE_USHORT
: retval = GetReturnValue<
unsigned
short
>(pHook);
break
;
case
DATA_TYPE_INT
: retval = GetReturnValue<
int
>(pHook);
break
;
case
DATA_TYPE_UINT
: retval = GetReturnValue<
unsigned
int
>(pHook);
break
;
case
DATA_TYPE_LONG
: retval = GetReturnValue<
long
>(pHook);
break
;
case
DATA_TYPE_ULONG
: retval = GetReturnValue<
unsigned
long
>(pHook);
break
;
case
DATA_TYPE_LONG_LONG
: retval = GetReturnValue<
long
long
>(pHook);
break
;
case
DATA_TYPE_ULONG_LONG
: retval = GetReturnValue<
unsigned
long
long
>(pHook);
break
;
case
DATA_TYPE_FLOAT
: retval = GetReturnValue<
float
>(pHook);
break
;
case
DATA_TYPE_DOUBLE
: retval = GetReturnValue<
double
>(pHook);
break
;
case
DATA_TYPE_POINTER
: retval =
object
(
CPointer
(pHook->
GetReturnValue
<
unsigned
long
>()));
break
;
case
DATA_TYPE_STRING
: retval = GetReturnValue<
const
char
*>(pHook);
break
;
default
:
BOOST_RAISE_EXCEPTION
(PyExc_TypeError,
"
Unknown type.
"
);
}
}
CStackData stackdata =
CStackData
(pHook);
bool
bOverride =
false
;
for
(std::list<object>::iterator it=callbacks.
begin
(); it != callbacks.
end
(); ++it)
{
BEGIN_BOOST_PY
()
object pyretval;
if
(eHookType ==
HOOKTYPE_PRE
)
pyretval = (*it)(stackdata);
else
pyretval = (*it)(stackdata, retval);
if
(!pyretval.
is_none
())
{
bOverride =
true
;
switch
(pHook->
m_pCallingConvention
->
m_returnType
)
{
case
DATA_TYPE_VOID
:
break
;
case
DATA_TYPE_BOOL
: SetReturnValue<
bool
>(pHook, pyretval);
break
;
case
DATA_TYPE_CHAR
: SetReturnValue<
char
>(pHook, pyretval);
break
;
case
DATA_TYPE_UCHAR
: SetReturnValue<
unsigned
>(pHook, pyretval);
break
;
case
DATA_TYPE_SHORT
: SetReturnValue<
short
>(pHook, pyretval);
break
;
case
DATA_TYPE_USHORT
: SetReturnValue<
unsigned
short
>(pHook, pyretval);
break
;
case
DATA_TYPE_INT
: SetReturnValue<
int
>(pHook, pyretval);
break
;
case
DATA_TYPE_UINT
: SetReturnValue<
unsigned
int
>(pHook, pyretval);
break
;
case
DATA_TYPE_LONG
: SetReturnValue<
long
>(pHook, pyretval);
break
;
case
DATA_TYPE_ULONG
: SetReturnValue<
unsigned
long
>(pHook, pyretval);
break
;
case
DATA_TYPE_LONG_LONG
: SetReturnValue<
long
long
>(pHook, pyretval);
break
;
case
DATA_TYPE_ULONG_LONG
: SetReturnValue<
unsigned
long
long
>(pHook, pyretval);
break
;
case
DATA_TYPE_FLOAT
: SetReturnValue<
float
>(pHook, pyretval);
break
;
case
DATA_TYPE_DOUBLE
: SetReturnValue<
double
>(pHook, pyretval);
break
;
case
DATA_TYPE_POINTER
:
{
CPointer* pPtr =
ExtractPointer
(pyretval);
pHook->
SetReturnValue
<
unsigned
long
>(pPtr->
m_ulAddr
);
}
break
;
case
DATA_TYPE_STRING
: SetReturnValue<
const
char
*>(pHook, pyretval);
break
;
default
:
BOOST_RAISE_EXCEPTION
(PyExc_TypeError,
"
Unknown type.
"
)
}
}
END_BOOST_PY_NORET
()
}
return
bOverride;
}
// ============================================================================
//
>> CStackData
// ============================================================================
CStackData::CStackData
(CHook* pHook)
{
m_pHook = pHook;
}
object
CStackData::GetItem
(
unsigned
int
iIndex)
{
if
(iIndex >= (
unsigned
int
) m_pHook->
m_pCallingConvention
->
m_vecArgTypes
.
size
())
BOOST_RAISE_EXCEPTION
(PyExc_IndexError,
"
Index out of range.
"
)
//
Argument already cached?
object retval = m_mapCache[iIndex];
if
(retval)
return
retval;
switch
(m_pHook->
m_pCallingConvention
->
m_vecArgTypes
[iIndex])
{
case
DATA_TYPE_BOOL
: retval = GetArgument<
bool
>(m_pHook, iIndex);
break
;
case
DATA_TYPE_CHAR
: retval = GetArgument<
char
>(m_pHook, iIndex);
break
;
case
DATA_TYPE_UCHAR
: retval = GetArgument<
unsigned
char
>(m_pHook, iIndex);
break
;
case
DATA_TYPE_SHORT
: retval = GetArgument<
short
>(m_pHook, iIndex);
break
;
case
DATA_TYPE_USHORT
: retval = GetArgument<
unsigned
short
>(m_pHook, iIndex);
break
;
case
DATA_TYPE_INT
: retval = GetArgument<
int
>(m_pHook, iIndex);
break
;
case
DATA_TYPE_UINT
: retval = GetArgument<
unsigned
int
>(m_pHook, iIndex);
break
;
case
DATA_TYPE_LONG
: retval = GetArgument<
long
>(m_pHook, iIndex);
break
;
case
DATA_TYPE_ULONG
: retval = GetArgument<
unsigned
long
>(m_pHook, iIndex);
break
;
case
DATA_TYPE_LONG_LONG
: retval = GetArgument<
long
long
>(m_pHook, iIndex);
break
;
case
DATA_TYPE_ULONG_LONG
: retval = GetArgument<
unsigned
long
long
>(m_pHook, iIndex);
break
;
case
DATA_TYPE_FLOAT
: retval = GetArgument<
float
>(m_pHook, iIndex);
break
;
case
DATA_TYPE_DOUBLE
: retval = GetArgument<
double
>(m_pHook, iIndex);
break
;
case
DATA_TYPE_POINTER
: retval =
object
(
CPointer
(m_pHook->
GetArgument
<
unsigned
long
>(iIndex)));
break
;
case
DATA_TYPE_STRING
: retval = GetArgument<
const
char
*>(m_pHook, iIndex);
break
;
default
:
BOOST_RAISE_EXCEPTION
(PyExc_TypeError,
"
Unknown type.
"
)
break
;
}
m_mapCache[iIndex] = retval;
return
retval;
}
void
CStackData::SetItem
(
unsigned
int
iIndex, object value)
{
if
(iIndex >= (
unsigned
int
) m_pHook->
m_pCallingConvention
->
m_vecArgTypes
.
size
())
BOOST_RAISE_EXCEPTION
(PyExc_IndexError,
"
Index out of range.
"
)
//
Update cache
m_mapCache[iIndex] = value;
switch
(m_pHook->
m_pCallingConvention
->
m_vecArgTypes
[iIndex])
{
case
DATA_TYPE_BOOL
: SetArgument<
bool
>(m_pHook, iIndex, value);
break
;
case
DATA_TYPE_CHAR
: SetArgument<
char
>(m_pHook, iIndex, value);
break
;
case
DATA_TYPE_UCHAR
: SetArgument<
unsigned
char
>(m_pHook, iIndex, value);
break
;
case
DATA_TYPE_SHORT
: SetArgument<
short
>(m_pHook, iIndex, value);
break
;
case
DATA_TYPE_USHORT
: SetArgument<
unsigned
short
>(m_pHook, iIndex, value);
break
;
case
DATA_TYPE_INT
: SetArgument<
int
>(m_pHook, iIndex, value);
break
;
case
DATA_TYPE_UINT
: SetArgument<
unsigned
int
>(m_pHook, iIndex, value);
break
;
case
DATA_TYPE_LONG
: SetArgument<
long
>(m_pHook, iIndex, value);
break
;
case
DATA_TYPE_ULONG
: SetArgument<
unsigned
long
>(m_pHook, iIndex, value);
break
;
case
DATA_TYPE_LONG_LONG
: SetArgument<
long
long
>(m_pHook, iIndex, value);
break
;
case
DATA_TYPE_ULONG_LONG
: SetArgument<
unsigned
long
long
>(m_pHook, iIndex, value);
break
;
case
DATA_TYPE_FLOAT
: SetArgument<
float
>(m_pHook, iIndex, value);
break
;
case
DATA_TYPE_DOUBLE
: SetArgument<
double
>(m_pHook, iIndex, value);
break
;
case
DATA_TYPE_POINTER
:
{
CPointer* pPtr =
ExtractPointer
(value);
SetArgument<
unsigned
long
>(m_pHook, iIndex,
object
(pPtr->
m_ulAddr
));
}
break
;
case
DATA_TYPE_STRING
: SetArgument<
const
char
*>(m_pHook, iIndex, value);
break
;
default
:
BOOST_RAISE_EXCEPTION
(PyExc_TypeError,
"
Unknown type.
"
)
}
}
Back
|
FazBrowse Home
|
New Git URL