anvil-sdk
Safe Rust API for plugins of Anvil,
the native plugin loader for Europa Universalis IV 1.37.5. The package is
anvil-sdk; the library is anvil, so code says anvil::…. It sits on the raw
bindings of anvil-sys and depends on
nothing else.
[]
= ["cdylib"]
[]
= "0.1"
use ;
use ;
use World;
;
plugin!;
What it gives over the C ABI:
anvil::plugin!(Type)exportsanvil_plugin_load.Plugin::loadreturns the plugin or ananvil::Error; an error or a panic becomes the result Anvil rolls the plugin back on.- Every callback runs behind an adapter with
catch_unwind: a panic in a mid hook, block replacement, event, setting or click handler, or in work for the main thread, is logged once per callback and never crosses the FFI. Changeremoves its change onDrop;keep()keeps it for the process.FunctionHook<sym::NameFn>lives in astatic, where Anvil writes the rest of the chain.- Typed symbols and settings from
anvil gen --lang rust(symbols.gen.rs,settings.gen.rs, written by a build script). - Typed wrappers for the services Anvil ships:
anvil::game(anvil-game.gameand its events),anvil::world(anvil-game.world),anvil::commands(anvil-game.commands),anvil::panel(anvil-overlay.panel),anvil::benchmark(anvil.benchmark) andanvil::map(anvil-map.modesand its events). A function a running service is too old to have answersErrorCode::Unsupported.
Host and service calls are safe. What reaches the game's memory by address, or
puts raw bytes and pointers into it, stays an unsafe fn with its contract:
calling a hook's next (the generated function types are unsafe extern "C" fn), Host::function, Host::data, writing the mid-hook context
(Cpu::regs_mut), byte patches, pointer swaps, call redirects, import
replacements and changes at raw addresses.
Examples in the Anvil repository: examples/hello-rust (a function hook, a
mid hook and an event on declared symbols) and examples/panel-rust (the
player's country from the world service in an overlay panel, with no game
addresses).
Versions: an own 0.x line. Anvil's source compatibility (ADR 0001) covers
the crate from its 1.0, which comes after the first real Rust plugin. A new
Anvil service, or a function appended to one, gets its wrapper here in the
same Anvil pull request as its C header.
License: MIT.