2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 #pragma off (unreferenced)
16 static char rcsid[] = "$Id: winferno.c,v 1.1.1.1 2001-01-19 03:30:14 bradleyb Exp $";
17 #pragma on (unreferenced)
68 // Globals --------------------------------------------------------------------
69 extern int Network_allow_socket_changes;
70 extern char gr_palette[3*256];
71 extern int grd_fades_disabled;
72 extern int MenuHiresAvailable;
73 extern int piggy_low_memory;
75 int Function_mode=FMODE_MENU; //game or editor?
76 int Screen_mode=-1; //game screen or editor screen?
77 int descent_critical_error = 0;
78 unsigned descent_critical_deverror = 0;
79 unsigned descent_critical_errcode = 0;
81 /// CHANGE THIS. PUT THIS WHERE IT SHOULD ME.
83 int WVIDEO_running=1; //debugger can set to 1 if running
86 // Version ID Info. -----------------------------------------------------------
90 //Current version number
92 ubyte Version_major = 1; //FULL VERSION
93 ubyte Version_minor = 2;
95 int registered_copy=0;
96 char name_copy[DESC_ID_LEN];
98 static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; //4-byte checksum
99 char desc_id_exit_num = 0;
100 time_t t_current_time, t_saved_time;
102 byte CybermouseActive = 0;
104 static char title_pal[768];
107 // THIS IS A HACK UNTIL WE HAVE MOVIES
109 char CDROM_dir[30] = "";
110 int Hogfile_on_CD = 0;
113 // Function Prototypes --------------------------------------------------------
115 int InitGraphics(void);
116 void DisplayDescentTitle(void);
118 void check_joystick_calibration();
120 void check_id_checksum_and_date();
122 HANDLE clipboard_renderformat(int cf);
123 HPALETTE SetPalette(HDC hdc, HPALETTE hPal);
124 void DestroyPalette(HPALETTE hPal);
126 #define HOGNAME "descent2.hog"
128 extern int CD_audio_desktop_dev;
129 extern DWORD CD_audio_desktop_vol;
132 // Functions ------------------------------------------------------------------
134 void InitCD(char *arg)
138 logentry("Initializing CD-ROM...\n");
140 if (!init_cdrom()) { //look for Cd, etc.
142 Error("Sorry, the Descent II CD must be present to run.");
145 else { //check to make sure not running off CD
146 // if (toupper(arg[0]) == toupper(CDROM_dir[0]))
147 // Error("You cannot run Descent II directly from your CD-ROM drive.\n"
148 // " To run Descent II, CD to the directory you installed to, then type D2.\n"
149 // " To install Descent II, type %c:\\INSTALL.",toupper(CDROM_dir[0]));
152 // Let's save the current volume of CD-audio-out
153 // Find CD-AUDIO device if there is one.
154 for (i = 0; i < auxGetNumDevs(); i++)
157 auxGetDevCaps(i, &caps, sizeof(caps));
158 if (caps.wTechnology == AUXCAPS_CDAUDIO) {
159 CD_audio_desktop_dev = i;
160 mprintf((0, "CD audio operating on AUX %d.\n", CD_audio_desktop_dev));
165 if (CD_audio_desktop_dev != -1) {
167 auxGetVolume(CD_audio_desktop_dev, &CD_audio_desktop_vol);
168 mprintf((1, "CD vol: 0x%x\n", CD_audio_desktop_vol));
177 logentry("Initializing Video System...\n");
179 if (FindArg("-hw_3dacc")) flag = 1;
183 Error("Unable to initialize GFX system.");
186 //@@ _3dfx_available = _3dfx_Init();
192 logentry("Initializing IO System...\n");
196 if (!win95_controls_init())
197 logentry("\tUnable to detect an auxillary control.\n");
198 mouse_set_window (_hAppWnd);
199 mouse_set_mode(0); // Non-centering mode
205 logentry("Initializing Data...\n");
209 if (! cfile_init(HOGNAME)) { //didn't find HOG. Check on CD
211 Error("Could not find required file <%s>",HOGNAME);
217 //print out the banner title
219 cprintf("\nDESCENT II %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
221 cprintf(" %s", VERSION_NAME);
223 cprintf(" %s %s\n", __DATE__,__TIME__);
224 cprintf("%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
228 check_id_checksum_and_date();
234 logentry("Initializing Sound System...\n");
237 logentry("Unable to initialize sound system.\n");
244 int socket=0, showaddress=0;
248 logentry("Initializing Networking system...\n");
250 if ((t=FindArg("-socket")))
251 socket = atoi( Args[t+1] );
253 if ( FindArg("-showaddress") ) showaddress=1;
255 if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket,showaddress))==0) {
256 mprintf((0, "IPX protocol on channel %x.\n", IPX_DEFAULT_SOCKET+socket ));
260 switch( ipx_error ) {
261 case 3: mprintf((1, "%s\n", TXT_NO_NETWORK)); break;
262 case -2: mprintf((1, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket)); break;
263 case -4: mprintf((1, "%s\n", TXT_MEMORY_IPX )); break;
265 mprintf((1, "\t%s %d\n", TXT_ERROR_IPX, ipx_error ));
268 logentry("%s\n",TXT_NETWORK_DISABLED);
269 Network_active = 0; // Assume no network
272 mprintf((0, "Here?"));
274 ipx_read_user_file( "descent.usr" );
275 ipx_read_network_file( "descent.net" );
281 Lighting_on = 1; // Turn on lighting for now.
285 if (!dd_VR_offscreen_buffer)
288 // Create and Set Initial Palette.
289 logentry("Initializing palette system...\n" );
290 gr_use_palette_table(DEFAULT_PALETTE);
291 gr_palette_load(gr_palette);
293 logentry( "Initializing font system...\n" );
296 if (FindArg("-lowresmovies"))
299 MenuHires = MenuHiresAvailable = 1;
301 // Set up movies and title
302 logentry("Initializing movie libraries...\n" );
303 init_movies(); //init movie libraries
305 if (!init_subtitles("intro.tex"))
306 mprintf((1, "Unable to open subtitles.\n"));
307 PlayMovie("intro.mve",MOVIE_ABORT_ON);
311 songs_play_song( SONG_TITLE, 1);
313 FontHires = MenuHires;
315 //LoadCursorWin(MOUSE_WAIT_CURSOR);
317 DEFINE_SCREEN("DESCENTB.PCX");
318 DisplayDescentTitle();
320 // SendMessage(_hAppWnd, WM_SETREDRAW, FALSE, 0);
322 // Doing some 3d initialization
323 logentry( "Doing bm_init...\n" );
328 logentry( "Initializing 3d system...\n" );
331 logentry( "Initializing texture caching system...\n" );
332 texmerge_init( 10 ); // 10 cache bitmaps
334 logentry("Final initialization...\n" );
336 memcpy(gr_palette,title_pal,sizeof(gr_palette));
338 set_screen_mode(SCREEN_MENU);
342 set_detail_level_parameters(Detail_level);
344 // SendMessage(_hAppWnd, WM_SETREDRAW, TRUE, 0);
345 //LoadCursorWin(MOUSE_DEFAULT_CURSOR);
351 // Title Page gone, now start main program
352 // Players[Player_num].callsign[0] = '\0';
354 do_register_player(title_pal);
356 gr_palette_fade_out( title_pal, 32, 0 );
358 //check for special stamped version
359 if (registered_copy) {
363 _ctime(&t_saved_time, time_str);
364 _ctime(&t_current_time, time_str2);
366 nm_messagebox("EVALUATION COPY",1,"Continue",
367 "This special evaluation copy\n"
368 "of DESCENT II has been issued to:\n\n"
370 "\nEXPIRES %s\nYOUR TIME: %s\nNOT FOR DISTRIBUTION",
371 name_copy, time_str,time_str2);
373 gr_palette_fade_out( gr_palette, 32, 0 );
376 Game_mode = GM_GAME_OVER;
380 // Winferno Internal Routines
382 void DisplayDescentTitle(void)
384 // Create Descent Title Window and Load Title bitmap, and display it.
388 logentry("Displaying title...\n");
390 // Display Title Bitmap, using title palette.
391 pcx_error = pcx_get_dimensions("DESCENTB.PCX", &width, &height);
392 if (pcx_error != PCX_ERROR_NONE) {
394 Error( "Couldn't load pcx file 'DESCENTB.PCX', PCX load error: %s\n", pcx_errormsg(pcx_error));
397 // pcx_canvas = dd_gr_create_canvas(width, height );
401 dd_gr_set_current_canvas(NULL);
402 DDGRLOCK(dd_grd_curcanv)
404 pcx_error=pcx_read_bitmap( "DESCENTB.PCX", &grd_curcanv->cv_bitmap,
405 grd_curcanv->cv_bitmap.bm_type,
408 DDGRUNLOCK(dd_grd_curcanv)
410 if (pcx_error == PCX_ERROR_NONE) {
411 // Blt to screen, then restore display
413 gr_palette_fade_in( title_pal, 32, 0 );
416 Error( "Couldn't load pcx file 'DESCENT.PCX', PCX load error: %s\n", pcx_errormsg(pcx_error));
421 do_register_player(ubyte *title_pal)
423 Players[Player_num].callsign[0] = '\0';
429 memcpy(gr_palette,title_pal,sizeof(gr_palette));
430 remap_fonts_and_menus(1);
431 RegisterPlayer(); //get player's name
436 //@@void check_joystick_calibration()
438 //@@ int x1, y1, x2, y2, c;
441 //@@ if ( (Config_control_type!=CONTROL_JOYSTICK) &&
442 //@@ (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
443 //@@ (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
444 //@@ (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
447 //@@ joy_get_pos( &x1, &y1 );
449 //@@ t1 = timer_get_fixed_seconds();
450 //@@ while( timer_get_fixed_seconds() < t1 + F1_0/100 )
453 //@@ joy_get_pos( &x2, &y2 );
455 //@@ // If joystick hasn't moved...
456 //@@ if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
457 //@@ if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
458 //@@ c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
460 //@@ joydefs_calibrate();
468 int find_descent_cd()
471 char oldpath[MAX_PATH];
480 GetCurrentDirectory(MAX_PATH, oldpath);
482 for (i = 0; i < 26; i++)
485 if (GetDriveType(path) == DRIVE_CDROM) {
487 GetVolumeInformation(path, volume, 256, NULL, NULL, NULL, NULL, 0);
488 mprintf((0, "CD volume: %s\n", volume));
489 if (!strcmpi(volume, "DESCENT_II") || !strcmpi(volume, "DESCENT.II")) {
491 if (!chdir("\\d2data")) {
499 SetCurrentDirectory(oldpath);
510 i = find_descent_cd();
515 if ((i=FindArg("-cdproxy")) != 0) {
516 strcpy(CDROM_dir,"d:\\d2data\\"); //set directory
517 CDROM_dir[0] = Args[i+1][0];
525 strcpy(CDROM_dir,"d:\\d2data\\"); //set directory
526 CDROM_dir[0] = 'A'+i; //set correct drive leter
527 mprintf((0, "Descent 2 CD-ROM: %s\n", CDROM_dir));
533 // ----------------------------------------------------------------------------
536 check_id_checksum_and_date()
538 const char name[sizeof(DESC_ID_TAG)-1+DESC_ID_LEN] = DESC_ID_TAG;
539 char time_str[] = DESC_DEAD_TIME_TAG "00000000"; //second part gets overwritten
541 unsigned long *checksum, test_checksum;
542 time_t current_time, saved_time;
544 saved_time = (time_t)strtol(time_str + strlen(DESC_DEAD_TIME_TAG), NULL, 16);
546 t_saved_time = saved_time;
548 if (saved_time == (time_t)0)
551 mprintf((1, "TIME STAMPED: %d\n", saved_time));
553 strcpy(name_copy,name+strlen(DESC_ID_TAG));
556 t_current_time = current_time = time(NULL);
558 mprintf((1, "CURTIME: %d\n", current_time));
560 if (current_time >= saved_time)
561 desc_id_exit_num = 1;
564 for (i = 0; i < strlen(name_copy); i++) {
566 test_checksum += name_copy[i];
567 if (((test_checksum / 2) * 2) != test_checksum)
569 test_checksum = test_checksum >> 1;
571 test_checksum |= 0x80000000;
573 checksum = (unsigned long *)(desc_id_checksum_str + strlen(DESC_ID_CHKSUM_TAG));
574 if (test_checksum != *checksum)
575 desc_id_exit_num = 2;
577 cprintf ("%s %s\n", TXT_REGISTRATION, name_copy);
581 // ----------------------------------------------------------------------------
582 // Nifty clipboard functions for placing a screen shot
583 // ----------------------------------------------------------------------------
585 extern HANDLE win95_dib_from_bitmap(HBITMAP hbm);
587 void win95_save_pcx_shot()
590 static int savenum = 0;
593 dd_grs_canvas *screen_canv = dd_grd_screencanv;
594 dd_grs_canvas *temp_canv_1, *save_canv; //*temp_canv_2,
598 char savename[FILENAME_LEN]; //NO STEREO savename2[FILENAME_LEN];
604 mprintf((0, "Screen shot!\n"));
607 save_canv = dd_grd_curcanv;
608 temp_canv_1 = dd_gr_create_canvas(screen_canv->canvas.cv_bitmap.bm_w,
609 screen_canv->canvas.cv_bitmap.bm_h);
611 dd_gr_blt_notrans(screen_canv, 0, 0, 0, 0, temp_canv_1, 0, 0, 0, 0);
613 /* Saved screen shot */
614 dd_gr_set_current_canvas(save_canv);
616 if ( savenum > 99 ) savenum = 0;
617 sprintf(savename,"screen%02d.pcx",savenum++);
618 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
620 dd_gr_set_current_canvas(NULL);
622 DDGRLOCK(dd_grd_curcanv);
624 save_font = grd_curcanv->cv_font;
625 gr_set_curfont(GAME_FONT);
626 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
627 gr_get_string_size(message,&w,&h,&aw);
629 x = (grd_curcanv->cv_w-w)/2;
630 y = (grd_curcanv->cv_h-h)/2;
632 gr_setcolor(gr_find_closest_color_current(0,0,0));
633 gr_rect(x-2,y-2,x+w+2,y+h+2);
634 gr_printf(x,y,message);
635 gr_set_curfont(save_font);
637 DDGRUNLOCK(dd_grd_curcanv);
639 if (GRMODEINFO(modex)) dd_gr_flip();
641 t1 = timer_get_fixed_seconds() + F1_0;
643 gr_palette_read(pal); //get actual palette from the hardware
645 DDGRLOCK(temp_canv_1);
646 pcx_write_bitmap(savename,&temp_canv_1->canvas.cv_bitmap,pal);
647 DDGRUNLOCK(temp_canv_1);
649 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
651 dd_gr_set_current_canvas(screen_canv);
653 dd_gr_blt_notrans(temp_canv_1, 0,0,0,0, dd_grd_curcanv, 0,0,0,0);
655 if (GRMODEINFO(modex)) dd_gr_flip();
657 dd_gr_free_canvas(temp_canv_1);
659 dd_gr_set_current_canvas(save_canv);
666 HANDLE hClipData = NULL;
668 BOOL clipboard_screenshot()
670 if (OpenClipboard(_hAppWnd)) {
672 SetClipboardData (CF_DIB ,clipboard_renderformat(CF_DIB));
673 SetClipboardData (CF_BITMAP ,clipboard_renderformat(CF_BITMAP));
674 SetClipboardData (CF_PALETTE ,clipboard_renderformat(CF_PALETTE));
682 HANDLE clipboard_renderformat(int cf)
691 // Create screen shot BBM
692 mprintf((1, "Creating DDB for clipboard.\n"));
693 hMem = win95_screen_shot();
694 if (!hMem) mprintf((1, "Unable to create clipboard object: CF_BITMAP\n"));
700 // Create DIB and all memory associated with it.
701 mprintf((1, "Creating DIB for clipboard.\n"));
702 hbm = win95_screen_shot();
703 hMem = win95_dib_from_bitmap(hbm);
704 if (!hMem) mprintf((1, "Unable to create clipboard object: CF_DIB\n"));
711 // Get current palette! (create a GDI palette from grpal)
716 mprintf((1, "Creating Palette for clipboard.\n"));
717 gr_palette_read(grpal);
718 lpal.version = 0x300;
719 lpal.num_entries = 256;
720 for (i = 0; i < 256; i++)
722 lpal.entries[i].peRed = grpal[i*3] << 2;
723 lpal.entries[i].peGreen = grpal[i*3+1] << 2;
724 lpal.entries[i].peBlue = grpal[i*3+2] << 2;
725 lpal.entries[i].peFlags = 0;
728 hMem = CreatePalette((LOGPALETTE*)&lpal);
729 if (!hMem) mprintf((1, "Unable to create clipboard object: CF_PALETTE\n"));