-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8dd7044
commit 61ad2aa
Showing
4 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>net9.0-windows;net9.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PublishAot>true</PublishAot> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Src\GBX.NET.PAK\GBX.NET.PAK.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using GBX.NET; | ||
using GBX.NET.Components; | ||
using GBX.NET.Exceptions; | ||
using GBX.NET.PAK; | ||
|
||
var pakFileNameOrDirectory = args[0]; | ||
var isDirectory = Directory.Exists(pakFileNameOrDirectory); | ||
|
||
var directoryPath = isDirectory ? pakFileNameOrDirectory : Path.GetDirectoryName(pakFileNameOrDirectory)!; | ||
|
||
var extractFolderPath = args.Length > 1 ? args[1] : ""; | ||
|
||
var game = PakListGame.TM; | ||
|
||
if (args.Length > 2 && args[2].Equals("vsk5", StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
game = PakListGame.Vsk5; | ||
} | ||
|
||
Console.WriteLine("Bruteforcing possible file names from hashes..."); | ||
|
||
var hashes = await Pak.BruteforceFileHashesAsync(directoryPath, game, onlyUsedHashes: false); | ||
|
||
var packlistFileName = Path.Combine(directoryPath, "packlist.dat"); | ||
var packlist = await PakList.ParseAsync(packlistFileName, game); | ||
|
||
var pakFileNames = isDirectory ? Directory.GetFiles(pakFileNameOrDirectory, "*.pak", SearchOption.AllDirectories) : [pakFileNameOrDirectory]; | ||
|
||
foreach (var pakFileName in pakFileNames) | ||
{ | ||
var key = packlist[Path.GetFileNameWithoutExtension(pakFileName).ToLowerInvariant()].Key; | ||
|
||
await using var fs = File.OpenRead(pakFileName); | ||
await using var pak = await Pak.ParseAsync(fs, key); | ||
|
||
foreach (var file in pak.Files.Values) | ||
{ | ||
var fileName = hashes.GetValueOrDefault(file.Name)?.Replace('\\', Path.DirectorySeparatorChar) ?? file.Name; | ||
var fullPath = string.IsNullOrEmpty(extractFolderPath) | ||
? Path.Combine(file.FolderPath, fileName) | ||
: Path.Combine(extractFolderPath, file.FolderPath, fileName); | ||
|
||
Console.WriteLine(fullPath); | ||
|
||
Directory.CreateDirectory(Path.GetDirectoryName(fullPath)!); | ||
|
||
if (File.Exists(fullPath)) | ||
{ | ||
File.Delete(fullPath); | ||
} | ||
|
||
using var stream = File.OpenWrite(fullPath); | ||
|
||
try | ||
{ | ||
var gbx = await pak.OpenGbxFileAsync(file); | ||
|
||
if (gbx.Header is GbxHeaderUnknown) | ||
{ | ||
CopyFileToStream(pak, file, stream); | ||
} | ||
else | ||
{ | ||
gbx.Save(stream); | ||
} | ||
} | ||
catch (NotAGbxException) | ||
{ | ||
CopyFileToStream(pak, file, stream); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex); | ||
} | ||
} | ||
} | ||
|
||
static void CopyFileToStream(Pak pak, PakFile file, Stream stream) | ||
{ | ||
var pakItemFileStream = pak.OpenFile(file, out _); | ||
var data = new byte[file.UncompressedSize]; | ||
var count = pakItemFileStream.Read(data); | ||
stream.Write(data, 0, count); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters