GBX.NET 2.0.6

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package GBX.NET --version 2.0.6                
NuGet\Install-Package GBX.NET -Version 2.0.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GBX.NET" Version="2.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GBX.NET --version 2.0.6                
#r "nuget: GBX.NET, 2.0.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GBX.NET as a Cake Addin
#addin nuget:?package=GBX.NET&version=2.0.6

// Install GBX.NET as a Cake Tool
#tool nuget:?package=GBX.NET&version=2.0.6                

GBX.NET

NuGet Discord

A general purpose library for Gbx files - data from Nadeo games like Trackmania or Shootmania, written in C#/.NET. It supports high performance serialization and deserialization of 200+ Gbx classes.

For more details, see the main README.

Framework support

Due to the recently paced evolution of .NET, framework support has been limited only to a few ones compared to GBX.NET 1:

  • .NET 8
  • .NET 6
  • .NET Standard 2.0

You can still use GBX.NET 2 on the old .NET Framework, but the performance of the library could be degraded.

Usage

These examples expect you to have <ImplicitUsings>enable</ImplicitUsings>. If this does not work for you, add using System.Linq; at the top.

Map information

Additional package GBX.NET.LZO is required in this example.

using GBX.NET;
using GBX.NET.Engines.Game;
using GBX.NET.LZO;

Gbx.LZO = new Lzo();

var map = Gbx.ParseNode<CGameCtnChallenge>("Path/To/My.Map.Gbx");

foreach (var block in map.GetBlocks().GroupBy(x => x.Name))
{
    Console.WriteLine($"{block.Key}: {block.Count()}");
}

Map information from Gbx header

using GBX.NET;
using GBX.NET.Engines.Game;
using GBX.NET.LZO;

var map = Gbx.ParseHeaderNode<CGameCtnChallenge>("Path/To/My.Map.Gbx");

Console.WriteLine(map.MapName);
Console.WriteLine(map.Xml);

Header contains a lot less information than the full node.

Modify and save a map

using GBX.NET;
using GBX.NET.Engines.Game;
using GBX.NET.LZO;

Gbx.LZO = new Lzo();

var gbx = Gbx.Parse<CGameCtnChallenge>("Path/To/My.Map.Gbx");
var map = gbx.Node; // See Clarity section for more info

map.MapName = "My new map name";

gbx.Save("Path/To/MyNew.Map.Gbx");

The trick here is that the Gbx properties are saved in the gbx object variable (Gbx class).

If you were to go with ParseNode in this case, this would not work for TMF and older games, but it is still possible if you specify the Gbx parameters in the Save method:

map.Save("Path/To/MyNew.Map.Gbx", new()
{
    PackDescVersion = 2 // Latest known PackDesc version in TMF
});

For TMS or TMN ESWC, you would have to specify ClassIdRemapMode for example:

map.Save("Path/To/MyNew.Map.Gbx", new()
{
    ClassIdRemapMode = ClassIdRemapMode.Id2006
    PackDescVersion = 1
});

These save parameters depend on the game of choice, but since Trackmania 2, this does not matter.

Processing multiple Gbx types

Additional package GBX.NET.LZO is required in this example.

This example shows how you can retrieve ghost objects from multiple different types of Gbx:

using GBX.NET;
using GBX.NET.Engines.Game;
using GBX.NET.LZO;

Gbx.LZO = new Lzo();

var node = Gbx.ParseNode("Path/To/My.Gbx");

var ghost = node switch
{
    CGameCtnReplayRecord replay => replay.GetGhosts().FirstOrDefault(),
    CGameCtnMediaClip clip => clip.GetGhosts().FirstOrDefault(),
    CGameCtnGhost g => g,
    _ => null
};

if (ghost is null)
{
    Console.WriteLine("This Gbx file does not have any ghost.");
}
else
{
    Console.WriteLine("Time: {0}", ghost.RaceTime);
}

Using pattern matching with non-generic Parse methods is a safer approach (no exceptions on different Gbx types), but less trim-friendly.

Read a large amount of replay metadata quickly

In case you only need the most basic information about many of the most common Gbx files (maps, replays, items, ...), do not read the full Gbx file, but only the header part. It is a great performance benefit for disk scans.

using GBX.NET;
using GBX.NET.Engines.Game;

foreach (var filePath in Directory.EnumerateFiles("Path/To/My/Directory", "*.Replay.Gbx", SearchOption.AllDirectories))
{
    try
    {
        DisplayBasicReplayInfo(filePath);
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Gbx exception occurred {Path.GetFileName(filePath)}: {ex}");
    }
}

void DisplayBasicReplayInfo(string filePath)
{
    var nodeHeader = Gbx.ParseHeaderNode(filePath);

    if (nodeHeader is CGameCtnReplayRecord replay)
    {
        Console.WriteLine($"{replay.MapInfo}: {replay.Time}");
    }
}

File types

Some of the common types to start with (a lot more are supported):

Latest extension Class Can read Can write Other extension/s
Map.Gbx CGameCtnChallenge Yes Yes Challenge.Gbx
Replay.Gbx CGameCtnReplayRecord Yes No
Ghost.Gbx CGameCtnGhost Yes Yes
Clip.Gbx CGameCtnMediaClip Yes Yes
Item.Gbx CGameItemModel Yes Yes Block.Gbx
Mat.Gbx CPlugMaterialUserInst Yes Yes
Mesh.Gbx CPlugSolid2Model Yes Yes
Shape.Gbx CPlugSurface Yes Yes
Macroblock.Gbx CGameCtnMacroBlockInfo Yes Yes
LightMapCache.Gbx CHmsLightMapCache No No
SystemConfig.Gbx CSystemConfig Yes Yes
FidCache.Gbx CMwRefBuffer Yes Yes
Profile.Gbx CGamePlayerProfile Up to TMF Up to TMF
Scores.Gbx CGamePlayerScore Yes No

Supported games

Many essential Gbx files from many games are supported:

  • Trackmania (2020), April 2024 update
  • ManiaPlanet 4(.1), TM2/SM
  • Trackmania Turbo
  • ManiaPlanet 3, TM2/SM
  • ManiaPlanet 2, TM2/SM
  • ManiaPlanet 1, TM2
  • TrackMania Forever, Nations/United
  • Virtual Skipper 5
  • TrackMania United
  • TrackMania Nations ESWC
  • TrackMania Sunrise eXtreme
  • TrackMania Original
  • TrackMania Sunrise
  • TrackMania Power Up
  • TrackMania (1.0)

License

GBX.NET library (this package) is MIT Licensed.

However, if you would use GBX.NET.LZO package with it (which is usually required), you'd need to follow the GNU GPL v3 License. See License section on the main README for more details.

Special thanks

Without these people, this project wouldn't be what it is today (ordered by impact):

  • Stefan Baumann (Solux)
  • Melissa (Miss)
  • florenzius
  • Kim
  • tilman
  • schadocalex
  • James Romeril
  • frolad (Juice)
  • Mika Kuijpers (TheMrMiku)
  • donadigo

And many thanks to every bug reporter!

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (13)

Showing the top 5 NuGet packages that depend on GBX.NET:

Package Downloads
GBX.NET.LZO

An LZO compression plugin for GBX.NET to allow de/serialization of compressed Gbx bodies. This official implementation uses lzo 2.10 from NativeSharpLzo and minilzo 2.06 port by zzattack.

GBX.NET.Imaging

Provides extensions for image handling in GBX.NET (GDI+, Windows only).

GBX.NET.Json

A wrapper for better JSON serialization of GBX.NET nodes, useful for comparing data.

GBX.NET.PAK

A PAK file parser using the GBX.NET features.

GBX.NET.Imaging.SkiaSharp

Provides extensions for image handling in GBX.NET (Google's Skia with SkiaSharp).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.9 245 10/1/2024
2.0.8 149 9/29/2024
2.0.7 536 8/16/2024
2.0.6 338 7/23/2024
2.0.6-beta3 130 7/20/2024
2.0.6-beta2 174 7/16/2024
2.0.6-beta1 159 7/16/2024
2.0.5 285 7/1/2024
2.0.4 290 6/12/2024
2.0.3 175 5/31/2024
2.0.3-beta1 161 5/30/2024
2.0.2 325 5/4/2024
2.0.1 205 4/29/2024
2.0.0 353 4/26/2024
2.0.0-rc1 281 4/23/2024
2.0.0-beta2 112 4/21/2024
2.0.0-beta1 272 4/20/2024
2.0.0-alpha3 99 4/18/2024
2.0.0-alpha2 185 4/14/2024
2.0.0-alpha1 197 4/12/2024
1.2.9 56 11/7/2024
1.2.8 34 11/7/2024
1.2.7 216 8/12/2024
1.2.6 896 2/19/2024
1.2.5 457 12/31/2023
1.2.4 537 11/26/2023
1.2.3 348 11/24/2023
1.2.2 592 7/8/2023
1.2.1 677 6/7/2023
1.2.0 864 5/4/2023
1.2.0-beta2 130 4/30/2023
1.2.0-beta1 117 4/25/2023
1.1.3 542 2/1/2023
1.1.2 328 1/21/2023
1.1.1 527 12/30/2022
1.1.0 1,304 12/11/2022
1.1.0-alpha2 211 11/11/2022
1.1.0-alpha1 131 10/25/2022
1.0.1 786 9/10/2022
1.0.0 445 9/9/2022
0.16.6 480 8/24/2022
0.16.5 493 8/21/2022 0.16.5 is deprecated because it is no longer maintained and has critical bugs.
0.16.4 487 8/19/2022 0.16.4 is deprecated because it is no longer maintained and has critical bugs.
0.16.3 497 8/18/2022 0.16.3 is deprecated because it is no longer maintained and has critical bugs.
0.16.2 773 8/11/2022 0.16.2 is deprecated because it is no longer maintained and has critical bugs.
0.16.1 509 7/21/2022 0.16.1 is deprecated because it is no longer maintained and has critical bugs.
0.16.0 1,316 7/16/2022 0.16.0 is deprecated because it has critical bugs.
0.15.1 564 4/4/2022
0.15.0 1,010 2/23/2022
0.15.0-rc2 156 2/19/2022
0.15.0-rc 197 2/1/2022 0.15.0-rc is deprecated because it has critical bugs.
0.14.3 376 12/19/2021
0.11.0 601 6/25/2021
0.8.0 454 1/29/2021