forked from Source-Python-Dev-Team/Source.Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentities.h
More file actions
executable file
·331 lines (284 loc) · 9.74 KB
/
entities.h
File metadata and controls
executable file
·331 lines (284 loc) · 9.74 KB
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/**
* =============================================================================
* 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.
*/
#ifndef _ENTITIES_H
#define _ENTITIES_H
//-----------------------------------------------------------------------------
// Includes.
//-----------------------------------------------------------------------------
// Source.Python
#include "modules/memory/memory_tools.h"
#include "utilities/conversions.h"
#include "entities_entity.h"
#include "entities_generator.h"
// SDK
#include "edict.h"
#include "server_class.h"
#include <cstdint>
#include "string_t.h"
#include "dt_send.h"
#include "game/shared/ehandle.h"
#include "isaverestore.h"
#include "datamap.h"
#include "game/shared/takedamageinfo.h"
#include "game/server/entityoutput.h"
//-----------------------------------------------------------------------------
// IServerEntity extension class.
//-----------------------------------------------------------------------------
class ServerEntityExt
{
public:
static void SetModelName(IServerEntity *pServerEntity, const char *szModelName);
static MDLHandle_t get_model_handle(IServerEntity *pServerEntity);
static studiohdr_t* get_model_header(IServerEntity *pServerEntity);
static int lookup_attachment(IServerEntity* pEntity, const char* name);
static int lookup_bone(IServerEntity* pEntity, const char* name);
};
//-----------------------------------------------------------------------------
// CEdictWrapper.
//-----------------------------------------------------------------------------
struct CEdictWrapper : public edict_t
{
void SetUnknown(IServerUnknown *pUnk) {
m_pUnk = pUnk;
}
};
//-----------------------------------------------------------------------------
// CBaseEdict extension class.
//-----------------------------------------------------------------------------
class _BaseEdictExt
{
public:
static void set_free(CBaseEdict *pEdict, bool bState)
{
if (bState)
pEdict->SetFree();
else
pEdict->ClearFree();
}
};
//-----------------------------------------------------------------------------
// CTakeDamageInfo wrapper class.
//-----------------------------------------------------------------------------
class TakeDamageInfoBaseWrapper: public CTakeDamageInfo
{
public:
unsigned int get_inflictor()
{
return ExcIndexFromBaseHandle(m_hInflictor);
}
void set_inflictor(unsigned int uiInflictor)
{
#if defined(ENGINE_ORANGEBOX)
m_hInflictor = EHANDLE::UnsafeFromBaseHandle(ExcBaseHandleFromIndex(uiInflictor));
#else
m_hInflictor = ExcBaseHandleFromIndex(uiInflictor);
#endif
}
unsigned int get_attacker()
{
#if defined(ENGINE_CSGO)
return (unsigned int)m_CSGOAttacker.m_iClientIndex;
#else
return ExcIndexFromBaseHandle(m_hAttacker);
#endif
}
void set_attacker(unsigned int uiAttacker)
{
#if defined(ENGINE_CSGO)
m_CSGOAttacker.m_hHndl = ExcBaseHandleFromIndex(uiAttacker);
m_CSGOAttacker.m_bNeedInit = false;
m_CSGOAttacker.m_bIsWorld = false;
m_CSGOAttacker.m_iClientIndex = (int)uiAttacker;
IPlayerInfo* pPlayerInfo;
if (PlayerInfoFromIndex(uiAttacker, pPlayerInfo))
{
m_CSGOAttacker.m_bIsPlayer = true;
int iTeamIndex = pPlayerInfo->GetTeamIndex();
m_CSGOAttacker.m_iTeamChecked = iTeamIndex;
m_CSGOAttacker.m_iTeamNum = iTeamIndex;
m_CSGOAttacker.m_iUserId = pPlayerInfo->GetUserID();
}
else
{
if (uiAttacker == 0)
{
m_CSGOAttacker.m_bIsWorld = true;
}
m_CSGOAttacker.m_bIsPlayer = false;
m_CSGOAttacker.m_iTeamChecked = -1;
m_CSGOAttacker.m_iTeamNum = -1;
m_CSGOAttacker.m_iUserId = -1;
}
#elif defined(ENGINE_ORANGEBOX)
m_hAttacker = EHANDLE::UnsafeFromBaseHandle(ExcBaseHandleFromIndex(uiAttacker));
#else
m_hAttacker = ExcBaseHandleFromIndex(uiAttacker);
#endif
}
unsigned int get_weapon()
{
unsigned int index;
if (IndexFromBaseHandle(m_hWeapon, index))
return index;
if (m_hAttacker.ToInt() == m_hInflictor.ToInt())
{
CBaseEntity* _attacker;
if (!BaseEntityFromBaseHandle(m_hAttacker, _attacker))
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Failed to retrieve the attacker")
CBaseEntityWrapper* attacker = (CBaseEntityWrapper*) _attacker;
if (!attacker->IsPlayer())
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Attacker is not a player.");
// TODO: Don't hardcode m_hActiveWeapon
return ExcIndexFromIntHandle(attacker->GetDatamapProperty<unsigned int>("m_hActiveWeapon"));
}
return get_inflictor();
}
void set_weapon(unsigned int uiWeapon)
{
#if defined(ENGINE_ORANGEBOX)
m_hWeapon = EHANDLE::UnsafeFromBaseHandle(ExcBaseHandleFromIndex(uiWeapon));
#else
m_hWeapon = ExcBaseHandleFromIndex(uiWeapon);
#endif
}
void set_base_damage(float flBaseDamage)
{
m_flBaseDamage = flBaseDamage;
}
int get_damaged_other_players()
{
return -1;
// return m_iDamagedOtherPlayers;
}
void set_damaged_other_players(int iDamagedOtherPlayers)
{
// m_iDamagedOtherPlayers = iDamagedOtherPlayers;
}
};
//-----------------------------------------------------------------------------
// CTakeDamageInfo extension class.
//-----------------------------------------------------------------------------
class TakeDamageInfoSharedExt
{
public:
static CTakeDamageInfo *__init__()
{
CTakeDamageInfo *pTakeDamageInfo = new CTakeDamageInfo();
set_inflictor(pTakeDamageInfo, 0);
set_attacker(pTakeDamageInfo, 0);
return pTakeDamageInfo;
}
static unsigned int get_inflictor(CTakeDamageInfo *pTakeDamageInfo)
{
return ((TakeDamageInfoBaseWrapper *)pTakeDamageInfo)->get_inflictor();
}
static void set_inflictor(CTakeDamageInfo *pTakeDamageInfo, unsigned int iInflictor)
{
((TakeDamageInfoBaseWrapper *)pTakeDamageInfo)->set_inflictor(iInflictor);
}
static unsigned int get_attacker(CTakeDamageInfo *pTakeDamageInfo)
{
return ((TakeDamageInfoBaseWrapper *)pTakeDamageInfo)->get_attacker();
}
static void set_attacker(CTakeDamageInfo *pTakeDamageInfo, unsigned int iAttacker)
{
((TakeDamageInfoBaseWrapper *)pTakeDamageInfo)->set_attacker(iAttacker);
}
static unsigned int get_weapon(CTakeDamageInfo *pTakeDamageInfo)
{
return ((TakeDamageInfoBaseWrapper *)pTakeDamageInfo)->get_weapon();
}
static void set_weapon(CTakeDamageInfo *pTakeDamageInfo, unsigned int iWeapon)
{
((TakeDamageInfoBaseWrapper *)pTakeDamageInfo)->set_weapon(iWeapon);
}
static void set_base_damage(CTakeDamageInfo *pTakeDamageInfo, float flBaseDamage)
{
((TakeDamageInfoBaseWrapper *)pTakeDamageInfo)->set_base_damage(flBaseDamage);
}
static int get_damaged_other_players(CTakeDamageInfo *pTakeDamageInfo)
{
return ((TakeDamageInfoBaseWrapper *)pTakeDamageInfo)->get_damaged_other_players();
}
static void set_damaged_other_players(CTakeDamageInfo *pTakeDamageInfo, int iDamagedOtherPlayers)
{
((TakeDamageInfoBaseWrapper *)pTakeDamageInfo)->set_damaged_other_players(iDamagedOtherPlayers);
}
};
//-----------------------------------------------------------------------------
// CEventAction extension class.
//-----------------------------------------------------------------------------
class EventActionExt
{
public:
static const char *get_target(CEventAction *pEventAction)
{
return STRING(pEventAction->m_iTarget);
}
static void set_target(CEventAction *pEventAction, const char *szTarget)
{
pEventAction->m_iTarget = MAKE_STRING(szTarget);
}
static const char *get_target_input(CEventAction *pEventAction)
{
return STRING(pEventAction->m_iTargetInput);
}
static void set_target_input(CEventAction *pEventAction, const char *szTargetInput)
{
pEventAction->m_iTargetInput = MAKE_STRING(szTargetInput);
}
static const char *get_parameter(CEventAction *pEventAction)
{
return STRING(pEventAction->m_iParameter);
}
static void set_parameter(CEventAction *pEventAction, const char *szParameter)
{
pEventAction->m_iParameter = MAKE_STRING(szParameter);
}
};
//-----------------------------------------------------------------------------
// CBaseEntityOutput wrapper class.
//-----------------------------------------------------------------------------
class CBaseEntityOutputWrapper: public CBaseEntityOutput
{
public:
static CEventAction *get_event_action(CBaseEntityOutputWrapper *pBaseEntityOutput)
{
return pBaseEntityOutput->m_ActionList;
}
static void set_event_action(CBaseEntityOutputWrapper *pBaseEntityOutput, CEventAction *pEventAction)
{
pBaseEntityOutput->m_ActionList = pEventAction;
}
static object get_event_actions(CBaseEntityOutputWrapper *pBaseEntityOutput)
{
return import("_entities").attr("EventActionGenerator")(boost::ref(pBaseEntityOutput->m_ActionList));
}
public:
using CBaseEntityOutput::m_Value;
using CBaseEntityOutput::m_ActionList;
};
#endif // _ENTITIES_H