-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathpr2_exec.c
322 lines (272 loc) · 8.68 KB
/
pr2_exec.c
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
/*
* QW262
* Copyright (C) 2004 [sd] angel
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* $Id: pr2_exec.c 695 2007-09-30 14:43:34Z tonik $
*/
#ifdef USE_PR2
#include "qwsvdef.h"
gameData_t *gamedata;
cvar_t sv_progtype = {"sv_progtype","0"}; // bound the size of the
#ifdef QVM_PROFILE
extern cvar_t sv_enableprofile;
#endif
//int usedll;
void ED2_PrintEdicts (void);
void PR2_Profile_f (void);
void ED2_PrintEdict_f (void);
void ED_Count (void);
void PR_CleanLogText_Init(void);
void PR2_Init(void)
{
int p;
int usedll;
Cvar_Register(&sv_progtype);
Cvar_Register(&sv_progsname);
Cvar_Register(&sv_forcenqprogs);
#ifdef QVM_PROFILE
Cvar_Register(&sv_enableprofile);
#endif
p = COM_CheckParm ("-progtype");
if (p && p < COM_Argc())
{
usedll = Q_atoi(COM_Argv(p + 1));
if (usedll > 2)
usedll = VM_NONE;
Cvar_SetValue(&sv_progtype,usedll);
}
Cmd_AddCommand ("edict", ED2_PrintEdict_f);
Cmd_AddCommand ("edicts", ED2_PrintEdicts);
Cmd_AddCommand ("edictcount", ED_Count);
Cmd_AddCommand ("profile", PR2_Profile_f);
Cmd_AddCommand ("mod", PR2_GameConsoleCommand);
PR_CleanLogText_Init();
}
//===========================================================================
// PR2_GetString
//===========================================================================
char *PR2_GetString(int num)
{
qvm_t *qvm;
if(!sv_vm)
return PR_GetString(num);
switch (sv_vm->type)
{
case VM_NONE:
return PR_GetString(num);
case VM_NATIVE:
if (num)
return (char *) num;
else
return "";
case VM_BYTECODE:
if (!num)
return "";
qvm = (qvm_t*)(sv_vm->hInst);
if ( num & ( ~qvm->ds_mask) )
{
Con_DPrintf("PR2_GetString error off %8x/%8x\n", num, qvm->len_ds );
return "";
}
return (char *) (qvm->ds+ num);
}
return NULL;
}
//===========================================================================
// PR2_SetString
// FIXME for VM
//===========================================================================
int PR2_SetString(char *s)
{
qvm_t *qvm;
int off;
if(!sv_vm)
return PR_SetString(s);
switch (sv_vm->type)
{
case VM_NONE:
return PR_SetString(s);
case VM_NATIVE:
return (int) s;
case VM_BYTECODE:
qvm = (qvm_t*)(sv_vm->hInst);
off = (byte*)s - qvm->ds;
if (off &(~qvm->ds_mask))
return 0;
return off;
break;
}
return 0;
}
/*
=================
PR2_LoadEnts
=================
*/
extern char *pr2_ent_data_ptr;
void PR2_LoadEnts(char *data)
{
pr2_ent_data_ptr = data;
//Init parse
VM_Call(sv_vm, GAME_LOADENTS, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// GameStartFrame
//===========================================================================
void PR2_GameStartFrame(void)
{
VM_Call(sv_vm, GAME_START_FRAME, (int) (sv.time * 1000), 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0);
}
//===========================================================================
// GameClientConnect
//===========================================================================
void PR2_GameClientConnect(int spec)
{
VM_Call(sv_vm, GAME_CLIENT_CONNECT, spec, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// GamePutClientInServer
//===========================================================================
void PR2_GamePutClientInServer(int spec)
{
VM_Call(sv_vm, GAME_PUT_CLIENT_IN_SERVER, spec, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// GameClientDisconnect
//===========================================================================
void PR2_GameClientDisconnect(int spec)
{
VM_Call(sv_vm, GAME_CLIENT_DISCONNECT, spec, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// GameClientPreThink
//===========================================================================
void PR2_GameClientPreThink(int spec)
{
VM_Call(sv_vm, GAME_CLIENT_PRETHINK, spec, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// GameClientPostThink
//===========================================================================
void PR2_GameClientPostThink(int spec)
{
VM_Call(sv_vm, GAME_CLIENT_POSTTHINK, spec, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// ClientCmd return false on unknown command
//===========================================================================
qbool PR2_ClientCmd(void)
{
return VM_Call(sv_vm, GAME_CLIENT_COMMAND, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// ClientSay return false if say unhandled by mod
//===========================================================================
qbool PR2_ClientSay(int isTeamSay)
{
return VM_Call(sv_vm, GAME_CLIENT_SAY, isTeamSay, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// GameSetNewParms
//===========================================================================
void PR2_GameSetNewParms(void)
{
VM_Call(sv_vm, GAME_SETNEWPARMS, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// GameSetNewParms
//===========================================================================
void PR2_GameSetChangeParms(void)
{
VM_Call(sv_vm, GAME_SETCHANGEPARMS, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// EdictTouch
//===========================================================================
void PR2_EdictTouch(void)
{
VM_Call(sv_vm, GAME_EDICT_TOUCH, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// EdictThink
//===========================================================================
void PR2_EdictThink(void)
{
VM_Call(sv_vm, GAME_EDICT_THINK, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// EdictBlocked
//===========================================================================
void PR2_EdictBlocked(void)
{
VM_Call(sv_vm, GAME_EDICT_BLOCKED, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// UserInfoChanged
//===========================================================================
qbool PR2_UserInfoChanged(void)
{
return VM_Call(sv_vm, GAME_CLIENT_USERINFO_CHANGED, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// UserInfoChanged
//===========================================================================
void PR2_GameShutDown(void)
{
VM_Call(sv_vm, GAME_SHUTDOWN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//===========================================================================
// UserInfoChanged
//===========================================================================
void PR2_GameConsoleCommand(void)
{
int old_other, old_self;
client_t *cl;
int i;
if( sv_vm )
{
old_self = pr_global_struct->self;
old_other = pr_global_struct->other;
pr_global_struct->other = 0; //sv_cmd = SV_CMD_CONSOLE;
pr_global_struct->self = 0;
for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++)
{
if (!cl->state)
continue;
if ( cl->isBot )
continue;
if (NET_CompareAdr(cl->netchan.remote_address, net_from))
{
pr_global_struct->self = EDICT_TO_PROG(cl->edict);
break;
}
}
VM_Call(sv_vm, GAME_CONSOLE_COMMAND, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
pr_global_struct->self = old_self;
pr_global_struct->other = old_other;
}
}
//===========================================================================
// PausedTic
//===========================================================================
void PR2_PausedTic(float duration)
{
VM_Call(sv_vm, GAME_PAUSED_TIC, duration*1000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
#endif /* USE_PR2 */