Skip to content

Commit

Permalink
Add Vector2D and FINNetworkTrace structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Goz3rr committed Oct 2, 2020
1 parent 69629ce commit 7e06324
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
return "Rotator";
case Vector v:
return "Vector";
case Vector2D v2:
return "Vector2D";
case GuidStruct g:
return "Guid";
case FluidBox fb:
return "FluidBox";
case FINNetworkTrace nt:
return "FINNetworkTrace";
case SerializedPropertyViewModel spvm: // TODO: This seems like a bad idea, but it works for now
return new SerializablePropertyToTypeStringConverter().Convert(spvm, targetType, parameter, culture);
default:
Expand Down
15 changes: 15 additions & 0 deletions SatisfactorySaveParser/BinaryIOExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ public static int GetSerializedLength(this string str)
return str.Length + 5;
}

public static Vector2 ReadVector2(this BinaryReader reader)
{
return new Vector2()
{
X = reader.ReadSingle(),
Y = reader.ReadSingle(),
};
}

public static void Write(this BinaryWriter writer, Vector2 vec)
{
writer.Write(vec.X);
writer.Write(vec.Y);
}

public static Vector3 ReadVector3(this BinaryReader reader)
{
return new Vector3()
Expand Down
4 changes: 4 additions & 0 deletions SatisfactorySaveParser/PropertyTypes/StructProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ private static IStructData ParseStructData(BinaryReader reader, string type)
return new Rotator(reader);
case "Vector":
return new Vector(reader);
case "Vector2D":
return new Vector2D(reader);
case "Box":
return new Box(reader);
case "Quat":
Expand All @@ -133,6 +135,8 @@ private static IStructData ParseStructData(BinaryReader reader, string type)
return new GuidStruct(reader);
case "FluidBox":
return new FluidBox(reader);
case "FINNetworkTrace":
return new FINNetworkTrace(reader);
/*
case "InventoryStack":
case "InventoryItem":
Expand Down
57 changes: 57 additions & 0 deletions SatisfactorySaveParser/PropertyTypes/Structs/FINNetworkTrace.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.IO;

using SatisfactorySaveParser.Structures;

namespace SatisfactorySaveParser.PropertyTypes.Structs
{
public class FINNetworkTrace : IStructData
{
public bool IsValid { get; set; }
public ObjectReference Reference { get; set; }
public bool HasPrev { get; set; }
public FINNetworkTrace Prev { get; set; }
public bool HasStep { get; set; }
public string Step { get; set; }

public int SerializedLength => throw new NotImplementedException();
public string Type => "FINNetworkTrace";

public FINNetworkTrace(BinaryReader reader)
{
IsValid = reader.ReadInt32() != 0;

if(IsValid)
{
Reference = new ObjectReference(reader);

HasPrev = reader.ReadInt32() != 0;
if (HasPrev)
Prev = new FINNetworkTrace(reader);

HasStep = reader.ReadInt32() != 0;
if (HasStep)
Step = reader.ReadLengthPrefixedString();
}
}

public void Serialize(BinaryWriter writer)
{
writer.Write(IsValid ? 1 : 0);

if (IsValid)
{
writer.WriteLengthPrefixedString(Reference.LevelName);
writer.WriteLengthPrefixedString(Reference.PathName);

writer.Write(HasPrev ? 1 : 0);
if (HasPrev)
Prev.Serialize(writer);

writer.Write(HasStep ? 1 : 0);
if (HasStep)
writer.WriteLengthPrefixedString(Step);
}
}
}
}
12 changes: 4 additions & 8 deletions SatisfactorySaveParser/PropertyTypes/Structs/Vector.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using SatisfactorySaveParser.Structures;
using System.IO;
using System.IO;

using SatisfactorySaveParser.Structures;

namespace SatisfactorySaveParser.PropertyTypes.Structs
{
Expand All @@ -11,12 +12,7 @@ public class Vector : IStructData

public Vector(BinaryReader reader)
{
Data = new Vector3()
{
X = reader.ReadSingle(),
Y = reader.ReadSingle(),
Z = reader.ReadSingle()
};
Data = reader.ReadVector3();
}

public void Serialize(BinaryWriter writer)
Expand Down
23 changes: 23 additions & 0 deletions SatisfactorySaveParser/PropertyTypes/Structs/Vector2D.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.IO;

using SatisfactorySaveParser.Structures;

namespace SatisfactorySaveParser.PropertyTypes.Structs
{
public class Vector2D : IStructData
{
public int SerializedLength => 8;
public string Type => "Vector2D";
public Vector2 Data { get; set; }

public Vector2D(BinaryReader reader)
{
Data = reader.ReadVector2();
}

public void Serialize(BinaryWriter writer)
{
writer.Write(Data);
}
}
}
3 changes: 3 additions & 0 deletions SatisfactorySaveParser/SatisfactorySaveParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<Compile Include="PropertyTypes\StructProperty.cs" />
<Compile Include="PropertyTypes\Structs\Box.cs" />
<Compile Include="PropertyTypes\Structs\DynamicStructData.cs" />
<Compile Include="PropertyTypes\Structs\FINNetworkTrace.cs" />
<Compile Include="PropertyTypes\Structs\FluidBox.cs" />
<Compile Include="PropertyTypes\Structs\Guid.cs" />
<Compile Include="PropertyTypes\Structs\InventoryItem.cs" />
Expand All @@ -91,6 +92,7 @@
<Compile Include="PropertyTypes\Structs\Quat.cs" />
<Compile Include="PropertyTypes\Structs\RailroadTrackPosition.cs" />
<Compile Include="PropertyTypes\Structs\Rotator.cs" />
<Compile Include="PropertyTypes\Structs\Vector2D.cs" />
<Compile Include="PropertyTypes\Structs\Vector.cs" />
<Compile Include="PropertyTypes\TextProperty.cs" />
<Compile Include="SatisfactoryConstants.cs" />
Expand All @@ -107,6 +109,7 @@
<Compile Include="SerializedFields.cs" />
<Compile Include="Structures\IObjectReference.cs" />
<Compile Include="Structures\ObjectReference.cs" />
<Compile Include="Structures\Vector2.cs" />
<Compile Include="Structures\Vector3.cs" />
<Compile Include="Structures\Vector4.cs" />
</ItemGroup>
Expand Down
13 changes: 13 additions & 0 deletions SatisfactorySaveParser/Structures/Vector2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace SatisfactorySaveParser.Structures
{
public class Vector2
{
public float X { get; set; }
public float Y { get; set; }

public override string ToString()
{
return $"X: {X} Y: {Y}";
}
}
}

0 comments on commit 7e06324

Please sign in to comment.