1 /* Main designed spec for use with windows95*/
2 
3 #include "3dc.h"
4 #include "module.h"
5 #include "inline.h"
6 #include "stratdef.h"
7 #include "gamedef.h"
8 #include "gameplat.h"
9 
10 #include "bh_types.h"
11 #include "usr_io.h"
12 #include "font.h"
13 
14 /* JH 27/1/97 */
15 #include "comp_shp.h"
16 
17 #include "chnkload.hpp"
18 #include "npcsetup.h" /* JH 30/4/97 */
19 #include "krender.h"
20 #include "pldnet.h"
21 #include "avpview.h"
22 #include "scrshot.hpp"
23 #include "language.h"
24 #include "huddefs.h"
25 #include "vision.h"
26 #include "pcmenus.h"
27 #include "multmenu.h"
28 #include "menudefs.h"
29 #include "database.h"
30 #include "avp_menus.h"
31 #include "kshape.h"
32 #define UseLocalAssert Yes
33 
34 #include "ourasert.h"
35 
36 #include "ffstdio.h" // fast file stdio
37 
38 #include "davehook.h"
39 
40 #include "rebmenus.hpp"
41 #include "intro.hpp"
42 #include "showcmds.h"
43 
44 #include "consbind.hpp"
45 
46 #include "AvpReg.hpp"
47 #include "mempool.h"
48 #include "GammaControl.h"
49 
50 #include "CDTrackSelection.h"
51 
52 /*------------Patrick 1/6/97---------------
53 New sound system
54 -------------------------------------------*/
55 #include "psndplat.h"
56 
57 #define FRAMEAV 100
58 
59 #include "AvP_UserProfile.h"
60 
61 #define PROFILING_ON 0
62 #if PROFILING_ON
63 #include "pentime.h"
64 #endif
65 
66 #if 0
67 #undef PrintDebuggingText
68 extern int PrintDebuggingText(const char* t, ...);
69 #endif
70 
71 /*
72 
73  externs for commonly used global variables and arrays
74 
75 */
76 extern int VideoMode;
77 extern DISPLAYBLOCK* ActiveBlockList[];
78 extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
79 extern void (*SetVideoMode[]) (void);
80 extern int FrameRate;
81 
82 extern int WindowRequestMode;
83 
84 extern int NumActiveBlocks;
85 int HWAccel = 0;
86 
87 #if debug
88 #define MainTextPrint 1
89 extern int alloc_cnt, deall_cnt;
90 extern int ItemCount;
91 int DebugFontLoaded = 0;
92 
93 extern BOOL ForceLoad_Alien;
94 extern BOOL ForceLoad_Marine;
95 extern BOOL ForceLoad_Predator;
96 extern BOOL ForceLoad_Hugger;
97 extern BOOL ForceLoad_Queen;
98 extern BOOL ForceLoad_Civvie;
99 extern BOOL ForceLoad_PredAlien;
100 extern BOOL ForceLoad_Xenoborg;
101 extern BOOL ForceLoad_Pretorian;
102 extern BOOL ForceLoad_SentryGun;
103 
104 
105 BOOL UseMouseCentreing = FALSE;
106 #else
107 #define MainTextPrint 0
108 #endif
109 
110 BOOL KeepMainRifFile=FALSE;
111 
112 extern void LoadKeyConfiguration();
113 extern void DeInitialisePlayer();
114 
115 extern int AvP_MainMenus(void);
116 extern int AvP_InGameMenus(void);
117 
118 extern IngameKeyboardInput_ClearBuffer(void);
119 
120 HINSTANCE AVP_HInstance, hInst;
121 int AVP_NCmd;
122 
123 extern unsigned long TotalMemAllocated;
124 
125 char LevelName[] = {"predbit6\0QuiteALongNameActually"};
126 static ELO ELOLevelToLoad = {&LevelName};
127 
128 int QuickStartMultiplayer=1;
129 
130 int VideoModeNotAvailable=0;
131 
132 extern int DebuggingCommandsActive;
133 
134 extern void BuildMultiplayerLevelNameArray();
135 
136 extern int WindowMode;
exit_break_point_fucntion()137 void exit_break_point_fucntion ()
138 {
139 	#if debug
140 	if (WindowMode == WindowModeSubWindow)
141 	{
142 		__asm int 3;
143 	}
144 	#endif
145 }
146 
147 
WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)148 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
149                         LPSTR lpCmdLine, int nCmdShow)
150 {
151 	char * instr;
152 	#if debug
153 	int level_to_load = I_Num_Environments;
154 	char * command_line = lpCmdLine;
155 	#endif
156 
157 	AVP_HInstance = hInst = hInstance;
158 	AVP_NCmd = nCmdShow;
159 
160 	EnumerateCardsAndVideoModes();
161 
162 	LoadCDTrackList(); //load list of cd tracks assigned to levels , from a text file
163 
164 
165 //	CDDA_Start();
166 //	CDDA_Play(1);
167 
168 	SetFastRandom();
169 
170 	/**** init game now ONLY sets up varibles for the whole
171 				game. If you want to put something in it it must
172 				be something that only needs to be called once
173 	****/
174 	#if debug && 1//!PREDATOR_DEMO
175 	{
176 		#if OverrideOldMenus
177 		{
178 			HWAccel = 1;
179  		}
180 		#else
181 		if(strstr(command_line, "-h"))
182 		{
183 			HWAccel = 1;
184 		}
185 		#endif
186 
187 		//see if any extra npc rif files should be loaded
188 		{
189 			char* strpos=strstr(command_line, "-l");
190 			if(strpos)
191 			{
192 				while(strpos)
193 				{
194 					strpos+=2;
195 					if(*strpos>='a' && *strpos<='z')
196 					{
197 						while(*strpos>='a' && *strpos<='z')
198 						{
199 							switch (*strpos)
200 							{
201 								case 'a':
202 									ForceLoad_Alien = TRUE;
203 									break;
204 								case 'm':
205 									ForceLoad_Marine = TRUE;
206 									break;
207 								case 'p':
208 									ForceLoad_Predator = TRUE;
209 									break;
210 								case 'h':
211 									ForceLoad_Hugger = TRUE;
212 									break;
213 								case 'q':
214 									ForceLoad_Queen = TRUE;
215 									break;
216 								case 'c':
217 									ForceLoad_Civvie = TRUE;
218 									break;
219 								case 'x':
220 									ForceLoad_Xenoborg = TRUE;
221 									break;
222 								case 't':
223 									ForceLoad_Pretorian = TRUE;
224 									break;
225 								case 'r':
226 									ForceLoad_PredAlien = TRUE;
227 									break;
228 								case 's':
229 									ForceLoad_SentryGun = TRUE;
230 									break;
231 							}
232 							strpos++;
233 						}
234 					}
235 					else
236 					{
237 						ForceLoad_Alien = TRUE;
238 					}
239 					strpos=strstr(strpos,"-l");
240 				}
241 			}
242 		}
243 
244 		#ifdef AVP_DEBUG_VERSION
245 		if (strstr(command_line, "-intro"))	WeWantAnIntro();
246 		if (strstr(command_line, "-qm"))
247 		{
248 			QuickStartMultiplayer = 1;
249 		}
250 		else if (strstr(command_line, "-qa"))
251 		{
252 			QuickStartMultiplayer = 2;
253 		}
254 		else if (strstr(command_line, "-qp"))
255 		{
256 			QuickStartMultiplayer = 3;
257 		}
258 		else
259 		{
260 			QuickStartMultiplayer = 0;
261 		}
262 
263 		if(strstr(command_line,"-keeprif"))
264 		{
265 			KeepMainRifFile=TRUE;
266 		}
267 
268 		if (strstr(command_line, "-m"))
269 		{
270 			UseMouseCentreing = 1;
271 		}
272 		#endif //AVP_DEBUG_VERSION
273 	}
274 	#else
275 	{
276 		#if OverrideOldMenus
277 		{
278 			HWAccel = 1;
279 		}
280 		#endif
281 	}
282 	#endif
283 
284 	if(strstr(command_line,"-server"))
285 	{
286 		extern int DirectPlay_InitLobbiedGame();
287 		//game has been launched by mplayer , we best humour it
288 		LobbiedGame=LobbiedGame_Server;
289 		if(!DirectPlay_InitLobbiedGame())
290 		{
291 			exit(0x6364);
292 		}
293 	}
294 	else if(strstr(command_line,"-client"))
295 	{
296 		extern int DirectPlay_InitLobbiedGame();
297 		//ditto
298 		LobbiedGame=LobbiedGame_Client;
299 		if(!DirectPlay_InitLobbiedGame())
300 		{
301 			exit(0x6364);
302 		}
303 	}
304 	else if (strstr(command_line, "-debug"))
305 	{
306 		DebuggingCommandsActive = 1;
307 	}
308 
309 	if(instr = strstr(command_line, "-ip"))
310 	{
311 		char buffer[100];
312 		extern char CommandLineIPAddressString[];
313 
314 		sscanf(instr, "-ip %s", &buffer);
315 		strncpy(CommandLineIPAddressString,buffer,15);
316 		CommandLineIPAddressString[15] = 0;
317 	}
318 
319 
320  	// Modified by Edmond for mplayer demo
321  	#if MPLAYER_DEMO
322  	if (!LobbiedGame)
323  	{
324  		MessageBox(NULL, "This demo can only be launched from Mplayer.", "Oh no!", MB_OK);
325  		exit(33445);
326  	}
327  	#endif
328 
329  	#if PLAY_INTRO//(MARINE_DEMO||ALIEN_DEMO||PREDATOR_DEMO)
330   	if (!LobbiedGame)  // Edmond
331 	 	WeWantAnIntro();
332 	#endif
333 	GetPathFromRegistry();
334 
335 	/* JH 28/5/97 */
336 	/* Initialise 'fast' file system */
337 	#if MARINE_DEMO
338 	ffInit("fastfile\\mffinfo.txt","fastfile\\");
339 	#elif ALIEN_DEMO
340 	ffInit("alienfastfile\\ffinfo.txt","alienfastfile\\");
341 	#else
342 	ffInit("fastfile\\ffinfo.txt","fastfile\\");
343 	#endif
344 
345 	InitGame();
346 
347 
348     /*** Define video mode for windows initialisation ***/
349 	InitialVideoMode();
350 
351 	/****** Put in by John to sort out easy sub window mode ******/
352 	/****** REMOVE FOR GAME!!!!! ******/
353 
354 	#if debug && 1//!PREDATOR_DEMO
355 	if(strstr(command_line, "-w"))
356 	{
357 		WindowRequestMode = WindowModeSubWindow;
358 		if (!HWAccel)
359 			RasterisationRequestMode = RequestSoftwareRasterisation;
360 	}
361 	if(instr = strstr(command_line, "-s"))
362 		sscanf(instr, "-s%d", &level_to_load);
363 
364 	#endif
365 
366 	Env_List[0] = &(ELOLevelToLoad);
367 	level_to_load = 0;
368 
369 	/*******	System initialisation **********/
370 	InitialiseSystem(hInstance, nCmdShow);
371 	InitialiseRenderer();
372 
373 	InitOptionsMenu(); /* by this time we know all about the video card, etc */
374 
375 	LoadKeyConfiguration();
376 	/********** Grab The Video mode **********/
377 	/* JH - nope, not yet; not until we start the menus
378 		(or if debugging, start the game), do we need to
379 		set the initial video mode */
380 
381 
382 	/*-------------------Patrick 2/6/97-----------------------
383 	Start the sound system
384 	----------------------------------------------------------*/
385 	SoundSys_Start();
386 	CDDA_Start();
387 
388 	/* kill mouse cursor */
389 	SetCursor(NULL);
390 
391 	/* load language file and setup text string access */
392 	InitTextStrings();
393 
394 	BuildMultiplayerLevelNameArray();//sort out multiplayer level names
395 
396 	ChangeDirectDrawObject();
397 	AvP.LevelCompleted = 0;
398 	LoadSounds("PLAYER");
399 
400 	#if PREDATOR_DEMO||MARINE_DEMO||ALIEN_DEMO
401 	if(AvP_MainMenus())
402 	#else
403 	while(AvP_MainMenus())
404 	#endif
405 	{
406 		int menusActive=0;
407 		int thisLevelHasBeenCompleted=0;
408 		#if !(PREDATOR_DEMO||MARINE_DEMO||ALIEN_DEMO)
409 		if(instr = strstr(command_line, "-n"))
410 		{
411 			sscanf(instr, "-n %s", &LevelName);
412 		}
413 		#endif
414 
415 		#if debug
416 		if(UseMouseCentreing)
417 		{
418 			//Start thread that recentres mouse , making it easier to play
419 			//in subwindow mode
420 			InitCentreMouseThread();
421 		}
422 		#endif
423 //		Env_List[0] = &(ELOLevelToLoad);
424 //		level_to_load = 0;
425 //		AvP.PlayerType = I_Marine;
426 
427 
428 		/* turn off any special effects */
429 		d3d_light_ctrl.ctrl = LCCM_NORMAL;
430 		d3d_overlay_ctrl.ctrl = OCCM_NORMAL;
431 
432 		/* JH 20/5/97
433 			The video mode is no longer set when exiting the menus
434 			(not necessary if user selects EXIT)
435 			So it is set here */
436 
437 		/********** Grab The Video mode **********/
438 		GetCorrectDirectDrawObject();
439 
440 		if(!SetGameVideoMode())
441 		{
442 			VideoModeNotAvailable=1;
443 			continue;
444 		}
445 
446 	    /* Dubious restart hack for DirectDraw problems */
447 		/* JH - I'm not sure this is really necessary
448 			- it only comes into play if you try and set
449 			a video mode which is not supported
450 			BUT we are never going to try and do that
451 			- or are we? */
452 	    HandleVideoModeRestarts(hInstance, nCmdShow);
453 
454 
455 		/* Check Gamma Settings are correct after video mode change */
456 		InitialiseGammaSettings(RequestedGammaSetting);
457 
458 
459 
460 
461 		/**** init the chunk loaders ***************/
462 
463 		// no longer required here
464 
465 		// Load precompiled shapes
466 	    start_of_loaded_shapes = load_precompiled_shapes();
467 
468 		/***********  Load up the character stuff *******/
469 
470 		InitCharacter();
471 
472 		/* KJL 17:56:14 26/02/98 - load a font required for Dave's HUD */
473 //		LoadPFFont(DATABASE_MESSAGE_FONT);
474 
475 		/***********  Read in the env Map	 **************/
476 
477 		#if debug
478   		if(level_to_load != I_Num_Environments)
479   		{
480   			if((level_to_load < 0) || (level_to_load > I_Num_Environments))
481  				#ifdef MPLAYER_DEMO
482  					level_to_load = I_Dml1;
483  				#else
484  					level_to_load = I_Sp1;
485  				#endif
486 
487   			AvP.CurrentEnv = AvP.StartingEnv = level_to_load;
488   		}
489 		#endif
490 
491 		LoadRifFile(); /* sets up a map*/
492 		#if debug
493 		DebugFontLoaded = 1;
494 		#endif
495 
496 		/*********** Process the data ************/
497 		AssignAllSBNames();
498 		StartGame();
499 
500 //		UnloadRifFile();//deletes environment File_Chunk since it is no longer needed
501 
502 
503 		/* Patrick 26/6/97
504 		Load the game sounds here: should be done after loading everthing
505 		else, incase sounds take up system memory */
506 //		LoadSounds("PLAYER");
507 
508 		/* JH 28/5/97 */
509 		/* remove resident loaded 'fast' files */
510 		ffcloseall();
511 		/*********** Play the game ***************/
512 
513 		/* KJL 15:43:25 03/11/97 - run until this boolean is set to 0 */
514 		AvP.MainLoopRunning = 1;
515 
516 		ScanImagesForFMVs();
517 
518 		ResetFrameCounter();
519 		Game_Has_Loaded();
520 		ResetFrameCounter();
521 
522 		if(AvP.Network!=I_No_Network)
523 		{
524 			/*Need to choose a starting position for the player , but first we must look
525 			through the network messages to find out which generator spots are currently clear*/
526 			netGameData.myGameState = NGS_Playing;
527 			MinimalNetCollectMessages();
528 			TeleportNetPlayerToAStartingPosition(Player->ObStrategyBlock,1);
529 		}
530 
531 		IngameKeyboardInput_ClearBuffer();
532 		while(AvP.MainLoopRunning)
533 		{
534 
535 			#if debug
536 			#if 0
537 			DumpBoundsCheckInfo(DUMPTOSCREEN);
538 			#endif
539 			#endif
540 
541 		 	CheckForWindowsMessages();
542 			CursorHome();
543 
544 			#if debug
545 			if (memoryInitialisationFailure)
546 			{
547 				textprint("Initialisation not completed - out of memory!\n");
548 				GLOBALASSERT(1 == 0);
549 			}
550 			#endif
551 
552 			switch(AvP.GameMode)
553 			{
554 				case I_GM_Playing:
555 				{
556 					if ((!menusActive || (AvP.Network!=I_No_Network && !netGameData.skirmishMode)) && !AvP.LevelCompleted)
557 					{
558 						#if MainTextPrint 		/* debugging stuff */
559 						{
560 
561 							if (ShowDebuggingText.FPS) ReleasePrintDebuggingText("FrameRate = %d fps\n",FrameRate);
562 							if (ShowDebuggingText.Environment) ReleasePrintDebuggingText("Environment %s\n", Env_List[AvP.CurrentEnv]->main);
563 							if (ShowDebuggingText.Coords) ReleasePrintDebuggingText("Player World Coords: %d,%d,%d\n",Player->ObWorld.vx,Player->ObWorld.vy,Player->ObWorld.vz);
564 
565 							{
566 								PLAYER_STATUS *playerStatusPtr= (PLAYER_STATUS *) (Player->ObStrategyBlock->SBdataptr);
567 								PLAYER_WEAPON_DATA *weaponPtr = &(playerStatusPtr->WeaponSlot[playerStatusPtr->SelectedWeaponSlot]);
568 								TEMPLATE_WEAPON_DATA *twPtr = &TemplateWeapon[weaponPtr->WeaponIDNumber];
569 								if (ShowDebuggingText.GunPos)
570 								{
571 									PrintDebuggingText("Gun Position x:%d,y:%d,z:%d\n",twPtr->RestPosition.vx,twPtr->RestPosition.vy,twPtr->RestPosition.vz);
572 								}
573 							}
574 						}
575 						#endif  /* MainTextPrint */
576 
577 						DoAllShapeAnimations();
578 
579 						UpdateGame();
580 
581 						#if 1
582 						#if PROFILING_ON
583 					  	ProfileStart();
584 						#endif
585 						AvpShowViews();
586 						#if PROFILING_ON
587 					  	ProfileStop("SHOW VIEW");
588 						#endif
589 
590 						//Do screen shot here so that text and  hud graphics aren't shown
591 						#if PROFILING_ON
592 					  	ProfileStart();
593 						#endif
594 						MaintainHUD();
595 						#if PROFILING_ON
596 					  	ProfileStop("RENDER HUD");
597 						#endif
598 
599 						#if debug
600 						FlushTextprintBuffer();
601 						#endif
602 
603 						//check cd status
604 						CheckCDAndChooseTrackIfNeeded();
605 
606 						// check to see if we're pausing the game;
607 						// if so kill off any sound effects
608 						if(InGameMenusAreRunning() && ( (AvP.Network!=I_No_Network && netGameData.skirmishMode) || (AvP.Network==I_No_Network))	)
609 							SoundSys_StopAll();
610 					}
611 					else
612 					{
613 						ReadUserInput();
614 //						UpdateAllFMVTextures();
615 						SoundSys_Management();
616 						#if SOFTWARE_RENDERER
617 						FlushSoftwareZBuffer();
618 						#else
619 						FlushD3DZBuffer();
620 						#endif621 						{
622 							extern void ThisFramesRenderingHasBegun(void);
623 							ThisFramesRenderingHasBegun();
624 						}
625 					}
626 
627 					{
628 						menusActive = AvP_InGameMenus();
629 						if(AvP.RestartLevel) menusActive=0;
630 					}
631 					if (AvP.LevelCompleted)
632 					{
633 						SoundSys_FadeOutFast();
634 						DoCompletedLevelStatisticsScreen();
635 						thisLevelHasBeenCompleted = 1;
636 					}
637 
638 					{
639 						/* after this call, no more graphics can be drawn until the next frame */
640 						extern void ThisFramesRenderingHasFinished(void);
641 						ThisFramesRenderingHasFinished();
642 					}
643 
644 					/* JH 5/6/97 - this function may draw translucent polygons to the whole screen */
645 					//HandleD3DScreenFading();
646 					#else
647 					{
648 
649 					ColourFillBackBuffer(0);
650 					}
651 					#endif
652 
653 
654 					InGameFlipBuffers();
655 
656 					FrameCounterHandler();
657 					{
658 						PLAYER_STATUS *playerStatusPtr= (PLAYER_STATUS *) (Player->ObStrategyBlock->SBdataptr);
659 
660 						if (!menusActive && playerStatusPtr->IsAlive && !AvP.LevelCompleted)
661 						{
662 							DealWithElapsedTime();
663 						}
664 					}
665 					break;
666 				}
667 				case I_GM_Menus:
668 				{
669 					AvP.GameMode = I_GM_Playing;
670 					//StartGameMenus();
671 					LOCALASSERT(AvP.Network == I_No_Network);
672 					//AccessDatabase(0);
673 					break;
674 				}
675 				#if 0
676 				case I_GM_Paused:
677 				{
678 					{
679 						extern void DoPcPause(void);
680 						DoPcPause();
681 					}
682 					break;
683 				}
684 				#endif
685 
686 				default:
687 				{
688 					GLOBALASSERT(2<1);
689 					break;
690 				}
691 			}
692 
693 			if(AvP.RestartLevel)
694 			{
695 				AvP.RestartLevel=0;
696 				AvP.LevelCompleted = 0;
697 				FixCheatModesInUserProfile(UserProfilePtr);
698 				RestartLevel();
699 			}
700 
701 
702 		}// end of main game loop
703 		{
704 			AvP.LevelCompleted = thisLevelHasBeenCompleted;
705 		}
706 
707 		FixCheatModesInUserProfile(UserProfilePtr);
708 
709 		#if !(PREDATOR_DEMO||MARINE_DEMO||ALIEN_DEMO)
710 		TimeStampedMessage("We're out of the main loop");
711 
712 		/* KJL 17:56:14 26/02/98 - unload a font required for Dave's HUD */
713 //		UnloadFont(&AvpFonts[DATABASE_MESSAGE_FONT]);
714 		#if 1
715 		{
716 			extern void CloseFMV(void);
717 			CloseFMV();
718 			ReleaseAllFMVTextures();
719 		}
720 		#endif
721 
722 		/* DHM 23/3/98 */
723 //		REBMENUS_ProjectSpecific_EndOfMainLoopHook();
724 
725 		/* DHM 8/4/98 */
726 		CONSBIND_WriteKeyBindingsToConfigFile();
727 		TimeStampedMessage("After key bindings writen");
728 
729 		/* CDF 2/10/97 */
730 		DeInitialisePlayer();
731 		TimeStampedMessage("After DeInitialisePlayer");
732 
733 		DeallocatePlayersMirrorImage();
734 		TimeStampedMessage("After DeallocatePlayersMirrorImage");
735 
736 		/* KJL 15:26:43 03/12/97 - clear data */
737 		KillHUD();
738 		TimeStampedMessage("After KillHUD");
739 
740 		Destroy_CurrentEnvironment();
741 		TimeStampedMessage("After Destroy_CurrentEnvironment");
742 		DeallocateAllImages();
743 		TimeStampedMessage("After DeallocateAllImages");
744 		EndNPCs(); /* JH 30/4/97 - unload npc rifs */
745 		TimeStampedMessage("After EndNPCs");
746 		ExitGame();
747 		#endif
748 		/* Patrick 26/6/97
749 		Stop and remove all game sounds here, since we are returning to the menus */
750 		SoundSys_StopAll();
751 		ResetEaxEnvironment();
752 		//make sure the volume gets reset for the menus
753 		SoundSys_ResetFadeLevel();
754 
755 		TimeStampedMessage("After SoundSys_StopAll");
756 
757 //		SoundSys_RemoveAll();
758 
759 		TimeStampedMessage("After SoundSys_RemoveAll");
760 		CDDA_Stop();
761 		TimeStampedMessage("After CDDA_Stop");
762 
763 		/* netgame support */
764 		if(AvP.Network != I_No_Network)
765 		{
766 			/* we cleanup and reset our game mode here, at the end of the game loop, as other
767 			clean-up functions need to know if we've just exited a netgame */
768 			EndAVPNetGame();
769 			//EndOfNetworkGameScreen();
770 		}
771 
772 		//need to get rid of the player rifs before we can clear the memory pool
773 
774 		ClearMemoryPool();
775 
776 		#if debug
777 		if(UseMouseCentreing)
778 		{
779 			//Stop thread that recentres mouse , making it easier to play
780 			//in subwindow mode
781 			FinishCentreMouseThread();
782 		}
783 		#endif
784 
785 		if(LobbiedGame)
786 		{
787 			/*
788 			We have been playing a lobbied game , and have now diconnected.
789 			Since we can't start a new multiplayer game , exit to avoid confusion
790 			*/
791 			break;
792 		}
793 	}
794 	#if !(PREDATOR_DEMO||MARINE_DEMO||ALIEN_DEMO)
795 	TimeStampedMessage("After Menus");
796 
797 	/* Added 28/1/98 by DHM: hook for my code on program shutdown */
798 	{
799 		DAVEHOOK_UnInit();
800 	}
801 	TimeStampedMessage("After DAVEHOOK_UnInit");
802 
803 	/*-------------------Patrick 2/6/97-----------------------
804 	End the sound system
805 	----------------------------------------------------------*/
806 	SoundSys_StopAll();
807   	SoundSys_RemoveAll();
808 
809 
810 
811 
812 
813 	#else
814 	QuickSplashScreens();
815 	#endif
816 	#if !(PREDATOR_DEMO||MARINE_DEMO||ALIEN_DEMO)
817 	TimeStampedMessage("After SoundSys_End");
818 	TimeStampedMessage("After CDDA_End");
819 	/* unload language file */
820 //	KillTextStrings();
821 // 	TimeStampedMessage("After KillTextStrings");
822 	ExitSystem();
823 	TimeStampedMessage("After ExitSystem");
824 
825 //	ffKill(); /* to avoid misreported memory leaks */
826 	TimeStampedMessage("After ffKill");
827 	#else
828 	SoundSys_End();
829 	ReleaseDirect3D();
830 	//TimeStampedMessage("after ReleaseDirect3D");
831 
832 	/* Kill windows procedures */
833 	ExitWindowsSystem();
834 	//TimeStampedMessage("after ExitWindowsSystem");
835 
836 	#endif
837  	CDDA_End();
838 	ClearMemoryPool();
839 
840 	return(0);
841 }
842 
843