Skip to content

Commit

Permalink
datacore v5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotr7 committed Dec 30, 2024
1 parent a3ed33c commit 631df87
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 9 deletions.
18 changes: 16 additions & 2 deletions src/StarBreaker.Cli/DataCoreCommands/DataCoreExtractCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,22 @@ public ValueTask ExecuteAsync(IConsole console)
{
var p4k = P4k.P4kFile.FromFile(P4kFile);
console.Output.WriteLine("P4k loaded.");
var dcbStream = p4k.OpenRead(@"Data\Game2.dcb");
console.Output.WriteLine("DataCore extracted.");
Stream? dcbStream = null;
if (p4k.FileExists(@"Data\Game2.dcb"))
{
dcbStream = p4k.OpenRead(@"Data\Game2.dcb");
console.Output.WriteLine("Game.dcb found");
}
else if (p4k.FileExists(@"Data\Game.dcb"))
{
dcbStream = p4k.OpenRead(@"Data\Game.dcb");
console.Output.WriteLine("Game.dcb found");
}
else
{
console.Output.WriteLine("DataCore not found.");
return default;
}

var df = new DataForge(dcbStream);

Expand Down
4 changes: 4 additions & 0 deletions src/StarBreaker.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"commandName": "Project",
"commandLineArgs": "dcb-extract --p4k \"C:\\Program Files\\Roberts Space Industries\\StarCitizen\\4.0_PREVIEW\\Data.p4k\" --output D:\\StarCitizen\\DataCoreExport"
},
"dcb-extract-old": {
"commandName": "Project",
"commandLineArgs": "dcb-extract --p4k \"\\\\UNRAID\\backups\\StarCitizen\\Data.p4k\" --output \"D:\\StarCitizen2\\DataCoreExport\""
},
"p4k-extract": {
"commandName": "Project",
"commandLineArgs": "p4k-extract --p4k \"C:\\Program Files\\Roberts Space Industries\\StarCitizen\\4.0_PREVIEW\\Data.p4k\" --output \"D:\\StarCitizen\\P4k\""
Expand Down
6 changes: 6 additions & 0 deletions src/StarBreaker.CryXmlB/CryXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,10 @@ public override string ToString()
WriteTo(writer);
return sb.ToString();
}

public void Save(string entry)
{
using var writer = XmlWriter.Create(entry, new XmlWriterSettings { Indent = true });
WriteTo(writer);
}
}
22 changes: 17 additions & 5 deletions src/StarBreaker.DataCore/DataCoreDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace StarBreaker.DataCore;

public class DataCoreDatabase
{
public uint Version { get; }

private readonly ConcurrentDictionary<int, DataCorePropertyDefinition[]> _propertiesCache = new();
private readonly int DataSectionOffset;
private readonly byte[] DataSection;
Expand Down Expand Up @@ -55,9 +57,9 @@ public DataCoreDatabase(Stream fs)
using var reader = new BinaryReader(fs);

_ = reader.ReadUInt32();
var fileVersion = reader.ReadUInt32();
if (fileVersion != 6)
throw new Exception($"Unsupported file version: {fileVersion}");
Version = reader.ReadUInt32();
if (Version is < 5 or > 6)
throw new Exception($"Unsupported file version: {Version}");
_ = reader.ReadUInt32();
_ = reader.ReadUInt32();

Expand Down Expand Up @@ -119,7 +121,10 @@ public DataCoreDatabase(Stream fs)
EnumOptions = reader.ReadArray<DataCoreStringId2>(enumOptionCount);

CachedStrings = ReadStringTable(reader.ReadBytes((int)textLength).AsSpan());
CachedStrings2 = ReadStringTable(reader.ReadBytes((int)textLength2).AsSpan());
if (Version >= 6)
CachedStrings2 = ReadStringTable(reader.ReadBytes((int)textLength2).AsSpan());
else
CachedStrings2 = FrozenDictionary<int, string>.Empty;

var bytesRead = (int)fs.Position;

Expand All @@ -146,7 +151,14 @@ public DataCoreDatabase(Stream fs)

public SpanReader GetReader(int offset) => new(DataSection, offset - DataSectionOffset);
public string GetString(DataCoreStringId id) => CachedStrings[id.Id];
public string GetString2(DataCoreStringId2 id) => CachedStrings2[id.Id];
public string GetString2(DataCoreStringId2 id)
{
if (Version < 6)
return CachedStrings[id.Id];

return CachedStrings2[id.Id];
}

public DataCoreRecord GetRecord(CigGuid guid) => RecordMap[guid];

private static FrozenDictionary<int, string> ReadStringTable(ReadOnlySpan<byte> span)
Expand Down
17 changes: 17 additions & 0 deletions src/StarBreaker.Sandbox/CryXmlConvert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace StarBreaker.Sandbox;

public static class CryXmlConvert
{
public static void Run()
{
var entries = Directory.GetFiles(@"D:\StarCitizen\P4k\Data\Scripts", "*.xml", SearchOption.AllDirectories);
Parallel.ForEach(entries, entry =>
{
if (entry.EndsWith("proper.xml"))
return;

if (CryXmlB.CryXml.TryOpen(File.OpenRead(entry), out var cryXml))
cryXml.Save(Path.ChangeExtension(entry, "proper.xml"));
});
}
}
5 changes: 3 additions & 2 deletions src/StarBreaker.Sandbox/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
//TimeP4kExtract.Run();
//TagDatabase.Run();
//StringCrc32c.Run();
DdsUnsplit.Run();
//ZipFile.Run();
//DdsUnsplit.Run();
//ZipFile.Run();
CryXmlConvert.Run();

0 comments on commit 631df87

Please sign in to comment.