forked from scp-fs2open/PCS2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
POFHandler.cpp
3557 lines (2618 loc) · 88.7 KB
/
POFHandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//****************************************************************************
// POFHandler.cpp
// Author: Derek Meek
// Implentation of the POF Handler Functions
//****************************************************************************
/*
* $Logfile: /POFHandler.cpp $
* $Revision: 1.24 $
* $Date: 2008/11/08 15:13:19 $
* $Author: kazan $
*
* $Log: POFHandler.cpp,v $
* Revision 1.24 2008/11/08 15:13:19 kazan
* Updated to wxWidgets 2.8.9 and switched from static linkage to DLL linkage.
*
* Revision 1.23 2008/02/11 13:18:15 kazan
* Possible fix for Mantis #59
*
* Revision 1.22 2008/02/09 23:01:41 kazan
* post-kaz_templates removal cleanup
*
* Revision 1.21 2008/02/09 22:32:58 kazan
* bye bye kaz_vector
*
* Revision 1.20 2008/02/09 22:28:09 kazan
* checkin before i do something drastic (pull out my templates - don't need them anymore)
*
* Revision 1.19 2007/10/18 15:54:08 kazan
* Removed all instances of POFstring in favor of std::strings
*
* Revision 1.18 2007/07/13 18:22:20 kazan
* implement SLDC (Shield Collision Tree) chunk
*
* Revision 1.17 2007/07/12 05:36:35 bobboau
* fixed a crash bug in glowpoint saveing related to memcpying a class with a string (which has a pointer to it's own memory buffer which it deletes on destruction) in it.
*
* Revision 1.16 2007/07/03 02:52:20 bobboau
* trying to undo the commit to the wrong branch..
*
* Revision 1.14 2007/06/29 21:00:26 bobboau
* added shield chunk "editor", doesn't actualy let you edit anything, but will display shield poly count and activate the rendering of shileds, which I also added.
*
* Revision 1.13 2007/06/18 01:15:01 kazan
* Resolve #005, add cache-bsp-on-generate, add .25s sleeps to each cycle on the GUI side while waiting for threads... was spiking both CPUs in my big machine.. and that's not right
*
* Revision 1.12 2007/06/16 19:40:11 bobboau
* some small bugfixes, and added light color options.
*
* Revision 1.11 2007/03/25 03:17:46 kazan
* Implemented COB importer/autogen features - i haven't implemented them
* cleaned up a bunch of signed/unsigned bitching - more cleaning to come
*
* Revision 1.10 2007/03/22 13:15:33 kazan
* MSVC8 compatability checkin, requires wxWidgets 2.8
*
* Revision 1.9 2006/04/07 11:57:05 kazan
* sine _WIN32 !defined checks
*
* Revision 1.8 2005/10/07 14:08:06 kazan
* linux compat syncs - i'm getting memory crashes in linux, hopefully it happens in windows too so it's easier to debug
*
* Revision 1.7 2005/09/19 21:47:12 kazan
* Linux compat changes
*
* Revision 1.6 2005/08/30 04:45:15 kazan
* load/save progress bars, wireframe/solid/texture toggle, app icon, enabled bsp splitting special case count=2
*
* Revision 1.5 2005/08/29 01:25:06 kazan
* Saves POFs succesfully -- completely new BSP Gen routine
* Loads and Renders Textures
*
* Revision 1.4 2005/08/25 15:06:38 kazan
* various bugfixes and tweaks
*
* Revision 1.3 2005/08/23 22:36:42 kazan
* s/std::{vector:string}/kaz_{vector:string}
* renderer motion works
* location PMF::LoadFromPOF bottleneck
*
* Revision 1.2 2005/08/21 01:58:53 kazan
* Context Menu framework, tree ctrl contructor
* bug fixes to std::string handling, POF->PMF translator
* Loaded it's first model!
*
* Revision 1.1.1.1 2004/12/31 06:19:42 kazan
* no message
*
*
*
*/
#if !defined(_WIN32)
#include "compat/filelength.h"
#include "compat/strncmp.h"
#endif
#include <memory.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <boost/scoped_array.hpp>
#include "POFHandler.h"
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Notes: 1/18/2001
// Complete [X]: Need to Finished up FUEL and DOCK structures
// Complete [*]: [most] Array resizing functions need to be updated to the more efficient way i realized while writing the program
// Complete [X]: Need to Finish up Parse_Memory_XXXX functions
// Complete [X]: Need to write file output function
// Notes: 1/26/2001
// Correct a few mistakes in the SavePOF() function
// Notes:11/16/2001
// Moved Notes to top of file
// Notes: 11/17/2001
// Array resizing optimized, found some memory leaks in it too
// Notes: 07/18/2002
// Complete [!]: Search and destroy memory leaks created by destroing (pof)strings without remembering to first delete[] string.str
// Added Parse_Memory_GLOW function and added all of GLOW chunk's functions
// Notes: 10/18/2007
// Replaced all instances of POFstring with std::string
//**********************************************************************************************************************
template<typename T>
void write_to_file(std::ostream& out, const T& value) {
out.write(reinterpret_cast<const char*>(&value), sizeof(T));
}
template<>
void write_to_file(std::ostream& out, const std::string& value) {
out.write(value.c_str(), value.size());
}
template<>
void write_to_file(std::ostream& out, const std::vector<char>& value) {
out.write(value.data(), value.size());
}
void write_to_file(std::ostream& out, const char* value) {
out.write(value, strlen(value));
}
template<>
void write_to_file(std::ostream& out, const uint64_t& value);
template<>
void write_to_file(std::ostream& out, const int64_t& value);
//**********************************************************************************************************************
void POF::SLDC_SetTree(const std::vector<char>& sldc_tree)
// setting this to empty will empty the tree
{
shield_collision.tree_data = sldc_tree;
}
void POF::SLDC_SetTree(std::vector<char>&& sldc_tree)
// setting this to empty will empty the tree
{
shield_collision.tree_data.swap(sldc_tree);
}
//**********************************************************************************************************************
// non member functions
/*std::string APStoString(std::string aps)
{
std::string temp;
temp.length = aps.length();
temp.str = new char[temp.length];
strncpy(temp.str, aps.c_str(), temp.length);
return temp;
}
std::string StringToAPS(std::string &str)
{
char *cstr = new char[str.length + 1];
memset(cstr, 0, str.length + 1);
strncpy(cstr, str.str, str.length);
std::string aps(cstr);
delete[] cstr;
return aps;
}*/
//**********************************************************************************************************************
// Misc
void POF::StatsToFile(std::ofstream &outfile)
{
unsigned int i;
vector3d vect;
vect = ACEN_Get_acen();
// ACEN
outfile << "ACEN: (" << vect.x << "," << vect.y << "," << vect.z << ")" << std::endl;
//DOCK
outfile << "DOCK: " << DOCK_Count_Docks() << " docks." << std::endl;
for (i = 0; i < DOCK_Count_Docks(); i++)
{
outfile << " +Dock[" << i << "]: " << DOCK_Count_Points(i) << " points, " << DOCK_Count_SplinePaths(i) << " spline paths." << std::endl;
}
//EYE
outfile << " EYE: " << EYE_Count_Eyes() << " eyes." << std::endl;
//FUEL
outfile << "FUEL: " << FUEL_Count_Thrusters() << " thrusters." << std::endl;
for (i = 0; i < FUEL_Count_Thrusters(); i++)
{
outfile << " +Fuel[" << i << "]: " << FUEL_Count_Glows(i) << " glow points." << std::endl;
}
//GPNT
outfile << "GPNT: " << GPNT_SlotCount() << " slots." << std::endl;
for (i = 0; i < GPNT_SlotCount(); i++)
{
outfile << " +Gun[" << i << "]: " << GPNT_PointCount(i) << " firing points." << std::endl;
}
//MPNT
outfile << "MPNT: " << MPNT_SlotCount() << " slots." << std::endl;
for (i = 0; i < MPNT_SlotCount(); i++)
{
outfile << " +Mis[" << i << "]: " << MPNT_PointCount(i) << " firing points." << std::endl;
}
//HDR2
outfile << "HRD2: " << HDR2_Get_Mass() << " object mass, " << HDR2_Get_SOBJCount() << " SubObjects." << std::endl;
//INSG
outfile << "INSG: " << INSG_Count_Insignia() << " insignias." << std::endl;
//OBJ2
outfile << "OBJ2: " << OBJ2_Count() << " SubObjects." << std::endl;
for (i = 0; i < OBJ2_Count(); i++)
{
outfile << " +sobj[" << i << "]:" << OBJ2_BSP_Datasize(i) << " bytes of BSP data." << std::endl;
}
//PATH
outfile << "PATH: " << PATH_Count_Paths() << " paths." << std::endl;
for (i = 0; i < PATH_Count_Paths(); i++)
{
outfile << " +Path[" << i << "]: " << PATH_Count_Verts(i) << " verts. Parent: " << StringToAPS(paths.paths[i].parent) << ", Name: " << StringToAPS(paths.paths[i].name) << std::endl;
}
//PINF
outfile << "PINF: ";
std::vector<std::string> strings = PINF_Get();
for (i = 0; i < strings.size(); i++)
{
outfile << strings[i].c_str() << ", ";
}
outfile << std::endl;
//SHLD
outfile << "SHLD: " << SHLD_Count_Faces() << " faces, " << SHLD_Count_Vertices() << " verts." << std::endl;
//SPCL
outfile << "SPCL: " << SPCL_Count() << " specials." << std::endl;
//TGUN
outfile << "TGUN: " << TGUN_Count_Banks() << " turrets." << std::endl;
//TMIS
outfile << "TMIS: " << TMIS_Count_Banks() << " turrets." << std::endl;
//TXTR
outfile << "TXTR: " << TXTR_Count_Textures() << " textures." << std::endl;
for (i = 0; i < TXTR_Count_Textures(); i++)
{
outfile << " +tex[" << i << "]: " << TXTR_GetTextures(i) << std::endl;
}
}
//**********************************************************************************************************************
// File IO Functions
std::string Parse_BPOFstring(char *&localptr)
{
std::string retval;
int len;
memcpy(&len, localptr, sizeof(int));
localptr += sizeof(int);
boost::scoped_array<char> str(new char[len+1]);
memcpy(str.get(), localptr, len);
localptr += len;
str[len] = '\0';
retval = str.get();
return retval;
}
//****************************************************************************************************************
void POF::Parse_Memory_PNT(int mode, char *buffer)
{
// this is going to be FUN
char *localptr = buffer;
GPNT_MPNT *pnt = PNT_Alias(mode);
unsigned int num_slots;
memcpy(&num_slots, buffer, 4);
localptr += 4;
pnt->slots.resize(num_slots);
for (unsigned int i = 0; i < num_slots; i++)
{
unsigned int num_guns;
memcpy(&num_guns, localptr, 4);
pnt->slots[i].guns.resize(num_guns);
localptr += 4; //pointer arithmetic
for (unsigned int j = 0; j < num_guns; j++)
{
memcpy(&pnt->slots[i].guns[j], localptr, sizeof(gun));
localptr += sizeof(gun);
}
}
}
//-----------------------------------------------------------------
void POF::Parse_Memory_T(int mode, char *buffer)
{
TGUN_TMIS *pnt = T_Alias(mode);
char *localptr = buffer;
unsigned int num_banks;
memcpy(&num_banks, localptr, 4);
localptr += 4;
pnt->banks.resize(num_banks);
for (unsigned int i = 0; i < num_banks; i++)
{
//int
memcpy(&pnt->banks[i].sobj_parent, localptr, 4);
localptr += 4; //pointer arithmetic
//int
memcpy(&pnt->banks[i].sobj_par_phys, localptr, 4);
localptr += 4; //pointer arithmetic
//vector (float[3])
memcpy(&pnt->banks[i].turret_normal, localptr, 12);
localptr += 12; //pointer arithmetic
//int
unsigned int num_firing_points;
memcpy(&num_firing_points, localptr, 4);
localptr += 4; //pointer arithmetic
pnt->banks[i].position.resize(num_firing_points);
for (unsigned int j = 0; j < num_firing_points; j++)
{
//verctor (float[3])
memcpy(&pnt->banks[i].position[j], localptr, 12);
localptr += 12;
}
}
}
//-----------------------------------------------------------------
void POF::Parse_Memory_OBJ2(char *buffer)
{
OBJ2 temp;
char *localptr = buffer;
memcpy(&temp.submodel_number, localptr, sizeof(int));
localptr += sizeof(int);
memcpy(&temp.radius, localptr, sizeof(float));
localptr += sizeof(float);
memcpy(&temp.submodel_parent, localptr, sizeof(int));
localptr += sizeof(int);
memcpy(&temp.offset, localptr, sizeof(vector3d));
localptr += sizeof(vector3d);
memcpy(&temp.geometric_center, localptr, sizeof(vector3d));
localptr += sizeof(vector3d);
memcpy(&temp.bounding_box_min_point, localptr, sizeof(vector3d));
localptr += sizeof(vector3d);
memcpy(&temp.bounding_box_max_point, localptr, sizeof(vector3d));
localptr += sizeof(vector3d);
//string copy
/*memcpy(&temp.submodel_name.length, localptr, sizeof(int));
localptr += sizeof(int);
if (temp.submodel_name.length)
temp.submodel_name.str = new char[temp.submodel_name.length];
else
temp.submodel_name.str = 0;
memcpy(temp.submodel_name.str, localptr, temp.submodel_name.length);
localptr += temp.submodel_name.length;*/
temp.submodel_name = Parse_BPOFstring(localptr);
//string copy
/*memcpy(&temp.properties.length, localptr, sizeof(int));
localptr += sizeof(int);
if (temp.properties.length)
temp.properties.str = new char[temp.properties.length];
else
temp.properties.str = NULL;
memcpy(temp.properties.str, localptr, temp.properties.length);
localptr += temp.properties.length;*/
temp.properties = Parse_BPOFstring(localptr);
memcpy(&temp.movement_type, localptr, sizeof(int));
localptr += sizeof(int);
memcpy(&temp.movement_axis, localptr, sizeof(int));
localptr += sizeof(int);
memcpy(&temp.reserved, localptr, sizeof(int));
localptr += sizeof(int);
int size = temp.bsp_data.size();
memcpy(&size, localptr, sizeof(int));
localptr += sizeof(int);
temp.bsp_data.resize(size);
memcpy(&temp.bsp_data.front(), localptr, temp.bsp_data.size());
//done!
temp.reserved = 0;
objects.push_back(temp);
}
//-----------------------------------------------------------------
void POF::Parse_Memory_DOCK(char *buffer)
{
char *localptr = buffer;
unsigned int num_docks;
memcpy(&num_docks, localptr, sizeof(int));
localptr += sizeof(int);
docking.points.resize(num_docks);
for (unsigned int i = 0; i < num_docks; i++)
{
/*
memcpy(&docking.points[i].properties.length, localptr, sizeof(int));
localptr += sizeof(int);
if (docking.points[i].properties.length)
docking.points[i].properties.str = new char[docking.points[i].properties.length];
else
docking.points[i].properties.str = NULL;
memcpy(docking.points[i].properties.str, localptr, docking.points[i].properties.length);
localptr += docking.points[i].properties.length;
*/
docking.points[i].properties = Parse_BPOFstring(localptr);
unsigned int num_spline_paths;
memcpy(&num_spline_paths, localptr, sizeof(int));
localptr += sizeof(int);
docking.points[i].path_number.resize(num_spline_paths);
for (unsigned int j = 0; j < num_spline_paths; j++)
{
memcpy(&docking.points[i].path_number[j], localptr, sizeof(int));
localptr += sizeof(int);
}
unsigned int num_points;
memcpy(&num_points, localptr, sizeof(int));
localptr += sizeof(int);
docking.points[i].points.resize(num_points);
for (unsigned int k = 0; k < num_points; k++)
{
memcpy(&docking.points[i].points[k], localptr, sizeof(gun));
localptr += sizeof(gun);
}
}
}
//-----------------------------------------------------------------
void POF::Parse_Memory_GLOW(char *buffer)
{
//hull_lights
char *localptr = buffer;
unsigned int num_glows_arrays;
memcpy(&num_glows_arrays, localptr, sizeof(int));
localptr += sizeof(int);
hull_lights.lights.resize(num_glows_arrays);
for (unsigned int i = 0; i < num_glows_arrays; i++)
{
memcpy(&hull_lights.lights[i].disp_time, localptr, sizeof(int));
localptr += sizeof(int);
memcpy(&hull_lights.lights[i].on_time, localptr, sizeof(int));
localptr += sizeof(int);
memcpy(&hull_lights.lights[i].off_time, localptr, sizeof(int));
localptr += sizeof(int);
memcpy(&hull_lights.lights[i].obj_parent, localptr, sizeof(int));
localptr += sizeof(int);
memcpy(&hull_lights.lights[i].LOD, localptr, sizeof(int));
localptr += sizeof(int);
memcpy(&hull_lights.lights[i].type, localptr, sizeof(int));
localptr += sizeof(int);
unsigned int num_Lights;
memcpy(&num_Lights, localptr, sizeof(int));
localptr += sizeof(int);
/*memcpy(&hull_lights.lights[i].properties.length, localptr, sizeof(int));
localptr += sizeof(int);
if (hull_lights.lights[i].properties.length)
hull_lights.lights[i].properties.str = new char[hull_lights.lights[i].properties.length];
else
hull_lights.lights[i].properties.str = NULL;
memcpy(hull_lights.lights[i].properties.str, localptr, hull_lights.lights[i].properties.length);
localptr += hull_lights.lights[i].properties.length;*/
hull_lights.lights[i].properties = Parse_BPOFstring(localptr);
hull_lights.lights[i].lights.resize(num_Lights);
for (unsigned int j = 0; j < num_Lights; j++)
{
memcpy(&hull_lights.lights[i].lights[j].point, localptr, sizeof(vector3d));
localptr += sizeof(vector3d);
memcpy(&hull_lights.lights[i].lights[j].norm, localptr, sizeof(vector3d));
localptr += sizeof(vector3d);
memcpy(&hull_lights.lights[i].lights[j].radius, localptr, sizeof(float));
localptr += sizeof(float);
}
}
}
//-----------------------------------------------------------------
void POF::Parse_Memory_FUEL(char *buffer)
{
char *localptr = buffer;
unsigned int num_thrusters;
memcpy(&num_thrusters, localptr, sizeof(int));
localptr += sizeof(int);
thrusters.thrusters.resize(num_thrusters);
for (unsigned int i = 0; i < num_thrusters; i++)
{
unsigned int num_glows;
memcpy(&num_glows, localptr, sizeof(int));
localptr += sizeof(int);
//warning: Version check. version >= 2117 only
if (version >= 2117)
{
/*memcpy(&thrusters.thrusters[i].properties.length, localptr, sizeof(int));
localptr += sizeof(int);
if (thrusters.thrusters[i].properties.length)
thrusters.thrusters[i].properties.str = new char[thrusters.thrusters[i].properties.length];
else
thrusters.thrusters[i].properties.str = NULL;
memcpy(thrusters.thrusters[i].properties.str, localptr, thrusters.thrusters[i].properties.length);
localptr += thrusters.thrusters[i].properties.length;*/
thrusters.thrusters[i].properties = Parse_BPOFstring(localptr);
}
//else
//{
// thrusters.thrusters[i].properties.str = NULL;
// thrusters.thrusters[i].properties.length = 0;
//}// End version check block
thrusters.thrusters[i].points.resize(num_glows);
for (unsigned int j = 0; j < num_glows; j++)
{
memcpy(&thrusters.thrusters[i].points[j], localptr, sizeof(glow_point));
localptr += sizeof(glow_point);
}
}
}
//-----------------------------------------------------------------
void POF::Parse_Memory_SHLD(char *buffer)
{
char *localptr = buffer;
unsigned int num_vertices;
memcpy(&num_vertices, localptr, sizeof(int));
localptr += sizeof(int);
shields.vertecies.resize(num_vertices);
for (unsigned int i = 0; i < num_vertices; i++)
{
memcpy(&shields.vertecies[i], localptr, sizeof(vector3d));
localptr += sizeof(vector3d);
}
unsigned int num_faces;
memcpy(&num_faces, localptr, sizeof(int));
localptr += sizeof(int);
shields.shield_faces.resize(num_faces);
for (unsigned int j = 0; j < num_faces; j++)
{
memcpy(&shields.shield_faces[j], localptr, sizeof(shield_face));
localptr += sizeof(shield_face);
}
}
//-----------------------------------------------------------------
void POF::Parse_Memory_EYE(char *buffer)
{
char *localptr = buffer;
unsigned int num_eye_positions;
memcpy(&num_eye_positions, localptr, sizeof(int));
localptr += sizeof(int);
eyes.eye_positions.resize(num_eye_positions);
for (unsigned int i = 0; i < num_eye_positions; i++)
{
memcpy(&eyes.eye_positions[i], localptr, sizeof(eye_pos));
localptr += sizeof(eye_pos);
}
}
//-----------------------------------------------------------------
void POF::Parse_Memory_ACEN(char *buffer)
{ // really hard.. mwahahah
memcpy(&autocentering.point, buffer, sizeof(vector3d));
}
void POF::Parse_Memory_INSG(char *buffer)
{
char *localptr = buffer;
unsigned int num_insignias;
memcpy(&num_insignias, localptr, sizeof(int));
localptr += sizeof(int);
insignia.insignias.resize(num_insignias);
for (unsigned int i = 0; i < num_insignias; i++)
{
memcpy(&insignia.insignias[i].detail_level, localptr, sizeof(int));
localptr += sizeof(int);
unsigned int num_faces;
memcpy(&num_faces, localptr, sizeof(int));
localptr += sizeof(int);
unsigned int num_verticies;
memcpy(&num_verticies, localptr, sizeof(int));
localptr += sizeof(int);
insignia.insignias[i].vertex_pos.resize(num_verticies);
insignia.insignias[i].faces.resize(num_faces);
for (unsigned int j = 0; j < num_verticies; j++)
{
memcpy(&insignia.insignias[i].vertex_pos[j], localptr, sizeof(vector3d));
localptr += sizeof(vector3d);
}
memcpy(&insignia.insignias[i].offset, localptr, sizeof(vector3d));
localptr += sizeof(vector3d);
for (unsigned int k = 0; k < num_faces; k++)
{
memcpy(&insignia.insignias[i].faces[k], localptr, sizeof(insg_face));
localptr += sizeof(insg_face);
}
}
}
void POF::Parse_Memory_PATH(char *buffer)
{
char *localptr = buffer;
unsigned int num_paths;
memcpy(&num_paths, localptr, sizeof(int));
localptr += sizeof(int);
paths.paths.resize(num_paths);
for (unsigned int i = 0; i < num_paths; i++)
{
/*memcpy(&paths.paths[i].name.length, localptr, sizeof(int));
localptr += sizeof(int);
if (paths.paths[i].name.length)
paths.paths[i].name.str.resize(length);
else
paths.paths[i].name.str = NULL;
memcpy(paths.paths[i].name.str, localptr, paths.paths[i].name.length);
localptr += paths.paths[i].name.length;*/
paths.paths[i].name = Parse_BPOFstring(localptr);
/*memcpy(&paths.paths[i].parent.length, localptr, sizeof(int));
localptr += sizeof(int);
if (paths.paths[i].parent.length)
paths.paths[i].parent.str.resize(length);
else
paths.paths[i].parent.str = NULL;
memcpy(paths.paths[i].parent.str, localptr, paths.paths[i].parent.length);
localptr += paths.paths[i].parent.length;*/
paths.paths[i].parent = Parse_BPOFstring(localptr);
unsigned int num_verts;
memcpy(&num_verts, localptr, sizeof(int));
localptr += sizeof(int);
paths.paths[i].verts.resize(num_verts);
for (unsigned int j = 0; j < num_verts; j++)
{
memcpy(&paths.paths[i].verts[j].pos, localptr, sizeof(vector3d));
localptr += sizeof(vector3d);
memcpy(&paths.paths[i].verts[j].radius, localptr, sizeof(float));
localptr += sizeof(float);
unsigned int num_turrets;
memcpy(&num_turrets, localptr, sizeof(int));
localptr += sizeof(int);
paths.paths[i].verts[j].sobj_number.resize(num_turrets);
for (unsigned int k = 0; k < num_turrets; k++)
{
memcpy(&paths.paths[i].verts[j].sobj_number[k], localptr, sizeof(int));
localptr += sizeof(int);
}
}
}
}
void POF::Parse_Memory_SLDC(char *buffer)
{
char *localptr = buffer;
int size;
memcpy(&size, localptr, sizeof(unsigned int));
localptr += sizeof(unsigned int);
shield_collision.tree_data.resize(size);
memcpy(&shield_collision.tree_data.front(), localptr, size);
}
void POF::Parse_Memory_PINF (char *buffer, int size)
{
pofinfo.strings.resize(size);
if (size) {
memcpy(&pofinfo.strings.front(), buffer, size);
}
}
void POF::Parse_Memory_SPCL(char *buffer)
{
//specials
char *localptr = buffer;
unsigned int num_special_points;
memcpy(&num_special_points, localptr, sizeof(int));
localptr += sizeof(int);
specials.special_points.resize(num_special_points);
for (unsigned int i = 0; i < num_special_points; i++)
{
/*memcpy(&specials.special_points[i].name.length, localptr, sizeof(int));
localptr += sizeof(int);
if (specials.special_points[i].name.length)
specials.special_points[i].name.str = new char[specials.special_points[i].name.length];
else
specials.special_points[i].name.str = NULL;
memcpy(specials.special_points[i].name.str, localptr, specials.special_points[i].name.length);
localptr += specials.special_points[i].name.length;*/
specials.special_points[i].name = Parse_BPOFstring(localptr);
/*memcpy(&specials.special_points[i].properties.length, localptr, sizeof(int));
localptr += sizeof(int);
if (specials.special_points[i].properties.length)
specials.special_points[i].properties.str = new char[specials.special_points[i].properties.length];
else
specials.special_points[i].properties.str = NULL;
memcpy(specials.special_points[i].properties.str, localptr, specials.special_points[i].properties.length);
localptr += specials.special_points[i].properties.length;*/
specials.special_points[i].properties = Parse_BPOFstring(localptr);
memcpy(&specials.special_points[i].point, localptr, sizeof(vector3d));
localptr += sizeof(vector3d);
memcpy(&specials.special_points[i].radius, localptr, sizeof(float));
localptr += sizeof(float);
}
}
void POF::Parse_Memory_HDR2(char *buffer)
{
unsigned int i, first = sizeof(float) + (2 * sizeof(int)) + (2 * sizeof(vector3d));
char *localptr = buffer;
//header
//i get to cheat on the first 6 vars because they are all non-dyamic and i can pull chiggy stuff :)
memcpy(&header, localptr, first);
localptr += first;
unsigned int num_detaillevels;
memcpy(&num_detaillevels, localptr, sizeof(int));
localptr += sizeof(int);
header.sobj_detaillevels.resize(num_detaillevels);
for (i = 0; i < num_detaillevels; i++)
{
memcpy(&header.sobj_detaillevels[i], localptr, sizeof(int));
localptr += sizeof(int);
}
unsigned int num_debris;
memcpy(&num_debris, localptr, sizeof(int));
localptr += sizeof(int);
header.sobj_debris.resize(num_debris);
for (i = 0; i < num_debris; i++)
{
memcpy(&header.sobj_debris[i], localptr, sizeof(int));
localptr += sizeof(int);
}
memcpy(&header.mass, localptr, sizeof(float));
localptr += sizeof(float);
memcpy(&header.mass_center, localptr, sizeof(vector3d));
localptr += sizeof(vector3d);
memcpy(header.moment_inertia, localptr, sizeof(float) * 9);
localptr += (sizeof(float) * 9);
int num_cross_sections;
memcpy(&num_cross_sections, localptr, sizeof(int));
localptr += sizeof(int);
// dunno how this happened.. but i've seen it on atleast one model (created by PCS1 :( ) -- kaz
if (num_cross_sections == -1)
num_cross_sections = 0;
header.cross_sections.resize(num_cross_sections);
for (i = 0; i < (unsigned int)num_cross_sections; i++)
{
memcpy(&header.cross_sections[i], localptr, sizeof(cross_section));
localptr += sizeof(cross_section);
}
unsigned int num_lights;
memcpy(&num_lights, localptr, sizeof(int));
localptr += sizeof(int);
header.lights.resize(num_lights);
for (i = 0; i < num_lights; i++)
{
memcpy(&header.lights[i], localptr, sizeof(muzzle_light));
localptr += sizeof(muzzle_light);
}
}
void POF::Parse_Memory_TXTR(char *buffer)
{
//textures
char *localptr = buffer;
unsigned int num_textures;
memcpy(&num_textures, localptr, sizeof(int));
localptr += sizeof(int);
textures.tex_filename.resize(num_textures);
for (unsigned int i = 0; i < num_textures; i++)
{
/*memcpy(&textures.tex_filename[i].length, localptr, sizeof(int));
localptr += sizeof(int);
if (textures.tex_filename[i].length)
textures.tex_filename[i].str = new char[textures.tex_filename[i].length];
else
textures.tex_filename[i].str = NULL;
memcpy(textures.tex_filename[i].str, localptr, textures.tex_filename[i].length);
localptr += textures.tex_filename[i].length;*/
textures.tex_filename[i] = Parse_BPOFstring(localptr);
}
}