@@ -447,3 +447,64 @@ void CND::writeSection_Cogs(OutputStream& ostream, const std::vector<SharedRef<C
447
447
);
448
448
}
449
449
}
450
+
451
+
452
+ std::size_t CND::getOffset_PVS (const InputStream& istream, const CndHeader& header)
453
+ {
454
+ AT_SCOPE_EXIT ([ &istream, off = istream.tell () ](){
455
+ istream.seek (off);
456
+ });
457
+
458
+ // PVS section is at the end of thing section
459
+ istream.seek (getOffset_Things (istream, header));
460
+ istream.advance (sizeof (CndThingHeader) * header.numThings );
461
+
462
+ auto sizes = istream.read <CndThingSectorListSizes>();
463
+ istream.advance (
464
+ sizeof (CndPhysicsInfo) * sizes.sizePhysicsInfoList +
465
+ sizeof (uint32_t ) * sizes.sizeNumPathFramesList +
466
+ sizeof (PathFrame) * sizes.sizePathFrameList +
467
+ sizeof (CndActorInfo) * sizes.sizeActorInfoList +
468
+ sizeof (CndWeaponInfo) * sizes.sizeWeaponInfoList +
469
+ sizeof (CndExplosionInfo) * sizes.sizeExplosionInfoList +
470
+ sizeof (CndItemInfo) * sizes.sizeItemInfoList +
471
+ sizeof (CndHintUserVal) * sizes.sizeHintUserValueList +
472
+ sizeof (CndParticleInfo) * sizes.sizeParticleInfoList +
473
+ sizeof (CndAiControlInfoHeader) * sizes.sizeAiControlInfoList +
474
+ sizeof (Vector3f) * sizes.sizeAiPathFrameList
475
+ );
476
+
477
+ return istream.tell ();
478
+ }
479
+
480
+ ByteArray CND::parseSection_PVS (const InputStream& istream)
481
+ {
482
+ try {
483
+ return istream.read <ByteArray>(istream.read <uint32_t >());
484
+ }
485
+ catch (const std::exception & e) {
486
+ throw CNDError (" parseSection_PVS" ,
487
+ " An exception was encountered while parsing section 'PVS': " s + e.what ()
488
+ );
489
+ }
490
+ }
491
+
492
+ ByteArray CND::readPVS (const InputStream& istream)
493
+ {
494
+ auto header = readHeader (istream);
495
+ istream.seek (getOffset_PVS (istream, header));
496
+ return parseSection_PVS (istream);
497
+ }
498
+
499
+ void CND::writeSection_PVS (OutputStream& ostream, const ByteArray& pvs)
500
+ {
501
+ try {
502
+ ostream.write <int32_t >(safe_cast<int32_t >(pvs.size ()));
503
+ ostream.write (pvs);
504
+ }
505
+ catch (const std::exception & e) {
506
+ throw CNDError (" writeSection_PVS" ,
507
+ " An exception was encountered while writing section 'PVS': " s + e.what ()
508
+ );
509
+ }
510
+ }
0 commit comments