Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotr7 committed Dec 28, 2024
1 parent ab930ca commit 5ffda6d
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 148 deletions.
6 changes: 1 addition & 5 deletions src/StarBreaker.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
},
"p4k-extract": {
"commandName": "Project",
"commandLineArgs": "p4k-extract --p4k \"C:\\Program Files\\Roberts Space Industries\\StarCitizen\\4.0_PREVIEW\\Data.p4k\" --output \"D:\\StarCitizen\\p4keptu\""
},
"p4k-extract-datacore": {
"commandName": "Project",
"commandLineArgs": "p4k-extract --p4k \"C:\\Program Files\\Roberts Space Industries\\StarCitizen\\4.0_PREVIEW\\Data.p4k\" --output \"D:\\StarCitizen\\p4keptu\" --filter \"*.dcb\""
"commandLineArgs": "p4k-extract --p4k \"C:\\Program Files\\Roberts Space Industries\\StarCitizen\\4.0_PREVIEW\\Data.p4k\" --output \"D:\\StarCitizen\\P4k\""
},
"chf-download": {
"commandName": "Project",
Expand Down
96 changes: 6 additions & 90 deletions src/StarBreaker.CryXmlB/CryXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,100 +87,16 @@ private static string GetString(Span<byte> data, int offset)
var length = relevantData.IndexOf((byte)'\0');

if (length == 0)
return "";
return "empty";

return Encoding.ASCII.GetString(relevantData[..length]);
}

public void WriteXmlFast(TextWriter writer)
public override string ToString()
{
if (_nodes[0].ParentIndex != -1)
throw new Exception("Root node has parent");

writer.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
WriteXmlElementFast(writer, 0, 0);
}

private void WriteXmlElementFast(TextWriter writer, int depth, int nodeIndex)
{
var node = _nodes[nodeIndex];

for (var i = 0; i < depth; i++)
{
writer.Write(' ');
writer.Write(' ');
}

writer.Write('<');
if (writer.WriteXmlString(_stringData, (int)node.TagStringOffset) == 0)
writer.Write("__unknown__");

var attributes = _attributes.AsSpan(node.FirstAttributeIndex, node.AttributeCount);
foreach (var attribute in attributes)
{
writer.Write(' ');
writer.WriteXmlString(_stringData, (int)attribute.KeyStringOffset);
writer.Write('=');
writer.Write('\"');
writer.WriteXmlString(_stringData, (int)attribute.ValueStringOffset);
writer.Write('\"');
}

var stringElementLength = _stringData.AsSpan((int)node.ItemType).IndexOf((byte)'\0');
var hasStringElement = stringElementLength != 0;
var hasChildren = node.ChildCount != 0;

if (!hasChildren && !hasStringElement)
{
writer.Write(' ');
writer.Write('/');
writer.WriteLine('>');
return;
}

writer.Write('>');

if (hasStringElement && !hasChildren)
{
writer.WriteXmlString(_stringData, (int)node.ItemType);
writer.Write('<');
writer.Write('/');
writer.WriteXmlString(_stringData, (int)node.TagStringOffset);
writer.WriteLine('>');
return;
}

if (hasStringElement)
{
writer.WriteLine();
writer.WriteXmlString(_stringData, (int)node.ItemType);
writer.WriteLine();
}

if (!hasStringElement && hasChildren)
{
writer.WriteLine();
}

var childIndices = _childIndices.AsSpan(node.FirstChildIndex, node.ChildCount);
foreach (var childIndex in childIndices)
{
WriteXmlElementFast(writer, depth + 1, childIndex);
}

for (var i = 0; i < depth; i++)
{
writer.Write(' ');
writer.Write(' ');
}

writer.Write('<');
writer.Write('/');
writer.WriteXmlString(_stringData, (int)node.TagStringOffset);

if (nodeIndex == 0)
writer.Write('>');
else
writer.WriteLine('>');
var sb = new StringBuilder();
using var writer = XmlWriter.Create(sb, new XmlWriterSettings { Indent = true });
WriteXml(writer);
return sb.ToString();
}
}
42 changes: 0 additions & 42 deletions src/StarBreaker.CryXmlB/TextWriterExtensions.cs

This file was deleted.

5 changes: 0 additions & 5 deletions src/StarBreaker.DataCore/DataCoreBinary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@ private XElement GetFromInstance(int structIndex, int instanceIndex, DataCoreExt
var reader = Database.GetReader(Database.Offsets[structIndex][instanceIndex]);
var element = GetFromStruct(structIndex, ref reader, context);

//TODO: make this configurable?
// Popping it here makes it repeat the same data more often.
// If we leave it in the stack (could be a HashSet), it will only ever print the same data once per file.
//context.Tracker.Pop();

// add some metadata to the element, mostly so we can figure out what a CircularReference is pointing to
element.Add(new XAttribute("__structIndex", structIndex.ToString(CultureInfo.InvariantCulture)));
element.Add(new XAttribute("__instanceIndex", instanceIndex.ToString(CultureInfo.InvariantCulture)));
Expand Down
5 changes: 3 additions & 2 deletions src/StarBreaker.P4k/P4kFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ public void Extract(string outputDir, string? filter = null, IProgress<double>?
return;

Directory.CreateDirectory(Path.GetDirectoryName(entryPath) ?? throw new InvalidOperationException());

using (var writeStream = new FileStream(entryPath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: (int)entry.UncompressedSize, useAsync: true))
var sss = (int)entry.UncompressedSize;
using (var writeStream = new FileStream(entryPath, FileMode.Create, FileAccess.Write, FileShare.None,
bufferSize: entry.UncompressedSize > int.MaxValue ? 81920 : (int)entry.UncompressedSize, useAsync: true))
{
using (var entryStream = Open(entry))
{
Expand Down
14 changes: 11 additions & 3 deletions src/StarBreaker.Sandbox/ChfProcessing.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
using System.Text;
using StarBreaker.Chf;
using StarBreaker.Common;

namespace StarBreaker.Chf;
namespace StarBreaker.Sandbox;

public class DebugCommand
public static class ChfProcessing
{
public async ValueTask ExecuteAsync()
public static async Task Run()
{
var dnas = @"C:\Users\Diogo\Desktop\dnas.txt";
var load = (await File.ReadAllLinesAsync(dnas)).Select(FixWeirdDnaString).ToArray();
int i = 0;
await CreateCharactersFromDnaStrings(load.Select(x => ($"female_{i++}.chf", x)));

return;

await FixDnaStrings();

var hugeData = Path.Combine(DefaultPaths.ResearchFolder, "dna", "huge_fixed.csv");
Expand Down
4 changes: 3 additions & 1 deletion src/StarBreaker.Sandbox/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

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


await ChfProcessing.Run();
//ExtractChunkFiles.Run();
//ExtractSocPak.Run();
//await GrpcClient.RunAsync();
//TimeP4kExtract.Run();
TagDatabase.Run();
//TagDatabase.Run();
//StringCrc32c.Run();
//DdsUnsplit.Run();

0 comments on commit 5ffda6d

Please sign in to comment.