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.
| Azimuth | Loads |
|---|---|
| before 1.0.1 | d3dcompiler_47.dll only |
| 1.0.1 | both (one copy runs, see below) |
| 1.0.3 and later | DWrite.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.dllruns; - 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.dllput back by another mod's zip beats a newerDWrite.dllon 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:
- Find the game's
Mountfolder (honouringazimuth.exe --game=DIR), rewriteplatform.logand start a session. If Azimuth was started for another game, load nothing. - Title gate (2.9.0): when
azimuth.inilists 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 everyfh2mod_inithas returned (at most 2 minutes). - List
fh2-mods\*.dll, sorted by file name, and load each one the player hasn't turned off. A DLL without anfh2mod_initexport is a pre-platform mod: loaded later, once the game is known to be FH2, and it starts itself fromDllMain. - Call each
fh2mod_initin that order, one after another, inside SEH. - 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:
| Change | Made inside fh2mod_init | Made later |
|---|---|---|
set_string, replace_string, set_string_tr, set_notice | shows this session (written after all inits) | written by apply_strings, shows next launch |
add_sql | applied for you this session | apply_database writes it, shows next launch |
set_file | written at once; shows if the game hasn't read the file yet | same; most files are read once |
add_setting, add_page, add_title_entry, add_hotkey, add_page_text | shows this session | shows next launch, or refused |
add_translation, ui_uses, request_save_snapshot, HUD/pad add_layer | works | refused or too late to matter |
set_page_rows, set_setting, show_toast, hooks | any time | any time |
Waiting
| Call | Waits until | Returns | Notes |
|---|---|---|---|
wait_for_game(ms) | Azimuth has mapped the exe (the player pressed Play) | base or NULL | own thread only; 0xFFFFFFFF = forever |
wait_for_code(ms) | as above, plus Extra Options has finished patching | base or NULL | required before hooking game code; gives up waiting for Extra Options 20 s after mapping |
wait_for_mods(ms) | every fh2mod_init has returned | 1, or 0 | returns 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
| Callback | Thread |
|---|---|
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 get | the game's UI thread |
hotkey on_press | the platform's hotkey thread |
| command handlers | the platform's command thread |
pad layer on_press | a platform thread |
hook_instruction callback, detours | whichever 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_initlogsX: fh2mod_init returned Norcrashed (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.
| API | Platform | Adds |
|---|---|---|
| 1 | 2.0.0 | register_mod, log; string tables (set_string, replace_string, clear_strings, apply_strings); set_notice; game_base, wait_for_game |
| 2 | 2.1.0 | set_file, clear_file; add_sql, clear_sql, apply_database; publish_interface, get_interface, wait_for_mods, mod_version |
| 3 | 2.2.0 | hook_function, hook_call, hook_pointer, enable_hooks, disable_hooks, wait_for_code (MinHook built in) |
| 4 | 2.3.0 | settings rows: add_setting, get_setting, set_setting (On/Off, needs_restart) |
| 5 | 2.4.0 | sliders: get_slider, set_slider, FH2_SETTING_SLIDER |
| 6 | 2.5.0 | FH2ModInfo.description, link rows (FH2_SETTING_LINK), the MODS tab |
| 7 | 2.6.0 | patch_bytes, hook_instruction (registers including xmm0-15) |
| 8 | 2.7.0 | pages: add_page, set_page_rows, set_page_xaml, page slots, focus_page_element, tile text and colours |
| 9 | 2.8.0 | add_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 |
| 10 | 2.9.0 | game_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 |
| 11 | 2.9.1 | page 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.
| Call | Does |
|---|---|
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
UPDATEandINSERTonly. 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_initare applied for you; later,apply_databaserebuilds (seconds: use your own thread).clear_sql(mod)drops yours. - From 2.7.2 the base is another mod's database in
mediaoverride\Strippedif 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 deletemediaoverride\Stripped\gamedbRC.slt. A database you ship yourself must start from the game's original, or setapplication_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
sizemember; 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 afterwait_for_mods. The platform's own interfaces (FH2Platform.HudLayer,FH2Platform.PadLayer,FH2Platform.Online) exist fromfh2mod_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.
| Call | API | Hooks |
|---|---|---|
hook_function(mod, name, target, detour, &original) | 3 | a function's start (inline) |
hook_call(mod, name, call_site, detour, &original) | 3 | one E8 CALL or E9 JMP rel32, only that call |
hook_pointer(mod, name, slot, detour, &original) | 3 | a vtable slot, table entry or import (8-byte aligned) |
patch_bytes(mod, name, at, expect, bytes, size) | 7 | 1-32 bytes, restored when disabled |
hook_instruction(mod, name, at, fn, user) | 7 | calls fn(FH2Context*, user) before one instruction; change any register but rsp |
enable_hooks(mod, h) / disable_hooks(mod, h) | 3 | one hook, or all yours with NULL |
- Hooks are created off. Set up all your state, then
enable_hooks: detours run on many threads. *originalis always safe to call. The most recently enabled hook runs first and itsoriginalleads 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 (
_BYTESinfh2game.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.
| Kind | API | Fields | Value shown |
|---|---|---|---|
FH2_SETTING_ON_OFF (0) | 4 | value 0/1 | On / Off |
FH2_SETTING_SLIDER (1) | 5 | min, max, step (0 = 1/100 of range), slider_value, display_scale, decimals (0-3), on_slide | a slider |
FH2_SETTING_LINK (2) | 6 | url (http/https) | "Browser" |
FH2_SETTING_CHOICE (3) | 9 | choices, 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 = 1adds "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_slidershow a change you made (from a hotkey, say) without callingon_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_rowsreplaces the rows (up to 1,000) from any thread; styles are normal, dim and heading (orange), andvalue_alertmakes a value red. on_buttongets A, B, X, Y, LB and RB and returnsFH2_PAGE_IGNORED,HANDLED,HANDLED_SELECTorHANDLED_BACK.- Own-design pages (
set_page_xaml) have 16 integer slots for bindings ({Binding FH2Mod_Slot_<n>}, convertersFH2Mod_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_filefirst. 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
(
ó). Decimal references show as a space, UTF-8 as two wrong letters. - Extra Options rewrites some pages it recognises by their exact
x:Classtext. On a page of your own, writex: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_HANDLEDto stay on the title screen. - An entry with
choices(up to 100, shown 8 a page past 10) opens a list;on_choosegets 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
| Call | API | Does |
|---|---|---|
session_id() | 9 | 20261021-203224-1234 (start time and process id), also on line 3 of platform.log |
session_log_path(mod, L"MyMod", keep) | 9 | makes <Azimuth folder>\MyMod\logs\ and returns ...\<session>.log, deleting older logs beyond keep; you open the file |
request_save_snapshot(mod, reason, keep) | 9 | from fh2mod_init: after all inits, copies the save folder once to fh2-mods\save-snapshots\<session>\ |
add_dump_memory(mod, p, n) | 9 | adds 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_modreturns NULL for anoffline_onlymod, 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 checkplaying_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_usesinfh2mod_init. The platform hooks the game's notification only in a session where some mod declared pop-ups or tips; otherwiseshow_toastandshow_tipreturn 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:
- 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. tools/l10n/extract.py --domain MyMod srcmakesl10n/MyMod.pot, with notes (// L10N:above the line) and length limits (// L10N(max=24):).- Translators make
l10n/<lang>.powith Poedit or Weblate. tools/l10n/po2inc.py src/mymod_l10n.inc mymod_translations l10n/*.pobuilds them into the DLL. Both scripts take--checkfor 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 inon_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_numberandformat_datefollow each language's style.test=1infh2-mods\platform-language.inigives a padded pseudo-language for layout tests; a translator can dropfh2-mods\lang\<Mod name>\<lang>.poto 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.iniis 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 byapi_version. Before drawing, check all three: interface not NULL,add_hud_layerreturned 1,hud_statushasFH2_HUD_AVAILABLE. - One layer per mod, four across mods, one on screen at a time (the newest
show_hud_layerwins).hold_game_hudhides 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) andFH2_PAD_LAYER_LATCH(no modifier;set_openopens 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
| Member | API | Meaning |
|---|---|---|
size | 1 | sizeof(FH2ModInfo) |
name | 1 | display name, UTF-8: log prefix, notices, YOUR MODS |
version | 1 | "x.y.z" |
github_repo | 1 | "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_version | 1 | pass FH2MOD_PLATFORM_VERSION; an older installed platform gives "Old FH2 Mod Platform: reinstall Name" |
check_updates | 1 | 0 = never go online for this mod (give players a setting) |
description | 6 | a sentence or two for YOUR MODS and "What it does"; translation key mod.description |
offline_only | 9 | nonzero: 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.
| Name | RVA | Address | What it is |
|---|---|---|---|
| Cars | |||
FH2_GAME_FORZACAR_VTABLE | game+0x2C5CB80 | 0x142C5CB80 | ForzaCar vtable; slot 0 is the deleting destructor |
FH2_GAME_FORZACAR_KIND | game+0xF62280 | 0x140F62280 | int(car): 0 player, 1 Drivatar, 2 traffic, 3-5 the same in another player's game (car+0x4D08) |
FH2_GAME_FORZACAR_REQUESTS | game+0xF60510 | 0x140F60510 | void*(car): the car's collidable request set (car+0x4C58) |
FH2_GAME_FORZACAR_DTOR | game+0x289320 | 0x140289320 | ~ForzaCar, before the memory is freed: drop per-car notes here |
FH2_GAME_FORZACAR_UPDATE | game+0x2A9400 | 0x1402A9400 | vtable slot 0x80: per-frame update |
FH2_GAME_FORZACAR_APPLY_COLLIDABLE | game+0x28D930 | 0x14028D930 | vtable slot 0x130: works out the car's alpha and hands it to presentation |
FH2_GAME_FORZACAR_ALPHA | game+0x28C590 | 0x14028C590 | float(self, ForzaCar**): alpha from the newest request, or distance fade |
FH2_GAME_FORZACAR_SHOULD_START_GRIEFING | game+0x28D350 | 0x14028D350 | bool(car, float dt): the online anti-griefing rule that ghosts the local car |
FH2_GAME_COLLIDABLE_REQUESTS_MAKE | game+0xF5B420 | 0x140F5B420 | makes a request handle from a preset name |
FH2_GAME_COLLIDABLE_REQUESTS_ADD | game+0xF73080 | 0x140F73080 | registers a request (takes the handle) |
FH2_GAME_COLLIDABLE_REQUESTS_REMOVE | game+0xF5B890 | 0x140F5B890 | removes a request by preset name |
FH2_GAME_CAR_HIDE | game+0xF649F0 | 0x140F649F0 | HideCar; called by the request set when alpha reaches 0 |
| Entity events | |||
FH2_GAME_ENTITY_SEND_EVENT | game+0x190BF90 | 0x14190BF90 | queues an event on an entity |
FH2_GAME_ENTITY_SEND_EVENT_DATA | game+0x190BFD0 | 0x14190BFD0 | the same with data |
FH2_GAME_EVENT_SPEED_ZONE_ACTIVATED | game+0x34BFF20 | 0x1434BFF20 | event symbol (global), sent by the speed camera with data |
FH2_GAME_EVENT_SPEED_ZONE_COMPLETED | game+0x34BFB10 | 0x1434BFB10 | event symbol: speed zone completed |
FH2_GAME_EVENT_SPEED_ZONE_ABORTED | game+0x34BFDB8 | 0x1434BFDB8 | event symbol: speed zone aborted |
FH2_GAME_EVENT_SPEED_TRAP_ACTIVATED | game+0x34BFDD8 | 0x1434BFDD8 | event symbol: speed trap passed, with data |
| Collision and the world | |||
FH2_GAME_COLLISIONWORLD_GETPOLYS | game+0x12CC730 | 0x1412CC730 | CollisionWorld::GetPolys: triangles a query box touches (WreckingBall's solid pylons) |
FH2_GAME_COLLISION_TEMPLATE_QUERY | game+0x12CC1A0 | 0x1412CC1A0 | collision template grid query |
FH2_GAME_COLLISION_INSTANCE_TEMPLATE_LOAD | game+0x12B2500 | 0x1412B2500 | makes a collision instance's template available |
FH2_GAME_COLLISION_DEFINITION | game+0x12CC010 | 0x1412CC010 | a definition by index (leaf, no unwind info) |
FH2_GAME_COLLISION_DEFINITION_MODEL | game+0x12CD300 | 0x1412CD300 | a definition's model by index (leaf) |
FH2_GAME_COLLISIONTEMPLATERESOURCE_VTABLE | game+0x2EB43C0 | 0x142EB43C0 | StreamedPhysics::CollisionTemplateResource vtable |
FH2_GAME_WORLDCOLLOBJMAN_ADD_CELL | game+0x36A330 | 0x14036A330 | CWorldCollObjMan::AddCell: a streamed cell's objects arrive |
FH2_GAME_WORLDCOLLOBJMAN_SPAWN_CELL | game+0x368D90 | 0x140368D90 | CWorldCollObjMan::SpawnCell |
FH2_GAME_WORLDCOLLOBJMAN_MAKE_DYNAMIC | game+0x368C60 | 0x140368C60 | CWorldCollObjMan::MakeDynamic: a static object becomes loose |
FH2_GAME_WORLDCOLLOBJMAN_BREAK_INTO_PIECES | game+0x36AC80 | 0x14036AC80 | CWorldCollObjMan::BreakIntoPieces |
FH2_GAME_WORLDCOLLOBJMAN_BREAK_MODEL_AT | game+0x36AEAC | 0x14036AEAC | instruction in BreakIntoPieces where the loose copy's model is picked |
FH2_GAME_WORLDCOLLOBJMAN_UPDATE | game+0x384C00 | 0x140384C00 | CWorldCollObjMan update |
FH2_GAME_WORLDCOLLOBJMAN_SHUTDOWN | game+0x382F20 | 0x140382F20 | shutdown (vtable slot 1, and from the destructor) |
FH2_GAME_WORLDCOLLOBJMAN_RECYCLE_SLOT | game+0x37A7D0 | 0x14037A7D0 | takes a slot for a new loose object, recycling the farthest loose piece |
FH2_GAME_WORLDCOLLOBJ_VTABLE | game+0x2C6A208 | 0x142C6A208 | CWorldCollObj vtable; slot 0 is OnCollision |
FH2_GAME_TRACKPRESENTATION11_DTOR | game+0x1377B50 | 0x141377B50 | TrackPresentation11 destructor: the world is going away |
FH2_GAME_PRESENTATION11_RENDER_NODE_UPDATE | game+0x13A41E0 | 0x1413A41E0 | render node update |
| Procedural models (trees, bushes) | |||
FH2_GAME_PROCEDURALMODELSDATA_SERIALIZE | game+0x1871B90 | 0x141871B90 | ProceduralModelsData::Serialize: procedural trees load |
FH2_GAME_PROCEDURAL_GROUPS_RESIZE | game+0x1881EC0 | 0x141881EC0 | vector<Group>::resize |
FH2_GAME_PROCEDURAL_DECODE_INSTANCE | game+0x1874600 | 0x141874600 | decodes one procedural instance |
FH2_GAME_PROCEDURALMODELS_VTABLE | game+0x2F5A300 | 0x142F5A300 | Procedural::ProceduralModels vtable |
| Skills | |||
FH2_GAME_SKILL_DESTRUCTION_VTABLE | game+0x2D4BBF0 | 0x142D4BBF0 | Destruction skill vtable (its Load slot is hooked by WreckingBall) |
FH2_GAME_SKILL_LUMBERJACK_VTABLE | game+0x2D4BA28 | 0x142D4BA28 | Lumberjack skill vtable |
FH2_GAME_SKILL_SIDESWIPE_VTABLE | game+0x2D4B270 | 0x142D4B270 | Sideswipe skill vtable |
| Achievements and HUD notifications | |||
FH2_GAME_IMPORT_ETXEVENTWRITE | game+0x1DD0060 | 0x141DD0060 | the telemetry EtxEventWrite import slot; Azimuth fills it, so no bytes |
FH2_GAME_SETSTAT_AT | game+0x2F7977 | 0x1402F7977 | instruction in SetStat with the new value in registers |
FH2_GAME_HUD_NOTIFICATION_CTOR_AT | game+0x73E0B1 | 0x14073E0B1 | instruction in the HUD notification constructor; shared by the platform and Achievements: use show_toast |
FH2_GAME_HUD_NOTIFICATION_DTOR_AT | game+0x73F046 | 0x14073F046 | the same in the destructor; shared |
FH2_GAME_ACHIEVEMENTSMODULE_TICK_AT | game+0x3FCD84 | 0x1403FCD84 | instruction in the achievements tick; shared by the platform's pop-ups, the HUD layer and Achievements |
FH2_GAME_MAKE_DISPLAY_STRING | game+0x323310 | 0x140323310 | MakeDisplayString; call it, don't patch its first 16 bytes |
FH2_GAME_SHOW_NOTIFICATION | game+0x755330 | 0x140755330 | shows a HUD notification; call it, don't patch its first 16 bytes; new mods use show_toast |
| Radio (FMOD) | |||
FH2_GAME_RADIOSTREAMFMOD_LOAD_CREATESOUND_CALL | game+0x1018A13 | 0x141018A13 | the call to System::createSound in RadioStreamFmod::load (FH2 Universal Radio, hook_call) |
FH2_GAME_RADIOSTREAMFMOD_START_GETSUBSOUND_CALL | game+0x10221F2 | 0x1410221F2 | the call to Sound::getSubSound in RadioStreamFmod::start (hook_call) |
| The game's runtime | |||
FH2_GAME_OPERATOR_NEW | game+0x3229C0 | 0x1403229C0 | the game's operator new; its heap uses the game's TLS, so only game threads can call it |
FH2_GAME_OPERATOR_DELETE | game+0x31C7B0 | 0x14031C7B0 | the game's operator delete |
FH2_GAME_RAND | game+0x1259200 | 0x141259200 | calls the C runtime's rand |
| Free-roam HUD | |||
FH2_GAME_HUD_VTABLE | game+0x2DEF9C8 | 0x142DEF9C8 | Hud page vtable; +0x488 shown, +0x4F8 hidden |
FH2_GAME_HUD_SHOWN | game+0xD38DD0 | 0x140D38DD0 | HUD page shown (sets page+0x410 = 1) |
FH2_GAME_HUD_HIDDEN | game+0xD41540 | 0x140D41540 | HUD page hidden (sets page+0x410 = 0) |
FH2_GAME_HUD_SUSPEND | game+0x78B0F0 | 0x14078B0F0 | suspends the game HUD (HUDModule); behind hold_game_hud |
FH2_GAME_HUD_SUSPEND_AR | game+0x78B1A0 | 0x14078B1A0 | the same for HUDModuleAR |
FH2_GAME_HUD_RESUME | game+0x785CD0 | 0x140785CD0 | resumes either HUD module |
FH2_GAME_AVUI_ALLOC | game+0x14424E0 | 0x1414424E0 | allocates an AVUI (UI framework) object |
FH2_GAME_AVUI_STRING_WIDE | game+0x1663340 | 0x141663340 | makes an AVUI String from wchar_t* |
FH2_GAME_AVUI_PROPERTY_CHANGED | game+0xCF9C60 | 0x140CF9C60 | raises PropertyChanged on a UI object |
| Text | |||
FH2_GAME_STRING_TABLES | game+0x3662990 | 0x143662990 | pointer 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_initreturns 0, always.register_modfirst, 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 tooriginal; 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_versionorFH2_API_HAS. - UI callbacks stay short and never call into the game.
- Database:
add_sqlwithUPDATE/INSERTonly. Neverset_filea platform-owned file; never edit the game's zips; never write to saves. - No data files in
fh2-mods(every.dllthere 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_onlyfor 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.
| Site | Address | What | Kind | In since |
|---|---|---|---|---|
game+0x157FF60 | 0x14157FF60 | AVUI::Type::FindProperty | function | 2.3.0 |
game+0xDC8A60 | 0x140DC8A60 | Settings page wiring its tiles (calls game+0xD9FC10, HUD tile game+0xDC6C40) | function | 2.3.0 |
game+0xB3A3E0 | 0x140B3A3E0 | HUD options page's scene record (factory game+0xB0B990) | function | 2.3.0 |
game+0x2DF06C0, game+0x2DF07B0 | 0x142DF06C0, 0x142DF07B0 | HUD options page vtable +0x488 (loaded), +0x578 (buttons) | pointer | 2.5.0 |
game+0xDC6E30 | 0x140DC6E30 | pause menu wiring its tiles (calls game+0xD9F9F0) | function | 2.5.0 |
game+0xDBD720, 0xDBDD00, 0xDBDD60, 0xDBFE40 | 0x140DBD720 ... | Marketplace tab tile handlers | function | 2.5.0 |
game+0xDDACAD, 0xDDAE1F, 0xDDB2F5, 0xDDB910, 0xDDBB3E | 0x140DDACAD ... | code that hides the Marketplace tab | byte patch | 2.5.0 |
game+0xDBD635, game+0xDBF185 | 0x140DBD635, 0x140DBF185 | the Achievements tiles' calls (when a mod page takes the tile) | call | 2.7.0 |
game+0x2E53940 | 0x142E53940 | title-screen buttons (Splash vtable +0x578) | pointer | 2.8.0 |
game+0x2DEFE50, game+0x2DEFEC0, game+0x2DEF9C8 | 0x142DEFE50, 0x142DEFEC0, 0x142DEF9C8 | Hud vtable: shown, hidden, destructor | pointer | 2.5.0 / 2.9.0 |
game+0x2E6EF28 | 0x142E6EF28 | file system resolver slot (without Extra Options, or with car packs) | slot | 2.7.3 |
game+0x3FCD84 | 0x1403FCD84 | achievements tick (shared: chain with hook_instruction) | instruction | 2.9.0 |
game+0x73E0B1, game+0x73F046 | 0x14073E0B1, 0x14073F046 | HUD notification constructor and destructor (shared) | instruction | 2.9.0 |
game+0x75542C, game+0x7555A5, game+0x750FB1 | 0x14075542C, 0x1407555A5, 0x140750FB1 | the three calls of the minor-notification gate game+0x754920 | call | 2.9.0 |
game+0x10768D0 | 0x1410768D0 | controller manager, after each frame's reading (pad layer) | function | 2.9.0 |
game+0xB99CA0, game+0xB99D74 | 0x140B99CA0, 0x140B99D74 | DriveTrainConverter's type checks (database guard) | instruction | 2.9.0 |
game+0xDC6F29 | 0x140DC6F29 | pause menu call that makes its navigation grid (Exit Game tile) | call | 2.9.0 |
game+0x1400030 | 0x141400030 | navigation grid cell constructor (Exit Game tile) | function | 2.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.xaml | HUD notices and the HUD layer |
UI\Scenes\Anthem\A_Splash.xaml | title-screen entries and notices |
UI\Scenes\Anthem\A_PauseMenu.xaml | the MODS tab |
UI\Scenes\Anthem\A_PauseOptions.xaml | the Settings > MODS tile |
UI\Scenes\Anthem\A_ModOptions.xaml | the 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.xml | page flow for the MODS tab |
zipmanifest.xml | while 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 than | Breaks |
|---|---|
| 2.7.1 | no database changes under Wine (no built-in SQLite) |
| 2.7.2 | overwrites and loses other mods' game databases |
| 2.7.3 | nothing reads mediaoverride without Extra Options |
| 2.7.4 | Azimuth 1.0.3 doesn't load the platform at all |
| 2.8.0 | title entries, hotkeys, commands and choice rows are gone |
| 2.9.0 | every 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_repoand publish GitHub releases taggedx.y.zorvx.y.z, matching yourversion. - 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_initmust always return 0.docs/writing-a-mod.mdandexamples/hello_modshowif (!g_mod) return 1;, andhello_modalso returns 1 onapi_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. (Theoffline_onlycase 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.mdand the 2.9.0 notes are right, and Extra Options 0.6.0 was tested. - Check
basefor NULL. Thehook_pointerexample indocs/api.mduses the result ofwait_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\.
