From 163b0c5407ed163d681cea60daa5fbe7cfe7d09c Mon Sep 17 00:00:00 2001 From: NintenHero <37460517+MichaelHinrichs@users.noreply.github.com> Date: Sat, 9 Mar 2024 11:14:12 -0600 Subject: [PATCH] Add files via upload --- ACotGK-seng-Extractor.csproj | 9 +++++ ACotGK-seng-Extractor.sln | 25 ++++++++++++++ Program.cs | 65 ++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 ACotGK-seng-Extractor.csproj create mode 100644 ACotGK-seng-Extractor.sln create mode 100644 Program.cs diff --git a/ACotGK-seng-Extractor.csproj b/ACotGK-seng-Extractor.csproj new file mode 100644 index 0000000..30cdbf3 --- /dev/null +++ b/ACotGK-seng-Extractor.csproj @@ -0,0 +1,9 @@ + + + + Exe + net5.0 + ACotGK_seng_Extractor + + + diff --git a/ACotGK-seng-Extractor.sln b/ACotGK-seng-Extractor.sln new file mode 100644 index 0000000..18e9764 --- /dev/null +++ b/ACotGK-seng-Extractor.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.34407.143 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ACotGK-seng-Extractor", "ACotGK-seng-Extractor.csproj", "{879F783D-F43F-41E2-B47F-5A7D35CFC70B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {879F783D-F43F-41E2-B47F-5A7D35CFC70B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {879F783D-F43F-41E2-B47F-5A7D35CFC70B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {879F783D-F43F-41E2-B47F-5A7D35CFC70B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {879F783D-F43F-41E2-B47F-5A7D35CFC70B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E148DFAD-0BFD-44C3-A171-4AC9AD3B50A5} + EndGlobalSection +EndGlobal diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..36aea13 --- /dev/null +++ b/Program.cs @@ -0,0 +1,65 @@ +//Written for The Accursed Crown of the Giant King. https://store.steampowered.com/app/1970780/ +using System; +using System.IO; + +namespace ACotGK_seng_Extractor +{ + static class Program + { + public static BinaryReader br; + + static void Main(string[] args) + { + using FileStream source = File.OpenRead(args[0]); + br = new(source); + int fileCount = br.ReadInt32(); + + System.Collections.Generic.List fileTable = new(); + for (int i = 0; i < fileCount - 1; i++) + { + br.ReadInt32(); + string name = NullTerminatedString(); + if (br.BaseStream.Position < (i + 1) * 0x4C + 0x48) + br.BaseStream.Position = (i + 1) * 0x4C + 0x48; + + fileTable.Add(new SUBFILE + { + name = name, + offset = br.ReadInt32(), + size = br.ReadInt32() + }); + } + foreach (SUBFILE sub in fileTable) + { + br.BaseStream.Position = sub.offset; + Directory.CreateDirectory(Path.GetDirectoryName(args[0]) + "//" + Path.GetFileNameWithoutExtension(args[0]) + "//" + Path.GetDirectoryName(sub.name)); + using FileStream FS = File.Create(Path.GetDirectoryName(args[0]) + "//" + Path.GetFileNameWithoutExtension(args[0]) + "//" + sub.name); + BinaryWriter bw = new(FS); + bw.Write(br.ReadBytes(sub.size)); + bw.Close(); + } + } + + public struct SUBFILE + { + public string name; + public int offset; + public int size; + } + + public static string NullTerminatedString() + { + char[] fileName = Array.Empty(); + char readchar = (char)1; + while (readchar > 0) + { + readchar = br.ReadChar(); + Array.Resize(ref fileName, fileName.Length + 1); + fileName[^1] = readchar; + } + Array.Resize(ref fileName, fileName.Length - 1); + string name = new(fileName); + return name; + } + } +}