GBX.NET 2.1.0-nightly.20241223.e293b64

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), July 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!

Showing the top 20 packages that depend on GBX.NET.

Packages Downloads
GBX.NET.Tool
Base library for creating rich tools for different environments with GBX.NET.
41
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.
32
GBX.NET.Hashing
Hashing features (CRC32) for GBX.NET 2.
31
GBX.NET.Tool
Base library for creating rich tools for different environments with GBX.NET.
28
GBX.NET.Tool
Base library for creating rich tools for different environments with GBX.NET.
26
GBX.NET.ZLib
Support for zlib compressed parts of Gbx, integrated with GBX.NET. This official implementation uses Iconic.Zlib.Netstandard.
24
GBX.NET.Tool
Base library for creating rich tools for different environments with GBX.NET.
23
GBX.NET.Crypto
Cryptographic features for GBX.NET 2.
23
GBX.NET.Imaging
Provides extensions for image handling in GBX.NET (GDI+, Windows only).
23
GBX.NET.NewtonsoftJson
Better and easier JSON serialization with polymorphic support for GBX.NET objects.
23
GBX.NET.Tool
Base library for creating rich tools for different environments with GBX.NET.
22

Version Downloads Last updated
2.1.0-nightly.20241223.e293b64 2 12/23/2024
2.1.0-nightly.20241222.e293b64 2 12/22/2024
2.1.0-nightly.20241221.e293b64 4 12/21/2024
2.1.0-nightly.20241220.e293b64 12 12/20/2024
2.1.0-nightly.20241220.e0c54b9 3 12/20/2024
2.1.0-nightly.20241220.c45aaa8 4 12/20/2024
2.1.0-nightly.20241219.e0c54b9 15 12/19/2024
2.1.0-nightly.20241218.7ff3ff1 5 12/18/2024
2.1.0-nightly.20241217.1279c7b 5 12/17/2024
2.1.0-nightly.20241216.9ff62e8 5 12/16/2024
2.1.0-nightly.20241215.9ff62e8 5 12/15/2024
2.1.0-nightly.20241214.9ff62e8 4 12/14/2024
2.1.0-nightly.20241213.9ff62e8 5 12/13/2024
2.1.0-nightly.20241212.9ff62e8 5 12/12/2024
2.1.0-nightly.20241211.9ff62e8 13 12/11/2024
2.1.0-nightly.20241210.ba792c4 10 12/10/2024
2.1.0-nightly.20241209.69b3821 8 12/09/2024
2.1.0-nightly.20241208.c435869 11 12/08/2024
2.1.0-nightly.20241207.82b53c8 8 12/07/2024
2.1.0-nightly.20241206.82b53c8 7 12/06/2024
2.1.0-nightly.20241205.82b53c8 9 12/05/2024
2.1.0-nightly.20241204.82b53c8 7 12/04/2024
2.1.0-nightly.20241203.82b53c8 5 12/03/2024
2.1.0-nightly.20241130.82b53c8 6 11/30/2024
2.1.0-nightly.20241129.82b53c8 10 11/29/2024
2.1.0-nightly.20241128.82b53c8 8 11/28/2024
2.1.0-nightly.20241127.82b53c8 5 11/27/2024
2.1.0-nightly.20241126.82b53c8 14 11/26/2024
2.1.0-nightly.20241125.82b53c8 6 11/25/2024
2.1.0-nightly.20241124.82b53c8 15 11/24/2024
2.1.0-nightly.20241123.8c6b466 8 11/23/2024
2.1.0-nightly.20241122.8c6b466 13 11/22/2024
2.1.0-nightly.20241121.8c6b466 6 11/21/2024
2.1.0-nightly.20241120.8b1a087 13 11/20/2024
2.1.0-nightly.20241119.93c22eb 14 11/19/2024
2.1.0-nightly.20241118.93c22eb 8 11/18/2024
2.1.0-nightly.20241117.93c22eb 15 11/17/2024
2.1.0-nightly.20241116.93c22eb 12 11/16/2024
2.1.0-nightly.20241115.93c22eb 18 11/15/2024
2.1.0-nightly.20241114.93c22eb 5 11/14/2024
2.1.0-nightly.20241113.93c22eb 15 11/13/2024
2.1.0-nightly.20241112.248d1cd 17 11/12/2024
2.1.0-nightly.20241111.248d1cd 17 11/11/2024
2.1.0-nightly.20241110.e8ee7e0 18 11/10/2024
2.1.0-nightly.20241109.e8ee7e0 18 11/09/2024
2.1.0-nightly.20241108.8ba35d0 20 11/08/2024
2.1.0-nightly.20241108.8477567 16 11/08/2024
2.1.0-nightly.20241107.25e6fd7 14 11/07/2024
2.1.0-nightly.20241106.25e6fd7 17 11/06/2024
2.1.0-nightly.20241105.4d6adf5 17 11/05/2024
2.1.0-nightly.20241105.25e6fd7 18 11/05/2024
2.1.0-nightly.20241104.4d6adf5 7 11/04/2024
2.1.0-nightly.20241104.3fd0f4f 7 11/04/2024
2.1.0-nightly.20241103.3fd0f4f 15 11/03/2024
2.1.0-nightly.20241102.3fd0f4f 15 11/02/2024
2.1.0-nightly.20241101.3fd0f4f 13 11/01/2024
2.1.0-nightly.20241031.3fd0f4f 18 10/31/2024
2.1.0-nightly.20241030.3fd0f4f 18 10/30/2024
2.1.0-nightly.20241029.3fd0f4f 19 10/29/2024
2.1.0-nightly.20241028.3fd0f4f 19 10/28/2024
2.1.0-nightly.20241027.3fd0f4f 19 10/27/2024
2.1.0-nightly.20241026.3fd0f4f 16 10/26/2024
2.1.0-nightly.20241025.3fd0f4f 13 10/25/2024
2.1.0-nightly.20241024.9bb5282 20 10/24/2024
2.1.0-nightly.20241023.9bb5282 17 10/23/2024
2.1.0-nightly.20241022.9bb5282 20 10/22/2024
2.1.0-nightly.20241021.9bb5282 19 10/21/2024
2.1.0-nightly.20241020.9bb5282 19 10/20/2024
2.1.0-nightly.20241019.9bb5282 17 10/19/2024
2.1.0-nightly.20241018.9bb5282 22 10/18/2024
2.1.0-nightly.20241017.9bb5282 23 10/17/2024
2.1.0-nightly.20241016.9bb5282 24 10/16/2024
2.1.0-nightly.20241015.9bb5282 5 10/15/2024
2.1.0-nightly.20241014.9bb5282 6 10/14/2024
2.1.0-nightly.20241013.9bb5282 20 10/13/2024
2.1.0-nightly.20241012.9bb5282 7 10/12/2024
2.1.0-nightly.20241011.9bb5282 12 10/11/2024
2.1.0-nightly.20241009.9bb5282 22 10/09/2024
2.1.0-nightly.20241008.9bb5282 19 10/08/2024
2.1.0-nightly.20241007.9bb5282 21 10/07/2024
2.1.0-nightly.20241006.4099e01 23 10/06/2024
2.0.9 36 10/01/2024
2.0.9-nightly.20241006.119dd40 22 10/06/2024
2.0.9-nightly.20241005.119dd40 22 10/05/2024
2.0.9-nightly.20241004.119dd40 20 10/04/2024
2.0.9-nightly.20241003.119dd40 21 10/03/2024
2.0.9-nightly.20241002.119dd40 20 10/02/2024
2.0.9-nightly.20241001.bedb272 21 10/01/2024
2.0.9-nightly.20240930.006258e 22 09/30/2024
2.0.8 25 09/29/2024
2.0.8-nightly.20240930.13d122d 21 09/30/2024
2.0.8-nightly.20240929.cf61d64 23 09/29/2024
2.0.8-nightly.20240928.cf61d64 24 09/28/2024
2.0.8-nightly.20240927.cf61d64 26 09/27/2024
2.0.8-nightly.20240926.cf61d64 22 09/26/2024
2.0.8-nightly.20240925.cf61d64 26 09/25/2024
2.0.8-nightly.20240924.cf61d64 23 09/24/2024
2.0.8-nightly.20240923.cf61d64 6 09/23/2024
2.0.8-nightly.20240922.47ec8ee 25 09/22/2024
2.0.8-nightly.20240921.47ec8ee 25 09/21/2024
2.0.8-nightly.20240920.47ec8ee 24 09/20/2024
2.0.8-nightly.20240919.47ec8ee 23 09/19/2024
2.0.8-nightly.20240918.47ec8ee 5 09/18/2024
2.0.8-nightly.20240917.47ec8ee 21 09/17/2024
2.0.8-nightly.20240916.47ec8ee 24 09/16/2024
2.0.8-nightly.20240915.ceae473 23 09/15/2024
2.0.8-nightly.20240914.0f65302 74 09/14/2024
2.0.8-nightly.20240913.f82616f 25 09/13/2024
2.0.8-nightly.20240913.7bb81bd 21 09/13/2024
2.0.8-nightly.20240913.606d5ba 25 09/13/2024
2.0.8-nightly.20240912.322c516 23 09/12/2024