New console commands sv_cmd, menu_cmd, cl_cmd, that call GameCommand(string s) in...
[divverent/darkplaces.git] / mvm_cmds.c
1 #include "prvm_cmds.h"
2
3 //============================================================================
4 // Menu
5
6 char *vm_m_extensions =
7 "BX_WAL_SUPPORT "
8 "DP_CINEMATIC_DPV "
9 "DP_MENU_EXTRESPONSEPACKET "
10 "DP_QC_ASINACOSATANATAN2TAN "
11 "DP_QC_STRFTIME "
12 "DP_QC_STRINGCOLORFUNCTIONS "
13 "DP_QC_TOKENIZEBYSEPARATOR "
14 "DP_QC_UNLIMITEDTEMPSTRINGS "
15 "DP_QC_CMD "
16 ;
17
18 /*
19 =========
20 VM_M_setmousetarget
21
22 setmousetarget(float target)
23 =========
24 */
25 void VM_M_setmousetarget(void)
26 {
27         VM_SAFEPARMCOUNT(1, VM_M_setmousetarget);
28
29         switch((int)PRVM_G_FLOAT(OFS_PARM0))
30         {
31         case 1:
32                 in_client_mouse = false;
33                 break;
34         case 2:
35                 in_client_mouse = true;
36                 break;
37         default:
38                 PRVM_ERROR("VM_M_setmousetarget: wrong destination %f !",PRVM_G_FLOAT(OFS_PARM0));
39         }
40 }
41
42 /*
43 =========
44 VM_M_getmousetarget
45
46 float   getmousetarget
47 =========
48 */
49 void VM_M_getmousetarget(void)
50 {
51         VM_SAFEPARMCOUNT(0,VM_M_getmousetarget);
52
53         if(in_client_mouse)
54                 PRVM_G_FLOAT(OFS_RETURN) = 2;
55         else
56                 PRVM_G_FLOAT(OFS_RETURN) = 1;
57 }
58
59
60
61 /*
62 =========
63 VM_M_setkeydest
64
65 setkeydest(float dest)
66 =========
67 */
68 void VM_M_setkeydest(void)
69 {
70         VM_SAFEPARMCOUNT(1,VM_M_setkeydest);
71
72         switch((int)PRVM_G_FLOAT(OFS_PARM0))
73         {
74         case 0:
75                 // key_game
76                 key_dest = key_game;
77                 break;
78         case 2:
79                 // key_menu
80                 key_dest = key_menu;
81                 break;
82         case 1:
83                 // key_message
84                 // key_dest = key_message
85                 // break;
86         default:
87                 PRVM_ERROR("VM_M_setkeydest: wrong destination %f !", PRVM_G_FLOAT(OFS_PARM0));
88         }
89 }
90
91 /*
92 =========
93 VM_M_getkeydest
94
95 float   getkeydest
96 =========
97 */
98 void VM_M_getkeydest(void)
99 {
100         VM_SAFEPARMCOUNT(0,VM_M_getkeydest);
101
102         // key_game = 0, key_message = 1, key_menu = 2, unknown = 3
103         switch(key_dest)
104         {
105         case key_game:
106                 PRVM_G_FLOAT(OFS_RETURN) = 0;
107                 break;
108         case key_menu:
109                 PRVM_G_FLOAT(OFS_RETURN) = 2;
110                 break;
111         case key_message:
112                 // not supported
113                 // PRVM_G_FLOAT(OFS_RETURN) = 1;
114                 // break;
115         default:
116                 PRVM_G_FLOAT(OFS_RETURN) = 3;
117         }
118 }
119
120 /*
121 =========
122 VM_M_callfunction
123
124         callfunction(...,string function_name)
125 Extension: pass
126 =========
127 */
128 mfunction_t *PRVM_ED_FindFunction (const char *name);
129 void VM_M_callfunction(void)
130 {
131         mfunction_t *func;
132         const char *s;
133
134         VM_SAFEPARMCOUNTRANGE(1, 8, VM_M_callfunction);
135
136         s = PRVM_G_STRING(OFS_PARM0 + (prog->argc - 1));
137
138         VM_CheckEmptyString(s);
139
140         func = PRVM_ED_FindFunction(s);
141
142         if(!func)
143                 PRVM_ERROR("VM_M_callfunciton: function %s not found !", s);
144         else if (func->first_statement < 0)
145         {
146                 // negative statements are built in functions
147                 int builtinnumber = -func->first_statement;
148                 prog->xfunction->builtinsprofile++;
149                 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
150                         prog->builtins[builtinnumber]();
151                 else
152                         PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME);
153         }
154         else if(func - prog->functions > 0)
155         {
156                 prog->argc--;
157                 PRVM_ExecuteProgram(func - prog->functions,"");
158                 prog->argc++;
159         }
160 }
161
162 /*
163 =========
164 VM_M_isfunction
165
166 float   isfunction(string function_name)
167 =========
168 */
169 mfunction_t *PRVM_ED_FindFunction (const char *name);
170 void VM_M_isfunction(void)
171 {
172         mfunction_t *func;
173         const char *s;
174
175         VM_SAFEPARMCOUNT(1, VM_M_isfunction);
176
177         s = PRVM_G_STRING(OFS_PARM0);
178
179         VM_CheckEmptyString(s);
180
181         func = PRVM_ED_FindFunction(s);
182
183         if(!func)
184                 PRVM_G_FLOAT(OFS_RETURN) = false;
185         else
186                 PRVM_G_FLOAT(OFS_RETURN) = true;
187 }
188
189 /*
190 =========
191 VM_M_getresolution
192
193 vector  getresolution(float number)
194 =========
195 */
196 extern unsigned short video_resolutions[][2];
197 void VM_M_getresolution(void)
198 {
199         int nr;
200         VM_SAFEPARMCOUNT(1, VM_getresolution);
201
202         nr = (int)PRVM_G_FLOAT(OFS_PARM0);
203
204
205         PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr][0];
206         PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr][1];
207         PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
208 }
209
210 /*
211 =========
212 VM_M_findkeysforcommand
213
214 string  findkeysforcommand(string command)
215
216 the returned string is an altstring
217 =========
218 */
219 #define NUMKEYS 5 // TODO: merge the constant in keys.c with this one somewhen
220
221 void M_FindKeysForCommand(const char *command, int *keys);
222 void VM_M_findkeysforcommand(void)
223 {
224         const char *cmd;
225         char ret[VM_STRINGTEMP_LENGTH];
226         int keys[NUMKEYS];
227         int i;
228
229         VM_SAFEPARMCOUNT(1, VM_M_findkeysforcommand);
230
231         cmd = PRVM_G_STRING(OFS_PARM0);
232
233         VM_CheckEmptyString(cmd);
234
235         M_FindKeysForCommand(cmd, keys);
236
237         ret[0] = 0;
238         for(i = 0; i < NUMKEYS; i++)
239                 strlcat(ret, va(" \'%i\'", keys[i]), sizeof(ret));
240
241         PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(ret);
242 }
243
244 /*
245 =========
246 VM_M_getserverliststat
247
248 float   getserverliststat(float type)
249 =========
250 */
251 /*
252         type:
253 0       serverlist_viewcount
254 1   serverlist_totalcount
255 2       masterquerycount
256 3       masterreplycount
257 4       serverquerycount
258 5       serverreplycount
259 6       sortfield
260 7       sortdescending
261 */
262 void VM_M_getserverliststat( void )
263 {
264         int type;
265         VM_SAFEPARMCOUNT ( 1, VM_M_getserverliststat );
266
267         PRVM_G_FLOAT( OFS_RETURN ) = 0;
268
269         type = (int)PRVM_G_FLOAT( OFS_PARM0 );
270         switch(type)
271         {
272         case 0:
273                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_viewcount;
274                 return;
275         case 1:
276                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_cachecount;
277         case 2:
278                 PRVM_G_FLOAT ( OFS_RETURN ) = masterquerycount;
279                 return;
280         case 3:
281                 PRVM_G_FLOAT ( OFS_RETURN ) = masterreplycount;
282                 return;
283         case 4:
284                 PRVM_G_FLOAT ( OFS_RETURN ) = serverquerycount;
285                 return;
286         case 5:
287                 PRVM_G_FLOAT ( OFS_RETURN ) = serverreplycount;
288                 return;
289         case 6:
290                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortbyfield;
291                 return;
292         case 7:
293                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortdescending;
294                 return;
295         default:
296                 VM_Warning( "VM_M_getserverliststat: bad type %i!\n", type );
297         }
298 }
299
300 /*
301 ========================
302 VM_M_resetserverlistmasks
303
304 resetserverlistmasks()
305 ========================
306 */
307 void VM_M_resetserverlistmasks( void )
308 {
309         VM_SAFEPARMCOUNT(0, VM_M_resetserverlistmasks);
310         ServerList_ResetMasks();
311 }
312
313
314 /*
315 ========================
316 VM_M_setserverlistmaskstring
317
318 setserverlistmaskstring(float mask, float fld, string str, float op)
319 0-511           and
320 512 - 1024      or
321 ========================
322 */
323 void VM_M_setserverlistmaskstring( void )
324 {
325         const char *str;
326         int masknr;
327         serverlist_mask_t *mask;
328         int field;
329
330         VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmaskstring );
331         str = PRVM_G_STRING( OFS_PARM2 );
332
333         masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
334         if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
335                 mask = &serverlist_andmasks[masknr];
336         else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
337                 mask = &serverlist_ormasks[masknr - 512 ];
338         else
339         {
340                 VM_Warning( "VM_M_setserverlistmaskstring: invalid mask number %i\n", masknr );
341                 return;
342         }
343
344         field = (int) PRVM_G_FLOAT( OFS_PARM1 );
345
346         switch( field ) {
347                 case SLIF_CNAME:
348                         strlcpy( mask->info.cname, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.cname) );
349                         break;
350                 case SLIF_NAME:
351                         strlcpy( mask->info.name, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.name)  );
352                         break;
353                 case SLIF_MAP:
354                         strlcpy( mask->info.map, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.map)  );
355                         break;
356                 case SLIF_MOD:
357                         strlcpy( mask->info.mod, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.mod)  );
358                         break;
359                 case SLIF_GAME:
360                         strlcpy( mask->info.game, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.game)  );
361                         break;
362                 default:
363                         VM_Warning( "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
364                         return;
365         }
366
367         mask->active = true;
368         mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
369 }
370
371 /*
372 ========================
373 VM_M_setserverlistmasknumber
374
375 setserverlistmasknumber(float mask, float fld, float num, float op)
376
377 0-511           and
378 512 - 1024      or
379 ========================
380 */
381 void VM_M_setserverlistmasknumber( void )
382 {
383         int number;
384         serverlist_mask_t *mask;
385         int     masknr;
386         int field;
387         VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmasknumber );
388
389         masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
390         if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
391                 mask = &serverlist_andmasks[masknr];
392         else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
393                 mask = &serverlist_ormasks[masknr - 512 ];
394         else
395         {
396                 VM_Warning( "VM_M_setserverlistmasknumber: invalid mask number %i\n", masknr );
397                 return;
398         }
399
400         number = (int)PRVM_G_FLOAT( OFS_PARM2 );
401         field = (int) PRVM_G_FLOAT( OFS_PARM1 );
402
403         switch( field ) {
404                 case SLIF_MAXPLAYERS:
405                         mask->info.maxplayers = number;
406                         break;
407                 case SLIF_NUMPLAYERS:
408                         mask->info.numplayers = number;
409                         break;
410                 case SLIF_PING:
411                         mask->info.ping = number;
412                         break;
413                 case SLIF_PROTOCOL:
414                         mask->info.protocol = number;
415                         break;
416                 default:
417                         VM_Warning( "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
418                         return;
419         }
420
421         mask->active = true;
422         mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
423 }
424
425
426 /*
427 ========================
428 VM_M_resortserverlist
429
430 resortserverlist
431 ========================
432 */
433 void VM_M_resortserverlist( void )
434 {
435         VM_SAFEPARMCOUNT(0, VM_M_resortserverlist);
436         ServerList_RebuildViewList();
437 }
438
439 /*
440 =========
441 VM_M_getserverliststring
442
443 string  getserverliststring(float field, float hostnr)
444 =========
445 */
446 void VM_M_getserverliststring(void)
447 {
448         serverlist_entry_t *cache;
449         int hostnr;
450
451         VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
452
453         PRVM_G_INT(OFS_RETURN) = OFS_NULL;
454
455         hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
456
457         if(hostnr < 0 || hostnr >= serverlist_viewcount)
458         {
459                 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
460                 return;
461         }
462         cache = serverlist_viewlist[hostnr];
463         switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
464                 case SLIF_CNAME:
465                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.cname );
466                         break;
467                 case SLIF_NAME:
468                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.name );
469                         break;
470                 case SLIF_GAME:
471                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.game );
472                         break;
473                 case SLIF_MOD:
474                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.mod );
475                         break;
476                 case SLIF_MAP:
477                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.map );
478                         break;
479                 // TODO remove this again
480                 case 1024:
481                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line1 );
482                         break;
483                 case 1025:
484                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line2 );
485                         break;
486                 default:
487                         Con_Print("VM_M_getserverliststring: bad field number passed!\n");
488         }
489 }
490
491 /*
492 =========
493 VM_M_getserverlistnumber
494
495 float   getserverlistnumber(float field, float hostnr)
496 =========
497 */
498 void VM_M_getserverlistnumber(void)
499 {
500         serverlist_entry_t *cache;
501         int hostnr;
502
503         VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
504
505         PRVM_G_INT(OFS_RETURN) = OFS_NULL;
506
507         hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
508
509         if(hostnr < 0 || hostnr >= serverlist_viewcount)
510         {
511                 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
512                 return;
513         }
514         cache = serverlist_viewlist[hostnr];
515         switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
516                 case SLIF_MAXPLAYERS:
517                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.maxplayers;
518                         break;
519                 case SLIF_NUMPLAYERS:
520                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numplayers;
521                         break;
522                 case SLIF_PING:
523                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.ping;
524                         break;
525                 case SLIF_PROTOCOL:
526                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.protocol;
527                         break;
528                 default:
529                         Con_Print("VM_M_getserverlistnumber: bad field number passed!\n");
530         }
531 }
532
533 /*
534 ========================
535 VM_M_setserverlistsort
536
537 setserverlistsort(float field, float descending)
538 ========================
539 */
540 void VM_M_setserverlistsort( void )
541 {
542         VM_SAFEPARMCOUNT( 2, VM_M_setserverlistsort );
543
544         serverlist_sortbyfield = (serverlist_infofield_t)((int)PRVM_G_FLOAT( OFS_PARM0 ));
545         serverlist_sortdescending = (qboolean) PRVM_G_FLOAT( OFS_PARM1 );
546 }
547
548 /*
549 ========================
550 VM_M_refreshserverlist
551
552 refreshserverlist()
553 ========================
554 */
555 void VM_M_refreshserverlist( void )
556 {
557         VM_SAFEPARMCOUNT( 0, VM_M_refreshserverlist );
558         ServerList_QueryList(true, false);
559 }
560
561 /*
562 ========================
563 VM_M_getserverlistindexforkey
564
565 float getserverlistindexforkey(string key)
566 ========================
567 */
568 void VM_M_getserverlistindexforkey( void )
569 {
570         const char *key;
571         VM_SAFEPARMCOUNT( 1, VM_M_getserverlistindexforkey );
572
573         key = PRVM_G_STRING( OFS_PARM0 );
574         VM_CheckEmptyString( key );
575
576         if( !strcmp( key, "cname" ) )
577                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CNAME;
578         else if( !strcmp( key, "ping" ) )
579                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PING;
580         else if( !strcmp( key, "game" ) )
581                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_GAME;
582         else if( !strcmp( key, "mod" ) )
583                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MOD;
584         else if( !strcmp( key, "map" ) )
585                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAP;
586         else if( !strcmp( key, "name" ) )
587                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NAME;
588         else if( !strcmp( key, "maxplayers" ) )
589                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAXPLAYERS;
590         else if( !strcmp( key, "numplayers" ) )
591                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMPLAYERS;
592         else if( !strcmp( key, "protocol" ) )
593                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL;
594         else
595                 PRVM_G_FLOAT( OFS_RETURN ) = -1;
596 }
597
598 /*
599 ========================
600 VM_M_addwantedserverlistkey
601
602 addwantedserverlistkey(string key)
603 ========================
604 */
605 void VM_M_addwantedserverlistkey( void )
606 {
607         VM_SAFEPARMCOUNT( 1, VM_M_addwantedserverlistkey );
608 }
609
610 /*
611 ===============================================================================
612 MESSAGE WRITING
613
614 used only for client and menu
615 server uses VM_SV_...
616
617 Write*(* data, float type, float to)
618
619 ===============================================================================
620 */
621
622 #define MSG_BROADCAST   0               // unreliable to all
623 #define MSG_ONE                 1               // reliable to one (msg_entity)
624 #define MSG_ALL                 2               // reliable to all
625 #define MSG_INIT                3               // write to the init string
626
627 sizebuf_t *VM_M_WriteDest (void)
628 {
629         int             dest;
630         int             destclient;
631
632         if(!sv.active)
633                 PRVM_ERROR("VM_M_WriteDest: game is not server (%s)", PRVM_NAME);
634
635         dest = (int)PRVM_G_FLOAT(OFS_PARM1);
636         switch (dest)
637         {
638         case MSG_BROADCAST:
639                 return &sv.datagram;
640
641         case MSG_ONE:
642                 destclient = (int) PRVM_G_FLOAT(OFS_PARM2);
643                 if (destclient < 0 || destclient >= svs.maxclients || !svs.clients[destclient].active || !svs.clients[destclient].netconnection)
644                         PRVM_ERROR("VM_clientcommand: %s: invalid client !", PRVM_NAME);
645
646                 return &svs.clients[destclient].netconnection->message;
647
648         case MSG_ALL:
649                 return &sv.reliable_datagram;
650
651         case MSG_INIT:
652                 return &sv.signon;
653
654         default:
655                 PRVM_ERROR ("WriteDest: bad destination");
656                 break;
657         }
658
659         return NULL;
660 }
661
662 void VM_M_WriteByte (void)
663 {
664         VM_SAFEPARMCOUNT(1, VM_M_WriteByte);
665         MSG_WriteByte (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
666 }
667
668 void VM_M_WriteChar (void)
669 {
670         VM_SAFEPARMCOUNT(1, VM_M_WriteChar);
671         MSG_WriteChar (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
672 }
673
674 void VM_M_WriteShort (void)
675 {
676         VM_SAFEPARMCOUNT(1, VM_M_WriteShort);
677         MSG_WriteShort (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
678 }
679
680 void VM_M_WriteLong (void)
681 {
682         VM_SAFEPARMCOUNT(1, VM_M_WriteLong);
683         MSG_WriteLong (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
684 }
685
686 void VM_M_WriteAngle (void)
687 {
688         VM_SAFEPARMCOUNT(1, VM_M_WriteAngle);
689         MSG_WriteAngle (VM_M_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
690 }
691
692 void VM_M_WriteCoord (void)
693 {
694         VM_SAFEPARMCOUNT(1, VM_M_WriteCoord);
695         MSG_WriteCoord (VM_M_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
696 }
697
698 void VM_M_WriteString (void)
699 {
700         VM_SAFEPARMCOUNT(1, VM_M_WriteString);
701         MSG_WriteString (VM_M_WriteDest(), PRVM_G_STRING(OFS_PARM0));
702 }
703
704 void VM_M_WriteEntity (void)
705 {
706         VM_SAFEPARMCOUNT(1, VM_M_WriteEntity);
707         MSG_WriteShort (VM_M_WriteDest(), PRVM_G_EDICTNUM(OFS_PARM0));
708 }
709
710 //string(void) getextresponse = #624; // returns the next extResponse packet that was sent to this client
711 void VM_M_getextresponse (void)
712 {
713         VM_SAFEPARMCOUNT(0,VM_argv);
714
715         if (net_extresponse_count <= 0)
716                 PRVM_G_INT(OFS_RETURN) = OFS_NULL;
717         else
718         {
719                 int first;
720                 --net_extresponse_count;
721                 first = (net_extresponse_last + NET_EXTRESPONSE_MAX - net_extresponse_count) % NET_EXTRESPONSE_MAX;
722                 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(net_extresponse[first]);
723         }
724 }
725
726 /*
727 =================
728 VM_M_copyentity
729
730 copies data from one entity to another
731
732 copyentity(entity src, entity dst)
733 =================
734 */
735 static void VM_M_copyentity (void)
736 {
737         prvm_edict_t *in, *out;
738         VM_SAFEPARMCOUNT(2,VM_M_copyentity);
739         in = PRVM_G_EDICT(OFS_PARM0);
740         out = PRVM_G_EDICT(OFS_PARM1);
741         memcpy(out->fields.vp, in->fields.vp, prog->progs->entityfields * 4);
742 }
743
744 prvm_builtin_t vm_m_builtins[] = {
745 NULL,                                           //   #0 NULL function (not callable)
746 VM_checkextension,                      //   #1
747 VM_error,                                       //   #2
748 VM_objerror,                            //   #3
749 VM_print,                                       //   #4
750 VM_bprint,                                      //   #5
751 VM_sprint,                                      //   #6
752 VM_centerprint,                         //   #7
753 VM_normalize,                           //   #8
754 VM_vlen,                                        //   #9
755 VM_vectoyaw,                            //  #10
756 VM_vectoangles,                         //  #11
757 VM_random,                                      //  #12
758 VM_localcmd,                            //  #13
759 VM_cvar,                                        //  #14
760 VM_cvar_set,                            //  #15
761 VM_dprint,                                      //  #16
762 VM_ftos,                                        //  #17
763 VM_fabs,                                        //  #18
764 VM_vtos,                                        //  #19
765 VM_etos,                                        //  #20
766 VM_stof,                                        //  #21
767 VM_spawn,                                       //  #22
768 VM_remove,                                      //  #23
769 VM_find,                                        //  #24
770 VM_findfloat,                           //  #25
771 VM_findchain,                           //  #26
772 VM_findchainfloat,                      //  #27
773 VM_precache_file,                       //  #28
774 VM_precache_sound,                      //  #29
775 VM_coredump,                            //  #30
776 VM_traceon,                                     //  #31
777 VM_traceoff,                            //  #32
778 VM_eprint,                                      //  #33
779 VM_rint,                                        //  #34
780 VM_floor,                                       //  #35
781 VM_ceil,                                        //  #36
782 VM_nextent,                                     //  #37
783 VM_sin,                                         //  #38
784 VM_cos,                                         //  #39
785 VM_sqrt,                                        //  #40
786 VM_randomvec,                           //  #41
787 VM_registercvar,                        //  #42
788 VM_min,                                         //  #43
789 VM_max,                                         //  #44
790 VM_bound,                                       //  #45
791 VM_pow,                                         //  #46
792 VM_M_copyentity,                        //  #47
793 VM_fopen,                                       //  #48
794 VM_fclose,                                      //  #49
795 VM_fgets,                                       //  #50
796 VM_fputs,                                       //  #51
797 VM_strlen,                                      //  #52
798 VM_strcat,                                      //  #53
799 VM_substring,                           //  #54
800 VM_stov,                                        //  #55
801 VM_strzone,                                     //  #56
802 VM_strunzone,                           //  #57
803 VM_tokenize,                            //  #58
804 VM_argv,                                        //  #59
805 VM_isserver,                            //  #60
806 VM_clientcount,                         //  #61
807 VM_clientstate,                         //  #62
808 VM_clcommand,                           //  #63
809 VM_changelevel,                         //  #64
810 VM_localsound,                          //  #65
811 VM_getmousepos,                         //  #66
812 VM_gettime,                                     //  #67
813 VM_loadfromdata,                        //  #68
814 VM_loadfromfile,                        //  #69
815 VM_modulo,                                      //  #70
816 VM_cvar_string,                         //  #71
817 VM_crash,                                       //  #72
818 VM_stackdump,                           //  #73
819 VM_search_begin,                        //  #74
820 VM_search_end,                          //  #75
821 VM_search_getsize,                      //  #76
822 VM_search_getfilename,          //  #77
823 VM_chr,                                         //  #78
824 VM_itof,                                        //  #79
825 VM_ftoe,                                        //  #80
826 VM_itof,                                        //  #81 isString
827 VM_altstr_count,                        //  #82
828 VM_altstr_prepare,                      //  #83
829 VM_altstr_get,                          //  #84
830 VM_altstr_set,                          //  #85
831 VM_altstr_ins,                          //  #86
832 VM_findflags,                           //  #87
833 VM_findchainflags,                      //  #88
834 VM_cvar_defstring,                      //  #89
835 NULL,                                           //  #90
836 NULL,                                           //  #91
837 NULL,                                           //  #92
838 NULL,                                           //  #93
839 NULL,                                           //  #94
840 NULL,                                           //  #95
841 NULL,                                           //  #96
842 NULL,                                           //  #97
843 NULL,                                           //  #98
844 NULL,                                           //  #99
845 NULL,                                           // #100
846 NULL,                                           // #101
847 NULL,                                           // #102
848 NULL,                                           // #103
849 NULL,                                           // #104
850 NULL,                                           // #105
851 NULL,                                           // #106
852 NULL,                                           // #107
853 NULL,                                           // #108
854 NULL,                                           // #109
855 NULL,                                           // #110
856 NULL,                                           // #111
857 NULL,                                           // #112
858 NULL,                                           // #113
859 NULL,                                           // #114
860 NULL,                                           // #115
861 NULL,                                           // #116
862 NULL,                                           // #117
863 NULL,                                           // #118
864 NULL,                                           // #119
865 NULL,                                           // #120
866 NULL,                                           // #121
867 NULL,                                           // #122
868 NULL,                                           // #123
869 NULL,                                           // #124
870 NULL,                                           // #125
871 NULL,                                           // #126
872 NULL,                                           // #127
873 NULL,                                           // #128
874 NULL,                                           // #129
875 NULL,                                           // #130
876 NULL,                                           // #131
877 NULL,                                           // #132
878 NULL,                                           // #133
879 NULL,                                           // #134
880 NULL,                                           // #135
881 NULL,                                           // #136
882 NULL,                                           // #137
883 NULL,                                           // #138
884 NULL,                                           // #139
885 NULL,                                           // #140
886 NULL,                                           // #141
887 NULL,                                           // #142
888 NULL,                                           // #143
889 NULL,                                           // #144
890 NULL,                                           // #145
891 NULL,                                           // #146
892 NULL,                                           // #147
893 NULL,                                           // #148
894 NULL,                                           // #149
895 NULL,                                           // #150
896 NULL,                                           // #151
897 NULL,                                           // #152
898 NULL,                                           // #153
899 NULL,                                           // #154
900 NULL,                                           // #155
901 NULL,                                           // #156
902 NULL,                                           // #157
903 NULL,                                           // #158
904 NULL,                                           // #159
905 NULL,                                           // #160
906 NULL,                                           // #161
907 NULL,                                           // #162
908 NULL,                                           // #163
909 NULL,                                           // #164
910 NULL,                                           // #165
911 NULL,                                           // #166
912 NULL,                                           // #167
913 NULL,                                           // #168
914 NULL,                                           // #169
915 NULL,                                           // #170
916 NULL,                                           // #171
917 NULL,                                           // #172
918 NULL,                                           // #173
919 NULL,                                           // #174
920 NULL,                                           // #175
921 NULL,                                           // #176
922 NULL,                                           // #177
923 NULL,                                           // #178
924 NULL,                                           // #179
925 NULL,                                           // #180
926 NULL,                                           // #181
927 NULL,                                           // #182
928 NULL,                                           // #183
929 NULL,                                           // #184
930 NULL,                                           // #185
931 NULL,                                           // #186
932 NULL,                                           // #187
933 NULL,                                           // #188
934 NULL,                                           // #189
935 NULL,                                           // #190
936 NULL,                                           // #191
937 NULL,                                           // #192
938 NULL,                                           // #193
939 NULL,                                           // #194
940 NULL,                                           // #195
941 NULL,                                           // #196
942 NULL,                                           // #197
943 NULL,                                           // #198
944 NULL,                                           // #199
945 NULL,                                           // #200
946 NULL,                                           // #201
947 NULL,                                           // #202
948 NULL,                                           // #203
949 NULL,                                           // #204
950 NULL,                                           // #205
951 NULL,                                           // #206
952 NULL,                                           // #207
953 NULL,                                           // #208
954 NULL,                                           // #209
955 NULL,                                           // #210
956 NULL,                                           // #211
957 NULL,                                           // #212
958 NULL,                                           // #213
959 NULL,                                           // #214
960 NULL,                                           // #215
961 NULL,                                           // #216
962 NULL,                                           // #217
963 NULL,                                           // #218
964 NULL,                                           // #219
965 NULL,                                           // #220
966 NULL,                                           // #221
967 NULL,                                           // #222
968 NULL,                                           // #223
969 NULL,                                           // #224
970 NULL,                                           // #225
971 NULL,                                           // #226
972 NULL,                                           // #227
973 NULL,                                           // #228
974 NULL,                                           // #229
975 NULL,                                           // #230
976 NULL,                                           // #231
977 NULL,                                           // #232
978 NULL,                                           // #233
979 NULL,                                           // #234
980 NULL,                                           // #235
981 NULL,                                           // #236
982 NULL,                                           // #237
983 NULL,                                           // #238
984 NULL,                                           // #239
985 NULL,                                           // #240
986 NULL,                                           // #241
987 NULL,                                           // #242
988 NULL,                                           // #243
989 NULL,                                           // #244
990 NULL,                                           // #245
991 NULL,                                           // #246
992 NULL,                                           // #247
993 NULL,                                           // #248
994 NULL,                                           // #249
995 NULL,                                           // #250
996 NULL,                                           // #251
997 NULL,                                           // #252
998 NULL,                                           // #253
999 NULL,                                           // #254
1000 NULL,                                           // #255
1001 NULL,                                           // #256
1002 NULL,                                           // #257
1003 NULL,                                           // #258
1004 NULL,                                           // #259
1005 NULL,                                           // #260
1006 NULL,                                           // #261
1007 NULL,                                           // #262
1008 NULL,                                           // #263
1009 NULL,                                           // #264
1010 NULL,                                           // #265
1011 NULL,                                           // #266
1012 NULL,                                           // #267
1013 NULL,                                           // #268
1014 NULL,                                           // #269
1015 NULL,                                           // #270
1016 NULL,                                           // #271
1017 NULL,                                           // #272
1018 NULL,                                           // #273
1019 NULL,                                           // #274
1020 NULL,                                           // #275
1021 NULL,                                           // #276
1022 NULL,                                           // #277
1023 NULL,                                           // #278
1024 NULL,                                           // #279
1025 NULL,                                           // #280
1026 NULL,                                           // #281
1027 NULL,                                           // #282
1028 NULL,                                           // #283
1029 NULL,                                           // #284
1030 NULL,                                           // #285
1031 NULL,                                           // #286
1032 NULL,                                           // #287
1033 NULL,                                           // #288
1034 NULL,                                           // #289
1035 NULL,                                           // #290
1036 NULL,                                           // #291
1037 NULL,                                           // #292
1038 NULL,                                           // #293
1039 NULL,                                           // #294
1040 NULL,                                           // #295
1041 NULL,                                           // #296
1042 NULL,                                           // #297
1043 NULL,                                           // #298
1044 NULL,                                           // #299
1045 NULL,                                           // #300
1046 NULL,                                           // #301
1047 NULL,                                           // #302
1048 NULL,                                           // #303
1049 NULL,                                           // #304
1050 NULL,                                           // #305
1051 NULL,                                           // #306
1052 NULL,                                           // #307
1053 NULL,                                           // #308
1054 NULL,                                           // #309
1055 NULL,                                           // #310
1056 NULL,                                           // #311
1057 NULL,                                           // #312
1058 NULL,                                           // #313
1059 NULL,                                           // #314
1060 NULL,                                           // #315
1061 NULL,                                           // #316
1062 NULL,                                           // #317
1063 NULL,                                           // #318
1064 NULL,                                           // #319
1065 NULL,                                           // #320
1066 NULL,                                           // #321
1067 NULL,                                           // #322
1068 NULL,                                           // #323
1069 NULL,                                           // #324
1070 NULL,                                           // #325
1071 NULL,                                           // #326
1072 NULL,                                           // #327
1073 NULL,                                           // #328
1074 NULL,                                           // #329
1075 NULL,                                           // #330
1076 NULL,                                           // #331
1077 NULL,                                           // #332
1078 NULL,                                           // #333
1079 NULL,                                           // #334
1080 NULL,                                           // #335
1081 NULL,                                           // #336
1082 NULL,                                           // #337
1083 NULL,                                           // #338
1084 NULL,                                           // #339
1085 NULL,                                           // #340
1086 NULL,                                           // #341
1087 NULL,                                           // #342
1088 NULL,                                           // #343
1089 NULL,                                           // #344
1090 NULL,                                           // #345
1091 NULL,                                           // #346
1092 NULL,                                           // #347
1093 NULL,                                           // #348
1094 NULL,                                           // #349
1095 NULL,                                           // #350
1096 NULL,                                           // #351
1097 NULL,                                           // #352
1098 NULL,                                           // #353
1099 NULL,                                           // #354
1100 NULL,                                           // #355
1101 NULL,                                           // #356
1102 NULL,                                           // #357
1103 NULL,                                           // #358
1104 NULL,                                           // #359
1105 NULL,                                           // #360
1106 NULL,                                           // #361
1107 NULL,                                           // #362
1108 NULL,                                           // #363
1109 NULL,                                           // #364
1110 NULL,                                           // #365
1111 NULL,                                           // #366
1112 NULL,                                           // #367
1113 NULL,                                           // #368
1114 NULL,                                           // #369
1115 NULL,                                           // #370
1116 NULL,                                           // #371
1117 NULL,                                           // #372
1118 NULL,                                           // #373
1119 NULL,                                           // #374
1120 NULL,                                           // #375
1121 NULL,                                           // #376
1122 NULL,                                           // #377
1123 NULL,                                           // #378
1124 NULL,                                           // #379
1125 NULL,                                           // #380
1126 NULL,                                           // #381
1127 NULL,                                           // #382
1128 NULL,                                           // #383
1129 NULL,                                           // #384
1130 NULL,                                           // #385
1131 NULL,                                           // #386
1132 NULL,                                           // #387
1133 NULL,                                           // #388
1134 NULL,                                           // #389
1135 NULL,                                           // #390
1136 NULL,                                           // #391
1137 NULL,                                           // #392
1138 NULL,                                           // #393
1139 NULL,                                           // #394
1140 NULL,                                           // #395
1141 NULL,                                           // #396
1142 NULL,                                           // #397
1143 NULL,                                           // #398
1144 NULL,                                           // #399
1145 NULL,                                           // #400
1146 VM_M_WriteByte,                         // #401
1147 VM_M_WriteChar,                         // #402
1148 VM_M_WriteShort,                        // #403
1149 VM_M_WriteLong,                         // #404
1150 VM_M_WriteAngle,                        // #405
1151 VM_M_WriteCoord,                        // #406
1152 VM_M_WriteString,                       // #407
1153 VM_M_WriteEntity,                       // #408
1154 NULL,                                           // #409
1155 NULL,                                           // #410
1156 NULL,                                           // #411
1157 NULL,                                           // #412
1158 NULL,                                           // #413
1159 NULL,                                           // #414
1160 NULL,                                           // #415
1161 NULL,                                           // #416
1162 NULL,                                           // #417
1163 NULL,                                           // #418
1164 NULL,                                           // #419
1165 NULL,                                           // #420
1166 NULL,                                           // #421
1167 NULL,                                           // #422
1168 NULL,                                           // #423
1169 NULL,                                           // #424
1170 NULL,                                           // #425
1171 NULL,                                           // #426
1172 NULL,                                           // #427
1173 NULL,                                           // #428
1174 NULL,                                           // #429
1175 NULL,                                           // #430
1176 NULL,                                           // #431
1177 NULL,                                           // #432
1178 NULL,                                           // #433
1179 NULL,                                           // #434
1180 NULL,                                           // #435
1181 NULL,                                           // #436
1182 NULL,                                           // #437
1183 NULL,                                           // #438
1184 NULL,                                           // #439
1185 NULL,                                           // #440
1186 NULL,                                           // #441
1187 NULL,                                           // #442
1188 NULL,                                           // #443
1189 NULL,                                           // #444
1190 NULL,                                           // #445
1191 NULL,                                           // #446
1192 NULL,                                           // #447
1193 NULL,                                           // #448
1194 NULL,                                           // #449
1195 NULL,                                           // #450
1196 VM_iscachedpic,                         // #451 draw functions...
1197 VM_precache_pic,                        // #452
1198 VM_freepic,                                     // #453
1199 VM_drawcharacter,                       // #454
1200 VM_drawstring,                          // #455
1201 VM_drawpic,                                     // #456
1202 VM_drawfill,                            // #457
1203 VM_drawsetcliparea,                     // #458
1204 VM_drawresetcliparea,           // #459
1205 VM_getimagesize,                        // #460
1206 VM_cin_open,                            // #461
1207 VM_cin_close,                           // #462
1208 VM_cin_setstate,                        // #463
1209 VM_cin_getstate,                        // #464
1210 VM_cin_restart,                         // #465
1211 VM_drawline,                            // #466
1212 NULL,                                           // #467
1213 NULL,                                           // #468
1214 NULL,                                           // #469
1215 NULL,                                           // #470
1216 VM_asin,                                        // #471 float(float s) VM_asin (DP_QC_ASINACOSATANATAN2TAN)
1217 VM_acos,                                        // #472 float(float c) VM_acos (DP_QC_ASINACOSATANATAN2TAN)
1218 VM_atan,                                        // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
1219 VM_atan2,                                       // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
1220 VM_tan,                                         // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
1221 VM_strlennocol,                         // #476 float(string s) : DRESK - String Length (not counting color codes) (DP_QC_STRINGCOLORFUNCTIONS)
1222 VM_strdecolorize,                       // #477 string(string s) : DRESK - Decolorized String (DP_QC_STRINGCOLORFUNCTIONS)
1223 VM_strftime,                            // #478 string(float uselocaltime, string format, ...) (DP_QC_STRFTIME)
1224 VM_tokenizebyseparator,         // #479 float(string s) tokenizebyseparator (DP_QC_TOKENIZEBYSEPARATOR)
1225 NULL,                                           // #480
1226 NULL,                                           // #481
1227 NULL,                                           // #482
1228 NULL,                                           // #483
1229 NULL,                                           // #484
1230 NULL,                                           // #485
1231 NULL,                                           // #486
1232 NULL,                                           // #487
1233 NULL,                                           // #488
1234 NULL,                                           // #489
1235 NULL,                                           // #490
1236 NULL,                                           // #491
1237 NULL,                                           // #492
1238 NULL,                                           // #493
1239 NULL,                                           // #494
1240 NULL,                                           // #495
1241 NULL,                                           // #496
1242 NULL,                                           // #497
1243 NULL,                                           // #498
1244 NULL,                                           // #499
1245 NULL,                                           // #500
1246 NULL,                                           // #501
1247 NULL,                                           // #502
1248 NULL,                                           // #503
1249 NULL,                                           // #504
1250 NULL,                                           // #505
1251 NULL,                                           // #506
1252 NULL,                                           // #507
1253 NULL,                                           // #508
1254 NULL,                                           // #509
1255 NULL,                                           // #510
1256 NULL,                                           // #511
1257 NULL,                                           // #512
1258 NULL,                                           // #513
1259 NULL,                                           // #514
1260 NULL,                                           // #515
1261 NULL,                                           // #516
1262 NULL,                                           // #517
1263 NULL,                                           // #518
1264 NULL,                                           // #519
1265 NULL,                                           // #520
1266 NULL,                                           // #521
1267 NULL,                                           // #522
1268 NULL,                                           // #523
1269 NULL,                                           // #524
1270 NULL,                                           // #525
1271 NULL,                                           // #526
1272 NULL,                                           // #527
1273 NULL,                                           // #528
1274 NULL,                                           // #529
1275 NULL,                                           // #530
1276 NULL,                                           // #531
1277 NULL,                                           // #532
1278 NULL,                                           // #533
1279 NULL,                                           // #534
1280 NULL,                                           // #535
1281 NULL,                                           // #536
1282 NULL,                                           // #537
1283 NULL,                                           // #538
1284 NULL,                                           // #539
1285 NULL,                                           // #540
1286 NULL,                                           // #541
1287 NULL,                                           // #542
1288 NULL,                                           // #543
1289 NULL,                                           // #544
1290 NULL,                                           // #545
1291 NULL,                                           // #546
1292 NULL,                                           // #547
1293 NULL,                                           // #548
1294 NULL,                                           // #549
1295 NULL,                                           // #550
1296 NULL,                                           // #551
1297 NULL,                                           // #552
1298 NULL,                                           // #553
1299 NULL,                                           // #554
1300 NULL,                                           // #555
1301 NULL,                                           // #556
1302 NULL,                                           // #557
1303 NULL,                                           // #558
1304 NULL,                                           // #559
1305 NULL,                                           // #560
1306 NULL,                                           // #561
1307 NULL,                                           // #562
1308 NULL,                                           // #563
1309 NULL,                                           // #564
1310 NULL,                                           // #565
1311 NULL,                                           // #566
1312 NULL,                                           // #567
1313 NULL,                                           // #568
1314 NULL,                                           // #569
1315 NULL,                                           // #570
1316 NULL,                                           // #571
1317 NULL,                                           // #572
1318 NULL,                                           // #573
1319 NULL,                                           // #574
1320 NULL,                                           // #575
1321 NULL,                                           // #576
1322 NULL,                                           // #577
1323 NULL,                                           // #578
1324 NULL,                                           // #579
1325 NULL,                                           // #580
1326 NULL,                                           // #581
1327 NULL,                                           // #582
1328 NULL,                                           // #583
1329 NULL,                                           // #584
1330 NULL,                                           // #585
1331 NULL,                                           // #586
1332 NULL,                                           // #587
1333 NULL,                                           // #588
1334 NULL,                                           // #589
1335 NULL,                                           // #590
1336 NULL,                                           // #591
1337 NULL,                                           // #592
1338 NULL,                                           // #593
1339 NULL,                                           // #594
1340 NULL,                                           // #595
1341 NULL,                                           // #596
1342 NULL,                                           // #597
1343 NULL,                                           // #598
1344 NULL,                                           // #599
1345 NULL,                                           // #600
1346 VM_M_setkeydest,                        // #601 menu functions...
1347 VM_M_getkeydest,                        // #602
1348 VM_M_setmousetarget,            // #603
1349 VM_M_getmousetarget,            // #604
1350 VM_M_callfunction,                      // #605
1351 VM_writetofile,                         // #606
1352 VM_M_isfunction,                        // #607
1353 VM_M_getresolution,                     // #608
1354 VM_keynumtostring,                      // #609
1355 VM_M_findkeysforcommand,        // #610
1356 VM_M_getserverliststat,         // #611
1357 VM_M_getserverliststring,       // #612
1358 VM_parseentitydata,                     // #613
1359 VM_stringtokeynum,                      // #614
1360 VM_M_resetserverlistmasks,      // #615
1361 VM_M_setserverlistmaskstring,// #616
1362 VM_M_setserverlistmasknumber,// #617
1363 VM_M_resortserverlist,          // #618
1364 VM_M_setserverlistsort,         // #619
1365 VM_M_refreshserverlist,         // #620
1366 VM_M_getserverlistnumber,       // #621
1367 VM_M_getserverlistindexforkey,// #622
1368 VM_M_addwantedserverlistkey,// #623
1369 VM_M_getextresponse                     // #624
1370 };
1371
1372 const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);
1373
1374 void VM_M_Cmd_Init(void)
1375 {
1376         VM_Cmd_Init();
1377 }
1378
1379 void VM_M_Cmd_Reset(void)
1380 {
1381         //VM_Cmd_Init();
1382         VM_Cmd_Reset();
1383 }