Manifest reference
A plugin folder has up to three TOML files: plugin.toml (required), symbols.toml and
settings.toml. All three are strict: an unknown key is an error and the plugin is
skipped, with the file and line in the log. anvil check reports the same errors before
you ship. From Anvil 1.20 a plugin may also carry translations of its
texts, which never make Anvil skip it.
Real files: the hello examples, the template and the plugins in the Plugins page.
plugin.toml
Section titled “plugin.toml”From Anvil 1.12, a plugin.toml over 1 MB, or a symbols.toml or settings.toml over 16 MB, is not read.
id = "my-plugin" # [a-z0-9-]+, max 64 characters, uniquename = "My Plugin"version = "1.0.0" # SemVerauthors = ["Your Name"]description = "One sentence about the plugin."api = 2 # plugin API major versionanvil = ">=1.0.0" # Anvil versions the plugin needsentry = "my_plugin.dll" # DLL file name inside the plugin folderphase = "main" # "early" or "main"symbols = "symbols.toml" # game addresses; its build limits the plugin to itsettings = "settings.toml" # what the player can changeaffects_gameplay = false # required: true if the plugin may change the simulationallow_ironman = false # false or "opt-in"allow_multiplayer = false # false or "opt-in"load_after = [] # ordering only, not a dependencyissues = "https://github.com/you/my-plugin/issues" # shown in crash reportsrepository = "https://github.com/you/my-plugin"
[[dependencies]] # zero or moreid = "anvil-game"version = "^1"optional = false
[[conflicts]] # zero or more: this plugin is skipped while one is enabledid = "other-plugin"version = "<2"| Field | Required | Meaning |
|---|---|---|
id |
yes | Unique id, lowercase letters, digits and -, up to 64 characters. Also the folder name under anvil/data/. |
name |
yes | Display name. |
version |
yes | Plugin version, SemVer. |
authors |
no | List of authors. |
description |
no | One sentence about the plugin. |
api |
yes | Plugin API major version: 2. Anvil 1.0 skips api = 1 plugins with plugin API 1: update the plugin. |
anvil |
no | SemVer range of Anvil versions, for example ">=1.0.0". An older Anvil skips the plugin with a log line. |
entry |
yes | File name of the plugin DLL inside the plugin folder. |
phase |
no | early or main (default); see Writing plugins. |
symbols |
no | The plugin’s symbols.toml. Without it the plugin uses no game addresses and loads on every game build. |
settings |
no | The plugin’s settings.toml. |
affects_gameplay |
yes | true if the plugin can change the state or results of the simulation. See Ironman and multiplayer. |
allow_ironman, allow_multiplayer |
no | false (default) or "opt-in": the player may allow the plugin in that mode. |
load_after |
no | Plugin ids to load before this one, if present. Ordering only. |
issues |
no | Where to report problems; shown with crash reports. |
repository |
no | The plugin’s source. |
dependencies |
no | Plugins this one needs; see Dependencies and conflicts. |
conflicts |
no | Plugins this one cannot run with. |
game_builds and [[expect]] from API 1 are gone: symbols.toml replaces both.
Dependencies and conflicts
Section titled “Dependencies and conflicts”Each [[dependencies]] entry has an id, a SemVer version range and an optional
flag. Ranges are comparators joined by commas; ^, ~, =, >, >=, <, <= and *
are supported.
- A required dependency that is missing or out of range skips the plugin, and every plugin that depends on it.
- An optional dependency is loaded first when present and is never required.
- Plugins load in dependency order within each phase. A cycle, or an
earlyplugin depending on amainplugin, skips the plugins involved.
A [[conflicts]] entry (id, version) skips the declaring plugin while a plugin with
that id and a version in the range is enabled; the other one loads normally. The log says
conflicts with <id> <version>; disable one of them.
Ironman and multiplayer
Section titled “Ironman and multiplayer”A plugin with affects_gameplay = true depends on the standard plugin anvil-game
without declaring it: only anvil-game tells Anvil about ironman and multiplayer
sessions. In such a session Anvil suspends all changes of the plugin and puts them back
when the session ends. The player can allow a plugin that offers "opt-in" in
anvil/anvil.toml:
allow_ironman = ["my-plugin"]allow_multiplayer = []A session that is both ironman and multiplayer needs both.
Modules
Section titled “Modules”From Anvil 1.22 a plugin can bundle features of different kinds as modules: parts of one plugin, each with its own switch for the player and its own gameplay flags. Without modules, one feature that changes the game makes the whole plugin a gameplay plugin, and Anvil suspends all of it in ironman, interface features included.
anvil = ">=1.22.0" # older Anvils skip a plugin with [[modules]]affects_gameplay = false # the plugin's own handle: shared code, reads, services
[[modules]]id = "ui_size_fix" # [a-z][a-z0-9_]*, at most 32 charactersname = "Large country views at a raised GUI scale"description = "Optional, shown to the player."affects_gameplay = false
[[modules]]id = "drill_all"name = "Drill all selected armies"affects_gameplay = true # required, as for the pluginallow_ironman = "opt-in" # false (default) or "opt-in"allow_multiplayer = "opt-in"default = true # on until the player chooses; default truegroup = "Armies" # optional subheading (Anvil 1.23), translated like the restAt most 32 modules; a module that does not affect gameplay offers no opt-in. The plugin acts
for a module through its handle: host->module(self, "drill_all", &handle) in C,
host.module("drill_all") in C++ (std::nullopt when the player turned it off), and
Host::module in anvil-sdk 0.1.10. Every call that takes self takes the handle, so hooks,
patches, event subscriptions and anvil-game.commands posts belong to the module. Settings,
symbols, folders and services stay the plugin’s.
- A module the player turned off answers
ANVIL_ERROR_DISABLEDand gives no handle, so its code never runs. An undeclared one answersANVIL_ERROR_NOT_DECLARED. - Anvil suspends each module by its own flags in ironman and multiplayer, and only its
subscriptions get
anvil.suspended. - The player names a module
<plugin>.<module>inanvil/anvil.toml, or switches it in the Manager’s Plugins page. A choice applies at the next start:
disabled_modules = ["smithy.sharp_text"] # turns off a module (wins over enabled_modules)enabled_modules = ["smithy.extra"] # turns on a module whose default is falseallow_ironman = ["smithy.drill_all"] # a module's opt-in, next to plugin ids- The multiplayer hash has a line
<plugin>.<module> <version>for every gameplay module that acts, so two players with different gameplay modules see different hashes. From Anvil 1.23 the line also carries the values of the settings that count (see settings.toml). - The plugin depends on
anvil-gameimplicitly when it or any module affects gameplay.
The design is Anvil’s ADR 0011.
symbols.toml
Section titled “symbols.toml”Every address in eu4.exe that the plugin uses, declared once:
build = "eu4-1.37.5-steam-win64"
[symbol.speed_object] # a functionrva = 0x8024D0sha256 = "AE4C23FB37CE181F11EF2E3EAF4BAC498572CD06FA1783BB0BBCFE0FE93A1407"size = 8 # the digest covers the 8 bytes at rvamemory = "code" # code, read or writesignature = "void* (void* session)" # typed in C, C++ and Rustnote = "session vtable slot 0x100: returns the game-speed object"
[symbol.frontend_tick_slot] # a pointer slot, for swap_pointerrva = 0x1D5A8E8memory = "read"points_to = 0x10D2E80
[symbol.root_and_date] # values read from the verified bytesrva = 0x14321FCsha256 = "1CB3A5F923B2390CEBF07440FFAC7742C7369FB6B8E4AE06E0DECBC38376D5D8"size = 13memory = "code"values.root = { at = 3, rip_relative = 7, type = "Root", is = 0x233FE78 }values.date_offset = { at = 9, size = 4, is = 0x1DD0 }
[symbol.physfs_get_write_dir] # by export name instead of RVAexport = "PHYSFS_getWriteDir"signature = "const char* ()"buildis the one game build the plugin runs on. On any other build, or an unknown one, Anvil skips the plugin. For several builds see below.- A symbol is a function (
signature), a pointer slot (points_to), data (type) or a site (none of them).signature,points_toandtypeexclude each other. - A symbol has exactly one of
rvaandexport. One at anrvaneedsmemory, andsha256withsizeorpoints_to(a data symbol may have neither). For anexport,sha256andsizeare optional and check the prologue. sha256is the SHA-256 of thesizebytes at the symbol, in hex, with every offset thatanylists set to 0 before hashing;anylists offsets that are not compared. While you work you may write the expected bytes instead; see Digests instead of bytes.- A block for
replace_blockmay nameresume, another symbol where the game continues; the default is the end of the block. - A value has
at(its offset in the symbol’s bytes) and eithersize(1, 2, 4 or 8) orrip_relative, the offset of the instruction’s end, which yields an RVA.isstates the value the bytes must give: verification checks it, andanvil genwrites it as the constant. A value withoutisis read when the game loads. - Names match
[a-z][a-z0-9_]*; they become identifiers in the generated headers.
Before loading the DLL, Anvil compares every symbol with the running game:
the digest of its bytes (any offsets zeroed) and each is, the memory kind against the
section, and points_to against the stored pointer. Bytes already changed by other plugins
are compared in their original form, so two plugins can rely on the same function. On a
mismatch the plugin is skipped with the symbol, the RVA and both digests in the log.
Several builds
Section titled “Several builds”From Anvil 1.7, a file can declare more than one build, for example Steam and the GOG build
1.37.5.2. It lists them in builds instead of build and still declares each symbol once.
What a symbol is stays shared; only where it is and what bytes it has (rva, sha256,
size, any and points_to) may differ, in a build."<id>" table of the symbol:
builds = ["eu4-1.37.5-steam-win64", "eu4-1.37.5.2-gog-win64"]
[symbol.frame] # the same bytes, another addresssha256 = "6E06F5F68091C944A879D036CD67F041FAC7D1D1B62ADFF485C5EE3A90362A64"size = 10memory = "code"signature = "uintptr_t (void* app, uint8_t outer)"build."eu4-1.37.5-steam-win64" = { rva = 0x14C25A0 }build."eu4-1.37.5.2-gog-win64" = { rva = 0x14BC400 }
[symbol.speed_object] # other bytes: a table per buildmemory = "code"values.speed = { at = 3, size = 4 } # 0x418 on Steam, 0x408 on GOG: no is, read at load
[symbol.speed_object.build."eu4-1.37.5-steam-win64"]rva = 0x8024D0sha256 = "AE4C23FB37CE181F11EF2E3EAF4BAC498572CD06FA1783BB0BBCFE0FE93A1407"size = 8
[symbol.speed_object.build."eu4-1.37.5.2-gog-win64"]rva = 0x801850sha256 = "8F07B1074C83410F33EBF37059EF5D88E560BD1B81DECD74D35506EC5408E384"size = 8- Each of
rva,sha256,size,anyandpoints_tois given either for every build or per build, not both. Each build must pass the rules above on its own; an error names the build. - A symbol keeps its id in every build, so the plugin’s code does not change. Anvil uses the running game’s addresses, and a file that does not list the running build skips the plugin.
anvil genwrites a value as a constant only when every build has the same one; otherwise the plugin reads it when the game loads (symbol_value).anvil check --exechecks the build of theeu4.exeit is given, so run it once per build. The lock then keeps one check per build.
Absent symbols
Section titled “Absent symbols”From Anvil 1.9, a symbol may be missing from one of the builds a file lists, such as Steam
code the GOG build does not have. absent names those builds; the symbol’s other keys
apply to the builds it is in:
[symbol.lobby_close]rva = 0x1658D50sha256 = "621623B29226F30F5005D55F719BC15E2CBADAF7A1AEAFA0B1A2F71213541DD6"size = 6memory = "code"signature = "void (void* lobby)"absent = ["eu4-1.37.5.2-gog-win64"]- On an absent build the symbol is not checked and has no address:
address_ofreturnsNULL, and a hook or patch on it fails withANVIL_ERROR_NOT_DECLARED. Check it before you use it:host->address_of(self, SYM_LOBBY_CLOSE) != NULLin C,host.present(sym::lobby_close)in C++. absentneedsbuilds, cannot list every build, and an absent build gets nobuild."<id>"table. Aresumemust name a symbol that is in every build its block is in.- Only the builds
absentnames are exempt: a symbol that does not verify on any other build still skips the plugin. anvil check --exelists the symbols absent on the exe’s build, andanvil gennames the absent builds in each symbol’s comment.- An older Anvil does not know the key and skips the plugin, so declare
anvil = ">=1.9.0".
Digests instead of bytes
Section titled “Digests instead of bytes”From Anvil 1.10 a symbol states the SHA-256 of its bytes, so your repository, zip and
Workshop item hold no code of eu4.exe. The older key bytes writes the expected bytes
out as hex pairs (?? for any byte); it stays valid for all of plugin API 2 and is the
handy form while you work, but it copies pieces of the game into every file you share.
Write it locally, for example:
[symbol.my_site]rva = 0x123450bytes = "40 53 ?? ?? 90 90" # an invented example, not the game's codememory = "code"and before you commit, run
tools/symbols-to-digest.py
on symbols.toml. It needs no game: it replaces each bytes with sha256, size and
any (any = [2, 3] here) and writes is for each value that is the same in every build
and does not lie on a ??; then run anvil check --exe once per build.
sha256,sizeandanyare placement keys likebytes, shared or per build.bytesandsha256exclude each other per placement.- A mismatch names both digests, not the first differing byte, and a port to another game build
needs the old
eu4.exe, because the repository no longer holds the pattern. - An older Anvil does not know the keys and skips the plugin, so declare
anvil = ">=1.10.0". - Describe the game’s code in
noteand comments by its address and what it does, not by the names a debugger shows.
ADR 0003 has the reasons and the limits: a digest is not secrecy.
symbols.lock
Section titled “symbols.lock”anvil check --exe writes symbols.lock next to plugin.toml: the SHA-256 of eu4.exe,
a digest of symbols.toml, the build and the result. Commit it. Without the game,
anvil check fails when the lock is missing, does not match symbols.toml, or says
result = "problems", so CI catches a symbol that was never checked against the game.
settings.toml
Section titled “settings.toml”What the player can change:
[setting.log_menu_returns]type = "bool" # bool, int, float, enum, string or keydefault = truelabel = "Log each return to the menu"description = "Writes a line to anvil.log whenever the game returns to the main menu."restart = false # false: applies at once; default true: at the next start
[setting.mode]type = "enum"values = [{ name = "off", label = "Off" }, { name = "on", label = "On" }]default = "off"label = "Mode"
[setting.panel_key]type = "key"default = "Ctrl+Shift+F12"label = "Panel key"type,defaultandlabelare required;description,groupandrestartare optional.intandfloattake optionalmin,maxandstep;enumtakesvalues.- A
keyis a binding such as"Ctrl+Shift+F12", or""for none.
From Anvil 1.23 (declare anvil = ">=1.23.0": an older Anvil skips a plugin with these keys)
settings follow the plugin’s modules:
[setting.flip_ratio]type = "float"default = 1.5label = "Flip ratio"module = "flows" # a module of plugin.toml: shown under it, off with itadvanced = true # folded under "Advanced" in the overlay and the Manager
[setting.log_flows]type = "bool"default = falselabel = "Log flows"affects_gameplay = false # does not change the game
[retired.flows_mode] # a setting you removed for the module's own switchmodule = "flows"off = ["off"] # these saved values turn the module offon = ["on", "verify"] # these turn it on
[retired.flows_ironman]module = "flows"ironman = [true] # allows it in ironman, if flows offers allow_ironman = "opt-in"- Settings that count. In a plugin or module that changes the game, every setting counts
for the game unless it says
affects_gameplay = false; akeysetting does not count by default. The values in effect of the settings that count join their owner’s line in the multiplayer hash (lode 1.2.0 cooldown_months=24 flip_ratio=1.5, names sorted), so players with different values see different codes, and they are locked during a multiplayer game. Arestart = truevalue saved for the next start counts from that start. - Retired settings. At the first start of the new version, a player’s saved value of a
[retired.<name>]that is in itsofforonturns<plugin>.<module>off or on inanvil/anvil.toml(as the overlay’s switch does, so it also turns on a module withdefault = false), and one in itsironmanormultiplayerallows the module there (the module must offer that opt-in). It holds at that same start, and every saved value of the name is removed from the player’s file. Both are written toanvil.log. Each list is optional, a value cannot be in bothoffandon, and a setting and a retired setting cannot share a name. Several retired settings may name one module; from Anvil 1.24, when a player’s values of them disagree (one in anoff, another in anon), the module is off, whatever their order in the file. Give the module the old setting’s default: the player’s file holds only values that differ from the default, so a player who kept the old default has nothing to move, and the module’sdefaultdecides for them.
The player’s values live in anvil/data/<plugin-id>/settings.toml, only those that differ
from the default, as name = value. The file can be edited by hand while the game is
closed. An invalid value falls back to the default with a warning in the log. For a test,
an environment variable ANVIL_<ID>_<NAME> (upper case, - as _) overrides a value for
one session.
The plugin reads validated values through the generated headers: cfg::<name>.get() in
C++, host->setting_bool(self, CFG_<NAME>) and its siblings in C. See
Settings in the Host API.
Translations
Section titled “Translations”From Anvil 1.20, the overlay and Anvil Manager show a plugin’s description and its
settings’ label, description, group and option labels in the player’s language when
the plugin carries translations/<code>.toml: one file per language, named fr, de,
es, zh-Hans, zh-Hant, ja, ko or pl. Each maps the English words of
plugin.toml and settings.toml to that language’s words:
status = "draft" # "checked" once a native speaker checked it[text]"Log each return to the menu" = "Noter chaque retour au menu""Writes a line to anvil.log whenever the game returns to the main menu." = "Écrit une ligne dans anvil.log chaque fois que le jeu revient au menu principal."- A text without a translation, and every text in a language without a file, is shown in
English. The plugin’s
namealways is. - The key is the English text itself: when you change an English text, change its key and translation in every file. Until then the player sees the new English words, never a translation of the old ones.
- Chinese, Japanese and Korean words are drawn with the fonts of Windows.
plugin.tomldoes not name the folder, so an Anvil before 1.20 ignores it: translations need no neweranvilrange. A file that does not parse is left out with a warning inanvil.log; the plugin still loads.anvil_add_plugincopiestranslations/*.tomlinto the built plugin folder.- The template carries all eight files for its one setting.
anvil gen
Section titled “anvil gen”anvil gen (in the SDK’s bin/) writes headers from symbols.toml and settings.toml.
anvil_add_plugin runs it at build time; call it yourself for other build systems:
anvil gen [--lang c|cpp|rust|rust-sdk] [--settings <settings.toml>] <symbols.toml|settings.toml>... <out-dir>| File | Contents |
|---|---|
symbols.gen.h |
SYM_<NAME> ids, sym_<name>_fn function pointer types, SYMVAL_<SYMBOL>_<VALUE> values |
symbols.gen.hpp |
namespace sym: one typed constant per symbol, for example sym::speed_object |
settings.gen.h |
CFG_<NAME> ids and CFG_<NAME>_<OPTION> enum indices |
settings.gen.hpp |
namespace cfg: cfg::<name>.get() |
symbols.gen.rs, settings.gen.rs |
the same ids, function types and values for Rust (--lang rust or rust-sdk only) |
Without --lang it writes the C and C++ headers. From Anvil 1.25:
--lang rust-sdkwrites the samesymbols.gen.rsas--lang rust, with a moduletypedfor theanvil-sdkcrate: each function symbol with its type, forHost::hook_symbol.--langgiven more than once writes each language named, e.g.--lang c --lang cpp.- Besides C++ keywords and a value named
id,valueorsymbol_name,anvil genrefuses names that the C++ header cannot hold: a symbol namedid,valueorsymbol_name, a value with its symbol’s name, a setting namedid,get,setting_name,restart,default_value,minimumormaximum, and an enum option with its setting’s name.anvil checkreports them at their line, whatever language the plugin uses.
Declare the types named in signature and type before including the header.
anvil check
Section titled “anvil check”anvil check validates a plugin without starting the game:
anvil check <plugin folder> [--exe <eu4.exe>] [--format text|json|github] [--complete-translations]anvil check --game <game folder> [--format text|json|github] [--host-version <x.y.z>]- Without
--exe: the schemas of the three files, names thatanvil genwould refuse, and thesymbols.lockcheck. This is what CI runs. - Translations (Anvil 1.20): a file that does not parse, a file name that is not one
of the eight codes and an entry no text of the plugin has any more are errors; a text
without a translation, and a language without a file, are warnings.
--complete-translationsmakes them errors, for a plugin that ships every language. - Modules (Anvil 1.22): one line per module with its flags and default, and a warning
when the
anvilrange admits a release without modules. - Settings of modules (Anvil 1.23): a
moduleor retiredmodulethatplugin.tomldoes not declare is an error. Warnings: theanvilrange admits a release withoutmodule,advanced,affects_gameplay,[retired.*]or a module’sgroup; a setting named as a module; two[retired.*]of one module of which one has anonlist (Anvil 1.24); a setting withoutaffects_gameplayin a plugin or module that offers multiplayer. - With
--exe: also the build, every symbol’s bytes, memory kind, pointers, exports and values, and instruction boundaries: the declared bytes of a function or site must be whole instructions, and a hook must not relocateJRCXZ,JECXZorLOOP*. From Anvil 1.26 also a short branch before the last relocated instruction, and a hook whose overwritten bytes are all??, as the loader refuses them. It rewritessymbols.lock. From Anvil 1.26 an exe of a build the file does not declare, or one this Anvil does not know, is reported and leavessymbols.lockalone. - With
--game: checks every plugin in the game’sanvil/plugins/and resolves them as the loader would: what loads in which order, what is skipped and why, and warnings for plugins whose code symbols overlap. From Anvil 1.24 it also shows the next start’s plan: whether that start is in safe mode, and what it writes before any plugin loads (approved copies to make or remove, retired settings to move intoanvil.toml). The JSON report has them innext_start(safe_mode,unfinished_starts, andwriteswithremove,copiesandretired). From Anvil 1.26 the plugins’anvilranges are checked against the Anvil installed in that folder (the version of itsversion.dll), as its loader checks them, not against the CLI’s own version; without an Anvil there it uses its own and says so.--host-versionsets the version to check against. Ananvil.tomlthat does not parse, or a list of the wrong type, is a problem, since the loader then loads no plugin. --format githubprints::error file=…,line=…annotations, so run it from the repository root in GitHub Actions.
Exit codes: 0 OK, 1 problems, 2 cannot check.
anvil port
Section titled “anvil port”After a game update, anvil port places a plugin’s symbols in the new build. It needs the old
eu4.exe as well as the new one, so keep a copy before the game updates:
anvil port symbols.toml --from <old eu4.exe> --to <new eu4.exe> --build <new build id> --out symbols.tomlFrom Anvil 1.12, --build must be the id this Anvil has for the new eu4.exe, since a file with
any other id never loads. Add --unknown-build for a build it does not know yet; the id then needs
the form eu4-<version>-<store>-win64.
Add --from-build <id> when this Anvil does not know the old eu4.exe, and
--format json for a report you can feed to a generator. Without --out nothing is written.
It compares the code of both builds with the addresses the linker chose set aside, and adds a
build."<id>" entry to each symbol, keeping your comments and layout. Symbols with sha256
stay digests. The tool never touches eu4.exe.
A wrong address is worse than none, so a symbol stays for you to place when:
- its code has no match in the new build, or more than one;
- the only match is out of order with the functions around it, or refers to other code;
- an operand differs that no
valuesentry declares, because your plugin may depend on it; - it fails what
anvil check --exewould report for the new build.
Each of those gets a comment in the file with the reason and, where one is known, an address to
look at. The file does not parse until you place the symbol or declare it absent; an export
has no address to drop, so anvil check --exe reports it on the new build instead. The entry of
a function whose operands changed is placed, with a warning to read it.
anvil port edits each symbol’s own [symbol.<name>] table. From Anvil 1.25 it refuses, before
writing anything, a file with a symbol written as an inline table or with dotted keys under
[symbol]; write that symbol as a table of its own first.
Exit codes: 0 every symbol placed, 1 some left for you, 2 cannot port. Then run
anvil check --exe for each build, which needs an Anvil that knows the new one.
On the two builds we have, Steam 1.37.5 and GOG 1.37.5.2, it placed 98.4% of the symbols in our five plugin files with no wrong address, but those builds are close. Expect a longer list after a real update, which it has not met yet.