-
Notifications
You must be signed in to change notification settings - Fork 2
/
d_main.c
1839 lines (1599 loc) · 53.7 KB
/
d_main.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
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id: d_main.c,v 1.3 2000-08-12 21:29:25 fraggle Exp $
//
// Copyright (C) 1993-1996 by 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
//
// DESCRIPTION:
// DOOM main program (D_DoomMain) and game loop, plus functions to
// determine game mode (shareware, registered), parse command line
// parameters, configure game parameters (turbo), and call the startup
// functions.
//
//-----------------------------------------------------------------------------
static const char rcsid[] = "$Id: d_main.c,v 1.3 2000-08-12 21:29:25 fraggle Exp $";
#include <unistd.h>
//#include <sys/types.h> // GB 2014 not needed here
#include <sys/stat.h>
//#include <fcntl.h> // GB 2014 not needed here
#include <gppconio.h> // GB 2014, gotoxy, textcolor
#include <sys/nearptr.h> // needed for __djgpp_nearptr_enable() -- stan
#include <dos.h> // GB 2014, for get dos version (and delay)
#include "doomdef.h" // GB 2014 not needed here. Sakitoshi 2019 needed now :)
#include "doomstat.h"
#include "dstrings.h"
//#include "sounds.h" // GB 2014 not needed here
#include "z_zone.h"
#include "w_wad.h"
#include "s_sound.h"
#include "v_video.h"
#include "f_finale.h"
#include "f_wipe.h"
#include "m_argv.h"
#include "m_misc.h"
#include "m_menu.h"
#include "i_system.h"
#include "i_sound.h"
#include "i_video.h"
#include "g_game.h"
#include "hu_stuff.h"
#include "wi_stuff.h"
#include "st_stuff.h"
#include "am_map.h"
#include "p_setup.h"
#include "r_draw.h"
#include "r_main.h"
#include "d_main.h"
#include "d_deh.h" // Ty 04/08/98 - Externalizations
#include "crc32.h" // Sakitoshi 2019, to calculate crc of the mission packs
// DEHacked support - Ty 03/09/97
// killough 10/98:
// Add lump number as third argument, for use when filename==NULL
void ProcessDehFile(char *filename, char *outfilename, int lump);
// killough 10/98: support -dehout filename
static char *D_dehout(void)
{
static char *s; // cache results over multiple calls
if (!s)
{
int p = M_CheckParm("-dehout");
if (!p)
p = M_CheckParm("-bexout");
s = p && ++p < myargc ? myargv[p] : "";
}
return s;
}
char **wadfiles;
// killough 10/98: preloaded files
#define MAXLOADFILES 2
char *wad_files[MAXLOADFILES], *deh_files[MAXLOADFILES];
// jff 1/24/98 add new versions of these variables to remember command line
boolean clnomonsters; // checkparm of -nomonsters
boolean clrespawnparm; // checkparm of -respawn
boolean clfastparm; // checkparm of -fast
// jff 1/24/98 end definition of command line version of play mode switches
boolean devparm; // working -devparm
boolean nomonsters; // working -nomonsters
boolean respawnparm; // working -respawn
boolean fastparm; // working -fast
boolean ssgparm; // working -ssg GB 2013
boolean nolfbparm; // working -nolfb GB 2014
boolean nopmparm; // working -nopm GB 2014
boolean noasmparm; // working -noasm GB 2014
boolean noasmxparm; // working -noasmx GB 2014
boolean asmp6parm; // working -asmp6 GB 2014
boolean safeparm; // working -safe GB 2014
boolean stdvidparm; // working -stdvid GB 2014
boolean bestvidparm; // working -stdvid GB 2014
boolean lowdetparm; // working -lowdet GB 2015
boolean nosfxparm; // jff 1/22/98 parms for disabling music and sound, -nosfx
boolean nomusicparm; // jff 1/22/98 parms for disabling music and sound, -nomusic
boolean v12_compat=false;// GB 2014, for v1.2 WAD stock demos
boolean singletics = false; // debug flag to cancel adaptiveness
//jff 4/18/98
extern boolean inhelpscreens;
skill_t startskill;
int startepisode;
int startmap;
boolean autostart;
FILE *debugfile;
boolean advancedemo;
extern boolean timingdemo, singledemo, demoplayback, fastdemo; // killough
char wadfile[PATH_MAX+1]; // primary wad file
char mapdir[PATH_MAX+1]; // directory of development maps
char basedefault[PATH_MAX+1]; // default file
char baseiwad[PATH_MAX+1]; // jff 3/23/98: iwad directory
char basesavegame[PATH_MAX+1]; // killough 2/16/98: savegame directory
//jff 4/19/98 list of standard IWAD names
const char *const standard_iwads[]=
{
"/doom2f.wad",
"/doom2.wad",
"/plutonia.wad",
"/tnt.wad",
"/doom.wad",
"/doom1.wad",
"/doomu.wad", // GB 2014
};
static const int nstandard_iwads = sizeof standard_iwads/sizeof*standard_iwads;
void D_CheckNetGame (void);
void D_ProcessEvents (void);
void G_BuildTiccmd (ticcmd_t* cmd);
void D_DoAdvanceDemo (void);
//
// EVENT HANDLING
//
// Events are asynchronous inputs generally generated by the game user.
// Events can be discarded if no responder claims them
//
event_t events[MAXEVENTS];
int eventhead, eventtail;
//
// D_PostEvent
// Called by the I/O functions when input is detected
//
void D_PostEvent(event_t *ev)
{
events[eventhead++] = *ev;
eventhead &= MAXEVENTS-1;
}
//
// D_ProcessEvents
// Send all the events of the given timestamp down the responder chain
//
void D_ProcessEvents (void)
{
// IF STORE DEMO, DO NOT ACCEPT INPUT
if (gamemode != commercial || W_CheckNumForName("map01") >= 0)
for (; eventtail != eventhead; eventtail = (eventtail+1) & (MAXEVENTS-1))
if (!M_Responder(events+eventtail))
G_Responder(events+eventtail);
}
//
// D_Display
// draw current display, possibly wiping it from the previous
//
// wipegamestate can be set to -1 to force a wipe on the next draw
gamestate_t wipegamestate = GS_DEMOSCREEN;
extern boolean setsizeneeded;
extern int showMessages;
void R_ExecuteSetViewSize(void);
void D_Display (void)
{
static boolean viewactivestate = false;
static boolean menuactivestate = false;
static boolean inhelpscreensstate = false;
static boolean fullscreen = false;
static gamestate_t oldgamestate = -1;
static int borderdrawcount;
int wipestart;
boolean done, wipe, redrawsbar;
if (nodrawers) // for comparative timing / profiling
return;
redrawsbar = false;
if (setsizeneeded) // change the view size if needed
{
R_ExecuteSetViewSize();
oldgamestate = -1; // force background redraw
borderdrawcount = 3;
}
// save the current screen if about to wipe
if ((wipe = gamestate != wipegamestate))
wipe_StartScreen(0, 0, SCREENWIDTH, SCREENHEIGHT);
if (gamestate == GS_LEVEL && gametic)
HU_Erase();
switch (gamestate) // do buffered drawing
{
case GS_LEVEL:
if (!gametic)
break;
if (automapactive)
AM_Drawer();
if (wipe || (scaledviewheight != 200 && fullscreen) // killough 11/98
|| (inhelpscreensstate && !inhelpscreens))
redrawsbar = true; // just put away the help screen
ST_Drawer(scaledviewheight == 200, redrawsbar ); // killough 11/98
fullscreen = scaledviewheight == 200; // killough 11/98
break;
case GS_INTERMISSION:
WI_Drawer();
break;
case GS_FINALE:
F_Drawer();
break;
case GS_DEMOSCREEN:
D_PageDrawer();
break;
}
// draw buffered stuff to screen
I_UpdateNoBlit();
// draw the view directly
if (gamestate == GS_LEVEL && !automapactive && gametic)
R_RenderPlayerView (&players[displayplayer]);
if (gamestate == GS_LEVEL && gametic)
HU_Drawer ();
// clean up border stuff
if (gamestate != oldgamestate && gamestate != GS_LEVEL)
I_SetPalette (W_CacheLumpName ("PLAYPAL",PU_CACHE));
// see if the border needs to be initially drawn
if (gamestate == GS_LEVEL && oldgamestate != GS_LEVEL)
{
viewactivestate = false; // view was not active
R_FillBackScreen (); // draw the pattern into the back screen
}
// see if the border needs to be updated to the screen
if (gamestate == GS_LEVEL && !automapactive && scaledviewwidth != 320)
{
if (menuactive || menuactivestate || !viewactivestate)
borderdrawcount = 3;
if (borderdrawcount)
{
R_DrawViewBorder (); // erase old menu stuff
borderdrawcount--;
}
}
menuactivestate = menuactive;
viewactivestate = viewactive;
inhelpscreensstate = inhelpscreens;
oldgamestate = wipegamestate = gamestate;
// draw pause pic
if (paused)
{
int y = 4;
if (!automapactive)
y += viewwindowy;
V_DrawPatchDirect(viewwindowx+(scaledviewwidth-68)/2,
y,0,W_CacheLumpName ("M_PAUSE", PU_CACHE));
}
// menus go directly to the screen
M_Drawer(); // menu is drawn even on top of everything
NetUpdate(); // send out any new accumulation
// normal update
if (!wipe)
{
I_FinishUpdate (); // page flip or blit buffer
return;
}
// wipe update
wipe_EndScreen(0, 0, SCREENWIDTH, SCREENHEIGHT);
wipestart = I_GetTime () - 1;
do
{
int nowtime, tics;
statusbar_dirty=2; // GB 2014
do
{
nowtime = I_GetTime();
tics = nowtime - wipestart;
}
while (!tics);
wipestart = nowtime;
done = wipe_ScreenWipe(wipe_Melt,0,0,SCREENWIDTH,SCREENHEIGHT,tics);
I_UpdateNoBlit();
M_Drawer(); // menu is drawn even on top of wipes
I_FinishUpdate(); // page flip or blit buffer
}
while (!done);
}
//
// DEMO LOOP
//
static int demosequence; // killough 5/2/98: made static
static int pagetic;
static char *pagename;
//
// D_PageTicker
// Handles timing for warped projection
//
void D_PageTicker(void)
{
// killough 12/98: don't advance internal demos if a single one is
// being played. The only time this matters is when using -loadgame with
// -fastdemo, -playdemo, or -timedemo, and a consistency error occurs.
if (!singledemo && --pagetic < 0)
D_AdvanceDemo();
}
//
// D_PageDrawer
//
// killough 11/98: add credits screen
//
void D_PageDrawer(void)
{
if (pagename)
{
int l = W_CheckNumForName(pagename);
byte *t = W_CacheLumpNum(l, PU_CACHE);
size_t s = W_LumpLength(l);
unsigned c = 0;
while (s--)
c = c*3 + t[s];
V_DrawPatch(0, 0, 0, (patch_t *) t);
#ifdef DOGS // GB 2014
if (c==2119826587u || c==2391756584u)
V_DrawPatch(0, 0, 0, W_CacheLumpName("DOGOVRLY", PU_CACHE));
#endif //DOGS
}
else
M_DrawCredits();
}
//
// D_AdvanceDemo
// Called after each demo or intro demosequence finishes
//
void D_AdvanceDemo (void)
{
advancedemo = true;
}
// killough 11/98: functions to perform demo sequences
static void D_SetPageName(char *name)
{
pagename = name;
}
static void D_DrawTitle1(char *name)
{
S_StartMusic(mus_intro);
pagetic = (TICRATE*170)/35;
if (W_CheckNumForName("SIGILINT") != -1 || W_CheckNumForName("SIGILIN2") != -1) // Sakitoshi 2019: if Sigil detected, wait for the title theme to end.
pagetic = (TICRATE*404)/35;
D_SetPageName(name);
}
static void D_DrawTitle2(char *name)
{
S_StartMusic(mus_dm2ttl);
D_SetPageName(name);
}
// killough 11/98: tabulate demo sequences
static struct
{
void (*func)(char *);
char *name;
} const demostates[][4] =
{
{
{D_DrawTitle1, "TITLEPIC"},
{D_DrawTitle1, "TITLEPIC"},
{D_DrawTitle2, "TITLEPIC"},
{D_DrawTitle1, "TITLEPIC"},
},
{
{G_DeferedPlayDemo, "demo1"},
{G_DeferedPlayDemo, "demo1"},
{G_DeferedPlayDemo, "demo1"},
{G_DeferedPlayDemo, "demo1"},
},
{
{D_SetPageName, NULL},
{D_SetPageName, NULL},
{D_SetPageName, NULL},
{D_SetPageName, NULL},
},
{
{G_DeferedPlayDemo, "demo2"},
{G_DeferedPlayDemo, "demo2"},
{G_DeferedPlayDemo, "demo2"},
{G_DeferedPlayDemo, "demo2"},
},
{
{D_SetPageName, "HELP2"},
{D_SetPageName, "HELP2"},
{D_SetPageName, "CREDIT"},
{D_DrawTitle1, "TITLEPIC"},
},
{
{G_DeferedPlayDemo, "demo3"},
{G_DeferedPlayDemo, "demo3"},
{G_DeferedPlayDemo, "demo3"},
{G_DeferedPlayDemo, "demo3"},
},
{
{NULL},
{NULL},
{NULL},
{D_SetPageName, "CREDIT"},
},
{
{NULL},
{NULL},
{NULL},
{G_DeferedPlayDemo, "demo4"},
},
{
{NULL},
{NULL},
{NULL},
{NULL},
}
};
//
// This cycles through the demo sequences.
//
// killough 11/98: made table-driven
void D_DoAdvanceDemo(void)
{
players[consoleplayer].playerstate = PST_LIVE; // not reborn
advancedemo = usergame = paused = false;
gameaction = ga_nothing;
pagetic = TICRATE * 11; // killough 11/98: default behavior
gamestate = GS_DEMOSCREEN;
if (!demostates[++demosequence][gamemode].func)
demosequence = 0;
demostates[demosequence][gamemode].func
(demostates[demosequence][gamemode].name);
}
//
// D_StartTitle
//
void D_StartTitle (void)
{
gameaction = ga_nothing;
demosequence = -1;
D_AdvanceDemo();
}
// print title for every printed line
static char title[128];
//
// D_AddFile
//
// Rewritten by Lee Killough
//
// killough 11/98: remove limit on number of files
//
void D_AddFile(const char *file)
{
static int numwadfiles, numwadfiles_alloc;
if (numwadfiles >= numwadfiles_alloc)
wadfiles = realloc(wadfiles, (numwadfiles_alloc = numwadfiles_alloc ?
numwadfiles_alloc * 2 : 8)*sizeof*wadfiles);
wadfiles[numwadfiles++] = !file ? NULL : strdup(file);
}
// Return the path where the executable lies -- Lee Killough
char *D_DoomExeDir(void)
{
static char *base;
if (!base) // cache multiple requests
{
size_t len = strlen(*myargv);
char *p = (base = malloc(len+1)) + len;
strcpy(base,*myargv);
while (p > base && *p!='/' && *p!='\\')
*p--=0;
}
return base;
}
// killough 10/98: return the name of the program the exe was invoked as
char *D_DoomExeName(void)
{
static char *name; // cache multiple requests
if (!name)
{
char *p = *myargv + strlen(*myargv);
int i = 0;
while (p > *myargv && p[-1] != '/' && p[-1] != '\\' && p[-1] != ':')
p--;
while (p[i] && p[i] != '.')
i++;
strncpy(name = malloc(i+1), p, i)[i] = 0;
}
return name;
}
//
// CheckIWAD
//
// Verify a file is indeed tagged as an IWAD
// Scan its lumps for levelnames and return gamemode as indicated
// Detect missing wolf levels in DOOM II
//
// The filename to check is passed in iwadname, the gamemode detected is
// returned in gmode, hassec returns the presence of secret levels
//
// jff 4/19/98 Add routine to test IWAD for validity and determine
// the gamemode from it. Also note if DOOM II, whether secret levels exist
//
// killough 11/98:
// Rewritten to considerably simplify
// Added Final Doom support (thanks to Joel Murdoch)
//
static void CheckIWAD(const char *iwadname,
GameMode_t *gmode,
//GameMission_t *gmission, // joel 10/17/98 Final DOOM fix
boolean *hassec)
{
FILE *fp = fopen(iwadname, "rb");
int ud, rg, sw, cm, sc, tnt, plut;
filelump_t lump;
wadinfo_t header;
const char *n = lump.name;
if (!fp)
I_Error("Can't open IWAD: %s\n",iwadname);
// read IWAD header
if (fread(&header, 1, sizeof header, fp) != sizeof header ||
header.identification[0] != 'I' || header.identification[1] != 'W' ||
header.identification[2] != 'A' || header.identification[3] != 'D')
I_Error("IWAD tag not present: %s\n",iwadname);
fseek(fp, LONG(header.infotableofs), SEEK_SET);
// Determine game mode from levels present
// Must be a full set for whichever mode is present
// Lack of wolf-3d levels also detected here
for (ud=rg=sw=cm=sc=tnt=plut=0, header.numlumps = LONG(header.numlumps);
header.numlumps && fread(&lump, sizeof lump, 1, fp); header.numlumps--)
*n=='E' && n[2]=='M' && !n[4] ?
n[1]=='4' ? ++ud : n[1]!='1' ? rg += n[1]=='3' || n[1]=='2' : ++sw :
*n=='M' && n[1]=='A' && n[2]=='P' && !n[5] ?
++cm, sc += n[3]=='3' && (n[4]=='1' || n[4]=='2') :
*n=='C' && n[1]=='A' && n[2]=='V' && !n[7] ? ++tnt :
*n=='M' && n[1]=='C' && !n[3] && ++plut;
fclose(fp);
//*gmission = doom;
*hassec = false;
*gmode =
/*cm >= 30 ? (*gmission = tnt >= 4 ? pack_tnt :
plut >= 8 ? pack_plut : doom2,
*hassec = sc >= 2, commercial) :*/
cm >= 30 ? (*hassec = sc >= 2, commercial) :
ud >= 9 ? retail :
rg >= 18 ? registered :
sw >= 9 ? shareware :
indetermined;
}
//
// AddIWAD
//
void AddIWAD(const char *iwad)
{
size_t i;
if (!(iwad && *iwad))
return;
//jff 9/3/98 use logical output routine.
//Sakitoshi 2019 lprintf not implemented, so using regular printf.
printf("IWAD found: %s\n",iwad); //jff 4/20/98 print only if found
CheckIWAD(iwad,&gamemode,&haswolflevels);
/* jff 8/23/98 set gamemission global appropriately in all cases
* cphipps 12/1999 - no version output here, leave that to the caller
*/
i = strlen(iwad);
switch(gamemode)
{
case retail:
case registered:
case shareware:
gamemission = doom;
//if (i>=8 && !strnicmp(iwad+i-8,"chex.wad",8))
// gamemission = chex;
break;
case commercial:
gamemission = doom2;
if (i>=10 && !strnicmp(iwad+i-10,"doom2f.wad",10))
language=french;
else if (i>=7 && !strnicmp(iwad+i-7,"tnt.wad",7))
gamemission = pack_tnt;
else if (i>=12 && !strnicmp(iwad+i-12,"plutonia.wad",12))
gamemission = pack_plut;
//else if (i>=8 && !strnicmp(iwad+i-8,"hacx.wad",8))
// gamemission = hacx;
break;
default:
gamemission = none;
break;
}
if (gamemode == indetermined)
//jff 9/3/98 use logical output routine
//Sakitoshi 2019 lprintf not implemented, so using regular printf.
printf("Unknown Game Version, may not work\n");
D_AddFile(iwad);
}
// jff 4/19/98 Add routine to check a pathname for existence as
// a file or directory. If neither append .wad and check if it
// exists as a file then. Else return non-existent.
boolean WadFileStatus(char *filename,boolean *isdir)
{
struct stat sbuf;
int i;
*isdir = false; //default is directory to false
if (!filename || !*filename) //if path NULL or empty, doesn't exist
return false;
if (!stat(filename,&sbuf)) //check for existence
{
*isdir=S_ISDIR(sbuf.st_mode); //if it does, set whether a dir or not
return true; //return does exist
}
i = strlen(filename); //get length of path
if (i>=4)
if(!strnicmp(filename+i-4,".wad",4))
return false; //if already ends in .wad, not found
strcat(filename,".wad"); //try it with .wad added
if (!stat(filename,&sbuf)) //if it exists then
{
if (S_ISDIR(sbuf.st_mode)) //but is a dir, then say we didn't find it
return false;
return true; //otherwise return file found, w/ .wad added
}
filename[i]=0; //remove .wad
return false; //and report doesn't exist
}
//
// FindIWADFIle
//
// Search in all the usual places until an IWAD is found.
//
// The global baseiwad contains either a full IWAD file specification
// or a directory to look for an IWAD in, or the name of the IWAD desired.
//
// The global standard_iwads lists the standard IWAD names
//
// The result of search is returned in baseiwad, or set blank if none found
//
// IWAD search algorithm:
//
// Set customiwad blank
// If -iwad present set baseiwad to normalized path from -iwad parameter
// If baseiwad is an existing file, thats it
// If baseiwad is an existing dir, try appending all standard iwads
// If haven't found it, and no : or / is in baseiwad,
// append .wad if missing and set customiwad to baseiwad
//
// Look in . for customiwad if set, else all standard iwads
//
// Look in DoomExeDir. for customiwad if set, else all standard iwads
//
// If $DOOMWADDIR is an existing file
// If customiwad is not set, thats it
// else replace filename with customiwad, if exists thats it
// If $DOOMWADDIR is existing dir, try customiwad if set, else standard iwads
//
// If $HOME is an existing file
// If customiwad is not set, thats it
// else replace filename with customiwad, if exists thats it
// If $HOME is an existing dir, try customiwad if set, else standard iwads
//
// IWAD not found
//
// jff 4/19/98 Add routine to search for a standard or custom IWAD in one
// of the standard places. Returns a blank string if not found.
//
// killough 11/98: simplified, removed error-prone cut-n-pasted code
//
char *FindIWADFile(void)
{
static const char *envvars[] = {"DOOMWADDIR", "HOME"};
static char iwad[PATH_MAX+1], customiwad[PATH_MAX+1];
boolean isdir=false;
int i,j;
char *p;
*iwad = 0; // default return filename to empty
*customiwad = 0; // customiwad is blank
//jff 3/24/98 get -iwad parm if specified else use .
if ((i = M_CheckParm("-iwad")) && i < myargc-1)
{
NormalizeSlashes(strcpy(baseiwad,myargv[i+1]));
if (WadFileStatus(strcpy(iwad,baseiwad),&isdir))
if (!isdir)
return iwad;
else
for (i=0;i<nstandard_iwads;i++)
{
int n = strlen(iwad);
strcat(iwad,standard_iwads[i]);
if (WadFileStatus(iwad,&isdir) && !isdir)
return iwad;
iwad[n] = 0; // reset iwad length to former
}
else
if (!strchr(iwad,':') && !strchr(iwad,'/'))
AddDefaultExtension(strcat(strcpy(customiwad, "/"), iwad), ".wad");
}
for (j=0; j<2; j++)
{
strcpy(iwad, j ? D_DoomExeDir() : ".");
NormalizeSlashes(iwad);
printf("Looking in %s\n",iwad); // killough 8/8/98
if (*customiwad)
{
strcat(iwad,customiwad);
if (WadFileStatus(iwad,&isdir) && !isdir)
return iwad;
}
else
for (i=0;i<nstandard_iwads;i++)
{
int n = strlen(iwad);
strcat(iwad,standard_iwads[i]);
if (WadFileStatus(iwad,&isdir) && !isdir)
return iwad;
iwad[n] = 0; // reset iwad length to former
}
}
// GB 2013, also look in iwad subfolder of D_DoomExeDir
for (j=0; j<2; j++)
{
strcpy(iwad, j ? D_DoomExeDir() : ".");
strcat(iwad, "/iwad");
NormalizeSlashes(iwad);
printf("Looking in %s\n",iwad); // killough 8/8/98
if (*customiwad)
{
strcat(iwad,customiwad);
if (WadFileStatus(iwad,&isdir) && !isdir)
return iwad;
}
else
for (i=0;i<nstandard_iwads;i++)
{
int n = strlen(iwad);
strcat(iwad,standard_iwads[i]);
if (WadFileStatus(iwad,&isdir) && !isdir)
return iwad;
iwad[n] = 0; // reset iwad length to former
}
}
for (i=0; i<sizeof envvars/sizeof *envvars;i++) if ((p = getenv(envvars[i])))
{
NormalizeSlashes(strcpy(iwad,p));
if (WadFileStatus(iwad,&isdir))
{
if (!isdir)
{
if (!*customiwad)
return printf("Looking for %s\n",iwad), iwad; // killough 8/8/98
else
if ((p = strrchr(iwad,'/')))
{
*p=0;
strcat(iwad,customiwad);
printf("Looking for %s\n",iwad); // killough 8/8/98
if (WadFileStatus(iwad,&isdir) && !isdir)
return iwad;
}
}
else
{
printf("Looking in %s\n",iwad); // killough 8/8/98
if (*customiwad)
{
if (WadFileStatus(strcat(iwad,customiwad),&isdir) && !isdir)
return iwad;
}
else
for (i=0;i<nstandard_iwads;i++)
{
int n = strlen(iwad);
strcat(iwad,standard_iwads[i]);
if (WadFileStatus(iwad,&isdir) && !isdir)
return iwad;
iwad[n] = 0; // reset iwad length to former
}
}
}
}
*iwad = 0;
return iwad;
}
//
// IdentifyVersion
//
// Set the location of the defaults file and the savegame root
// Locate and validate an IWAD file
// Determine gamemode from the IWAD
//
// supports IWADs with custom names. Also allows the -iwad parameter to
// specify which iwad is being searched for if several exist in one dir.
// The -iwad parm may specify:
//
// 1) a specific pathname, which must exist (.wad optional)
// 2) or a directory, which must contain a standard IWAD,
// 3) or a filename, which must be found in one of the standard places:
// a) current dir,
// b) exe dir
// c) $DOOMWADDIR
// d) or $HOME
//
// jff 4/19/98 rewritten to use a more advanced search algorithm
void IdentifyVersion (void)
{
int i; //jff 3/24/98 index of args on commandline
struct stat sbuf; //jff 3/24/98 used to test save path for existence
char *iwad;
// get config file from same directory as executable
// killough 10/98
sprintf(basedefault,"%s/%s.cfg", D_DoomExeDir(), D_DoomExeName());
// set save path to -save parm or current dir
strcpy(basesavegame,"."); //jff 3/27/98 default to current dir
if ((i=M_CheckParm("-save")) && i<myargc-1) //jff 3/24/98 if -save present
{
if (!stat(myargv[i+1],&sbuf) && S_ISDIR(sbuf.st_mode)) // and is a dir
strcpy(basesavegame,myargv[i+1]); //jff 3/24/98 use that for savegame
else
puts("Error: -save path does not exist, using current dir"); // killough 8/8/98
}
// locate the IWAD and determine game mode from it
iwad = FindIWADFile();
if (iwad && *iwad)
{
//printf("IWAD found: %s\n",iwad); //jff 4/20/98 print only if found. Sakitoshi 2019, not needed here anymore
AddIWAD(iwad);
}
else
I_Error("IWAD not found\n");
}
// killough 5/3/98: old code removed
//
// Find a Response File
//
#define MAXARGVS 100
void FindResponseFile (void)
{
int i;
for (i = 1;i < myargc;i++)
if (myargv[i][0] == '@')
{
FILE *handle;
int size;
int k;
int index;
int indexinfile;
char *infile;
char *file;
char *moreargs[MAXARGVS];
char *firstargv;
// READ THE RESPONSE FILE INTO MEMORY
// killough 10/98: add default .rsp extension
char *filename = malloc(strlen(myargv[i])+5);
AddDefaultExtension(strcpy(filename,&myargv[i][1]),".rsp");
handle = fopen(filename,"rb");
if (!handle)
I_Error("No such response file!"); // killough 10/98
printf("Found response file %s!\n",filename);
free(filename);
fseek(handle,0,SEEK_END);
size = ftell(handle);
fseek(handle,0,SEEK_SET);
file = malloc (size);
fread(file,size,1,handle);
fclose(handle);
// KEEP ALL CMDLINE ARGS FOLLOWING @RESPONSEFILE ARG
for (index = 0,k = i+1; k < myargc; k++)
moreargs[index++] = myargv[k];