/
players_wrap.cpp
337 lines (273 loc) · 8.15 KB
/
players_wrap.cpp
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
332
333
334
335
336
337
/**
* =============================================================================
* 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 "players_generator.h"
#include "export_main.h"
#include "modules/memory/memory_tools.h"
#include "game/shared/shareddefs.h"
#include "game/shared/usercmd.h"
#include "public/game/server/iplayerinfo.h"
#include "iclient.h"
#include "inetchannelinfo.h"
#include "inetchannel.h"
#include "players_wrap.h"
#include ENGINE_INCLUDE_PATH(players_wrap.h)
//-----------------------------------------------------------------------------
// Forward declarations.
//-----------------------------------------------------------------------------
void export_playerinfo(scope);
void export_player_generator(scope);
void export_client(scope);
void export_user_cmd(scope);
//-----------------------------------------------------------------------------
// Declare the _players module.
//-----------------------------------------------------------------------------
DECLARE_SP_MODULE(_players)
{
export_playerinfo(_players);
export_player_generator(_players);
export_client(_players);
export_user_cmd(_players);
}
//-----------------------------------------------------------------------------
// Exports IPlayerInfo.
//-----------------------------------------------------------------------------
void export_playerinfo(scope _players)
{
class_<IPlayerInfo, boost::noncopyable>("PlayerInfo", no_init)
.def("get_name",
&IPlayerInfoExt::GetName,
"Returns the player's name"
)
.def("get_userid",
&IPlayerInfo::GetUserID,
"Returns the player's userid."
)
.def("get_networkid_string",
&IPlayerInfo::GetNetworkIDString,
"Returns the player's SteamID."
)
.def("get_team_index",
&IPlayerInfo::GetTeamIndex,
"Returns the player's team number."
)
.def("change_team",
&IPlayerInfo::ChangeTeam,
"Moves the player to the given team.",
args("team_number")
)
.def("get_frag_count",
&IPlayerInfo::GetFragCount,
"Returns the player's frag count."
)
.def("get_death_count",
&IPlayerInfo::GetDeathCount,
"Returns the player's death count."
)
.def("is_connected",
&IPlayerInfo::IsConnected,
"Returns whether the player is connected."
)
.def("get_armor_value",
&IPlayerInfo::GetArmorValue,
"Returns the player's armor value."
)
.def("is_hltv",
&IPlayerInfo::IsHLTV,
"Returns whether the player is HLTV."
)
.def("is_player",
&IPlayerInfo::IsPlayer,
"Returns whether the player is a client."
)
.def("is_fake_client",
&IPlayerInfo::IsFakeClient,
"Returns whether the player is a fake client."
)
.def("is_dead",
&IPlayerInfo::IsDead,
"Returns whether the player is dead."
)
.def("is_in_a_vehicle",
&IPlayerInfo::IsInAVehicle,
"Returns whether the player is in a vehicle."
)
.def("is_observer",
&IPlayerInfo::IsObserver,
"Returns whether the player is an observer."
)
.def("get_abs_origin",
&IPlayerInfo::GetAbsOrigin,
"Returns the player's origin Vector instance."
)
.def("get_abs_angles",
&IPlayerInfo::GetAbsAngles,
"Returns the player's angle QAngle instance."
)
.def("get_player_mins",
&IPlayerInfo::GetPlayerMins,
"Returns the player's min Vector instance."
)
.def("get_player_maxs",
&IPlayerInfo::GetPlayerMaxs,
"Returns the player's max Vector instance."
)
.def("get_weapon_name",
&IPlayerInfo::GetWeaponName,
"Returns the name of the weapon the player is carrying."
)
.def("get_model_name",
&IPlayerInfo::GetModelName,
"Returns the name of the player's model."
)
.def("get_health",
&IPlayerInfo::GetHealth,
"Returns the player's health."
)
.def("get_max_health",
&IPlayerInfo::GetMaxHealth,
"Returns the player's maximum health."
)
.def("get_last_user_command",
&IPlayerInfo::GetLastUserCommand
)
ADD_MEM_TOOLS(IPlayerInfo)
;
}
//-----------------------------------------------------------------------------
// Exports CPlayerGenerator.
//-----------------------------------------------------------------------------
void export_player_generator(scope _players)
{
class_<CPlayerGenerator>("PlayerGenerator")
.def("__iter__",
&CPlayerGenerator::iter,
"Returns the iterable object."
)
.def("__next__",
&CPlayerGenerator::next,
"Returns the next valid instance.",
reference_existing_object_policy()
)
;
}
//-----------------------------------------------------------------------------
// Exports IClient.
//-----------------------------------------------------------------------------
void export_client(scope _players)
{
class_<IClient, IClient*, bases<INetChannelHandler>, boost::noncopyable> Client("Client", no_init);
Client.def(
"get_client_name",
&IClient::GetClientName,
"Return the client's name."
);
Client.def(
"get_net_channel",
&IClient::GetNetChannel,
reference_existing_object_policy()
);
// TODO: Export more
Client ADD_MEM_TOOLS(IClient);
}
//-----------------------------------------------------------------------------
// Exports CUserCmd.
//-----------------------------------------------------------------------------
void export_user_cmd(scope _players)
{
class_<CUserCmd, CUserCmd*> UserCmd("UserCmd");
UserCmd.def(
"reset",
&CUserCmd::Reset
);
UserCmd.def(
"get_checksum",
&CUserCmd::GetChecksum
);
UserCmd.def_readwrite("command_number",
&CUserCmd::command_number,
"For matching server and client commands for debugging."
);
UserCmd.def_readwrite("tick_count",
&CUserCmd::tick_count,
"The tick the client created this command."
);
UserCmd.def_readwrite("view_angles",
&CUserCmd::viewangles,
"Player instantaneous view angles."
);
UserCmd.NOT_IMPLEMENTED("aim_direction");
UserCmd.def_readwrite("forward_move",
&CUserCmd::forwardmove,
"Forward velocity."
);
UserCmd.def_readwrite("side_move",
&CUserCmd::sidemove,
"Sideways velocity."
);
UserCmd.def_readwrite("up_move",
&CUserCmd::upmove,
"Upward velocity."
);
UserCmd.def_readwrite("buttons",
&CUserCmd::buttons,
"Button states."
);
UserCmd.def_readwrite("impulse",
&CUserCmd::impulse,
"Impulse command."
);
UserCmd.def_readwrite("weaponselect",
&CUserCmd::weaponselect,
"Current weapon ID."
);
UserCmd.def_readwrite("weaponsubtype",
&CUserCmd::weaponsubtype,
"Current weapon ID."
);
UserCmd.def_readwrite("random_seed",
&CUserCmd::random_seed,
"For shared random functions."
);
UserCmd.def_readwrite("mousedx",
&CUserCmd::mousedx,
"Mouse accum in x from create move."
);
UserCmd.def_readwrite("mousedy",
&CUserCmd::mousedy,
"Mouse accum in y from create move."
);
UserCmd.def_readwrite("has_been_predicted",
&CUserCmd::hasbeenpredicted,
"Client only, tracks whether we've predicted this command at least once."
);
UserCmd.NOT_IMPLEMENTED("head_angles");
UserCmd.NOT_IMPLEMENTED("head_offset");
export_engine_specific_user_cmd(_players, UserCmd);
UserCmd ADD_MEM_TOOLS(CUserCmd);
}