add support for AFS2 (AWB) format, without filenames (ACB) since don't have a sample to test

This commit is contained in:
Michael Becker 2019-11-15 14:20:10 -05:00
parent 74770c9a3e
commit c31ca9f164
No known key found for this signature in database
GPG Key ID: 389DFF5D73781A12
5 changed files with 106 additions and 11 deletions

View File

@ -3,9 +3,10 @@
<Associations>
<Association>
<Filters>
<Filter Title="AFS archive">
<Filter Title="CRI Middleware AFS/AWB/ACB archive">
<FileNameFilters>
<FileNameFilter>*.afs</FileNameFilter>
<FileNameFilter>*.awb</FileNameFilter>
</FileNameFilters>
<MagicByteSequences>
<MagicByteSequence>

View File

@ -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);

View File

@ -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);
}
}
}

View File

@ -0,0 +1,29 @@
//
// AFSFormatVersion.cs
//
// Author:
// Mike Becker <alcexhim@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
using System;
namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.AFS
{
public enum AFSFormatVersion
{
AFS0,
AFS2
}
}

View File

@ -39,6 +39,7 @@
<Compile Include="DataFormats\FileSystem\CPK\UTF\UTFDataFormat.cs" />
<Compile Include="DataFormats\FileSystem\AFS\AFSDataFormat.cs" />
<Compile Include="DataFormats\FileSystem\AFS\AFSFileInfo.cs" />
<Compile Include="DataFormats\FileSystem\AFS\AFSFormatVersion.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="DataFormats\" />