Skip to content

Commit

Permalink
Merge pull request #43 from BigBang1112/patch-small
Browse files Browse the repository at this point in the history
GBX.NET 0.15.1
  • Loading branch information
BigBang1112 committed Apr 4, 2022
2 parents db7daab + 945a5dc commit 5ed4a3f
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 88 deletions.
5 changes: 5 additions & 0 deletions Src/GBX.NET/Engines/Game/CGameCtnChallenge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3898,6 +3898,11 @@ public override void Write(CGameCtnChallenge n, GameBoxWriter w, ILogger? logger

if (gbxItem.FileName is null)
{
if (gbxItem.Node.Ident is not null)
{
embedded.Add(gbxItem.Node.Ident);
}

continue;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace GBX.NET.Engines.Game;

public partial class CGameCtnMediaBlockOpponentVisibility
{
public enum EVisibility
{
Hidden,
Ghost,
Opaque
}
}
63 changes: 63 additions & 0 deletions Src/GBX.NET/Engines/Game/CGameCtnMediaBlockOpponentVisibility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace GBX.NET.Engines.Game;

/// <summary>
/// MediaTracker block - Opponent visibility (0x0338B000)
/// </summary>
[Node(0x0338B000)]
public partial class CGameCtnMediaBlockOpponentVisibility : CGameCtnMediaBlock, CGameCtnMediaBlock.IHasTwoKeys
{
private TimeSingle start;
private TimeSingle end = TimeSingle.FromSeconds(3);
private EVisibility visibility;

[NodeMember]
public TimeSingle Start { get => start; set => start = value; }

[NodeMember]
public TimeSingle End { get => end; set => end = value; }

[NodeMember]
public EVisibility Visibility { get => visibility; set => visibility = value; }

protected CGameCtnMediaBlockOpponentVisibility()
{

}

#region Chunks

#region 0x000 chunk

/// <summary>
/// CGameCtnMediaBlockOpponentVisibility 0x000 chunk
/// </summary>
[Chunk(0x0338B000)]
public class Chunk0338B000 : Chunk<CGameCtnMediaBlockOpponentVisibility>
{
public override void ReadWrite(CGameCtnMediaBlockOpponentVisibility n, GameBoxReaderWriter rw)
{
rw.TimeSingle(ref n.start);
rw.TimeSingle(ref n.end);
}
}

#endregion

#region 0x001 chunk

/// <summary>
/// CGameCtnMediaBlockOpponentVisibility 0x001 chunk
/// </summary>
[Chunk(0x0338B001)]
public class Chunk0338B001 : Chunk<CGameCtnMediaBlockOpponentVisibility>
{
public override void ReadWrite(CGameCtnMediaBlockOpponentVisibility n, GameBoxReaderWriter rw)
{
rw.EnumInt32<EVisibility>(ref n.visibility);
}
}

#endregion

#endregion
}
41 changes: 39 additions & 2 deletions Src/GBX.NET/Engines/GameData/CGameCtnCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public string? Name
[NodeMember]
public Color[,]? Icon { get; set; }

[NodeMember]
public byte[]? IconWebP { get; set; }

[NodeMember]
public CMwNod? IconFid { get; set; }

Expand Down Expand Up @@ -228,11 +231,30 @@ public override void ReadWrite(CGameCtnCollector n, GameBoxReaderWriter rw)
[Chunk(0x2E001004, "icon")]
public class Chunk2E001004 : HeaderChunk<CGameCtnCollector>
{
public short U01 = 1;

public override void Read(CGameCtnCollector n, GameBoxReader r)
{
var width = r.ReadInt16();
var height = r.ReadInt16();

var flags1 = width & 0x8000;
var flags2 = width & 0x8000;

var isWebP = flags1 >> 15 != 0 && flags2 >> 15 != 0;

if (isWebP)
{
// width &= 255;
// height &= 255;
// both seem to be unused so this operation is not useful

U01 = r.ReadInt16();
n.IconWebP = r.ReadBytes();

return;
}

var iconData = r.ReadArray<int>(width * height);

n.Icon = new Color[width, height];
Expand All @@ -248,12 +270,27 @@ public override void Read(CGameCtnCollector n, GameBoxReader r)

public override void Write(CGameCtnCollector n, GameBoxWriter w)
{
var width = (short)(n.Icon?.GetLength(0) ?? 64);
var height = (short)(n.Icon?.GetLength(1) ?? 64);
var width = (ushort)(n.Icon?.GetLength(0) ?? 64);
var height = (ushort)(n.Icon?.GetLength(1) ?? 64);

if (n.IconWebP is not null)
{
width |= 0x8000;
height |= 0x8000;
}

w.Write(width);
w.Write(height);

if (n.IconWebP is not null)
{
w.Write(U01);
w.Write(n.IconWebP.Length);
w.Write(n.IconWebP);

return;
}

if (n.Icon is null)
{
for (var y = 0; y < height; y++)
Expand Down
159 changes: 81 additions & 78 deletions Src/GBX.NET/Engines/Plug/CPlugEntRecordData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,84 +113,87 @@ private ObservableCollection<Sample> ReadSamples()
var timestamp = r.ReadInt32();
var buffer = r.ReadBytes(); // MwBuffer

if (buffer.Length > 0)
{
using var bufferMs = new MemoryStream(buffer);
using var bufferR = new GameBoxReader(bufferMs);

var sampleProgress = (int)bufferMs.Position;

var sample = new Sample(buffer)
{
BufferType = (byte)bufferType
};

switch (bufferType)
{
case 0:
break;
case 2:
{
bufferMs.Position = 5;

var (position, rotation, speed, velocity) = bufferR.ReadTransform(); // Only position matches

sample.Timestamp = TimeInt32.FromMilliseconds(timestamp);
sample.Position = position;
sample.Rotation = rotation;
sample.Speed = speed * 3.6f;
sample.Velocity = velocity;

break;
}
case 4:
{
bufferMs.Position = 5;
var rpmByte = bufferR.ReadByte();

bufferMs.Position = 14;
var steerByte = bufferR.ReadByte();
var steer = ((steerByte / 255f) - 0.5f) * 2;

bufferMs.Position = 91;
var gearByte = bufferR.ReadByte();
var gear = gearByte / 5f;

sample.Gear = gear;
sample.RPM = rpmByte;
sample.Steer = steer;

bufferMs.Position = 15;
var u15 = bufferR.ReadByte();

bufferMs.Position = 18;
var brakeByte = bufferR.ReadByte();
var brake = brakeByte / 255f;
var gas = u15 / 255f + brake;

sample.Brake = brake;
sample.Gas = gas;

bufferMs.Position = 47;

var (position, rotation, speed, velocity) = bufferR.ReadTransform();

sample.Timestamp = TimeInt32.FromMilliseconds(timestamp);
sample.Position = position;
sample.Rotation = rotation;
sample.Speed = speed * 3.6f;
sample.Velocity = velocity;

break;
}
case 10:
break;
default:
break;
}

samples.Add(sample);
}
if (buffer.Length == 0)
{
continue;
}

using var bufferMs = new MemoryStream(buffer);
using var bufferR = new GameBoxReader(bufferMs);

var sampleProgress = (int)bufferMs.Position;

var sample = new Sample(buffer)
{
BufferType = (byte)bufferType
};

switch (bufferType)
{
case 0:
break;
case 2:
{
bufferMs.Position = 5;

var (position, rotation, speed, velocity) = bufferR.ReadTransform(); // Only position matches

sample.Timestamp = TimeInt32.FromMilliseconds(timestamp);
sample.Position = position;
sample.Rotation = rotation;
sample.Speed = speed * 3.6f;
sample.Velocity = velocity;

break;
}
case 4:
case 6:
{
bufferMs.Position = 5;
var rpmByte = bufferR.ReadByte();

bufferMs.Position = 14;
var steerByte = bufferR.ReadByte();
var steer = ((steerByte / 255f) - 0.5f) * 2;

bufferMs.Position = 91;
var gearByte = bufferR.ReadByte();
var gear = gearByte / 5f;

sample.Gear = gear;
sample.RPM = rpmByte;
sample.Steer = steer;

bufferMs.Position = 15;
var u15 = bufferR.ReadByte();

bufferMs.Position = 18;
var brakeByte = bufferR.ReadByte();
var brake = brakeByte / 255f;
var gas = u15 / 255f + brake;

sample.Brake = brake;
sample.Gas = gas;

bufferMs.Position = 47;

var (position, rotation, speed, velocity) = bufferR.ReadTransform();

sample.Timestamp = TimeInt32.FromMilliseconds(timestamp);
sample.Position = position;
sample.Rotation = rotation;
sample.Speed = speed * 3.6f;
sample.Velocity = velocity;

break;
}
case 10:
break;
default:
break;
}

samples.Add(sample);
}

u04 = r.ReadByte();
Expand Down
4 changes: 2 additions & 2 deletions Src/GBX.NET/GBX.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<AssemblyName>GBX.NET</AssemblyName>
<AssemblyTitle>GBX.NET</AssemblyTitle>
<Authors>Petr Pivoňka (BigBang1112)</Authors>
<Description>C#/.NET parser for Gbx files from Nadeo games. Supports deserialization of 150+ nodes, where 50%+ can be serialized back to Gbx.</Description>
<Description>C#/.NET parser for Gbx files from Nadeo games. Supports deserialization of 150+ nodes, where 50 %+ can be serialized back to Gbx.</Description>
<Copyright>Copyright © Petr 'BigBang1112' Pivoňka</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>

<Version>0.15.0</Version>
<Version>0.15.1</Version>
<PackageReleaseNotes></PackageReleaseNotes>

<TargetFrameworks>net6.0;netstandard2.1;netstandard2.0;net462</TargetFrameworks>
Expand Down
1 change: 1 addition & 0 deletions Src/GBX.NET/Resources/ClassID.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@
2AC CGameObjectVis
2CB CGameArenaPlayer
2E3 CGameSlotVis
38B CGameCtnMediaBlockOpponentVisibility
04 Graphic
001 GxLight
002 GxLightBall
Expand Down
12 changes: 6 additions & 6 deletions Tests/GBX.NET.Tests/Integration/GameBoxTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using GBX.NET.Engines.Game;
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace GBX.NET.Tests.Integration;
Expand All @@ -14,6 +9,8 @@ public class GameBoxTests
public static IEnumerable<string> ExampleMaps { get; } = Directory.GetFiles("Maps", "*.Gbx", SearchOption.AllDirectories);
public static IEnumerable<string> ExampleReplays { get; } = Directory.GetFiles("Replays", "*.Gbx", SearchOption.AllDirectories);

#if !NET462_OR_GREATER

[Fact(DisplayName = "Parse example maps - no exception is thrown")]
public void ParseExampleMaps_NoExceptionIsThrown()
{
Expand Down Expand Up @@ -59,4 +56,7 @@ public void ParseExampleReplay_NoExceptionIsThrown()
using var node = GameBox.ParseNode(mapFileName);
}
}

#endif

}

0 comments on commit 5ed4a3f

Please sign in to comment.