/* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ /* * $Source: /cvsroot/dxx-rebirth/d1x-rebirth/main/playsave.c,v $ * $Revision: 1.1.1.1 $ * $Author: zicodxx $ * $Date: 2006/03/17 19:42:10 $ * * Functions to load & save player games * * $Log: playsave.c,v $ * Revision 1.1.1.1 2006/03/17 19:42:10 zicodxx * initial import * * Revision 1.3 2003/02/16 10:44:56 donut * fix the weird bug where joystick fire button would do all the d1x key functions at once, when joining a udp game. (but going into config menu would fix it.) It was due to kc_set_controls() being called before read_player_d1x, so the d1x settings weren't getting noticed. * * Revision 1.2 1999/06/14 23:44:12 donut * Orulz' svgalib/ggi/noerror patches. * * Revision 1.1.1.1 1999/06/14 22:11:04 donut * Import of d1x 1.37 source. * * Revision 2.3 1995/05/26 16:16:23 john * Split SATURN into define's for requiring cd, using cd, etc. * Also started adding all the Rockwell stuff. * * Revision 2.2 1995/03/24 17:48:21 john * Made player files from saturn excrement the highest level for * normal descent levels. * * Revision 2.1 1995/03/21 14:38:49 john * Ifdef'd out the NETWORK code. * * Revision 2.0 1995/02/27 11:27:59 john * New version 2.0, which has no anonymous unions, builds with * Watcom 10.0, and doesn't require parsing BITMAPS.TBL. * * Revision 1.57 1995/02/13 20:34:55 john * Lintized * * Revision 1.56 1995/02/13 13:23:24 john * Fixed bug with new player joystick selection. * * Revision 1.55 1995/02/13 12:01:19 john * Fixed bug with joystick throttle still asking for * calibration with new pilots. * * Revision 1.54 1995/02/13 10:29:12 john * Fixed bug with creating new player not resetting everything to default. * * Revision 1.53 1995/02/03 10:58:46 john * Added code to save shareware style saved games into new format... * Also, made new player file format not have the saved game array in it. * * Revision 1.52 1995/02/02 21:09:28 matt * Let player start of level 8 if he made it to level 7 in the shareware * * Revision 1.51 1995/02/02 18:50:14 john * Added warning for FCS when new pilot chooses. * * Revision 1.50 1995/02/02 11:21:34 john * Made joystick calibrate when new user selects. * * Revision 1.49 1995/02/01 18:06:38 rob * Put defaults macros into descent.tex * * Revision 1.48 1995/01/25 14:37:53 john * Made joystick only prompt for calibration once... * * Revision 1.47 1995/01/24 19:37:12 matt * Took out incorrect mprintf * * Revision 1.46 1995/01/22 18:57:22 matt * Made player highest level work with missions * * Revision 1.45 1995/01/21 16:36:05 matt * Made starting level system work for now, pending integration with * mission code. * * Revision 1.44 1995/01/20 22:47:32 matt * Mission system implemented, though imcompletely * * Revision 1.43 1995/01/04 14:58:39 rob * Fixed for shareware build. * * Revision 1.42 1995/01/04 11:36:43 rob * Added compatibility with older shareware pilot files. * * Revision 1.41 1995/01/03 11:01:58 rob * fixed a default macro. * * Revision 1.40 1995/01/03 10:44:06 rob * Added default taunt macros. * * Revision 1.39 1994/12/13 10:01:16 allender * pop up message box when unable to correctly save player file * * Revision 1.38 1994/12/12 11:37:14 matt * Fixed auto leveling defaults & saving * * Revision 1.37 1994/12/12 00:26:59 matt * Added support for no-levelling option * * Revision 1.36 1994/12/10 19:09:54 matt * Added assert for valid player number when loading game * * Revision 1.35 1994/12/08 10:53:07 rob * Fixed a bug in highest_level tracking. * * Revision 1.34 1994/12/08 10:01:36 john * Changed the way the player callsign stuff works. * * Revision 1.33 1994/12/07 18:30:38 rob * Load highest level along with player (used to be only if higher) * Capped at LAST_LEVEL in case a person loads a registered player in shareware. * * Revision 1.32 1994/12/03 16:01:12 matt * When player file has bad version, force player to choose another * * Revision 1.31 1994/12/02 19:54:00 yuan * Localization. * * Revision 1.30 1994/12/02 11:01:36 yuan * Localization. * * Revision 1.29 1994/11/29 03:46:28 john * Added joystick sensitivity; Added sound channels to detail menu. Removed -maxchannels * command line arg. * * Revision 1.28 1994/11/29 01:10:23 john * Took out code that allowed new players to * configure keyboard. * * Revision 1.27 1994/11/25 22:47:10 matt * Made saved game descriptions longer * * Revision 1.26 1994/11/22 12:10:42 rob * Fixed file handle left open if player file versions don't * match. * * Revision 1.25 1994/11/21 19:35:30 john * Replaced calls to joy_init with if (joy_present) * * Revision 1.24 1994/11/21 17:29:34 matt * Cleaned up sequencing & game saving for secret levels * * Revision 1.23 1994/11/21 11:10:01 john * Fixed bug with read-only .plr file making the config file * not update. * * Revision 1.22 1994/11/20 19:03:08 john * Fixed bug with if not having a joystick, default * player input device is cyberman. * * Revision 1.21 1994/11/17 12:24:07 matt * Made an array the right size, to fix error loading games * * Revision 1.20 1994/11/14 17:52:54 allender * add call to WriteConfigFile when player files gets written * * Revision 1.19 1994/11/14 17:19:23 rob * Removed gamma, joystick calibration, and sound settings from player file. * Added default difficulty and multi macros. * * Revision 1.18 1994/11/07 14:01:23 john * Changed the gamma correction sequencing. * * Revision 1.17 1994/11/05 17:22:49 john * Fixed lots of sequencing problems with newdemo stuff. * * Revision 1.16 1994/11/01 16:40:11 john * Added Gamma correction. * * Revision 1.15 1994/10/24 19:56:50 john * Made the new user setup prompt for config options. * * Revision 1.14 1994/10/24 17:44:21 john * Added stereo channel reversing. * * Revision 1.13 1994/10/24 16:05:12 matt * Improved handling of player names that are the names of DOS devices * * Revision 1.12 1994/10/22 00:08:51 matt * Fixed up problems with bonus & game sequencing * Player doesn't get credit for hostages unless he gets them out alive * * Revision 1.11 1994/10/19 19:59:57 john * Added bonus points at the end of level based on skill level. * * Revision 1.10 1994/10/19 15:14:34 john * Took % hits out of player structure, made %kills work properly. * * Revision 1.9 1994/10/19 12:44:26 john * Added hours field to player structure. * * Revision 1.8 1994/10/17 17:24:34 john * Added starting_level to player struct. * * Revision 1.7 1994/10/17 13:07:15 john * Moved the descent.cfg info into the player config file. * * Revision 1.6 1994/10/09 14:54:31 matt * Made player cockpit state & window size save/restore with saved games & automap * * Revision 1.5 1994/10/08 23:08:09 matt * Added error check & handling for game load/save disk io * * Revision 1.4 1994/10/05 17:40:54 rob * Bumped save_file_version to 5 due to change in player.h * * Revision 1.3 1994/10/03 23:00:54 matt * New file version for shorter callsigns * * Revision 1.2 1994/09/28 17:25:05 matt * Added first draft of game save/load system * * Revision 1.1 1994/09/27 14:39:12 matt * Initial revision * * */ #ifdef RCS #pragma off (unreferenced) static char rcsid[] = "$Id: playsave.c,v 1.1.1.1 2006/03/17 19:42:10 zicodxx Exp $"; #pragma on (unreferenced) #endif #include #include #include #include #include "error.h" #include "gameseq.h" #include "player.h" #include "playsave.h" #include "joy.h" #include "kconfig.h" #include "digi.h" #include "newmenu.h" #include "joydefs.h" #include "palette.h" #include "multi.h" #include "menu.h" #include "config.h" #include "text.h" #include "mono.h" #include "state.h" #include "reorder.h" #include "d_io.h" //added on 9/16/98 by adb to add memory tracking for this module #include "u_mem.h" //end additions - adb //added on 11/12/98 by Victor Rachels to add networkrejoin thing #include "network.h" //end this section addition - VR //added 6/15/99 - Owen Evans #include "strutil.h" //end added #include "strio.h" #include "vers_id.h" #ifndef PATH_MAX #define PATH_MAX 255 #endif #define SAVE_FILE_ID 0x44504c52 /* 'DPLR' */ //this is for version 5 and below typedef struct save_info_v5 { int id; short saved_game_version,player_struct_version; int highest_level; int default_difficulty_level; int default_leveling_on; } __pack__ save_info_v5; //this is for version 6 and above typedef struct save_info { int id; short saved_game_version,player_struct_version; int n_highest_levels; //how many highest levels are saved int default_difficulty_level; int default_leveling_on; int Game_window_w; int Game_window_h; } __pack__ save_info; typedef struct hli { char shortname[9]; ubyte level_num; } __pack__ hli; int n_highest_levels; hli highest_levels[MAX_MISSIONS]; #define SAVED_GAME_VERSION 8 //increment this every time saved_game struct changes //version 5 -> 6: added new highest level information //version 6 -> 7: stripped out the old saved_game array. //version 7 -> 8: readded the old saved_game array since this is needed // for shareware saved games //the shareware is level 4 #define COMPATIBLE_SAVED_GAME_VERSION 4 #define COMPATIBLE_PLAYER_STRUCT_VERSION 16 typedef struct saved_game { char name[GAME_NAME_LEN+1]; //extra char for terminating zero player player; int difficulty_level; //which level game is played at int primary_weapon; //which weapon selected int secondary_weapon; //which weapon selected int cockpit_mode; //which cockpit mode selected int window_w,window_h; //size of player's window int next_level_num; //which level we're going to int auto_leveling_on; //does player have autoleveling on? } __pack__ saved_game; saved_game saved_games[N_SAVE_SLOTS]; int Default_leveling_on=1; void init_game_list() { int i; for (i=0;i0) && (Config_control_type<5) ) { // joydefs_calibrate(); // } Player_default_difficulty = 1; Auto_leveling_on = Default_leveling_on = 1; n_highest_levels = 1; highest_levels[0].shortname[0] = 0; //no name for mission 0 highest_levels[0].level_num = 1; //was highest level in old struct Config_joystick_sensitivity = 8; memcpy(primary_order, default_primary_order, sizeof(primary_order)); memcpy(secondary_order, default_secondary_order, sizeof(secondary_order)); // Default taunt macros #ifdef NETWORK strcpy(Network_message_macro[0], TXT_DEF_MACRO_1); strcpy(Network_message_macro[1], TXT_DEF_MACRO_2); strcpy(Network_message_macro[2], TXT_DEF_MACRO_3); strcpy(Network_message_macro[3], TXT_DEF_MACRO_4); #endif return 1; } int read_player_d1x(const char *filename) { FILE *f; int rc = 0; char *line,*word; int Stop=0; int i; char plxver[6]; sprintf(plxver,"v0.00"); //added on 10/15/98 by Victor Rachels for effeciency stuff plyr_read_stats(); //end this section addition - Victor Rachels // set defaults for when nothing is specified memcpy(primary_order, default_primary_order, sizeof(primary_order)); memcpy(secondary_order, default_secondary_order, sizeof(secondary_order)); //added/killed on 2/4/99 by Victor Rachels for new keys //-killed- kconfig_settings[0][46]=255; //-killed- kconfig_settings[0][47]=255; //-killed- kconfig_settings[0][48]=255; //-killed- kconfig_settings[0][49]=255; //-killed- kconfig_settings[0][50]=255; //-killed- kconfig_settings[0][51]=255; for(i=0;i='a'){ neg=1;I=p[0]-'a'; }else{ neg=0;I=p[0]-'A'; } i=0;*v=0; p++; while (p[i*2] && p[i*2+1] && p[i*2]!=' '){ c=(p[i*2]-33)+((p[i*2+1]-33)<<4); c^=effcode[i+neg]; *v+=c << (i*8); i++; } if (neg) *v *= -1; // printf("decode_stat: i=%i neg=%i v=%i\n",i,neg,*v); if (!p[i*2])return NULL; return p+(i*2); } void plyr_read_stats_v(int *k, int *d){ char filename[14]; int k1=-1,k2=0,d1=-1,d2=0; FILE *f; *k=0;*d=0;//in case the file doesn't exist. sprintf(filename,"%s.eff",Players[Player_num].callsign); strlwr(filename); f=fopen(filename, "rt"); if(f && isatty(fileno(f))) { fclose(f); sprintf(filename,"$%.7s.pl$",Players[Player_num].callsign); strlwr(filename); f=fopen(filename,"rt"); } if(f) { char *line,*word; if(!feof(f)) { line=fsplitword(f,'\n'); word=splitword(line,':'); if(!strcmp(word,"kills")) *k=atoi(line); free(line); free(word); } if(!feof(f)) { line=fsplitword(f,'\n'); word=splitword(line,':'); if(!strcmp(word,"deaths")) *d=atoi(line); free(line); free(word); } if(!feof(f)) { line=fsplitword(f,'\n'); word=splitword(line,':'); if(!strcmp(word,"key") && strlen(line)>10){ unsigned char *p; if (line[0]=='0' && line[1]=='1'){ if ((p=decode_stat(line+3,&k1,effcode1))&& (p=decode_stat(p+1,&k2,effcode2))&& (p=decode_stat(p+1,&d1,effcode3))){ decode_stat(p+1,&d2,effcode4); } } } free(line); free(word); } if (k1!=k2 || k1!=*k || d1!=d2 || d1!=*d){ *k=0;*d=0;//printf("cheater!\n"); } } if(f) fclose(f); } //end addition -MM int multi_kills_stat=0; int multi_deaths_stat=0; //edited 11/11/98 by Matthew Mueller - some stuff cut out, some moved into above function //added on 10/15/98 by Victor Rachels for effeciency stuff void plyr_read_stats() { plyr_read_stats_v(&multi_kills_stat,&multi_deaths_stat); } //end this section addition - Victor Rachels //added on 10/15/98 by Victor Rachels to add player stats void plyr_save_stats() { int kills,deaths,neg; char filename[14]; unsigned char buf[16],buf2[16],a; int i; FILE *f; kills=0; deaths=0; //added/edited on 11/12/98 by Victor Rachels to fix kills=multi_kills_stat; deaths=multi_deaths_stat; //end this section addition - VR sprintf(filename,"%s.eff",Players[Player_num].callsign); strlwr(filename); f=fopen(filename, "rt"); if(f && isatty(fileno(f))) { fclose(f); sprintf(filename,"$%.7s.pl$",Players[Player_num].callsign); strlwr(filename); f=fopen(filename,"rt"); } f=fopen(filename, "wt"); if(!f) return; //broken! fprintf(f,"kills:%i\n",kills); fprintf(f,"deaths:%i\n",deaths); fprintf(f,"key:01 "); if (kills<0){ neg=1; kills*=-1; }else neg=0; for (i=0;kills;i++){ a=(kills & 0xFF) ^ effcode1[i+neg]; buf[i*2]=(a&0xF)+33; buf[i*2+1]=(a>>4)+33; a=(kills & 0xFF) ^ effcode2[i+neg]; buf2[i*2]=(a&0xF)+33; buf2[i*2+1]=(a>>4)+33; kills>>=8; } buf[i*2]=0; buf2[i*2]=0; if (neg)i+='a'; else i+='A'; fprintf(f,"%c%s %c%s ",i,buf,i,buf2); if (deaths<0){ neg=1; deaths*=-1; }else neg=0; for (i=0;deaths;i++){ a=(deaths & 0xFF) ^ effcode3[i+neg]; buf[i*2]=(a&0xF)+33; buf[i*2+1]=(a>>4)+33; a=(deaths & 0xFF) ^ effcode4[i+neg]; buf2[i*2]=(a&0xF)+33; buf2[i*2+1]=(a>>4)+33; deaths>>=8; } buf[i*2]=0; buf2[i*2]=0; if (neg)i+='a'; else i+='A'; fprintf(f,"%c%s %c%s\n",i,buf,i,buf2); fclose(f); } //end this section addition - Victor Rachels //end edit -MM // this mess tries to preserve unknown settings in the file... int write_player_d1x(const char *filename) { FILE *fin, *fout; int rc=0; int Stop=0; char *line; char tempfile[PATH_MAX]; strcpy(tempfile,filename); tempfile[strlen(tempfile)-4]=0; strcat(tempfile,".pl$"); fout=fopen(tempfile,"wt"); if (fout && isatty(fileno(fout))) { //if the callsign is the name of a tty device, prepend a char fclose(fout); sprintf(tempfile,"$%.7s.pl$",Players[Player_num].callsign); strlwr(tempfile); fout = fopen(tempfile,"wt"); } if(fout) { fin=fopen(filename,"rt"); if(!fin) { fprintf(fout,"[D1X Options]\n"); fprintf(fout,"[new keys]\n"); //added/changed on 2/5/99 by Victor Rachels for d1x new keys fprintf(fout,"cycle primary=0x%x,0xff,0x%x\n",kconfig_d1x_settings[20],kconfig_d1x_settings[21]); fprintf(fout,"cycle secondary=0x%x,0xff,0x%x\n",kconfig_d1x_settings[22],kconfig_d1x_settings[23]); fprintf(fout,"autoselect toggle=0x%x,0xff,0x%x\n",kconfig_d1x_settings[24],kconfig_d1x_settings[25]); // fprintf(fout,"cycle primary=0x%x,0x%x,0x%x\n",kconfig_settings[0][46],kconfig_settings[0][47],kconfig_settings[Config_control_type][27]); // fprintf(fout,"cycle secondary=0x%x,0x%x,0x%x\n",kconfig_settings[0][48],kconfig_settings[0][49],kconfig_settings[Config_control_type][28]); // fprintf(fout,"autoselect toggle=0x%x,0x%x,0x%x\n",kconfig_settings[0][50],kconfig_settings[0][51],kconfig_settings[Config_control_type][29]); //end this section change - VR fprintf(fout,"[end]\n"); fprintf(fout,"[joystick]\n"); fprintf(fout,"deadzone=%i\n",joy_deadzone); fprintf(fout,"[end]\n"); fprintf(fout,"[weapon order]\n"); fprintf(fout,"primary=1,2,3,4,5\n"); fprintf(fout,"secondary=%d,%d,%d,%d,%d\n",secondary_order[0], secondary_order[1], secondary_order[2],secondary_order[3], secondary_order[4]); fprintf(fout,"[end]\n"); fprintf(fout,"[advanced ordering]\n"); fprintf(fout,"primary=%d,%d,%d,%d,%d\n",primary_order[0], primary_order[1], primary_order[2],primary_order[3], primary_order[4]); fprintf(fout,"primary+=%d,%d,%d,%d,%d,%d,%d,%d\n",primary_order[5],primary_order[6],primary_order[7],primary_order[8],primary_order[9],primary_order[10],primary_order[11],primary_order[12]); fprintf(fout,"secondary=%d,%d,%d,%d,%d\n",secondary_order[0], secondary_order[1], secondary_order[2],secondary_order[3], secondary_order[4]); fprintf(fout,"[end]\n"); fprintf(fout,"[newer keys]\n"); //added/changed on 2/5/99 by Victor Rachels for d1x new keys fprintf(fout,"primary autoselect toggle=0x%x,0xff,0x%x\n",kconfig_d1x_settings[24],kconfig_d1x_settings[25]); fprintf(fout,"secondary autoselect toggle=0x%x,0xff,0x%x\n",kconfig_d1x_settings[26],kconfig_d1x_settings[27]); // fprintf(fout,"primary autoselect toggle=0x%x,0x%x,0x%x\n",kconfig_settings[0][50],kconfig_settings[0][51],kconfig_settings[Config_control_type][29]); // fprintf(fout,"secondary autoselect toggle=0x%x,0x%x,0x%x\n",kconfig_settings[0][52],kconfig_settings[0][53],kconfig_settings[Config_control_type][30]); //end this section change - VR fprintf(fout,"[end]\n"); //added on 2/5/99 by Victor Rachels for d1x new keys fprintf(fout,"[weapon keys]\n"); fprintf(fout,"1=0x%x,0x%x\n",kconfig_d1x_settings[0],kconfig_d1x_settings[1]); fprintf(fout,"2=0x%x,0x%x\n",kconfig_d1x_settings[2],kconfig_d1x_settings[3]); fprintf(fout,"3=0x%x,0x%x\n",kconfig_d1x_settings[4],kconfig_d1x_settings[5]); fprintf(fout,"4=0x%x,0x%x\n",kconfig_d1x_settings[6],kconfig_d1x_settings[7]); fprintf(fout,"5=0x%x,0x%x\n",kconfig_d1x_settings[8],kconfig_d1x_settings[9]); fprintf(fout,"6=0x%x,0x%x\n",kconfig_d1x_settings[10],kconfig_d1x_settings[11]); fprintf(fout,"7=0x%x,0x%x\n",kconfig_d1x_settings[12],kconfig_d1x_settings[13]); fprintf(fout,"8=0x%x,0x%x\n",kconfig_d1x_settings[14],kconfig_d1x_settings[15]); fprintf(fout,"9=0x%x,0x%x\n",kconfig_d1x_settings[16],kconfig_d1x_settings[17]); fprintf(fout,"0=0x%x,0x%x\n",kconfig_d1x_settings[18],kconfig_d1x_settings[19]); fprintf(fout,"[end]\n"); //end this section change - VR fprintf(fout,"[plx version]\n"); fprintf(fout,"plx version=%s\n",D1X_VERSION); fprintf(fout,"[end]\n"); fprintf(fout,"[end]\n"); } else { int printed=0; #define ADV_WEAPON_ORDER 1 #define NEW_KEYS 2 #define WEAPON_KEYS 4 #define JOYSTICK 8 #define NEWER_KEYS 16 #define WEAPON_ORDER 32 while(!Stop && !feof(fin)) { line=fsplitword(fin,'\n'); strupr(line); if (strstr(line,"PLX VERSION")) // we don't want to keep this { while(!strstr(line,"END")&&!feof(fin)) { free(line); line=fsplitword(fin,'\n'); strupr(line); } free(line); } else if (strstr(line,"WEAPON ORDER")) { fprintf(fout,"[weapon order]\n"); fprintf(fout,"primary=1,2,3,4,5\n"); fprintf(fout,"secondary=%d,%d,%d,%d,%d\n",secondary_order[0], secondary_order[1], secondary_order[2],secondary_order[3], secondary_order[4]); fprintf(fout,"[end]\n"); while(!strstr(line,"END")&&!feof(fin)) { free(line); line=fsplitword(fin,'\n'); strupr(line); } free(line); printed |= WEAPON_ORDER; } //added on 2/5/99 by Victor Rachels for d1x new keys else if (strstr(line,"WEAPON KEYS")) { fprintf(fout,"[weapon keys]\n"); fprintf(fout,"1=0x%x,0x%x\n",kconfig_d1x_settings[0],kconfig_d1x_settings[1]); fprintf(fout,"2=0x%x,0x%x\n",kconfig_d1x_settings[2],kconfig_d1x_settings[3]); fprintf(fout,"3=0x%x,0x%x\n",kconfig_d1x_settings[4],kconfig_d1x_settings[5]); fprintf(fout,"4=0x%x,0x%x\n",kconfig_d1x_settings[6],kconfig_d1x_settings[7]); fprintf(fout,"5=0x%x,0x%x\n",kconfig_d1x_settings[8],kconfig_d1x_settings[9]); fprintf(fout,"6=0x%x,0x%x\n",kconfig_d1x_settings[10],kconfig_d1x_settings[11]); fprintf(fout,"7=0x%x,0x%x\n",kconfig_d1x_settings[12],kconfig_d1x_settings[13]); fprintf(fout,"8=0x%x,0x%x\n",kconfig_d1x_settings[14],kconfig_d1x_settings[15]); fprintf(fout,"9=0x%x,0x%x\n",kconfig_d1x_settings[16],kconfig_d1x_settings[17]); fprintf(fout,"0=0x%x,0x%x\n",kconfig_d1x_settings[18],kconfig_d1x_settings[19]); fprintf(fout,"[end]\n"); while(!strstr(line,"END")&&!feof(fin)) { free(line); line=fsplitword(fin,'\n'); strupr(line); } free(line); printed |= WEAPON_KEYS; } //end this section addition - VR else if (strstr(line,"ADVANCED ORDERING")) { fprintf(fout,"[advanced ordering]\n"); fprintf(fout,"primary=%d,%d,%d,%d,%d\n",primary_order[0], primary_order[1], primary_order[2],primary_order[3], primary_order[4]); fprintf(fout,"primary+=%d,%d,%d,%d,%d,%d,%d,%d\n",primary_order[5],primary_order[6],primary_order[7],primary_order[8],primary_order[9],primary_order[10],primary_order[11],primary_order[12]); fprintf(fout,"secondary=%d,%d,%d,%d,%d\n",secondary_order[0], secondary_order[1], secondary_order[2],secondary_order[3], secondary_order[4]); fprintf(fout,"[end]\n"); while(!strstr(line,"END")&&!feof(fin)) { free(line); line=fsplitword(fin,'\n'); strupr(line); } free(line); printed |= ADV_WEAPON_ORDER; } else if (strstr(line,"CYCLE KEYS")||strstr(line,"NEW KEYS")) { fprintf(fout,"[new keys]\n"); //added/changed on 2/5/99 by Victor Rachels for d1x new keys fprintf(fout,"cycle primary=0x%x,0xff,0x%x\n",kconfig_d1x_settings[20],kconfig_d1x_settings[21]); fprintf(fout,"cycle secondary=0x%x,0xff,0x%x\n",kconfig_d1x_settings[22],kconfig_d1x_settings[23]); fprintf(fout,"autoselect toggle=0x%x,0xff,0x%x\n",kconfig_d1x_settings[24],kconfig_d1x_settings[25]); // fprintf(fout,"cycle primary=0x%x,0x%x,0x%0x\n",kconfig_settings[0][46],kconfig_settings[0][47],kconfig_settings[Config_control_type][27]); // fprintf(fout,"cycle secondary=0x%x,0x%x,0x%x\n",kconfig_settings[0][48],kconfig_settings[0][49],kconfig_settings[Config_control_type][28]); // fprintf(fout,"autoselect toggle=0x%x,0x%x,0x%x\n",kconfig_settings[0][50],kconfig_settings[0][51],kconfig_settings[Config_control_type][29]); //end this section addition - VR fprintf(fout,"[end]\n"); while(!strstr(line,"END")&&!feof(fin)) { free(line); line=fsplitword(fin,'\n'); strupr(line); } free(line); printed |= NEW_KEYS; } else if (strstr(line,"NEWER KEYS")) { fprintf(fout,"[newer keys]\n"); //added/changed on 2/5/99 by Victor Rachels for d1x new keys fprintf(fout,"primary autoselect toggle=0x%x,0xff,0x%x\n",kconfig_d1x_settings[24],kconfig_d1x_settings[25]); fprintf(fout,"secondary autoselect toggle=0x%x,0xff,0x%x\n",kconfig_d1x_settings[26],kconfig_d1x_settings[27]); // fprintf(fout,"primary autoselect toggle=0x%x,0x%x,0x%x\n",kconfig_settings[0][50],kconfig_settings[0][51],kconfig_settings[Config_control_type][29]); // fprintf(fout,"secondary autoselect toggle=0x%x,0x%x,0x%x\n",kconfig_settings[0][52],kconfig_settings[0][53],kconfig_settings[Config_control_type][30]); //end this section addition - VR fprintf(fout,"[end]\n"); while(!strstr(line,"END")&&!feof(fin)) { free(line); line=fsplitword(fin,'\n'); strupr(line); } free(line); printed |= NEWER_KEYS; } else if (strstr(line,"JOYSTICK")) { fprintf(fout,"[joystick]\n"); fprintf(fout,"deadzone=%i\n",joy_deadzone); fprintf(fout,"[end]\n"); while(!strstr(line,"END")&&!feof(fin)) { free(line); line=fsplitword(fin,'\n'); strupr(line); } free(line); printed |= JOYSTICK; } else if (strstr(line,"END")) { Stop=1; free(line); } else { if(line[0]=='['&&!strstr(line,"D1X OPTIONS")) while(!strstr(line,"END") && !feof(fin)) { fprintf(fout,"%s\n",line); free(line); line=fsplitword(fin,'\n'); strupr(line); } fprintf(fout,"%s\n",line); free(line); } if(!Stop&&feof(fin)) Stop=1; } if(!(printed&NEW_KEYS)) { fprintf(fout,"[new keys]\n"); //added/changed on 2/5/99 by Victor Rachels for d1x new keys fprintf(fout,"cycle primary=0x%x,0xff,0x%x\n",kconfig_d1x_settings[20],kconfig_d1x_settings[21]); fprintf(fout,"cycle secondary=0x%x,0xff,0x%x\n",kconfig_d1x_settings[22],kconfig_d1x_settings[23]); fprintf(fout,"autoselect toggle=0x%x,0xff,0x%x\n",kconfig_d1x_settings[24],kconfig_d1x_settings[25]); // fprintf(fout,"cycle primary=0x%x,0x%x,0x%x\n",kconfig_settings[0][46],kconfig_settings[0][47],kconfig_settings[Config_control_type][27]); // fprintf(fout,"cycle secondary=0x%x,0x%x,0x%x\n",kconfig_settings[0][48],kconfig_settings[0][49],kconfig_settings[Config_control_type][28]); // fprintf(fout,"autoselect toggle=0x%x,0x%x,0x%x\n",kconfig_settings[0][50],kconfig_settings[0][51],kconfig_settings[Config_control_type][29]); //end this section addition - VR fprintf(fout,"[end]\n"); } if(!(printed&JOYSTICK)) { fprintf(fout,"[joystick]\n"); fprintf(fout,"deadzone=%i\n",joy_deadzone); fprintf(fout,"[end]\n"); } if(!(printed&WEAPON_ORDER)) { fprintf(fout,"[weapon order]\n"); fprintf(fout,"secondary=%d,%d,%d,%d,%d\n",secondary_order[0], secondary_order[1], secondary_order[2],secondary_order[3], secondary_order[4]); fprintf(fout,"[end]\n"); } if(!(printed&ADV_WEAPON_ORDER)) { fprintf(fout,"[advanced ordering]\n"); fprintf(fout,"primary=%d,%d,%d,%d,%d\n",primary_order[0], primary_order[1], primary_order[2],primary_order[3],primary_order[4]); fprintf(fout,"primary+=%d,%d,%d,%d,%d,%d,%d,%d\n",primary_order[5],primary_order[6],primary_order[7],primary_order[8],primary_order[9],primary_order[10],primary_order[11],primary_order[12]); fprintf(fout,"secondary=%d,%d,%d,%d,%d\n",secondary_order[0], secondary_order[1], secondary_order[2],secondary_order[3], secondary_order[4]); fprintf(fout,"[end]\n"); } if(!(printed&NEWER_KEYS)) { fprintf(fout,"[newer keys]\n"); //added/changed on 2/5/99 by Victor Rachels for d1x new keys fprintf(fout,"primary autoselect toggle=0x%x,0xff,0x%x\n",kconfig_d1x_settings[24],kconfig_d1x_settings[25]); fprintf(fout,"secondary autoselect toggle=0x%x,0xff,0x%x\n",kconfig_d1x_settings[26],kconfig_d1x_settings[27]); // fprintf(fout,"primary autoselect toggle=0x%x,0x%x,0x%x\n",kconfig_settings[0][50],kconfig_settings[0][51],kconfig_settings[Config_control_type][29]); // fprintf(fout,"secondary autoselect toggle=0x%x,0x%x,0x%x\n",kconfig_settings[0][52],kconfig_settings[0][53],kconfig_settings[Config_control_type][30]); //end this section addition - VR fprintf(fout,"[end]\n"); } //added on 2/5/99 by Victor Rachels for d1x new keys if(!(printed&WEAPON_KEYS)) { fprintf(fout,"[weapon keys]\n"); fprintf(fout,"1=0x%x,0x%x\n",kconfig_d1x_settings[0],kconfig_d1x_settings[1]); fprintf(fout,"2=0x%x,0x%x\n",kconfig_d1x_settings[2],kconfig_d1x_settings[3]); fprintf(fout,"3=0x%x,0x%x\n",kconfig_d1x_settings[4],kconfig_d1x_settings[5]); fprintf(fout,"4=0x%x,0x%x\n",kconfig_d1x_settings[6],kconfig_d1x_settings[7]); fprintf(fout,"5=0x%x,0x%x\n",kconfig_d1x_settings[8],kconfig_d1x_settings[9]); fprintf(fout,"6=0x%x,0x%x\n",kconfig_d1x_settings[10],kconfig_d1x_settings[11]); fprintf(fout,"7=0x%x,0x%x\n",kconfig_d1x_settings[12],kconfig_d1x_settings[13]); fprintf(fout,"8=0x%x,0x%x\n",kconfig_d1x_settings[14],kconfig_d1x_settings[15]); fprintf(fout,"9=0x%x,0x%x\n",kconfig_d1x_settings[16],kconfig_d1x_settings[17]); fprintf(fout,"0=0x%x,0x%x\n",kconfig_d1x_settings[18],kconfig_d1x_settings[19]); fprintf(fout,"[end]\n"); } //end this section addition - VR fprintf(fout,"[plx version]\n"); fprintf(fout,"plx version=%s\n",D1X_VERSION); fprintf(fout,"[end]\n"); fprintf(fout,"[end]\n"); fclose(fin); } if (ferror(fout)) rc = errno; fclose(fout); if(rc==0) { unlink(filename); rc = rename(tempfile,filename); } return rc; } else return errno; } extern int screen_width; extern int screen_height; //read in the player's saved games. returns errno (0 == no error) int read_player_file() { char filename[13]; FILE *file; save_info info; int errno_ret = EZERO; Assert(Player_num>=0 && Player_num0) highest_primary++; for(i=0; i0) highest_secondary++; } if (errno_ret==EZERO) { kc_set_controls(); } Game_window_w = info.Game_window_w; // ZICO - read out saved pilot data Game_window_h = info.Game_window_h; VR_render_width = info.Game_window_w; VR_render_height = info.Game_window_h; return errno_ret; } //finds entry for this level in table. if not found, returns ptr to //empty entry. If no empty entries, takes over last one int find_hli_entry() { #ifdef SHAREWARE return 0; #else int i; for (i=0;i highest_levels[i].level_num) highest_levels[i].level_num = levelnum; write_player_file(); } //gets the player's highest level from the file for this mission int get_highest_level(void) { int i; int highest_saturn_level = 0; read_player_file(); #ifndef SHAREWARE #ifndef DEST_SAT if (strlen(Mission_list[Current_mission_num].filename)==0 ) { for (i=0;i i ) i = highest_saturn_level; return i; } //write out player's saved games. returns errno (0 == no error) int write_player_file() { char filename[13]; FILE *file; save_info info; int errno_ret; errno_ret = WriteConfigFile(); info.id = SAVE_FILE_ID; info.saved_game_version = SAVED_GAME_VERSION; info.player_struct_version = PLAYER_STRUCT_VERSION; info.default_difficulty_level = Player_default_difficulty; info.default_leveling_on = Auto_leveling_on; info.Game_window_w = Game_window_w; info.Game_window_h = Game_window_h; info.n_highest_levels = n_highest_levels; sprintf(filename,"%s.plx",Players[Player_num].callsign); strlwr(filename); write_player_d1x(filename); sprintf(filename,"%s.plr",Players[Player_num].callsign); strlwr(filename); file = fopen(filename,"wb"); //check filename if (file && isatty(fileno(file))) { //if the callsign is the name of a tty device, prepend a char fclose(file); sprintf(filename,"$%.7s.plr",Players[Player_num].callsign); strlwr(filename); file = fopen(filename,"wb"); } if (!file) return errno; errno_ret = EZERO; if (fwrite(&info,sizeof(info),1,file) != 1) { errno_ret = errno; fclose(file); return errno_ret; } //write higest level info if ((fwrite(highest_levels, sizeof(hli), n_highest_levels, file) != n_highest_levels)) { errno_ret = errno; fclose(file); return errno_ret; } if (fwrite(saved_games,sizeof(saved_games),1,file) != 1) { errno_ret = errno; fclose(file); return errno_ret; } #ifdef NETWORK if ((fwrite(Network_message_macro, MAX_MESSAGE_LEN, 4, file) != 4)) { errno_ret = errno; fclose(file); return errno_ret; } #else fseek( file, MAX_MESSAGE_LEN * 4, SEEK_CUR ); #endif //write kconfig info { // if (fwrite( kconfig_settings, MAX_CONTROLS*CONTROL_MAX_TYPES, 1, file )!=1) // errno_ret=errno; int i,j; for(i=0;i