void pilotfile::plr_read_controls() { int idx, list_size, list_axis; short id1, id2, id3; int axi, inv; list_size = (int)cfread_ushort(cfp); for (idx = 0; idx < list_size; idx++) { id1 = cfread_short(cfp); id2 = cfread_short(cfp); id3 = cfread_short(cfp); // unused, at the moment if (idx < CCFG_MAX) { Control_config[idx].key_id = id1; Control_config[idx].joy_id = id2; } } list_axis = cfread_int(cfp); for (idx = 0; idx < list_axis; idx++) { axi = cfread_int(cfp); inv = cfread_int(cfp); if (idx < NUM_JOY_AXIS_ACTIONS) { Axis_map_to[idx] = axi; Invert_axis[idx] = inv; } } }
void pilotfile::plr_read_flags() { // tips? p->tips = (int)cfread_ubyte(cfp); // saved flags p->save_flags = cfread_int(cfp); // listing mode (single or campaign missions p->readyroom_listing_mode = cfread_int(cfp); // briefing auto-play p->auto_advance = cfread_int(cfp); // special rank setting (to avoid having to read all stats on verify) // will be the multi rank // if there's a valid CSG, this will be overwritten p->stats.rank = cfread_int(cfp); if (version > 0) { p->player_was_multi = cfread_int(cfp); } else { p->player_was_multi = 0; // Default to single player } // which language was this pilot created with if (version > 1) { cfread_string_len(p->language, sizeof(p->language), cfp); } else { // if we don't know, default to the current language setting lcl_get_language_name(p->language); } }
void pilotfile::plr_read_flags() { // tips? p->tips = (int)cfread_ubyte(cfp); // saved flags p->save_flags = cfread_int(cfp); // listing mode (single or campaign missions p->readyroom_listing_mode = cfread_int(cfp); // briefing auto-play p->auto_advance = cfread_int(cfp); // special rank setting (to avoid having to read all stats on verify) p->stats.rank = cfread_int(cfp); if (version > 0) { p->player_was_multi = cfread_int(cfp); } else { p->player_was_multi = 0; // Default to single player } }
void pilotfile::csg_read_stats() { int idx, list_size = 0; int count; if ( !m_have_info ) { throw "Stats before Info!"; } // scoring stats p->stats.score = cfread_int(cfp); p->stats.rank = cfread_int(cfp); p->stats.assists = cfread_int(cfp); p->stats.kill_count = cfread_int(cfp); p->stats.kill_count_ok = cfread_int(cfp); p->stats.bonehead_kills = cfread_int(cfp); p->stats.p_shots_fired = cfread_uint(cfp); p->stats.p_shots_hit = cfread_uint(cfp); p->stats.p_bonehead_hits = cfread_uint(cfp); p->stats.s_shots_fired = cfread_uint(cfp); p->stats.s_shots_hit = cfread_uint(cfp); p->stats.s_bonehead_hits = cfread_uint(cfp); p->stats.flight_time = cfread_uint(cfp); p->stats.missions_flown = cfread_uint(cfp); p->stats.last_flown = (_fs_time_t)cfread_int(cfp); p->stats.last_backup = (_fs_time_t)cfread_int(cfp); // ship kills (scoring) list_size = (int)ship_list.size(); for (idx = 0; idx < list_size; idx++) { count = cfread_int(cfp); if (ship_list[idx].index >= 0) { p->stats.kills[ship_list[idx].index] = count; } } // medals earned (scoring) list_size = (int)medals_list.size(); for (idx = 0; idx < list_size; idx++) { count = cfread_int(cfp); if (medals_list[idx].index >= 0) { p->stats.medal_counts[medals_list[idx].index] = count; } } }
void pilotfile::plr_read_multiplayer() { // netgame options p->m_server_options.squad_set = cfread_ubyte(cfp); p->m_server_options.endgame_set = cfread_ubyte(cfp); p->m_server_options.flags = cfread_int(cfp); p->m_server_options.respawn = cfread_uint(cfp); p->m_server_options.max_observers = cfread_ubyte(cfp); p->m_server_options.skill_level = cfread_ubyte(cfp); p->m_server_options.voice_qos = cfread_ubyte(cfp); p->m_server_options.voice_token_wait = cfread_int(cfp); p->m_server_options.voice_record_time = cfread_int(cfp); p->m_server_options.mission_time_limit = (fix)cfread_int(cfp); p->m_server_options.kill_limit = cfread_int(cfp); // local options p->m_local_options.flags = cfread_int(cfp); p->m_local_options.obj_update_level = cfread_int(cfp); // netgame protocol Multi_options_g.protocol = cfread_int(cfp); if (Multi_options_g.protocol == NET_VMT) { Multi_options_g.protocol = NET_TCP; } Assert( (Multi_options_g.protocol == NET_IPX) || (Multi_options_g.protocol == NET_TCP) ); }
void pilotfile_convert::csg_import_techroom() { int idx, list_size = 0; bool visible; unsigned char in = 0; // intel entry count int intel_count = cfread_int(cfp); csg->ships_techroom.reserve( csg->ship_list.size() ); csg->weapons_techroom.reserve( csg->weapon_list.size() ); csg->intel_techroom.reserve( intel_count ); // ships list_size = (int)csg->ship_list.size(); for (idx = 0; idx < list_size; idx++) { in = cfread_ubyte(cfp); if (in > 1) { throw std::runtime_error("Data check failure (techroom-ship)!"); } visible = (in == 1) ? true : false; csg->ships_techroom.push_back( visible ); } // weapons list_size = (int)csg->weapon_list.size(); for (idx = 0; idx < list_size; idx++) { in = cfread_ubyte(cfp); if (in > 1) { throw std::runtime_error("Data check failure (techroom-weapon)!"); } visible = (in == 1) ? true : false; csg->weapons_techroom.push_back( visible ); } // intel list_size = intel_count; for (idx = 0; idx < list_size; idx++) { in = cfread_ubyte(cfp); if (in > 1) { throw std::runtime_error("Data check failure (techroom-intel)!"); } visible = (in == 1) ? true : false; csg->intel_techroom.push_back( visible ); } }
void pilotfile_convert::plr_import_red_alert() { int idx, j; char name[35]; if (fver >= 242) { return; } // have to read it, but don't need any of it ... int num_slots = cfread_int(cfp); if ( (num_slots < 0) || (num_slots >= 32) ) { throw "Data check failure in red-alert!"; } if ( !num_slots ) { return; } for (idx = 0; idx < num_slots; idx++) { cfread_string(name, sizeof(name) - 1, cfp); cfread_float(cfp); cfread_string_len(name, sizeof(name), cfp); // subsystem hits for (j = 0; j < 64; j++) { cfread_float(cfp); } // aggregate hits for (j = 0; j < 12; j++) { cfread_float(cfp); } // weapons for (j = 0; j < 12; j++) { cfread_string_len(name, sizeof(name), cfp); cfread_int(cfp); } } }
void pilotfile::csg_read_flags() { // tips? p->tips = (int)cfread_ubyte(cfp); // avoid having to read everything to get the rank if (csg_ver >= 5) { p->stats.rank = cfread_int(cfp); } }
size_t pilot::BinaryFileHandler::startArrayRead(const char*, bool short_index) { Assertion(!_in_array, "Array nesting is not supported!"); _in_array = true; if (short_index) { return (size_t) cfread_short(_cfp); } else { return (size_t) cfread_int(_cfp); } }
void pilotfile::csg_read_variables() { int idx; Campaign.num_variables = cfread_int(cfp); if (Campaign.num_variables > 0) { Campaign.variables = (sexp_variable *) vm_malloc( Campaign.num_variables * sizeof(sexp_variable) ); Verify( Campaign.variables != NULL ); memset( Campaign.variables, 0, Campaign.num_variables * sizeof(sexp_variable) ); for (idx = 0; idx < Campaign.num_variables; idx++) { Campaign.variables[idx].type = cfread_int(cfp); cfread_string_len(Campaign.variables[idx].text, TOKEN_LENGTH, cfp); cfread_string_len(Campaign.variables[idx].variable_name, TOKEN_LENGTH, cfp); } } if (csg_ver < 4) { // CSG files before version 4 don't have a Red Alert set of CPVs to load, so just copy the regular set. Campaign.redalert_num_variables = Campaign.num_variables; Campaign.redalert_variables = (sexp_variable *) vm_malloc( Campaign.redalert_num_variables * sizeof(sexp_variable) ); Verify( Campaign.redalert_variables != NULL); memcpy( Campaign.redalert_variables, Campaign.variables, Campaign.num_variables * sizeof(sexp_variable)); } else { Campaign.redalert_num_variables = cfread_int(cfp); if (Campaign.redalert_num_variables > 0) { Campaign.redalert_variables = (sexp_variable *) vm_malloc( Campaign.redalert_num_variables * sizeof(sexp_variable) ); Verify( Campaign.redalert_variables != NULL ); memset( Campaign.redalert_variables, 0, Campaign.redalert_num_variables * sizeof(sexp_variable) ); for (idx = 0; idx < Campaign.redalert_num_variables; idx++) { Campaign.redalert_variables[idx].type = cfread_int(cfp); cfread_string_len(Campaign.redalert_variables[idx].text, TOKEN_LENGTH, cfp); cfread_string_len(Campaign.redalert_variables[idx].variable_name, TOKEN_LENGTH, cfp); } } } }
void pilotfile::plr_read_hud() { int idx; // flags HUD_config.show_flags = cfread_int(cfp); HUD_config.show_flags2 = cfread_int(cfp); HUD_config.popup_flags = cfread_int(cfp); HUD_config.popup_flags2 = cfread_int(cfp); // settings HUD_config.num_msg_window_lines = cfread_ubyte(cfp); HUD_config.rp_flags = cfread_int(cfp); HUD_config.rp_dist = cfread_int(cfp); // basic colors HUD_config.main_color = cfread_int(cfp); HUD_color_alpha = cfread_int(cfp); if (HUD_color_alpha < HUD_COLOR_ALPHA_USER_MIN) { HUD_color_alpha = HUD_COLOR_ALPHA_DEFAULT; } hud_config_set_color(HUD_config.main_color); // gauge-specific colors int num_gauges = cfread_int(cfp); for (idx = 0; idx < num_gauges; idx++) { ubyte red = cfread_ubyte(cfp); ubyte green = cfread_ubyte(cfp); ubyte blue = cfread_ubyte(cfp); ubyte alpha = cfread_ubyte(cfp); if (idx >= NUM_HUD_GAUGES) { continue; } HUD_config.clr[idx].red = red; HUD_config.clr[idx].green = green; HUD_config.clr[idx].blue = blue; HUD_config.clr[idx].alpha = alpha; } }
void pilotfile_convert::plr_import_variables() { int idx; sexp_variable nvar; int num_variables = cfread_int(cfp); if ( (num_variables < 0) || (num_variables >= 100) ) { throw "Data check failure in variables!"; } plr->variables.reserve(num_variables); for (idx = 0; idx < num_variables; idx++) { nvar.type = cfread_int(cfp); cfread_string_len(nvar.text, sizeof(nvar.text), cfp); cfread_string_len(nvar.variable_name, sizeof(nvar.variable_name), cfp); plr->variables.push_back( nvar ); } }
void pilotfile_convert::plr_import_hud() { int idx; conv_color c; plr->hud_show_flags = cfread_int(cfp); plr->hud_show_flags2 = cfread_int(cfp); plr->hud_popup_flags = cfread_int(cfp); plr->hud_popup_flags2 = cfread_int(cfp); plr->hud_num_lines = cfread_ubyte(cfp); plr->hud_rp_flags = cfread_int(cfp); plr->hud_rp_dist = cfread_int(cfp); for (idx = 0; idx < 39; idx++) { cfread(&c, sizeof(conv_color), 1, cfp); if ( (c.alphacolor != -1) || (c.is_alphacolor != 1) ) { throw "Data check failure in hud!"; } plr->hud_colors[idx][0] = c.red; plr->hud_colors[idx][1] = c.green; plr->hud_colors[idx][2] = c.blue; plr->hud_colors[idx][3] = c.alpha; } }
void pilotfile::plr_read_variables() { int list_size = 0; int idx; sexp_variable n_var; list_size = cfread_int(cfp); if (list_size <= 0) { return; } p->variables.reserve(list_size); for (idx = 0; idx < list_size; idx++) { n_var.type = cfread_int(cfp); cfread_string_len(n_var.text, TOKEN_LENGTH, cfp); cfread_string_len(n_var.variable_name, TOKEN_LENGTH, cfp); p->variables.push_back( n_var ); } }
void pilotfile_convert::csg_import_loadout() { char t_string[50] = { '\0' }; // mission name/status cfread_string_len(t_string, sizeof(t_string), cfp); csg->loadout.filename = t_string; cfread_string_len(t_string, sizeof(t_string), cfp); csg->loadout.last_modified = t_string; // ship pool size_t list_size = csg->ship_list.size(); csg->loadout.ship_pool.reserve(list_size); for (size_t idx = 0; idx < list_size; idx++) { int count = cfread_int(cfp); csg->loadout.ship_pool.push_back( count ); } // weapon pool list_size = csg->weapon_list.size(); csg->loadout.weapon_pool.reserve(list_size); for (size_t idx = 0; idx < list_size; idx++) { int count = cfread_int(cfp); csg->loadout.weapon_pool.push_back( count ); } // loadout info for (size_t idx = 0; idx < MAX_WSS_SLOTS_CONV; idx++) { csg->loadout.slot[idx].ship_index = cfread_int(cfp); for (size_t j = 0; j < MAX_SHIP_WEAPONS_CONV; j++) { csg->loadout.slot[idx].wep[j] = cfread_int(cfp); csg->loadout.slot[idx].wep_count[j] = cfread_int(cfp); } } }
/* * Only used for quick start missions */ void pilotfile::csg_read_lastmissions() { int i; // restore list of most recently played missions Num_recent_missions = cfread_int( cfp ); Assert(Num_recent_missions <= MAX_RECENT_MISSIONS); for ( i = 0; i < Num_recent_missions; i++ ) { char *cp; cfread_string_len( Recent_missions[i], MAX_FILENAME_LEN, cfp); // Remove the extension (safety check: shouldn't exist anyway) cp = strchr(Recent_missions[i], '.'); if (cp) *cp = 0; } }
void pilotfile_convert::plr_import_multiplayer() { plr->multi_squad_set = cfread_ubyte(cfp); plr->multi_endgame_set = cfread_ubyte(cfp); plr->multi_flags = cfread_int(cfp); plr->multi_respawn = cfread_uint(cfp); plr->multi_max_observers = cfread_ubyte(cfp); plr->multi_skill_level = cfread_ubyte(cfp); plr->multi_voice_qos = cfread_ubyte(cfp); plr->multi_voice_token_wait = cfread_int(cfp); plr->multi_voice_record_time = cfread_int(cfp); plr->multi_time_limit = cfread_int(cfp); plr->multi_kill_limit = cfread_int(cfp); plr->multi_local_flags = cfread_int(cfp); plr->multi_local_update_level = cfread_int(cfp); }
void pilotfile_convert::plr_import_loadout() { int idx, j; int s_count, w_count; char name[52]; if (fver >= 242) { return; } // have to read it, but don't need any of it ... cfread_string_len(name, sizeof(name), cfp); // filename cfread_string_len(name, sizeof(name), cfp); // last_modified s_count = cfread_int(cfp); // num ships w_count = cfread_int(cfp); // num weapons // ships for (idx = 0; idx < s_count; idx++) { cfread_int(cfp); // count cfread_string_len(name, sizeof(name), cfp); // name } // weapons for (idx = 0; idx < w_count; idx++) { cfread_int(cfp); // count cfread_string_len(name, sizeof(name), cfp); // name } // loadout info for (idx = 0; idx < 12; idx++) { cfread_int(cfp); // ship class cfread_string_len(name, sizeof(name), cfp); // ship name for (j = 0; j < 12; j++) { cfread_int(cfp); // weapon type cfread_int(cfp); // weapon count cfread_string_len(name, sizeof(name), cfp); // weapon name } } }
void pilotfile_convert::csg_import_stats() { int list_size = 0; int idx; csg->stats.score = cfread_int(cfp); csg->stats.rank = cfread_int(cfp); csg->stats.assists = cfread_int(cfp); csg->stats.medals_earned = csg->medals_list; list_size = (int)csg->stats.medals_earned.size(); for (idx = 0; idx < list_size; idx++) { csg->stats.medals_earned[idx].val = cfread_int(cfp); } csg->stats.ship_kills = csg->ship_list; list_size = cfread_int(cfp); // NOTE: could be less, but never greater than if ( list_size > (int)csg->stats.ship_kills.size() ) { throw std::runtime_error("Data check failure (kills size)!"); } for (idx = 0; idx < list_size; idx++) { csg->stats.ship_kills[idx].val = (int)cfread_ushort(cfp); } csg->stats.kill_count = cfread_int(cfp); csg->stats.kill_count_ok = cfread_int(cfp); csg->stats.p_shots_fired = cfread_uint(cfp); csg->stats.s_shots_fired = cfread_uint(cfp); csg->stats.p_shots_hit = cfread_uint(cfp); csg->stats.s_shots_hit = cfread_uint(cfp); csg->stats.p_bonehead_hits = cfread_uint(cfp); csg->stats.s_bonehead_hits = cfread_uint(cfp); csg->stats.bonehead_kills = cfread_uint(cfp); }
void pilotfile_convert::plr_import_stats() { int idx; char name[35]; if (fver >= 242) { return; } // read everything, but we don't need any of it ... cfread_int(cfp); // score cfread_int(cfp); // rank cfread_int(cfp); // assists // medals for (idx = 0; idx < 18; idx++) { cfread_int(cfp); } // kills per ship int count = cfread_int(cfp); for (idx = 0; idx < count; idx++) { cfread_ushort(cfp); cfread_string_len(name, sizeof(name), cfp); } cfread_int(cfp); // kill_count cfread_int(cfp); // kill_count_ok cfread_uint(cfp); // p_shots_fired cfread_uint(cfp); // s_shots_fired cfread_uint(cfp); // p_shots_hit cfread_uint(cfp); // s_shots_hit cfread_uint(cfp); // p_bonehead_hits cfread_uint(cfp); // s_bonehead_hits cfread_uint(cfp); // bonehead_kills }
std::int32_t pilot::BinaryFileHandler::readInt(const char*) { return cfread_int(_cfp); }
void pilotfile::csg_read_redalert() { int idx, i, j, list_size = 0; int count; char t_string[MAX_FILENAME_LEN+NAME_LENGTH+1] = { '\0' }; float hit; wep_t weapons; if ( !m_have_info ) { throw "RedAlert before Info!"; } list_size = cfread_int(cfp); if (list_size <= 0) { return; } cfread_string_len(t_string, MAX_FILENAME_LEN, cfp); Red_alert_precursor_mission = t_string; for (idx = 0; idx < list_size; idx++) { red_alert_ship_status ras; cfread_string_len(t_string, NAME_LENGTH, cfp); ras.name = t_string; ras.hull = cfread_float(cfp); // ship class, index into ship_list[] i = cfread_int(cfp); if ( (i >= (int)ship_list.size()) || (i < RED_ALERT_LOWEST_VALID_SHIP_CLASS) ) { mprintf(("CSG => Parse Warning: Invalid value for red alert ship index (%d), emptying slot.\n", i)); ras.ship_class = RED_ALERT_DESTROYED_SHIP_CLASS; } else if ( (i < 0 ) && (i >= RED_ALERT_LOWEST_VALID_SHIP_CLASS) ) { // ship destroyed/exited ras.ship_class = i; } else { ras.ship_class = ship_list[i].index; } // subsystem hits count = cfread_int(cfp); for (j = 0; j < count; j++) { hit = cfread_float(cfp); ras.subsys_current_hits.push_back( hit ); } // subsystem aggregate hits count = cfread_int(cfp); for (j = 0; j < count; j++) { hit = cfread_float(cfp); ras.subsys_aggregate_current_hits.push_back( hit ); } // primary weapon loadout and status count = cfread_int(cfp); for (j = 0; j < count; j++) { i = cfread_int(cfp); weapons.index = weapon_list[i].index; weapons.count = cfread_int(cfp); // triggering this means something is really fubar if (weapons.index < 0) { continue; } ras.primary_weapons.push_back( weapons ); } // secondary weapon loadout and status count = cfread_int(cfp); for (j = 0; j < count; j++) { i = cfread_int(cfp); weapons.index = weapon_list[i].index; weapons.count = cfread_int(cfp); // triggering this means something is really fubar if (weapons.index < 0) { continue; } ras.secondary_weapons.push_back( weapons ); } // this is quite likely a *bad* thing if it doesn't happen if (ras.ship_class >= RED_ALERT_LOWEST_VALID_SHIP_CLASS) { Red_alert_wingman_status.push_back( ras ); } } }
void pilotfile::csg_read_loadout() { int j, count, ship_idx = -1, wep_idx = -1; size_t idx, list_size = 0; if ( !m_have_info ) { throw "Loadout before Info!"; } // base info cfread_string_len(Player_loadout.filename, MAX_FILENAME_LEN, cfp); cfread_string_len(Player_loadout.last_modified, DATE_TIME_LENGTH, cfp); // ship pool list_size = ship_list.size(); for (idx = 0; idx < list_size; idx++) { count = cfread_int(cfp); if (ship_list[idx].index >= 0) { Player_loadout.ship_pool[ship_list[idx].index] = count; } } // weapon pool list_size = weapon_list.size(); for (idx = 0; idx < list_size; idx++) { count = cfread_int(cfp); if (weapon_list[idx].index >= 0) { Player_loadout.weapon_pool[weapon_list[idx].index] = count; } } // player ship loadout list_size = (uint)cfread_ushort(cfp); for (uint i = 0; i < list_size; i++) { wss_unit *slot = NULL; if (i < MAX_WSS_SLOTS) { slot = &Player_loadout.unit_data[i]; } // ship ship_idx = cfread_int(cfp); if ( (ship_idx >= (int)ship_list.size()) || (ship_idx < -1) ) { // on the casts, assume that ship & weapon lists will never exceed ~2 billion mprintf(("CSG => Parse Warning: Invalid value for ship index (%d), emptying slot.\n", ship_idx)); ship_idx = -1; } if (slot) { if (ship_idx == -1) { // -1 means no ship in this slot slot->ship_class = -1; } else { slot->ship_class = ship_list[ship_idx].index; } } // primary weapons count = cfread_int(cfp); for (j = 0; j < count; j++) { wep_idx = cfread_int(cfp); if ( (wep_idx >= (int)weapon_list.size()) || (wep_idx < -1) ) { mprintf(("CSG => Parse Warning: Invalid value for primary weapon index (%d), emptying slot.\n", wep_idx)); wep_idx = -1; } if ( slot && (j < MAX_SHIP_PRIMARY_BANKS) ) { if (wep_idx == -1) { // -1 means no weapon in this slot slot->wep[j] = -1; } else { slot->wep[j] = weapon_list[wep_idx].index; } } int read_idx = cfread_int(cfp); if ( slot && (j < MAX_SHIP_PRIMARY_BANKS) ) { slot->wep_count[j] = read_idx; } } // secondary weapons count = cfread_int(cfp); for (j = 0; j < count; j++) { wep_idx = cfread_int(cfp); if ( (wep_idx >= (int)weapon_list.size()) || (wep_idx < -1) ) { mprintf(("CSG => Parse Warning: Invalid value for secondary weapon index (%d), emptying slot.\n", wep_idx)); wep_idx = -1; } if ( slot && (j < MAX_SHIP_SECONDARY_BANKS) ) { if (wep_idx == -1) { // -1 means no weapon in this slot slot->wep[j+MAX_SHIP_PRIMARY_BANKS] = -1; } else { slot->wep[j+MAX_SHIP_PRIMARY_BANKS] = weapon_list[wep_idx].index; } } int read_idx = cfread_int(cfp); if ( slot && (j < MAX_SHIP_SECONDARY_BANKS) ) { slot->wep_count[j+MAX_SHIP_PRIMARY_BANKS] = read_idx; } } } }
void pilotfile_convert::plr_import_detail() { bool data_failure = false; plr->detail_setting = cfread_int(cfp); plr->detail_nebula = cfread_int(cfp); plr->detail_distance = cfread_int(cfp); plr->detail_hardware_textures = cfread_int(cfp); plr->detail_num_debris = cfread_int(cfp); plr->detail_num_particles = cfread_int(cfp); plr->detail_num_stars = cfread_int(cfp); plr->detail_shield_effects = cfread_int(cfp); plr->detail_lighting = cfread_int(cfp); plr->detail_targetview_model = cfread_int(cfp); plr->detail_planets_suns = cfread_int(cfp); plr->detail_weapon_extras = cfread_int(cfp); if ( (plr->detail_setting < -1) || (plr->detail_setting > 4) ) { data_failure = true; } else if ( (plr->detail_nebula < 0) || (plr->detail_nebula > 4) ) { data_failure = true; } else if ( (plr->detail_distance < 0) || (plr->detail_distance > 4) ) { data_failure = true; } else if ( (plr->detail_hardware_textures < 0) || (plr->detail_hardware_textures > 4) ) { data_failure = true; } else if ( (plr->detail_num_debris < 0) || (plr->detail_num_debris > 4) ) { data_failure = true; } else if ( (plr->detail_num_particles < 0) || (plr->detail_num_particles > 4) ) { data_failure = true; } else if ( (plr->detail_num_stars < 0) || (plr->detail_num_stars > 4) ) { data_failure = true; } else if ( (plr->detail_shield_effects < 0) || (plr->detail_shield_effects > 4) ) { data_failure = true; } else if ( (plr->detail_lighting < 0) || (plr->detail_lighting > 4) ) { data_failure = true; } else if ( (plr->detail_targetview_model < 0) || (plr->detail_targetview_model > 1) ) { data_failure = true; } else if ( (plr->detail_planets_suns < 0) || (plr->detail_planets_suns > 1) ) { data_failure = true; } else if ( (plr->detail_weapon_extras < 0) || (plr->detail_weapon_extras > 1) ) { data_failure = true; } if (data_failure) { throw "Data check failure in details!"; } }
void pilotfile::csg_read_missions() { int i, j, idx, list_size; cmission *missionp; if ( !m_have_info ) { throw "Missions before Info!"; } for (i = 0; i < Campaign.num_missions_completed; i++) { idx = cfread_int(cfp); missionp = &Campaign.missions[idx]; missionp->completed = 1; // flags missionp->flags = cfread_int(cfp); // goals missionp->num_goals = cfread_int(cfp); if (missionp->num_goals > 0) { missionp->goals = (mgoal *) vm_malloc( missionp->num_goals * sizeof(mgoal) ); Verify( missionp->goals != NULL ); memset( missionp->goals, 0, missionp->num_goals * sizeof(mgoal) ); for (j = 0; j < missionp->num_goals; j++) { cfread_string_len(missionp->goals[j].name, NAME_LENGTH, cfp); missionp->goals[j].status = cfread_char(cfp); } } // events missionp->num_events = cfread_int(cfp); if (missionp->num_events > 0) { missionp->events = (mevent *) vm_malloc( missionp->num_events * sizeof(mevent) ); Verify( missionp->events != NULL ); memset( missionp->events, 0, missionp->num_events * sizeof(mevent) ); for (j = 0; j < missionp->num_events; j++) { cfread_string_len(missionp->events[j].name, NAME_LENGTH, cfp); missionp->events[j].status = cfread_char(cfp); } } // variables missionp->num_variables = cfread_int(cfp); if (missionp->num_variables > 0) { missionp->variables = (sexp_variable *) vm_malloc( missionp->num_variables * sizeof(sexp_variable) ); Verify( missionp->variables != NULL ); memset( missionp->variables, 0, missionp->num_variables * sizeof(sexp_variable) ); for (j = 0; j < missionp->num_variables; j++) { missionp->variables[j].type = cfread_int(cfp); cfread_string_len(missionp->variables[j].text, TOKEN_LENGTH, cfp); cfread_string_len(missionp->variables[j].variable_name, TOKEN_LENGTH, cfp); } } // scoring stats missionp->stats.score = cfread_int(cfp); missionp->stats.rank = cfread_int(cfp); missionp->stats.assists = cfread_int(cfp); missionp->stats.kill_count = cfread_int(cfp); missionp->stats.kill_count_ok = cfread_int(cfp); missionp->stats.bonehead_kills = cfread_int(cfp); missionp->stats.p_shots_fired = cfread_uint(cfp); missionp->stats.p_shots_hit = cfread_uint(cfp); missionp->stats.p_bonehead_hits = cfread_uint(cfp); missionp->stats.s_shots_fired = cfread_uint(cfp); missionp->stats.s_shots_hit = cfread_uint(cfp); missionp->stats.s_bonehead_hits = cfread_uint(cfp); // ship kills (scoring) list_size = (int)ship_list.size(); for (j = 0; j < list_size; j++) { idx = cfread_int(cfp); if (ship_list[j].index >= 0) { missionp->stats.kills[ship_list[j].index] = idx; } } // medals (scoring) list_size = (int)medals_list.size(); for (j = 0; j < list_size; j++) { idx = cfread_int(cfp); if (medals_list[j].index >= 0) { missionp->stats.medal_counts[medals_list[j].index] = idx; } } } }
void pilotfile_convert::plr_import() { char name[35]; int idx; unsigned int plr_id = cfread_uint(cfp); if (plr_id != 0x46505346) { throw "Invalid file signature!"; } fver = cfread_uint(cfp); if ( (fver != 142) && (fver != 242) ) { throw "Unsupported file version!"; } // multi flag plr->is_multi = (int)cfread_ubyte(cfp); // rank plr->rank = cfread_int(cfp); // mainhall, don't need it if (fver < 242) { cfread_ubyte(cfp); } plr->tips = cfread_int(cfp); if ( (plr->tips < 0) || (plr->tips > 1) ) { throw "Data check failure!"; } cfread_string_len(plr->image_filename, sizeof(plr->image_filename), cfp); cfread_string_len(plr->squad_name, sizeof(plr->squad_name), cfp); cfread_string_len(plr->squad_filename, sizeof(plr->squad_filename), cfp); cfread_string_len(plr->current_campaign, sizeof(plr->current_campaign), cfp); cfread_string_len(plr->last_ship_flown, sizeof(plr->last_ship_flown), cfp); // controls plr_import_controls(); // hud config plr_import_hud(); // cutscenes, don't need it if (fver < 242) { cfread_int(cfp); } // volume stuff plr->sound_volume = cfread_float(cfp); plr->music_volume = cfread_float(cfp); plr->voice_volume = cfread_float(cfp); // detail settings plr_import_detail(); // recent missions, don't need it int num_missions = cfread_int(cfp); for (idx = 0; idx < num_missions; idx++) { cfread_string_len(name, sizeof(name), cfp); } // stats, will skip if fver < 242 plr_import_stats(); plr->skill_level = cfread_int(cfp); if ( (plr->skill_level < 0) || (plr->skill_level > 4) ) { throw "Data check failure!"; } // extra joystick stuff for (idx = 0; idx < 5; idx++) { plr->joy_axis_map_to[idx] = cfread_int(cfp); plr->joy_invert_axis[idx] = cfread_int(cfp); } // flags plr->save_flags = cfread_int(cfp); // loadout, will skip if fver < 242 plr_import_loadout(); // multiplayer plr_import_multiplayer(); // two briefing related values plr->readyroom_listing_mode = cfread_int(cfp); Briefing_voice_enabled = cfread_int(cfp); plr->net_protocol = cfread_int(cfp); // protocol must be set to something if (plr->net_protocol == NET_NONE) { plr->net_protocol = NET_TCP; } else if ( (plr->net_protocol < 0) || (plr->net_protocol > NET_VMT) ) { throw "Data check failure!"; } // red alert status, will skip if fver < 242 (and should be empty if multi) plr_import_red_alert(); // briefing auto-advance plr->auto_advance = cfread_int(cfp); if ( (plr->auto_advance < 0) || (plr->auto_advance > 1) ) { throw "Data check failure!"; } // some input options plr->Use_mouse_to_fly = cfread_int(cfp); plr->Mouse_sensitivity = cfread_int(cfp); plr->Joy_sensitivity = cfread_int(cfp); plr->Dead_zone_size = cfread_int(cfp); // variables plr_import_variables(); // and... we're done! :) }
void pilotfile::plr_read_stats_multi() { int idx, j, list_size = 0; index_list_t ilist; char t_string[NAME_LENGTH+1]; // global, all-time stats (used only until campaign stats are loaded) multi_stats.score = cfread_int(cfp); multi_stats.rank = cfread_int(cfp); multi_stats.assists = cfread_int(cfp); multi_stats.kill_count = cfread_int(cfp); multi_stats.kill_count_ok = cfread_int(cfp); multi_stats.bonehead_kills = cfread_int(cfp); multi_stats.p_shots_fired = cfread_uint(cfp); multi_stats.p_shots_hit = cfread_uint(cfp); multi_stats.p_bonehead_hits = cfread_uint(cfp); multi_stats.s_shots_fired = cfread_uint(cfp); multi_stats.s_shots_hit = cfread_uint(cfp); multi_stats.s_bonehead_hits = cfread_uint(cfp); multi_stats.flight_time = cfread_uint(cfp); multi_stats.missions_flown = cfread_uint(cfp); multi_stats.last_flown = (_fs_time_t)cfread_int(cfp); multi_stats.last_backup = (_fs_time_t)cfread_int(cfp); // ship kills (contains ships across all mods, not just current) list_size = cfread_int(cfp); multi_stats.ship_kills.reserve(list_size); for (idx = 0; idx < list_size; idx++) { cfread_string_len(t_string, NAME_LENGTH, cfp); ilist.name = t_string; ilist.index = ship_info_lookup(t_string); ilist.val = cfread_int(cfp); multi_stats.ship_kills.push_back(ilist); } // medals earned (contains medals across all mods, not just current) list_size = cfread_int(cfp); multi_stats.medals_earned.reserve(list_size); for (idx = 0; idx < list_size; idx++) { cfread_string_len(t_string, NAME_LENGTH,cfp); ilist.name = t_string; ilist.index = medals_info_lookup(t_string); ilist.val = cfread_int(cfp); multi_stats.medals_earned.push_back(ilist); } // if in multiplayer mode then set these stats as the player stats if (Game_mode & GM_MULTIPLAYER) { p->stats.score = multi_stats.score; p->stats.rank = multi_stats.rank; p->stats.assists = multi_stats.assists; p->stats.kill_count = multi_stats.kill_count; p->stats.kill_count_ok = multi_stats.kill_count_ok; p->stats.bonehead_kills = multi_stats.bonehead_kills; p->stats.p_shots_fired = multi_stats.p_shots_fired; p->stats.p_shots_hit = multi_stats.p_shots_hit; p->stats.p_bonehead_hits = multi_stats.p_bonehead_hits; p->stats.s_shots_fired = multi_stats.s_shots_fired; p->stats.s_shots_hit = multi_stats.s_shots_hit; p->stats.s_bonehead_hits = multi_stats.s_bonehead_hits; p->stats.flight_time = multi_stats.flight_time; p->stats.missions_flown = multi_stats.missions_flown; p->stats.last_flown = multi_stats.last_flown; p->stats.last_backup = multi_stats.last_backup; // ship kills (have to find ones that match content) list_size = (int)multi_stats.ship_kills.size(); for (idx = 0; idx < list_size; idx++) { j = multi_stats.ship_kills[idx].index; if (j >= 0) { p->stats.kills[j] = multi_stats.ship_kills[idx].val; } } // medals earned (have to fine ones that match content) list_size = (int)multi_stats.medals_earned.size(); for (idx = 0; idx < list_size; idx++) { j = multi_stats.medals_earned[idx].index; if (j >= 0) { p->stats.medals[j] = multi_stats.medals_earned[idx].val; } } } }
void pilotfile::csg_read_info() { char t_string[NAME_LENGTH+1] = { '\0' }; index_list_t ilist; int idx, list_size = 0; ubyte allowed = 0; if ( !m_have_flags ) { throw "Info before Flags!"; } // // NOTE: lists may contain missing/invalid entries for current data // this is not necessarily fatal // // ship list (NOTE: may contain more than MAX_SHIP_CLASSES) list_size = cfread_int(cfp); for (idx = 0; idx < list_size; idx++) { cfread_string_len(t_string, NAME_LENGTH, cfp); ilist.name = t_string; ilist.index = ship_info_lookup(t_string); ship_list.push_back(ilist); } // weapon list (NOTE: may contain more than MAX_WEAPON_TYPES) list_size = cfread_int(cfp); for (idx = 0; idx < list_size; idx++) { cfread_string_len(t_string, NAME_LENGTH, cfp); ilist.name = t_string; ilist.index = weapon_info_lookup(t_string); weapon_list.push_back(ilist); } // intel list (NOTE: may contain more than MAX_INTEL_ENTRIES) list_size = cfread_int(cfp); for (idx = 0; idx < list_size; idx++) { cfread_string_len(t_string, NAME_LENGTH, cfp); ilist.name = t_string; ilist.index = intel_info_lookup(t_string); intel_list.push_back(ilist); } // medals list (NOTE: may contain more than Num_medals) list_size = cfread_int(cfp); for (idx = 0; idx < list_size; idx++) { cfread_string_len(t_string, NAME_LENGTH, cfp); ilist.name = t_string; ilist.index = medals_info_lookup(t_string); medals_list.push_back(ilist); } // last ship flown (index into ship_list) idx = cfread_int(cfp); // check the idx is within bounds Assertion ((idx < (int)ship_list.size()), "Campaign file contains an incorrect value for the last flown ship class. No data in ship_list for ship number %d.", idx); if (idx >= (int)ship_list.size()) idx = -1; else if (idx != -1) p->last_ship_flown_si_index = ship_list[idx].index; else p->last_ship_flown_si_index = -1; // progression state Campaign.prev_mission = cfread_int(cfp); Campaign.next_mission = cfread_int(cfp); // loop state Campaign.loop_reentry = cfread_int(cfp); Campaign.loop_enabled = cfread_int(cfp); // missions completed Campaign.num_missions_completed = cfread_int(cfp); // allowed ships list_size = (int)ship_list.size(); for (idx = 0; idx < list_size; idx++) { allowed = cfread_ubyte(cfp); if (allowed) { if (ship_list[idx].index >= 0) { Campaign.ships_allowed[ship_list[idx].index] = 1; } else { m_data_invalid = true; } } } // allowed weapons list_size = (int)weapon_list.size(); for (idx = 0; idx < list_size; idx++) { allowed = cfread_ubyte(cfp); if (allowed) { if (weapon_list[idx].index >= 0) { Campaign.weapons_allowed[weapon_list[idx].index] = 1; } else { m_data_invalid = true; } } } if (csg_ver >= 2) { // single/campaign squad name & image cfread_string_len(p->s_squad_name, NAME_LENGTH, cfp); cfread_string_len(p->s_squad_filename, MAX_FILENAME_LEN, cfp); } // if anything we need/use was missing then it should be considered fatal if (m_data_invalid) { throw "Invalid data for CSG!"; } }
void pilotfile::plr_read_settings() { // sound/voice/music Master_sound_volume = cfread_float(cfp); Master_event_music_volume = cfread_float(cfp); Master_voice_volume = cfread_float(cfp); audiostream_set_volume_all(Master_voice_volume, ASF_VOICE); audiostream_set_volume_all(Master_event_music_volume, ASF_EVENTMUSIC); if (Master_event_music_volume > 0.0f) { Event_music_enabled = 1; } else { Event_music_enabled = 0; } Briefing_voice_enabled = cfread_int(cfp); // skill level Game_skill_level = cfread_int(cfp); // input options Use_mouse_to_fly = cfread_int(cfp); Mouse_sensitivity = cfread_int(cfp); Joy_sensitivity = cfread_int(cfp); Dead_zone_size = cfread_int(cfp); // detail Detail.setting = cfread_int(cfp); Detail.nebula_detail = cfread_int(cfp); Detail.detail_distance = cfread_int(cfp); Detail.hardware_textures = cfread_int(cfp); Detail.num_small_debris = cfread_int(cfp); Detail.num_particles = cfread_int(cfp); Detail.num_stars = cfread_int(cfp); Detail.shield_effects = cfread_int(cfp); Detail.lighting = cfread_int(cfp); Detail.targetview_model = cfread_int(cfp); Detail.planets_suns = cfread_int(cfp); Detail.weapon_extras = cfread_int(cfp); }
void pilotfile::csg_read_settings() { // sound/voice/music Master_sound_volume = cfread_float(cfp); Master_event_music_volume = cfread_float(cfp); Master_voice_volume = cfread_float(cfp); audiostream_set_volume_all(Master_voice_volume, ASF_VOICE); audiostream_set_volume_all(Master_event_music_volume, ASF_EVENTMUSIC); if (Master_event_music_volume > 0.0f) { Event_music_enabled = 1; } else { Event_music_enabled = 0; } Briefing_voice_enabled = cfread_int(cfp); // skill level Game_skill_level = cfread_int(cfp); // input options Use_mouse_to_fly = cfread_int(cfp); Mouse_sensitivity = cfread_int(cfp); Joy_sensitivity = cfread_int(cfp); Joy_dead_zone_size = cfread_int(cfp); if (csg_ver < 3) { // detail int dummy __UNUSED = cfread_int(cfp); dummy = cfread_int(cfp); dummy = cfread_int(cfp); dummy = cfread_int(cfp); dummy = cfread_int(cfp); dummy = cfread_int(cfp); dummy = cfread_int(cfp); dummy = cfread_int(cfp); dummy = cfread_int(cfp); dummy = cfread_int(cfp); dummy = cfread_int(cfp); dummy = cfread_int(cfp); } }