diff --git a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/Database/UTF/UTFColumnDataType.cs b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/Database/UTF/UTFColumnDataType.cs index 488b3e66..c24252c8 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/Database/UTF/UTFColumnDataType.cs +++ b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/Database/UTF/UTFColumnDataType.cs @@ -1,5 +1,5 @@ // -// CPKColumnDataType.cs +// UTFColumnDataType.cs - CRI Middleware UTF table column data types // // Author: // Mike Becker @@ -21,19 +21,58 @@ using System; namespace UniversalEditor.Plugins.CRI.DataFormats.Database.UTF { + /// + /// The data type for a column in a UTF table. + /// public enum UTFColumnDataType : byte { + /// + /// Mask value for combining with . + /// Mask = 0x0f, + /// + /// The column represents a variable-length array of data. + /// Data = 0x0b, + /// + /// The column represents a variable-length . + /// String = 0x0a, + /// + /// The column represents a value. + /// Float = 0x08, + /// + /// The column represents a value. There may or may not be a distinction between signed and unsigned types. + /// Long2 = 0x07, + /// + /// The column represents a value. There may or may not be a distinction between signed and unsigned types. + /// Long = 0x06, + /// + /// The column represents a value. There may or may not be a distinction between signed and unsigned types. + /// Int2 = 0x05, + /// + /// The column represents a value. There may or may not be a distinction between signed and unsigned types. + /// Int = 0x04, + /// + /// The column represents a value. There may or may not be a distinction between signed and unsigned types. + /// Short2 = 0x03, + /// + /// The column represents a value. There may or may not be a distinction between signed and unsigned types. + /// Short = 0x02, + /// + /// The column represents a value. There may or may not be a distinction between signed and unsigned types. + /// Byte2 = 0x01, + /// + /// The column represents a value. There may or may not be a distinction between signed and unsigned types. + /// Byte = 0x00 } } diff --git a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/Database/UTF/UTFColumnStorageType.cs b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/Database/UTF/UTFColumnStorageType.cs index d336e841..ff5a93fc 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/Database/UTF/UTFColumnStorageType.cs +++ b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/Database/UTF/UTFColumnStorageType.cs @@ -1,5 +1,5 @@ // -// CPKColumnStorageType.cs +// UTFColumnStorageType.cs - CRI Middleware UTF table column storage types // // Author: // Mike Becker @@ -21,11 +21,26 @@ using System; namespace UniversalEditor.Plugins.CRI.DataFormats.Database.UTF { + /// + /// The storage type for a column in a UTF table. + /// public enum UTFColumnStorageType : byte { + /// + /// Mask value for combining with . + /// Mask = 0xf0, + /// + /// Data in this column is stored per row, with a single value written for each ROW in the table. + /// PerRow = 0x50, + /// + /// Data in this column is constant regardless of row, with a single value written for each COLUMN in the table. + /// Constant = 0x30, + /// + /// Data in this column is declared NULL for all rows in the table. No data is written for this column. + /// Zero = 0x10 } } 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 fc56ae63..2bb2b19a 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSDataFormat.cs +++ b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSDataFormat.cs @@ -25,9 +25,16 @@ using UniversalEditor.ObjectModels.FileSystem; namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.AFS { + /// + /// A for loading and saving archives in CRI Middleware AFS/AWB/ACB format. + /// public class AFSDataFormat : DataFormat { private static DataFormatReference _dfr = null; + /// + /// Creates a containing metadata about the . + /// + /// The which contains metadata about the . protected override DataFormatReference MakeReferenceInternal() { if (_dfr == null) @@ -38,8 +45,17 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.AFS return _dfr; } + /// + /// Gets or sets the version of AFS archive to read or write. Defaults to ('AFS\0'). + /// + /// The version of AFS archive to read or write. public AFSFormatVersion FormatVersion { get; set; } = AFSFormatVersion.AFS0; + /// + /// Reads an AFS format 0 archive (AFS). + /// + /// The which reads the data. + /// The into which to populate archive content. private void ReadAFS0(IO.Reader reader, FileSystemObjectModel fsom) { uint fileCount = reader.ReadUInt32(); @@ -83,6 +99,11 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.AFS } } + /// + /// Reads an AFS format 2 archive (AWB/ACB). + /// + /// The which reads the data. + /// The into which to populate archive content. private void ReadAFS2(IO.Reader reader, FileSystemObjectModel fsom) { uint unknown1 = reader.ReadUInt32(); @@ -119,6 +140,10 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.AFS } } + /// + /// Loads the data from the input . + /// + /// A into which to load archive content. protected override void LoadInternal(ref ObjectModel objectModel) { FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); @@ -158,7 +183,10 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.AFS e.Data = Accessor.Reader.ReadBytes(fileinfo.length); } - + /// + /// Writes the data to the output . + /// + /// A containing the archive content to write. protected override void SaveInternal(ObjectModel objectModel) { FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); 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 dc563ed4..2e8438ed 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSFileInfo.cs +++ b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSFileInfo.cs @@ -21,7 +21,7 @@ using System; namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.AFS { - public struct AFSFileInfo + internal struct AFSFileInfo { public string name; public uint offset; diff --git a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSFormatVersion.cs b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSFormatVersion.cs index 51cfcbad..890d10a5 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSFormatVersion.cs +++ b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/AFS/AFSFormatVersion.cs @@ -21,9 +21,18 @@ using System; namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.AFS { + /// + /// The version of AFS archive being handled by a instance. + /// public enum AFSFormatVersion { + /// + /// Older version of AFS, which stores file data and TOC information in the same AFS file. + /// AFS0, + /// + /// Newer version of AFS, which stores file data in an AWB file and writes the TOC to a separate ACB file. + /// AFS2 } } diff --git a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/CPK/CPKDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/CPK/CPKDataFormat.cs index 99f560fa..6bb22081 100755 --- a/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/CPK/CPKDataFormat.cs +++ b/CSharp/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/CPK/CPKDataFormat.cs @@ -29,9 +29,16 @@ using UniversalEditor.Plugins.CRI.DataFormats.Database.UTF; namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK { + /// + /// A for loading and saving archives in CRI Middleware CPK format. + /// public class CPKDataFormat : DataFormat { private static DataFormatReference _dfr = null; + /// + /// Creates a containing metadata about the . + /// + /// The which contains metadata about the . protected override DataFormatReference MakeReferenceInternal() { if (_dfr == null) @@ -44,8 +51,17 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK return _dfr; } + /// + /// Gets or sets the version string which contains information about the library which created the archive. The default value is "CPKMC2.14.00, DLL2.74.00" which is the version string that official CRI Middleware CPK tools use. + /// + /// The version string. public string VersionString { get; set; } = "CPKMC2.14.00, DLL2.74.00"; - public int FileAlignment { get; set; } = 2048; + + /// + /// Gets or sets the sector alignment, in bytes, of the CPK archive. The default value is 2048. + /// + /// The file alignment. + public int SectorAlignment { get; set; } = 2048; // these are mainly for the benefit of the CRI Extensions for FileSystemEditor @@ -84,6 +100,10 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK /// The raw data from the "ETOC" chunk. public byte[] ETocData { get { return _ETocData; } } + /// + /// Loads the data from the input . + /// + /// A into which to load archive content. protected override void LoadInternal (ref ObjectModel objectModel) { FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); @@ -300,7 +320,7 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK new DatabaseField("FileSize", null), new DatabaseField("ContentOffset", contentOffset), // 18432 , should be 20480 new DatabaseField("ContentSize", contentSize), // 8217472, should be 8564736 (347264 difference!) - new DatabaseField("TocOffset", (ulong)FileAlignment), + new DatabaseField("TocOffset", (ulong)SectorAlignment), new DatabaseField("TocSize", (ulong)tocsize), new DatabaseField("TocCrc", null), new DatabaseField("EtocOffset", etocOffset), @@ -323,7 +343,7 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK new DatabaseField("Updates", null), new DatabaseField("Version", (ushort)7), new DatabaseField("Revision", (ushort)0), - new DatabaseField("Align", (ushort)FileAlignment), + new DatabaseField("Align", (ushort)SectorAlignment), new DatabaseField("Sorted", (ushort)1), new DatabaseField("EID", (ushort)1), new DatabaseField("CpkMode", (uint)2), @@ -384,7 +404,7 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK dt.Fields.Add("UserString", "", typeof(string)); ulong offset = initialFileOffset; - offset -= (ulong) FileAlignment; // idk? + offset -= (ulong) SectorAlignment; // idk? List offsets = new List(files.Length); for (int i = 0; i < files.Length; i++) @@ -399,7 +419,7 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK { offsets[i] = new IDOFFSET(offsets[i].INDEX, offsets[i].ID, offset, offsets[i].SIZE); offset += offsets[i].SIZE; - offset = offset.RoundUp(FileAlignment); + offset = offset.RoundUp(SectorAlignment); } offsets.Sort((x, y) => x.INDEX.CompareTo(y.INDEX)); @@ -483,7 +503,11 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK return db; } - + /// + /// Applies a simple cipher to decrypt an encrypted UTF sector. + /// + /// The decrypted data. + /// The data to decrypt. private byte[] DecryptUTF(byte[] input) { byte[] result = new byte[input.Length]; @@ -500,6 +524,10 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK return result; } + /// + /// Writes the data to the output . + /// + /// A containing the archive content to write. protected override void SaveInternal(ObjectModel objectModel) { FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); @@ -529,7 +557,7 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK MemoryAccessor _tmp_ma = new MemoryAccessor(); Document.Save(_tmp_om, dfUTF, _tmp_ma); contentOffset += (ulong)_tmp_ma.Length; - contentOffset = contentOffset.RoundUp(FileAlignment); + contentOffset = contentOffset.RoundUp(SectorAlignment); headerLength = (ulong) _tmp_ma.Length; @@ -539,7 +567,7 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK contentOffset += 16; contentOffset += (ulong)_tmp_ma.Length; - contentOffset = contentOffset.RoundUp(FileAlignment); + contentOffset = contentOffset.RoundUp(SectorAlignment); tocLength = (ulong) _tmp_ma.Length; _tmp_om = BuildItocUTF(sortedOffsets); @@ -550,7 +578,7 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK contentOffset += 16; contentOffset += (ulong)_tmp_ma.Length; - contentOffset = contentOffset.RoundUp(FileAlignment); + contentOffset = contentOffset.RoundUp(SectorAlignment); itocLength = (ulong) _tmp_ma.Length; // 21728 _tmp_om = BuildEtocUTF(files); @@ -572,13 +600,13 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK for (uint i = 0; i < files.Length; i++) { contentSize += (ulong)files[i].Size; - contentSize = contentSize.RoundUp(FileAlignment); + contentSize = contentSize.RoundUp(SectorAlignment); } ulong itocOffset = 16 + headerLength; - itocOffset = itocOffset.RoundUp(FileAlignment); + itocOffset = itocOffset.RoundUp(SectorAlignment); itocOffset += (16 + tocLength); - itocOffset = itocOffset.RoundUp(FileAlignment); + itocOffset = itocOffset.RoundUp(SectorAlignment); itocOffset = itocOffset.RoundToNearestPowerOf2(); @@ -593,7 +621,7 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK bw.WriteInt64(utfHeader_data.Length); bw.WriteBytes(utfHeader_data); - bw.Align(FileAlignment); + bw.Align(SectorAlignment); bw.Accessor.Seek(-6, SeekOrigin.Current); bw.WriteFixedLengthString("(c)CRI"); @@ -603,7 +631,7 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK bw.WriteInt64(utfTOC_data.Length); bw.WriteBytes(utfTOC_data); - bw.Align(FileAlignment); + bw.Align(SectorAlignment); // here comes the ITOC (indexes TOC) UTF table chunk. DatabaseObjectModel utfITOC = BuildItocUTF(sortedOffsets); @@ -619,11 +647,11 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK bw.WriteBytes(utfITOC_data); // here comes the file data. each file is aligned to FileAlignment bytes, apparently. - bw.Align(FileAlignment); + bw.Align(SectorAlignment); for (uint i = 0; i < sortedOffsets.Length; i++) { bw.WriteBytes(files[sortedOffsets[i].INDEX].GetData()); - bw.Align(FileAlignment); + bw.Align(SectorAlignment); } DatabaseObjectModel utfETOC = BuildEtocUTF(files); @@ -631,7 +659,7 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK Document.Save(utfETOC, dfUTF, maUTFETOC); byte[] utfETOC_data = maUTFETOC.ToArray(); - bw.Align(FileAlignment); + bw.Align(SectorAlignment); bw.WriteFixedLengthString("ETOC"); bw.WriteInt32(255); bw.WriteInt64(utfETOC_data.Length);