diff --git a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Associations/FileSystem/CRI/AFS.uexml b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Associations/FileSystem/CRI/AFS.uexml index f4204708..cba48e6e 100644 --- a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Associations/FileSystem/CRI/AFS.uexml +++ b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Associations/FileSystem/CRI/AFS.uexml @@ -3,9 +3,10 @@ - + *.afs + *.awb diff --git a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSDataFormat.cs index b7c41580..50c1276b 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSDataFormat.cs +++ b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSDataFormat.cs @@ -38,17 +38,10 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.AFS return _dfr; } - protected override void LoadInternal(ref ObjectModel objectModel) + public AFSFormatVersion FormatVersion { get; set; } = AFSFormatVersion.AFS0; + + private void ReadAFS0(IO.Reader reader, FileSystemObjectModel fsom) { - FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); - if (fsom == null) - throw new ObjectModelNotSupportedException(); - - Reader reader = Accessor.Reader; - string afs = reader.ReadFixedLengthString(4); - if (afs != "AFS\0") - throw new InvalidDataFormatException("file does not begin with \"AFS\\0\""); - uint fileCount = reader.ReadUInt32(); AFSFileInfo[] fileinfos = new AFSFileInfo[fileCount]; @@ -93,6 +86,72 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.AFS } } + private void ReadAFS2(IO.Reader reader, FileSystemObjectModel fsom) + { + uint unknown1 = reader.ReadUInt32(); + + uint fileCount = reader.ReadUInt32(); + AFSFileInfo[] fileinfos = new AFSFileInfo[fileCount]; + + uint unknown2 = reader.ReadUInt32(); + for (uint i = 0; i < fileCount; i++) + { + ushort index = reader.ReadUInt16(); + } + for (uint i = 0; i < fileCount; i++) + { + fileinfos[i].offset = reader.ReadUInt32(); + fileinfos[i].offset = fileinfos[i].offset.RoundUp(0x10); // does not affect 6 and 1 in v_etc_streamfiles.awb; idk why + if (i > 0) + { + fileinfos[i - 1].length = fileinfos[i].offset - fileinfos[i - 1].offset; + } + } + + uint totalArchiveSize = reader.ReadUInt32(); + fileinfos[fileinfos.Length - 1].length = totalArchiveSize - fileinfos[fileinfos.Length - 1].offset; + + ushort unknown4 = reader.ReadUInt16(); + + for (uint i = 0; i < fileinfos.Length; i++) + { + File f = fsom.AddFile(i.ToString().PadLeft(8, '0')); + f.Properties.Add("fileinfo", fileinfos[i]); + f.DataRequest += f_DataRequest; + f.Size = fileinfos[i].length; + } + } + + protected override void LoadInternal(ref ObjectModel objectModel) + { + FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); + if (fsom == null) + throw new ObjectModelNotSupportedException(); + + Reader reader = Accessor.Reader; + string afs = reader.ReadFixedLengthString(4); + + switch (afs) + { + case "AFS\0": + { + FormatVersion = AFSFormatVersion.AFS0; + ReadAFS0(reader, fsom); + break; + } + case "AFS2": + { + FormatVersion = AFSFormatVersion.AFS2; + ReadAFS2(reader, fsom); + break; + } + default: + { + throw new InvalidDataFormatException("file does not begin with \"AFS\\0\""); + } + } + } + void f_DataRequest(object sender, DataRequestEventArgs e) { File f = (sender as File); diff --git a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSFileInfo.cs b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSFileInfo.cs index 7ec901c6..13870d22 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSFileInfo.cs +++ b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSFileInfo.cs @@ -28,5 +28,10 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.AFS public DateTime datetime; public uint length; public uint maybeChecksum; + + public override string ToString() + { + return String.Format("{0} : {1} [{2}]", name, offset, length); + } } } diff --git a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSFormatVersion.cs b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSFormatVersion.cs new file mode 100644 index 00000000..51cfcbad --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSFormatVersion.cs @@ -0,0 +1,29 @@ +// +// AFSFormatVersion.cs +// +// Author: +// Mike Becker +// +// Copyright (c) 2019 Mike Becker +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.AFS +{ + public enum AFSFormatVersion + { + AFS0, + AFS2 + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.CRI/UniversalEditor.Plugins.CRI.csproj b/CSharp/Plugins/UniversalEditor.Plugins.CRI/UniversalEditor.Plugins.CRI.csproj index ec55110f..1ec51a54 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.CRI/UniversalEditor.Plugins.CRI.csproj +++ b/CSharp/Plugins/UniversalEditor.Plugins.CRI/UniversalEditor.Plugins.CRI.csproj @@ -39,6 +39,7 @@ +