Navigation
Browse the developer docs

FH2 Mod Platform for .NET

Reloading and debugging

Rebuild and swap hosted mods and scripts while the game runs, and debug them.

By Bartholomew Ho (qiangqiang101) · MIT license · v0.12.0 · 15 Nov 2026 · repository · original page

On this page

Reloading without restarting the game

Hosted mods and scripts can be rebuilt and swapped in while the game runs. NativeAOT mods can't, which is one more reason to develop hosted and ship NativeAOT.

Three ways to reload:

  • On every build: turn on MODS > Installed mods > Platform.NET > Reload .NET mods when rebuilt. With <FH2ModsDir> set in your project, dotnet build copies the mod into the game and it restarts straight away. Scripts reload when you save them.
  • From the console: type reload MyMod. Leave out the name to reload every hosted mod and start any new ones.
  • From a key: bind Reload .NET mods on the Mods page.

What happens in a reload

  1. The old copy's Unloading token is cancelled and its OnUnload() runs. Stop your threads and timers there.
  2. The old copy's hooks are switched off, and its Game.Tick handlers, ANNA entries and other FH2 registrations are removed.
  3. The new copy's OnInit() runs, with IsReload set to true.
protected override void OnInit()
{
    new Thread(() =>
    {
        while (!Unloading.IsCancellationRequested)
        {
            // ...
            Unloading.WaitHandle.WaitOne(1000);   // sleeps, but wakes up for a reload
        }
    }) { IsBackground = true }.Start();
}

protected override void OnUnload() => _file?.Dispose();

What a reload can't change

The platform can't remove things a mod added, so:

  • Settings, pages, title-screen entries, hotkeys and commands the new copy adds with the same key keep their place and call the new code.
  • Ones it adds for the first time only show from the next launch.
  • Ones it no longer adds stay until the game restarts, and do nothing.
  • Text and database edits take effect at the next launch, because the game reads them once.

The old copy stays in memory until the game closes, so reloading is for development, not for players.

Mods that can't be reloaded

Some mods change the game as it loads: what they did is in the game's data and in the old copy's memory, and a fresh copy can't pick it up. Such a mod says so, and a reload (A on the Hosted .NET mods page, the reload key, reload, auto-reload) then leaves it running, with a line in the log saying a restart is needed for the new build:

public override bool Reloadable => false;
Public Overrides ReadOnly Property Reloadable As Boolean
    Get
        Return False
    End Get
End Property

The console

Press ~ (the key left of 1) to open or close it. It shows platform.log as it's written, with failures in red and warnings in yellow. It also has a prompt:

TypeTo
listlist every mod's commands
MyMod speedrun your mod's speed command
reload MyModreload a hosted mod
modslist the hosted mods
log offhide the log: only what you type and the replies show
log MyModshow only the log lines with that text (your mod's, say)
log onshow the whole log again
cls, helpclear the screen, show help

The console remembers what log was set to, in FH2Console.ini beside it. log is new in 0.12.0.

The console is a separate program (fh2-mods\dotnet\FH2Console.exe), so closing it can't close the game.

Logging

  • Log("...") writes a line to platform.log, tagged with your mod's name.
  • Console.WriteLine, Trace.WriteLine and Debug.WriteLine go there too. They're safe to call anywhere, hooks included.

Watching values

Add a command, then type it in the console:

AddCommand("speed", "my car's speed", _ => $"{Player.Car?.SpeedKmh:F0} km/h");

Or show values over the game while you drive with DebugOverlay.

Breakpoints

Attach Visual Studio to azimuth.exe (Debug > Attach to Process), with code type Managed (.NET Core, .NET 5+). Hosted mods load with their .pdb, so breakpoints in your code are hit in the running game, after reloads too.

A breakpoint pauses the game's thread. Don't stop on one in Game.Tick while you're racing.

Copied from the wiki page Reloading-and-debugging at commit 7396a07 · MIT license
MIT License

Copyright (c) 2026 Bartholomew Ho

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.