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 Lumina.Data;
using Penumbra.GameData.Enums; 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 EntryDescSize = 4;
private const ushort EntrySize = 2; 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 uint NumEntries { get; set; }
private EstFile( EstFile clone ) private EstFile( EstFile clone )
{ {
NumEntries = clone.NumEntries; NumEntries = clone.NumEntries;
_entries = new Dictionary< GenderRace, Dictionary< ushort, ushort > >( clone._entries.Count ); _entries = new SortedList< GenderRace, SortedList< ushort, ushort > >( clone._entries.Count );
foreach( var kvp in clone._entries ) foreach( var (genderRace, data) in clone._entries )
{ {
var dict = kvp.Value.ToDictionary( k => k.Key, k => k.Value ); var dict = new SortedList< ushort, ushort >( data.Count );
_entries.Add( kvp.Key, dict ); foreach( var (setId, value) in data )
{
dict.Add( setId, value );
}
_entries.Add( genderRace, dict );
} }
} }
public EstFile Clone() public EstFile Clone()
=> new( this ); => new(this);
private bool DeleteEntry( GenderRace gr, ushort setId ) private bool DeleteEntry( GenderRace gr, ushort setId )
{ {
@ -58,7 +64,7 @@ namespace Penumbra.Meta.Files
{ {
if( !_entries.TryGetValue( gr, out var setDict ) ) if( !_entries.TryGetValue( gr, out var setDict ) )
{ {
_entries[ gr ] = new Dictionary< ushort, ushort >(); _entries[ gr ] = new SortedList< ushort, ushort >();
setDict = _entries[ gr ]; setDict = _entries[ gr ];
} }
@ -106,8 +112,8 @@ namespace Penumbra.Meta.Files
public byte[] WriteBytes() public byte[] WriteBytes()
{ {
using MemoryStream mem = new( ( int )( 4 + ( EntryDescSize + EntrySize ) * NumEntries ) ); using MemoryStream mem = new(( int )( 4 + ( EntryDescSize + EntrySize ) * NumEntries ));
using BinaryWriter bw = new( mem ); using BinaryWriter bw = new(mem);
bw.Write( NumEntries ); bw.Write( NumEntries );
foreach( var kvp1 in _entries ) foreach( var kvp1 in _entries )
@ -153,5 +159,4 @@ namespace Penumbra.Meta.Files
AddEntry( raceId, setId, entry ); AddEntry( raceId, setId, entry );
} }
} }
}
} }