void pilotfile_convert::plr_export_hud() { int idx; startSection(Section::HUD); // flags cfwrite_int(plr->hud_show_flags, cfp); cfwrite_int(plr->hud_show_flags2, cfp); cfwrite_int(plr->hud_popup_flags, cfp); cfwrite_int(plr->hud_popup_flags2, cfp); // settings cfwrite_ubyte(plr->hud_num_lines, cfp); cfwrite_int(plr->hud_rp_flags, cfp); cfwrite_int(plr->hud_rp_dist, cfp); // basic colors cfwrite_int(0, cfp); // color cfwrite_int(8, cfp); // alpha // gauge-specific colors cfwrite_int(39, cfp); for (idx = 0; idx < 39; idx++) { cfwrite_ubyte(plr->hud_colors[idx][0], cfp); cfwrite_ubyte(plr->hud_colors[idx][1], cfp); cfwrite_ubyte(plr->hud_colors[idx][2], cfp); cfwrite_ubyte(plr->hud_colors[idx][3], cfp); } endSection(); }
void pilotfile_convert::plr_export_multiplayer() { startSection(Section::Multiplayer); // netgame options cfwrite_ubyte(plr->multi_squad_set, cfp); cfwrite_ubyte(plr->multi_endgame_set, cfp); cfwrite_int(plr->multi_flags, cfp); cfwrite_uint(plr->multi_respawn, cfp); cfwrite_ubyte(plr->multi_max_observers, cfp); cfwrite_ubyte(plr->multi_skill_level, cfp); cfwrite_ubyte(plr->multi_voice_qos, cfp); cfwrite_int(plr->multi_voice_token_wait, cfp); cfwrite_int(plr->multi_voice_record_time, cfp); cfwrite_int(plr->multi_time_limit, cfp); cfwrite_int(plr->multi_kill_limit, cfp); // local options cfwrite_int(plr->multi_local_flags, cfp); cfwrite_int(plr->multi_local_update_level, cfp); // netgame protocol cfwrite_int(plr->net_protocol, cfp); endSection(); }
void pilotfile::plr_write_hud() { int idx; startSection(Section::HUD); // flags cfwrite_int(HUD_config.show_flags, cfp); cfwrite_int(HUD_config.show_flags2, cfp); cfwrite_int(HUD_config.popup_flags, cfp); cfwrite_int(HUD_config.popup_flags2, cfp); // settings cfwrite_ubyte(HUD_config.num_msg_window_lines, cfp); cfwrite_int(HUD_config.rp_flags, cfp); cfwrite_int(HUD_config.rp_dist, cfp); // basic colors cfwrite_int(HUD_config.main_color, cfp); cfwrite_int(HUD_color_alpha, cfp); // gauge-specific colors cfwrite_int(NUM_HUD_GAUGES, cfp); for (idx = 0; idx < NUM_HUD_GAUGES; idx++) { cfwrite_ubyte(HUD_config.clr[idx].red, cfp); cfwrite_ubyte(HUD_config.clr[idx].green, cfp); cfwrite_ubyte(HUD_config.clr[idx].blue, cfp); cfwrite_ubyte(HUD_config.clr[idx].alpha, cfp); } endSection(); }
void pilotfile_convert::csg_export_techroom() { int list_size = 0; int idx; ubyte visible; startSection(Section::Techroom); // visible ships list_size = (int)csg->ships_techroom.size(); for (idx = 0; idx < list_size; idx++) { visible = csg->ships_techroom[idx] ? 1 : 0; cfwrite_ubyte(visible, cfp); } // visible weapons list_size = (int)csg->weapons_techroom.size(); for (idx = 0; idx < list_size; idx++) { visible = csg->weapons_techroom[idx] ? 1 : 0; cfwrite_ubyte(visible, cfp); } // visible intel entries list_size = (int)csg->intel_techroom.size(); for (idx = 0; idx < list_size; idx++) { visible = csg->intel_techroom[idx] ? 1 : 0; cfwrite_ubyte(visible, cfp); } endSection(); }
void pilotfile::plr_write_multiplayer() { startSection(Section::Multiplayer); // netgame options cfwrite_ubyte(p->m_server_options.squad_set, cfp); cfwrite_ubyte(p->m_server_options.endgame_set, cfp); cfwrite_int(p->m_server_options.flags, cfp); cfwrite_uint(p->m_server_options.respawn, cfp); cfwrite_ubyte(p->m_server_options.max_observers, cfp); cfwrite_ubyte(p->m_server_options.skill_level, cfp); cfwrite_ubyte(p->m_server_options.voice_qos, cfp); cfwrite_int(p->m_server_options.voice_token_wait, cfp); cfwrite_int(p->m_server_options.voice_record_time, cfp); cfwrite_int((int)p->m_server_options.mission_time_limit, cfp); cfwrite_int(p->m_server_options.kill_limit, cfp); // local options cfwrite_int(p->m_local_options.flags, cfp); cfwrite_int(p->m_local_options.obj_update_level, cfp); // netgame protocol cfwrite_int(Multi_options_g.protocol, cfp); endSection(); }
void pilotfile::plr_write_flags() { startSection(Section::Flags); // tips cfwrite_ubyte((unsigned char)p->tips, cfp); // saved flags cfwrite_int(p->save_flags, cfp); // listing mode (single or campaign missions) cfwrite_int(p->readyroom_listing_mode, cfp); // briefing auto-play cfwrite_int(p->auto_advance, cfp); // special rank setting (to avoid having to read all stats on verify) // should be multi only from now on cfwrite_int(multi_stats.rank, cfp); // What game mode we were in last on this pilot cfwrite_int(p->player_was_multi, cfp); // which language was this pilot created with cfwrite_string_len(p->language, cfp); endSection(); }
void pilotfile::csg_write_techroom() { int idx; ubyte visible; startSection(Section::Techroom); // visible ships for (auto it = Ship_info.cbegin(); it != Ship_info.cend(); ++it) { if ((it->flags[Ship::Info_Flags::In_tech_database]) && !(it->flags[Ship::Info_Flags::Default_in_tech_database])) { visible = 1; } else { visible = 0; } cfwrite_ubyte(visible, cfp); } // visible weapons for (idx = 0; idx < Num_weapon_types; idx++) { // only visible if not in techroom by default if ( (Weapon_info[idx].wi_flags & WIF_IN_TECH_DATABASE) && !(Weapon_info[idx].wi_flags2 & WIF2_DEFAULT_IN_TECH_DATABASE) ) { visible = 1; } else { visible = 0; } cfwrite_ubyte(visible, cfp); } // visible intel entries for (idx = 0; idx < Intel_info_size; idx++) { // only visible if not in techroom by default if ( (Intel_info[idx].flags & IIF_IN_TECH_DATABASE) && !(Intel_info[idx].flags & IIF_DEFAULT_IN_TECH_DATABASE) ) { visible = 1; } else { visible = 0; } cfwrite_ubyte(visible, cfp); } endSection(); }
void pilotfile::csg_write_techroom() { int idx; ubyte visible; startSection(Section::Techroom); // visible ships for (idx = 0; idx < Num_ship_classes; idx++) { // only visible if not in techroom by default if ( (Ship_info[idx].flags & SIF_IN_TECH_DATABASE) && !(Ship_info[idx].flags2 & SIF2_DEFAULT_IN_TECH_DATABASE) ) { visible = 1; } else { visible = 0; } cfwrite_ubyte(visible, cfp); } // visible weapons for (idx = 0; idx < Num_weapon_types; idx++) { // only visible if not in techroom by default if ( (Weapon_info[idx].wi_flags & WIF_IN_TECH_DATABASE) && !(Weapon_info[idx].wi_flags2 & WIF2_DEFAULT_IN_TECH_DATABASE) ) { visible = 1; } else { visible = 0; } cfwrite_ubyte(visible, cfp); } // visible intel entries for (idx = 0; idx < Intel_info_size; idx++) { // only visible if not in techroom by default if ( (Intel_info[idx].flags & IIF_IN_TECH_DATABASE) && !(Intel_info[idx].flags & IIF_DEFAULT_IN_TECH_DATABASE) ) { visible = 1; } else { visible = 0; } cfwrite_ubyte(visible, cfp); } endSection(); }
void pilotfile_convert::csg_export_flags() { startSection(Section::Flags); // tips cfwrite_ubyte((ubyte)plr->tips, cfp); // special rank cfwrite_int(csg->stats.rank, cfp); endSection(); }
void pilotfile::csg_write_flags() { startSection(Section::Flags); // tips cfwrite_ubyte((ubyte)p->tips, cfp); // avoid having to read everything to get the rank cfwrite_int(p->stats.rank, cfp); endSection(); }
void pilotfile_convert::plr_export_flags() { startSection(Section::Flags); // tips cfwrite_ubyte((unsigned char)plr->tips, cfp); // saved flags cfwrite_int(plr->save_flags, cfp); // listing mode (single or campaign missions) cfwrite_int(plr->readyroom_listing_mode, cfp); // briefing auto-play cfwrite_int(plr->auto_advance, cfp); // special rank setting (to avoid having to read all stats on verify) cfwrite_int(plr->rank, cfp); // What game mode we were in last on this pilot cfwrite_int(plr->is_multi, cfp); endSection(); }
void pilotfile_convert::plr_export() { Assert( cfp != NULL ); // header and version cfwrite_int(PLR_FILE_ID, cfp); cfwrite_ubyte(PLR_VERSION, cfp); // flags and info sections go first plr_export_flags(); plr_export_info(); // everything else is next, not order specific plr_export_stats(); plr_export_stats_multi(); plr_export_hud(); plr_export_variables(); plr_export_multiplayer(); plr_export_controls(); plr_export_settings(); // and... we're done! :) }
void pilotfile_convert::csg_export() { Assert( cfp != NULL ); // header and version cfwrite_int(CSG_FILE_ID, cfp); cfwrite_ubyte(CSG_VERSION, cfp); // flags and info sections go first csg_export_flags(); csg_export_info(); // everything else is next, not order specific csg_export_missions(); csg_export_techroom(); csg_export_loadout(); csg_export_stats(); csg_export_redalert(); csg_export_hud(); csg_export_variables(); csg_export_cutscenes(); // and... we're done! :) }
bool pilotfile::save_player(player *_p) { // never save a pilot file for the standalone server in multiplayer if ( (Game_mode & GM_MULTIPLAYER) && (Game_mode & GM_STANDALONE_SERVER) ) { return false; } // set player ptr first thing p = _p; if ( !p ) { Assert( (Player_num >= 0) && (Player_num < MAX_PLAYERS) ); p = &Players[Player_num]; } if ( !strlen(p->callsign) ) { return false; } filename = p->callsign; filename += ".plr"; if ( filename.size() == 4 ) { mprintf(("PLR => Invalid filename '%s'!\n", filename.c_str())); return false; } // open it, hopefully... cfp = cfopen((char*)filename.c_str(), "wb", CFILE_NORMAL, CF_TYPE_PLAYERS); if ( !cfp ) { mprintf(("PLR => Unable to open '%s' for saving!\n", filename.c_str())); return false; } // header and version cfwrite_int(PLR_FILE_ID, cfp); cfwrite_ubyte(PLR_VERSION, cfp); mprintf(("PLR => Saving '%s' with version %d...\n", filename.c_str(), (int)PLR_VERSION)); // flags and info sections go first mprintf(("PLR => Saving: Flags...\n")); plr_write_flags(); mprintf(("PLR => Saving: Info...\n")); plr_write_info(); // everything else is next, not order specific mprintf(("PLR => Saving: Scoring...\n")); plr_write_stats(); mprintf(("PLR => Saving: ScoringMulti...\n")); plr_write_stats_multi(); mprintf(("PLR => Saving: HUD...\n")); plr_write_hud(); mprintf(("PLR => Saving: Variables...\n")); plr_write_variables(); mprintf(("PLR => Saving: Multiplayer...\n")); plr_write_multiplayer(); mprintf(("PLR => Saving: Controls...\n")); plr_write_controls(); mprintf(("PLR => Saving: Settings...\n")); plr_write_settings(); // Done! mprintf(("PLR => Saving complete!\n")); plr_close(); return true; }
void pilotfile_convert::csg_export_info() { int list_size = 0; int idx; ubyte visible; startSection(Section::Info); // ship list list_size = (int)csg->ship_list.size(); cfwrite_int(list_size, cfp); for (idx = 0; idx < list_size; idx++) { cfwrite_string_len(csg->ship_list[idx].name.c_str(), cfp); } // weapon list list_size = (int)csg->weapon_list.size(); cfwrite_int(list_size, cfp); for (idx = 0; idx < list_size; idx++) { cfwrite_string_len(csg->weapon_list[idx].name.c_str(), cfp); } // intel list list_size = (int)csg->intel_list.size(); cfwrite_int(list_size, cfp); for (idx = 0; idx < list_size; idx++) { cfwrite_string_len(csg->intel_list[idx].name.c_str(), cfp); } // medals list list_size = (int)csg->stats.medals_earned.size(); cfwrite_int(list_size, cfp); for (idx = 0; idx < list_size; idx++) { cfwrite_string_len(csg->stats.medals_earned[idx].name.c_str(), cfp); } // last ship flown cfwrite_int(csg->last_ship_flown_index, cfp); // progression state cfwrite_int(csg->prev_mission, cfp); cfwrite_int(csg->next_mission, cfp); // loop state cfwrite_int(csg->loop_enabled, cfp); cfwrite_int(csg->loop_reentry, cfp); // missions completed list_size = (int)csg->missions.size(); cfwrite_int(list_size, cfp); // allowed ships list_size = (int)csg->ships_allowed.size(); for (idx = 0; idx < list_size; idx++) { visible = csg->ships_allowed[idx] ? 1 : 0; cfwrite_ubyte(visible, cfp); } // allowed weapons list_size = (int)csg->weapons_allowed.size(); for (idx = 0; idx < list_size; idx++) { visible = csg->weapons_allowed[idx] ? 1 : 0; cfwrite_ubyte(visible, cfp); } // single/campaign squad name & image, make it the same as multi cfwrite_string_len(plr->squad_name, cfp); cfwrite_string_len(plr->squad_filename, cfp); endSection(); }
bool pilotfile::save_savefile() { char base[_MAX_FNAME] = { '\0' }; std::ostringstream buf; if (Game_mode & GM_MULTIPLAYER) { return false; } // set player ptr first thing Assert( (Player_num >= 0) && (Player_num < MAX_PLAYERS) ); p = &Players[Player_num]; if ( !strlen(Campaign.filename) ) { return false; } // build up filename for the savefile... _splitpath(Campaign.filename, NULL, NULL, base, NULL); buf << p->callsign << "." << base << ".csg"; filename = buf.str().c_str(); // make sure that we can actually save this safely if (m_data_invalid) { mprintf(("CSG => Skipping save of '%s' due to invalid data check!\n", filename.c_str())); return false; } // validate the number of red alert entries // assertion before writing so that we don't corrupt the .csg by asserting halfway through writing // assertion should also prevent loss of major campaign progress // i.e. lose one mission, not several missions worth (in theory) Assertion(Red_alert_wingman_status.size() <= MAX_SHIPS, "Invalid number of Red_alert_wingman_status entries: " SIZE_T_ARG "\n", Red_alert_wingman_status.size()); // open it, hopefully... cfp = cfopen((char*)filename.c_str(), "wb", CFILE_NORMAL, CF_TYPE_PLAYERS); if ( !cfp ) { mprintf(("CSG => Unable to open '%s' for saving!\n", filename.c_str())); return false; } // header and version cfwrite_int(CSG_FILE_ID, cfp); cfwrite_ubyte(CSG_VERSION, cfp); mprintf(("CSG => Saving '%s' with version %d...\n", filename.c_str(), (int)CSG_VERSION)); // flags and info sections go first mprintf(("CSG => Saving: Flags...\n")); csg_write_flags(); mprintf(("CSG => Saving: Info...\n")); csg_write_info(); // everything else is next, not order specific mprintf(("CSG => Saving: Missions...\n")); csg_write_missions(); mprintf(("CSG => Saving: Techroom...\n")); csg_write_techroom(); mprintf(("CSG => Saving: Loadout...\n")); csg_write_loadout(); mprintf(("CSG => Saving: Scoring...\n")); csg_write_stats(); mprintf(("CSG => Saving: RedAlert...\n")); csg_write_redalert(); mprintf(("CSG => Saving: HUD...\n")); csg_write_hud(); mprintf(("CSG => Saving: Variables...\n")); csg_write_variables(); mprintf(("CSG => Saving: Settings...\n")); csg_write_settings(); mprintf(("CSG => Saving: Controls...\n")); csg_write_controls(); mprintf(("CSG => Saving: Cutscenes...\n")); csg_write_cutscenes(); mprintf(("CSG => Saving: Last Missions...\n")); csg_write_lastmissions(); // Done! mprintf(("CSG => Saving complete!\n")); csg_close(); return true; }
void pilot::BinaryFileHandler::writeUByte(const char*, std::uint8_t value) { cfwrite_ubyte(value, _cfp); }
void pilotfile::csg_write_info() { int idx; startSection(Section::Info); // ship list cfwrite_int(static_cast<int>(Ship_info.size()), cfp); for (auto it = Ship_info.cbegin(); it != Ship_info.cend(); ++it) { cfwrite_string_len(it->name, cfp); } // weapon list cfwrite_int(Num_weapon_types, cfp); for (idx = 0; idx < Num_weapon_types; idx++) { cfwrite_string_len(Weapon_info[idx].name, cfp); } // intel list cfwrite_int(Intel_info_size, cfp); for (idx = 0; idx < Intel_info_size; idx++) { cfwrite_string_len(Intel_info[idx].name, cfp); } // medals list cfwrite_int(Num_medals, cfp); for (idx = 0; idx < Num_medals; idx++) { cfwrite_string_len(Medals[idx].name, cfp); } // last ship flown cfwrite_int(p->last_ship_flown_si_index, cfp); // progression state cfwrite_int(Campaign.prev_mission, cfp); cfwrite_int(Campaign.next_mission, cfp); // loop state cfwrite_int(Campaign.loop_reentry, cfp); cfwrite_int(Campaign.loop_enabled, cfp); // missions completed cfwrite_int(Campaign.num_missions_completed, cfp); // allowed ships for (idx = 0; idx < static_cast<int>(Ship_info.size()); idx++) { cfwrite_ubyte(Campaign.ships_allowed[idx], cfp); } // allowed weapons for (idx = 0; idx < Num_weapon_types; idx++) { cfwrite_ubyte(Campaign.weapons_allowed[idx], cfp); } // single/campaign squad name & image cfwrite_string_len(p->s_squad_name, cfp); cfwrite_string_len(p->s_squad_filename, cfp); endSection(); }