Skip to content

Commit

Permalink
make subrecord references not be written out
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotr7 committed Jan 31, 2025
1 parent 992446e commit 907672a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 11 deletions.
7 changes: 5 additions & 2 deletions scripts/diff.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#Run StarBreaker.Cli diff with the correct parameters
$starBreakerCliCsproj = "C:\Development\StarCitizen\StarBreaker\src\StarBreaker.Cli\StarBreaker.Cli.csproj"
$starCitizenBasePath = "C:\Program Files\Roberts Space Industries\StarCitizen"

#$channel = "LIVE"
#$channel = "PTU"
$channel = "4.0_PREVIEW"
#$channel = "4.0_PREVIEW"
$channel = "HOTFIX"

$starCitizenPath = "$starCitizenBasePath\$channel"
$gitRepoPath = "C:\Development\StarCitizen\StarCitizenDiff2"

Expand All @@ -12,5 +15,5 @@ dotnet run --project $starBreakerCliCsproj -- diff -g $starCitizenPath -o $gitRe
#Set-Location $gitRepoPath
#git add .
#git commit --author="StarBreaker <>" -m "StarBreaker diff"
#
##
#Write-Host "Diff completed"
21 changes: 20 additions & 1 deletion src/StarBreaker.DataCore/DataCoreBinaryJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,32 @@ private void WriteFromReference(DataCoreReference reference, Context context, st
return;
}

if (record.GetFileName(Database) == context.Path)
{
//if we're referencing a record in the same file, we have to write it out
if (propName == null)
context.Writer.WriteStartObject();
else
context.Writer.WriteStartObject(propName);

context.Writer.WriteString("_RecordId_", record.Id.ToString());
context.Writer.WriteString("_RecordName_", record.GetName(Database));
WriteInstance(record.StructIndex, record.InstanceIndex, context);
context.Writer.WriteEndObject();

return;
}

//if we get here, we're referencing a part of another file. mention the file and some details
if (propName == null)
context.Writer.WriteStartObject();
else
context.Writer.WriteStartObject(propName);

context.Writer.WriteString("_RecordPath_", Path.ChangeExtension(DataCoreUtils.ComputeRelativePath(record.GetFileName(Database), context.Path), "json"));
context.Writer.WriteString("_RecordName_", record.GetName(Database));
context.Writer.WriteString("_RecordId_", record.Id.ToString());
WriteInstance(record.StructIndex, record.InstanceIndex, context);

context.Writer.WriteEndObject();
}

Expand Down
23 changes: 18 additions & 5 deletions src/StarBreaker.DataCore/DataCoreBinaryJsonObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,24 @@ private JsonArray GetArray(DataCorePropertyDefinition prop, ref SpanReader reade
if (Database.MainRecords.Contains(reference.RecordId))
return JsonValue.Create(Path.ChangeExtension(DataCoreUtils.ComputeRelativePath(record.GetFileName(Database), context.RecordFilePath), "json"));

var recordNode = GetInstance(record.StructIndex, record.InstanceIndex, context);

recordNode.Insert(0, "_RecordId_", JsonValue.Create(reference.RecordId.ToString()));

return recordNode;
//if we're referencing a record in the same file, write it out
if (record.GetFileName(Database) == context.RecordFilePath)
{
var recordNode = GetInstance(record.StructIndex, record.InstanceIndex, context);

recordNode.Insert(0, "_RecordName_", JsonValue.Create(record.GetName(Database)));
recordNode.Insert(0, "_RecordId_", JsonValue.Create(reference.RecordId.ToString()));

return recordNode;
}

//if we're referencing a record that's part of another file, mention it
return new JsonObject
{
{ "_RecordPath_", Path.ChangeExtension(DataCoreUtils.ComputeRelativePath(record.GetFileName(Database), context.RecordFilePath), "json") },
{ "_RecordName_", record.GetName(Database) },
{ "_RecordId_", reference.RecordId.ToString() }
};
}

private JsonObject? GetFromStrongPointer(DataCorePointer strongPointer, Context context)
Expand Down
12 changes: 10 additions & 2 deletions src/StarBreaker.DataCore/DataCoreBinaryWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class DataCoreBinaryWalker
{
public static Dictionary<(int, int), int> WalkRecord(DataCoreRecord record, DataCoreDatabase database)
{
var context = new Context { Database = database, WeakPointers = [] };
var context = new Context { Database = database, WeakPointers = [], Self = record.FileNameOffset };

WalkInstance(record.StructIndex, record.InstanceIndex, context);

Expand Down Expand Up @@ -70,11 +70,18 @@ private static void WalkReference(DataCoreReference reference, Context context)
if (reference.RecordId == CigGuid.Empty || reference.InstanceIndex == -1)
return;

// a full file reference won't be walked
if (context.Database.MainRecords.Contains(reference.RecordId))
return;

var record = context.Database.GetRecord(reference.RecordId);

if (context.Database.MainRecords.Contains(reference.RecordId))
//if the subrecord we're referencing is in a different file, it won't be walked
if (record.FileNameOffset != context.Self)
return;

// we only care about walking the subrecord if it's in the same file.
// Otherwise, we'll just reference it here (and thus no weak pointer will be found)
WalkInstance(record.StructIndex, record.InstanceIndex, context);
}

Expand All @@ -98,6 +105,7 @@ private readonly struct Context
{
public required DataCoreDatabase Database { get; init; }
public required Dictionary<(int, int), int> WeakPointers { get; init; }
public required DataCoreStringId Self { get; init; }

public void TryAddWeakPointer(int structIndex, int instanceIndex)
{
Expand Down
14 changes: 13 additions & 1 deletion src/StarBreaker.DataCore/DataCoreBinaryXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,20 @@ private void WriteFromReference(DataCoreReference reference, Context context)
return;
}

if (record.GetFileName(Database) == context.Path)
{
//if we're referencing a record in the same file, write it out.
//This should ensure that when exporting the entire datacore, each record is only written once.
context.Writer.WriteAttributeString("RecordId", reference.RecordId.ToString());
context.Writer.WriteAttributeString("RecordName", record.GetName(Database));
WriteInstance(record.StructIndex, record.InstanceIndex, context);
return;
}

//if we're referencing a record that's part of another file, mention it
context.Writer.WriteAttributeString("RecordReference", DataCoreUtils.ComputeRelativePath(record.GetFileName(Database), context.Path));
context.Writer.WriteAttributeString("RecordName", record.GetName(Database));
context.Writer.WriteAttributeString("RecordId", reference.RecordId.ToString());
WriteInstance(record.StructIndex, record.InstanceIndex, context);
}

private readonly struct Context
Expand Down

0 comments on commit 907672a

Please sign in to comment.