Skip to content

Metadata Providers

Stefan Baumann edited this page Apr 19, 2020 · 2 revisions

Metadata providers are the easiest way to get metadata for a .gbx file. Just pass your GameBoxFile instance into a matching metadata provider and extract the data you are interested in.

Code Example: Parsing a .gbx map file

First, add a reference the ManiaPlanetSharp assembly. For improved performance, it is recommended you also add a reference to the ManiaPlanetSharp.GameBox.AutoGenerated assembly, which will then be used automatically to allow for faster parsing and less memory use.

//Parse the gbx file by path - parsing from a stream is supported, too
var file = GameBoxFile.Parse("Your-Map.Map.Gbx");
//Create an instance of the appropriate metadata provider
//This will give you direct access to the available data points without having to interact with the complex internal file structure
var metadata = new MapMetadataProvider(file);

//That's it - now you can get all the information you need from the metadata provider
//Metadata providers are implemented for maps, replays and items
Console.WriteLine($"Map '{metadata.Name}' by '{metadata.AuthorNickname}'");
Console.WriteLine($"Uid: '{metadata.Uid}'");
Console.WriteLine($"Environment: {metadata.Environment} with {metadata.Vehicle ?? "default"} vehicle");
Console.WriteLine($"Titlepack: {metadata.Titlepack}");

Validating mode

If the specific property is present multiple times in the file, the metadata provider offers the possibility to validate the data between the different sources to detect manipulation attempts by setting the MetadataProvider.ValidatingMode property in your MetadataProvider instance to true - the metadata provider will then throw an InvalidDataException on access to a property where the data sources do not match. This feature can be used to detect attempts at manipulating files, where the value has have been changed in one place but not another, which is a common pattern amongst manipulated .gbx files.