mirror of
https://github.com/UltiNaruto/PKGTool
synced 2024-11-10 06:04:19 +00:00
Version 1.1
Fixed extracting/repacking non world PKG
This commit is contained in:
parent
b6067401f4
commit
a4b37a9b16
3 changed files with 11 additions and 4 deletions
|
@ -7,6 +7,7 @@ namespace Dread.FileFormats
|
|||
{
|
||||
public class PKG : Misc.Structs.BinaryStruct
|
||||
{
|
||||
public Int32 HeaderPaddingLength = 0;
|
||||
public List<KeyValuePair<UInt64, MemoryStream>> Files = new List<KeyValuePair<UInt64, MemoryStream>>();
|
||||
|
||||
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<byte>(0, HeaderPaddingLength).ToArray());
|
||||
|
||||
header_size = (Int32)stream.Position;
|
||||
|
||||
// padding
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
{
|
||||
"profiles": {
|
||||
"PKGTool": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "-c \"D:\\Projects\\PKGTool\\PKGTool\\bin\\Debug\\net5.0\\s010_cave\""
|
||||
"commandName": "Project"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue