Merge branch 'master' of github.com:alcexhim/UniversalEditor

This commit is contained in:
Michael Becker 2022-04-11 19:15:40 -04:00
commit 4390d84c01
No known key found for this signature in database
GPG Key ID: 98C333A81F18C22C
2 changed files with 14 additions and 19 deletions

View File

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

View File

@ -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,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 lContentOffset = (ulong)dtUTF.Records[0].Fields["TocOffset"].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);
@ -402,16 +411,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);