From e585c425b8884df95a1fa0d714b34d87acb0f29e Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Mon, 11 Apr 2022 19:13:25 -0400 Subject: [PATCH 1/4] provide a way to annotate DataFormats that are incomplete --- .../DataFormatImplementationStatus.cs | 32 ++++++++++++++++++ .../ImplementationStatusAttribute.cs | 33 +++++++++++++++++++ .../UniversalEditor.Core.csproj | 2 ++ 3 files changed, 67 insertions(+) create mode 100644 Libraries/UniversalEditor.Core/DataFormatImplementationStatus.cs create mode 100644 Libraries/UniversalEditor.Core/ImplementationStatusAttribute.cs diff --git a/Libraries/UniversalEditor.Core/DataFormatImplementationStatus.cs b/Libraries/UniversalEditor.Core/DataFormatImplementationStatus.cs new file mode 100644 index 00000000..35332152 --- /dev/null +++ b/Libraries/UniversalEditor.Core/DataFormatImplementationStatus.cs @@ -0,0 +1,32 @@ +// +// DataFormatImplementationStatus.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// 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 +{ + public enum DataFormatImplementationStatus + { + None = 0, + Incomplete = -1, + Load = 1, + Save = 2, + Complete = 3 + } +} diff --git a/Libraries/UniversalEditor.Core/ImplementationStatusAttribute.cs b/Libraries/UniversalEditor.Core/ImplementationStatusAttribute.cs new file mode 100644 index 00000000..7da8558e --- /dev/null +++ b/Libraries/UniversalEditor.Core/ImplementationStatusAttribute.cs @@ -0,0 +1,33 @@ +// +// Implementationstatus.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// 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 +{ + public class ImplementationStatusAttribute : Attribute + { + private DataFormatImplementationStatus _dfStatus = DataFormatImplementationStatus.None; + + public ImplementationStatusAttribute(DataFormatImplementationStatus status) + { + _dfStatus = status; + } + } +} diff --git a/Libraries/UniversalEditor.Core/UniversalEditor.Core.csproj b/Libraries/UniversalEditor.Core/UniversalEditor.Core.csproj index 020f4c42..d4a0e241 100644 --- a/Libraries/UniversalEditor.Core/UniversalEditor.Core.csproj +++ b/Libraries/UniversalEditor.Core/UniversalEditor.Core.csproj @@ -101,6 +101,8 @@ + + From 7899dbc7ce418a75311f03ec5c6a5cbd811f28c6 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Mon, 11 Apr 2022 19:14:24 -0400 Subject: [PATCH 2/4] properly implement Merscom DPK data format --- .../Associations/Merscom/DPK.uexml | 25 +++++++++++ .../FileSystem/Merscom/DPKDataFormat.cs | 41 +++++++++++++------ .../UniversalEditor.Plugins.FileSystem.csproj | 2 + 3 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 Plugins/UniversalEditor.Plugins.FileSystem/Associations/Merscom/DPK.uexml diff --git a/Plugins/UniversalEditor.Plugins.FileSystem/Associations/Merscom/DPK.uexml b/Plugins/UniversalEditor.Plugins.FileSystem/Associations/Merscom/DPK.uexml new file mode 100644 index 00000000..139a03da --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.FileSystem/Associations/Merscom/DPK.uexml @@ -0,0 +1,25 @@ + + + + + + + + *.dpk + + + + DPK4 + + + + + + + + + + + + + diff --git a/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/Merscom/DPKDataFormat.cs b/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/Merscom/DPKDataFormat.cs index c8da3b13..b1f7fab8 100644 --- a/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/Merscom/DPKDataFormat.cs +++ b/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/Merscom/DPKDataFormat.cs @@ -28,6 +28,7 @@ namespace UniversalEditor.DataFormats.FileSystem.Merscom /// /// Provides a for manipulating archives in Merscom DPK format. /// + [ImplementationStatus(DataFormatImplementationStatus.Load)] public class DPKDataFormat : DataFormat { private static DataFormatReference _dfr; @@ -53,27 +54,43 @@ namespace UniversalEditor.DataFormats.FileSystem.Merscom if (DPK4 != "DPK4") throw new InvalidDataFormatException(); - uint u1 = br.ReadUInt32(); - uint u2 = br.ReadUInt32(); + uint archiveLength = br.ReadUInt32(); + uint tocLength = br.ReadUInt32(); uint u3 = br.ReadUInt32(); - uint u4 = br.ReadUInt32(); - uint uFileCount = br.ReadUInt32(); - for (int i = 0; i < uFileCount; i++) + for (int i = 0; i < u3; i++) { - br.SeekUntilFirstNonNull(); + uint u4 = br.ReadUInt32(); + uint decompressedLength = br.ReadUInt32(); + uint compressedLength = br.ReadUInt32(); // 371 39325 + uint offset = br.ReadUInt32(); // 292196 292567 - uint u6 = br.ReadUInt32(); - uint u7 = br.ReadUInt32(); + string nam = br.ReadNullTerminatedString(); // action.accfg + br.Align(4); - string nam = br.ReadNullTerminatedString(); File file = fsom.AddFile(nam); - ushort u8 = br.ReadUInt16(); - uint u9 = br.ReadUInt32(); - uint u10 = br.ReadUInt32(); + file.Properties["compressedLength"] = compressedLength; + file.Properties["offset"] = offset; + + file.Size = decompressedLength; + + file.DataRequest += File_DataRequest; } } + void File_DataRequest(object sender, DataRequestEventArgs e) + { + File file = (File)sender; + uint compressedLength = (uint)file.Properties["compressedLength"]; + uint offset = (uint)file.Properties["offset"]; + + Accessor.Reader.Seek(offset, SeekOrigin.Begin); + byte[] compressedData = Accessor.Reader.ReadBytes(compressedLength); + byte[] decompressedData = Compression.CompressionModule.FromKnownCompressionMethod(Compression.CompressionMethod.Zlib).Decompress(compressedData); + e.Data = decompressedData; + } + + protected override void SaveInternal(ObjectModel objectModel) { throw new NotImplementedException(); diff --git a/Plugins/UniversalEditor.Plugins.FileSystem/UniversalEditor.Plugins.FileSystem.csproj b/Plugins/UniversalEditor.Plugins.FileSystem/UniversalEditor.Plugins.FileSystem.csproj index d35edc4a..59091cee 100644 --- a/Plugins/UniversalEditor.Plugins.FileSystem/UniversalEditor.Plugins.FileSystem.csproj +++ b/Plugins/UniversalEditor.Plugins.FileSystem/UniversalEditor.Plugins.FileSystem.csproj @@ -306,6 +306,7 @@ + @@ -396,6 +397,7 @@ +