FS2_Open
Open source remastering of the Freespace 2 engine
plr_convert.cpp
Go to the documentation of this file.
1 
2 /* WARNING:
3  * This is magic-number central, but these numbers are set specifically
4  * to the acceptable defaults or range values that were used when the
5  * pl2/plr files were created. Standard game defines should not be used in
6  * place of these major numbers for /any/ reason, *ever*!
7  */
8 
9 #include "cfile/cfilesystem.h"
11 #include "network/psnet2.h"
13 
14 
15 // this struct isn't well packed, and is written whole to the pilot file, so
16 // we can't easily just get the RGBA that we need and instead must retain this
17 typedef struct conv_color { //-V802
27  int magic;
28 } conv_color;
29 
30 
32 {
33  // not carried over, just for reference during conversion process
34  version = 0;
35  is_multi = 0;
37 
38  // basic flags and settings
39  tips = 0;
40  rank = 0;
41  skill_level = 1;
42  save_flags = 0;
44  voice_enabled = 1;
45  auto_advance = 1;
46  Use_mouse_to_fly = 0;
48  Joy_sensitivity = 9;
49  Dead_zone_size = 10;
50 
51  // multiplayer settings/options
52  net_protocol = 1;
53 
54  multi_squad_set = 2;
56  multi_flags = 3;
57  multi_respawn = 2;
60  multi_voice_qos = 10;
63  multi_time_limit = -65536;
64  multi_kill_limit = 9999;
65 
68 
69  // pilot info stuff
70  memset(image_filename, 0, sizeof(image_filename));
71  memset(squad_name, 0, sizeof(squad_name));
72  memset(squad_filename, 0, sizeof(squad_filename));
73  memset(current_campaign, 0, sizeof(current_campaign));
74  memset(last_ship_flown, 0, sizeof(last_ship_flown));
75 
76  // HUD config
77  hud_show_flags = -1;
78  hud_show_flags2 = 31;
79  hud_popup_flags = 0;
80  hud_popup_flags2 = 0;
81  hud_num_lines = 4;
82  hud_rp_flags = 7;
83  hud_rp_dist = 2;
84 
85  for (int idx = 0; idx < 39; idx++) {
86  hud_colors[idx][0] = 0;
87  hud_colors[idx][1] = 255;
88  hud_colors[idx][2] = 0;
89  hud_colors[idx][3] = 144;
90  }
91 
92  // control setup
93  joy_axis_map_to[0] = 0;
94  joy_axis_map_to[1] = 1;
95  joy_axis_map_to[2] = 3;
96  joy_invert_axis[3] = -1;
97  joy_invert_axis[4] = -1;
98 
99  memset(joy_invert_axis, 0, sizeof(joy_invert_axis));
100 
101  // audio
102  sound_volume = 1.0f;
103  music_volume = 0.5f;
104  voice_volume = 0.7f;
105 
106  // detail settings
107  detail_setting = 3;
108  detail_nebula = 3;
109  detail_distance = 3;
111  detail_num_debris = 4;
113  detail_num_stars = 4;
115  detail_lighting = 4;
119 }
120 
122 {
123  controls.clear();
124 }
125 
126 void pilotfile_convert::plr_import_controls()
127 {
128  int idx;
129  config_item con;
130 
131  unsigned char num_controls = cfread_ubyte(cfp);
132 
133  if ( !num_controls ) {
134  return;
135  }
136 
137  // it may be less than 118, but it shouldn't be more than 118
138  if (num_controls > 118) {
139  throw "Data check failure in controls!";
140  }
141 
142  plr->controls.reserve(num_controls);
143 
144  for (idx = 0; idx < num_controls; idx++) {
145  con.key_id = cfread_short(cfp);
146 
147  if (con.key_id == 255) {
148  con.key_id = -1;
149  }
150 
151  con.joy_id = cfread_short(cfp);
152 
153  if (con.joy_id == 255) {
154  con.joy_id = -1;
155  }
156 
157  plr->controls.push_back( con );
158  }
159 }
160 
161 void pilotfile_convert::plr_import_hud()
162 {
163  int idx;
164  conv_color c;
165 
166  plr->hud_show_flags = cfread_int(cfp);
167  plr->hud_show_flags2 = cfread_int(cfp);
168 
169  plr->hud_popup_flags = cfread_int(cfp);
170  plr->hud_popup_flags2 = cfread_int(cfp);
171 
172  plr->hud_num_lines = cfread_ubyte(cfp);
173  plr->hud_rp_flags = cfread_int(cfp);
174  plr->hud_rp_dist = cfread_int(cfp);
175 
176  for (idx = 0; idx < 39; idx++) {
177  cfread(&c, sizeof(conv_color), 1, cfp);
178 
179  if ( (c.alphacolor != -1) || (c.is_alphacolor != 1) ) {
180  throw "Data check failure in hud!";
181  }
182 
183  plr->hud_colors[idx][0] = c.red;
184  plr->hud_colors[idx][1] = c.green;
185  plr->hud_colors[idx][2] = c.blue;
186  plr->hud_colors[idx][3] = c.alpha;
187  }
188 }
189 
190 void pilotfile_convert::plr_import_detail()
191 {
192  bool data_failure = false;
193 
194  plr->detail_setting = cfread_int(cfp);
195  plr->detail_nebula = cfread_int(cfp);
196  plr->detail_distance = cfread_int(cfp);
198  plr->detail_num_debris = cfread_int(cfp);
199  plr->detail_num_particles = cfread_int(cfp);
200  plr->detail_num_stars = cfread_int(cfp);
201  plr->detail_shield_effects = cfread_int(cfp);
202  plr->detail_lighting = cfread_int(cfp);
204  plr->detail_planets_suns = cfread_int(cfp);
205  plr->detail_weapon_extras = cfread_int(cfp);
206 
207  if ( (plr->detail_setting < -1) || (plr->detail_setting > 4) ) {
208  data_failure = true;
209  } else if ( (plr->detail_nebula < 0) || (plr->detail_nebula > 4) ) {
210  data_failure = true;
211  } else if ( (plr->detail_distance < 0) || (plr->detail_distance > 4) ) {
212  data_failure = true;
213  } else if ( (plr->detail_hardware_textures < 0) || (plr->detail_hardware_textures > 4) ) {
214  data_failure = true;
215  } else if ( (plr->detail_num_debris < 0) || (plr->detail_num_debris > 4) ) {
216  data_failure = true;
217  } else if ( (plr->detail_num_particles < 0) || (plr->detail_num_particles > 4) ) {
218  data_failure = true;
219  } else if ( (plr->detail_num_stars < 0) || (plr->detail_num_stars > 4) ) {
220  data_failure = true;
221  } else if ( (plr->detail_shield_effects < 0) || (plr->detail_shield_effects > 4) ) {
222  data_failure = true;
223  } else if ( (plr->detail_lighting < 0) || (plr->detail_lighting > 4) ) {
224  data_failure = true;
225  } else if ( (plr->detail_targetview_model < 0) || (plr->detail_targetview_model > 1) ) {
226  data_failure = true;
227  } else if ( (plr->detail_planets_suns < 0) || (plr->detail_planets_suns > 1) ) {
228  data_failure = true;
229  } else if ( (plr->detail_weapon_extras < 0) || (plr->detail_weapon_extras > 1) ) {
230  data_failure = true;
231  }
232 
233  if (data_failure) {
234  throw "Data check failure in details!";
235  }
236 }
237 
238 void pilotfile_convert::plr_import_stats()
239 {
240  int idx;
241  char name[35];
242 
243  if (fver >= 242) {
244  return;
245  }
246 
247  // read everything, but we don't need any of it ...
248 
249  cfread_int(cfp); // score
250  cfread_int(cfp); // rank
251  cfread_int(cfp); // assists
252 
253  // medals
254  for (idx = 0; idx < 18; idx++) {
255  cfread_int(cfp);
256  }
257 
258  // kills per ship
259  int count = cfread_int(cfp);
260 
261  for (idx = 0; idx < count; idx++) {
262  cfread_ushort(cfp);
263  cfread_string_len(name, sizeof(name), cfp);
264  }
265 
266  cfread_int(cfp); // kill_count
267  cfread_int(cfp); // kill_count_ok
268 
269  cfread_uint(cfp); // p_shots_fired
270  cfread_uint(cfp); // s_shots_fired
271  cfread_uint(cfp); // p_shots_hit
272  cfread_uint(cfp); // s_shots_hit
273 
274  cfread_uint(cfp); // p_bonehead_hits
275  cfread_uint(cfp); // s_bonehead_hits
276  cfread_uint(cfp); // bonehead_kills
277 }
278 
279 void pilotfile_convert::plr_import_loadout()
280 {
281  int idx, j;
282  int s_count, w_count;
283  char name[52];
284 
285  if (fver >= 242) {
286  return;
287  }
288 
289  // have to read it, but don't need any of it ...
290 
291  cfread_string_len(name, sizeof(name), cfp); // filename
292  cfread_string_len(name, sizeof(name), cfp); // last_modified
293 
294  s_count = cfread_int(cfp); // num ships
295  w_count = cfread_int(cfp); // num weapons
296 
297  // ships
298  for (idx = 0; idx < s_count; idx++) {
299  cfread_int(cfp); // count
300  cfread_string_len(name, sizeof(name), cfp); // name
301  }
302 
303  // weapons
304  for (idx = 0; idx < w_count; idx++) {
305  cfread_int(cfp); // count
306  cfread_string_len(name, sizeof(name), cfp); // name
307  }
308 
309  // loadout info
310  for (idx = 0; idx < 12; idx++) {
311  cfread_int(cfp); // ship class
312  cfread_string_len(name, sizeof(name), cfp); // ship name
313 
314  for (j = 0; j < 12; j++) {
315  cfread_int(cfp); // weapon type
316  cfread_int(cfp); // weapon count
317  cfread_string_len(name, sizeof(name), cfp); // weapon name
318  }
319  }
320 }
321 
322 void pilotfile_convert::plr_import_multiplayer()
323 {
324  plr->multi_squad_set = cfread_ubyte(cfp);
325  plr->multi_endgame_set = cfread_ubyte(cfp);
326  plr->multi_flags = cfread_int(cfp);
327  plr->multi_respawn = cfread_uint(cfp);
328  plr->multi_max_observers = cfread_ubyte(cfp);
329  plr->multi_skill_level = cfread_ubyte(cfp);
330  plr->multi_voice_qos = cfread_ubyte(cfp);
333  plr->multi_time_limit = cfread_int(cfp);
334  plr->multi_kill_limit = cfread_int(cfp);
335 
336  plr->multi_local_flags = cfread_int(cfp);
338 }
339 
340 void pilotfile_convert::plr_import_red_alert()
341 {
342  int idx, j;
343  char name[35];
344 
345  if (fver >= 242) {
346  return;
347  }
348 
349  // have to read it, but don't need any of it ...
350 
351  int num_slots = cfread_int(cfp);
352 
353  if ( (num_slots < 0) || (num_slots >= 32) ) {
354  throw "Data check failure in red-alert!";
355  }
356 
357  if ( !num_slots ) {
358  return;
359  }
360 
361  for (idx = 0; idx < num_slots; idx++) {
362  cfread_string(name, sizeof(name) - 1, cfp);
363  cfread_float(cfp);
364 
365  cfread_string_len(name, sizeof(name), cfp);
366 
367  // subsystem hits
368  for (j = 0; j < 64; j++) {
369  cfread_float(cfp);
370  }
371 
372  // aggregate hits
373  for (j = 0; j < 12; j++) {
374  cfread_float(cfp);
375  }
376 
377  // weapons
378  for (j = 0; j < 12; j++) {
379  cfread_string_len(name, sizeof(name), cfp);
380  cfread_int(cfp);
381  }
382  }
383 }
384 
385 void pilotfile_convert::plr_import_variables()
386 {
387  int idx;
388  sexp_variable nvar;
389 
390  int num_variables = cfread_int(cfp);
391 
392  if ( (num_variables < 0) || (num_variables >= 100) ) {
393  throw "Data check failure in variables!";
394  }
395 
396  plr->variables.reserve(num_variables);
397 
398  for (idx = 0; idx < num_variables; idx++) {
399  nvar.type = cfread_int(cfp);
400  cfread_string_len(nvar.text, sizeof(nvar.text), cfp);
401  cfread_string_len(nvar.variable_name, sizeof(nvar.variable_name), cfp);
402 
403  plr->variables.push_back( nvar );
404  }
405 }
406 
407 void pilotfile_convert::plr_import()
408 {
409  char name[35];
410  int idx;
411 
412  unsigned int plr_id = cfread_uint(cfp);
413 
414  if (plr_id != 0x46505346) {
415  throw "Invalid file signature!";
416  }
417 
418  fver = cfread_uint(cfp);
419 
420  if ( (fver != 142) && (fver != 242) ) {
421  throw "Unsupported file version!";
422  }
423 
424  // multi flag
425  plr->is_multi = (int)cfread_ubyte(cfp);
426 
427  // rank
428  plr->rank = cfread_int(cfp);
429 
430  // mainhall, don't need it
431  if (fver < 242) {
432  cfread_ubyte(cfp);
433  }
434 
435  plr->tips = cfread_int(cfp);
436 
437  if ( (plr->tips < 0) || (plr->tips > 1) ) {
438  throw "Data check failure!";
439  }
440 
441  cfread_string_len(plr->image_filename, sizeof(plr->image_filename), cfp);
442  cfread_string_len(plr->squad_name, sizeof(plr->squad_name), cfp);
443  cfread_string_len(plr->squad_filename, sizeof(plr->squad_filename), cfp);
444  cfread_string_len(plr->current_campaign, sizeof(plr->current_campaign), cfp);
445  cfread_string_len(plr->last_ship_flown, sizeof(plr->last_ship_flown), cfp);
446 
447  // controls
448  plr_import_controls();
449 
450  // hud config
451  plr_import_hud();
452 
453  // cutscenes, don't need it
454  if (fver < 242) {
455  cfread_int(cfp);
456  }
457 
458  // volume stuff
459  plr->sound_volume = cfread_float(cfp);
460  plr->music_volume = cfread_float(cfp);
461  plr->voice_volume = cfread_float(cfp);
462 
463  // detail settings
464  plr_import_detail();
465 
466  // recent missions, don't need it
467  int num_missions = cfread_int(cfp);
468 
469  for (idx = 0; idx < num_missions; idx++) {
470  cfread_string_len(name, sizeof(name), cfp);
471  }
472 
473  // stats, will skip if fver < 242
474  plr_import_stats();
475 
476  plr->skill_level = cfread_int(cfp);
477 
478  if ( (plr->skill_level < 0) || (plr->skill_level > 4) ) {
479  throw "Data check failure!";
480  }
481 
482  // extra joystick stuff
483  for (idx = 0; idx < 5; idx++) {
484  plr->joy_axis_map_to[idx] = cfread_int(cfp);
485  plr->joy_invert_axis[idx] = cfread_int(cfp);
486  }
487 
488  // flags
489  plr->save_flags = cfread_int(cfp);
490 
491  // loadout, will skip if fver < 242
492  plr_import_loadout();
493 
494  // multiplayer
495  plr_import_multiplayer();
496 
497  // two briefing related values
500 
501  plr->net_protocol = cfread_int(cfp);
502 
503  // protocol must be set to something
504  if (plr->net_protocol == NET_NONE) {
505  plr->net_protocol = NET_TCP;
506  } else if ( (plr->net_protocol < 0) || (plr->net_protocol > NET_VMT) ) {
507  throw "Data check failure!";
508  }
509 
510  // red alert status, will skip if fver < 242 (and should be empty if multi)
511  plr_import_red_alert();
512 
513  // briefing auto-advance
514  plr->auto_advance = cfread_int(cfp);
515 
516  if ( (plr->auto_advance < 0) || (plr->auto_advance > 1) ) {
517  throw "Data check failure!";
518  }
519 
520  // some input options
521  plr->Use_mouse_to_fly = cfread_int(cfp);
522  plr->Mouse_sensitivity = cfread_int(cfp);
523  plr->Joy_sensitivity = cfread_int(cfp);
524  plr->Dead_zone_size = cfread_int(cfp);
525 
526  // variables
527  plr_import_variables();
528 
529 
530  // and... we're done! :)
531 }
532 
533 void pilotfile_convert::plr_export_flags()
534 {
535  startSection(Section::Flags);
536 
537  // tips
538  cfwrite_ubyte((unsigned char)plr->tips, cfp);
539 
540  // saved flags
541  cfwrite_int(plr->save_flags, cfp);
542 
543  // listing mode (single or campaign missions)
545 
546  // briefing auto-play
547  cfwrite_int(plr->auto_advance, cfp);
548 
549  // special rank setting (to avoid having to read all stats on verify)
550  cfwrite_int(plr->rank, cfp);
551 
552  // What game mode we were in last on this pilot
553  cfwrite_int(plr->is_multi, cfp);
554 
555  // which language was this pilot created with
556  cfwrite_string_len(plr->language, cfp);
557 
558  endSection();
559 }
560 
561 void pilotfile_convert::plr_export_info()
562 {
563  startSection(Section::Info);
564 
565  // pilot image
567 
568  // squad name
569  cfwrite_string_len(plr->squad_name, cfp);
570 
571  // squad image
573 
574  // active campaign
576 
577  endSection();
578 }
579 
580 void pilotfile_convert::plr_export_stats()
581 {
582  int idx, list_size = 0;
583 
584  startSection(Section::Scoring);
585 
586  // global, all-time stats
587  cfwrite_int(all_time_stats.score, cfp);
588  cfwrite_int(all_time_stats.rank, cfp);
589  cfwrite_int(all_time_stats.assists, cfp);
590  cfwrite_int(all_time_stats.kill_count, cfp);
591  cfwrite_int(all_time_stats.kill_count_ok, cfp);
592  cfwrite_int(all_time_stats.bonehead_kills, cfp);
593 
594  cfwrite_uint(all_time_stats.p_shots_fired, cfp);
595  cfwrite_uint(all_time_stats.p_shots_hit, cfp);
596  cfwrite_uint(all_time_stats.p_bonehead_hits, cfp);
597 
598  cfwrite_uint(all_time_stats.s_shots_fired, cfp);
599  cfwrite_uint(all_time_stats.s_shots_hit, cfp);
600  cfwrite_uint(all_time_stats.s_bonehead_hits, cfp);
601 
602  cfwrite_uint(all_time_stats.flight_time, cfp);
603  cfwrite_uint(all_time_stats.missions_flown, cfp);
604  cfwrite_int((int)all_time_stats.last_flown, cfp);
605  cfwrite_int((int)all_time_stats.last_backup, cfp);
606 
607  // ship kills (contains ships across all mods, not just current)
608  list_size = (int)all_time_stats.ship_kills.size();
609  cfwrite_int(list_size, cfp);
610 
611  for (idx = 0; idx < list_size; idx++) {
612  cfwrite_string_len(all_time_stats.ship_kills[idx].name.c_str(), cfp);
613  cfwrite_int(all_time_stats.ship_kills[idx].val, cfp);
614  }
615 
616  // medals earned (contains medals across all mods, not just current)
617  list_size = (int)all_time_stats.medals_earned.size();
618  cfwrite_int(list_size, cfp);
619 
620  for (idx = 0; idx < list_size; idx++) {
621  cfwrite_string_len(all_time_stats.medals_earned[idx].name.c_str(), cfp);
622  cfwrite_int(all_time_stats.medals_earned[idx].val, cfp);
623  }
624 
625  endSection();
626 }
627 
628 void pilotfile_convert::plr_export_stats_multi()
629 {
630  int idx, list_size = 0;
631 
632  startSection(Section::ScoringMulti);
633 
634  // global, all-time stats
635  cfwrite_int(multi_stats.score, cfp);
636  cfwrite_int(multi_stats.rank, cfp);
637  cfwrite_int(multi_stats.assists, cfp);
638  cfwrite_int(multi_stats.kill_count, cfp);
639  cfwrite_int(multi_stats.kill_count_ok, cfp);
640  cfwrite_int(multi_stats.bonehead_kills, cfp);
641 
642  cfwrite_uint(multi_stats.p_shots_fired, cfp);
643  cfwrite_uint(multi_stats.p_shots_hit, cfp);
644  cfwrite_uint(multi_stats.p_bonehead_hits, cfp);
645 
646  cfwrite_uint(multi_stats.s_shots_fired, cfp);
647  cfwrite_uint(multi_stats.s_shots_hit, cfp);
648  cfwrite_uint(multi_stats.s_bonehead_hits, cfp);
649 
650  cfwrite_uint(multi_stats.flight_time, cfp);
651  cfwrite_uint(multi_stats.missions_flown, cfp);
652  cfwrite_int((int)multi_stats.last_flown, cfp);
653  cfwrite_int((int)multi_stats.last_backup, cfp);
654 
655  // ship kills (contains medals across all mods, not just current)
656  list_size = (int)multi_stats.ship_kills.size();
657  cfwrite_int(list_size, cfp);
658 
659  for (idx = 0; idx < list_size; idx++) {
660  cfwrite_string_len(multi_stats.ship_kills[idx].name.c_str(), cfp);
661  cfwrite_int(multi_stats.ship_kills[idx].val, cfp);
662  }
663 
664  // medals earned (contains medals across all mods, not just current)
665  list_size = (int)multi_stats.medals_earned.size();
666  cfwrite_int(list_size, cfp);
667 
668  for (idx = 0; idx < list_size; idx++) {
669  cfwrite_string_len(multi_stats.medals_earned[idx].name.c_str(), cfp);
670  cfwrite_int(multi_stats.medals_earned[idx].val, cfp);
671  }
672 
673  endSection();
674 }
675 
676 void pilotfile_convert::plr_export_hud()
677 {
678  int idx;
679 
680  startSection(Section::HUD);
681 
682  // flags
683  cfwrite_int(plr->hud_show_flags, cfp);
684  cfwrite_int(plr->hud_show_flags2, cfp);
685 
686  cfwrite_int(plr->hud_popup_flags, cfp);
687  cfwrite_int(plr->hud_popup_flags2, cfp);
688 
689  // settings
690  cfwrite_ubyte(plr->hud_num_lines, cfp);
691 
692  cfwrite_int(plr->hud_rp_flags, cfp);
693  cfwrite_int(plr->hud_rp_dist, cfp);
694 
695  // basic colors
696  cfwrite_int(0, cfp); // color
697  cfwrite_int(8, cfp); // alpha
698 
699  // gauge-specific colors
700  cfwrite_int(39, cfp);
701 
702  for (idx = 0; idx < 39; idx++) {
703  cfwrite_ubyte(plr->hud_colors[idx][0], cfp);
704  cfwrite_ubyte(plr->hud_colors[idx][1], cfp);
705  cfwrite_ubyte(plr->hud_colors[idx][2], cfp);
706  cfwrite_ubyte(plr->hud_colors[idx][3], cfp);
707  }
708 
709  endSection();
710 }
711 
712 void pilotfile_convert::plr_export_variables()
713 {
714  int list_size = 0;
715  int idx;
716 
717  startSection(Section::Variables);
718 
719  list_size = (int)plr->variables.size();
720 
721  cfwrite_int(list_size, cfp);
722 
723  for (idx = 0; idx < list_size; idx++) {
724  cfwrite_int(plr->variables[idx].type, cfp);
725  cfwrite_string_len(plr->variables[idx].text, cfp);
726  cfwrite_string_len(plr->variables[idx].variable_name, cfp);
727  }
728 
729  endSection();
730 }
731 
732 void pilotfile_convert::plr_export_multiplayer()
733 {
734  startSection(Section::Multiplayer);
735 
736  // netgame options
737  cfwrite_ubyte(plr->multi_squad_set, cfp);
738  cfwrite_ubyte(plr->multi_endgame_set, cfp);
739  cfwrite_int(plr->multi_flags, cfp);
740  cfwrite_uint(plr->multi_respawn, cfp);
742  cfwrite_ubyte(plr->multi_skill_level, cfp);
743  cfwrite_ubyte(plr->multi_voice_qos, cfp);
746  cfwrite_int(plr->multi_time_limit, cfp);
747  cfwrite_int(plr->multi_kill_limit, cfp);
748 
749  // local options
750  cfwrite_int(plr->multi_local_flags, cfp);
752 
753  // netgame protocol
754  cfwrite_int(plr->net_protocol, cfp);
755 
756  endSection();
757 }
758 
759 void pilotfile_convert::plr_export_controls()
760 {
761  unsigned int idx;
762 
763  startSection(Section::Controls);
764 
765  cfwrite_ushort((unsigned short)plr->controls.size(), cfp);
766 
767  for (idx = 0; idx < plr->controls.size(); idx++) {
768  cfwrite_short(plr->controls[idx].key_id, cfp);
769  cfwrite_short(plr->controls[idx].joy_id, cfp);
770  // placeholder? for future mouse_id?
771  cfwrite_short(-1, cfp);
772  }
773 
774  // extra joystick stuff
775  cfwrite_int(MAX_JOY_AXES_CONV, cfp);
776  for (idx = 0; idx < MAX_JOY_AXES_CONV; idx++) {
777  cfwrite_int(plr->joy_axis_map_to[idx], cfp);
778  cfwrite_int(plr->joy_invert_axis[idx], cfp);
779  }
780 
781  endSection();
782 }
783 
784 void pilotfile_convert::plr_export_settings()
785 {
786  startSection(Section::Settings);
787 
788  // sound/voice/music
789  cfwrite_float(plr->sound_volume, cfp);
790  cfwrite_float(plr->music_volume, cfp);
791  cfwrite_float(plr->voice_volume, cfp);
792 
793  cfwrite_int(plr->voice_enabled, cfp);
794 
795  // skill level
796  cfwrite_int(plr->skill_level, cfp);
797 
798  // input options
799  cfwrite_int(plr->Use_mouse_to_fly, cfp);
800  cfwrite_int(plr->Mouse_sensitivity, cfp);
801  cfwrite_int(plr->Joy_sensitivity, cfp);
802  cfwrite_int(plr->Dead_zone_size, cfp);
803 
804  // detail
805  cfwrite_int(plr->detail_setting, cfp);
806  cfwrite_int(plr->detail_nebula, cfp);
807  cfwrite_int(plr->detail_distance, cfp);
809  cfwrite_int(plr->detail_num_debris, cfp);
811  cfwrite_int(plr->detail_num_stars, cfp);
813  cfwrite_int(plr->detail_lighting, cfp);
815  cfwrite_int(plr->detail_planets_suns, cfp);
817 
818  endSection();
819 }
820 
821 void pilotfile_convert::plr_export()
822 {
823  Assert( cfp != NULL );
824 
825  // header and version
826  cfwrite_int(PLR_FILE_ID, cfp);
827  cfwrite_ubyte(PLR_VERSION, cfp);
828 
829  // flags and info sections go first
830  plr_export_flags();
831  plr_export_info();
832 
833  // everything else is next, not order specific
834  plr_export_stats();
835  plr_export_stats_multi();
836  plr_export_hud();
837  plr_export_variables();
838  plr_export_multiplayer();
839  plr_export_controls();
840  plr_export_settings();
841 
842 
843  // and... we're done! :)
844 }
845 
846 bool pilotfile_convert::plr_convert(const char *fname, bool inferno)
847 {
848  Assert( fname != NULL );
849 
851  bool rval = true;
852 
853 
854  if (plr == NULL) {
855  plr = new(std::nothrow) plr_data;
856  }
857 
858  if (plr == NULL) {
859  return false;
860  }
861 
862  filename.reserve(200);
863 
864  cf_create_default_path_string(filename, CF_TYPE_SINGLE_PLAYERS, (inferno) ? "inferno" : NULL);
865 
866  if (inferno) {
867  filename.append(DIR_SEPARATOR_STR);
868  }
869 
870  filename.append(fname);
871  filename.append(".pl2");
872 
873  mprintf((" PL2 => Converting '%s'...\n", filename.c_str()));
874 
875  cfp = cfopen(filename.c_str(), "rb", CFILE_NORMAL);
876 
877  if ( !cfp ) {
878  mprintf((" PL2 => Unable to open '%s' for import!\n", fname));
879  return false;
880  }
881 
882  try {
883  plr_import();
884  } catch (const char *err) {
885  mprintf(( " PL2 => Import ERROR: %s\n", err));
886  rval = false;
887  }
888 
889  cfclose(cfp);
890  cfp = NULL;
891 
892  if ( !rval ) {
893  return false;
894  }
895 
896  filename.assign(fname);
897  filename.append(".plr");
898 
899  cfp = cfopen(filename.c_str(), "wb", CFILE_NORMAL, CF_TYPE_PLAYERS);
900 
901  if ( !cfp ) {
902  mprintf((" PLR => Unable to open '%s' for export!\n", fname));
903  return false;
904  }
905 
906  try {
907  plr_export();
908  } catch (const char *err) {
909  mprintf((" PLR => Export ERROR: %s\n", err));
910  rval = false;
911  }
912 
913  cfclose(cfp);
914  cfp = NULL;
915 
916  if (rval) {
917  mprintf((" PLR => Conversion complete!\n"));
918  }
919 
920  return rval;
921 }
922 
int is_alphacolor
Definition: plr_convert.cpp:24
int cfwrite_ushort(ushort s, CFILE *file)
Definition: cfile.cpp:1328
#define CFILE_NORMAL
Definition: cfile.h:89
#define NET_TCP
Definition: psnet2.h:29
int Briefing_voice_enabled
#define CF_TYPE_SINGLE_PLAYERS
Definition: cfile.h:70
SCP_vector< index_list_t > medals_earned
char squad_filename[35]
char text[TOKEN_LENGTH]
Definition: sexp.h:1044
short key_id
actual key bound to action
#define CF_TYPE_PLAYERS
Definition: cfile.h:67
int cfread(void *buf, int elsize, int nelem, CFILE *fp)
SCP_vector< sexp_variable > variables
int cfwrite_ubyte(ubyte b, CFILE *file)
Definition: cfile.cpp:1334
int detail_weapon_extras
int cfwrite_uint(uint i, CFILE *file)
Definition: cfile.cpp:1316
int joy_axis_map_to[5]
SCP_vector< config_item > controls
Assert(pm!=NULL)
#define mprintf(args)
Definition: pstypes.h:238
char image_filename[35]
void cfread_string(char *buf, int n, CFILE *file)
Definition: cfile.cpp:1278
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
Definition: vmallocator.h:21
int cf_create_default_path_string(char *path, uint path_max, int pathtype, const char *filename, bool localize)
unsigned int p_shots_hit
unsigned char hud_colors[39][4]
short joy_id
joystick button bound to action
unsigned int s_bonehead_hits
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
int joy_invert_axis[5]
int detail_planets_suns
int multi_voice_record_time
int detail_hardware_textures
ubyte ac_type
Definition: plr_convert.cpp:23
unsigned int uint
Definition: pstypes.h:64
#define cfopen(...)
Definition: cfile.h:134
unsigned int multi_respawn
float voice_volume
int cfwrite_float(float f, CFILE *file)
Definition: cfile.cpp:1304
#define DIR_SEPARATOR_STR
Definition: pstypes.h:44
char * filename
int multi_local_update_level
SCP_vector< index_list_t > ship_kills
uint screen_sig
Definition: plr_convert.cpp:18
unsigned char multi_squad_set
char language[LCL_LANG_NAME_LEN+1]
bool plr_convert(const char *fname, bool inferno)
int cfwrite_string_len(const char *buf, CFILE *file)
Write a fixed length string (not including its null terminator), with the length stored in file...
Definition: cfile.cpp:1378
unsigned int p_shots_fired
char current_campaign[35]
int detail_shield_effects
short cfread_short(CFILE *file, int ver, short deflt)
Definition: cfile.cpp:1192
unsigned char multi_skill_level
struct conv_color conv_color
int idx
Definition: multiui.cpp:761
int cfwrite_int(int i, CFILE *file)
Definition: cfile.cpp:1310
int type
Definition: sexp.h:1043
unsigned char ubyte
Definition: pstypes.h:62
unsigned int s_shots_fired
unsigned int s_shots_hit
unsigned int p_bonehead_hits
ubyte cfread_ubyte(CFILE *file, int ver, ubyte deflt)
Definition: cfile.cpp:1220
GLuint const GLchar * name
Definition: Glext.h:5608
unsigned char multi_endgame_set
char last_ship_flown[35]
int cfwrite_short(short s, CFILE *file)
Definition: cfile.cpp:1322
unsigned int missions_flown
#define NET_VMT
Definition: psnet2.h:30
unsigned char multi_voice_qos
ushort cfread_ushort(CFILE *file, int ver, ushort deflt)
Definition: cfile.cpp:1206
int readyroom_listing_mode
unsigned int flight_time
int cfread_int(CFILE *file, int ver, int deflt)
Definition: cfile.cpp:1164
float cfread_float(CFILE *file, int ver, float deflt)
Definition: cfile.cpp:1150
GLint GLsizei count
Definition: Gl.h:1491
int detail_num_particles
int multi_voice_token_wait
char variable_name[TOKEN_LENGTH]
Definition: sexp.h:1045
char squad_name[35]
unsigned char multi_max_observers
float music_volume
int cfclose(CFILE *cfile)
Definition: cfile.cpp:895
#define NET_NONE
Definition: psnet2.h:28
int detail_targetview_model
unsigned char hud_num_lines
float sound_volume
const GLubyte * c
Definition: Glext.h:8376
void lcl_get_language_name(char *lang_name)
Definition: localize.cpp:1121
uint cfread_uint(CFILE *file, int ver, uint deflt)
Definition: cfile.cpp:1178
void cfread_string_len(char *buf, int n, CFILE *file)
Read a fixed length string that is not null-terminated, with the length stored in file...
Definition: cfile.cpp:1291