TmEssentials 2.9.1
dotnet add package TmEssentials --version 2.9.1
NuGet\Install-Package TmEssentials -Version 2.9.1
<PackageReference Include="TmEssentials" Version="2.9.1" />
<PackageVersion Include="TmEssentials" Version="2.9.1" />
<PackageReference Include="TmEssentials" />
paket add TmEssentials --version 2.9.1
#r "nuget: TmEssentials, 2.9.1"
#:package TmEssentials@2.9.1
#addin nuget:?package=TmEssentials&version=2.9.1
#tool nuget:?package=TmEssentials&version=2.9.1
![]()
Welcome to TmEssentials!
A light-weight .NET library with the essentials of Trackmania and ManiaPlanet:
- Race times with
TimeInt32andTimeSingle, formatted and parsed like in the game - Text formatting that reads
$codes the same way as the game, to plain text, HTML or ANSI - Account IDs and logins converted both ways
- Map UIDs made and decoded like the game does
- Fully managed, trimmable and NativeAOT compatible
- Runs anywhere from .NET Framework 4.6.2 to .NET 11
Try the text formatting in the web sample.
Packages
| Package | Description |
|---|---|
| TmEssentials | Times, text formatting, accounts and map UIDs |
| TmEssentials.Razor | The FormattedText Blazor component, with a stylesheet for the game's icons |
dotnet add package TmEssentials
Framework support
TmEssentials targets .NET 11, 10, 9 and 8, .NET Standard 2.1 and 2.0, and .NET Framework 4.6.2. TmEssentials.Razor targets .NET 11, 10, 9 and 8.
| Feature | .NET 8+ | .NET Standard 2.0/2.1 | .NET Framework 4.6.2+ |
|---|---|---|---|
| Times, text formatting, accounts, map UIDs | Yes | Yes | Yes |
IParsable and ISpanParsable on times |
Yes | No | No |
| System.Text.Json converters | Yes | No | No |
HttpClient.HeadAsync |
Yes | Yes | No |
Time
TimeInt32 and TimeSingle
The game stores race times as whole milliseconds in an int, and other times, like MediaTracker keys, as seconds in a float. TimeInt32 and TimeSingle hold exactly that in 4 bytes, half the size of TimeSpan. They have the familiar TimeSpan members (Days, TotalSeconds, Add, Duration, operators and more), share the ITime interface, and ToString() writes the time in the Trackmania format.
var time = new TimeInt32(TotalMilliseconds: 36217);
time.ToTmString(); // 0:36.217 (ToString() does the same)
time.ToTmString(useHundredths: true); // 0:36.21
time.ToTmString(useApostrophe: true); // 0'36''217
time.ToTmString(compact: true); // 36.217, handy for time differences
new TimeInt32(3_723_456).ToString(); // 1:02:03.456
TimeInt32? noTime = null;
noTime.ToTmString(); // -:--.---
noTime.ToTmString(useHundredths: true); // -:--.--
noTime.ToTmString(useApostrophe: true); // -'--''---
TimeSingle works the same way. It rounds to the nearest millisecond when formatting, so float errors don't show:
var time = new TimeSingle(TotalSeconds: 23.51f);
time.ToTmString(); // 0:23.510
time.ToTmString(useHundredths: true); // 0:23.51
new TimeSingle(0.251f).ToString(); // 0:00.251, even though the float is 0.25099998
Parsing
Both types parse the formats that ToString() writes, with milliseconds or hundredths and an optional minus sign. Parsing does not depend on the culture.
TimeInt32.Parse("1:23.456"); // 83456 milliseconds
TimeInt32.Parse("36.217"); // 36217 milliseconds
TimeInt32.TryParse("abc", out var result); // false
TimeSingle.Parse("1:23.456"); // 83.456 seconds
A number without a colon or a dot is read as a fraction of a second, like TimeSpan.ParseExact with the FFFFFFF format. 5 is 500 milliseconds, 05 is 50 milliseconds and 500 is 500 milliseconds.
Conversions and overflow
TimeInt32 behaves like TimeSpan when a value doesn't fit: it throws OverflowException instead of wrapping around. Its range is about ±24.8 days.
TimeSpan timeSpan = new TimeInt32(1234); // implicit
TimeSingle single = new TimeInt32(1234); // implicit
var a = (TimeInt32)TimeSpan.FromSeconds(1.2345); // 1234 ms, truncated to whole milliseconds
var b = (TimeInt32)new TimeSingle(0.251f); // 251 ms, rounded to the nearest millisecond
var c = TimeInt32.FromSeconds(0.251f); // 251 ms, rounded to the nearest millisecond
new TimeInt32(251) == new TimeSingle(0.251f); // true, compared by TotalSeconds
TimeInt32.MaxValue + new TimeInt32(1); // OverflowException
TimeInt32.FromDays(30); // OverflowException
These are breaking changes from 2.8.0: conversions to TimeInt32 from TimeSpan and TimeSingle need a cast, the From methods round instead of truncating, and arithmetic throws on overflow. See the releases for the full list.
TimeSpan extensions
The same formatting is available on TimeSpan:
TimeSpan.FromMilliseconds(83456).ToTmString(); // 1:23.456
TimeSpan? noTime = null;
noTime.ToTmString(); // -:--.---
TimeSpan.FromTicks(15_000).ToMilliseconds(); // 1, the total milliseconds truncated to an int
JSON and TypeConverter
On .NET 8+, JsonTimeInt32Converter and JsonTimeSingleConverter read and write the times as JSON numbers: TimeInt32 as milliseconds and TimeSingle as seconds. They use no reflection, so they also work in source-generated contexts.
var options = new JsonSerializerOptions
{
Converters = { new JsonTimeInt32Converter(), new JsonTimeSingleConverter() }
};
JsonSerializer.Serialize(new { Time = new TimeInt32(36217), Key = new TimeSingle(1.5f) }, options);
// {"Time":36217,"Key":1.5}
Both types also have a TypeConverter, so configuration and input binding can read times from strings like 1:23.456.
Text formatting
TextFormatter reads formatting codes the same way as the formatting parser of ManiaPlanet:
- Colors with 1 to 3 hex digits (
$fis$f00) $<and$>save and restore up to 7 styles, and$zand$greset to the style saved by$<$l,$hand$plinks, with or without[url]- The
$$,$[and$]escapes - Carriage returns and a trailing
$are removed, like in the game
Deformat
TextFormatter.Deformat() removes the formatting codes:
TextFormatter.Deformat("$F00T$D01M$C13U$A14.$815K$727r$528a$329z$23By$03CC$03Co$04Bl$059o$068r$077s$085 $094v$0A30$0B1.$0C01");
// TMU.KrazyColors v0.1
TextFormatter.Deformat("$o$f00Big $<$iRed$> $$5 $l[https://trackmania.io]link$l");
// Big Red $5 link
HTML
TextFormatter.FormatHtml() turns the colors and styles into inline CSS, and the links into <a> elements when they are allowed:
TextFormatter.FormatHtml("$f00Red $l[https://trackmania.io]link$l", allowLinks: true);
// <span style="color:#f00">Red </span><a href="https://trackmania.io" style="color:#f00">link</a>
TextFormatter.FormatHtml("$o$iBold italic$z $sShadow");
// <span style="font-weight:bold;font-style:italic">Bold italic</span> <span style="text-shadow:1px 1px 2px black">Shadow</span>
TextFormatter.FormatHtml("$h[maniaplanet]Home$h", allowManialinks: true);
// <a href="maniaplanet:///:maniaplanet">Home</a>
Links are safe to show from untrusted text. Only http:// and https:// URLs become links, URLs without a scheme (like www.trackmania.com) get http:// in front, and URLs with any other scheme (like javascript:) are shown as plain text.
Icons
The game renders the private use characters U+F000 to U+F2E0 as Font Awesome 4.7 icons (see Text Styling). Pass a CSS class to wrap them in <span> elements, so that a page can display them with the icon font:
TextFormatter.FormatHtml(" Winner", allowLinks: false, allowManialinks: false, iconCssClass: "fa");
// <span class="fa"></span> Winner
fa works with the Font Awesome 4.7 stylesheet, or use tm-icon with the stylesheet of TmEssentials.Razor. TextFormatter.IsFontAwesomeIcon(char) tells whether a character is one of these icons.
ANSI
TextFormatter.FormatAnsi() turns the colors into the closest ANSI colors for terminals:
TextFormatter.FormatAnsi("$f00Red $0f0Green $zDefault");
// \x1B[91mRed \x1B[92mGreen \x1B[39m\x1B[22mDefault\x1B[39m\x1B[22m
Regex pattern
TextFormatter.FormattingCodeRegexPattern matches one formatting code, for when you need the codes themselves:
Regex.Matches("$f00Red $l[https://trackmania.io]link$l", TextFormatter.FormattingCodeRegexPattern);
// $f00, $l[https://trackmania.io], $l
A regex cannot know whether a link is open, so inside a link it can read more than the formatters do. Prefer the TextFormatter methods when you only need the result.
Blazor
TmEssentials.Razor provides the FormattedText component. Add @using TmEssentials.Razor to _Imports.razor, then:
<FormattedText Text="$f00Red $l[https://trackmania.io]link$l" AllowLinks="true" />
To display the icons, add the stylesheet that comes with the package (it includes the Font Awesome 4.7 font, licensed under the SIL OFL 1.1):
<link rel="stylesheet" href="_content/TmEssentials.Razor/tm-essentials.css" />
Set IconCssClass="fa" if the page uses the Font Awesome 4.7 stylesheet instead, or IconCssClass="@null" to not wrap the icons.
Accounts
AccountUtils converts between account IDs and logins:
AccountUtils.ToAccountId("v89i_w-eQKq5JBG5xwuKCQ"); // bfcf62ff-0f9e-40aa-b924-11b9c70b8a09
AccountUtils.ToLogin(Guid.Parse("bfcf62ff-0f9e-40aa-b924-11b9c70b8a09")); // v89i_w-eQKq5JBG5xwuKCQ
ToAccountId throws FormatException when the login does not decode to exactly 16 bytes.
Map UIDs
MapUtils makes map UIDs the same way as the game: a new UUID and a CRC32 (20 bytes) written as one number in base 63, with _0-9a-zA-Z as the digits. They are most often 27 characters long, sometimes shorter.
MapUtils.GenerateMapUid(); // random, like az8D4K6OKOuyGtUjHV_ui39x4xi
MapUtils.GenerateMapUid(seed: 1112); // OQNeAcbA0Uh7ftCm_tRbW7wezdb, the same for the same seed
MapUtils.GenerateMapUid(uuid, crc32); // exactly what the game makes from these
MapUtils.TryDecodeMapUid("az8D4K6OKOuyGtUjHV_ui39x4xi", out var uuid, out var crc32);
// true, eabd691c-a87f-428c-9e56-608e21bc91dd, 0xCF9B930D
The game uses the CRC32 of the map's serialized data, which needs the whole map, so the random overloads use a random number in its place.
HTTP HEAD requests
HttpClientExtensions.HeadAsync() sends a HEAD request, which is useful for checking a file's size or last modified date without downloading it:
using var response = await http.HeadAsync("https://example.com/map.Map.Gbx");
var lastModified = response.Content.Headers.LastModified;
Benchmarks
The benchmarks are in Tests/TmEssentials.Benchmarks. Run them with:
dotnet run -c Release --project Tests/TmEssentials.Benchmarks/TmEssentials.Benchmarks.csproj
Build
Make sure you have the .NET 11 SDK installed, then:
git clone https://github.com/BigBang1112/tm-essentials.git
cd tm-essentials
dotnet build
dotnet test --solution TmEssentials.slnx
The browser tests of TmEssentials.Razor use the installed Google Chrome, and the .NET Framework tests only run on Windows.
License
- TmEssentials and TmEssentials.Razor are licensed under the MIT License.
- The Font Awesome 4.7 font included in TmEssentials.Razor is licensed under the SIL OFL 1.1.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
| .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 is compatible. |
| .NET Framework | net461 was computed. net462 is compatible. 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. |
-
.NETFramework 4.6.2
- System.Memory (>= 4.6.3)
-
.NETStandard 2.0
- System.Memory (>= 4.6.3)
-
.NETStandard 2.1
- No dependencies.
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (8)
Showing the top 5 NuGet packages that depend on TmEssentials:
| Package | Downloads |
|---|---|
|
GBX.NET
General purpose library for Gbx files - data from Nadeo games like Trackmania or Shootmania. It supports high performance serialization and deserialization of 500+ Gbx classes. |
|
|
ManiaAPI.NadeoAPI
Wrapper for the official in-game Nadeo API from Trackmania released in 2020. Part of the ManiaAPI.NET library set. |
|
|
ManiaAPI.TMX
Wrapper for the TMX API, currently only on tm-exchange.com. Part of the ManiaAPI.NET library set. |
|
|
ManiaAPI.TrackmaniaIO
Wrapper for the Trackmania.io API. Part of the ManiaAPI.NET library set. |
|
|
ManiaAPI.TrackmaniaWS
Wrapper for the old TMF web API (ws.trackmania.com). Part of the ManiaAPI.NET library set. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on TmEssentials:
| Repository | Stars |
|---|---|
|
BigBang1112/gbx-net
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 500+ Gbx classes.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2.9.1 | 61 | 11/17/2026 |
| 2.9.0 | 120 | 11/17/2026 |
| 2.8.0 | 2,164 | 5/9/2026 |
| 2.7.0 | 6,073 | 4/11/2026 |
| 2.6.2 | 1,488 | 3/15/2026 |
| 2.6.1 | 234 | 2/7/2026 |
| 2.6.0 | 4,429 | 1/8/2026 |
| 2.5.3 | 1,689 | 10/16/2025 |
| 2.5.2 | 2,600 | 3/28/2025 |
| 2.5.0 | 6,764 | 7/20/2024 |
| 2.4.2 | 3,433 | 4/14/2024 |
| 2.4.1 | 1,953 | 1/24/2024 |
| 2.4.0 | 3,041 | 12/21/2023 |
| 2.3.3 | 671 | 7/5/2023 |
| 2.3.2 | 7,850 | 8/30/2022 |
| 2.3.1 | 3,179 | 8/10/2022 |
| 2.3.0 | 1,952 | 8/4/2022 |
| 2.2.0 | 2,217 | 5/30/2022 |
| 2.1.3 | 4,142 | 4/2/2022 |
| 2.1.2 | 2,899 | 2/19/2022 |
- Changed `TextFormatter.FormatAnsi` to write bright colors with the bright color codes instead of bold
- Fixed `TextFormatter.FormatAnsi` writing grays like `$888` and `$ccc` in red