]> icculus.org git repositories - btb/d2x.git/blob - main/playsave.c
remove control_type_win
[btb/d2x.git] / main / playsave.c
1 /*
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.
12 */
13
14 /*
15  *
16  * Functions to load & save player's settings (*.plr file)
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include <conf.h>
22 #endif
23
24 #ifdef WINDOWS
25 #include "desw.h"
26 #include <mmsystem.h>
27 #endif
28
29 #include <stdio.h>
30 #include <string.h>
31 #if !defined(_MSC_VER) && !defined(macintosh)
32 #include <unistd.h>
33 #endif
34 #ifndef _WIN32_WCE
35 #include <errno.h>
36 #endif
37
38 #include <physfs.h>
39
40 #include "error.h"
41
42 #include "strutil.h"
43 #include "game.h"
44 #include "gameseq.h"
45 #include "player.h"
46 #include "playsave.h"
47 #include "joy.h"
48 #include "kconfig.h"
49 #include "digi.h"
50 #include "newmenu.h"
51 #include "joydefs.h"
52 #include "palette.h"
53 #include "multi.h"
54 #include "menu.h"
55 #include "config.h"
56 #include "text.h"
57 #include "mono.h"
58 #include "state.h"
59 #include "gauges.h"
60 #include "screens.h"
61 #include "powerup.h"
62 #include "makesig.h"
63 #include "byteswap.h"
64 #include "escort.h"
65
66 #include "physfsx.h"
67
68 #define SAVE_FILE_ID                    MAKE_SIG('D','P','L','R')
69
70 #ifdef MACINTOSH
71         #include <Files.h>
72         #include <Errors.h>                     // mac doesn't have "normal" error numbers -- must use mac equivs
73         #ifndef ENOENT
74                 #define ENOENT fnfErr
75         #endif
76         #include "isp.h"
77 #elif defined(_WIN32_WCE)
78 # define errno -1
79 # define ENOENT -1
80 # define strerror(x) "Unknown Error"
81 #endif
82
83 int get_lifetime_checksum (int a,int b);
84
85 typedef struct hli {
86         char    shortname[9];
87         ubyte   level_num;
88 } hli;
89
90 short n_highest_levels;
91
92 hli highest_levels[MAX_MISSIONS];
93
94 #define PLAYER_FILE_VERSION     25 //increment this every time the player file changes
95
96 //version 5  ->  6: added new highest level information
97 //version 6  ->  7: stripped out the old saved_game array.
98 //version 7  ->  8: added reticle flag, & window size
99 //version 8  ->  9: removed player_struct_version
100 //version 9  -> 10: added default display mode
101 //version 10 -> 11: added all toggles in toggle menu
102 //version 11 -> 12: added weapon ordering
103 //version 12 -> 13: added more keys
104 //version 13 -> 14: took out marker key
105 //version 14 -> 15: added guided in big window
106 //version 15 -> 16: added small windows in cockpit
107 //version 16 -> 17: ??
108 //version 17 -> 18: save guidebot name
109 //version 18 -> 19: added automap-highres flag
110 //version 19 -> 20: added kconfig data for windows joysticks
111 //version 20 -> 21: save seperate config types for DOS & Windows
112 //version 21 -> 22: save lifetime netstats 
113 //version 22 -> 23: ??
114 //version 23 -> 24: add name of joystick for windows version.
115 //version 24 -> 25: removed kconfig data
116
117 #define COMPATIBLE_PLAYER_FILE_VERSION          17
118
119
120 int Default_leveling_on=1;
121 extern ubyte SecondaryOrder[],PrimaryOrder[];
122 extern void InitWeaponOrdering();
123
124 #ifdef MACINTOSH
125 extern ubyte default_firebird_settings[];
126 extern ubyte default_mousestick_settings[];
127 #endif
128
129 int new_player_config()
130 {
131         int nitems;
132         int i,j,control_choice;
133         newmenu_item m[8];
134    int mct=CONTROL_MAX_TYPES;
135  
136    #ifndef WINDOWS
137          mct--;
138         #endif
139
140    InitWeaponOrdering ();               //setup default weapon priorities 
141
142 #if defined(MACINTOSH) && defined(USE_ISP)
143         if (!ISpEnabled())
144         {
145 #endif
146 RetrySelection:
147                 #if !defined(MACINTOSH)
148                 for (i=0; i<mct; i++ )  {
149                         m[i].type = NM_TYPE_MENU; m[i].text = CONTROL_TEXT(i);
150                 }
151                 #else
152                 for (i = 0; i < 6; i++) {
153                         m[i].type = NM_TYPE_MENU; m[i].text = CONTROL_TEXT(i);
154                 }
155                 m[4].text = "Gravis Firebird/Mousetick II";
156                 m[3].text = "Thrustmaster";
157                 #endif
158                 
159                 nitems = i;
160                 m[0].text = TXT_CONTROL_KEYBOARD;
161         
162                         control_choice = Config_control_type;                           // Assume keyboard
163         
164                 #ifndef APPLE_DEMO
165                         control_choice = newmenu_do1( NULL, TXT_CHOOSE_INPUT, i, m, NULL, control_choice );
166                 #else
167                         control_choice = 0;
168                 #endif
169                 
170                 if ( control_choice < 0 )
171                         return 0;
172
173 #if defined(MACINTOSH) && defined(USE_ISP)
174         }
175         else    // !!!!NOTE ... link to above if (!ISpEnabled()), this is a really crappy function
176         {
177                 control_choice = 0;
178         }
179 #endif
180
181         kc_set_controls();
182
183         Config_control_type = control_choice;
184
185         #ifndef MACINTOSH
186         if ( Config_control_type==CONTROL_THRUSTMASTER_FCS)     {
187                 i = nm_messagebox( TXT_IMPORTANT_NOTE, 2, "Choose another", TXT_OK, TXT_FCS );
188                 if (i==0) goto RetrySelection;
189         }
190         
191         if ( (Config_control_type>0) &&         (Config_control_type<5))        {
192                 joydefs_calibrate();
193         }
194         #else           // some macintosh only stuff here
195         if ( Config_control_type==CONTROL_THRUSTMASTER_FCS)     {
196                 extern char *tm_warning;
197                 
198                 i = nm_messagebox( TXT_IMPORTANT_NOTE, 2, "Choose another", TXT_OK, tm_warning );
199                 if (i==0) goto RetrySelection;
200         } else  if ( Config_control_type==CONTROL_FLIGHTSTICK_PRO )     {
201                 extern char *ch_warning;
202
203                 i = nm_messagebox( TXT_IMPORTANT_NOTE, 2, "Choose another", TXT_OK, ch_warning );
204                 if (i==0) goto RetrySelection;
205         } else  if ( Config_control_type==CONTROL_GRAVIS_GAMEPAD )      {
206                 extern char *ms_warning;
207
208                 i = nm_messagebox( TXT_IMPORTANT_NOTE, 2, "Choose another", TXT_OK, ms_warning );
209                 if (i==0) goto RetrySelection;
210                 // stupid me -- get real default setting for either mousestick or firebird
211                 joydefs_set_type( Config_control_type );
212                 if (joy_have_firebird())
213                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )
214                                 kconfig_settings[Config_control_type][i] = default_firebird_settings[i];
215                 else
216                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )
217                                 kconfig_settings[Config_control_type][i] = default_mousestick_settings[i];
218                 kc_set_controls();              // reset the joystick control
219         }
220         if ( (Config_control_type>0) && (Config_control_type<5)  ) {
221                 joydefs_set_type( Config_control_type );
222                 joydefs_calibrate();
223         }
224
225         #endif
226         
227         Player_default_difficulty = 1;
228         Auto_leveling_on = Default_leveling_on = 1;
229         n_highest_levels = 1;
230         highest_levels[0].shortname[0] = 0;                     //no name for mission 0
231         highest_levels[0].level_num = 1;                                //was highest level in old struct
232         Config_joystick_sensitivity = 8;
233         Cockpit_3d_view[0]=CV_NONE;
234         Cockpit_3d_view[1]=CV_NONE;
235
236         // Default taunt macros
237         #ifdef NETWORK
238         strcpy(Network_message_macro[0], "Why can't we all just get along?");
239         strcpy(Network_message_macro[1], "Hey, I got a present for ya");
240         strcpy(Network_message_macro[2], "I got a hankerin' for a spankerin'");
241         strcpy(Network_message_macro[3], "This one's headed for Uranus");
242         Netlife_kills=0; Netlife_killed=0;      
243         #endif
244         
245         return 1;
246 }
247
248 extern int Guided_in_big_window,Automap_always_hires;
249
250 //this length must match the value in escort.c
251 #define GUIDEBOT_NAME_LEN 9
252 extern char guidebot_name[];
253 extern char real_guidebot_name[];
254
255
256 uint32_t legacy_display_mode[] = { SM(320,200), SM(640,480), SM(320,400), SM(640,400), SM(800,600), SM(1024,768), SM(1280,1024) };
257
258 //read in the player's saved games.  returns errno (0 == no error)
259 int read_player_file()
260 {
261         #ifdef MACINTOSH
262         char filename[FILENAME_LEN+15];
263         #else
264         char filename[FILENAME_LEN];
265         #endif
266         PHYSFS_file *file;
267         int id, i;
268         short player_file_version;
269         int rewrite_it=0;
270         int swap = 0;
271
272         Assert(Player_num>=0 && Player_num<MAX_PLAYERS);
273
274         sprintf(filename, PLAYER_DIR "%.8s.plr", Players[Player_num].callsign);
275
276         if (!PHYSFS_exists(filename))
277                 return ENOENT;
278
279         file = PHYSFSX_openReadBuffered(filename);
280
281 #if 0
282 #ifndef MACINTOSH
283         //check filename
284         if (file && isatty(fileno(file))) {
285                 //if the callsign is the name of a tty device, prepend a char
286                 PHYSFS_close(file);
287                 sprintf(filename, PLAYER_DIR "$%.7s.plr",Players[Player_num].callsign);
288                 file = PHYSFSX_openReadBuffered(filename);
289         }
290 #endif
291 #endif
292
293         if (!file)
294                 goto read_player_file_failed;
295
296         PHYSFS_readSLE32(file, &id);
297
298         // SWAPINT added here because old versions of d2x
299         // used the wrong byte order.
300         if (id!=SAVE_FILE_ID && id!=SWAPINT(SAVE_FILE_ID)) {
301                 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Invalid player file");
302                 PHYSFS_close(file);
303                 return -1;
304         }
305
306         player_file_version = cfile_read_short(file);
307
308         if (player_file_version > 255) // bigendian file?
309                 swap = 1;
310
311         if (swap)
312                 player_file_version = SWAPSHORT(player_file_version);
313
314         if (player_file_version<COMPATIBLE_PLAYER_FILE_VERSION) {
315                 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_ERROR_PLR_VERSION);
316                 PHYSFS_close(file);
317                 return -1;
318         }
319
320         Game_window_w = cfile_read_short(file);
321         Game_window_h = cfile_read_short(file);
322
323         if (swap) {
324                 Game_window_w = SWAPSHORT(Game_window_w);
325                 Game_window_h = SWAPSHORT(Game_window_h);
326         }
327
328         Player_default_difficulty = cfile_read_byte(file);
329         Default_leveling_on       = cfile_read_byte(file);
330         Reticle_on                = cfile_read_byte(file);
331         Cockpit_mode              = cfile_read_byte(file);
332
333         i                         = cfile_read_byte(file);
334         Default_display_mode = legacy_display_mode[i];
335
336         Missile_view_enabled      = cfile_read_byte(file);
337         Headlight_active_default  = cfile_read_byte(file);
338         Guided_in_big_window      = cfile_read_byte(file);
339                 
340         if (player_file_version >= 19)
341                 Automap_always_hires = cfile_read_byte(file);
342
343         Auto_leveling_on = Default_leveling_on;
344
345         //read new highest level info
346
347         n_highest_levels = cfile_read_short(file);
348         if (swap)
349                 n_highest_levels = SWAPSHORT(n_highest_levels);
350         Assert(n_highest_levels <= MAX_MISSIONS);
351
352         if (PHYSFS_read(file, highest_levels, sizeof(hli), n_highest_levels) != n_highest_levels)
353                 goto read_player_file_failed;
354
355         //read taunt macros
356         {
357 #ifdef NETWORK
358                 int i,len;
359
360                 len = MAX_MESSAGE_LEN;
361
362                 for (i = 0; i < 4; i++)
363                         if (PHYSFS_read(file, Network_message_macro[i], len, 1) != 1)
364                                 goto read_player_file_failed;
365 #else
366                 char dummy[4][MAX_MESSAGE_LEN];
367
368                 cfread(dummy, MAX_MESSAGE_LEN, 4, file);
369 #endif
370         }
371
372         //read kconfig data
373         {
374                 int n_control_types = (player_file_version<20)?7:CONTROL_MAX_TYPES;
375                 ubyte kconfig_settings[CONTROL_MAX_TYPES][MAX_CONTROLS], control_type_win;
376
377                 if (player_file_version < 25)
378                         if (PHYSFS_read(file, kconfig_settings, MAX_CONTROLS*n_control_types, 1) != 1)
379                                 goto read_player_file_failed;
380                 if (PHYSFS_read(file, (ubyte *)&Config_control_type, sizeof(ubyte), 1) != 1)
381                         goto read_player_file_failed;
382                 else if (player_file_version >= 21 && player_file_version < 25
383                         && PHYSFS_read(file, (ubyte *)&control_type_win, sizeof(ubyte), 1) != 1)
384                         goto read_player_file_failed;
385                 else if (PHYSFS_read(file, &Config_joystick_sensitivity, sizeof(ubyte), 1) !=1 )
386                         goto read_player_file_failed;
387                 
388                 #ifdef MACINTOSH
389                 joydefs_set_type(Config_control_type);
390                 #endif
391
392                 for (i=0;i<11;i++)
393                 {
394                         PrimaryOrder[i] = cfile_read_byte(file);
395                         SecondaryOrder[i] = cfile_read_byte(file);
396                 }
397
398                 if (player_file_version>=16)
399                 {
400                         PHYSFS_readSLE32(file, &Cockpit_3d_view[0]);
401                         PHYSFS_readSLE32(file, &Cockpit_3d_view[1]);
402                         if (swap)
403                         {
404                                 Cockpit_3d_view[0] = SWAPINT(Cockpit_3d_view[0]);
405                                 Cockpit_3d_view[1] = SWAPINT(Cockpit_3d_view[1]);
406                         }
407                 }
408
409                 kc_set_controls();
410
411         }
412
413         if (player_file_version>=22)
414         {
415 #ifdef NETWORK
416                 PHYSFS_readSLE32(file, &Netlife_kills);
417                 PHYSFS_readSLE32(file, &Netlife_killed);
418                 if (swap) {
419                         Netlife_kills = SWAPINT(Netlife_kills);
420                         Netlife_killed = SWAPINT(Netlife_killed);
421                 }
422 #else
423                 {
424                         int dummy;
425                         PHYSFS_readSLE32(file, &dummy);
426                         PHYSFS_readSLE32(file, &dummy);
427                 }
428 #endif
429         }
430 #ifdef NETWORK
431         else
432         {
433                 Netlife_kills=0; Netlife_killed=0;
434         }
435 #endif
436
437         if (player_file_version>=23)
438         {
439                 PHYSFS_readSLE32(file, &i);
440                 if (swap)
441                         i = SWAPINT(i);
442 #ifdef NETWORK
443                 mprintf ((0,"Reading: lifetime checksum is %d\n",i));
444                 if (i!=get_lifetime_checksum (Netlife_kills,Netlife_killed))
445                 {
446                         Netlife_kills=0; Netlife_killed=0;
447                         nm_messagebox(NULL, 1, "Shame on me", "Trying to cheat eh?");
448                         rewrite_it=1;
449                 }
450 #endif
451         }
452
453         //read guidebot name
454         if (player_file_version >= 18)
455                 PHYSFSX_readString(file, guidebot_name);
456         else
457                 strcpy(guidebot_name,"GUIDE-BOT");
458
459         strcpy(real_guidebot_name,guidebot_name);
460
461         {
462                 char buf[128];
463
464                 if (player_file_version >= 24)
465                         PHYSFSX_readString(file, buf);                  // Just read it in fpr DPS.
466         }
467
468         if (!PHYSFS_close(file))
469                 goto read_player_file_failed;
470
471         if (rewrite_it)
472                 write_player_file();
473
474         return EZERO;
475
476  read_player_file_failed:
477         nm_messagebox(TXT_ERROR, 1, TXT_OK, "%s\n\n%s", "Error reading PLR file", PHYSFS_getLastError());
478         if (file)
479                 PHYSFS_close(file);
480
481         return -1;
482 }
483
484
485 //finds entry for this level in table.  if not found, returns ptr to 
486 //empty entry.  If no empty entries, takes over last one 
487 int find_hli_entry()
488 {
489         int i;
490
491         for (i=0;i<n_highest_levels;i++)
492                 if (!stricmp(highest_levels[i].shortname, Current_mission_filename))
493                         break;
494
495         if (i==n_highest_levels) {              //not found.  create entry
496
497                 if (i==MAX_MISSIONS)
498                         i--;            //take last entry
499                 else
500                         n_highest_levels++;
501
502                 strcpy(highest_levels[i].shortname, Current_mission_filename);
503                 highest_levels[i].level_num                     = 0;
504         }
505
506         return i;
507 }
508
509 //set a new highest level for player for this mission
510 void set_highest_level(int levelnum)
511 {
512         int ret,i;
513
514         if ((ret=read_player_file()) != EZERO)
515                 if (ret != ENOENT)              //if file doesn't exist, that's ok
516                         return;
517
518         i                       = find_hli_entry();
519
520         if (levelnum > highest_levels[i].level_num)
521                 highest_levels[i].level_num                     = levelnum;
522
523         write_player_file();
524 }
525
526 //gets the player's highest level from the file for this mission
527 int get_highest_level(void)
528 {
529         int i;
530         int highest_saturn_level                        = 0;
531         read_player_file();
532 #ifndef SATURN
533         if (strlen(Current_mission_filename)==0 )       {
534                 for (i=0;i<n_highest_levels;i++)
535                         if (!stricmp(highest_levels[i].shortname, "DESTSAT"))   //      Destination Saturn.
536                                 highest_saturn_level                    = highest_levels[i].level_num; 
537         }
538 #endif
539    i                    = highest_levels[find_hli_entry()].level_num;
540         if ( highest_saturn_level > i )
541         i                       = highest_saturn_level;
542         return i;
543 }
544
545 extern int Cockpit_mode_save;
546
547
548 //write out player's saved games.  returns errno (0 == no error)
549 int write_player_file()
550 {
551         char filename[FILENAME_LEN+15];
552         PHYSFS_file *file;
553         int i;
554
555 //      #ifdef APPLE_DEMO               // no saving of player files in Apple OEM version
556 //      return 0;
557 //      #endif
558
559         WriteConfigFile();
560
561         sprintf(filename, PLAYER_DIR "%s.plr", Players[Player_num].callsign);
562         file = PHYSFSX_openWriteBuffered(filename);
563
564 #if 0 //ndef MACINTOSH
565         //check filename
566         if (file && isatty(fileno(file))) {
567
568                 //if the callsign is the name of a tty device, prepend a char
569
570                 PHYSFS_close(file);
571                 sprintf(filename, PLAYER_DIR "$%.7s.plr", Players[Player_num].callsign);
572                 file = PHYSFSX_openWriteBuffered(filename);
573         }
574 #endif
575
576         if (!file)
577                 return -1;
578
579         //Write out player's info
580         PHYSFS_writeULE32(file, SAVE_FILE_ID);
581         PHYSFS_writeULE16(file, PLAYER_FILE_VERSION);
582
583         PHYSFS_writeULE16(file, Game_window_w);
584         PHYSFS_writeULE16(file, Game_window_h);
585
586         PHYSFSX_writeU8(file, Player_default_difficulty);
587         PHYSFSX_writeU8(file, Auto_leveling_on);
588         PHYSFSX_writeU8(file, Reticle_on);
589         PHYSFSX_writeU8(file, (Cockpit_mode_save!=-1)?Cockpit_mode_save:Cockpit_mode);  //if have saved mode, write it instead of letterbox/rear view
590
591         for (i = 0; i < (sizeof(legacy_display_mode) / sizeof(uint32_t)); i++) {
592                 if (legacy_display_mode[i] == Current_display_mode)
593                         break;
594         }
595         PHYSFSX_writeU8(file, i);
596
597         PHYSFSX_writeU8(file, Missile_view_enabled);
598         PHYSFSX_writeU8(file, Headlight_active_default);
599         PHYSFSX_writeU8(file, Guided_in_big_window);
600         PHYSFSX_writeU8(file, Automap_always_hires);
601
602         //write higest level info
603         PHYSFS_writeULE16(file, n_highest_levels);
604         if ((PHYSFS_write(file, highest_levels, sizeof(hli), n_highest_levels) != n_highest_levels))
605                 goto write_player_file_failed;
606
607 #ifdef NETWORK
608         if ((PHYSFS_write(file, Network_message_macro, MAX_MESSAGE_LEN, 4) != 4))
609                 goto write_player_file_failed;
610 #else
611         {
612                 char dummy[4][MAX_MESSAGE_LEN]; // Pull the messages from a hat! ;-)
613
614                 if ((PHYSFS_write(file, dummy, MAX_MESSAGE_LEN, 4) != 4))
615                         goto write_player_file_failed;
616         }
617 #endif
618
619         //write kconfig info
620         {
621                 if (PHYSFS_write(file, &Config_control_type, sizeof(ubyte), 1) != 1)
622                         goto write_player_file_failed;
623                 else if (PHYSFS_write(file, &Config_joystick_sensitivity, sizeof(ubyte), 1) != 1)
624                         goto write_player_file_failed;
625
626                 for (i = 0; i < 11; i++)
627                 {
628                         PHYSFS_write(file, &PrimaryOrder[i], sizeof(ubyte), 1);
629                         PHYSFS_write(file, &SecondaryOrder[i], sizeof(ubyte), 1);
630                 }
631
632                 PHYSFS_writeULE32(file, Cockpit_3d_view[0]);
633                 PHYSFS_writeULE32(file, Cockpit_3d_view[1]);
634
635 #ifdef NETWORK
636                 PHYSFS_writeULE32(file, Netlife_kills);
637                 PHYSFS_writeULE32(file, Netlife_killed);
638                 i=get_lifetime_checksum (Netlife_kills,Netlife_killed);
639                 mprintf ((0,"Writing: Lifetime checksum is %d\n",i));
640 #else
641                 PHYSFS_writeULE32(file, 0);
642                 PHYSFS_writeULE32(file, 0);
643                 i = get_lifetime_checksum (0, 0);
644 #endif
645                 PHYSFS_writeULE32(file, i);
646         }
647
648         //write guidebot name
649         PHYSFSX_writeString(file, real_guidebot_name);
650
651         {
652                 char buf[128];
653                 strcpy(buf, "DOS joystick");
654                 PHYSFSX_writeString(file, buf);         // Write out current joystick for player.
655         }
656
657         if (!PHYSFS_close(file))
658                 goto write_player_file_failed;
659
660         #ifdef MACINTOSH                // set filetype and creator for playerfile
661         {
662                 FInfo finfo;
663                 Str255 pfilename;
664                 OSErr err;
665
666                 strcpy(pfilename, filename);
667                 c2pstr(pfilename);
668                 err = HGetFInfo(0, 0, pfilename, &finfo);
669                 finfo.fdType = 'PLYR';
670                 finfo.fdCreator = 'DCT2';
671                 err = HSetFInfo(0, 0, pfilename, &finfo);
672         }
673         #endif
674
675         return EZERO;
676
677  write_player_file_failed:
678         nm_messagebox(TXT_ERROR, 1, TXT_OK, "%s\n\n%s", TXT_ERROR_WRITING_PLR, PHYSFS_getLastError());
679         if (file)
680         {
681                 PHYSFS_close(file);
682                 PHYSFS_delete(filename);        //delete bogus file
683         }
684
685         return -1;
686 }
687
688 //update the player's highest level.  returns errno (0 == no error)
689 int update_player_file()
690 {
691         int ret;
692
693         if ((ret=read_player_file()) != EZERO)
694                 if (ret != ENOENT)              //if file doesn't exist, that's ok
695                         return ret;
696
697         return write_player_file();
698 }
699
700 int get_lifetime_checksum (int a,int b)
701  {
702   int num;
703
704   // confusing enough to beat amateur disassemblers? Lets hope so
705
706   num=(a<<8 ^ b);
707   num^=(a | b);
708   num*=num>>2;
709   return (num);
710  }
711   
712