From 1f96edaef51e7a45360b14f9777607712cfc0410 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sun, 20 Mar 2022 23:59:41 -0400 Subject: [PATCH 1/3] i'm stupid, TocOffset is SOMETIMES equal to ContentOffset, but we really want ContentOffset --- .../DataFormats/FileSystem/CPK/CPKDataFormat.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/CPK/CPKDataFormat.cs b/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/CPK/CPKDataFormat.cs index 7b405637..b30df5bf 100644 --- a/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/CPK/CPKDataFormat.cs +++ b/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/CPK/CPKDataFormat.cs @@ -163,6 +163,7 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK // Rebuilt based on cpk_unpack // Rebuilt AGAIN based on github.com/esperknight/CriPakTools DatabaseObjectModel utf_om = ReadUTF("CPK ", br, out _HeaderData); + int utf_checksum = br.ReadInt32(); // maybe checksum? DatabaseTable dtUTF = utf_om.Tables[0]; HeaderTable = dtUTF; @@ -267,7 +268,7 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK uint decompressedLength = (uint)dtUTFTOC.Records[i].Fields["FileSize"].Value; uint compressedLength = (uint)dtUTFTOC.Records[i].Fields["ExtractSize"].Value; ulong offset = (ulong)dtUTFTOC.Records[i].Fields["FileOffset"].Value; - ulong lContentOffset = (ulong)dtUTF.Records[0].Fields["TocOffset"].Value; + ulong lContentOffset = (ulong)dtUTF.Records[0].Fields["ContentOffset"].Value; offset += lContentOffset; File f = fsom.AddFile(fileName); @@ -402,16 +403,17 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK } } - private DatabaseObjectModel ReadUTF(string v, Reader br, out byte[] data) + private DatabaseObjectModel ReadUTF(string expectedSignature, Reader br, out byte[] data) { string tocSignature = br.ReadFixedLengthString(4); - if (tocSignature != v) + if (tocSignature != expectedSignature) throw new InvalidDataFormatException(); - int unknown1 = br.ReadInt32(); + int unknown1 = br.ReadInt32(); // always 255? // UTF table for TOC long utf_size = br.ReadInt64(); // size of UTF including "@UTF" + byte[] utf_data = br.ReadBytes(utf_size); MemoryAccessor ma = new MemoryAccessor(utf_data); From 3eaf148e3145465442749d5c2ae14cc31a8f57d3 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Mon, 21 Mar 2022 00:04:03 -0400 Subject: [PATCH 2/3] now that we inherit from EditorApplication (defined in UniversalEditor.UserInterface.dll), this check is useless and doesn't work if the DLL is missing --- .../UniversalEditor.Bootstrapper/Program.cs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/Applications/UniversalEditor.Bootstrapper/Program.cs b/Applications/UniversalEditor.Bootstrapper/Program.cs index 8d9af4e0..5abfa912 100644 --- a/Applications/UniversalEditor.Bootstrapper/Program.cs +++ b/Applications/UniversalEditor.Bootstrapper/Program.cs @@ -42,21 +42,6 @@ namespace UniversalEditor.Bootstrapper [STAThread] static void Main() { - try - { - string path = - System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) - + System.IO.Path.DirectorySeparatorChar.ToString() - + "UniversalEditor.UserInterface.dll"; - - Assembly asm = System.Reflection.Assembly.LoadFile(path); - } - catch - { - MessageDialog.ShowDialog("The file 'UniversalEditor.UserInterface.dll' is required for this software to run, but is either missing or corrupted. Please re-install the software and try again.", "Error", MessageDialogButtons.OK, MessageDialogIcon.Error); - return; - } - (new Program()).Start(); } } From 4f05e156210b12c15f6ffca4cc2cb14b66cb6037 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Mon, 21 Mar 2022 15:31:58 -0400 Subject: [PATCH 3/3] kind of hacky but all the test files work now --- .../DataFormats/FileSystem/CPK/CPKDataFormat.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/CPK/CPKDataFormat.cs b/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/CPK/CPKDataFormat.cs index b30df5bf..4e9fa85b 100644 --- a/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/CPK/CPKDataFormat.cs +++ b/Plugins/UniversalEditor.Plugins.CRI/DataFormats/FileSystem/CPK/CPKDataFormat.cs @@ -268,7 +268,15 @@ namespace UniversalEditor.Plugins.CRI.DataFormats.FileSystem.CPK uint decompressedLength = (uint)dtUTFTOC.Records[i].Fields["FileSize"].Value; uint compressedLength = (uint)dtUTFTOC.Records[i].Fields["ExtractSize"].Value; ulong offset = (ulong)dtUTFTOC.Records[i].Fields["FileOffset"].Value; + + ulong lTocOffset = (ulong)dtUTF.Records[0].Fields["TocOffset"].Value; ulong lContentOffset = (ulong)dtUTF.Records[0].Fields["ContentOffset"].Value; + + // HACK: according to kamikat cpk tools, the real content offset is whichever is smaller TocOffset vs ContentOffset + // https://github.com/kamikat/cpktools/blob/master/cpkunpack.py + // this feels EXTREMELY hacky, but it works... for now + ulong lRealContentOffset = Math.Min(lTocOffset, lContentOffset); + offset += lContentOffset; File f = fsom.AddFile(fileName);