-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgsc_custom_player.cpp
260 lines (215 loc) · 6.13 KB
/
gsc_custom_player.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
#include "gsc_custom_player.hpp"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void Gsc_Player_SetPMFlags(int id)
{
int numParams = Scr_GetNumParam();
const char *szSyntax = "expected 1-2 arguments: <pm_flags> [pm_time]";
if ((numParams < 1) || (numParams > 2))
{
stackError(szSyntax);
return;
}
if (stackGetParamType(0) != STACK_INT)
{
stackError(szSyntax);
return;
}
if ((numParams > 1) && (stackGetParamType(1) != STACK_INT))
{
stackError(szSyntax);
return;
}
int flags = 0;
stackGetParamInt(0, &flags);
int time = 0;
if (numParams > 1)
{
stackGetParamInt(1, &time);
}
playerState_t *ps = SV_GameClientNum(id);
if (ps != NULL)
{
ps->pm_flags = flags;
if (numParams > 1)
{
ps->pm_time = time;
}
}
}
void Gsc_Player_GetPMFlags(int id)
{
playerState_t *ps = SV_GameClientNum(id);
stackPushInt(ps->pm_flags);
}
void Gsc_Player_GetPMTime(int id)
{
playerState_t *ps = SV_GameClientNum(id);
stackPushInt(ps->pm_time);
}
void Gsc_Player_GetGroundEntity(int id)
{
playerState_t *ps = SV_GameClientNum(id);
if(ps->groundEntityNum < 1022)
{
stackPushEntity(&g_entities[ps->groundEntityNum]);
return;
}
stackPushUndefined();
}
void Gsc_Player_setOriginAndAngles(int id)
{
//sets origin, angles
//resets pm_flags and velocity
//keeps stance
#ifndef COD2
extern void __cdecl G_EntUnlink(gentity_t *);
extern void __cdecl SV_UnlinkEntity(gentity_t *);
extern void __cdecl G_ClientStopUsingTurret(gentity_t *);
extern level_locals_t level;
extern void __cdecl SetClientViewAngle(gentity_s *ent, const float *angle);
extern void __cdecl Pmove(pmove_t *);
#endif
//identical for cod2 and cod4
#define PMF_DUCKED 0x2
#define PMF_PRONE 0x1 //untested
#define EF_TELEPORT_BIT 0x2
gentity_s *ent;
vec3_t origin;
vec3_t angles;
ent = &g_entities[id];
if(!ent->client)
{
Scr_ObjectError(va("entity %i is not a player", id));
}
Scr_GetVector(0, origin);
Scr_GetVector(1, angles);
bool isUsingTurret;
#ifdef COD2
isUsingTurret = ((ent->client->ps.pm_flags & 0x800000) != 0 && (ent->client->ps.eFlags & 0x300) != 0);
#else
isUsingTurret = ((ent->client->ps.otherFlags & 4) != 0 && (ent->client->ps.eFlags & 0x300) != 0);
#endif
//stop using MGs
if(isUsingTurret)
{
G_ClientStopUsingTurret(&g_entities[ent->client->ps.viewlocked_entNum]);
}
G_EntUnlink(ent);
//unlink client from linkto() stuffs
if (ent->r.linked)
{
SV_UnlinkEntity(ent);
}
//clear flags
ent->client->ps.pm_flags &= (PMF_DUCKED | PMF_PRONE);//keep stance
ent->client->ps.eFlags ^= EF_TELEPORT_BIT; //alternate teleport flag, unsure why
//set times
ent->client->ps.pm_time = 0;
ent->client->ps.jumpTime = 0; //to reset wallspeed effects
//set origin
VectorCopy(origin, ent->client->ps.origin);
G_SetOrigin(ent, origin);
//reset velocity
ent->client->ps.velocity[0] = 0;
ent->client->ps.velocity[1] = 0;
ent->client->ps.velocity[2] = 0;
#ifdef COD4
ent->client->ps.sprintState.sprintButtonUpRequired = 0;
ent->client->ps.sprintState.sprintDelay = 0;
ent->client->ps.sprintState.lastSprintStart = 0;
ent->client->ps.sprintState.lastSprintEnd = 0;
ent->client->ps.sprintState.sprintStartMaxLength = 0;
#endif
//pretend we're not proning so that prone angle is ok after having called SetClientViewAngle (otherwise it gets a correction)
int flags = ent->client->ps.pm_flags;
ent->client->ps.pm_flags &= ~PMF_PRONE;
ent->client->sess.cmd.serverTime = level.time; //if this isnt set then errordecay takes place
// Prevent players from being able able to walk around without starting a run (because WASD callback is only called)
extern void opencj_clearPlayerMovementCheckVars(int);
opencj_clearPlayerMovementCheckVars(id);
SetClientViewAngle(ent, angles);
//create a pmove object and execute to bypass the errordecay thing
pmove_t pm;
memset(&pm, 0, sizeof(pm));
pm.ps = &ent->client->ps;
memcpy(&pm.cmd, &ent->client->sess.cmd, sizeof(pm.cmd));
pm.cmd.serverTime = level.time - 50;
ent->client->sess.oldcmd.serverTime = level.time - 100;
pm.oldcmd = ent->client->sess.oldcmd;
pm.tracemask = 42008593;
pm.handler = 1;
Pmove(&pm);
//reset velocity
ent->client->ps.velocity[0] = 0;
ent->client->ps.velocity[1] = 0;
ent->client->ps.velocity[2] = 0;
//restore prone if any
ent->client->ps.pm_flags = flags;
SV_LinkEntity(ent);
}
void Gsc_Player_JumpClearStateExtended(int id)
{
playerState_t *ps = SV_GameClientNum(id);
ps->pm_flags &= SHARED_CLEARJUMPSTATE_MASK;
ps->pm_time = 0;
ps->jumpTime = 0; //to reset wallspeed effects
ps->jumpOriginZ = 0.0;
}
void Gsc_player_GetJumpSlowdownTimer(int id)
{
playerState_t *ps = SV_GameClientNum(id);
int value = ps->pm_time;
stackPushInt(value);
}
void Gsc_Player_setWeaponAmmoClip(int id) //pls comment out for cod4
{
}
void Gsc_Player_switchToWeaponSeamless(int id)
{
const char *szWeaponName = NULL;
if (stackGetParamString(0, &szWeaponName))
{
playerState_t *ps = SV_GameClientNum(id);
int weaponIdx = G_GetWeaponIndexForName(szWeaponName);
if (BG_IsWeaponValid(ps, weaponIdx))
{
ps->weapon = weaponIdx;
//ps->weaponstate = 0; // WEAPON_READY
SV_GameSendServerCommand(id, 1, va("%c %i", 'a', weaponIdx));
}
}
}
void Gsc_Player_SV_GameSendServerCommand(int id)
{
int reliable;
char *message;
if (!stackGetParams("si", &message, &reliable))
{
stackError("Gsc_Player_SV_GameSendServerCommand() one or more arguments is undefined or has a wrong type");
stackPushUndefined();
return;
}
SV_GameSendServerCommand(id, reliable, message);
stackPushBool(qtrue);
}
void Gsc_Player_GetQueuedReliableMessages(int id)
{
client_t *pClient = &svs.clients[id];
if (!pClient)
{
stackPushUndefined();
return;
}
int nrQueued = pClient->reliableSequence - pClient->reliableAcknowledge;
stackPushInt(nrQueued);
}
void Gsc_Player_ClearFPSFilter(int id)
{
playerState_t *ps = SV_GameClientNum(id);
opencj_clearPlayerFPS(ps->clientNum);
}
#ifdef __cplusplus
}
#endif // __cplusplus