From 43eba7a66a172bb15f7f7a47f2bde276cdc84b78 Mon Sep 17 00:00:00 2001 From: alcexhim Date: Sun, 12 Oct 2014 17:04:34 -0400 Subject: [PATCH] Added Fever Pitch Studios' UTF data format --- .../FeverPitchStudios/UTF/UTFDataFormat.cs | 85 +++++++++++++++++++ .../FeverPitchStudios/UTF/UTFFlags.cs | 13 +++ .../UniversalEditor.Plugins.FileSystem.csproj | 2 + 3 files changed, 100 insertions(+) create mode 100644 CSharp/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/FeverPitchStudios/UTF/UTFDataFormat.cs create mode 100644 CSharp/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/FeverPitchStudios/UTF/UTFFlags.cs diff --git a/CSharp/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/FeverPitchStudios/UTF/UTFDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/FeverPitchStudios/UTF/UTFDataFormat.cs new file mode 100644 index 00000000..010cfc33 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/FeverPitchStudios/UTF/UTFDataFormat.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Text; +using UniversalEditor.IO; +using UniversalEditor.ObjectModels.FileSystem; + +namespace UniversalEditor.DataFormats.FileSystem.FeverPitchStudios.UTF +{ + public class UTFDataFormat : DataFormat + { + private DataFormatReference _dfr = null; + public override DataFormatReference MakeReference() + { + if (_dfr == null) + { + _dfr = base.MakeReference(); + _dfr.Capabilities.Add(typeof(FileSystemObjectModel), DataFormatCapabilities.All); + + } + return _dfr; + } + + private uint mvarFormatVersion = 0; + public uint FormatVersion { get { return mvarFormatVersion; } set { mvarFormatVersion = value; } } + + protected override void LoadInternal(ref ObjectModel objectModel) + { + FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); + if (fsom == null) throw new ObjectModelNotSupportedException(); + + Reader reader = base.Accessor.Reader; + string signature = reader.ReadFixedLengthString(4); + if (signature != "UTF\0") throw new InvalidDataFormatException("File does not begin with 'UTF', 0x00"); + + mvarFormatVersion = reader.ReadUInt32(); + + uint tableOffset = reader.ReadUInt32(); + uint tableLength = reader.ReadUInt32(); + uint unknown1 = reader.ReadUInt32(); + uint entryLength = reader.ReadUInt32(); // always 44? + uint nameTableOffset = reader.ReadUInt32(); // always 56? + uint totalNameTableLength = reader.ReadUInt32(); + uint nameTableLength = reader.ReadUInt32(); + uint fileDataOffset = reader.ReadUInt32(); + uint unknown2 = reader.ReadUInt32(); + uint unknown3 = reader.ReadUInt32(); + uint unknown4 = reader.ReadUInt32(); + uint unknown5 = reader.ReadUInt32(); + + int tableEntryCount = (int)((double)tableLength / entryLength); + + base.Accessor.Seek(nameTableOffset, SeekOrigin.Begin); + string[] nameTableEntries = new string[tableEntryCount]; + for (int i = 0; i < tableEntryCount; i++) + { + // TODO: figure out how to read name table entries (not documented in Xentax) + } + + for (int i = 0; i < tableEntryCount; i++) + { + // table offset of next entry in same hierarchy level + uint nextOffset = reader.ReadUInt32(); + // offset of entry's name in name table + uint nameOffset = reader.ReadUInt32(); + + // 16:folder else:file + UTFFlags flags = (UTFFlags)reader.ReadUInt32(); + uint unknown6 = reader.ReadUInt32(); + // file:offset in file data, folder:offset of its first entry in table + uint dataOffset = reader.ReadUInt32(); + uint totalSize = reader.ReadUInt32(); + uint size1 = reader.ReadUInt32(); + uint size2 = reader.ReadUInt32(); + uint unknown7 = reader.ReadUInt32(); + uint unknown8 = reader.ReadUInt32(); + uint unknown9 = reader.ReadUInt32(); + } + } + + protected override void SaveInternal(ObjectModel objectModel) + { + throw new NotImplementedException(); + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/FeverPitchStudios/UTF/UTFFlags.cs b/CSharp/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/FeverPitchStudios/UTF/UTFFlags.cs new file mode 100644 index 00000000..918593f6 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/FeverPitchStudios/UTF/UTFFlags.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.DataFormats.FileSystem.FeverPitchStudios.UTF +{ + public enum UTFFlags : uint + { + None = 0, + Folder = 16 + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.FileSystem/UniversalEditor.Plugins.FileSystem.csproj b/CSharp/Plugins/UniversalEditor.Plugins.FileSystem/UniversalEditor.Plugins.FileSystem.csproj index cba1a443..e5575a13 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.FileSystem/UniversalEditor.Plugins.FileSystem.csproj +++ b/CSharp/Plugins/UniversalEditor.Plugins.FileSystem/UniversalEditor.Plugins.FileSystem.csproj @@ -92,6 +92,8 @@ + +