From 0e1d3a0fdfc783c84017979d331a7829c5948a76 Mon Sep 17 00:00:00 2001 From: Cade Date: Thu, 22 Sep 2022 18:16:50 -0400 Subject: [PATCH] [AnimationEditor] Fixed property ordering and more work on DATA/DAT2 reading --- .../AssetBankSdkCreator.cs | 4 ++- Plugins/AnimationEditorPlugin/Formats/Bank.cs | 14 +++++------ .../Formats/Sections/Section_DATA.cs | 25 +++++++++++++++++-- .../Formats/Sections/Section_REF2.cs | 14 +++++++---- .../Formats/Sections/Section_REFL.cs | 16 +++++++----- .../Managers/AssetBankFileManager.cs | 17 +++++++------ 6 files changed, 62 insertions(+), 28 deletions(-) diff --git a/Plugins/AnimationEditorPlugin/AssetBankSdkCreator.cs b/Plugins/AnimationEditorPlugin/AssetBankSdkCreator.cs index 95864c9dd..75ab09748 100644 --- a/Plugins/AnimationEditorPlugin/AssetBankSdkCreator.cs +++ b/Plugins/AnimationEditorPlugin/AssetBankSdkCreator.cs @@ -7,6 +7,7 @@ using System.Windows.Controls.Primitives; using AnimationEditorPlugin.Formats; using FrostySdk; +using FrostySdk.Attributes; using FrostySdk.IO; using Microsoft.CSharp; @@ -122,11 +123,12 @@ private string WriteField(Bank.Entry fieldObj) string fieldName = ReplaceBadCharacters(fieldObj.Name); string fieldType = ""; - BankType objType = (BankType)fieldObj.BankHash; + BankType objType = fieldObj.BankHash; fieldType = fieldObj.IsArray ? $"List<{GetFieldType(objType)}>" : GetFieldType(objType); + sb.AppendLine("[" + typeof(FieldIndexAttribute).Name + "(" + fieldObj.Index + ")]"); sb.AppendLine("public " + fieldType + " " + fieldName + " { get { return _" + fieldName + "; } set { _" + fieldName + " = value; } }"); bool requiresDeclaration = fieldObj.IsArray diff --git a/Plugins/AnimationEditorPlugin/Formats/Bank.cs b/Plugins/AnimationEditorPlugin/Formats/Bank.cs index 44a09fa13..38639706a 100644 --- a/Plugins/AnimationEditorPlugin/Formats/Bank.cs +++ b/Plugins/AnimationEditorPlugin/Formats/Bank.cs @@ -35,14 +35,14 @@ public class Bank public class Entry { public string Name; - public int Type; + public int Index; public int Size; public int Position; public int NameOffset; public bool IsArray; - public uint BankHash; + public BankType BankHash; public Bank Bank; public override string ToString() => Name != "" ? Name : "Empty"; @@ -50,10 +50,11 @@ public class Entry public string Name => m_name; public Entry[] Entries => m_entries; + public BankType Type => m_type; private string m_name; private Entry[] m_entries; - private uint m_type; + private BankType m_type; private int m_minEntryNum; private int m_maxEntryNum; private int m_size; @@ -88,7 +89,7 @@ public void Read(NativeReader reader, Endian endian, long bankStartPosition, Dic reader.ReadBoolean(); reader.ReadUShort(endian); - m_type = reader.ReadUInt(endian); + m_type = (BankType)reader.ReadUInt(endian); // // entries @@ -102,10 +103,11 @@ public void Read(NativeReader reader, Endian endian, long bankStartPosition, Dic for (int i = 0; i < entryCount; i++) { Bank.Entry entry = new Entry(); - entry.BankHash = reader.ReadUInt(endian); + entry.BankHash = (BankType)reader.ReadUInt(endian); entry.Size = reader.ReadInt(endian); entry.Position = reader.ReadInt(endian); entry.NameOffset = reader.ReadInt(endian); + entry.Index = m_minEntryNum + i; // unknown reader.ReadUShort(endian); @@ -133,8 +135,6 @@ public void Read(NativeReader reader, Endian endian, long bankStartPosition, Dic entry.Bank = banks[pointer.GetPosition()]; } } - - entry.Type = m_minEntryNum + i; } // diff --git a/Plugins/AnimationEditorPlugin/Formats/Sections/Section_DATA.cs b/Plugins/AnimationEditorPlugin/Formats/Sections/Section_DATA.cs index 84ece31d0..8daaf7409 100644 --- a/Plugins/AnimationEditorPlugin/Formats/Sections/Section_DATA.cs +++ b/Plugins/AnimationEditorPlugin/Formats/Sections/Section_DATA.cs @@ -1,17 +1,38 @@ +using System; +using System.Collections.Generic; using FrostySdk.IO; namespace AnimationEditorPlugin.Formats.Sections { public class Section_DATA : Section { - public Section_DATA(SectionHeader inHeader) + public int Size { get; protected set; } + + private Dictionary m_banks; + + public Section_DATA(SectionHeader inHeader, Dictionary banks) : base(inHeader) { + m_banks = banks; } public override void Read(NativeReader reader) { - throw new System.NotImplementedException(); + Size = (int)reader.ReadUInt(m_endian); + + long bankStartPosition = reader.Position; + + reader.ReadULong(); // unknown + reader.ReadULong(); // unknown + BankType type = (BankType)reader.ReadULong(); + reader.ReadUInt(); // unknown + ushort position = reader.ReadUShort(); + reader.ReadUShort(); // unknown + + Bank bank = m_banks[type]; + + Type assetBankType = AssetBankTypeLibrary.GetType(bank.Name); + object assetBankObject = Activator.CreateInstance(assetBankType); } } } \ No newline at end of file diff --git a/Plugins/AnimationEditorPlugin/Formats/Sections/Section_REF2.cs b/Plugins/AnimationEditorPlugin/Formats/Sections/Section_REF2.cs index f52098b3b..4d1748642 100644 --- a/Plugins/AnimationEditorPlugin/Formats/Sections/Section_REF2.cs +++ b/Plugins/AnimationEditorPlugin/Formats/Sections/Section_REF2.cs @@ -48,25 +48,29 @@ public override void Read(NativeReader reader) long bankStartPosition = reader.Position; ulong bankCount = reader.ReadULong(m_endian); - Dictionary banks = new Dictionary(); + Dictionary banksPositions = new Dictionary(); for (ulong i = 0; i < bankCount; i++) { // this is always in little endian, not sure why Pointer pointer = new Pointer(reader.Position - bankStartPosition, reader.ReadLong(Endian.Little)); - banks.Add(pointer.GetPosition(), new Bank(m_endian)); + banksPositions.Add(pointer.GetPosition(), new Bank(m_endian)); } // parse banks - foreach (KeyValuePair bank in banks) + Dictionary banks = new Dictionary(); + foreach (KeyValuePair bank in banksPositions) { reader.Position = bankStartPosition + bank.Key; - bank.Value.Read(reader, m_endian, bankStartPosition, banks, 2); + bank.Value.Read(reader, m_endian, bankStartPosition, banksPositions, 2); + + banks.Add(bank.Value.Type, bank.Value); } reader.BaseStream.Position = m_endPosition; - Banks = banks.Values.ToList(); + + Banks = banks; } } } \ No newline at end of file diff --git a/Plugins/AnimationEditorPlugin/Formats/Sections/Section_REFL.cs b/Plugins/AnimationEditorPlugin/Formats/Sections/Section_REFL.cs index ff758d6ba..218557103 100644 --- a/Plugins/AnimationEditorPlugin/Formats/Sections/Section_REFL.cs +++ b/Plugins/AnimationEditorPlugin/Formats/Sections/Section_REFL.cs @@ -7,7 +7,7 @@ namespace AnimationEditorPlugin.Formats.Sections public class Section_REFL : Section { public int Size { get; protected set; } - public List Banks { get; protected set; } + public Dictionary Banks { get; protected set; } public Section_REFL(SectionHeader inHeader) : base(inHeader) @@ -25,23 +25,27 @@ public override void Read(NativeReader reader) // setup banks ulong bankCount = reader.ReadULong(m_endian); - Dictionary banks = new Dictionary(); + Dictionary banksPositions = new Dictionary(); for (ulong i = 0; i < bankCount; i++) { long bankPosition = reader.ReadLong(m_endian); - banks.Add(bankPosition, new Bank(m_endian)); + banksPositions.Add(bankPosition, new Bank(m_endian)); } // parse banks - foreach (KeyValuePair bank in banks) + Dictionary banks = new Dictionary(); + foreach (KeyValuePair bank in banksPositions) { reader.Position = bankStartPosition + bank.Key; - bank.Value.Read(reader, m_endian, bankStartPosition, banks, 1); + bank.Value.Read(reader, m_endian, bankStartPosition, banksPositions, 1); + + banks.Add(bank.Value.Type, bank.Value); } reader.BaseStream.Position = m_endPosition; - Banks = banks.Values.ToList(); + + Banks = banks; } } } \ No newline at end of file diff --git a/Plugins/AnimationEditorPlugin/Managers/AssetBankFileManager.cs b/Plugins/AnimationEditorPlugin/Managers/AssetBankFileManager.cs index 91a27b920..67333f9f3 100644 --- a/Plugins/AnimationEditorPlugin/Managers/AssetBankFileManager.cs +++ b/Plugins/AnimationEditorPlugin/Managers/AssetBankFileManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using AnimationEditorPlugin.Formats; using AnimationEditorPlugin.Formats.Sections; using Frosty.Core; @@ -87,12 +88,14 @@ public void Initialize(ILogger logger) strm.Read(reader); - List banks; + Dictionary banks; /* * REFL or REF2 section * * Contains all of the asset types within the game. This should only be necessary to read when generating an sdk. + * + * @todo: only read when sdk isn't created */ header.Read(reader); if (header.Format == SectionFormat.REFL) @@ -111,13 +114,13 @@ public void Initialize(ILogger logger) } else { - banks = new List(); + banks = new Dictionary(); } // write sdk if one doesn't exist - if (!File.Exists("AssetBankProfiles/" + ProfilesLibrary.SDKFilename + ".dll")) + if (banks.Count != 0 && !File.Exists("AssetBankProfiles/" + ProfilesLibrary.SDKFilename + ".dll")) { - WriteSdk(banks); + WriteSdk(banks.Values.ToList()); } /* @@ -125,7 +128,7 @@ public void Initialize(ILogger logger) * * Contains the file system, so all assets within the game. */ - /*while (reader.BaseStream.Position < endSectionPosition) + if (reader.BaseStream.Position < endSectionPosition) { header.Read(reader); if (header.Format == SectionFormat.DATA) @@ -136,9 +139,9 @@ public void Initialize(ILogger logger) { } - }*/ + } - foreach (Bank bank in banks) + foreach (Bank bank in banks.Values) { int hash = Fnv1.HashString(bank.Name);