Repository navigation
Reloading and debugging
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 buildcopies 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.
- The old copy's
Unloadingtoken is cancelled and itsOnUnload()runs. Stop your threads and timers there. - The old copy's hooks are switched off, and its
Game.Tickhandlers, ANNA entries and otherFH2registrations are removed. - The new copy's
OnInit()runs, withIsReloadset totrue.
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();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.
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:
| Type | To |
|---|---|
list |
list every mod's commands |
MyMod speed |
run your mod's speed command |
reload MyMod |
reload a hosted mod |
mods |
list the hosted mods |
cls, help
|
clear the screen, show help |
The console is a separate program (fh2-mods\dotnet\FH2Console.exe), so closing it can't close the game.
-
Log("...")writes a line toplatform.log, tagged with your mod's name. -
Console.WriteLine,Trace.WriteLineandDebug.WriteLinego there too. They're safe to call anywhere, hooks included.
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.
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.
Playing
Getting started
Writing mods
The FH2 classes
- Game
- Player
- Vehicle
- World
- Garage, CarCatalog, Profile
- UI and Hud
- Camera
- Audio
- ANNA
- DebugOverlay
- Controller
- GameInput
- GameWindow
- Menus and UiElement
- SettingsTile
- ButtonIcons and Picture
- MapView, PhotoCamera, GarageCamera
More