Skip to content

Commit 0e1d3a0

Browse files
committed
[AnimationEditor] Fixed property ordering and more work on DATA/DAT2 reading
1 parent 8582620 commit 0e1d3a0

File tree

6 files changed

+62
-28
lines changed

6 files changed

+62
-28
lines changed

Plugins/AnimationEditorPlugin/AssetBankSdkCreator.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Windows.Controls.Primitives;
88
using AnimationEditorPlugin.Formats;
99
using FrostySdk;
10+
using FrostySdk.Attributes;
1011
using FrostySdk.IO;
1112
using Microsoft.CSharp;
1213

@@ -122,11 +123,12 @@ private string WriteField(Bank.Entry fieldObj)
122123
string fieldName = ReplaceBadCharacters(fieldObj.Name);
123124
string fieldType = "";
124125

125-
BankType objType = (BankType)fieldObj.BankHash;
126+
BankType objType = fieldObj.BankHash;
126127
fieldType = fieldObj.IsArray
127128
? $"List<{GetFieldType(objType)}>"
128129
: GetFieldType(objType);
129130

131+
sb.AppendLine("[" + typeof(FieldIndexAttribute).Name + "(" + fieldObj.Index + ")]");
130132
sb.AppendLine("public " + fieldType + " " + fieldName + " { get { return _" + fieldName + "; } set { _" + fieldName + " = value; } }");
131133

132134
bool requiresDeclaration = fieldObj.IsArray

Plugins/AnimationEditorPlugin/Formats/Bank.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,26 @@ public class Bank
3535
public class Entry
3636
{
3737
public string Name;
38-
public int Type;
38+
public int Index;
3939
public int Size;
4040
public int Position;
4141
public int NameOffset;
4242

4343
public bool IsArray;
4444

45-
public uint BankHash;
45+
public BankType BankHash;
4646
public Bank Bank;
4747

4848
public override string ToString() => Name != "" ? Name : "Empty";
4949
}
5050

5151
public string Name => m_name;
5252
public Entry[] Entries => m_entries;
53+
public BankType Type => m_type;
5354

5455
private string m_name;
5556
private Entry[] m_entries;
56-
private uint m_type;
57+
private BankType m_type;
5758
private int m_minEntryNum;
5859
private int m_maxEntryNum;
5960
private int m_size;
@@ -88,7 +89,7 @@ public void Read(NativeReader reader, Endian endian, long bankStartPosition, Dic
8889
reader.ReadBoolean();
8990
reader.ReadUShort(endian);
9091

91-
m_type = reader.ReadUInt(endian);
92+
m_type = (BankType)reader.ReadUInt(endian);
9293

9394
//
9495
// entries
@@ -102,10 +103,11 @@ public void Read(NativeReader reader, Endian endian, long bankStartPosition, Dic
102103
for (int i = 0; i < entryCount; i++)
103104
{
104105
Bank.Entry entry = new Entry();
105-
entry.BankHash = reader.ReadUInt(endian);
106+
entry.BankHash = (BankType)reader.ReadUInt(endian);
106107
entry.Size = reader.ReadInt(endian);
107108
entry.Position = reader.ReadInt(endian);
108109
entry.NameOffset = reader.ReadInt(endian);
110+
entry.Index = m_minEntryNum + i;
109111
// unknown
110112
reader.ReadUShort(endian);
111113

@@ -133,8 +135,6 @@ public void Read(NativeReader reader, Endian endian, long bankStartPosition, Dic
133135
entry.Bank = banks[pointer.GetPosition()];
134136
}
135137
}
136-
137-
entry.Type = m_minEntryNum + i;
138138
}
139139

140140
//
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
13
using FrostySdk.IO;
24

35
namespace AnimationEditorPlugin.Formats.Sections
46
{
57
public class Section_DATA : Section
68
{
7-
public Section_DATA(SectionHeader inHeader)
9+
public int Size { get; protected set; }
10+
11+
private Dictionary<BankType, Bank> m_banks;
12+
13+
public Section_DATA(SectionHeader inHeader, Dictionary<BankType, Bank> banks)
814
: base(inHeader)
915
{
16+
m_banks = banks;
1017
}
1118

1219
public override void Read(NativeReader reader)
1320
{
14-
throw new System.NotImplementedException();
21+
Size = (int)reader.ReadUInt(m_endian);
22+
23+
long bankStartPosition = reader.Position;
24+
25+
reader.ReadULong(); // unknown
26+
reader.ReadULong(); // unknown
27+
BankType type = (BankType)reader.ReadULong();
28+
reader.ReadUInt(); // unknown
29+
ushort position = reader.ReadUShort();
30+
reader.ReadUShort(); // unknown
31+
32+
Bank bank = m_banks[type];
33+
34+
Type assetBankType = AssetBankTypeLibrary.GetType(bank.Name);
35+
object assetBankObject = Activator.CreateInstance(assetBankType);
1536
}
1637
}
1738
}

Plugins/AnimationEditorPlugin/Formats/Sections/Section_REF2.cs

+9-5
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,29 @@ public override void Read(NativeReader reader)
4848
long bankStartPosition = reader.Position;
4949

5050
ulong bankCount = reader.ReadULong(m_endian);
51-
Dictionary<long, Bank> banks = new Dictionary<long, Bank>();
51+
Dictionary<long, Bank> banksPositions = new Dictionary<long, Bank>();
5252
for (ulong i = 0; i < bankCount; i++)
5353
{
5454
// this is always in little endian, not sure why
5555
Pointer pointer = new Pointer(reader.Position - bankStartPosition, reader.ReadLong(Endian.Little));
5656

57-
banks.Add(pointer.GetPosition(), new Bank(m_endian));
57+
banksPositions.Add(pointer.GetPosition(), new Bank(m_endian));
5858
}
5959

6060
// parse banks
61-
foreach (KeyValuePair<long, Bank> bank in banks)
61+
Dictionary<BankType, Bank> banks = new Dictionary<BankType, Bank>();
62+
foreach (KeyValuePair<long, Bank> bank in banksPositions)
6263
{
6364
reader.Position = bankStartPosition + bank.Key;
6465

65-
bank.Value.Read(reader, m_endian, bankStartPosition, banks, 2);
66+
bank.Value.Read(reader, m_endian, bankStartPosition, banksPositions, 2);
67+
68+
banks.Add(bank.Value.Type, bank.Value);
6669
}
6770

6871
reader.BaseStream.Position = m_endPosition;
69-
Banks = banks.Values.ToList();
72+
73+
Banks = banks;
7074
}
7175
}
7276
}

Plugins/AnimationEditorPlugin/Formats/Sections/Section_REFL.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace AnimationEditorPlugin.Formats.Sections
77
public class Section_REFL : Section
88
{
99
public int Size { get; protected set; }
10-
public List<Bank> Banks { get; protected set; }
10+
public Dictionary<BankType, Bank> Banks { get; protected set; }
1111

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

2626
// setup banks
2727
ulong bankCount = reader.ReadULong(m_endian);
28-
Dictionary<long, Bank> banks = new Dictionary<long, Bank>();
28+
Dictionary<long, Bank> banksPositions = new Dictionary<long, Bank>();
2929
for (ulong i = 0; i < bankCount; i++)
3030
{
3131
long bankPosition = reader.ReadLong(m_endian);
32-
banks.Add(bankPosition, new Bank(m_endian));
32+
banksPositions.Add(bankPosition, new Bank(m_endian));
3333
}
3434

3535
// parse banks
36-
foreach (KeyValuePair<long, Bank> bank in banks)
36+
Dictionary<BankType, Bank> banks = new Dictionary<BankType, Bank>();
37+
foreach (KeyValuePair<long, Bank> bank in banksPositions)
3738
{
3839
reader.Position = bankStartPosition + bank.Key;
3940

40-
bank.Value.Read(reader, m_endian, bankStartPosition, banks, 1);
41+
bank.Value.Read(reader, m_endian, bankStartPosition, banksPositions, 1);
42+
43+
banks.Add(bank.Value.Type, bank.Value);
4144
}
4245

4346
reader.BaseStream.Position = m_endPosition;
44-
Banks = banks.Values.ToList();
47+
48+
Banks = banks;
4549
}
4650
}
4751
}

Plugins/AnimationEditorPlugin/Managers/AssetBankFileManager.cs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45
using AnimationEditorPlugin.Formats;
56
using AnimationEditorPlugin.Formats.Sections;
67
using Frosty.Core;
@@ -87,12 +88,14 @@ public void Initialize(ILogger logger)
8788

8889
strm.Read(reader);
8990

90-
List<Bank> banks;
91+
Dictionary<BankType, Bank> banks;
9192

9293
/*
9394
* REFL or REF2 section
9495
*
9596
* Contains all of the asset types within the game. This should only be necessary to read when generating an sdk.
97+
*
98+
* @todo: only read when sdk isn't created
9699
*/
97100
header.Read(reader);
98101
if (header.Format == SectionFormat.REFL)
@@ -111,21 +114,21 @@ public void Initialize(ILogger logger)
111114
}
112115
else
113116
{
114-
banks = new List<Bank>();
117+
banks = new Dictionary<BankType, Bank>();
115118
}
116119

117120
// write sdk if one doesn't exist
118-
if (!File.Exists("AssetBankProfiles/" + ProfilesLibrary.SDKFilename + ".dll"))
121+
if (banks.Count != 0 && !File.Exists("AssetBankProfiles/" + ProfilesLibrary.SDKFilename + ".dll"))
119122
{
120-
WriteSdk(banks);
123+
WriteSdk(banks.Values.ToList());
121124
}
122125

123126
/*
124127
* DATA or DAT2 section.
125128
*
126129
* Contains the file system, so all assets within the game.
127130
*/
128-
/*while (reader.BaseStream.Position < endSectionPosition)
131+
if (reader.BaseStream.Position < endSectionPosition)
129132
{
130133
header.Read(reader);
131134
if (header.Format == SectionFormat.DATA)
@@ -136,9 +139,9 @@ public void Initialize(ILogger logger)
136139
{
137140

138141
}
139-
}*/
142+
}
140143

141-
foreach (Bank bank in banks)
144+
foreach (Bank bank in banks.Values)
142145
{
143146
int hash = Fnv1.HashString(bank.Name);
144147

0 commit comments

Comments
 (0)