Skip to content

Commit

Permalink
Add support for extracting Sting's .pck files in the PC versions of Y…
Browse files Browse the repository at this point in the history
…ggdra Union and Riviera
  • Loading branch information
AdmiralCurtiss committed Jul 17, 2024
1 parent 566de2b commit 4b6cbb6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions HyoutaToolsLib/ProgramNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class ProgramNames {
{ new KeyValuePair<ProgramName, ExecuteProgramDelegate>( new ProgramName( "Patches.Bps.TextToBpsConverter", "-" ), Patches.Bps.TextToBpsConverter.Execute) },
{ new KeyValuePair<ProgramName, ExecuteProgramDelegate>( new ProgramName( "Patches.Bps.Create", "-" ), Patches.Bps.Program.ExecuteCreate) },
{ new KeyValuePair<ProgramName, ExecuteProgramDelegate>( new ProgramName( "Tales.Compression.Decompress", "-" ), Tales.Compression.Program.Decompress) },
{ new KeyValuePair<ProgramName, ExecuteProgramDelegate>( new ProgramName( "Sting.PcPckFile.Extract", "-" ), Sting.PcPckFile.ExecuteExtract) },
};
}
}
48 changes: 48 additions & 0 deletions HyoutaToolsLib/Sting/PcPckFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using HyoutaPluginBase;
using HyoutaTools.Tales.Vesperia.NUB;
using HyoutaUtils;
using HyoutaUtils.Streams;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HyoutaTools.Sting {
public class PcPckFile {
public static void Extract(DuplicatableStream file, string destination) {
System.IO.Directory.CreateDirectory(destination);

uint fileCount = file.ReadUInt32();
uint headerLength = file.ReadUInt32();

for (uint i = 0; i < fileCount; ++i) {
string filename = file.ReadSizedString(0x40, TextUtils.GameTextEncoding.ShiftJIS).TrimNull();
uint length = file.ReadUInt32();
uint offset = file.ReadUInt32();
using (FileStream newFile = new FileStream(System.IO.Path.Combine(destination, filename), FileMode.Create)) {
long p = file.Position;
file.Position = offset;
StreamUtils.CopyStream(file, newFile, length);
file.Position = p;
}
}
}

public static int ExecuteExtract(List<string> args) {
if (args.Count == 0) {
Console.WriteLine("Sting.PcPckFile.Extract file.pck [output_folder]");
return -1;
}

try {
Extract(new DuplicatableFileStream(args[0]), args.Count > 1 ? args[1] : (args[0] + ".ex"));
return 0;
} catch (Exception e) {
Console.WriteLine(e.Message);
return -1;
}
}
}
}

0 comments on commit 4b6cbb6

Please sign in to comment.