1 /* $Id: playsave.c,v 1.13 2003-06-06 19:04:27 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Functions to load & save player games
20 * Revision 1.1 1995/12/05 16:05:47 allender
23 * Revision 1.10 1995/11/03 12:53:24 allender
26 * Revision 1.9 1995/10/31 10:19:12 allender
29 * Revision 1.8 1995/10/23 14:50:11 allender
30 * set control type for new player *before* calling kc_set_controls
32 * Revision 1.7 1995/10/21 22:25:31 allender
33 * *** empty log message ***
35 * Revision 1.6 1995/10/17 15:57:42 allender
36 * removed line setting wrong COnfig_control_type
38 * Revision 1.5 1995/10/17 13:16:44 allender
39 * new controller support
41 * Revision 1.4 1995/08/24 16:03:38 allender
42 * call joystick code when player file uses joystick
44 * Revision 1.3 1995/08/03 15:15:39 allender
45 * got player save file working (more to go for shareware)
47 * Revision 1.2 1995/08/01 13:57:20 allender
48 * macified the player file stuff -- in a seperate folder
50 * Revision 1.1 1995/05/16 15:30:00 allender
53 * Revision 2.3 1995/05/26 16:16:23 john
54 * Split SATURN into define's for requiring cd, using cd, etc.
55 * Also started adding all the Rockwell stuff.
57 * Revision 2.2 1995/03/24 17:48:21 john
58 * Made player files from saturn excrement the highest level for
59 * normal descent levels.
61 * Revision 2.1 1995/03/21 14:38:49 john
62 * Ifdef'd out the NETWORK code.
64 * Revision 2.0 1995/02/27 11:27:59 john
65 * New version 2.0, which has no anonymous unions, builds with
66 * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
68 * Revision 1.57 1995/02/13 20:34:55 john
71 * Revision 1.56 1995/02/13 13:23:24 john
72 * Fixed bug with new player joystick selection.
74 * Revision 1.55 1995/02/13 12:01:19 john
75 * Fixed bug with joystick throttle still asking for
76 * calibration with new pilots.
78 * Revision 1.54 1995/02/13 10:29:12 john
79 * Fixed bug with creating new player not resetting everything to default.
81 * Revision 1.53 1995/02/03 10:58:46 john
82 * Added code to save shareware style saved games into new format...
83 * Also, made new player file format not have the saved game array in it.
85 * Revision 1.52 1995/02/02 21:09:28 matt
86 * Let player start of level 8 if he made it to level 7 in the shareware
88 * Revision 1.51 1995/02/02 18:50:14 john
89 * Added warning for FCS when new pilot chooses.
91 * Revision 1.50 1995/02/02 11:21:34 john
92 * Made joystick calibrate when new user selects.
94 * Revision 1.49 1995/02/01 18:06:38 rob
95 * Put defaults macros into descent.tex
97 * Revision 1.48 1995/01/25 14:37:53 john
98 * Made joystick only prompt for calibration once...
100 * Revision 1.47 1995/01/24 19:37:12 matt
101 * Took out incorrect mprintf
103 * Revision 1.46 1995/01/22 18:57:22 matt
104 * Made player highest level work with missions
106 * Revision 1.45 1995/01/21 16:36:05 matt
107 * Made starting level system work for now, pending integration with
110 * Revision 1.44 1995/01/20 22:47:32 matt
111 * Mission system implemented, though imcompletely
113 * Revision 1.43 1995/01/04 14:58:39 rob
114 * Fixed for shareware build.
116 * Revision 1.42 1995/01/04 11:36:43 rob
117 * Added compatibility with older shareware pilot files.
119 * Revision 1.41 1995/01/03 11:01:58 rob
120 * fixed a default macro.
122 * Revision 1.40 1995/01/03 10:44:06 rob
123 * Added default taunt macros.
125 * Revision 1.39 1994/12/13 10:01:16 allender
126 * pop up message box when unable to correctly save player file
128 * Revision 1.38 1994/12/12 11:37:14 matt
129 * Fixed auto leveling defaults & saving
131 * Revision 1.37 1994/12/12 00:26:59 matt
132 * Added support for no-levelling option
134 * Revision 1.36 1994/12/10 19:09:54 matt
135 * Added assert for valid player number when loading game
137 * Revision 1.35 1994/12/08 10:53:07 rob
138 * Fixed a bug in highest_level tracking.
140 * Revision 1.34 1994/12/08 10:01:36 john
141 * Changed the way the player callsign stuff works.
143 * Revision 1.33 1994/12/07 18:30:38 rob
144 * Load highest level along with player (used to be only if higher)
145 * Capped at LAST_LEVEL in case a person loads a registered player in shareware.
147 * Revision 1.32 1994/12/03 16:01:12 matt
148 * When player file has bad version, force player to choose another
150 * Revision 1.31 1994/12/02 19:54:00 yuan
153 * Revision 1.30 1994/12/02 11:01:36 yuan
156 * Revision 1.29 1994/11/29 03:46:28 john
157 * Added joystick sensitivity; Added sound channels to detail menu. Removed -maxchannels
160 * Revision 1.28 1994/11/29 01:10:23 john
161 * Took out code that allowed new players to
162 * configure keyboard.
164 * Revision 1.27 1994/11/25 22:47:10 matt
165 * Made saved game descriptions longer
167 * Revision 1.26 1994/11/22 12:10:42 rob
168 * Fixed file handle left open if player file versions don't
171 * Revision 1.25 1994/11/21 19:35:30 john
172 * Replaced calls to joy_init with if (joy_present)
174 * Revision 1.24 1994/11/21 17:29:34 matt
175 * Cleaned up sequencing & game saving for secret levels
177 * Revision 1.23 1994/11/21 11:10:01 john
178 * Fixed bug with read-only .plr file making the config file
181 * Revision 1.22 1994/11/20 19:03:08 john
182 * Fixed bug with if not having a joystick, default
183 * player input device is cyberman.
185 * Revision 1.21 1994/11/17 12:24:07 matt
186 * Made an array the right size, to fix error loading games
188 * Revision 1.20 1994/11/14 17:52:54 allender
189 * add call to WriteConfigFile when player files gets written
191 * Revision 1.19 1994/11/14 17:19:23 rob
192 * Removed gamma, joystick calibration, and sound settings from player file.
193 * Added default difficulty and multi macros.
195 * Revision 1.18 1994/11/07 14:01:23 john
196 * Changed the gamma correction sequencing.
198 * Revision 1.17 1994/11/05 17:22:49 john
199 * Fixed lots of sequencing problems with newdemo stuff.
201 * Revision 1.16 1994/11/01 16:40:11 john
202 * Added Gamma correction.
204 * Revision 1.15 1994/10/24 19:56:50 john
205 * Made the new user setup prompt for config options.
207 * Revision 1.14 1994/10/24 17:44:21 john
208 * Added stereo channel reversing.
210 * Revision 1.13 1994/10/24 16:05:12 matt
211 * Improved handling of player names that are the names of DOS devices
213 * Revision 1.12 1994/10/22 00:08:51 matt
214 * Fixed up problems with bonus & game sequencing
215 * Player doesn't get credit for hostages unless he gets them out alive
217 * Revision 1.11 1994/10/19 19:59:57 john
218 * Added bonus points at the end of level based on skill level.
220 * Revision 1.10 1994/10/19 15:14:34 john
221 * Took % hits out of player structure, made %kills work properly.
223 * Revision 1.9 1994/10/19 12:44:26 john
224 * Added hours field to player structure.
226 * Revision 1.8 1994/10/17 17:24:34 john
227 * Added starting_level to player struct.
229 * Revision 1.7 1994/10/17 13:07:15 john
230 * Moved the descent.cfg info into the player config file.
232 * Revision 1.6 1994/10/09 14:54:31 matt
233 * Made player cockpit state & window size save/restore with saved games & automap
235 * Revision 1.5 1994/10/08 23:08:09 matt
236 * Added error check & handling for game load/save disk io
238 * Revision 1.4 1994/10/05 17:40:54 rob
239 * Bumped save_file_version to 5 due to change in player.h
241 * Revision 1.3 1994/10/03 23:00:54 matt
242 * New file version for shorter callsigns
244 * Revision 1.2 1994/09/28 17:25:05 matt
245 * Added first draft of game save/load system
247 * Revision 1.1 1994/09/27 14:39:12 matt
258 #include <mmsystem.h>
268 #include "pa_enabl.h"
273 #include "playsave.h"
290 #include "byteswap.h"
291 #include "fileutil.h"
294 #define SAVE_FILE_ID MAKE_SIG('D','P','L','R')
298 #include <Errors.h> // mac doesn't have "normal" error numbers -- must use mac equivs
300 #define ENOENT fnfErr
303 #include "poly_acc.h"
308 int get_lifetime_checksum (int a,int b);
315 short n_highest_levels;
317 hli highest_levels[MAX_MISSIONS];
319 #define PLAYER_FILE_VERSION 25 //increment this every time the player file changes
321 //version 5 -> 6: added new highest level information
322 //version 6 -> 7: stripped out the old saved_game array.
323 //version 7 -> 8: added reticle flag, & window size
324 //version 8 -> 9: removed player_struct_version
325 //version 9 -> 10: added default display mode
326 //version 10 -> 11: added all toggles in toggle menu
327 //version 11 -> 12: added weapon ordering
328 //version 12 -> 13: added more keys
329 //version 13 -> 14: took out marker key
330 //version 14 -> 15: added guided in big window
331 //version 15 -> 16: added small windows in cockpit
332 //version 16 -> 17: ??
333 //version 17 -> 18: save guidebot name
334 //version 18 -> 19: added automap-highres flag
335 //version 19 -> 20: added kconfig data for windows joysticks
336 //version 20 -> 21: save seperate config types for DOS & Windows
337 //version 21 -> 22: save lifetime netstats
338 //version 22 -> 23: ??
339 //version 23 -> 24: add name of joystick for windows version.
340 //version 24 -> 25: add d2x keys array
342 #define COMPATIBLE_PLAYER_FILE_VERSION 17
345 int Default_leveling_on=1;
346 extern ubyte SecondaryOrder[],PrimaryOrder[];
347 extern void InitWeaponOrdering();
350 extern ubyte default_firebird_settings[];
351 extern ubyte default_mousestick_settings[];
354 int new_player_config()
357 int i,j,control_choice;
359 int mct=CONTROL_MAX_TYPES;
365 InitWeaponOrdering (); //setup default weapon priorities
367 #if defined(MACINTOSH) && defined(USE_ISP)
372 #if !defined(MACINTOSH) && !defined(WINDOWS)
373 for (i=0; i<mct; i++ ) {
374 m[i].type = NM_TYPE_MENU; m[i].text = CONTROL_TEXT(i);
376 #elif defined(WINDOWS)
377 m[0].type = NM_TYPE_MENU; m[0].text = CONTROL_TEXT(0);
378 m[1].type = NM_TYPE_MENU; m[1].text = CONTROL_TEXT(5);
379 m[2].type = NM_TYPE_MENU; m[2].text = CONTROL_TEXT(7);
382 for (i = 0; i < 6; i++) {
383 m[i].type = NM_TYPE_MENU; m[i].text = CONTROL_TEXT(i);
385 m[4].text = "Gravis Firebird/Mousetick II";
386 m[3].text = "Thrustmaster";
390 m[0].text = TXT_CONTROL_KEYBOARD;
393 if (Config_control_type==CONTROL_NONE) control_choice = 0;
394 else if (Config_control_type == CONTROL_MOUSE) control_choice = 1;
395 else if (Config_control_type == CONTROL_WINJOYSTICK) control_choice = 2;
396 else control_choice = 0;
398 control_choice = Config_control_type; // Assume keyboard
402 control_choice = newmenu_do1( NULL, TXT_CHOOSE_INPUT, i, m, NULL, control_choice );
407 if ( control_choice < 0 )
410 #if defined(MACINTOSH) && defined(USE_ISP)
412 else // !!!!NOTE ... link to above if (!ISpEnabled()), this is a really crappy function
418 for (i=0;i<CONTROL_MAX_TYPES; i++ )
419 for (j=0;j<MAX_CONTROLS; j++ )
420 kconfig_settings[i][j] = default_kconfig_settings[i][j];
421 //added on 2/4/99 by Victor Rachels for new keys
422 for(i=0; i < MAX_D2X_CONTROLS; i++)
423 kconfig_d2x_settings[i] = default_kconfig_d2x_settings[i];
424 //end this section addition - VR
427 Config_control_type = control_choice;
430 if (control_choice == 1) Config_control_type = CONTROL_MOUSE;
431 else if (control_choice == 2) Config_control_type = CONTROL_WINJOYSTICK;
433 // if (Config_control_type == CONTROL_WINJOYSTICK)
434 // joydefs_calibrate();
437 if ( Config_control_type==CONTROL_THRUSTMASTER_FCS) {
438 i = nm_messagebox( TXT_IMPORTANT_NOTE, 2, "Choose another", TXT_OK, TXT_FCS );
439 if (i==0) goto RetrySelection;
442 if ( (Config_control_type>0) && (Config_control_type<5)) {
445 #else // some macintosh only stuff here
446 if ( Config_control_type==CONTROL_THRUSTMASTER_FCS) {
447 extern char *tm_warning;
449 i = nm_messagebox( TXT_IMPORTANT_NOTE, 2, "Choose another", TXT_OK, tm_warning );
450 if (i==0) goto RetrySelection;
451 } else if ( Config_control_type==CONTROL_FLIGHTSTICK_PRO ) {
452 extern char *ch_warning;
454 i = nm_messagebox( TXT_IMPORTANT_NOTE, 2, "Choose another", TXT_OK, ch_warning );
455 if (i==0) goto RetrySelection;
456 } else if ( Config_control_type==CONTROL_GRAVIS_GAMEPAD ) {
457 extern char *ms_warning;
459 i = nm_messagebox( TXT_IMPORTANT_NOTE, 2, "Choose another", TXT_OK, ms_warning );
460 if (i==0) goto RetrySelection;
461 // stupid me -- get real default setting for either mousestick or firebird
462 joydefs_set_type( Config_control_type );
463 if (joy_have_firebird())
464 for (i=0; i<NUM_OTHER_CONTROLS; i++ )
465 kconfig_settings[Config_control_type][i] = default_firebird_settings[i];
467 for (i=0; i<NUM_OTHER_CONTROLS; i++ )
468 kconfig_settings[Config_control_type][i] = default_mousestick_settings[i];
469 kc_set_controls(); // reset the joystick control
471 if ( (Config_control_type>0) && (Config_control_type<5) ) {
472 joydefs_set_type( Config_control_type );
479 Player_default_difficulty = 1;
480 Auto_leveling_on = Default_leveling_on = 1;
481 n_highest_levels = 1;
482 highest_levels[0].shortname[0] = 0; //no name for mission 0
483 highest_levels[0].level_num = 1; //was highest level in old struct
484 Config_joystick_sensitivity = 8;
485 Cockpit_3d_view[0]=CV_NONE;
486 Cockpit_3d_view[1]=CV_NONE;
488 // Default taunt macros
490 strcpy(Network_message_macro[0], "Why can't we all just get along?");
491 strcpy(Network_message_macro[1], "Hey, I got a present for ya");
492 strcpy(Network_message_macro[2], "I got a hankerin' for a spankerin'");
493 strcpy(Network_message_macro[3], "This one's headed for Uranus");
494 Netlife_kills=0; Netlife_killed=0;
501 Scanline_double = 0; // no pixel doubling for poly_acc
505 Scanline_double = 1; // should be default for new player
508 Scanline_double = 1; // should be default for new player
515 extern int Guided_in_big_window,Automap_always_hires;
517 //this length must match the value in escort.c
518 #define GUIDEBOT_NAME_LEN 9
519 extern char guidebot_name[];
520 extern char real_guidebot_name[];
522 WIN(extern char win95_current_joyname[]);
524 ubyte control_type_dos,control_type_win;
526 //read in the player's saved games. returns errno (0 == no error)
527 int read_player_file()
530 char filename[FILENAME_LEN+15];
532 char filename[FILENAME_LEN];
535 int errno_ret = EZERO;
537 short player_file_version;
541 Assert(Player_num>=0 && Player_num<MAX_PLAYERS);
544 sprintf(filename,"%.8s.plr",Players[Player_num].callsign);
546 sprintf(filename, ":Players:%.8s.plr",Players[Player_num].callsign);
548 file = fopen(filename,"rb");
552 if (file && isatty(fileno(file))) {
553 //if the callsign is the name of a tty device, prepend a char
555 sprintf(filename,"$%.7s.plr",Players[Player_num].callsign);
556 file = fopen(filename,"rb");
564 id = file_read_int(file);
566 // SWAPINT added here because old versions of d2x
567 // used the wrong byte order.
568 if (id!=SAVE_FILE_ID && id!=SWAPINT(SAVE_FILE_ID)) {
569 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Invalid player file");
574 player_file_version = file_read_short(file);
576 if (player_file_version > 255) // bigendian file?
580 player_file_version = SWAPSHORT(player_file_version);
582 if (player_file_version<COMPATIBLE_PLAYER_FILE_VERSION) {
583 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_ERROR_PLR_VERSION);
588 Game_window_w = file_read_short(file);
589 Game_window_h = file_read_short(file);
592 Game_window_w = SWAPSHORT(Game_window_w);
593 Game_window_h = SWAPSHORT(Game_window_h);
596 Player_default_difficulty = file_read_byte(file);
597 Default_leveling_on = file_read_byte(file);
598 Reticle_on = file_read_byte(file);
599 Cockpit_mode = file_read_byte(file);
601 #ifdef PA_3DFX_VOODOO
611 Default_display_mode = file_read_byte(file);
612 Missile_view_enabled = file_read_byte(file);
613 Headlight_active_default = file_read_byte(file);
614 Guided_in_big_window = file_read_byte(file);
616 if (player_file_version >= 19)
617 Automap_always_hires = file_read_byte(file);
619 Auto_leveling_on = Default_leveling_on;
621 //read new highest level info
623 n_highest_levels = file_read_short(file);
625 n_highest_levels = SWAPSHORT(n_highest_levels);
627 if (fread(highest_levels,sizeof(hli),n_highest_levels,file) != n_highest_levels) {
638 len = MAX_MESSAGE_LEN;
640 for (i = 0; i < 4; i++)
641 if (fread(Network_message_macro[i], len, 1, file) != 1)
642 {errno_ret = errno; break;}
644 char dummy[4][MAX_MESSAGE_LEN];
645 fread(dummy, MAX_MESSAGE_LEN, 4, file);
652 int n_control_types = (player_file_version<20)?7:CONTROL_MAX_TYPES;
654 if (fread( kconfig_settings, MAX_CONTROLS*n_control_types, 1, file )!=1)
656 else if (fread((ubyte *)&control_type_dos, sizeof(ubyte), 1, file )!=1)
658 else if (player_file_version >= 21 && fread((ubyte *)&control_type_win, sizeof(ubyte), 1, file )!=1)
660 else if (fread(&Config_joystick_sensitivity, sizeof(ubyte), 1, file )!=1)
664 Config_control_type = control_type_win;
666 Config_control_type = control_type_dos;
670 joydefs_set_type(Config_control_type);
675 PrimaryOrder[i]=file_read_byte (file);
676 SecondaryOrder[i]=file_read_byte(file);
679 if (player_file_version>=16)
681 Cockpit_3d_view[0]=file_read_int(file);
682 Cockpit_3d_view[1]=file_read_int(file);
684 Cockpit_3d_view[0] = SWAPINT(Cockpit_3d_view[0]);
685 Cockpit_3d_view[1] = SWAPINT(Cockpit_3d_view[1]);
690 if (errno_ret==EZERO) {
696 if (player_file_version>=22)
699 Netlife_kills=file_read_int (file);
700 Netlife_killed=file_read_int (file);
702 Netlife_kills = SWAPINT(Netlife_kills);
703 Netlife_killed = SWAPINT(Netlife_killed);
706 file_read_int(file); file_read_int(file);
712 Netlife_kills=0; Netlife_killed=0;
716 if (player_file_version>=23)
718 i=file_read_int (file);
722 mprintf ((0,"Reading: lifetime checksum is %d\n",i));
723 if (i!=get_lifetime_checksum (Netlife_kills,Netlife_killed))
725 Netlife_kills=0; Netlife_killed=0;
726 nm_messagebox(NULL, 1, "Shame on me", "Trying to cheat eh?");
733 if (player_file_version >= 18)
734 file_read_string(guidebot_name,file);
736 strcpy(guidebot_name,"GUIDE-BOT");
738 strcpy(real_guidebot_name,guidebot_name);
744 joy95_get_name(JOYSTICKID1, buf, 127);
745 if (player_file_version >= 24)
746 file_read_string(win95_current_joyname, file);
748 strcpy(win95_current_joyname, "Old Player File");
750 mprintf((0, "Detected joystick: %s\n", buf));
751 mprintf((0, "Player's joystick: %s\n", win95_current_joyname));
753 if (strcmp(win95_current_joyname, buf)) {
754 for (i = 0; i < MAX_CONTROLS; i++)
755 kconfig_settings[CONTROL_WINJOYSTICK][i] =
756 default_kconfig_settings[CONTROL_WINJOYSTICK][i];
759 if (player_file_version >= 24)
760 file_read_string(buf, file); // Just read it in fpr DPS.
764 if (player_file_version >= 25)
765 fread(kconfig_d2x_settings, MAX_D2X_CONTROLS, 1, file);
767 for(i=0; i < MAX_D2X_CONTROLS; i++)
768 kconfig_d2x_settings[i] = default_kconfig_d2x_settings[i];
770 if (fclose(file) && errno_ret==EZERO)
781 //finds entry for this level in table. if not found, returns ptr to
782 //empty entry. If no empty entries, takes over last one
787 for (i=0;i<n_highest_levels;i++)
788 if (!stricmp(highest_levels[i].shortname,Mission_list[Current_mission_num].filename))
791 if (i==n_highest_levels) { //not found. create entry
794 i--; //take last entry
798 strcpy(highest_levels[i].shortname,Mission_list[Current_mission_num].filename);
799 highest_levels[i].level_num = 0;
805 //set a new highest level for player for this mission
806 void set_highest_level(int levelnum)
810 if ((ret=read_player_file()) != EZERO)
811 if (ret != ENOENT) //if file doesn't exist, that's ok
814 i = find_hli_entry();
816 if (levelnum > highest_levels[i].level_num)
817 highest_levels[i].level_num = levelnum;
822 //gets the player's highest level from the file for this mission
823 int get_highest_level(void)
826 int highest_saturn_level = 0;
829 if (strlen(Mission_list[Current_mission_num].filename)==0 ) {
830 for (i=0;i<n_highest_levels;i++)
831 if (!stricmp(highest_levels[i].shortname, "DESTSAT")) // Destination Saturn.
832 highest_saturn_level = highest_levels[i].level_num;
835 i = highest_levels[find_hli_entry()].level_num;
836 if ( highest_saturn_level > i )
837 i = highest_saturn_level;
841 extern int Cockpit_mode_save;
843 //write out player's saved games. returns errno (0 == no error)
844 int write_player_file()
847 char filename[FILENAME_LEN+15];
849 char filename[FILENAME_LEN]; // because of ":Players:" path
854 // #ifdef APPLE_DEMO // no saving of player files in Apple OEM version
858 errno_ret = WriteConfigFile();
861 sprintf(filename,"%s.plr",Players[Player_num].callsign);
863 sprintf(filename, ":Players:%.8s.plr",Players[Player_num].callsign);
865 file = fopen(filename,"wb");
869 if (file && isatty(fileno(file))) {
871 //if the callsign is the name of a tty device, prepend a char
874 sprintf(filename,"$%.7s.plr",Players[Player_num].callsign);
875 file = fopen(filename,"wb");
884 //Write out player's info
885 file_write_int(SAVE_FILE_ID,file);
886 file_write_short(PLAYER_FILE_VERSION,file);
888 file_write_short(Game_window_w,file);
889 file_write_short(Game_window_h,file);
891 file_write_byte(Player_default_difficulty,file);
892 file_write_byte(Auto_leveling_on,file);
893 file_write_byte(Reticle_on,file);
894 file_write_byte((Cockpit_mode_save!=-1)?Cockpit_mode_save:Cockpit_mode,file); //if have saved mode, write it instead of letterbox/rear view
895 file_write_byte(Default_display_mode,file);
896 file_write_byte(Missile_view_enabled,file);
897 file_write_byte(Headlight_active_default,file);
898 file_write_byte(Guided_in_big_window,file);
899 file_write_byte(Automap_always_hires,file);
901 //write higest level info
902 file_write_short(n_highest_levels,file);
903 if ((fwrite(highest_levels, sizeof(hli), n_highest_levels, file) != n_highest_levels)) {
910 if ((fwrite(Network_message_macro, MAX_MESSAGE_LEN, 4, file) != 4)) {
916 fseek( file, MAX_MESSAGE_LEN * 4, SEEK_CUR );
923 control_type_win = Config_control_type;
925 control_type_dos = Config_control_type;
928 if (fwrite( kconfig_settings, MAX_CONTROLS*CONTROL_MAX_TYPES, 1, file )!=1)
930 else if (fwrite( &control_type_dos, sizeof(ubyte), 1, file )!=1)
932 else if (fwrite( &control_type_win, sizeof(ubyte), 1, file )!=1)
934 else if (fwrite( &Config_joystick_sensitivity, sizeof(ubyte), 1, file )!=1)
939 fwrite (&PrimaryOrder[i],sizeof(ubyte),1,file);
940 fwrite (&SecondaryOrder[i],sizeof(ubyte),1,file);
943 file_write_int (Cockpit_3d_view[0],file);
944 file_write_int (Cockpit_3d_view[1],file);
947 file_write_int (Netlife_kills,file);
948 file_write_int (Netlife_killed,file);
949 i=get_lifetime_checksum (Netlife_kills,Netlife_killed);
950 mprintf ((0,"Writing: Lifetime checksum is %d\n",i));
952 file_write_int(0, file);
953 file_write_int(0, file);
954 i = get_lifetime_checksum (0, 0);
956 file_write_int (i,file);
959 //write guidebot name
960 file_write_string(real_guidebot_name,file);
965 joy95_get_name(JOYSTICKID1, buf, 127);
967 strcpy(buf, "DOS joystick");
969 file_write_string(buf, file); // Write out current joystick for player.
972 fwrite(kconfig_d2x_settings, MAX_D2X_CONTROLS, 1, file);
977 if (errno_ret != EZERO) {
978 remove(filename); //delete bogus file
979 nm_messagebox(TXT_ERROR, 1, TXT_OK, "%s\n\n%s",TXT_ERROR_WRITING_PLR, strerror(errno_ret));
982 #ifdef MACINTOSH // set filetype and creator for playerfile
988 strcpy(pfilename, filename);
990 err = HGetFInfo(0, 0, pfilename, &finfo);
991 finfo.fdType = 'PLYR';
992 finfo.fdCreator = 'DCT2';
993 err = HSetFInfo(0, 0, pfilename, &finfo);
1001 //update the player's highest level. returns errno (0 == no error)
1002 int update_player_file()
1006 if ((ret=read_player_file()) != EZERO)
1007 if (ret != ENOENT) //if file doesn't exist, that's ok
1010 return write_player_file();
1013 int get_lifetime_checksum (int a,int b)
1017 // confusing enough to beat amateur disassemblers? Lets hope so