From a4b37a9b16da01d19ce7858c05601a2beb829307 Mon Sep 17 00:00:00 2001 From: UltiNaruto Date: Thu, 14 Oct 2021 07:57:41 +0200 Subject: [PATCH] Version 1.1 Fixed extracting/repacking non world PKG --- PKGTool/Dread/FileFormats/PKG.cs | 10 ++++++++-- PKGTool/Program.cs | 2 ++ PKGTool/Properties/launchSettings.json | 3 +-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/PKGTool/Dread/FileFormats/PKG.cs b/PKGTool/Dread/FileFormats/PKG.cs index 069fff8..1fdf122 100644 --- a/PKGTool/Dread/FileFormats/PKG.cs +++ b/PKGTool/Dread/FileFormats/PKG.cs @@ -7,6 +7,7 @@ namespace Dread.FileFormats { public class PKG : Misc.Structs.BinaryStruct { + public Int32 HeaderPaddingLength = 0; public List> Files = new List>(); public void Close() @@ -20,7 +21,7 @@ namespace Dread.FileFormats { Int32 i = 0; Int32[,] offsets = new Int32[Files.Count, 2]; - Int32 cursor = 12 + Files.Count * 16; + Int32 cursor = 12 + Files.Count * 16 + HeaderPaddingLength; if ((cursor % 8) != 0) cursor += 8 - (cursor % 8); foreach (var file in Files) { @@ -66,7 +67,10 @@ namespace Dread.FileFormats } if (header_size != (Int32)stream.Position) - throw new Exception("Invalid PKG file! (Guessed header size doesn't correspond to the real size)"); + { + HeaderPaddingLength = header_size - (Int32)stream.Position; + stream.Position += HeaderPaddingLength; + } // padding if ((stream.Position % 8) != 0) stream.Position += 8 - (stream.Position % 8); @@ -103,6 +107,8 @@ namespace Dread.FileFormats writer.Write(offsets[i, 1]); } + writer.Write(Enumerable.Repeat(0, HeaderPaddingLength).ToArray()); + header_size = (Int32)stream.Position; // padding diff --git a/PKGTool/Program.cs b/PKGTool/Program.cs index e6dd1a6..0e128a6 100644 --- a/PKGTool/Program.cs +++ b/PKGTool/Program.cs @@ -128,6 +128,7 @@ namespace PKGTool using(var list = new StreamWriter(String.Join(Path.DirectorySeparatorChar, outPath, "files.list"))) { + list.WriteLine($"Padding = {pkg.HeaderPaddingLength}"); foreach (var file in pkg.Files) { fn = GenerateFileName(file.Key, file.Value); @@ -175,6 +176,7 @@ namespace PKGTool using (var list = new StreamReader(String.Join(Path.DirectorySeparatorChar, args[1], "files.list"))) { + pkg.HeaderPaddingLength = Convert.ToInt32(list.ReadLine().Substring("Padding = ".Length)); while (!list.EndOfStream) { fn = list.ReadLine().TrimEnd('\r', '\n'); diff --git a/PKGTool/Properties/launchSettings.json b/PKGTool/Properties/launchSettings.json index 2342efe..7873eaf 100644 --- a/PKGTool/Properties/launchSettings.json +++ b/PKGTool/Properties/launchSettings.json @@ -1,8 +1,7 @@ { "profiles": { "PKGTool": { - "commandName": "Project", - "commandLineArgs": "-c \"D:\\Projects\\PKGTool\\PKGTool\\bin\\Debug\\net5.0\\s010_cave\"" + "commandName": "Project" } } } \ No newline at end of file