Skip to content

Commit

Permalink
[AnimationEditor] Fixed property ordering and more work on DATA/DAT2 …
Browse files Browse the repository at this point in the history
…reading
  • Loading branch information
CadeEvs committed Sep 22, 2022
1 parent 8582620 commit 0e1d3a0
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 28 deletions.
4 changes: 3 additions & 1 deletion Plugins/AnimationEditorPlugin/AssetBankSdkCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Windows.Controls.Primitives;
using AnimationEditorPlugin.Formats;
using FrostySdk;
using FrostySdk.Attributes;
using FrostySdk.IO;
using Microsoft.CSharp;

Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions Plugins/AnimationEditorPlugin/Formats/Bank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,26 @@ 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";
}

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;
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -133,8 +135,6 @@ public void Read(NativeReader reader, Endian endian, long bankStartPosition, Dic
entry.Bank = banks[pointer.GetPosition()];
}
}

entry.Type = m_minEntryNum + i;
}

//
Expand Down
25 changes: 23 additions & 2 deletions Plugins/AnimationEditorPlugin/Formats/Sections/Section_DATA.cs
Original file line number Diff line number Diff line change
@@ -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<BankType, Bank> m_banks;

public Section_DATA(SectionHeader inHeader, Dictionary<BankType, Bank> 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);
}
}
}
14 changes: 9 additions & 5 deletions Plugins/AnimationEditorPlugin/Formats/Sections/Section_REF2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,29 @@ public override void Read(NativeReader reader)
long bankStartPosition = reader.Position;

ulong bankCount = reader.ReadULong(m_endian);
Dictionary<long, Bank> banks = new Dictionary<long, Bank>();
Dictionary<long, Bank> banksPositions = new Dictionary<long, Bank>();
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<long, Bank> bank in banks)
Dictionary<BankType, Bank> banks = new Dictionary<BankType, Bank>();
foreach (KeyValuePair<long, Bank> 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;
}
}
}
16 changes: 10 additions & 6 deletions Plugins/AnimationEditorPlugin/Formats/Sections/Section_REFL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace AnimationEditorPlugin.Formats.Sections
public class Section_REFL : Section
{
public int Size { get; protected set; }
public List<Bank> Banks { get; protected set; }
public Dictionary<BankType, Bank> Banks { get; protected set; }

public Section_REFL(SectionHeader inHeader)
: base(inHeader)
Expand All @@ -25,23 +25,27 @@ public override void Read(NativeReader reader)

// setup banks
ulong bankCount = reader.ReadULong(m_endian);
Dictionary<long, Bank> banks = new Dictionary<long, Bank>();
Dictionary<long, Bank> banksPositions = new Dictionary<long, Bank>();
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<long, Bank> bank in banks)
Dictionary<BankType, Bank> banks = new Dictionary<BankType, Bank>();
foreach (KeyValuePair<long, Bank> 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;
}
}
}
17 changes: 10 additions & 7 deletions Plugins/AnimationEditorPlugin/Managers/AssetBankFileManager.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -87,12 +88,14 @@ public void Initialize(ILogger logger)

strm.Read(reader);

List<Bank> banks;
Dictionary<BankType, Bank> 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)
Expand All @@ -111,21 +114,21 @@ public void Initialize(ILogger logger)
}
else
{
banks = new List<Bank>();
banks = new Dictionary<BankType, Bank>();
}

// 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());
}

/*
* DATA or DAT2 section.
*
* 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)
Expand All @@ -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);

Expand Down

0 comments on commit 0e1d3a0

Please sign in to comment.