@@ -10,36 +10,44 @@ namespace TACTLib.Core.Product.Fenris;
1010
1111public class CoreTOC {
1212 [ StructLayout ( LayoutKind . Sequential , Pack = 1 , Size = 0xC ) ]
13- public struct TOCEntry {
13+ public record struct TOCEntry {
1414 public SnoHandle Sno ;
1515 public int NameOffset ;
1616 }
1717
1818 public int [ ] GroupCounts { get ; }
1919 public int [ ] GroupOffsets { get ; }
2020 public int [ ] GroupCounts2 { get ; }
21+ public uint [ ] GroupFormats { get ; }
2122 public uint PrimaryId { get ; }
22- public Dictionary < SnoHandle , string > Files { get ; } = new ( ) ;
23+ public Dictionary < SnoHandle , string > Files { get ; } = [ ] ;
2324
2425 public CoreTOC ( Stream ? stream , EncryptedSnos encrypted ) {
2526 using var _ = new PerfCounter ( "CoreTOC::cctor`Stream`EncryptedSnos" ) ;
2627 if ( stream == null ) {
2728 throw new ArgumentNullException ( nameof ( stream ) ) ;
2829 }
2930
31+ var magic = stream . Read < uint > ( ) ;
32+ var isNew = magic == 0xBCDE6611 ;
33+ if ( ! isNew ) {
34+ stream . Position = 0 ;
35+ }
36+
3037 var count = stream . Read < int > ( ) ;
3138 GroupCounts = stream . ReadArray < int > ( count ) ;
3239 GroupOffsets = stream . ReadArray < int > ( count ) ;
3340 GroupCounts2 = stream . ReadArray < int > ( count ) ;
41+ GroupFormats = isNew ? stream . ReadArray < uint > ( count ) : [ ] ;
3442
3543 PrimaryId = stream . Read < uint > ( ) ;
3644
3745 var baseOffset = stream . Position ;
3846
39- Span < byte > stringBuffer = stackalloc byte [ 0xFF ] ;
47+ Span < byte > stringBuffer = stackalloc byte [ 0x1FF ] ;
4048 for ( var i = 0 ; i < count ; ++ i ) {
4149 // I'm assuming that GroupCounts2 is the count but with replaced files included.
42- Debug . Assert ( GroupCounts [ i ] == GroupCounts2 [ i ] , "GroupCounts[i] == GroupCounts2[i]" ) ;
50+ Debug . Assert ( GroupCounts [ i ] == GroupCounts2 [ i ] ) ;
4351 stream . Position = baseOffset + GroupOffsets [ i ] ;
4452
4553 var stringOffset = baseOffset + GroupOffsets [ i ] + 0xC * GroupCounts [ i ] ;
0 commit comments