]> icculus.org git repositories - btb/d2x.git/blob - main/playsave.c
make cvar for guidebot_name, remove it from plr file
[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, joy name, guidebot name
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 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) };
251
252 //read in the player's saved games.  returns errno (0 == no error)
253 int read_player_file()
254 {
255         #ifdef MACINTOSH
256         char filename[FILENAME_LEN+15];
257         #else
258         char filename[FILENAME_LEN];
259         #endif
260         PHYSFS_file *file;
261         int id, i;
262         short player_file_version;
263         int rewrite_it=0;
264         int swap = 0;
265
266         Assert(Player_num>=0 && Player_num<MAX_PLAYERS);
267
268         sprintf(filename, PLAYER_DIR "%.8s.plr", Players[Player_num].callsign);
269
270         if (!PHYSFS_exists(filename))
271                 return ENOENT;
272
273         file = PHYSFSX_openReadBuffered(filename);
274
275 #if 0
276 #ifndef MACINTOSH
277         //check filename
278         if (file && isatty(fileno(file))) {
279                 //if the callsign is the name of a tty device, prepend a char
280                 PHYSFS_close(file);
281                 sprintf(filename, PLAYER_DIR "$%.7s.plr",Players[Player_num].callsign);
282                 file = PHYSFSX_openReadBuffered(filename);
283         }
284 #endif
285 #endif
286
287         if (!file)
288                 goto read_player_file_failed;
289
290         PHYSFS_readSLE32(file, &id);
291
292         // SWAPINT added here because old versions of d2x
293         // used the wrong byte order.
294         if (id!=SAVE_FILE_ID && id!=SWAPINT(SAVE_FILE_ID)) {
295                 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Invalid player file");
296                 PHYSFS_close(file);
297                 return -1;
298         }
299
300         player_file_version = cfile_read_short(file);
301
302         if (player_file_version > 255) // bigendian file?
303                 swap = 1;
304
305         if (swap)
306                 player_file_version = SWAPSHORT(player_file_version);
307
308         if (player_file_version<COMPATIBLE_PLAYER_FILE_VERSION) {
309                 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_ERROR_PLR_VERSION);
310                 PHYSFS_close(file);
311                 return -1;
312         }
313
314         Game_window_w = cfile_read_short(file);
315         Game_window_h = cfile_read_short(file);
316
317         if (swap) {
318                 Game_window_w = SWAPSHORT(Game_window_w);
319                 Game_window_h = SWAPSHORT(Game_window_h);
320         }
321
322         Player_default_difficulty = cfile_read_byte(file);
323         Default_leveling_on       = cfile_read_byte(file);
324         Reticle_on                = cfile_read_byte(file);
325         Cockpit_mode              = cfile_read_byte(file);
326
327         i                         = cfile_read_byte(file);
328         Default_display_mode = legacy_display_mode[i];
329
330         Missile_view_enabled      = cfile_read_byte(file);
331         Headlight_active_default  = cfile_read_byte(file);
332         Guided_in_big_window      = cfile_read_byte(file);
333                 
334         if (player_file_version >= 19)
335                 Automap_always_hires = cfile_read_byte(file);
336
337         Auto_leveling_on = Default_leveling_on;
338
339         //read new highest level info
340
341         n_highest_levels = cfile_read_short(file);
342         if (swap)
343                 n_highest_levels = SWAPSHORT(n_highest_levels);
344         Assert(n_highest_levels <= MAX_MISSIONS);
345
346         if (PHYSFS_read(file, highest_levels, sizeof(hli), n_highest_levels) != n_highest_levels)
347                 goto read_player_file_failed;
348
349         //read taunt macros
350         {
351 #ifdef NETWORK
352                 int i,len;
353
354                 len = MAX_MESSAGE_LEN;
355
356                 for (i = 0; i < 4; i++)
357                         if (PHYSFS_read(file, Network_message_macro[i], len, 1) != 1)
358                                 goto read_player_file_failed;
359 #else
360                 char dummy[4][MAX_MESSAGE_LEN];
361
362                 cfread(dummy, MAX_MESSAGE_LEN, 4, file);
363 #endif
364         }
365
366         //read kconfig data
367         {
368                 int n_control_types = (player_file_version<20)?7:CONTROL_MAX_TYPES;
369                 ubyte kconfig_settings[CONTROL_MAX_TYPES][MAX_CONTROLS], control_type_win;
370
371                 if (player_file_version < 25)
372                         if (PHYSFS_read(file, kconfig_settings, MAX_CONTROLS*n_control_types, 1) != 1)
373                                 goto read_player_file_failed;
374                 if (PHYSFS_read(file, (ubyte *)&Config_control_type, sizeof(ubyte), 1) != 1)
375                         goto read_player_file_failed;
376                 else if (player_file_version >= 21 && player_file_version < 25
377                         && PHYSFS_read(file, (ubyte *)&control_type_win, sizeof(ubyte), 1) != 1)
378                         goto read_player_file_failed;
379                 else if (PHYSFS_read(file, &Config_joystick_sensitivity, sizeof(ubyte), 1) !=1 )
380                         goto read_player_file_failed;
381                 
382                 #ifdef MACINTOSH
383                 joydefs_set_type(Config_control_type);
384                 #endif
385
386                 for (i=0;i<11;i++)
387                 {
388                         PrimaryOrder[i] = cfile_read_byte(file);
389                         SecondaryOrder[i] = cfile_read_byte(file);
390                 }
391
392                 if (player_file_version>=16)
393                 {
394                         PHYSFS_readSLE32(file, &Cockpit_3d_view[0]);
395                         PHYSFS_readSLE32(file, &Cockpit_3d_view[1]);
396                         if (swap)
397                         {
398                                 Cockpit_3d_view[0] = SWAPINT(Cockpit_3d_view[0]);
399                                 Cockpit_3d_view[1] = SWAPINT(Cockpit_3d_view[1]);
400                         }
401                 }
402
403                 kc_set_controls();
404
405         }
406
407         if (player_file_version>=22)
408         {
409 #ifdef NETWORK
410                 PHYSFS_readSLE32(file, &Netlife_kills);
411                 PHYSFS_readSLE32(file, &Netlife_killed);
412                 if (swap) {
413                         Netlife_kills = SWAPINT(Netlife_kills);
414                         Netlife_killed = SWAPINT(Netlife_killed);
415                 }
416 #else
417                 {
418                         int dummy;
419                         PHYSFS_readSLE32(file, &dummy);
420                         PHYSFS_readSLE32(file, &dummy);
421                 }
422 #endif
423         }
424 #ifdef NETWORK
425         else
426         {
427                 Netlife_kills=0; Netlife_killed=0;
428         }
429 #endif
430
431         if (player_file_version>=23)
432         {
433                 PHYSFS_readSLE32(file, &i);
434                 if (swap)
435                         i = SWAPINT(i);
436 #ifdef NETWORK
437                 mprintf ((0,"Reading: lifetime checksum is %d\n",i));
438                 if (i!=get_lifetime_checksum (Netlife_kills,Netlife_killed))
439                 {
440                         Netlife_kills=0; Netlife_killed=0;
441                         nm_messagebox(NULL, 1, "Shame on me", "Trying to cheat eh?");
442                         rewrite_it=1;
443                 }
444 #endif
445         }
446
447         if (!PHYSFS_close(file))
448                 goto read_player_file_failed;
449
450         if (rewrite_it)
451                 write_player_file();
452
453         return EZERO;
454
455  read_player_file_failed:
456         nm_messagebox(TXT_ERROR, 1, TXT_OK, "%s\n\n%s", "Error reading PLR file", PHYSFS_getLastError());
457         if (file)
458                 PHYSFS_close(file);
459
460         return -1;
461 }
462
463
464 //finds entry for this level in table.  if not found, returns ptr to 
465 //empty entry.  If no empty entries, takes over last one 
466 int find_hli_entry()
467 {
468         int i;
469
470         for (i=0;i<n_highest_levels;i++)
471                 if (!stricmp(highest_levels[i].shortname, Current_mission_filename))
472                         break;
473
474         if (i==n_highest_levels) {              //not found.  create entry
475
476                 if (i==MAX_MISSIONS)
477                         i--;            //take last entry
478                 else
479                         n_highest_levels++;
480
481                 strcpy(highest_levels[i].shortname, Current_mission_filename);
482                 highest_levels[i].level_num                     = 0;
483         }
484
485         return i;
486 }
487
488 //set a new highest level for player for this mission
489 void set_highest_level(int levelnum)
490 {
491         int ret,i;
492
493         if ((ret=read_player_file()) != EZERO)
494                 if (ret != ENOENT)              //if file doesn't exist, that's ok
495                         return;
496
497         i                       = find_hli_entry();
498
499         if (levelnum > highest_levels[i].level_num)
500                 highest_levels[i].level_num                     = levelnum;
501
502         write_player_file();
503 }
504
505 //gets the player's highest level from the file for this mission
506 int get_highest_level(void)
507 {
508         int i;
509         int highest_saturn_level                        = 0;
510         read_player_file();
511 #ifndef SATURN
512         if (strlen(Current_mission_filename)==0 )       {
513                 for (i=0;i<n_highest_levels;i++)
514                         if (!stricmp(highest_levels[i].shortname, "DESTSAT"))   //      Destination Saturn.
515                                 highest_saturn_level                    = highest_levels[i].level_num; 
516         }
517 #endif
518    i                    = highest_levels[find_hli_entry()].level_num;
519         if ( highest_saturn_level > i )
520         i                       = highest_saturn_level;
521         return i;
522 }
523
524 extern int Cockpit_mode_save;
525
526
527 //write out player's saved games.  returns errno (0 == no error)
528 int write_player_file()
529 {
530         char filename[FILENAME_LEN+15];
531         PHYSFS_file *file;
532         int i;
533
534 //      #ifdef APPLE_DEMO               // no saving of player files in Apple OEM version
535 //      return 0;
536 //      #endif
537
538         WriteConfigFile();
539
540         sprintf(filename, PLAYER_DIR "%s.plr", Players[Player_num].callsign);
541         file = PHYSFSX_openWriteBuffered(filename);
542
543 #if 0 //ndef MACINTOSH
544         //check filename
545         if (file && isatty(fileno(file))) {
546
547                 //if the callsign is the name of a tty device, prepend a char
548
549                 PHYSFS_close(file);
550                 sprintf(filename, PLAYER_DIR "$%.7s.plr", Players[Player_num].callsign);
551                 file = PHYSFSX_openWriteBuffered(filename);
552         }
553 #endif
554
555         if (!file)
556                 return -1;
557
558         //Write out player's info
559         PHYSFS_writeULE32(file, SAVE_FILE_ID);
560         PHYSFS_writeULE16(file, PLAYER_FILE_VERSION);
561
562         PHYSFS_writeULE16(file, Game_window_w);
563         PHYSFS_writeULE16(file, Game_window_h);
564
565         PHYSFSX_writeU8(file, Player_default_difficulty);
566         PHYSFSX_writeU8(file, Auto_leveling_on);
567         PHYSFSX_writeU8(file, Reticle_on);
568         PHYSFSX_writeU8(file, (Cockpit_mode_save!=-1)?Cockpit_mode_save:Cockpit_mode);  //if have saved mode, write it instead of letterbox/rear view
569
570         for (i = 0; i < (sizeof(legacy_display_mode) / sizeof(uint32_t)); i++) {
571                 if (legacy_display_mode[i] == Current_display_mode)
572                         break;
573         }
574         PHYSFSX_writeU8(file, i);
575
576         PHYSFSX_writeU8(file, Missile_view_enabled);
577         PHYSFSX_writeU8(file, Headlight_active_default);
578         PHYSFSX_writeU8(file, Guided_in_big_window);
579         PHYSFSX_writeU8(file, Automap_always_hires);
580
581         //write higest level info
582         PHYSFS_writeULE16(file, n_highest_levels);
583         if ((PHYSFS_write(file, highest_levels, sizeof(hli), n_highest_levels) != n_highest_levels))
584                 goto write_player_file_failed;
585
586 #ifdef NETWORK
587         if ((PHYSFS_write(file, Network_message_macro, MAX_MESSAGE_LEN, 4) != 4))
588                 goto write_player_file_failed;
589 #else
590         {
591                 char dummy[4][MAX_MESSAGE_LEN]; // Pull the messages from a hat! ;-)
592
593                 if ((PHYSFS_write(file, dummy, MAX_MESSAGE_LEN, 4) != 4))
594                         goto write_player_file_failed;
595         }
596 #endif
597
598         //write kconfig info
599         {
600                 if (PHYSFS_write(file, &Config_control_type, sizeof(ubyte), 1) != 1)
601                         goto write_player_file_failed;
602                 else if (PHYSFS_write(file, &Config_joystick_sensitivity, sizeof(ubyte), 1) != 1)
603                         goto write_player_file_failed;
604
605                 for (i = 0; i < 11; i++)
606                 {
607                         PHYSFS_write(file, &PrimaryOrder[i], sizeof(ubyte), 1);
608                         PHYSFS_write(file, &SecondaryOrder[i], sizeof(ubyte), 1);
609                 }
610
611                 PHYSFS_writeULE32(file, Cockpit_3d_view[0]);
612                 PHYSFS_writeULE32(file, Cockpit_3d_view[1]);
613
614 #ifdef NETWORK
615                 PHYSFS_writeULE32(file, Netlife_kills);
616                 PHYSFS_writeULE32(file, Netlife_killed);
617                 i=get_lifetime_checksum (Netlife_kills,Netlife_killed);
618                 mprintf ((0,"Writing: Lifetime checksum is %d\n",i));
619 #else
620                 PHYSFS_writeULE32(file, 0);
621                 PHYSFS_writeULE32(file, 0);
622                 i = get_lifetime_checksum (0, 0);
623 #endif
624                 PHYSFS_writeULE32(file, i);
625         }
626
627         if (!PHYSFS_close(file))
628                 goto write_player_file_failed;
629
630         #ifdef MACINTOSH                // set filetype and creator for playerfile
631         {
632                 FInfo finfo;
633                 Str255 pfilename;
634                 OSErr err;
635
636                 strcpy(pfilename, filename);
637                 c2pstr(pfilename);
638                 err = HGetFInfo(0, 0, pfilename, &finfo);
639                 finfo.fdType = 'PLYR';
640                 finfo.fdCreator = 'DCT2';
641                 err = HSetFInfo(0, 0, pfilename, &finfo);
642         }
643         #endif
644
645         return EZERO;
646
647  write_player_file_failed:
648         nm_messagebox(TXT_ERROR, 1, TXT_OK, "%s\n\n%s", TXT_ERROR_WRITING_PLR, PHYSFS_getLastError());
649         if (file)
650         {
651                 PHYSFS_close(file);
652                 PHYSFS_delete(filename);        //delete bogus file
653         }
654
655         return -1;
656 }
657
658 //update the player's highest level.  returns errno (0 == no error)
659 int update_player_file()
660 {
661         int ret;
662
663         if ((ret=read_player_file()) != EZERO)
664                 if (ret != ENOENT)              //if file doesn't exist, that's ok
665                         return ret;
666
667         return write_player_file();
668 }
669
670 int get_lifetime_checksum (int a,int b)
671  {
672   int num;
673
674   // confusing enough to beat amateur disassemblers? Lets hope so
675
676   num=(a<<8 ^ b);
677   num^=(a | b);
678   num*=num>>2;
679   return (num);
680  }
681   
682