Skip to content

Commit

Permalink
Merge pull request #10 from BigBang1112/netstandard2.0
Browse files Browse the repository at this point in the history
GBX.NET 0.2.0
  • Loading branch information
BigBang1112 authored Sep 19, 2020
2 parents ddf9959 + ff10d6d commit b0123ae
Show file tree
Hide file tree
Showing 105 changed files with 4,351 additions and 4,345 deletions.
19 changes: 18 additions & 1 deletion GBX.NET.Json/GBX.NET.Json.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.1.1</Version>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Description>A wrapper for better JSON serialization of GBX, useful for comparing data.</Description>
<PackageLicenseFile>License.txt</PackageLicenseFile>
<PackageProjectUrl>https://github.com/BigBang1112/gbx-net</PackageProjectUrl>
<RepositoryUrl>https://github.com/BigBang1112/gbx-net</RepositoryUrl>
<PackageTags>gbx, trackmania, maniaplanet, gamebox, net, chunk, x86</PackageTags>
<Authors>BigBang1112</Authors>
<PackageReleaseNotes>Compatiblity change to .NET Standard 2.0</PackageReleaseNotes>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -20,4 +30,11 @@
<ProjectReference Include="..\GBX.NET\GBX.NET.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="License.txt">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
53 changes: 17 additions & 36 deletions GBX.NET/Byte3.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace GBX.NET
namespace GBX.NET
{
public struct Byte3
{
public byte X { get; set; }
public byte Y { get; set; }
public byte Z { get; set; }
public byte X { get; }
public byte Y { get; }
public byte Z { get; }

public Byte3(byte x, byte y, byte z)
{
Expand All @@ -17,39 +13,24 @@ public Byte3(byte x, byte y, byte z)
Z = z;
}

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

public static implicit operator Byte3((byte, byte, byte) v)
{
return new Byte3(v.Item1, v.Item2, v.Item3);
}

public static implicit operator (byte, byte, byte)(Byte3 v)
{
return (v.X, v.Y, v.Z);
}

public override bool Equals(object obj)
{
if (!(obj is Byte3)) return false;
return X == ((Byte3)obj).X && Y == ((Byte3)obj).Y && Z == ((Byte3)obj).Z;
}
public override string ToString() => $"({X}, {Y}, {Z})";
public override int GetHashCode() => X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode();
public override bool Equals(object obj) => obj is Byte3 a && a == this;

public override int GetHashCode()
{
return X ^ Y ^ Z;
}
public static bool operator ==(Byte3 a, Byte3 b) => a.X == b.X && b.Y == b.Y && b.Z == b.Z;
public static bool operator !=(Byte3 a, Byte3 b) => !(a.X == b.X && b.Y == b.Y && b.Z == b.Z);

public static Byte3 operator +(Byte3 a, Byte3 b) => new Byte3((byte)(a.X + b.X), (byte)(a.Y + b.Y), (byte)(a.Z + b.Z));
public static Byte3 operator +(Byte3 a, byte b) => new Byte3((byte)(a.X + b), (byte)(a.Y + b), (byte)(a.Z + b));

public static Byte3 operator -(Byte3 a, Byte3 b) => new Byte3((byte)(a.X - b.X), (byte)(a.Y - b.Y), (byte)(a.Z - b.Z));
public static bool operator ==(Byte3 a, Byte3 b) => a.Equals(b);
public static bool operator !=(Byte3 a, Byte3 b) => !a.Equals(b);
public static Byte3 operator -(Byte3 a, byte b) => new Byte3((byte)(a.X - b), (byte)(a.Y - b), (byte)(a.Z - b));

public static Byte3 operator *(Byte3 a, Byte3 b) => new Byte3((byte)(a.X * b.X), (byte)(a.Y * b.Y), (byte)(a.Z * b.Z));
public static Byte3 operator *(Byte3 a, byte b) => new Byte3((byte)(a.X * b), (byte)(a.Y * b), (byte)(a.Z * b));

public static Byte3 operator +(Byte3 a, (int, int, int) b) => new Byte3((byte)(a.X + b.Item1), (byte)(a.Y + b.Item2), (byte)(a.Z + b.Item3));
public static Byte3 operator -(Byte3 a, (int, int, int) b) => new Byte3((byte)(a.X - b.Item1), (byte)(a.Y - b.Item2), (byte)(a.Z - b.Item3));
public static implicit operator Byte3((byte X, byte Y, byte Z) v) => new Byte3(v.X, v.Y, v.Z);
public static implicit operator (byte X, byte Y, byte Z)(Byte3 v) => (v.X, v.Y, v.Z);

public static explicit operator Byte3(Int3 a) => new Byte3((byte)a.X, (byte)a.Y, (byte)a.Z);
}
Expand Down
25 changes: 18 additions & 7 deletions GBX.NET/Chunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace GBX.NET
public abstract class Chunk : IComparable<Chunk>
{
public virtual uint ID => GetType().GetCustomAttribute<ChunkAttribute>().ID;
public int Progress { get; internal set; }
/// <summary>
/// Stream of unknown bytes
/// </summary>
Expand All @@ -37,6 +36,7 @@ public virtual ILookbackable Lookbackable
}
}

[IgnoreDataMember]
public GameBoxPart Part { get; set; }

public Chunk()
Expand Down Expand Up @@ -89,10 +89,17 @@ public int CompareTo(Chunk other)
}
}

public abstract class Chunk<T> : Chunk where T : Node
public abstract class Chunk<T> : Chunk, IChunk where T : Node
{
[IgnoreDataMember]
public T Node { get; internal set; }
public int Progress { get; set; }

Node IChunk.Node
{
get => Node;
set => Node = (T)value;
}

public bool IsHeader => Lookbackable is GameBoxHeader;
public bool IsBody => Lookbackable is GameBoxBody;
Expand Down Expand Up @@ -166,6 +173,8 @@ public virtual void ReadWrite(T n, GameBoxReaderWriter rw)
}
}

void IChunk.ReadWrite(Node n, GameBoxReaderWriter rw) => ReadWrite((T)n, rw);

public byte[] ToByteArray()
{
var lookbackable = Lookbackable;
Expand All @@ -177,11 +186,13 @@ public byte[] ToByteArray()
lookbackable = l;
}

using var ms = new MemoryStream();
using var w = new GameBoxWriter(ms, lookbackable);
var rw = new GameBoxReaderWriter(w);
ReadWrite(Node, rw);
return ms.ToArray();
using (var ms = new MemoryStream())
using (var w = new GameBoxWriter(ms, lookbackable))
{
var rw = new GameBoxReaderWriter(w);
ReadWrite(Node, rw);
return ms.ToArray();
}
}
}
}
6 changes: 3 additions & 3 deletions GBX.NET/ChunkList.cs → GBX.NET/ChunkSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

namespace GBX.NET
{
public class ChunkList : SortedSet<Chunk>
public class ChunkSet : SortedSet<Chunk>
{
[IgnoreDataMember]
public Node Node { get; set; }

public ChunkList() : base()
public ChunkSet() : base()
{

}

public ChunkList(IEnumerable<Chunk> collection) : base(collection)
public ChunkSet(IEnumerable<Chunk> collection) : base(collection)
{

}
Expand Down
5 changes: 0 additions & 5 deletions GBX.NET/Engines/Control/CControlEffectSimi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ public class CControlEffectSimi : Node
{
public Key[] Keys { get; set; }

public CControlEffectSimi(ILookbackable lookbackable, uint classID) : base(lookbackable, classID)
{

}

[Chunk(0x07010004)]
public class Chunk004 : Chunk<CControlEffectSimi>
{
Expand Down
27 changes: 6 additions & 21 deletions GBX.NET/Engines/Game/CGameCtnAnchoredObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,26 @@ public class CGameCtnAnchoredObject : Node
{
public Meta ItemModel { get; set; }

public Vector3? PitchYawRoll { get; set; }
public Vec3? PitchYawRoll { get; set; }

public Byte3 BlockUnitCoord { get; set; }

public Vector3? AbsolutePositionInMap { get; set; }
public Vec3? AbsolutePositionInMap { get; set; }

public CGameWaypointSpecialProperty WaypointSpecialProperty { get; set; }

public short Flags { get; set; }

public float Scale { get; set; } = 1;

public Vector3 PivotPosition { get; set; }
public Vec3 PivotPosition { get; set; }

public int Variant
{
get => (Flags >> 8) & 15;
set => Flags = (short)((Flags & 0xF0FF) | ((value & 15) << 8));
}

public CGameCtnAnchoredObject(ILookbackable lookbackable) : base(lookbackable)
{

}

public CGameCtnAnchoredObject(ILookbackable lookbackable, uint classId) : base(lookbackable, classId)
{

}

public CGameCtnAnchoredObject(Chunk chunk) : base(chunk)
{

}

public override string ToString()
{
return ItemModel.ToString();
Expand All @@ -66,8 +51,8 @@ public class Chunk03101002 : Chunk<CGameCtnAnchoredObject>
public int Version { get; set; } = 7;
public int Unknown1 { get; set; } = -1;

public Vector3 Unknown3 { get; set; }
public Vector3 Unknown4 { get; set; }
public Vec3 Unknown3 { get; set; }
public Vec3 Unknown4 { get; set; }

public override void Read(CGameCtnAnchoredObject n, GameBoxReader r, GameBoxWriter unknownW)
{
Expand All @@ -79,7 +64,7 @@ public override void Read(CGameCtnAnchoredObject n, GameBoxReader r, GameBoxWrit
n.AbsolutePositionInMap = r.ReadVec3();
var specialWaypoint = r.ReadInt32();
if(specialWaypoint != -1)
n.WaypointSpecialProperty = Parse<CGameWaypointSpecialProperty>(Node.Body, r, true);
n.WaypointSpecialProperty = Parse<CGameWaypointSpecialProperty>(Node.Body, r);
n.Flags = r.ReadInt16();
n.PivotPosition = r.ReadVec3();
n.Scale = r.ReadSingle();
Expand Down
82 changes: 36 additions & 46 deletions GBX.NET/Engines/Game/CGameCtnBlock.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,50 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace GBX.NET.Engines.Game
{
using System;
using System.Collections.Generic;
using System.Text;

namespace GBX.NET.Engines.Game
{
/// <summary>
/// Block on a map (0x03057000)
/// </summary>
/// <remarks>A block placed on a map.</remarks>
[Node(0x03057000)]
public class CGameCtnBlock : Node
{
public Meta BlockInfo { get; set; }

public Direction? Direction { get; set; }

public Byte3? Coord { get; set; }

public int? Flags { get; set; }

public CGameCtnBlock(ILookbackable lookbackable, uint classID) : base(lookbackable, classID)
{

}

public CGameCtnBlock(ILookbackable lookbackable) : base(lookbackable, 0x03057000)
{

}

public override string ToString()
{
return $"{BlockInfo?.ID} {Coord}";
/// </summary>
/// <remarks>A block placed on a map.</remarks>
[Node(0x03057000)]
public class CGameCtnBlock : Node
{
public Meta BlockInfo { get; set; }

public Direction? Direction { get; set; }

public Byte3? Coord { get; set; }

public int? Flags { get; set; }

public override string ToString()
{
return $"{BlockInfo?.ID} {Coord}";
}

#region Chunks
#region Chunks

#region 0x002 chunk

/// <summary>
/// CGameCtnBlock 0x002 chunk
/// </summary>
[Chunk(0x03057002)]
public class Chunk03057002 : Chunk<CGameCtnBlock>
{
public override void ReadWrite(CGameCtnBlock n, GameBoxReaderWriter rw)
{
n.BlockInfo = rw.Meta(n.BlockInfo);
n.Direction = (Direction)rw.Byte((byte)n.Direction.GetValueOrDefault());
n.Coord = rw.Byte3(n.Coord.GetValueOrDefault());
n.Flags = rw.Int32(n.Flags.GetValueOrDefault());
}
[Chunk(0x03057002)]
public class Chunk03057002 : Chunk<CGameCtnBlock>
{
public override void ReadWrite(CGameCtnBlock n, GameBoxReaderWriter rw)
{
n.BlockInfo = rw.Meta(n.BlockInfo);
n.Direction = (Direction)rw.Byte((byte)n.Direction.GetValueOrDefault());
n.Coord = rw.Byte3(n.Coord.GetValueOrDefault());
n.Flags = rw.Int32(n.Flags.GetValueOrDefault());
}
}

#endregion

#endregion
}
}
#endregion
}
}
Loading

0 comments on commit b0123ae

Please sign in to comment.