Change EST files to be sorted and thus work.

This commit is contained in:
Ottermandias 2022-01-06 11:46:53 +01:00
parent 19b295bbc3
commit aa7d71530d

View file

@ -4,33 +4,39 @@ using System.Linq;
using Lumina.Data;
using Penumbra.GameData.Enums;
namespace Penumbra.Meta.Files
namespace Penumbra.Meta.Files;
// EST Structure:
// 1x [NumEntries : UInt32]
// Apparently entries need to be sorted.
// #NumEntries x [SetId : UInt16] [RaceId : UInt16]
// #NumEntries x [SkeletonId : UInt16]
public class EstFile
{
// EST Structure:
// 1x [NumEntries : UInt32]
// #NumEntries x [SetId : UInt16] [RaceId : UInt16]
// #NumEntries x [SkeletonId : UInt16]
public class EstFile
{
private const ushort EntryDescSize = 4;
private const ushort EntrySize = 2;
private readonly Dictionary< GenderRace, Dictionary< ushort, ushort > > _entries = new();
private readonly SortedList< GenderRace, SortedList< ushort, ushort > > _entries = new();
private uint NumEntries { get; set; }
private EstFile( EstFile clone )
{
NumEntries = clone.NumEntries;
_entries = new Dictionary< GenderRace, Dictionary< ushort, ushort > >( clone._entries.Count );
foreach( var kvp in clone._entries )
_entries = new SortedList< GenderRace, SortedList< ushort, ushort > >( clone._entries.Count );
foreach( var (genderRace, data) in clone._entries )
{
var dict = kvp.Value.ToDictionary( k => k.Key, k => k.Value );
_entries.Add( kvp.Key, dict );
var dict = new SortedList< ushort, ushort >( data.Count );
foreach( var (setId, value) in data )
{
dict.Add( setId, value );
}
_entries.Add( genderRace, dict );
}
}
public EstFile Clone()
=> new( this );
=> new(this);
private bool DeleteEntry( GenderRace gr, ushort setId )
{
@ -58,7 +64,7 @@ namespace Penumbra.Meta.Files
{
if( !_entries.TryGetValue( gr, out var setDict ) )
{
_entries[ gr ] = new Dictionary< ushort, ushort >();
_entries[ gr ] = new SortedList< ushort, ushort >();
setDict = _entries[ gr ];
}
@ -106,8 +112,8 @@ namespace Penumbra.Meta.Files
public byte[] WriteBytes()
{
using MemoryStream mem = new( ( int )( 4 + ( EntryDescSize + EntrySize ) * NumEntries ) );
using BinaryWriter bw = new( mem );
using MemoryStream mem = new(( int )( 4 + ( EntryDescSize + EntrySize ) * NumEntries ));
using BinaryWriter bw = new(mem);
bw.Write( NumEntries );
foreach( var kvp1 in _entries )
@ -153,5 +159,4 @@ namespace Penumbra.Meta.Files
AddEntry( raceId, setId, entry );
}
}
}
}