Navigation
Browse the developer docs

FH2 Mod Platform for .NET

Your first mod in C#

A ten-minute walkthrough: add Repair to ANNA's menu and warn above 300 km/h, in C#.

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

On this page

This walks you through a mod that adds Repair to FH2 ANNA's menu and warns you when you go over 300 km/h. It takes about ten minutes. Prefer VB.NET? See Your first mod in VB.

1. What you need

  • The .NET 10 SDK, plus Visual Studio 2026 or VS Code if you like an editor.
  • The game with FH2 Mod Platform for .NET installed: see Installing.
  • For the ANNA entry: the FH2 ANNA mod. Without it, the entry is just left out.

2. Get the SDK package

The release zip has the SDK as a NuGet package in sdk\FH2ModPlatform.<version>.nupkg.

  1. Copy it into a folder of its own, for example C:\FH2Sdk\.

  2. Tell NuGet about that folder, once:

    dotnet nuget add source C:\FH2Sdk --name FH2
    

The package is also on GitHub Packages. GitHub asks for a personal access token with read:packages even for public packages, so the folder is simpler.

3. Make the project

dotnet new classlib -n MyFirstMod -f net10.0
cd MyFirstMod
del Class1.cs

Replace MyFirstMod.csproj with:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <!-- Your Mod class: namespace.ClassName -->
    <FH2ModType>MyFirstMod.MyFirstMod</FH2ModType>
    <!-- Your game's fh2-mods folder: builds are copied there for you. -->
    <FH2ModsDir>D:\Games\Azimuth\fh2-mods</FH2ModsDir>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="FH2ModPlatform" Version="0.12.0" />
  </ItemGroup>
</Project>

4. Write the mod

MyFirstMod.cs:

using FH2;
using FH2ModPlatform;

namespace MyFirstMod;

public sealed class MyFirstMod : Mod
{
    public override ModInfo Info => new("MyFirstMod", "1.0.0")
    {
        Description = "Repair from ANNA, and a speed warning.",
    };

    private bool _warned;

    protected override void OnInit()
    {
        Log("hello!");

        // FH2 ANNA's menu (D-pad down while driving).
        ANNA.Items("Car").Add("Repair", () => Player.Car?.Repair());

        // Once a frame while you drive, on the game's thread.
        Game.Tick += () =>
        {
            var car = Player.Car;
            if (car is null) return;

            if (car.SpeedKmh > 300 && !_warned) UI.Notify("Slow down", $"{car.SpeedKmh:F0} km/h");
            _warned = car.SpeedKmh > 300;
        };
    }
}

What's going on:

  • Info is your mod's name and version. They show in the game and in the log.
  • OnInit runs once, when the game starts. Set things up there and return quickly.
  • Player.Car is your car, or null when you're not driving. That's why there's a ?. and an is null check.
  • Game.Tick runs on the game's thread, so the FH2 classes can be used straight away. See Threads.

5. Build and run

dotnet build

The build copies the mod to fh2-mods-dotnet\MyFirstMod\. Start the game, drive, press D-pad down and pick Car > Repair.

To see your Log lines, press ~ in the game or open fh2-mods\platform.log.

6. Change it without restarting

Turn on MODS > Installed mods > Platform.NET > Reload .NET mods when rebuilt. Now every dotnet build swaps the new code into the running game. See Reloading and debugging.

7. Ship it

For players, publish it as one DLL:

dotnet publish -c Release -p:FH2ModHosting=Aot

Give players bin\Release\net10.0\win-x64\publish\MyFirstMod.dll. It goes in fh2-mods\ and needs no .NET runtime. See Hosted or NativeAOT?.

Next

Copied from the wiki page Your-first-mod-in-CSharp 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.