Navigation
Browse the developer docs

FH2 Modding Guide · Chapter 2

The FH2 Mod Platform

You are writing a platform mod: a DLL in fh2-mods with settings on the in-game MODS page.

By Trinculo54 · from the FH2 Modding Guide · CC BY 4.0 · copied 4 Dec 2026 · read the original, which may be newer

On this page

The FH2 Mod Platform is a small loader that sits next to azimuth.exe, loads every mod DLL in fh2-mods\, and hands each one a table of functions: text, files, the game database, hooks, settings rows, pages, title-screen entries, hotkeys, pop-ups, translations, car packs and more. This chapter is for anyone writing a mod against it. It starts with the practical path (what the platform is, a working mod, when things happen), then goes through the API feature by feature, and ends with the reference tables, the rules and the sites you must leave alone.

Everything here matches platform v2.9.2 (API 11). Source and docs: https://github.com/Trinculo54/fh2-mod-platform (include/fh2mod.h, docs/api.md, docs/writing-a-mod.md). If you write an Extra Options plugin instead, read 03-extra-options.md; the two live side by side.

All game addresses in this chapter are for forza_durango_release_final.exe of 24 Nov 2015 (TimeDateStamp 0x565501ED, SizeOfImage 0x3A18000), image base 0x140000000. game+0x... is the offset from wherever the exe is mapped; the absolute form assumes the usual base.

Contents: what the platform is, your first mod, lifecycle and threads, the API by version, feature by feature, fh2game.h, rules, what the platform owns, releasing, doc corrections.

What the platform is

One DLL under two names

The platform is a single DLL shipped twice next to azimuth.exe: as d3dcompiler_47.dll and, from 2.7.4, as an identical DWrite.dll. Azimuth imports one of those system DLLs, so Windows finds the platform in Azimuth's folder first. Every real export forwards to the system copy in System32, so shaders and text work as before. Only the platform's own extra exports are new.

AzimuthLoads
before 1.0.1d3dcompiler_47.dll only
1.0.1both (one copy runs, see below)
1.0.3 and laterDWrite.dll only (1.0.3 dropped the d3dcompiler_47 import)

So always ship both names. Never proxy these DLLs yourself, and never proxy winmm.dll, which belongs to Extra Options.

Which copy runs

When both copies load, only one runs. They agree through a per-process named mutex (Local\FH2ModPlatform.<pid>) and the export fh2mod_platform_version():

  • the newer version wins;
  • on a tie, DWrite.dll runs;
  • a copy older than 2.7.4 has no version export and can't stand down, so it runs and the newer copy stands down. This is why an old d3dcompiler_47.dll put back by another mod's zip beats a newer DWrite.dll on Azimuth 1.0.1.

The copy that stood down writes fh2-mods\platform-standby.log. Line 1 of fh2-mods\platform.log always tells you what runs:

FH2 Mod Platform 2.9.2 (API 11) in <Azimuth folder>
loaded as DWrite.dll; d3dcompiler_47.dll stood down

What it does at start

DllMain only acts inside azimuth.exe or forza_durango_release_final.exe, pins the DLL and starts a thread. Everything else happens on that thread, never under the Windows loader lock:

  1. Find the game's Mount folder (honouring azimuth.exe --game=DIR), rewrite platform.log and start a session. If Azimuth was started for another game, load nothing.
  2. Title gate (2.9.0): when azimuth.ini lists other titles and the launcher shows, wait for the player's pick. Another game: no mod loads. FH2: carry on, holding Azimuth at the game's start until every fh2mod_init has returned (at most 2 minutes).
  3. List fh2-mods\*.dll, sorted by file name, and load each one the player hasn't turned off. A DLL without an fh2mod_init export is a pre-platform mod: loaded later, once the game is known to be FH2, and it starts itself from DllMain.
  4. Call each fh2mod_init in that order, one after another, inside SEH.
  5. Once all have returned: write the string tables, notices and database for the first time, start the settings pages, pop-ups, HUD and pad layers, and release anyone waiting in wait_for_mods.

The platform also loads one well-known racing-wheel mod's DLL from the Azimuth folder itself (from 2.6.1), because that mod used to ship its own d3dcompiler_47.dll. It is listed on the MODS tab like any other mod.

Your first mod

Project setup

Add the platform as a git submodule, so your mod builds against the exact version it ships:

git submodule add https://github.com/Trinculo54/fh2-mod-platform platform
cmake_minimum_required(VERSION 3.20)
project(mymod VERSION 1.0.0 LANGUAGES C CXX RC)

add_subdirectory(platform)   # gives you fh2mod_platform and fh2mod_api

add_library(mymod SHARED src/mymod.cpp)
target_link_libraries(mymod PRIVATE fh2mod_api)
set_target_properties(mymod PROPERTIES OUTPUT_NAME MyMod PREFIX "")
target_compile_definitions(mymod PRIVATE MYMOD_VERSION="${PROJECT_VERSION}")
if(NOT MSVC)
    target_link_options(mymod PRIVATE -static)   # no libc++/libunwind DLLs to ship
endif()

fh2mod_api brings the headers and defines FH2MOD_PLATFORM_VERSION from the submodule's version.

Building

The released mods build with llvm-mingw (clang), CMake and Ninja (01-getting-started.md). Clang gives you MSVC-style SEH (__try/__except, with -fms-extensions) as well as GNU extensions; GCC MinGW can't do SEH, which most hooking code needs. Add a VERSIONINFO resource: the platform logs it next to the file name. For symbols in crash reports, build with -gcodeview -Wl,--pdb= (llvm-mingw release builds are stripped).

The smallest mod

#include "fh2mod.h"

FH2MOD_EXPORT int fh2mod_init(const FH2ModApi* api) {
    FH2ModInfo info{sizeof info, "MyMod", "1.0.0", "You/MyMod", FH2MOD_PLATFORM_VERSION, 1};
    FH2Mod* mod = api->register_mod(&info);
    if (!mod) return 0;   // online with offline_only, or a bad info: nothing to do
    api->log(mod, "hello");
    api->set_string(mod, "LoadingMessages.str", 0x6875, L"Fast Traveling (with MyMod)");
    return 0;
}

Build it, put MyMod.dll in <Azimuth folder>\fh2-mods\, start the game and fast-travel: the loading message shows your text in every language.

The FH2ModInfo fields in order are size, name, version, github_repo (for the update check, or NULL), platform_version and check_updates. The full struct is in the reference below.

Always return 0

fh2mod_init must return 0, every time, including when your mod decides to turn itself off. Any other value puts a red "Not working" row on the mod's page ("It reported a problem while starting (it returned N).") and a red ! on the MODS tab. If your mod can't run (wrong game code, missing file, older platform), log one plain sentence saying why and return 0. A crash inside fh2mod_init is caught and shown the same way, so it won't take the game down, but players will see it.

Logging

api->log(mod, "...") writes one line to fh2-mods\platform.log with a timestamp and [MyMod]. Log what you change, in plain sentences ("Trees: game code doesn't match, off."); a chatty mod keeps its own log too (session_log_path, API 9). To check a mod, start with only it installed and read platform.log: your DLL loaded with its version, registered, and your tables, files and database lines.

Doing real work on your own thread

fh2mod_init runs before the game exe is mapped (except under the title gate). Anything that touches game code waits on a thread of your own:

#include <windows.h>
#include <cstring>
#include "fh2mod.h"
#include "fh2game.h"

static const FH2ModApi* g_api;
static FH2Mod* g_mod;
static int (*o_kind)(void* car);

static int d_kind(void* car) {
    return o_kind(car);            // look, change, or pass through
}

static DWORD WINAPI start(LPVOID) {
    char* game = static_cast<char*>(g_api->wait_for_code(0xFFFFFFFFu));
    if (!game) {                    // another game, or another FH2 build
        g_api->log(g_mod, "No Forza Horizon 2 to change this session.");
        return 0;
    }
    if (std::memcmp(game + FH2_GAME_FORZACAR_KIND, FH2_GAME_FORZACAR_KIND_BYTES,
                    sizeof FH2_GAME_FORZACAR_KIND_BYTES - 1) != 0) {
        g_api->log(g_mod, "Car kind: game code doesn't match, off.");
        return 0;
    }
    if (g_api->hook_function(g_mod, "ForzaCar kind", game + FH2_GAME_FORZACAR_KIND,
                             reinterpret_cast<void*>(&d_kind), reinterpret_cast<void**>(&o_kind)))
        g_api->enable_hooks(g_mod, nullptr);
    return 0;
}

FH2MOD_EXPORT int fh2mod_init(const FH2ModApi* api) {
    g_api = api;
    FH2ModInfo info{sizeof info, "MyMod", "1.0.0", "You/MyMod", FH2MOD_PLATFORM_VERSION, 1};
    g_mod = api->register_mod(&info);
    if (!g_mod) return 0;
    if (api->api_version < 3) {
        api->log(g_mod, "This mod needs platform 2.2.0 or newer; nothing changed.");
        return 0;
    }
    if (HANDLE t = CreateThread(nullptr, 0, start, nullptr, 0, nullptr)) CloseHandle(t);
    return 0;
}

Note the NULL check on the base: wait_for_code and wait_for_game return NULL when Azimuth runs another game, another FH2 build, or on timeout.

Lifecycle and threads

fh2mod_init is called once, on the platform's thread and not under the loader lock, so it may load DLLs, create files and start threads. Mods init one after another, so keep it quick: register, declare, start your thread. DllMain needs nothing beyond DisableThreadLibraryCalls.

When changes take effect

The game reads string tables, the database and most media files once at start-up. So:

ChangeMade inside fh2mod_initMade later
set_string, replace_string, set_string_tr, set_noticeshows this session (written after all inits)written by apply_strings, shows next launch
add_sqlapplied for you this sessionapply_database writes it, shows next launch
set_filewritten at once; shows if the game hasn't read the file yetsame; most files are read once
add_setting, add_page, add_title_entry, add_hotkey, add_page_textshows this sessionshows next launch, or refused
add_translation, ui_uses, request_save_snapshot, HUD/pad add_layerworksrefused or too late to matter
set_page_rows, set_setting, show_toast, hooksany timeany time

Waiting

CallWaits untilReturnsNotes
wait_for_game(ms)Azimuth has mapped the exe (the player pressed Play)base or NULLown thread only; 0xFFFFFFFF = forever
wait_for_code(ms)as above, plus Extra Options has finished patchingbase or NULLrequired before hooking game code; gives up waiting for Extra Options 20 s after mapping
wait_for_mods(ms)every fh2mod_init has returned1, or 0returns 0 at once from inside fh2mod_init (and logs it)

Extra Options patches about 130 sites all at once and refuses all of them if any one differs, so a mod that hooks early silently turns Extra Options off (03-extra-options.md). Under the title gate fh2mod_init already runs with the game mapped. Under Proton the exe is mapped at another base and pointers are relocated: always use the returned base.

Which thread runs your callback

CallbackThread
on_change, on_slide, page on_open / on_select / on_button / on_slot, title on_press / on_choose, message box on_choose, hotkey on_rebind, page text getthe game's UI thread
hotkey on_pressthe platform's hotkey thread
command handlersthe platform's command thread
pad layer on_pressa platform thread
hook_instruction callback, detourswhichever game thread runs the code

A crash in a callback is caught and logged. Every API function is thread-safe. Strings you pass in are copied, nothing returned needs freeing, and the FH2ModApi* stays valid until the process ends.

There is no exit

Azimuth ends the game with TerminateProcess. No DLL_PROCESS_DETACH, no atexit, nothing runs. Save your settings when they change, not at exit.

When things go wrong

  • A DLL that fails to load logs FAILED to load X (error N) and gets a red row and a HUD notice.
  • A non-zero return or a crash in fh2mod_init logs X: fh2mod_init returned N or crashed (exception 0x...) and gets the red "Not working" row.
  • A mod built for a newer platform than the one installed gets the title line "Old FH2 Mod Platform: reinstall ".
  • An API call that refuses something returns 0 or NULL and logs the reason.

The API by version

FH2ModApi only ever grows at the end. Check api->api_version (or api->size) before using anything newer than API 1, so a player on an older platform gets a log line, not a crash.

APIPlatformAdds
12.0.0register_mod, log; string tables (set_string, replace_string, clear_strings, apply_strings); set_notice; game_base, wait_for_game
22.1.0set_file, clear_file; add_sql, clear_sql, apply_database; publish_interface, get_interface, wait_for_mods, mod_version
32.2.0hook_function, hook_call, hook_pointer, enable_hooks, disable_hooks, wait_for_code (MinHook built in)
42.3.0settings rows: add_setting, get_setting, set_setting (On/Off, needs_restart)
52.4.0sliders: get_slider, set_slider, FH2_SETTING_SLIDER
62.5.0FH2ModInfo.description, link rows (FH2_SETTING_LINK), the MODS tab
72.6.0patch_bytes, hook_instruction (registers including xmm0-15)
82.7.0pages: add_page, set_page_rows, set_page_xaml, page slots, focus_page_element, tile text and colours
92.8.0add_title_entry, title_started_by; offline_only, playing_online; FH2_SETTING_CHOICE; add_hotkey; add_command; session_id, session_log_path; request_save_snapshot; add_dump_memory; include/fh2game.h
102.9.0game_language, language, translations (add_translation, tr, tr_plural, set_string_tr, format_number, format_date), set_setting_text, set_mod_description; UI templates (pop-ups, tips, message boxes, page help and hints, UI sounds); car packs; HUD and pad layer interfaces
112.9.1page texts: add_page_text, page_text_changed; choice rows up to 100 choices; HUD canvas (HUD interface 3); pad layer 2

2.9.2 is a fix release with the same API 11: car packs with Extra Options now answer file lookups from a per-pack list instead of the disk, which removes a stutter.

Point releases in between (2.7.1 to 2.7.4) fixed things every mod depends on; see Releasing and packaging for why you should never ship an old one.

Two ways to guard a newer call:

if (api->api_version >= 9) api->add_hotkey(mod, &hk);   // by version

#include "fh2mod_helpers.h"                             // or by member, after fh2_helpers_init(api, mod)
if (FH2_API_HAS(add_hotkey)) api->add_hotkey(mod, &hk);

FH2_API_HAS(m) checks that api->size covers the member and that it isn't NULL. The wrapper headers fh2mod_ui.h and fh2mod_l10n.h do this for you (see UI helpers).

Feature by feature

Strings

The game's text lives in per-language string tables (media\Stripped\StringTables\<LANG>.zip, tables like Main.str, LoadingMessages.str). Each string has a 16-bit key, the same in every language. Find keys with python scripts/dump_strings.py "<game>/Mount/media/Stripped/StringTables/EN.zip" Main.str PRESS from the platform repo; the format is in 04-game-data.md.

CallDoes
set_string(mod, table, key, text)sets that key in every language to the same UTF-16 text; a later-loaded mod wins a clash (logged)
replace_string(mod, table, from, to)replaces every string exactly equal to from (whole, case-sensitive); English from only matches the EN, GB, CZ and HU tables
set_string_tr(mod, table, key, msg_key, english) (API 10)each language gets its own translation
clear_strings(mod, table)drops your edits (NULL = all tables)
apply_strings(mod)writes now; automatic after all inits
set_notice(mod, lines)lines under "PRESS (A) TO START" on the title screen, \n separated, about 40 characters a line; NULL or "" clears

Keep {0} placeholders in text you replace. Notices are sorted by mod name.

Files and the media override

set_file replaces one file under the game's media folder for this session:

// a file inside media\UI.zip: the zip's name is used as a folder
api->set_file(mod, "UI/Controls/HUDSpeedometerControl.xaml", xaml, xaml_len);
  • The path is relative to media, with / or \. Call it early: the game reads most files once.
  • Returns 1 when the file is yours and written; 0 when another mod owns it, the path is bad, the file belongs to the platform, or the write failed (all logged). Each path has one owner. String tables and the database can't be replaced whole.
  • clear_file(mod, path) deletes your override (NULL = all yours). Files left by a removed mod are cleaned up about 15 s after start.

Where the files go. The game reads mediaoverride, then mediapc, then media. With Extra Options loaded and EnableMediaOverrides=1, Extra Options mounts those folders and the platform writes to mediaoverride. Without Extra Options, platform 2.7.3 and later mount them itself. From 2.9.0, on Azimuth 1.0 or later without Extra Options, the platform writes text, files, MODS pages and the database to the Azimuth folder's own layer, data\titles\1A96545B\tmp\fh2-platform\media\ (the game's T:\ drive), mounted ahead of mediaoverride. That lets two Azimuth folders that share one game folder run different mods. The choice is made once at start, and a fresh folder's first session still uses mediaoverride.

So never hard-code mediaoverride when you read a file back. fh2-mods\platform-files.txt lists what the platform wrote and where. Files a player copies into mediaoverride by hand can't be turned off online; set_file ones can. Details of the volumes and priorities are in 04-game-data.md.

The game database

media\Stripped\gamedbRC.slt is a plain SQLite file of about 290 tables, read once at start. Change it only through add_sql:

api->add_sql(mod, "UPDATE Data_Car SET BaseCost = BaseCost / 2");   // half-price Autoshow
  • Use UPDATE and INSERT only. Never DROP and recreate a table: other mods' changes must survive.
  • The platform copies the database the game would read and runs each mod's statements (; separated, calls add up) in load order, each mod in its own transaction, after car packs'. A failing statement rolls back that mod only and logs the SQLite error.
  • It rebuilds only when something changed. Statements from fh2mod_init are applied for you; later, apply_database rebuilds (seconds: use your own thread). clear_sql(mod) drops yours.
  • From 2.7.2 the base is another mod's database in mediaoverride\Stripped if there is one, else a car pack's, else the game's. FH2MP's online copy is recognised and never built over.
  • The platform's copies carry PRAGMA application_id = 0x46483244 ("FH2D"). Never ship the platform's built copy, and never tell players to delete mediaoverride\Stripped\gamedbRC.slt. A database you ship yourself must start from the game's original, or set application_id = 0.
  • Mods that add cars by their own Id use 9000 and up; 3000-8999 belong to car packs.
  • If your mod reads SQLite itself, compile SQLite in (Wine has no winsqlite3.dll).

A 2.9.0 database guard stops a crash when a car's PowertrainID isn't in Powertrains (stock Ids 0-7): the car is listed without a drivetrain and a red "Game database" row appears. Fix the data anyway.

Interfaces between mods

A mod can offer a struct of function pointers to other mods by name:

// mymod_thing.h, shipped for other mods
typedef struct MyModThing {
    uint32_t size;               // first member: sizeof(MyModThing)
    int (*count)(void);          // never change or remove; add new members at the end, bump the version
} MyModThing;

// publisher, in fh2mod_init
static int thing_count() { return 42; }
static const MyModThing g_thing = {sizeof(MyModThing), thing_count};   // must live for the whole process
api->publish_interface(g_mod, "MyMod.Thing", 1, &g_thing);

// consumer, on its own thread
if (api->wait_for_mods(30000)) {
    auto* t = static_cast<const MyModThing*>(api->get_interface("MyMod.Thing", 1));
    if (t && t->size >= sizeof(MyModThing)) { /* use t->count() */ } else { /* carry on without it */ }
}
  • Name it Mod.Thing. The first publisher owns the name; publishing NULL withdraws it.
  • Start the struct with a size member; only add members at the end and bump the version.
  • get_interface(name, min_version) returns NULL if nothing at least that version is published. Mods start alphabetically, so ask after wait_for_mods. The platform's own interfaces (FH2Platform.HudLayer, FH2Platform.PadLayer, FH2Platform.Online) exist from fh2mod_init.
  • mod_version(name) tells you another mod's registered version.

A real one: FH2 Universal Radio publishes FH2UniversalRadio.NowPlaying (include/fh2universalradio.h in its repo).

Hooks and byte patches

The platform has MinHook built in and chains every mod's hooks, so several mods can hook the same function. This is a summary; the full guide to safe hooking is 05-hooking.md.

CallAPIHooks
hook_function(mod, name, target, detour, &original)3a function's start (inline)
hook_call(mod, name, call_site, detour, &original)3one E8 CALL or E9 JMP rel32, only that call
hook_pointer(mod, name, slot, detour, &original)3a vtable slot, table entry or import (8-byte aligned)
patch_bytes(mod, name, at, expect, bytes, size)71-32 bytes, restored when disabled
hook_instruction(mod, name, at, fn, user)7calls fn(FH2Context*, user) before one instruction; change any register but rsp
enable_hooks(mod, h) / disable_hooks(mod, h)3one hook, or all yours with NULL
  • Hooks are created off. Set up all your state, then enable_hooks: detours run on many threads.
  • *original is always safe to call. The most recently enabled hook runs first and its original leads to the next mod's: pass through so other mods keep working.
  • The platform compares the bytes with the exe on disk and refuses a hook on changed bytes (Extra Options' patches, a self-patching mod) or a partial overlap with another mod (logged with its name).
  • Byte-check every hook and direct call yourself too (_BYTES in fh2game.h).
  • Hooks outside the game (Azimuth, Windows DLLs) don't need wait_for_code.

The log names each hook, for example [MyMod] hooked function game+0x1997740 (FMOD::System::createSound).

Settings rows

Rows appear on your mod's own page: Pause > MODS > YOUR MODS > your mod (Pause > Settings > MODS opens the same list from 2.9.0). Add them in fh2mod_init:

static void changed(void*, const char* key, int value) {
    WritePrivateProfileStringA("MyMod", key, value ? "1" : "0", g_ini.c_str());
    if (std::strcmp(key, "Sparks") == 0) g_sparks = value;   // takes effect at once
}

// in fh2mod_init, after register_mod:
if (api->api_version >= 4) {
    FH2Setting s{sizeof s};
    s.key = "Sparks"; s.label = "Sparks"; s.description = "Sparks fly when you scrape a wall.";
    s.value = g_sparks; s.on_change = changed;
    api->add_setting(mod, &s);
}

Your mod owns the value. The platform stores nothing: save it from on_change and pass it back in next launch.

KindAPIFieldsValue shown
FH2_SETTING_ON_OFF (0)4value 0/1On / Off
FH2_SETTING_SLIDER (1)5min, max, step (0 = 1/100 of range), slider_value, display_scale, decimals (0-3), on_slidea slider
FH2_SETTING_LINK (2)6url (http/https)"Browser"
FH2_SETTING_CHOICE (3)9choices, choice_count (2-100 from 2.9.1; 32 up to 2.9.0)the choice; over 8 choices, A opens a pick list
  • A newer kind on an older platform would show as On/Off: add sliders from API 5, links from 6, choices from 9 (an older platform refuses more than 32 choices).
  • needs_restart = 1 adds "Takes effect the next time you start the game." and, when the player leaves YOUR MODS with it changed, offers Restart now, Restart later or Go back.
  • Labels fit about 24 characters, without your mod's name. Put the main switch first: focus starts there.
  • set_setting / set_slider show a change you made (from a hotkey, say) without calling on_change; set_setting_text (API 10) changes a row's label, description or choices.

Below your rows the page lists hotkeys ("Keys and buttons"), links and pages, then "About " with "What it does", Load this mod, and with FH2MP installed Load when playing online.

Pages

API 8 lets a mod add pages of rows, or a page of its own XAML on a pause-menu tile.

static void on_open(void*, const char* page) {
    FH2PageRow rows[2]{};
    rows[0].size = sizeof rows[0]; rows[0].label = "Totals"; rows[0].style = FH2_ROW_HEADING;
    rows[1].size = sizeof rows[1]; rows[1].key = "trees"; rows[1].label = "Trees broken";
    rows[1].value = g_trees_text;
    g_api->set_page_rows(g_mod, page, rows, 2);
}

// in fh2mod_init
if (api->api_version >= 8) {
    FH2Page p{sizeof p};
    p.key = "Stats"; p.title = "Statistics"; p.description = "What you have broken so far.";
    p.on_open = on_open;
    api->add_page(mod, &p);
}
  • A row-page shows as an "Open" row on your mod's page. set_page_rows replaces the rows (up to 1,000) from any thread; styles are normal, dim and heading (orange), and value_alert makes a value red.
  • on_button gets A, B, X, Y, LB and RB and returns FH2_PAGE_IGNORED, HANDLED, HANDLED_SELECT or HANDLED_BACK.
  • Own-design pages (set_page_xaml) have 16 integer slots for bindings ({Binding FH2Mod_Slot_<n>}, converters FH2Mod_ShowIf, FH2Mod_ShowIfHidden, FH2Mod_HideIf). tile = "Achievements" puts a page on the Achievements tiles; one mod per tile, and the Achievements mod owns that one.
  • From 2.9.0 the platform checks your XAML first: every resource key must exist on every page or be your own, and every image must be a game texture or a file you set_file first. A page that crashed the game is left out next session until the DLL changes.
  • The game reads XAML one byte per character: write non-ASCII letters as lowercase-x hex references (&#xf3;). Decimal references show as a space, UTF-8 as two wrong letters.
  • Extra Options rewrites some pages it recognises by their exact x:Class text. On a page of your own, write x:Class = with a space before the = (see 03-extra-options.md).

The Achievements mod's src/ui.cpp is a full working own-design page. XAML and the UI files are covered in 04-game-data.md.

Page texts (API 11). add_page_text(mod, "MyMod_Tag", get, user) gives game pages a text binding, {Binding FH2Mod_Text_MyMod_Tag}. set_file a copy of a game page that uses it; get fills the text on the UI thread and page_text_changed asks for a re-read. The first use is the name tag over other cars (UI\Scenes\Anthem\AR_OpponentLabel.xaml, one page object per car). The game keeps every distinct text for the session, so use at most 256 per name: a fixed list of phrases, not a clock.

Title-screen entries

API 9 adds lines with a button under "PRESS (A) TO START". Four buttons are shared by all mods (Y, X, RB, LB in the order they are added).

static int on_press(void*, const char*) {
    g_free_roam_start = 1;
    return FH2_TITLE_START;       // the platform presses A for the player
}

if (api->api_version >= 9) {
    FH2TitleEntry e{sizeof e};
    e.key = "QuickStart"; e.label = "QUICK START"; e.on_press = on_press;
    api->add_title_entry(mod, &e);
}
  • Return FH2_TITLE_HANDLED to stay on the title screen.
  • An entry with choices (up to 100, shown 8 a page past 10) opens a list; on_choose gets the pick.
  • Labels are shown in capitals, about 24 characters; they're cut at 32.
  • title_started_by(mod) later tells you which of your entries started the game.

Hotkeys and commands

Hotkeys (API 9) give the player rebindable keys and controller chords, shown on your mod's page under "Keys and buttons":

static void on_photo(void*, const char*) { g_take_photo = 1; }   // hotkey thread: keep it short

FH2Hotkey h{sizeof h};
h.key = "Photo"; h.label = "Take photo";
h.vk = VK_F9;                                 // 0 = no key
h.pad_chord = FH2_PAD_LB | FH2_PAD_RB | FH2_PAD_Y;
h.on_press = on_photo;
h.on_rebind = on_rebind;                      // save the new binding in your ini
api->add_hotkey(mod, &h);

The platform polls the keyboard and XInput every 15 ms while Azimuth's window has focus; the game still gets the keys. It doesn't store bindings: save them in on_rebind and pass them in next launch. Each hotkey gets two choice rows, one for the key (Off, F1-F12, Ctrl+F1-F12, or yours) and one for the controller (Off, LB+RB with a face button or d-pad direction, or yours). Which pad buttons are free in game is in 08-hooks-ui-camera-input.md.

Commands (API 9) let a tool outside the game talk to your mod over a named pipe:

static void stats(void*, const char*, const char* args, char* reply, size_t size) {
    std::snprintf(reply, size, "trees %d", g_trees);       // start with "error: " to fail
}
api->add_command(mod, "stats", "Show counters.", stats, nullptr);

Then fh2mod MyMod stats (or fh2mod list, fh2mod --pid 1234 MyMod stats) with fh2mod.exe from the platform zip's tools folder. The pipe (\\.\pipe\fh2mod-<pid>) starts with the first command added, refuses remote clients and is open only to the game's Windows user. Replies are up to 16 KB.

Sessions, logs, crash dumps and save snapshots

CallAPIDoes
session_id()920261021-203224-1234 (start time and process id), also on line 3 of platform.log
session_log_path(mod, L"MyMod", keep)9makes <Azimuth folder>\MyMod\logs\ and returns ...\<session>.log, deleting older logs beyond keep; you open the file
request_save_snapshot(mod, reason, keep)9from fh2mod_init: after all inits, copies the save folder once to fh2-mods\save-snapshots\<session>\
add_dump_memory(mod, p, n)9adds a heap range (1 B to 64 MB; 64 ranges across all mods) to every minidump

A save snapshot is a copy for safety; mods must never write to saves.

Crash reports are automatic (fh2-mods\crashes\, ten newest): the exception, the call stack as game+0x... / YourMod.dll+0x..., which mod the crash came from, and every hook in place. Minidumps include every loaded mod's globals; full in fh2-mods\platform-dump.txt gives full-memory dumps. platform-session.json says running or crashed, never "ended". Reading crashes: 13-troubleshooting.md.

Online play and offline_only

Online means FH2MP is installed, turned on, and has a session. A mod that changes driving or what others see should say so:

FH2ModInfo info{sizeof info, "MyMod", "1.2.0", "You/MyMod", FH2MOD_PLATFORM_VERSION, 1};
info.description  = "Fast & Furious style nitro.";
info.offline_only = 1;            // the boost would be a cheat online
g_mod = api->register_mod(&info);
if (!g_mod) return 0;             // online: nothing to do, and not reported as a problem
  • Online, register_mod returns NULL for an offline_only mod, and from the next online launch the DLL isn't loaded at all. Older platforms ignore the flag: set it anyway. The player's Load when playing online switch wins over your flag.
  • playing_online() can turn from 0 to 1 during a session (2.9.0, never back). Offline-only mods already running are then stopped: hooks off; text, SQL and files removed; pop-ups, hotkeys, commands, pad layers and title entries inert. Your own threads and interfaces keep running, so check playing_online() where it matters. Pre-platform mods can't be stopped.

FH2MP uses the platform's FH2Platform.Online interface to ask whether going online is safe. More in 12-online.md.

UI templates and the helper headers

From 2.9.0 the platform shows pop-ups, tips and message boxes in the game's own style.

#include "fh2mod_ui.h"
#include "fh2mod_l10n.h"

// in fh2mod_init
g_mod = api->register_mod(&info);
fh2_helpers_init(api, g_mod);
fh2ui_ui_uses(FH2_UI_USES_TOASTS | FH2_UI_USES_TIPS);

// a hotkey's on_press: a pop-up that answers it, or a sound and a log line
static void on_snapshot(void*, const char*) {
    FH2Toast t{};
    t.size  = sizeof t;
    t.key   = "Snapshot";             // a second press replaces it while it waits
    t.title = FH2_TR(FH2_API, FH2_MOD, "toast.snapshot", "Snapshot written");
    t.icon  = FH2_ICON_PHOTO;
    t.flags = FH2_TOAST_FLAG_REPLY;
    if (!fh2ui_show_toast(&t)) {      // off, or an older platform
        fh2ui_play_ui_sound(FH2_SOUND_SELECT);
        FH2_API->log(FH2_MOD, "Snapshot written (no pop-up shown).");
    }
}
  • Declare what you use with ui_uses in fh2mod_init. The platform hooks the game's notification only in a session where some mod declared pop-ups or tips; otherwise show_toast and show_tip return 0.
  • Toasts: title (28 characters), subtitle (45), icon, sound. One queue for all mods with a 5 s gap, up to 4 waiting per mod; they wait through menus, replays and loading. Non-ASCII is folded to plain letters.
  • Tips: one per mod per session, after some driving; the seen state is kept for you.
  • Message boxes: only from your page, setting or title callbacks; up to 99 choices plus Back.
  • Page help and hints (set_page_help, set_page_hints, show_page_hint) and sounds (play_ui_sound: select, back, open, close, error, notify, ticks, shutter).
  • ui_status(mod) says whether pop-ups can show, whether the player turned them off, and whether the keyboard or controller was used last.

fh2mod_ui.h wraps each member as fh2ui_<member> without the api and mod arguments, returning 0 on older platforms. Call fh2_helpers_init(api, mod) once after register_mod; in C, define FH2_HELPERS_IMPLEMENTATION in one .c file.

Don't hook the game's notification code yourself (Show, MakeDisplayString, the notification constructor and destructor, the achievements tick): the platform chains those sites with the Achievements mod. Players control pop-ups on the platform's own page at the end of YOUR MODS and on each mod's Pop-ups row. [popups] Developer=1 in fh2-mods\platform-popups.ini adds a test page.

Localisation

API 10 lets a mod ship translations inside its DLL as gettext PO files.

#include "fh2mod_l10n.h"
#include "mymod_l10n.inc"    // built by po2inc.py: mymod_translations[]

g_mod = api->register_mod(&info);
FH2_ADD_TRANSLATIONS(api, g_mod, mymod_translations);   // right after register_mod

s.label = FH2_TR(api, g_mod, "row.Sparks.label", "Sparks");
api->set_string_tr(g_mod, "LoadingMessages.str", 0x6875, "loading.fasttravel", L"Fast Traveling (with MyMod)");

The workflow:

  1. Write English with a key: FH2_TR(api, mod, key, english), FH2_TR_PLURAL(...), FH2_TR_DESCRIPTION("..."). Key and English must be plain string literals.
  2. tools/l10n/extract.py --domain MyMod src makes l10n/MyMod.pot, with notes (// L10N: above the line) and length limits (// L10N(max=24):).
  3. Translators make l10n/<lang>.po with Poedit or Weblate.
  4. tools/l10n/po2inc.py src/mymod_l10n.inc mymod_translations l10n/*.po builds them into the DLL. Both scripts take --check for CI.
  • tr() text passed through as-is (rows, pages, title entries, notices) follows the game's language by itself; text you build from it doesn't, so rebuild it in on_open.
  • Lookup goes language, then parent (pt-BR to pt, es-MX to es-ES to es), then English. A translation made from different English isn't used: keep the key when you reword. Use placeholders ({count}), never glued sentences.
  • language() gives a BCP-47 tag (pl, pt-BR); game_language() the game's code (PL, BR). format_number and format_date follow each language's style.
  • test=1 in fh2-mods\platform-language.ini gives a padded pseudo-language for layout tests; a translator can drop fh2-mods\lang\<Mod name>\<lang>.po to override yours.
  • Game fonts cover the Latin languages the game ships, Polish, Czech and Hungarian; Cyrillic only when the game runs in Russian; Chinese, Japanese and Korean only the characters the game itself uses.

Length guides (characters): row label 30, description 450, choice 12, pop-up title 28, title entry 24, notice line 40.

Car packs

From 2.9.0 the platform adds new Autoshow cars from car packs: each pack is a folder in <Azimuth folder>\fh2-cars\<pack>\, with no installer and nothing written to the game folder.

fh2-cars\<pack>\
  pack.ini                                          name, version, author, and the cars
  <name>.sql                                        database changes, run in file-name order
  <car>.part-ids.txt                                where the carbin names its own part rows
  media\cars\<car>.zip                              model and data, as the game's own
  media\Stripped\RC1\Thumbnail_<car>_Big.swatchbin  (816x459)
  media\Stripped\RC1\Thumbnail_<car>_Small.swatchbin (192x108)
  • pack.ini is UTF-8 without a BOM: [pack] name=, version=, author= and one [car <MediaName>] name=, id= per car.
  • In the SQL, write {car:<media name>} wherever the car's Id goes, never a number; part rows are {car:X} * 1000 + n. Ids (3000-8999) are given once and kept for good.
  • Packs need Azimuth 1.0 or later. They work with or without Extra Options (Extra Options 0.6.0 tested, with EnableMediaOverrides=1). In a fresh Azimuth folder they show from the second start.
  • A pack is left out, with a reason in the log and on the MODS tab, when its car is already in the database, another pack adds the same car, its Ids are taken, or its SQL fails.
  • If a car the save knows goes missing, the platform copies the saves to fh2-mods\save-snapshots\car-packs-<session>\ first and shows a title-screen line and a red row.
  • Packs are off online.

The car data itself (rows a new car needs, zips, zipmanifest.xml, thumbnails) is in 04-game-data.md; docs/car-packs.md in the platform repo is the full reference.

HUD layer

The HUD layer (an interface, not an API version) lets a mod draw on the free-roam HUD with the game's own look: a bottom bar with tabs and prompts, chips, a tip card, a panel, a countdown, a shared feed of lines over the minimap, and (version 3) a canvas of your own XAML bound to numbers and texts.

#include "fh2mod_hud.h"

static const FH2HudInterface* g_hud;

// in fh2mod_init
g_hud = static_cast<const FH2HudInterface*>(api->get_interface(FH2_HUD_INTERFACE, 2));
if (g_hud) {
    FH2HudLayer l{sizeof l};
    l.parts = FH2_HUD_PART_FEED;
    if (!g_hud->add_hud_layer(g_mod, &l)) g_hud = nullptr;
}

// later, any thread
if (g_hud && (g_hud->hud_status(g_mod) & FH2_HUD_AVAILABLE)) {
    FH2HudFeedLine line{sizeof line};
    line.text = "Checkpoint saved"; line.style = FH2_HUD_FEED_GREEN;
    g_hud->post_hud_feed(g_mod, &line);
}
  • Detect it by the interface and its version (2 = 2.9.0 with the feed, 3 = 2.9.1 with the canvas), not by api_version. Before drawing, check all three: interface not NULL, add_hud_layer returned 1, hud_status has FH2_HUD_AVAILABLE.
  • One layer per mod, four across mods, one on screen at a time (the newest show_hud_layer wins). hold_game_hud hides the game's own HUD.
  • Every layer has a lease (lease_ms, default 5 s): if your mod stops calling while shown, the layer hides and the game's HUD comes back.
  • It runs on the UI thread; keep updates small (24 values a frame, text changes up to 10 a second).

Limits, parts and the canvas rules: docs/hud-layer-preview.md and include/fh2mod_hud.h. Director Mode and Do A Barrel Roll use it.

Pad layer

The pad layer lets a mod take controller buttons cleanly: while a modifier (say LB) is held, the buttons it takes are removed from what the game sees.

#include "fh2mod_pad.h"

static void on_pad(void*, const char*, uint32_t button) { g_last_button = button; }

// in fh2mod_init
auto* pad = static_cast<const FH2PadInterface*>(api->get_interface(FH2_PAD_INTERFACE, 1));
if (pad) {
    FH2PadLayer l{sizeof l};
    l.key = "Menu";
    l.modifier = FH2_PAD_LB;
    l.buttons = FH2_PAD_DPAD_UP | FH2_PAD_DPAD_DOWN | FH2_PAD_DPAD_LEFT | FH2_PAD_DPAD_RIGHT;
    l.flags = pad->version >= 2 ? FH2_PAD_LAYER_WORLD : 0;   // version 1 refuses any flag
    l.on_press = on_pad;
    pad->add_layer(g_mod, &l);
}
  • Up to 16 layers; two that could be open together and share a button clash, and the second is refused.
  • The modifier always reaches the game. LB is the clutch for manual-with-clutch players: offer a choice (set_modifier). Take all four d-pad directions together: the radio reads the d-pad as one control.
  • Version 2 adds FH2_PAD_LAYER_WORLD (only while the free-roam HUD shows) and FH2_PAD_LAYER_LATCH (no modifier; set_open opens it for 2 s at a time; never take Start in one).
  • buttons(&held) reads the held buttons from the game's own reading. More on the pad: 08-hooks-ui-camera-input.md.

Loaders

A DLL that hosts other mods (scripts, .NET mods, as Platform.NET does) calls register_mod for itself first, then once per hosted mod, all inside fh2mod_init. From 2.9.0 each hosted mod gets its own row, page, update check and Pop-ups row; online, each one's own offline_only decides. A mod registered after fh2mod_init returned works but isn't listed that session.

Reference

FH2ModApi starts with size, api_version (11 at 2.9.2), platform_version ("2.9.2"), azimuth_dir (the folder with azimuth.exe, no trailing slash) and game_dir (the game's Mount folder, game:\, or ""); both folders are const wchar_t*.

FH2ModInfo

MemberAPIMeaning
size1sizeof(FH2ModInfo)
name1display name, UTF-8: log prefix, notices, YOUR MODS
version1"x.y.z"
github_repo1"Owner/Repo" or NULL. The platform compares version with the latest published GitHub release at most every 6 hours and shows "Name x.y.z is out: Pause > MODS > UPDATES"
platform_version1pass FH2MOD_PLATFORM_VERSION; an older installed platform gives "Old FH2 Mod Platform: reinstall Name"
check_updates10 = never go online for this mod (give players a setting)
description6a sentence or two for YOUR MODS and "What it does"; translation key mod.description
offline_only9nonzero: don't run online

Named game addresses: fh2game.h

include/fh2game.h names game addresses that mods share, so two mods hooking the same thing use the same offset and check the same bytes. Each name is an RVA; most have a NAME_BYTES string of the bytes on disk for a check like this:

memcmp(game + FH2_GAME_FORZACAR_KIND, FH2_GAME_FORZACAR_KIND_BYTES,
       sizeof FH2_GAME_FORZACAR_KIND_BYTES - 1) == 0

Suffixes: _AT is an instruction (for hook_instruction or patch_bytes), _CALL a call instruction (for hook_call), _VTABLE a vtable (its bytes are slot 0 as mapped at 0x140000000); the rest are functions, or data without bytes. New names are added by pull request with the offset, meaning, bytes read from the exe on disk, and the mod that uses it. Most of these are described in full in 06-hooks-world.md and 08-hooks-ui-camera-input.md.

NameRVAAddressWhat it is
Cars
FH2_GAME_FORZACAR_VTABLEgame+0x2C5CB800x142C5CB80ForzaCar vtable; slot 0 is the deleting destructor
FH2_GAME_FORZACAR_KINDgame+0xF622800x140F62280int(car): 0 player, 1 Drivatar, 2 traffic, 3-5 the same in another player's game (car+0x4D08)
FH2_GAME_FORZACAR_REQUESTSgame+0xF605100x140F60510void*(car): the car's collidable request set (car+0x4C58)
FH2_GAME_FORZACAR_DTORgame+0x2893200x140289320~ForzaCar, before the memory is freed: drop per-car notes here
FH2_GAME_FORZACAR_UPDATEgame+0x2A94000x1402A9400vtable slot 0x80: per-frame update
FH2_GAME_FORZACAR_APPLY_COLLIDABLEgame+0x28D9300x14028D930vtable slot 0x130: works out the car's alpha and hands it to presentation
FH2_GAME_FORZACAR_ALPHAgame+0x28C5900x14028C590float(self, ForzaCar**): alpha from the newest request, or distance fade
FH2_GAME_FORZACAR_SHOULD_START_GRIEFINGgame+0x28D3500x14028D350bool(car, float dt): the online anti-griefing rule that ghosts the local car
FH2_GAME_COLLIDABLE_REQUESTS_MAKEgame+0xF5B4200x140F5B420makes a request handle from a preset name
FH2_GAME_COLLIDABLE_REQUESTS_ADDgame+0xF730800x140F73080registers a request (takes the handle)
FH2_GAME_COLLIDABLE_REQUESTS_REMOVEgame+0xF5B8900x140F5B890removes a request by preset name
FH2_GAME_CAR_HIDEgame+0xF649F00x140F649F0HideCar; called by the request set when alpha reaches 0
Entity events
FH2_GAME_ENTITY_SEND_EVENTgame+0x190BF900x14190BF90queues an event on an entity
FH2_GAME_ENTITY_SEND_EVENT_DATAgame+0x190BFD00x14190BFD0the same with data
FH2_GAME_EVENT_SPEED_ZONE_ACTIVATEDgame+0x34BFF200x1434BFF20event symbol (global), sent by the speed camera with data
FH2_GAME_EVENT_SPEED_ZONE_COMPLETEDgame+0x34BFB100x1434BFB10event symbol: speed zone completed
FH2_GAME_EVENT_SPEED_ZONE_ABORTEDgame+0x34BFDB80x1434BFDB8event symbol: speed zone aborted
FH2_GAME_EVENT_SPEED_TRAP_ACTIVATEDgame+0x34BFDD80x1434BFDD8event symbol: speed trap passed, with data
Collision and the world
FH2_GAME_COLLISIONWORLD_GETPOLYSgame+0x12CC7300x1412CC730CollisionWorld::GetPolys: triangles a query box touches (WreckingBall's solid pylons)
FH2_GAME_COLLISION_TEMPLATE_QUERYgame+0x12CC1A00x1412CC1A0collision template grid query
FH2_GAME_COLLISION_INSTANCE_TEMPLATE_LOADgame+0x12B25000x1412B2500makes a collision instance's template available
FH2_GAME_COLLISION_DEFINITIONgame+0x12CC0100x1412CC010a definition by index (leaf, no unwind info)
FH2_GAME_COLLISION_DEFINITION_MODELgame+0x12CD3000x1412CD300a definition's model by index (leaf)
FH2_GAME_COLLISIONTEMPLATERESOURCE_VTABLEgame+0x2EB43C00x142EB43C0StreamedPhysics::CollisionTemplateResource vtable
FH2_GAME_WORLDCOLLOBJMAN_ADD_CELLgame+0x36A3300x14036A330CWorldCollObjMan::AddCell: a streamed cell's objects arrive
FH2_GAME_WORLDCOLLOBJMAN_SPAWN_CELLgame+0x368D900x140368D90CWorldCollObjMan::SpawnCell
FH2_GAME_WORLDCOLLOBJMAN_MAKE_DYNAMICgame+0x368C600x140368C60CWorldCollObjMan::MakeDynamic: a static object becomes loose
FH2_GAME_WORLDCOLLOBJMAN_BREAK_INTO_PIECESgame+0x36AC800x14036AC80CWorldCollObjMan::BreakIntoPieces
FH2_GAME_WORLDCOLLOBJMAN_BREAK_MODEL_ATgame+0x36AEAC0x14036AEACinstruction in BreakIntoPieces where the loose copy's model is picked
FH2_GAME_WORLDCOLLOBJMAN_UPDATEgame+0x384C000x140384C00CWorldCollObjMan update
FH2_GAME_WORLDCOLLOBJMAN_SHUTDOWNgame+0x382F200x140382F20shutdown (vtable slot 1, and from the destructor)
FH2_GAME_WORLDCOLLOBJMAN_RECYCLE_SLOTgame+0x37A7D00x14037A7D0takes a slot for a new loose object, recycling the farthest loose piece
FH2_GAME_WORLDCOLLOBJ_VTABLEgame+0x2C6A2080x142C6A208CWorldCollObj vtable; slot 0 is OnCollision
FH2_GAME_TRACKPRESENTATION11_DTORgame+0x1377B500x141377B50TrackPresentation11 destructor: the world is going away
FH2_GAME_PRESENTATION11_RENDER_NODE_UPDATEgame+0x13A41E00x1413A41E0render node update
Procedural models (trees, bushes)
FH2_GAME_PROCEDURALMODELSDATA_SERIALIZEgame+0x1871B900x141871B90ProceduralModelsData::Serialize: procedural trees load
FH2_GAME_PROCEDURAL_GROUPS_RESIZEgame+0x1881EC00x141881EC0vector<Group>::resize
FH2_GAME_PROCEDURAL_DECODE_INSTANCEgame+0x18746000x141874600decodes one procedural instance
FH2_GAME_PROCEDURALMODELS_VTABLEgame+0x2F5A3000x142F5A300Procedural::ProceduralModels vtable
Skills
FH2_GAME_SKILL_DESTRUCTION_VTABLEgame+0x2D4BBF00x142D4BBF0Destruction skill vtable (its Load slot is hooked by WreckingBall)
FH2_GAME_SKILL_LUMBERJACK_VTABLEgame+0x2D4BA280x142D4BA28Lumberjack skill vtable
FH2_GAME_SKILL_SIDESWIPE_VTABLEgame+0x2D4B2700x142D4B270Sideswipe skill vtable
Achievements and HUD notifications
FH2_GAME_IMPORT_ETXEVENTWRITEgame+0x1DD00600x141DD0060the telemetry EtxEventWrite import slot; Azimuth fills it, so no bytes
FH2_GAME_SETSTAT_ATgame+0x2F79770x1402F7977instruction in SetStat with the new value in registers
FH2_GAME_HUD_NOTIFICATION_CTOR_ATgame+0x73E0B10x14073E0B1instruction in the HUD notification constructor; shared by the platform and Achievements: use show_toast
FH2_GAME_HUD_NOTIFICATION_DTOR_ATgame+0x73F0460x14073F046the same in the destructor; shared
FH2_GAME_ACHIEVEMENTSMODULE_TICK_ATgame+0x3FCD840x1403FCD84instruction in the achievements tick; shared by the platform's pop-ups, the HUD layer and Achievements
FH2_GAME_MAKE_DISPLAY_STRINGgame+0x3233100x140323310MakeDisplayString; call it, don't patch its first 16 bytes
FH2_GAME_SHOW_NOTIFICATIONgame+0x7553300x140755330shows a HUD notification; call it, don't patch its first 16 bytes; new mods use show_toast
Radio (FMOD)
FH2_GAME_RADIOSTREAMFMOD_LOAD_CREATESOUND_CALLgame+0x1018A130x141018A13the call to System::createSound in RadioStreamFmod::load (FH2 Universal Radio, hook_call)
FH2_GAME_RADIOSTREAMFMOD_START_GETSUBSOUND_CALLgame+0x10221F20x1410221F2the call to Sound::getSubSound in RadioStreamFmod::start (hook_call)
The game's runtime
FH2_GAME_OPERATOR_NEWgame+0x3229C00x1403229C0the game's operator new; its heap uses the game's TLS, so only game threads can call it
FH2_GAME_OPERATOR_DELETEgame+0x31C7B00x14031C7B0the game's operator delete
FH2_GAME_RANDgame+0x12592000x141259200calls the C runtime's rand
Free-roam HUD
FH2_GAME_HUD_VTABLEgame+0x2DEF9C80x142DEF9C8Hud page vtable; +0x488 shown, +0x4F8 hidden
FH2_GAME_HUD_SHOWNgame+0xD38DD00x140D38DD0HUD page shown (sets page+0x410 = 1)
FH2_GAME_HUD_HIDDENgame+0xD415400x140D41540HUD page hidden (sets page+0x410 = 0)
FH2_GAME_HUD_SUSPENDgame+0x78B0F00x14078B0F0suspends the game HUD (HUDModule); behind hold_game_hud
FH2_GAME_HUD_SUSPEND_ARgame+0x78B1A00x14078B1A0the same for HUDModuleAR
FH2_GAME_HUD_RESUMEgame+0x785CD00x140785CD0resumes either HUD module
FH2_GAME_AVUI_ALLOCgame+0x14424E00x1414424E0allocates an AVUI (UI framework) object
FH2_GAME_AVUI_STRING_WIDEgame+0x16633400x141663340makes an AVUI String from wchar_t*
FH2_GAME_AVUI_PROPERTY_CHANGEDgame+0xCF9C600x140CF9C60raises PropertyChanged on a UI object
Text
FH2_GAME_STRING_TABLESgame+0x36629900x143662990pointer to the string-table manager; +0x30 holds the language code ("EN", "br"); game_language() reads it

Rules every mod must follow

A checklist; each point is explained in the sections above.

  • fh2mod_init returns 0, always. register_mod first, keep it quick, slow work on your own thread.
  • Strings, settings, pages, title entries, hotkeys, translations and first SQL inside fh2mod_init.
  • wait_for_* only from your own thread; check the returned base for NULL.
  • Hook only after wait_for_code, or Extra Options refuses all its patches.
  • Byte-check every hook, patch and direct call; on a mismatch turn that feature off with a log line. A wrong guess should be a missing feature, not a crash.
  • Set up state before enable_hooks; pass through to original; no MinHook or raw patches of your own.
  • Game memory is reused as areas stream: drop per-object notes when the object goes.
  • Keep objects with destructors (locks, strings) out of functions with __try/__except; clang only protects calls made inside __try, so do risky reads in a called helper.
  • Guard every call newer than API 1 with api_version or FH2_API_HAS.
  • UI callbacks stay short and never call into the game.
  • Database: add_sql with UPDATE/INSERT only. Never set_file a platform-owned file; never edit the game's zips; never write to saves.
  • No data files in fh2-mods (every .dll there is loaded); use <Azimuth folder>\MyMod\.
  • Make features switchable and undo them when off (clear_strings, clear_file, clear_sql, disable_hooks). Log what you change, in plain sentences.
  • Set offline_only for anything that would be a cheat or look wrong online.
  • Ask other authors before taking a shared resource: the HUD layer screen, a title button, a tile, a pad button.

Sites and files the platform owns

Game sites: never hook, patch or check in memory

The platform hooks these (some only when a feature is in use). A mod that hooks or patches them breaks the MODS tab, pop-ups or the HUD layer for everyone.

SiteAddressWhatKindIn since
game+0x157FF600x14157FF60AVUI::Type::FindPropertyfunction2.3.0
game+0xDC8A600x140DC8A60Settings page wiring its tiles (calls game+0xD9FC10, HUD tile game+0xDC6C40)function2.3.0
game+0xB3A3E00x140B3A3E0HUD options page's scene record (factory game+0xB0B990)function2.3.0
game+0x2DF06C0, game+0x2DF07B00x142DF06C0, 0x142DF07B0HUD options page vtable +0x488 (loaded), +0x578 (buttons)pointer2.5.0
game+0xDC6E300x140DC6E30pause menu wiring its tiles (calls game+0xD9F9F0)function2.5.0
game+0xDBD720, 0xDBDD00, 0xDBDD60, 0xDBFE400x140DBD720 ...Marketplace tab tile handlersfunction2.5.0
game+0xDDACAD, 0xDDAE1F, 0xDDB2F5, 0xDDB910, 0xDDBB3E0x140DDACAD ...code that hides the Marketplace tabbyte patch2.5.0
game+0xDBD635, game+0xDBF1850x140DBD635, 0x140DBF185the Achievements tiles' calls (when a mod page takes the tile)call2.7.0
game+0x2E539400x142E53940title-screen buttons (Splash vtable +0x578)pointer2.8.0
game+0x2DEFE50, game+0x2DEFEC0, game+0x2DEF9C80x142DEFE50, 0x142DEFEC0, 0x142DEF9C8Hud vtable: shown, hidden, destructorpointer2.5.0 / 2.9.0
game+0x2E6EF280x142E6EF28file system resolver slot (without Extra Options, or with car packs)slot2.7.3
game+0x3FCD840x1403FCD84achievements tick (shared: chain with hook_instruction)instruction2.9.0
game+0x73E0B1, game+0x73F0460x14073E0B1, 0x14073F046HUD notification constructor and destructor (shared)instruction2.9.0
game+0x75542C, game+0x7555A5, game+0x750FB10x14075542C, 0x1407555A5, 0x140750FB1the three calls of the minor-notification gate game+0x754920call2.9.0
game+0x10768D00x1410768D0controller manager, after each frame's reading (pad layer)function2.9.0
game+0xB99CA0, game+0xB99D740x140B99CA0, 0x140B99D74DriveTrainConverter's type checks (database guard)instruction2.9.0
game+0xDC6F290x140DC6F29pause menu call that makes its navigation grid (Exit Game tile)call2.9.0
game+0x14000300x141400030navigation grid cell constructor (Exit Game tile)function2.9.0

The platform also calls game+0xD9FC10, game+0xDC6C40, game+0xB0B990, game+0xD9F9F0 and game+0x754920: leave their bytes alone too. Instruction hooks at the same address chain, so the three shared Achievements sites work with hook_instruction; but new mods should use show_toast instead.

Code released mods check in memory

Some released mods check game bytes in memory with no fallback to the exe on disk, so patching near them turns those mods off: Achievements 1.0.x (Show and MakeDisplayString, 15 bytes each), FH2MP 1.2.0 (MakeDisplayString and about 85 other places), WreckingBall up to 1.3.0, CCBR 1.0.0 and FH2 Universal Radio up to 1.7.1. The full list is in 05-hooking.md. Call Show and MakeDisplayString; never hook them.

Files: never set_file these

From 2.9.0 set_file refuses them in any spelling, case or slash direction. Before 2.9.0, the first mod to set one took the MODS tab away from everyone.

File (under media\UI.zip or media\stateflow.zip)Used for
UI\Scenes\Anthem\A_Hud.xamlHUD notices and the HUD layer
UI\Scenes\Anthem\A_Splash.xamltitle-screen entries and notices
UI\Scenes\Anthem\A_PauseMenu.xamlthe MODS tab
UI\Scenes\Anthem\A_PauseOptions.xamlthe Settings > MODS tile
UI\Scenes\Anthem\A_ModOptions.xamlthe stand-in list
UI\Scenes\Anthem\A_ModPage_NN.xaml (any NN)the MODS pages and mods' tile pages
stateflow\pause.xml, stateflow\ui_screens.xmlpage flow for the MODS tab
zipmanifest.xmlwhile car packs with zips are in use

Other UI files, such as UI\Controls\HUDSpeedometerControl.xaml, are fair game, one owner each.

Releasing and packaging

Pin the platform. Before each release, bump the platform submodule to the latest platform release tag, rebuild, and update the lines in your README that name the platform version.

Every mod zip ships its own platform, and extracting a zip overwrites the copies already there. So an old pinned platform downgrades every player who installs your mod:

Shipping a platform older thanBreaks
2.7.1no database changes under Wine (no built-in SQLite)
2.7.2overwrites and loses other mods' game databases
2.7.3nothing reads mediaoverride without Extra Options
2.7.4Azimuth 1.0.3 doesn't load the platform at all
2.8.0title entries, hotkeys, commands and choice rows are gone
2.9.0every car pack's cars vanish, with no warning

A good release zip:

d3dcompiler_47.dll        the platform
DWrite.dll                the same file again, for Azimuth 1.0.3 and later
fh2-mods\MyMod.dll
MyMod\...                 your data, if any (not in fh2-mods)
LICENSE-MinHook.txt       MinHook is built into the platform (BSD 2-clause)
README.txt
  • Tell players where the settings are: "In game: Pause > MODS > YOUR MODS > MyMod (Pause > Settings > MODS opens the same list)."
  • Don't ship a file that holds players' settings where unzipping over an install would overwrite it.
  • Set github_repo and publish GitHub releases tagged x.y.z or vx.y.z, matching your version.
  • Test builds often keep the old version string: tell builds apart by hash.

Where the platform's own docs are wrong

As of v2.9.2:

  • fh2mod_init must always return 0. docs/writing-a-mod.md and examples/hello_mod show if (!g_mod) return 1;, and hello_mod also returns 1 on api_version < 1. Any non-zero return shows the red "Not working" row. A mod that turns itself off on purpose should log why and return 0. (The offline_only case is the one exception the platform forgives, but 0 is right there too.)
  • Car packs work with Extra Options. The README says car packs need "Azimuth 1.0 or later without Extra Options". That is stale: docs/car-packs.md and the 2.9.0 notes are right, and Extra Options 0.6.0 was tested.
  • Check base for NULL. The hook_pointer example in docs/api.md uses the result of wait_for_code(0xFFFFFFFFu) straight away. It returns NULL when Azimuth runs another game or another build; stop then.

Files the platform keeps

All in <Azimuth folder>\fh2-mods\: platform.log (and platform-logs\, one per session), platform-standby.log, platform-session.json, crashes\, platform-tables.txt / platform-files.txt / platform-db*.txt (what was written for the game, and where), platform-disabled.txt and platform-online.txt (the player's load choices), platform-seen.txt, platform-popups.ini, platform-language.ini, the car-pack records platform-car-ids.txt and platform-cars-missing.txt, and save-snapshots\.

“The FH2 Modding Guide” by Trinculo54 is licensed under CC BY 4.0; its code samples are under the MIT licence. This page is an unchanged copy (links point to this site) of 02-platform.md at commit bb10508; corrections belong in the original repository.