Skip to content

Commit

Permalink
socpak things
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotr7 committed Jan 12, 2025
1 parent 8a031ab commit 6486cb1
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/StarBreaker.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
"commandName": "Project",
"commandLineArgs": "p4k-extract -p \"C:\\Program Files\\Roberts Space Industries\\StarCitizen\\PTU\\Data.p4k\" -o \"D:\\StarCitizen\\P4k\""
},
"p4k-extract-socpak": {
"commandName": "Project",
"commandLineArgs": "p4k-extract -p \"C:\\Program Files\\Roberts Space Industries\\StarCitizen\\PTU\\Data.p4k\" -o \"D:\\StarCitizen\\P4kSocPak\" -f \"*.socpak\" "
},
"p4k-dump": {
"commandName": "Project",
"commandLineArgs": "p4k-dump -p \"C:\\Program Files\\Roberts Space Industries\\StarCitizen\\PTU\\Data.p4k\" -o \"C:\\Development\\StarCitizen\\DataCoreExport\""
Expand Down
24 changes: 24 additions & 0 deletions src/StarBreaker.CryChunkFile/ChunkFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ public void WriteXmlTo(TextWriter writer)
}
}

public byte[][] GetPartsCrChf()
{
//skip the signature
var reader = new SpanReader(_data, sizeof(uint));

var version = reader.ReadUInt32();
if (version != 0x746)
throw new Exception("Invalid version");

var chunkCount = reader.ReadUInt32();
var chunkTableOffset = reader.ReadUInt32();
Debug.Assert(chunkTableOffset == reader.Position);
var headers = reader.ReadSpan<ChunkHeaderCrCh>((int)chunkCount);

var chunks = new byte[headers.Length][];
for (var i = 0; i < headers.Length; i++)
{
ref readonly var header = ref headers[i];
chunks[i] = _data.AsSpan((int)header.Offset, (int)header.Size).ToArray();
}

return chunks;
}

private static void WriteChCfTo(TextWriter writer, ref SpanReader reader)
{
var version = reader.ReadUInt32();
Expand Down
2 changes: 2 additions & 0 deletions src/StarBreaker.Sandbox/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

//Project just so I can run throwaway code without adding a project for each thing.

SocPakSandbox.Run();
// P4kSandbox.Run();
return;
//Crc32CSandbox.Run();

//DdsFile.MergeToFile(@"D:\StarCitizen\P4k\Data\Objects\Characters\Human\heads\shared\tattoos\sc\stormwal\tattoo_stormwal_01_decal.dds", @"D:\StarCitizen\DDS\merged_stormwal.dds");
Expand Down
75 changes: 75 additions & 0 deletions src/StarBreaker.Sandbox/SocPakSandbox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System.IO.Compression;
using StarBreaker.CryChunkFile;
using StarBreaker.CryXmlB;

namespace StarBreaker.Sandbox;

public static class SocPakSandbox
{
public static void Run()
{
var socParts = Directory.EnumerateFiles(@"D:\StarCitizen\P4kSocPak", "*.socpart", SearchOption.AllDirectories);
foreach (var socPart in socParts)
{
var fs = File.OpenRead(socPart);
if (CryXml.TryOpen(fs, out var cryXml))
{
var path = socPart.Replace(".socpart", ".xml");
cryXml.Save(path);
fs.Dispose();
File.Delete(socPart);
}
}

return;

var socs = Directory.EnumerateFiles(@"D:\StarCitizen\P4kSocPak", "*.soc", SearchOption.AllDirectories);
foreach (var soc in socs)
{
if (ChunkFile.TryOpen(File.ReadAllBytes(soc), out var chunkFile))
{
var parts = chunkFile!.GetPartsCrChf();

//create directory
var path = soc.Replace(".soc", ".socParts");
Directory.CreateDirectory(path);
var i = 0;
foreach (var part in parts)
{
var partPath = Path.Combine(path, $"{i++}.socpart");
File.WriteAllBytes(partPath, part);
}

File.Delete(soc);
}
}

return;


var entxml = Directory.EnumerateFiles(@"D:\StarCitizen\P4kSocPak", "*.entxml", SearchOption.AllDirectories);
foreach (var entXml in entxml)
{
File.Delete(entXml);
continue;
using var fs = File.OpenRead(entXml);
var path = entXml.Replace(".entxml", ".xml");
if (CryXml.TryOpen(fs, out var cryXml))
cryXml.Save(path);
}

return;

var socPaks = Directory.EnumerateFiles(@"D:\StarCitizen\P4kSocPak", "*.socpak", SearchOption.AllDirectories);
foreach (var socPak in socPaks)
{
var zip = new ZipArchive(File.OpenRead(socPak));
var path = socPak.Replace(".socpak", "");
Directory.CreateDirectory(path);
zip.ExtractToDirectory(path);
zip.Dispose();

File.Delete(socPak);
}
}
}

0 comments on commit 6486cb1

Please sign in to comment.