FS2_Open
Open source remastering of the Freespace 2 engine
pilotfile_convert.h
Go to the documentation of this file.
1 
2 /* WARNING:
3  * The conversion code is for converting pl2/plr versions 242 & 142 and cs2
4  * version 15 ONLY!!!
5  *
6  * Those versions are the only ones that allow for the conversion process to
7  * run without being directly tied to the active game data. Attempting
8  * conversion on older versions will almost certainly result in data
9  * corruption in the converted file!
10  */
11 
12 /* NOTE:
13  * Lots of duplicate info here for the old pilot file format. This is done
14  * so that any future engine changes won't break the conversion process
15  * or worrying about whether said changes would break anything. It also
16  * allows for better conversion sanity checks, and allows for the conversion
17  * process to run totally independently of current game data.
18  */
19 
20 #define REDALERT_INTERNAL
21 
22 #include "cfile/cfile.h"
24 #include "globalincs/pstypes.h"
25 #include "localization/localize.h"
27 #include "missionui/redalert.h"
28 #include "parse/sexp.h"
29 #include "pilotfile/pilotfile.h"
30 #include "stats/scoring.h"
31 
32 
33 static const unsigned short MAX_JOY_AXES_CONV = 5;
34 static const int MAX_WSS_SLOTS_CONV = 12; // 3 wings * 4 slots
35 static const int MAX_SHIP_WEAPONS_CONV = 7; // 3 primary + 4 secondary
36 
37 typedef struct index_list_t {
39  int index;
40  int val;
41 
43  index(-1), val(0)
44  {
45  }
46 } index_list_t;
47 
48 // special stats struct, since our use here is not content specific
49 typedef struct scoring_special_t {
50  int score;
51  int rank;
52  int assists;
56 
57  unsigned int p_shots_fired;
58  unsigned int p_shots_hit;
59  unsigned int p_bonehead_hits;
60 
61  unsigned int s_shots_fired;
62  unsigned int s_shots_hit;
63  unsigned int s_bonehead_hits;
64 
65  unsigned int missions_flown;
66  unsigned int flight_time;
69 
72 
74  score(0), rank(RANK_ENSIGN), assists(0), kill_count(0), kill_count_ok(0),
75  bonehead_kills(0), p_shots_fired(0), p_shots_hit(0), p_bonehead_hits(0),
76  s_shots_fired(0), s_shots_hit(0), s_bonehead_hits(0), missions_flown(0),
77  flight_time(0), last_flown(0), last_backup(0)
78  {
79  }
81 
82 typedef struct cmission_conv_t {
83  int index; // index into Campaign.missions[]
84  int flags;
85 
89 
92 
93 typedef struct wss_unit_conv_t {
95  int wep[MAX_SHIP_WEAPONS_CONV];
96  int wep_count[MAX_SHIP_WEAPONS_CONV];
97 
99  ship_index(-1)
100  {
101  }
103 
104 typedef struct loadout_conv_t {
107 
108  wss_unit_conv_t slot[MAX_WSS_SLOTS_CONV];
109 
113 
114 
115 struct plr_data {
116  plr_data();
117  ~plr_data();
118 
119  // -------------------------------------------------------------------------
120  // NOTE: we *do not* carry over the following items because they are either
121  // obsolete, removed functionality, or just not needed. But we still
122  // do have to take them into account during read ...
123  //
124  // - stats (ver 142 only)
125  // - loadout (ver 142 only)
126  // - techroom (ver 142 only)
127  // - recent missions (ver 142 & 242)
128  // - red alert (ver 142 only)
129  // -------------------------------------------------------------------------
130 
131  // not carried over, just for reference during conversion process
132  int version;
133 
134  // basic flags and settings
135  int is_multi;
137  int tips;
138  int rank;
148 
149  // multiplayer settings/options
151 
152  unsigned char multi_squad_set;
153  unsigned char multi_endgame_set;
155  unsigned int multi_respawn;
156  unsigned char multi_max_observers;
157  unsigned char multi_skill_level;
158  unsigned char multi_voice_qos;
163 
166 
167  // pilot info stuff
168  char image_filename[35];
169  char squad_name[35];
170  char squad_filename[35];
172  char last_ship_flown[35];
173 
174  // HUD config
179  unsigned char hud_num_lines;
182  unsigned char hud_colors[39][4];
183 
184  // control setup
186 
189 
190  // audio
194 
195  // detail settings
208 
209  // variables
211 };
212 
213 struct csg_data {
214  csg_data();
215  ~csg_data();
216 
217  int sig;
219 
226 
228 
231 
235 
240 
242 
244 
246 
248 
251 };
252 
254  public:
257 
258  bool load();
259  void save();
260 
261  bool plr_convert(const char *fname, bool inferno);
262  bool csg_convert(const char *fname, bool inferno);
263 
264  private:
265  CFILE *cfp;
266  unsigned int fver;
267 
268  scoring_special_t all_time_stats;
269  scoring_special_t multi_stats;
270 
271  // sections of a pilot file. includes both plr and csg sections
272  struct Section {
273  enum id {
274  Flags = 0x0001,
275  Info = 0x0002,
276  Loadout = 0x0003,
277  Controls = 0x0004,
278  Multiplayer = 0x0005,
279  Scoring = 0x0006,
280  ScoringMulti = 0x0007,
281  Techroom = 0x0008,
282  HUD = 0x0009,
283  Settings = 0x0010,
284  RedAlert = 0x0011,
285  Variables = 0x0012,
286  Missions = 0x0013,
287  Cutscenes = 0x0014,
288  };
289  };
290 
291  // for writing files, sets/updates section info
292  void startSection(Section::id section_id);
293  void endSection();
294  // file offset of the size value for the current section (set with startSection())
295  size_t m_size_offset;
296 
297 
298  // --------------------------------------------------------------------
299  // PLR specific
300  // --------------------------------------------------------------------
301  plr_data *plr;
302 
303  void plr_import();
304  void plr_import_controls();
305  void plr_import_hud();
306  void plr_import_detail();
307  void plr_import_stats();
308  void plr_import_loadout();
309  void plr_import_multiplayer();
310  void plr_import_red_alert();
311  void plr_import_variables();
312 
313  void plr_export();
314  void plr_export_flags();
315  void plr_export_info();
316  void plr_export_stats();
317  void plr_export_stats_multi();
318  void plr_export_hud();
319  void plr_export_variables();
320  void plr_export_multiplayer();
321  void plr_export_controls();
322  void plr_export_settings();
323 
324  // --------------------------------------------------------------------
325  // CSG specific
326  // --------------------------------------------------------------------
327  csg_data *csg;
328 
329  void csg_import(bool inferno);
330  void csg_import_loadout();
331  void csg_import_stats();
332  void csg_import_techroom();
333  void csg_import_red_alert();
334  void csg_import_missions(bool inferno);
335  void csg_import_ships_weapons();
336 
337  void csg_export();
338  void csg_export_flags();
339  void csg_export_info();
340  void csg_export_missions();
341  void csg_export_techroom();
342  void csg_export_loadout();
343  void csg_export_stats();
344  void csg_export_redalert();
345  void csg_export_hud();
346  void csg_export_variables();
347  void csg_export_cutscenes();
348 };
349 
SCP_vector< mevent > events
bool csg_convert(const char *fname, bool inferno)
SCP_vector< index_list_t > medals_earned
SCP_string name
SCP_vector< cutscene_info > Cutscenes
Definition: cutscenes.cpp:39
char squad_filename[35]
SCP_vector< sexp_variable > variables
int detail_weapon_extras
SCP_string precursor_mission
int joy_axis_map_to[5]
loadout_conv_t loadout
SCP_vector< config_item > controls
SCP_vector< bool > weapons_allowed
SCP_vector< sexp_variable > variables
char image_filename[35]
long _fs_time_t
Definition: pstypes.h:55
Definition: cfile.h:28
SCP_vector< index_list_t > intel_list
SCP_vector< sexp_variable > variables
#define RANK_ENSIGN
Definition: scoring.h:30
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
Definition: vmallocator.h:21
unsigned int p_shots_hit
unsigned char hud_colors[39][4]
struct cmission_conv_t cmission_conv_t
unsigned int s_bonehead_hits
scoring_special_t stats
SCP_vector< cmission_conv_t > missions
SCP_vector< index_list_t > weapon_list
int joy_invert_axis[5]
int detail_planets_suns
int multi_voice_record_time
int detail_hardware_textures
unsigned int multi_respawn
float voice_volume
int multi_local_update_level
SCP_string main_hall
SCP_vector< index_list_t > ship_kills
struct index_list_t index_list_t
unsigned char multi_squad_set
SCP_vector< red_alert_ship_status > wingman_status
char language[LCL_LANG_NAME_LEN+1]
bool plr_convert(const char *fname, bool inferno)
unsigned int p_shots_fired
char current_campaign[35]
int detail_shield_effects
SCP_vector< int > weapon_pool
unsigned char multi_skill_level
GLenum GLuint id
Definition: Glext.h:5156
SCP_vector< int > ship_pool
SCP_vector< index_list_t > medals_list
struct scoring_special_t scoring_special_t
unsigned int s_shots_fired
int last_ship_flown_index
unsigned int s_shots_hit
unsigned int p_bonehead_hits
unsigned char multi_endgame_set
SCP_vector< bool > ships_techroom
struct Section Section
char last_ship_flown[35]
SCP_vector< bool > intel_techroom
#define LCL_LANG_NAME_LEN
Definition: localize.h:31
unsigned int missions_flown
unsigned char multi_voice_qos
SCP_vector< bool > weapons_techroom
struct wss_unit_conv_t wss_unit_conv_t
int readyroom_listing_mode
unsigned int flight_time
int detail_num_particles
scoring_special_t stats
int multi_voice_token_wait
char squad_name[35]
unsigned char multi_max_observers
SCP_vector< bool > ships_allowed
int wep_count[MAX_SHIP_WEAPONS_CONV]
SCP_string last_modified
float music_volume
struct loadout_conv_t loadout_conv_t
SCP_vector< index_list_t > ship_list
int detail_targetview_model
wss_unit_conv_t slot[MAX_WSS_SLOTS_CONV]
unsigned char hud_num_lines
SCP_vector< mgoal > goals
float sound_volume
int wep[MAX_SHIP_WEAPONS_CONV]