-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.c
1864 lines (1527 loc) · 40 KB
/
common.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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 1996-1997 Id Software, Inc.
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.
*/
// common.c -- misc functions used in client and server
#include "quakedef.h"
#define NUM_SAFE_ARGVS 6
static char *largv[MAX_NUM_ARGVS + NUM_SAFE_ARGVS + 1];
static char *argvdummy = " ";
static char *safeargvs[NUM_SAFE_ARGVS] =
{"-nolan", "-nosound", "-nocdaudio", "-nojoy", "-nomouse", "-nomidi"};
cvar_t registered = {"registered","0"};
cvar_t oem = {"oem","0"};
cvar_t cmdline = {"cmdline","0", false, true};
qboolean com_modified; // set true if using non-raven files
qboolean com_oem;
int static_registered = 1; // only for startup check, then set
void COM_InitFilesystem (void);
void COM_Path_f (void);
// if a packfile directory differs from this, it is assumed to be hacked
// demo
#define PAK0_DEMO_COUNT 797 // pak0.pak, demo v1.11
#define PAK0_DEMO_CRC 22780
// retail
#define PAK0_COUNT 696 // pak0.pak, registered
#define PAK0_CRC 34289
#define PAK1_COUNT 523 // pak1.pak, registered
#define PAK1_CRC 2995
// oem
#define PAK0_OEM_COUNT 697 // pak0.pak, oem, v1.11
#define PAK0_OEM_CRC 9787
#define PAK2_OEM_COUNT 183 // pak2.pak, oem, v1.11
#define PAK2_OEM_CRC 4807
// portals
#define PAK3_COUNT 245 // pak3.pak, portals
#define PAK3_CRC 1478
char com_token[1024];
int com_argc;
char **com_argv;
#define CMDLINE_LENGTH 256
char com_cmdline[CMDLINE_LENGTH];
qboolean portals = false;
// this graphic needs to be in the pak file to use registered features
unsigned short pop[] =
{
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
,0x0000,0x0000,0x6600,0x0000,0x0000,0x0000,0x6600,0x0000
,0x0000,0x0066,0x0000,0x0000,0x0000,0x0000,0x0067,0x0000
,0x0000,0x6665,0x0000,0x0000,0x0000,0x0000,0x0065,0x6600
,0x0063,0x6561,0x0000,0x0000,0x0000,0x0000,0x0061,0x6563
,0x0064,0x6561,0x0000,0x0000,0x0000,0x0000,0x0061,0x6564
,0x0064,0x6564,0x0000,0x6469,0x6969,0x6400,0x0064,0x6564
,0x0063,0x6568,0x6200,0x0064,0x6864,0x0000,0x6268,0x6563
,0x0000,0x6567,0x6963,0x0064,0x6764,0x0063,0x6967,0x6500
,0x0000,0x6266,0x6769,0x6a68,0x6768,0x6a69,0x6766,0x6200
,0x0000,0x0062,0x6566,0x6666,0x6666,0x6666,0x6562,0x0000
,0x0000,0x0000,0x0062,0x6364,0x6664,0x6362,0x0000,0x0000
,0x0000,0x0000,0x0000,0x0062,0x6662,0x0000,0x0000,0x0000
,0x0000,0x0000,0x0000,0x0061,0x6661,0x0000,0x0000,0x0000
,0x0000,0x0000,0x0000,0x0000,0x6500,0x0000,0x0000,0x0000
,0x0000,0x0000,0x0000,0x0000,0x6400,0x0000,0x0000,0x0000
};
/*
All of Quake's data access is through a hierchal file system, but the contents of the
file system can be transparently merged from several sources.
The "base directory" is the path to the directory holding the quake.exe and all game
directories. The sys_* files pass this to host_init in quakeparms_t->basedir. This
can be overridden with the "-basedir" command line parm to allow code debugging in a
different directory. The base directory is
only used during filesystem initialization.
The "game directory" is the first tree on the search path and directory that all generated
files (savegames, screenshots, demos, config files) will be saved to. This can be
overridden with the "-game" command line parameter. The game directory can never be
changed while quake is executing. This is a precacution against having a malicious
server instruct clients to write files over areas they shouldn't.
The "cache directory" is only used during development to save network bandwidth,
especially over ISDN / T1 lines. If there is a cache directory
specified, when a file is found by the normal search path, it will be mirrored
into the cache directory, then opened there.
FIXME:
The file "parms.txt" will be read out of the game directory and appended to the current
command line arguments to allow different games to initialize startup parms differently.
This could be used to add a "-sspeed 22050" for the high quality sound edition. Because
they are added at the end, they will not override an explicit setting on the original
command line.
*/
//============================================================================
qboolean IsTimeout (float *prevtime, float waittime)
{
float currtime = Sys_DoubleTime ();
if (*prevtime && currtime - *prevtime < waittime)
return false;
*prevtime = currtime;
return true;
}
// ClearLink is used for new headnodes
void ClearLink (link_t *l)
{
l->prev = l->next = l;
}
void RemoveLink (link_t *l)
{
l->next->prev = l->prev;
l->prev->next = l->next;
}
void InsertLinkBefore (link_t *l, link_t *before)
{
l->next = before;
l->prev = before->prev;
l->prev->next = l;
l->next->prev = l;
}
void InsertLinkAfter (link_t *l, link_t *after)
{
l->next = after->next;
l->prev = after;
l->prev->next = l;
l->next->prev = l;
}
/*
============================================================================
LIBRARY REPLACEMENT FUNCTIONS
============================================================================
*/
/*
Q_strnlen
strlen with a cutoff
*/
size_t Q_strnlen (const char *s, size_t maxlen)
{
size_t i;
for (i = 0; i < maxlen && s[i]; i++);
return i;
}
/*
============================================================================
BYTE ORDER FUNCTIONS
============================================================================
*/
qboolean bigendian;
short (*BigShort) (short l);
short (*LittleShort) (short l);
int (*BigLong) (int l);
int (*LittleLong) (int l);
float (*BigFloat) (float l);
float (*LittleFloat) (float l);
short ShortSwap (short l)
{
byte b1,b2;
b1 = l&255;
b2 = (l>>8)&255;
return (b1<<8) + b2;
}
short ShortNoSwap (short l)
{
return l;
}
int LongSwap (int l)
{
byte b1,b2,b3,b4;
b1 = l&255;
b2 = (l>>8)&255;
b3 = (l>>16)&255;
b4 = (l>>24)&255;
return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
}
int LongNoSwap (int l)
{
return l;
}
float FloatSwap (float f)
{
union
{
float f;
byte b[4];
} dat1, dat2;
dat1.f = f;
dat2.b[0] = dat1.b[3];
dat2.b[1] = dat1.b[2];
dat2.b[2] = dat1.b[1];
dat2.b[3] = dat1.b[0];
return dat2.f;
}
float FloatNoSwap (float f)
{
return f;
}
/*
==============================================================================
MESSAGE IO FUNCTIONS
Handles byte ordering and avoids alignment errors
==============================================================================
*/
//
// writing functions
//
void MSG_WriteChar (sizebuf_t *sb, int c)
{
byte *buf;
buf = SZ_GetSpace (sb, 1);
buf[0] = c;
}
void MSG_WriteByte (sizebuf_t *sb, int c)
{
byte *buf;
buf = SZ_GetSpace (sb, 1);
buf[0] = c;
}
void MSG_WriteShort (sizebuf_t *sb, int c)
{
byte *buf;
buf = SZ_GetSpace (sb, 2);
buf[0] = c&0xff;
buf[1] = c>>8;
}
void MSG_WriteLong (sizebuf_t *sb, int c)
{
byte *buf;
buf = SZ_GetSpace (sb, 4);
buf[0] = c&0xff;
buf[1] = (c>>8)&0xff;
buf[2] = (c>>16)&0xff;
buf[3] = c>>24;
}
void MSG_WriteFloat (sizebuf_t *sb, float f)
{
union
{
float f;
int l;
} dat;
dat.f = f;
dat.l = LittleLong (dat.l);
SZ_Write (sb, &dat.l, 4);
}
void MSG_WriteString (sizebuf_t *sb, char *s)
{
if (!s)
SZ_Write (sb, "", 1);
else
SZ_Write (sb, s, strlen(s)+1);
}
//johnfitz -- original behavior, 13.3 fixed point coords, max range +-4096
void MSG_WriteCoord16 (sizebuf_t *sb, float f)
{
MSG_WriteShort (sb, Q_rint(f * 8.0));
}
//johnfitz -- 16.8 fixed point coords, max range +-32768
void MSG_WriteCoord24 (sizebuf_t *sb, float f)
{
MSG_WriteShort (sb, f);
MSG_WriteByte (sb, (int)(f * 255.0) % 255);
}
//johnfitz -- 32-bit float coords
void MSG_WriteCoord32f (sizebuf_t *sb, float f)
{
MSG_WriteFloat (sb, f);
}
void MSG_WriteCoord (sizebuf_t *sb, float f)
{
MSG_WriteShort (sb, (int)(f * 8.0));
}
void MSG_WriteAngle (sizebuf_t *sb, float f)
{
MSG_WriteByte (sb, (int)(f * 256.0 / 360.0) & 255);
}
// precise aim for ProQuake
void MSG_WritePreciseAngle (sizebuf_t *sb, float f)
{
MSG_WriteShort (sb, (int)(f * 65536.0 / 360.0) & 65535);
}
//johnfitz -- for PROTOCOL_FITZQUAKE
void MSG_WriteAngle16 (sizebuf_t *sb, float f)
{
MSG_WriteShort (sb, Q_rint(f * 65536.0 / 360.0) & 65535); //johnfitz -- use Q_rint instead of (int)
}
//johnfitz
//
// reading functions
//
void MSG_BeginReading (qmsg_t *msg)
{
msg->readcount = 0;
msg->badread = false;
}
// returns -1 and sets msg_badread if no more characters are available
int MSG_ReadChar (qmsg_t *msg)
{
if (msg->readcount + 1 <= msg->message->cursize)
return (signed char) msg->message->data[msg->readcount++];
msg->badread = true;
return -1;
}
int MSG_ReadByte (qmsg_t *msg)
{
if (msg->readcount + 1 <= msg->message->cursize)
return (byte) msg->message->data[msg->readcount++];
msg->badread = true;
return -1;
}
// JPG - need this to check for ProQuake messages
int MSG_PeekByte (qmsg_t *msg)
{
if (msg->readcount + 1 <= msg->message->cursize)
return (byte) msg->message->data[msg->readcount];
msg->badread = true;
return -1;
}
int MSG_ReadShort (qmsg_t *msg)
{
int c;
if (msg->readcount + 2 <= msg->message->cursize)
{
c = (short) (msg->message->data[msg->readcount]
+ (msg->message->data[msg->readcount + 1] << 8));
msg->readcount += 2;
return c;
}
msg->readcount = msg->message->cursize;
msg->badread = true;
return -1;
}
int MSG_ReadLong (qmsg_t *msg)
{
int c;
if (msg->readcount + 4 <= msg->message->cursize)
{
c = msg->message->data[msg->readcount]
+ (msg->message->data[msg->readcount + 1] << 8)
+ (msg->message->data[msg->readcount + 2] << 16)
+ (msg->message->data[msg->readcount + 3] << 24);
msg->readcount += 4;
return c;
}
msg->readcount = msg->message->cursize;
msg->badread = true;
return -1;
}
float MSG_ReadFloat (qmsg_t *msg)
{
union
{
byte b[4];
float f;
int l;
} dat;
if (msg->readcount + 4 <= msg->message->cursize)
{
dat.b[0] = msg->message->data[msg->readcount];
dat.b[1] = msg->message->data[msg->readcount + 1];
dat.b[2] = msg->message->data[msg->readcount + 2];
dat.b[3] = msg->message->data[msg->readcount + 3];
msg->readcount += 4;
dat.l = LittleLong (dat.l);
return dat.f;
}
msg->readcount = msg->message->cursize;
msg->badread = true;
return -1;
}
char *MSG_ReadString (qmsg_t *msg)
{
char *string;
size_t len, maxlen;
if (msg->badread || msg->readcount + 1 > msg->message->cursize)
{
msg->badread = true;
return "";
}
string = (char *)&msg->message->data[msg->readcount];
maxlen = msg->message->cursize - msg->readcount;
len = strnlen (string, maxlen);
if (len == maxlen)
{
msg->readcount = msg->readcount;
msg->badread = true;
if (len + 1 > msg->badread_string_size)
{
if (msg->badread_string)
free (msg->badread_string);
msg->badread_string = malloc (len + 1);
msg->badread_string_size = len + 1;
}
if (!msg->badread_string)
Sys_Error ("MSG_ReadString: out of memory");
strncpy (msg->badread_string, string, len);
msg->badread_string[len] = 0;
return msg->badread_string;
}
msg->readcount += len + 1;
return string;
}
//johnfitz -- original behavior, 13.3 fixed point coords, max range +-4096
float MSG_ReadCoord16 (qmsg_t *msg)
{
return MSG_ReadShort (msg) * (1.0 / 8.0);
}
//johnfitz -- 16.8 fixed point coords, max range +-32768
float MSG_ReadCoord24 (qmsg_t *msg)
{
return MSG_ReadShort (msg) + MSG_ReadByte (msg) * (1.0 / 255.0);
}
//johnfitz -- 32-bit float coords
float MSG_ReadCoord32f (qmsg_t *msg)
{
return MSG_ReadFloat (msg);
}
float MSG_ReadCoord (qmsg_t *msg)
{
return MSG_ReadShort (msg) * (1.0 / 8.0);
}
float MSG_ReadAngle (qmsg_t *msg)
{
return MSG_ReadChar (msg) * (360.0 / 256.0);
}
// precise aim for ProQuake
float MSG_ReadPreciseAngle (qmsg_t *msg)
{
return MSG_ReadShort (msg) * (360.0 / 65536.0);
}
//johnfitz -- for PROTOCOL_FITZQUAKE
float MSG_ReadAngle16 (qmsg_t *msg)
{
return MSG_ReadShort (msg) * (360.0 / 65536.0);
}
//johnfitz
//===========================================================================
void SZ_Alloc (sizebuf_t *buf, int startsize)
{
if (startsize < 256)
startsize = 256;
buf->data = Hunk_AllocName (startsize, "sizebuf");
buf->maxsize = startsize;
buf->cursize = 0;
}
void SZ_Free (sizebuf_t *buf)
{
buf->cursize = 0;
}
void SZ_Clear (sizebuf_t *buf)
{
buf->cursize = 0;
}
void *SZ_GetSpace (sizebuf_t *buf, int length)
{
void *data;
if (buf->cursize + length > buf->maxsize)
{
if (!buf->allowoverflow)
Sys_Error ("SZ_GetSpace: overflow without allowoverflow set (%d, max = %d)", buf->cursize + length, buf->maxsize);
if (length > buf->maxsize)
Sys_Error ("SZ_GetSpace: %i is > full buffer size %d", length, buf->maxsize);
buf->overflowed = true;
Con_Printf ("SZ_GetSpace: overflow (%d, max = %d)\n", buf->cursize + length, buf->maxsize);
SZ_Clear (buf);
}
data = buf->data + buf->cursize;
buf->cursize += length;
return data;
}
void SZ_Write (sizebuf_t *buf, void *data, int length)
{
memcpy (SZ_GetSpace(buf,length),data,length);
}
void SZ_Print (sizebuf_t *buf, char *data)
{
int len;
len = strlen(data)+1;
// byte * cast to keep VC++ happy
if (!buf->cursize || buf->data[buf->cursize-1]) // If buf->data has a trailing zero, overwrite it
memcpy ((byte *)SZ_GetSpace(buf, len),data,len); // no trailing 0
else
memcpy ((byte *)SZ_GetSpace(buf, len-1)-1,data,len); // write over trailing 0
}
//============================================================================
/*
============
COM_SkipPath
============
*/
char *COM_SkipPath (char *pathname)
{
char *last;
last = pathname;
while (*pathname)
{
if (*pathname=='/')
last = pathname+1;
pathname++;
}
return last;
}
/*
============
COM_StripExtension
============
*/
void COM_StripExtension (char *in, char *out)
{
while (*in && *in != '.')
*out++ = *in++;
*out = 0;
}
/*
============
COM_FileExtension
============
*/
char *COM_FileExtension (char *in)
{
static char exten[8];
int i;
while (*in && *in != '.')
in++;
if (!*in)
return "";
in++;
for (i=0 ; i<7 && *in ; i++,in++)
exten[i] = *in;
exten[i] = 0;
return exten;
}
/*
============
COM_FileBase
============
*/
void COM_FileBase (char *in, char *out)
{
char *s, *s2;
s = in + strlen(in) - 1;
while (s != in && *s != '.')
s--;
for (s2 = s ; s2 != in && *s2 != '/' && *s2 != '\\'; s2--)
;
if (s-s2 < 2)
strcpy (out,"?model?");
else
{
if (*s2 == '/' || *s2 == '\\')
++s2;
if (s - s2 >= 32)
s = s2 + 32 - 1;
strncpy (out,s2, s-s2);
out[s-s2] = 0;
}
}
/*
==================
COM_DefaultExtension
==================
*/
void COM_DefaultExtension (char *path, char *extension)
{
char *src;
//
// if path doesn't have a .EXT, append extension
// (extension should include the .)
//
src = path + strlen(path) - 1;
while (*src != '/' && src != path)
{
if (*src == '.')
return; // it has an extension
src--;
}
strcat (path, extension);
}
/*
==============
COM_Parse
Parse a token out of a string
==============
*/
char *COM_Parse (char *data)
{
int c;
int len;
len = 0;
com_token[0] = 0;
if (!data)
return NULL;
// skip whitespace
skipwhite:
while ( (c = *data) <= ' ')
{
if (c == 0)
return NULL; // end of file;
data++;
}
// skip // comments
if (c=='/' && data[1] == '/')
{
while (*data && *data != '\n')
data++;
goto skipwhite;
}
// handle quoted strings specially
if (c == '\"')
{
data++;
while (1)
{
c = *data++;
if (c=='\"' || !c)
{
com_token[len] = 0;
return !c ? NULL : data; // NULL, otherwise data becomes out of bounds
}
com_token[len] = c;
len++;
}
}
// parse single characters
if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
{
com_token[len] = c;
len++;
com_token[len] = 0;
return data+1;
}
// parse a regular word
do
{
com_token[len] = c;
data++;
len++;
c = *data;
// commented out the check for ':' so that ip:port works
if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' /* || c==':' */)
break;
} while (c>32);
com_token[len] = 0;
return data;
}
/*
================
COM_CheckParm
Returns the position (1 to argc-1) in the program's argument list
where the given parameter apears, or 0 if not present
================
*/
int COM_CheckParm (char *parm)
{
int i;
for (i=1 ; i<com_argc ; i++)
{
if (!com_argv[i])
continue; // NEXTSTEP sometimes clears appkit vars.
if (!strcmp (parm,com_argv[i]))
return i;
}
return 0;
}
/*
================
COM_CheckRegistered
Looks for the pop.txt file and verifies it.
Sets the "registered" cvar.
Immediately exits out if an alternate game was attempted to be started without
being registered.
================
*/
void COM_CheckRegistered (void)
{
int h;
unsigned short check[128];
int i;
COM_OpenFile("gfx/pop.lmp", &h, NULL);
static_registered = 0;
//-basedir c:\h3\test -game data1 +exec rick.cfg
if (h == -1)
{
Con_Printf ("Playing demo version.\n");
if (com_modified)
Sys_Error ("You must have the full version to use modified games");
return;
}
Sys_FileRead (h, check, sizeof(check));
COM_CloseFile (h);
for (i=0 ; i<128 ; i++)
if (pop[i] != (unsigned short)BigShort (check[i]))
Sys_Error ("Corrupted data file.");
Cvar_Set ("cmdline", com_cmdline+1); // johnfitz: eliminate leading space
Cvar_Set ("registered", "1");
if (com_oem)
Cvar_Set ("oem", "1");
static_registered = 1;
Con_Printf ("Playing %s version.\n", com_oem ? "oem" : "retail");
}
/*
================
COM_InitArgv
================
*/
void COM_InitArgv (int argc, char **argv)
{
qboolean safe;
int i, j, n;
// reconstitute the command line for the cmdline externally visible cvar
n = 0;
for (j=0 ; (j<MAX_NUM_ARGVS) && (j< argc) ; j++)
{
i = 0;
while ((n < (CMDLINE_LENGTH - 1)) && argv[j][i])
{
com_cmdline[n++] = argv[j][i++];
}
if (n < (CMDLINE_LENGTH - 1))
com_cmdline[n++] = ' ';
else
break;
}
if (n > 0 && com_cmdline[n-1] == ' ')
com_cmdline[n-1] = 0; // johnfitz: kill the trailing space
Con_Printf("Command line: %s\n", com_cmdline);
safe = false;
for (com_argc=0 ; (com_argc<MAX_NUM_ARGVS) && (com_argc < argc) ; com_argc++)
{
largv[com_argc] = argv[com_argc];
if (!strcmp ("-safe", argv[com_argc]))
safe = true;
}
if (safe)
{
// force all the safe-mode switches. Note that we reserved extra space in
// case we need to add these, so we don't need an overflow check
for (i=0 ; i<NUM_SAFE_ARGVS ; i++)
{
largv[com_argc] = safeargvs[i];
com_argc++;
}
}
largv[com_argc] = argvdummy;
com_argv = largv;
if (COM_CheckParm ("-portals") || COM_CheckParm ("-pop") || COM_CheckParm ("-missionpack") || COM_CheckParm ("-h2mp"))
portals = true;
}
/*
================
COM_Init
================
*/
void COM_Init (void)
{
unsigned short byteorder = 1; /* 0x0001 */
// set the byte swapping variables in a portable manner
if ( *((byte *) &byteorder) == 1 )
{
bigendian = false;
BigShort = ShortSwap;
LittleShort = ShortNoSwap;
BigLong = LongSwap;
LittleLong = LongNoSwap;
BigFloat = FloatSwap;
LittleFloat = FloatNoSwap;
}
else
{
bigendian = true;
BigShort = ShortNoSwap;
LittleShort = ShortSwap;
BigLong = LongNoSwap;
LittleLong = LongSwap;
BigFloat = FloatNoSwap;
LittleFloat = FloatSwap;
}
Cvar_RegisterVariable (®istered, NULL);
Cvar_RegisterVariable (&oem, NULL);
Cvar_RegisterVariable (&cmdline, NULL);
Cmd_AddCommand ("path", COM_Path_f);
COM_InitFilesystem ();
COM_CheckRegistered ();
}
/*
============
va
does a varargs printf into a temp buffer, so I don't need to have
varargs versions of all text functions.
cycles between NUM_BUFFS different static buffers.
FIXME: make this buffer size safe someday
============
*/
#define NUM_BUFFS 8
char *va(char *format, ...)
{
va_list argptr;
static char string[NUM_BUFFS][MAX_PRINTMSG]; // was 1024, changed to array
static int idx = 0;
idx++;
if (idx == NUM_BUFFS)
idx = 0;
va_start (argptr, format);
vsnprintf (string[idx], sizeof(string[idx]), format, argptr);
va_end (argptr);
return string[idx];
}