-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD3dmain.cpp
2262 lines (2115 loc) · 68.6 KB
/
D3dmain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
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
/*
* The X Men, June 1996
* Copyright (c) 1996 Probe Entertainment Limited
* All Rights Reserved
*
* $Revision: 177 $
*
* $Header: /PcProjectX/D3dmain.cpp 177 11/11/98 16:00 Philipy $
*
* $Log: /PcProjectX/D3dmain.cpp $
//
//177 11/11/98 16:00 Philipy
//various fixes for warnings / errors when compiling under VC6
//
//171 3/09/98 14:25 Philipy
//tidied up window mode slightly
//( no resize allowed, removed menu bar )
//
//170 3/09/98 9:31 Philipy
//somw Gamespy fixes
//added Session ( GUID ) and TCP command line flags
//added TRACKER_NAME facility
//
//169 27/08/98 20:12 Philipy
//manual / auto server mode now selectable from menus
//text now displayed when server in game & not rendering
//dynamic PPS setting re-enabled for server
//
//168 25/08/98 17:38 Philipy
//added gamespy support
//tracker config now selectable from start server game menu, & stored in
//reg
//
//166 17/08/98 17:13 Philipy
//added -ServerChoosesGame & ServerAutoStart command line options
//
//165 14/08/98 15:25 Philipy
//added trilinear option to menus
//fixed level name / shutdown packet in heartbeat
//
//
//163 10/08/98 17:33 Philipy
//rewrote AVI player
//
//162 5/08/98 11:04 Philipy
//added AutoStart facility ( joins game based on GUID in registery )
//upped patch version to 1.02
//
//161 9/07/98 12:43 Philipy
//few minor fixes for patch release
//
//160 8/07/98 11:42 Philipy
//re-enabled -NoSplash command line option
//
//159 7/07/98 18:05 Philipy
//added lobby autostart code ( when all players have recieved init msg )
//added num primary weapons menu option ( propergated to other players &|
//server )
//extracted new title text for localisation
//
//158 3/07/98 17:46 Philipy
//added quit option when using quickstart
//
//157 3/07/98 11:53 Philipy
//heartbeat & quickstart stuff
//
//151 8/04/98 20:47 Philipy
//title text messages now properly initialised
//holo-glaire removed for sw version
//compound buffer size can now be set in command line and opt file
//prevented "level select disabled" from appearing at start of
//multiplayer game
//
//150 8/04/98 10:15 Philipy
//Title CD track now only started after valid CD check
//
//149 7/04/98 11:00 Philipy
//potentially fixed crash when going from AVI to titles
//fixed CD audio looping
//no CD audio in front end unless full install
//bike features sliders now give correct values
//
//148 4/04/98 14:22 Philipy
//mode scaling stuff is now calculated rather than based on fixed values
//added -NoBlitTextScaling option to ReadIni and command line options
//
//146 3/04/98 19:15 Philipy
//blitted text now scales properly
//added -NoBlitTextScaling flag for cards that can't do a strech blit
//properly ( Riva )
//
//139 28/03/98 17:33 Philipy
//corrected some sfx
//added legal screen
//fixed mission briefing text bug
//
//135 15/03/98 18:40 Philipy
//added water effect splash screen
//fixed bug with end game sequence
//implemented attract mode
//text macros now saved in config
//
//131 7/03/98 15:25 Philipy
//re-implemented -NoAVI option
//
//129 6/03/98 16:51 Philipy
//
//126 20/02/98 15:28 Philipy
//re-implented AVI
//splash screens can now play demos and AVIs
//
//125 9/02/98 12:21 Philipy
//added sound buffer memory managment
//only one piece of bike computer speech can now play at a time
//
//122 1/27/98 12:07p Philipy
//fixed mode changing bug
//
//121 26/01/98 18:23 Philipy
//fixed video memory leaks
//splash screens now display after release view, and call InitScene,
//InitView after completion
//
//120 24/01/98 17:38 Philipy
//fixed multiplayer join-quit-join bug
//fixed attract mode loading wrong level
//
//118 21/01/98 12:19 Philipy
//Added attract mode for shareware
//fixed looping sfx volume bug
//
//117 18/01/98 23:36 Philipy
//added -NoDynamicSfx option
//
//113 13/01/98 12:05 Philipy
//put ifdefs around initial splash screen for shareware
//
//112 12/01/98 0:08 Philipy
//bug fixes
//added inter-level mission briefing
//changed splash screen code, + added splash screen on exit
//
//110 9/01/98 11:13 Philipy
//CD nows plays last track
//CD now replays current track from seperate ( low priority ) thread -
//but still causes pause
//loading bar now displayed when loading
//
//95 2/12/97 11:52 Philipy
//boot demo stuff
//
//91 26/11/97 11:48 Philipy
//implemented dynamic loading of SFX, dynamic allocation of mixing
//channels.
//3D sound currently disabled.
//
//85 4/11/97 16:26 Philipy
//AVI now plays for stats screens
//implemented scrolling messages (not enabled)
//
//84 27/10/97 15:38 Philipy
//added in-game cd track playing
//
//83 23/10/97 16:49 Philipy
//added tggle (number key 1) for playing AVI on texture.
//(no texture conversion yet, could appear corrupted)
//
//80 21/10/97 13:08 Philipy
//AVI now no longer sends main game thread to sleep
//WindowProc now handles CD track finishing
*
*/
/*
* Copyright (C) 1996 Microsoft Corporation. All Rights Reserved.
*
* File: d3dmain.cpp
*
* Each of the Direct3D samples must be linked with this file. It contains
* the code which allows them to run in the Windows environment.
*
* A window is created using d3dmain.res which allows the user to select the
* Direct3D driver to use and change the render options. The D3DApp
* collection of functions is used to initialize DirectDraw, Direct3D and
* keep surfaces and D3D devices available for rendering.
*
* Frame rate and a screen mode information buffer is Blt'ed to the screen
* by functions in stats.cpp.
*
* Each sample is executed through the functions: InitScene, InitView,
* RenderScene, ReleaseView, ReleaseScene and OverrideDefaults, as described
* in d3ddemo.h.
*/
#include "typedefs.h"
#include "demo_id.h"
#include "resource.h"
#include "d3dmain.h"
#include "main.h"
#include "dsound.h"
#ifdef PCIDENT
#include "finger.h"
#define PCIDENT_FILE "data\\offsets.dat"
#endif
#include "dbt.h"
#ifdef SOFTWARE_ENABLE
/*---------------------------------------------------------------------------
Chris Walsh's code
---------------------------------------------------------------------------*/
int MakeCodeWritable( void );
/*-------------------------------------------------------------------------*/
#endif
extern "C" {
#include "title.h"
//#include "cplay.h"
#include "stdwin.h"
#include "cdaudio.h"
#include "malloc.h"
#include "Exechand.h"
#include "DDSurfhand.h"
#include "SBufferHand.h"
#include "Readini.h"
#include "file.h"
#include "splash.h"
#include "XMem.h"
#ifdef SOFTWARE_ENABLE
/*---------------------------------------------------------------------------
Chris Walsh's code
---------------------------------------------------------------------------*/
extern CWmain(void); // Main render loop on chris' stuff....
extern BOOL SoftwareVersion;
/*-------------------------------------------------------------------------*/
#endif
extern BOOL ZClearsOn;
extern BOOL AllowServer;
extern void SetViewportError( char *where, D3DVIEWPORT *vp, HRESULT rval );
extern BOOL CheckDirectPlayVersion;
extern HKEY ghCondemnedKey; // Condemned registry key handle
#ifdef LOBBY_DEBUG
extern HKEY ghLobbyKey; // lobby registry key handle
#endif
extern int DPlayUpdateIntervalCmdLine;
extern BOOL GetValidCDPath( void );
extern int ValidInstall( void );
extern int ValidCD( void );
extern void GetGamePrefs( void );
extern int ScreenWidth;
extern int ScreenHeight;
extern int ScreenBPP;
extern BYTE Current_Camera_View; // which object is currently using the camera view....
extern BOOL PlayDemo;
extern BOOL DemoShipInit[];
extern BOOL flush_input;
extern int ddchosen3d;
extern int default_width;
extern int default_height;
extern int default_bpp;
extern int use_level_path;
extern char level_path[];
extern int use_data_path;
extern int use_local_data;
extern char data_path[];
extern int LogosEnable;
extern BOOL MoviePlaying;
extern BOOL SeriousError;
extern BOOL E3DemoHost;
extern BOOL E3DemoClient;
extern BOOL PowerVR_Overide;
extern BOOL E3DemoLoop;
extern BOOL Is3Dfx;
extern BOOL Is3Dfx2;
extern BOOL TriLinear;
extern BOOL NoSFX;
extern int TextureMemory;
extern BOOL NoTextureScaling;
extern BOOL MipMap;
extern BOOL TripleBuffer;
extern BOOL PolygonText;
extern BOOL UseSendAsync;
extern float UV_Fix;
extern BOOL ECTSDemo;
extern BOOL AllWires;
extern BOOL NoAVI;
extern BOOL CanDoStrechBlt;
extern float normal_fov;
extern float screen_aspect_ratio;
extern BOOL CreateBatchFile;
extern BOOL CreateLogFile;
extern BOOL LockOutWindows;
extern BOOL DplayRecieveThread;
extern BOOL PreventFlips;
extern BOOL DS;
extern BOOL NoDebugMsgs;
extern BOOL SpaceOrbSetup;
extern BOOL NoCompoundSfxBuffer;
extern long UseDDrawFlip;
extern BOOL NoSplash;
extern LPDIRECTSOUND3DLISTENER lpDS3DListener;
extern BOOL OptFileOnCommandline;
extern BOOL DeviceOnCommandline;
extern DWORD UserTotalCompoundSfxBufferSize;
extern BOOL CustomCompoundBufferSize;
extern uint8 QuickStart;
extern BOOL ServerChoosesGameType;
extern BOOL ForceHeartbeat;
extern GUID autojoin_session_guid;
extern BOOL SessionGuidExists;
extern BOOL bTCP;
int PreferredWidth, PreferredHeight;
int DebugMathErrors( void );
void OnceOnlyInit( void );
void OnceOnlyRelease( void );
void DebugPrintf( const char * format, ... );
void MovieRedraw (HWND); // ID_MOVE_REDRAW
void MovieStop (HWND);
void MoviePlay (HWND hwnd);
void AviFinished( void );
void ShowSplashScreen( int num );
void RemoveDynamicSfx( void );
void FillStatusTab( void );
void GetDeviceGuid( void );
extern LONG RegGet(LPCTSTR lptszName, LPBYTE lpData, LPDWORD lpdwDataSize);
HRESULT GUIDFromString( char *lpStr, GUID * pGuid);
}
/*
* GLOBAL VARIABLES
*/
D3DAppInfo* d3dapp; /* Pointer to read only collection of DD and D3D
objects maintained by D3DApp */
d3dmainglobals myglobs; /* collection of global variables */
HKEY ghLobbyKey = NULL; // lobby registry key handle
static UINT CancelAutoPlayMessage;
// AVI Specific stuff...
int AVI_bpp = 16;
int AVI_ZoomMode = 0;
HANDLE AVIThreadControlEvent;
/*
* INTERNAL FUNCTION PROTOTYPES
*/
static BOOL AppInit(HINSTANCE hInstance, LPSTR lpCmdLine);
static BOOL CreateD3DApp(LPSTR lpCmdLine);
static BOOL BeforeDeviceDestroyed(LPVOID lpContext);
static BOOL AfterDeviceCreated(int w, int h, LPDIRECT3DVIEWPORT* lpViewport,
LPVOID lpContext);
void CleanUpAndPostQuit(void);
static void InitGlobals(void);
static BOOL AppPause(BOOL f);
void ReportD3DAppError(void);
static BOOL RenderLoop(void);
static BOOL RestoreSurfaces();
long FAR PASCAL WindowProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam );
/****************************************************************************/
/* WinMain */
/****************************************************************************/
/*
* Initializes the application then enters a message loop which calls sample's
* RenderScene until a quit message is received.
*/
int PASCAL
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
{
HRESULT hr;
int failcount = 0; /* number of times RenderLoop has failed */
MSG msg;
HACCEL hAccelApp;
hPrevInstance;
UINT param1;
UINT param2;
// sets the minimum amount of memory allocated froma single malloc.....
//_amblksiz = 1024;
#ifdef DEBUG_ON
XMem_Init();
XExec_Init();
DDSurf_Init();
XSBuffer_Init();
#endif
FillStatusTab();
MyGameStatus = STATUS_Title;
AVIThreadControlEvent = CreateEvent(NULL, FALSE, FALSE, NULL );
// initialize COM library
hr = CoInitialize(NULL);
if FAILED(hr)
goto FAILURE;
/*
* Create the window and initialize all objects needed to begin rendering
*/
if(!AppInit(hInstance, lpCmdLine))
{
ClipCursor( NULL );
ReallyShowCursor( TRUE );
return FALSE;
}
hAccelApp = LoadAccelerators(hInstance, "AppAccel");
// if( ModeCase == -1 )
{
// D3DAppFullscreen(d3dapp->CurrMode);
}
#if 0 // no movie will play...
#if 1
PlayVideoInWindow(myglobs.hWndMain);
#else
PlayMovie( hInstance,
hPrevInstance,
0, myglobs.hWndMain );
#endif
#endif
while (!myglobs.bQuit) {
/*
* Monitor the message queue until there are no pressing
* messages
*/
#if 1
// This will disable windows key and alt-tab and ctrl-alt-del
if( LockOutWindows )
{
param1 = WM_NULL;
param2 = WM_KEYFIRST;
}else{
param1 = 0;
param2 = 0;
}
if (PeekMessage(&msg, NULL, param1, param2, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
CleanUpAndPostQuit();
break;
}
if (!d3dapp->bPaused ||
!myglobs.hWndMain
|| !TranslateAccelerator(myglobs.hWndMain, hAccelApp, &msg)
)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
#endif
/*
* If the app is not minimized, not about to quit, not paused and D3D
* has been initialized, we can render
*/
if (d3dapp->bRenderingIsOK && !d3dapp->bMinimized && !d3dapp->bPaused
&& !myglobs.bQuit) {
/*
* If were are not in single step mode or if we are and the
* bDrawAFrame flag is set, render one frame
*/
if (!(myglobs.bSingleStepMode && !myglobs.bDrawAFrame)) {
/*
* Attempt to render a frame, if it fails, take a note. If
* rendering fails more than twice, abort execution.
*/
if( !RenderLoop() )
{
++failcount;
if( SeriousError )
{
CleanUpAndPostQuit();
break;
}
// if (failcount == 3) {
// Msg("Rendering has failed too many times. Aborting execution.\n");
// CleanUpAndPostQuit();
// break;
// }
}
}
/*
* Reset the bDrawAFrame flag if we are in single step mode
*/
if (myglobs.bSingleStepMode)
myglobs.bDrawAFrame = FALSE;
}
}
ClipCursor( NULL );
ReallyShowCursor( TRUE );
if ( ghCondemnedKey )
RegCloseKey( ghCondemnedKey );
#ifdef LOBBY_DEBUG
if ( ghLobbyKey )
RegCloseKey( ghLobbyKey );
#endif
FAILURE:
// Uninitialize the COM library
CoUninitialize();
#ifdef DEBUG_ON
DebugMathErrors();
if ( UnMallocedBlocks() )
{
DebugPrintf( "Un-malloced blocks found!" );
}
if ( UnMallocedExecBlocks() )
{
DebugPrintf( "Un-malloced Exec blocks found!" );
}
if ( UnMallocedDDSurfBlocks() )
{
DebugPrintf( "Un-malloced DDSurf blocks found!" );
}
if ( UnMallocedSBufferBlocks() )
{
DebugPrintf( "Un-malloced SBuffer blocks found!" );
}
#endif
return msg.wParam;
}
/****************************************************************************/
/* D3DApp Initialization and callback functions */
/****************************************************************************/
/*
* AppInit
* Creates the window and initializes all objects necessary to begin rendering
*/
static BOOL
AppInit(HINSTANCE hInstance, LPSTR lpCmdLine)
{
WNDCLASS wc;
/*
* Initialize the global variables
*/
InitGlobals();
myglobs.hInstApp = hInstance;
/*
* Register the window class
*/
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( hInstance, "AppIcon");
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
// wc.lpszMenuName = "AppMenu";
wc.lpszMenuName = NULL;
wc.lpszClassName = "Example";
if (!RegisterClass(&wc))
return FALSE;
/*
* Create a window with some default settings that may change
*/
myglobs.hWndMain = CreateWindowEx(
WS_EX_APPWINDOW,
"Example",
"Forsaken",
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
WS_THICKFRAME | WS_MINIMIZEBOX,
0, 0, // start position of Window..
START_WIN_SIZE_X, START_WIN_SIZE_Y,
NULL, /* parent window */
NULL, /* menu handle */
hInstance, /* program handle */
NULL); /* create parms */
if (!myglobs.hWndMain){
Msg("CreateWindowEx failed");
return FALSE;
}
/*
* Display the window
*/
ShowWindow(myglobs.hWndMain, SW_SHOWNORMAL);
UpdateWindow(myglobs.hWndMain);
/*
* Have the example initialize it components which remain constant
* throughout execution
*/
OnceOnlyInit();
if (!InitScene())
return FALSE;
/*
* Call D3DApp to initialize all DD and D3D objects necessary to render.
* D3DApp will call the device creation callback which will initialize the
* viewport and the sample's execute buffers.
*/
if (!CreateD3DApp(lpCmdLine))
return FALSE;
#ifdef EXTERNAL_DEMO
myglobs.bShowFrameRate = FALSE;
#else
myglobs.bShowFrameRate = ( ECTSDemo || E3DemoHost || E3DemoClient || E3DemoLoop ) ? FALSE : TRUE;
#endif
return TRUE;
}
extern "C" {
extern char *config_name;
}
/*
* CreateD3DApp
* Create all DirectDraw and Direct3D objects necessary to begin rendering.
* Add the list of D3D drivers to the file menu.
*/
static BOOL
CreateD3DApp(LPSTR lpCmdLine)
{
char optname[256];
char optfile[256];
HMENU hmenu;
int i;
LPSTR option;
BOOL bOnlySystemMemory, bOnlyEmulation;
DWORD flags;
Defaults defaults;
#if defined( SHAREWARE_MAGAZINE ) || defined( SHAREWARE_RETAIL ) || defined( SHAREWARE_INTERNET ) || defined( SHAREWARE_TCP )
BOOL game_ok = TRUE;
#else
BOOL game_ok = FALSE;
#endif
char * DataPath;
char *cmdlineptr;
char tempcmdline[ 256 ];
char buf[ 256 ];
#ifdef SOFTWARE_ENABLE
/*---------------------------------------------------------------------------
Chris Walsh's code
---------------------------------------------------------------------------*/
int Writeable;
/*-------------------------------------------------------------------------*/
#endif
/*
* Parse the command line in search of one of the following options:
* systemmemory All surfaces should be created in system memory.
* Hardware DD and D3D devices are disabled, but
* debugging during the Win16 lock becomes possible.
* emulation Do not use hardware DD or D3D devices.
*/
bOnlySystemMemory = FALSE;
bOnlyEmulation = FALSE;
E3DemoHost = FALSE;
E3DemoClient = FALSE;
#if defined( ECTS )
LogosEnable = 1;
#endif
#ifdef SELF_PLAY
E3DemoLoop = TRUE;
#ifdef BOOT_DEMO
LogosEnable = 2;
#else
LogosEnable = 1;
#endif
#else
E3DemoLoop = FALSE;
#endif
PowerVR_Overide = FALSE;
Is3Dfx = FALSE;
Is3Dfx2 = FALSE;
TriLinear = FALSE;
NoSFX = FALSE;
TextureMemory = 0;
MipMap = FALSE;
TripleBuffer = FALSE;
ECTSDemo = FALSE;
NoTextureScaling = FALSE;
DplayRecieveThread = FALSE;
PolygonText = FALSE;
DS = FALSE;
NoSplash = FALSE;
SessionGuidExists = FALSE;
UseSendAsync = FALSE;
DPlayUpdateIntervalCmdLine = 0;
cmdlineptr = lpCmdLine;
// get around dplay bug of not propagating command line when lobby launched
// if app was launched from launcher, -xmen is always specified and so command line cannot be empty
if ( !lpCmdLine || !lpCmdLine[ 0 ] )
{
DWORD dwType;
DWORD dwDataSize = 256;
// get command line from registery...
// open key...
if ( RegOpenKeyEx(REGISTRY_ROOT_KEY, REGISTRY_LOBBY_KEY, 0, /*KEY_ALL_ACCESS*/KEY_QUERY_VALUE, &ghLobbyKey ) == ERROR_SUCCESS )
{
// get command line...
if ( RegQueryValueEx(ghLobbyKey, "CommandLine", NULL, &dwType, ( unsigned char * )tempcmdline, &dwDataSize) == ERROR_SUCCESS )
{
cmdlineptr = tempcmdline;
}
}
}
option = strtok(cmdlineptr, " -+");
while(option != NULL ) {
if (!_stricmp(option, "systemmemory")) {
bOnlySystemMemory = TRUE;
#ifdef SOFTWARE_ENABLE
SoftwareVersion = TRUE;
#endif
} else if (!_stricmp(option, "emulation")) {
bOnlyEmulation = TRUE;
} else if (!_stricmp(option, "xmen")) {
game_ok = TRUE;
} else if (!_stricmp(option, "E3DemoHost")) {
E3DemoHost = TRUE;
} else if (!_stricmp(option, "DS")) {
DS = TRUE;
} else if (!_stricmp(option, "E3DemoClient")) {
E3DemoClient = TRUE;
} else if (!_stricmp(option, "E3DemoLoop")) {
E3DemoLoop = TRUE;
} else if (!_stricmp(option, "PowerVR")) {
PowerVR_Overide = TRUE;
} else if (!_stricmp(option, "3Dfx")) {
Is3Dfx = TRUE;
} else if (!_stricmp(option, "SendAsync")) {
UseSendAsync = TRUE;
} else if (!_stricmp(option, "3Dfx2")) {
Is3Dfx2 = TRUE;
TriLinear = TRUE;
} else if (!_stricmp(option, "TriLinear")) {
TriLinear = TRUE;
} else if (!_stricmp(option, "NoSFX")) {
NoSFX = TRUE;
} else if (!_stricmp(option, "PolyText")) {
PolygonText = TRUE;
} else if (!_stricmp(option, "DplayThread")) {
DplayRecieveThread = TRUE;
} else if (!_stricmp(option, "NoTextureScaling")) {
NoTextureScaling = TRUE;
} else if (!_stricmp(option, "MipMap")) {
MipMap = TRUE;
} else if (!_stricmp(option, "TripleBuffer")) {
TripleBuffer = TRUE;
} else if (!_stricmp(option, "ECTS")) {
ECTSDemo = TRUE;
} else if (!_stricmp(option, "BatchFile")) {
CreateBatchFile = TRUE;
} else if (!_stricmp(option, "LogFile")) {
CreateLogFile = TRUE;
} else if (!_stricmp(option, "AllWires")) {
AllWires = TRUE;
} else if (!_stricmp(option, "NoDynamicSfx")) {
RemoveDynamicSfx();
} else if (!_stricmp(option, "NoAVI")) {
NoAVI = TRUE;
} else if (!_stricmp(option, "NoDebug")) {
NoDebugMsgs = TRUE;
} else if (!_stricmp(option, "Debug")) {
NoDebugMsgs = FALSE;
} else if ( !_stricmp( option, "SetupSpaceOrb" ) ) {
SpaceOrbSetup = TRUE;
} else if ( !_stricmp( option, "NoBlitTextScaling" ) ) {
CanDoStrechBlt = FALSE;
} else if ( !_stricmp( option, "NoCompoundSfxBuffer" ) ) {
NoCompoundSfxBuffer = TRUE;
} else if ( !_stricmp( option, "AnyDPlayVersion" ) ) {
CheckDirectPlayVersion = FALSE;
} else if ( !_stricmp( option, "QuickHost" ) ) {
NoSplash = TRUE;
QuickStart = QUICKSTART_Start;
} else if ( !_stricmp( option, "NoSplash" ) ) {
NoSplash = TRUE;
}else if ( !_stricmp( option, "Server" ) ) {
AllowServer = TRUE;
} else if ( !_stricmp( option, "ServerAutoStart" ) ) {
QuickStart = QUICKSTART_Server;
ServerChoosesGameType = TRUE;
NoSplash = TRUE;
} else if ( !_stricmp( option, "QuickJoin" ) ) {
NoSplash = TRUE;
QuickStart = QUICKSTART_Join;
}else if ( !_stricmp( option, "ForceHeartbeat" ) ) {
ForceHeartbeat = TRUE;
}else if ( !_stricmp( option, "session" ) ) {
option = strtok(NULL, "{}");
sprintf( buf, "{%s}", option );
if ( GUIDFromString( buf, &autojoin_session_guid ) == S_OK )
{
SessionGuidExists = TRUE;
}
}else if ( !_stricmp( option, "TCP" ) ) {
bTCP = TRUE;
option = strtok(NULL, " ");
strcpy( (LPSTR)TCPAddress.text, option );
} else if ( !_stricmp( option, "AutoStart" ) ) {
NoSplash = TRUE;
QuickStart = QUICKSTART_SelectSession;
#ifdef Z_TRICK
} else if ( !_stricmp( option, "NoZClear" ) ) {
ZClearsOn = FALSE;
#endif
#ifdef SOFTWARE_ENABLE
} else if ( !_stricmp( option, "UseDDrawFlip" ) ) {
UseDDrawFlip = TRUE;
#endif
} else {
#if 1
int num, denom;
float fnum;
DWORD mem;
if ( sscanf( option, "dev%d", &num ) == 1 )
{
ddchosen3d = num;
DeviceOnCommandline = TRUE;
}
if ( sscanf( option, "CompoundSfxBufferMem%d", &mem ) == 1 )
{
UserTotalCompoundSfxBufferSize = mem;
CustomCompoundBufferSize = TRUE;
}
else if ( sscanf( option, "PPS%d", &num ) == 1 )
{
DPlayUpdateIntervalCmdLine = num;
}
else if ( sscanf( option, "w%d", &num ) == 1 )
{
default_width = num;
}
else if ( sscanf( option, "h%d", &num ) == 1 )
{
default_height = num;
}
else if ( sscanf( option, "bpp%d", &num ) == 1 )
{
default_bpp = num;
}
else if ( sscanf( option, "pw%d", &num ) == 1 )
{
PreferredWidth = num;
}
else if ( sscanf( option, "ph%d", &num ) == 1 )
{
PreferredHeight = num;
}
else if ( sscanf( option, "TextureMemory%d", &num ) == 1 )
{
TextureMemory = num;
}
else if ( sscanf( option, "UVFix%f", &fnum ) == 1 )
{
UV_Fix = fnum;
}
else if ( sscanf( option, "lev:%s", level_path ) == 1 )
{
use_level_path = 1;
}
else if ( sscanf( option, "opt:%s", optname ) == 1 )
{
if ( strstr( optname, ".opt" ) || strstr( optname, ".OPT" ) )
sprintf( optfile, "%s", optname );
else
sprintf( optfile, "opt\\%s.opt", optname );
ReadIniFile( optfile );
}
else if ( !strcmp( option, "data" ) )
{
DataPath = getenv( "PROJXDATA" );
if( DataPath )
{
use_data_path = 1;
use_local_data = 1;
strcpy( &data_path[ 0 ], DataPath );
strcat( &data_path[ 0 ], "\\" );
}
}
else if ( sscanf( option, "data:%s", data_path ) == 1 )
{
strcat( &data_path[ 0 ], "\\" );
use_data_path = 1;
}
else if ( sscanf( option, "logos%d", &num ) == 1 )
{
LogosEnable = num;
}
else if ( sscanf( option, "fov%d", &num ) == 1 )
{
normal_fov = (float) num;
}
else if ( sscanf( option, "screen%d:%d", &num, &denom ) == 2 )
{
if ( num && denom )
screen_aspect_ratio = (float) num / denom;
}
else
{
config_name = option;
}
#else
Msg("Invalid command line options given.\nLegal options: -systemmemory, -emulation\n");
return FALSE;
#endif
}
option = strtok(NULL, " -+");
}
#ifndef SELF_PLAY
/*
#ifdef PCIDENT
if ( !game_ok || !AllowGame() || !ValidFingerPrint( PCIDENT_FILE ) )
#else
if ( !game_ok || !AllowGame() )
#endif
{
Msg( "Fatal initialization error\n" );
return FALSE;
}
*/
GetGamePrefs();
GetDeviceGuid();
#ifdef CD_REQUIRED
if (!GetValidCDPath() ) // validates CD path
{
Msg("Installation corrupted!\n-- please uninstall existing version of Forsaken\nand re-install from original Forsaken CD\n" );
return FALSE;
}
#endif
// for patch, only single player requires CD
#ifdef CD_CHECK_INIT
if ( !ValidCD() )
{
Msg( "Forsaken CD required\n" );
return FALSE;
}
if ( !ValidInstall() )
{
Msg( "Installation invalid\n" );
return FALSE;
}
#endif
SoundInit(); // cd audio
OpenCD();
if ( !default_width && !default_height && !default_bpp )
{
if ( ScreenWidth || ScreenHeight )
{
default_width = ScreenWidth;
default_height = ScreenHeight;
}
else
{
default_width = PreferredWidth;
default_height = PreferredHeight;
}
default_bpp = ScreenBPP;
}
#endif
if ( !default_bpp )