-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
9 changed files
with
253 additions
and
22 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,81 @@ | ||
using System.IO.Compression; | ||
using CliFx; | ||
using CliFx.Attributes; | ||
using CliFx.Infrastructure; | ||
using StarBreaker.DataCore; | ||
|
||
namespace StarBreaker.Cli; | ||
|
||
[Command("diff", Description = "Dumps game information into plain text files for comparison")] | ||
public class DiffCommand : ICommand | ||
{ | ||
[CommandOption("game", 'g', Description = "Path to the game folder")] | ||
public required string GameFolder { get; init; } | ||
|
||
[CommandOption("output", 'o', Description = "Path to the output directory")] | ||
public required string OutputDirectory { get; init; } | ||
|
||
public async ValueTask ExecuteAsync(IConsole console) | ||
{ | ||
// Hide output from subcommands | ||
var fakeConsole = new FakeConsole(); | ||
|
||
var p4kFile = Path.Combine(GameFolder, "Data.p4k"); | ||
var exeFile = Path.Combine(GameFolder, "Bin64", "StarCitizen.exe"); | ||
|
||
var dumpP4k = new DumpP4kCommand | ||
{ | ||
P4kFile = p4kFile, | ||
OutputDirectory = Path.Combine(OutputDirectory, "P4k") | ||
}; | ||
await dumpP4k.ExecuteAsync(fakeConsole); | ||
|
||
var dcbExtract = new DataCoreExtractCommand | ||
{ | ||
P4kFile = p4kFile, | ||
OutputDirectory = Path.Combine(OutputDirectory, "DataCore") | ||
}; | ||
await dcbExtract.ExecuteAsync(fakeConsole); | ||
|
||
var extractProtobufs = new ExtractProtobufsCommand | ||
{ | ||
Input = exeFile, | ||
Output = Path.Combine(OutputDirectory, "Protobuf") | ||
}; | ||
await extractProtobufs.ExecuteAsync(fakeConsole); | ||
|
||
var extractDescriptor = new ExtractDescriptorSetCommand | ||
{ | ||
Input = exeFile, | ||
Output = Path.Combine(OutputDirectory, "Protobuf", "descriptor_set.bin") | ||
}; | ||
await extractDescriptor.ExecuteAsync(fakeConsole); | ||
|
||
await ExtractDataCoreIntoZip(p4kFile, Path.Combine(OutputDirectory, "DataCore", "DataCore.zip")); | ||
|
||
await console.Output.WriteLineAsync("Done."); | ||
} | ||
|
||
private static async Task ExtractDataCoreIntoZip(string p4kFile, string zipPath) | ||
{ | ||
var p4k = P4k.P4kFile.FromFile(p4kFile); | ||
Stream? dcbStream = null; | ||
string? dcbFile = null; | ||
foreach (var file in DataCoreUtils.KnownPaths) | ||
{ | ||
if (!p4k.FileExists(file)) continue; | ||
|
||
dcbFile = file; | ||
dcbStream = p4k.OpenRead(file); | ||
break; | ||
} | ||
|
||
if (dcbStream == null || dcbFile == null) | ||
throw new InvalidOperationException("DataCore not found."); | ||
|
||
using var zip = new ZipArchive(File.Create(zipPath), ZipArchiveMode.Create); | ||
var entry = zip.CreateEntry(Path.GetFileName(dcbFile), CompressionLevel.SmallestSize); | ||
await using var entryStream = entry.Open(); | ||
await dcbStream.CopyToAsync(entryStream); | ||
} | ||
} |
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,27 @@ | ||
using System.Text; | ||
using CliFx; | ||
using CliFx.Attributes; | ||
using CliFx.Infrastructure; | ||
using StarBreaker.Cli.Utils; | ||
using StarBreaker.P4k; | ||
|
||
namespace StarBreaker.Cli; | ||
|
||
[Command("p4k-dump", Description = "Dumps the contents a Game.p4k file")] | ||
public class DumpP4kCommand : ICommand | ||
{ | ||
[CommandOption("p4k", 'p', Description = "Path to the Game.p4k")] | ||
public required string P4kFile { get; init; } | ||
|
||
[CommandOption("output", 'o', Description = "Path to the output directory")] | ||
public required string OutputDirectory { get; init; } | ||
|
||
public ValueTask ExecuteAsync(IConsole console) | ||
{ | ||
var p4k = P4k.P4kFile.FromFile(P4kFile); | ||
var p4kExtractor = new P4kExtractor(p4k); | ||
p4kExtractor.ExtractDummies(OutputDirectory, new ProgressBar(console)); | ||
|
||
return default; | ||
} | ||
} |
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
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,12 @@ | ||
using System.IO.Enumeration; | ||
|
||
namespace StarBreaker.DataCore; | ||
|
||
public static class DataCoreUtils | ||
{ | ||
public static readonly string[] KnownPaths = [@"Data\Game2.dcb", @"Data\Game.dcb"]; | ||
public static bool IsDataCoreFile(string path) | ||
{ | ||
return FileSystemName.MatchesSimpleExpression("Data\\*.dcb", path); | ||
} | ||
} |
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
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