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.
64 // Globals --------------------------------------------------------------------
65 extern int Network_allow_socket_changes;
66 extern char gr_palette[3*256];
67 extern int grd_fades_disabled;
68 extern int MenuHiresAvailable;
69 extern int piggy_low_memory;
71 int Function_mode=FMODE_MENU; //game or editor?
72 int Screen_mode=-1; //game screen or editor screen?
73 int descent_critical_error = 0;
74 unsigned descent_critical_deverror = 0;
75 unsigned descent_critical_errcode = 0;
77 /// CHANGE THIS. PUT THIS WHERE IT SHOULD ME.
79 int WVIDEO_running=1; //debugger can set to 1 if running
82 // Version ID Info. -----------------------------------------------------------
86 //Current version number
88 ubyte Version_major = 1; //FULL VERSION
89 ubyte Version_minor = 2;
91 int registered_copy=0;
92 char name_copy[DESC_ID_LEN];
94 static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; //4-byte checksum
95 char desc_id_exit_num = 0;
96 time_t t_current_time, t_saved_time;
98 byte CybermouseActive = 0;
100 static char title_pal[768];
103 // THIS IS A HACK UNTIL WE HAVE MOVIES
105 char CDROM_dir[30] = "";
106 int Hogfile_on_CD = 0;
109 // Function Prototypes --------------------------------------------------------
111 int InitGraphics(void);
112 void DisplayDescentTitle(void);
114 void check_joystick_calibration();
116 void check_id_checksum_and_date();
118 HANDLE clipboard_renderformat(int cf);
119 HPALETTE SetPalette(HDC hdc, HPALETTE hPal);
120 void DestroyPalette(HPALETTE hPal);
122 #define HOGNAME "descent2.hog"
124 extern int CD_audio_desktop_dev;
125 extern DWORD CD_audio_desktop_vol;
128 // Functions ------------------------------------------------------------------
130 void InitCD(char *arg)
134 logentry("Initializing CD-ROM...\n");
136 if (!init_cdrom()) { //look for Cd, etc.
138 Error("Sorry, the Descent II CD must be present to run.");
141 else { //check to make sure not running off CD
142 // if (toupper(arg[0]) == toupper(CDROM_dir[0]))
143 // Error("You cannot run Descent II directly from your CD-ROM drive.\n"
144 // " To run Descent II, CD to the directory you installed to, then type D2.\n"
145 // " To install Descent II, type %c:\\INSTALL.",toupper(CDROM_dir[0]));
148 // Let's save the current volume of CD-audio-out
149 // Find CD-AUDIO device if there is one.
150 for (i = 0; i < auxGetNumDevs(); i++)
153 auxGetDevCaps(i, &caps, sizeof(caps));
154 if (caps.wTechnology == AUXCAPS_CDAUDIO) {
155 CD_audio_desktop_dev = i;
156 mprintf((0, "CD audio operating on AUX %d.\n", CD_audio_desktop_dev));
161 if (CD_audio_desktop_dev != -1) {
163 auxGetVolume(CD_audio_desktop_dev, &CD_audio_desktop_vol);
164 mprintf((1, "CD vol: 0x%x\n", CD_audio_desktop_vol));
173 logentry("Initializing Video System...\n");
175 if (FindArg("-hw_3dacc")) flag = 1;
179 Error("Unable to initialize GFX system.");
182 //@@ _3dfx_available = _3dfx_Init();
188 logentry("Initializing IO System...\n");
192 if (!win95_controls_init())
193 logentry("\tUnable to detect an auxillary control.\n");
194 mouse_set_window (_hAppWnd);
195 mouse_set_mode(0); // Non-centering mode
201 logentry("Initializing Data...\n");
205 if (! cfile_init(HOGNAME)) { //didn't find HOG. Check on CD
207 Error("Could not find required file <%s>",HOGNAME);
213 //print out the banner title
215 cprintf("\nDESCENT II %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
217 cprintf(" %s", VERSION_NAME);
219 cprintf(" %s %s\n", __DATE__,__TIME__);
220 cprintf("%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
224 check_id_checksum_and_date();
230 logentry("Initializing Sound System...\n");
233 logentry("Unable to initialize sound system.\n");
240 int socket=0, showaddress=0;
244 logentry("Initializing Networking system...\n");
246 if ((t=FindArg("-socket")))
247 socket = atoi( Args[t+1] );
249 if ( FindArg("-showaddress") ) showaddress=1;
251 if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket,showaddress))==0) {
252 mprintf((0, "IPX protocol on channel %x.\n", IPX_DEFAULT_SOCKET+socket ));
256 switch( ipx_error ) {
257 case 3: mprintf((1, "%s\n", TXT_NO_NETWORK)); break;
258 case -2: mprintf((1, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket)); break;
259 case -4: mprintf((1, "%s\n", TXT_MEMORY_IPX )); break;
261 mprintf((1, "\t%s %d\n", TXT_ERROR_IPX, ipx_error ));
264 logentry("%s\n",TXT_NETWORK_DISABLED);
265 Network_active = 0; // Assume no network
268 mprintf((0, "Here?"));
270 ipx_read_user_file( "descent.usr" );
271 ipx_read_network_file( "descent.net" );
277 Lighting_on = 1; // Turn on lighting for now.
281 if (!dd_VR_offscreen_buffer)
282 set_display_mode(Default_display_mode);
284 // Create and Set Initial Palette.
285 logentry("Initializing palette system...\n" );
286 gr_use_palette_table(D2_DEFAULT_PALETTE);
287 gr_palette_load(gr_palette);
289 logentry( "Initializing font system...\n" );
292 if (FindArg("-lowresmovies"))
295 MenuHires = MenuHiresAvailable = 1;
297 // Set up movies and title
298 logentry("Initializing movie libraries...\n" );
299 init_movies(); //init movie libraries
301 if (!init_subtitles("intro.tex"))
302 mprintf((1, "Unable to open subtitles.\n"));
303 PlayMovie("intro.mve",MOVIE_ABORT_ON);
307 songs_play_song( SONG_TITLE, 1);
309 FontHires = MenuHires;
311 //LoadCursorWin(MOUSE_WAIT_CURSOR);
313 DEFINE_SCREEN("DESCENTB.PCX");
314 DisplayDescentTitle();
316 // SendMessage(_hAppWnd, WM_SETREDRAW, FALSE, 0);
318 // Doing some 3d initialization
319 logentry( "Doing bm_init...\n" );
324 logentry( "Initializing 3d system...\n" );
327 logentry( "Initializing texture caching system...\n" );
328 texmerge_init( 10 ); // 10 cache bitmaps
330 logentry("Final initialization...\n" );
332 memcpy(gr_palette,title_pal,sizeof(gr_palette));
334 set_screen_mode(SCREEN_MENU);
338 set_detail_level_parameters(Detail_level);
340 // SendMessage(_hAppWnd, WM_SETREDRAW, TRUE, 0);
341 //LoadCursorWin(MOUSE_DEFAULT_CURSOR);
347 // Title Page gone, now start main program
348 // Players[Player_num].callsign[0] = '\0';
350 do_register_player(title_pal);
352 gr_palette_fade_out( title_pal, 32, 0 );
354 //check for special stamped version
355 if (registered_copy) {
359 _ctime(&t_saved_time, time_str);
360 _ctime(&t_current_time, time_str2);
362 nm_messagebox("EVALUATION COPY",1,"Continue",
363 "This special evaluation copy\n"
364 "of DESCENT II has been issued to:\n\n"
366 "\nEXPIRES %s\nYOUR TIME: %s\nNOT FOR DISTRIBUTION",
367 name_copy, time_str,time_str2);
369 gr_palette_fade_out( gr_palette, 32, 0 );
372 Game_mode = GM_GAME_OVER;
376 // Winferno Internal Routines
378 void DisplayDescentTitle(void)
380 // Create Descent Title Window and Load Title bitmap, and display it.
384 logentry("Displaying title...\n");
386 // Display Title Bitmap, using title palette.
387 pcx_error = pcx_get_dimensions("DESCENTB.PCX", &width, &height);
388 if (pcx_error != PCX_ERROR_NONE) {
390 Error( "Couldn't load pcx file 'DESCENTB.PCX', PCX load error: %s\n", pcx_errormsg(pcx_error));
393 // pcx_canvas = dd_gr_create_canvas(width, height );
397 dd_gr_set_current_canvas(NULL);
398 DDGRLOCK(dd_grd_curcanv)
400 pcx_error=pcx_read_bitmap( "DESCENTB.PCX", &grd_curcanv->cv_bitmap,
401 grd_curcanv->cv_bitmap.bm_type,
404 DDGRUNLOCK(dd_grd_curcanv)
406 if (pcx_error == PCX_ERROR_NONE) {
407 // Blt to screen, then restore display
409 gr_palette_fade_in( title_pal, 32, 0 );
412 Error( "Couldn't load pcx file 'DESCENT.PCX', PCX load error: %s\n", pcx_errormsg(pcx_error));
417 do_register_player(ubyte *title_pal)
419 Players[Player_num].callsign[0] = '\0';
425 memcpy(gr_palette,title_pal,sizeof(gr_palette));
426 remap_fonts_and_menus(1);
427 RegisterPlayer(); //get player's name
432 //@@void check_joystick_calibration()
434 //@@ int x1, y1, x2, y2, c;
437 //@@ if ( (Config_control_type!=CONTROL_JOYSTICK) &&
438 //@@ (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
439 //@@ (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
440 //@@ (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
443 //@@ joy_get_pos( &x1, &y1 );
445 //@@ t1 = timer_get_fixed_seconds();
446 //@@ while( timer_get_fixed_seconds() < t1 + F1_0/100 )
449 //@@ joy_get_pos( &x2, &y2 );
451 //@@ // If joystick hasn't moved...
452 //@@ if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
453 //@@ if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
454 //@@ c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
456 //@@ joydefs_calibrate();
464 int find_descent_cd()
467 char oldpath[MAX_PATH];
476 GetCurrentDirectory(MAX_PATH, oldpath);
478 for (i = 0; i < 26; i++)
481 if (GetDriveType(path) == DRIVE_CDROM) {
483 GetVolumeInformation(path, volume, 256, NULL, NULL, NULL, NULL, 0);
484 mprintf((0, "CD volume: %s\n", volume));
485 if (!strcmpi(volume, "DESCENT_II") || !strcmpi(volume, "DESCENT.II")) {
487 if (!chdir("\\d2data")) {
495 SetCurrentDirectory(oldpath);
506 i = find_descent_cd();
511 if ((i=FindArg("-cdproxy")) != 0) {
512 strcpy(CDROM_dir,"d:\\d2data\\"); //set directory
513 CDROM_dir[0] = Args[i+1][0];
521 strcpy(CDROM_dir,"d:\\d2data\\"); //set directory
522 CDROM_dir[0] = 'A'+i; //set correct drive leter
523 mprintf((0, "Descent 2 CD-ROM: %s\n", CDROM_dir));
529 // ----------------------------------------------------------------------------
532 check_id_checksum_and_date()
534 const char name[sizeof(DESC_ID_TAG)-1+DESC_ID_LEN] = DESC_ID_TAG;
535 char time_str[] = DESC_DEAD_TIME_TAG "00000000"; //second part gets overwritten
537 unsigned long *checksum, test_checksum;
538 time_t current_time, saved_time;
540 saved_time = (time_t)strtol(time_str + strlen(DESC_DEAD_TIME_TAG), NULL, 16);
542 t_saved_time = saved_time;
544 if (saved_time == (time_t)0)
547 mprintf((1, "TIME STAMPED: %d\n", saved_time));
549 strcpy(name_copy,name+strlen(DESC_ID_TAG));
552 t_current_time = current_time = time(NULL);
554 mprintf((1, "CURTIME: %d\n", current_time));
556 if (current_time >= saved_time)
557 desc_id_exit_num = 1;
560 for (i = 0; i < strlen(name_copy); i++) {
562 test_checksum += name_copy[i];
563 if (((test_checksum / 2) * 2) != test_checksum)
565 test_checksum = test_checksum >> 1;
567 test_checksum |= 0x80000000;
569 checksum = (unsigned long *)(desc_id_checksum_str + strlen(DESC_ID_CHKSUM_TAG));
570 if (test_checksum != *checksum)
571 desc_id_exit_num = 2;
573 cprintf ("%s %s\n", TXT_REGISTRATION, name_copy);
577 // ----------------------------------------------------------------------------
578 // Nifty clipboard functions for placing a screen shot
579 // ----------------------------------------------------------------------------
581 extern HANDLE win95_dib_from_bitmap(HBITMAP hbm);
583 void win95_save_pcx_shot()
586 static int savenum = 0;
589 dd_grs_canvas *screen_canv = dd_grd_screencanv;
590 dd_grs_canvas *temp_canv_1, *save_canv; //*temp_canv_2,
594 char savename[FILENAME_LEN]; //NO STEREO savename2[FILENAME_LEN];
600 mprintf((0, "Screen shot!\n"));
603 save_canv = dd_grd_curcanv;
604 temp_canv_1 = dd_gr_create_canvas(screen_canv->canvas.cv_bitmap.bm_w,
605 screen_canv->canvas.cv_bitmap.bm_h);
607 dd_gr_blt_notrans(screen_canv, 0, 0, 0, 0, temp_canv_1, 0, 0, 0, 0);
609 /* Saved screen shot */
610 dd_gr_set_current_canvas(save_canv);
612 if ( savenum > 99 ) savenum = 0;
613 sprintf(savename,"screen%02d.pcx",savenum++);
614 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
616 dd_gr_set_current_canvas(NULL);
618 DDGRLOCK(dd_grd_curcanv);
620 save_font = grd_curcanv->cv_font;
621 gr_set_curfont(GAME_FONT);
622 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
623 gr_get_string_size(message,&w,&h,&aw);
625 x = (grd_curcanv->cv_w-w)/2;
626 y = (grd_curcanv->cv_h-h)/2;
628 gr_setcolor(gr_find_closest_color_current(0,0,0));
629 gr_rect(x-2,y-2,x+w+2,y+h+2);
630 gr_printf(x,y,message);
631 gr_set_curfont(save_font);
633 DDGRUNLOCK(dd_grd_curcanv);
635 if (GRMODEINFO(modex)) dd_gr_flip();
637 t1 = timer_get_fixed_seconds() + F1_0;
639 gr_palette_read(pal); //get actual palette from the hardware
641 DDGRLOCK(temp_canv_1);
642 pcx_write_bitmap(savename,&temp_canv_1->canvas.cv_bitmap,pal);
643 DDGRUNLOCK(temp_canv_1);
645 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
647 dd_gr_set_current_canvas(screen_canv);
649 dd_gr_blt_notrans(temp_canv_1, 0,0,0,0, dd_grd_curcanv, 0,0,0,0);
651 if (GRMODEINFO(modex)) dd_gr_flip();
653 dd_gr_free_canvas(temp_canv_1);
655 dd_gr_set_current_canvas(save_canv);
662 HANDLE hClipData = NULL;
664 BOOL clipboard_screenshot()
666 if (OpenClipboard(_hAppWnd)) {
668 SetClipboardData (CF_DIB ,clipboard_renderformat(CF_DIB));
669 SetClipboardData (CF_BITMAP ,clipboard_renderformat(CF_BITMAP));
670 SetClipboardData (CF_PALETTE ,clipboard_renderformat(CF_PALETTE));
678 HANDLE clipboard_renderformat(int cf)
687 // Create screen shot BBM
688 mprintf((1, "Creating DDB for clipboard.\n"));
689 hMem = win95_screen_shot();
690 if (!hMem) mprintf((1, "Unable to create clipboard object: CF_BITMAP\n"));
696 // Create DIB and all memory associated with it.
697 mprintf((1, "Creating DIB for clipboard.\n"));
698 hbm = win95_screen_shot();
699 hMem = win95_dib_from_bitmap(hbm);
700 if (!hMem) mprintf((1, "Unable to create clipboard object: CF_DIB\n"));
707 // Get current palette! (create a GDI palette from grpal)
712 mprintf((1, "Creating Palette for clipboard.\n"));
713 gr_palette_read(grpal);
714 lpal.version = 0x300;
715 lpal.num_entries = 256;
716 for (i = 0; i < 256; i++)
718 lpal.entries[i].peRed = grpal[i*3] << 2;
719 lpal.entries[i].peGreen = grpal[i*3+1] << 2;
720 lpal.entries[i].peBlue = grpal[i*3+2] << 2;
721 lpal.entries[i].peFlags = 0;
724 hMem = CreatePalette((LOGPALETTE*)&lpal);
725 if (!hMem) mprintf((1, "Unable to create clipboard object: CF_PALETTE\n"));