Skip to content

Commit

Permalink
Properly extract .tobj entries in HashFS v2
Browse files Browse the repository at this point in the history
  • Loading branch information
sk-zk committed Jul 4, 2024
1 parent 64c47f7 commit fbcddd4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
29 changes: 15 additions & 14 deletions Extractor/Extractor.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>extractor</AssemblyName>
<RootNamespace>Extractor</RootNamespace>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>extractor</AssemblyName>
<RootNamespace>Extractor</RootNamespace>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<Version>2024.07.04</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Mono.Options" Version="6.12.0.148" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Mono.Options" Version="6.12.0.148" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TruckLib\TruckLib.HashFs\TruckLib.HashFs.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TruckLib\TruckLib.HashFs\TruckLib.HashFs.csproj" />
</ItemGroup>

</Project>
22 changes: 17 additions & 5 deletions Extractor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Extractor
{
class Program
{
const string Version = "2024-07-04";

static string destination = "./extracted/";
static bool skipIfExists = false;
static bool forceEntryTableAtEnd = false;
Expand Down Expand Up @@ -44,7 +46,7 @@ static void Main(string[] args)
"-p=/def,/map\n" +
"-p=/def/world/road.sii",
x => { startPaths = x.Split(","); } },
{ "paths=",
{ "P=|paths=",
"Same as --partial, but expects a text file containing paths to extract, " +
"separated by newlines.",
x => { startPaths = LoadStartPathsFromFile(x); } },
Expand Down Expand Up @@ -80,7 +82,7 @@ static void Main(string[] args)

if (printHelp || args.Length == 0)
{
Console.WriteLine("Extractor 2024-04-18\n");
Console.WriteLine($"Extractor {Version}\n");
Console.WriteLine("Usage:\n extractor path... [options]\n");
Console.WriteLine("Options:");
p.WriteOptionDescriptions(Console.Out);
Expand Down Expand Up @@ -241,7 +243,7 @@ private static void ExtractRaw(string scsPath)

try
{
reader.ExtractToFile(entry, outputPath);
reader.ExtractToFile(entry, key.ToString("x"), outputPath);
}
catch (ZlibException zlex)
{
Expand Down Expand Up @@ -308,8 +310,18 @@ private static void ExtractFiles(IHashFsReader reader, List<string> files)
}
catch (ZlibException zlex)
{
Console.WriteLine($"Unable to extract entry {file}:");
Console.WriteLine(zlex.Message);
Console.Error.WriteLine($"Unable to extract entry {file}:");
Console.Error.WriteLine(zlex.Message);
}
catch (InvalidDataException idex)
{
Console.Error.WriteLine($"Unable to extract entry {file}:");
Console.Error.WriteLine(idex.Message);
}
catch (AggregateException agex)
{
Console.Error.WriteLine($"Unable to extract entry {file}:");
Console.Error.WriteLine(agex.ToString());
}
}
}
Expand Down
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
## Extractor
A cross-platform .scs (HashFS) extractor written in C#. Supports raw dumps, partial extraction, and extracting all .scs files at once.
A cross-platform .scs (HashFS) extractor written in C#. Supports raw dumps, partial extraction,
and extracting all .scs files at once.

HashFS v2, introduced with game version 1.50, is supported, with one limitation: the packed .tobj format, which
.tobj/.dds pairs are converted to in v2, can be extracted, but not unpacked.
HashFS v2, introduced with game version 1.50, is supported.

## Build
A self-contained binary for Windows is available on the Releases page. On other platforms, install the .NET 6 SDK and run the following:
A self-contained binary for Windows is available on the Releases page. On other platforms, install the
.NET 6 (or higher) SDK and run the following:
```sh
git clone https://github.com/sk-zk/Extractor.git --recursive
cd Extractor
Expand All @@ -14,7 +15,8 @@ dotnet publish -c Release

## Usage
```
extractor path... [options]
Usage:
extractor path... [options]
Options:
-a, --all Extracts all .scs archives in the specified
Expand All @@ -26,7 +28,7 @@ Options:
-p=/map
-p=/def,/map
-p=/def/world/road.sii
--paths=VALUE Same as --partial, but expects a text file
-P, --paths=VALUE Same as --partial, but expects a text file
containing paths to extract, separated by
newlines.
-r, --raw Directly dumps the contained files with their
Expand All @@ -39,13 +41,9 @@ Options:
this one instead.
-s, --skip-existing Don't overwrite existing files.
--table-at-end [HashFS v1 only] Ignores what the archive header
says and readsthe entry table from the end of
says and reads the entry table from the end of
the file.
--tree Prints the directory tree and exits. Can be
combined with --partial, --paths, and --all.
-?, -h, --help Prints this message and exits.
```

## Dependencies
* [Mono.Options](https://www.nuget.org/packages/Mono.Options/)
* [TruckLib.HashFs](https://github.com/sk-zk/TruckLib/)
2 changes: 1 addition & 1 deletion TruckLib
Submodule TruckLib updated 50 files
+2 −9 README.md
+1 −0 Samples/00-SimpleExample/01-SimpleExample.csproj
+1 −1 Samples/00-SimpleExample/Program.cs
+1 −1 Samples/01-Prefabs/02-Prefabs.csproj
+2 −2 Samples/01-Prefabs/Program.cs
+1 −1 Samples/02-RealRoad/03-RealRoad.csproj
+64 −0 TruckLib.HashFs/Dds/DdsFile.cs
+294 −0 TruckLib.HashFs/Dds/DdsHeader.cs
+62 −0 TruckLib.HashFs/Dds/DdsHeaderDxt10.cs
+148 −0 TruckLib.HashFs/Dds/DdsPixelFormat.cs
+408 −0 TruckLib.HashFs/Dds/DdsUtils.cs
+148 −0 TruckLib.HashFs/Dds/Enums.cs
+15 −0 TruckLib.HashFs/Dds/SubresourceData.cs
+6 −18 TruckLib.HashFs/EntryV1.cs
+3 −10 TruckLib.HashFs/EntryV2.cs
+6 −10 TruckLib.HashFs/HashFsReader.cs
+18 −12 TruckLib.HashFs/HashFsReaderBase.cs
+283 −46 TruckLib.HashFs/HashFsV2Reader.cs
+26 −0 TruckLib.HashFs/IEntry.cs
+31 −11 TruckLib.HashFs/IHashFsReader.cs
+59 −0 TruckLib.HashFs/PackedTobjDdsMetadata.cs
+11 −0 TruckLib.HashFs/Platform.cs
+8 −3 TruckLib.HashFs/TruckLib.HashFs.csproj
+3 −3 TruckLib.sln
+67 −0 TruckLib/Extensions/CloneExtensions.cs
+0 −38 TruckLib/Extensions/IOExtensions.cs
+49 −0 TruckLib/Extensions/IOPascalStringExtensions.cs
+66 −0 TruckLib/Extensions/MathExtensions.cs
+1 −117 TruckLib/Extensions/MiscExtensions.cs
+18 −15 TruckLib/Models/Tobj.cs
+1 −1 TruckLib/Sii/SiiFile.cs
+1 −1 TruckLib/TruckLib.csproj
+10 −11 docfx/docs/Samples/01-simple.md
+5 −5 docfx/docs/Samples/02-prefabs.md
+7 −6 docfx/docs/Samples/03-realroad.md
+4 −4 docfx/docs/Samples/toc.yml
+21 −14 docfx/docs/TruckLib.HashFs/hashfs.md
+8 −6 docfx/docs/introduction.md
+ docfx/images/00-final.png
+ docfx/images/00-wip1.png
+ docfx/images/00-wip2.png
+ docfx/images/01-final.png
+ docfx/images/01-wip1.png
+ docfx/images/01-wip2.png
+ docfx/images/01-wip3.png
+ docfx/images/02-final.png
+ docfx/images/02-wip1.png
+ docfx/images/02-wip2.png
+ docfx/images/03-data.png
+ docfx/images/03-final.png

0 comments on commit fbcddd4

Please sign in to comment.