Support modules: [[native.module]]

A support module puts shared Rust code in the function-replacement mirror of a game module. Its code can use that game module's private items, and your mixin helpers can call it. The launcher compiles the mirror against the prebuilt game; it does not edit or rebuild the original game source.

From Sunrise's modding bookead8a1e

On this page

Use one for code that several helpers share and that needs the game's private items. Shared code that needs only public items goes in your mod's own crate.

Example

Declare fnr_runtime in the mirror of the autosave module. The full manifest and a helper that calls it are on Bridges.

toml
[[native.module]]
id = "runtime"
file = "crates/sunrise-client/src/game/world/autosave.rs"
name = "fnr_runtime"
source = "src/runtime.rs"

src/runtime.rs holds the module's items, with no mod wrapper:

rust
pub fn bumped(ticks: i64) -> i64 {
    ticks + 1
}

A helper calls it by its path in the game crate: crate::game::autosave::fnr_runtime::bumped(*ticks). That file is the module game::autosave, because world/ is an area (Naming the target).

Inside the module, super:: is the game module that received it, such as super::Game. Make the items that helpers call pub. The module may call your mod's crate; your mod's crate cannot call the module.

Fields

  • id

    Required
    yes
    Meaning
    The row's name, unique in the mod.
  • file

    Required
    yes
    Meaning
    The game source file whose module is mirrored, relative to the repository root: crates/sunrise-client/src/….
  • name

    Required
    yes
    Meaning
    The module's Rust name. Pick one the destination module does not use, with a prefix of your own, such as fnr_.
  • source

    Required
    yes
    Meaning
    Your file under src/ with the module's items.
  • visibility

    Required
    no
    Meaning
    The module's visibility: "pub(crate)" (the default, enough for your helpers) or "pub".

What you will see

A module builds with the mixins, so the build log's Function replacement: line covers it.

Errors

The sunrise-mod.toml: errors come when the manifest is read; the coded ones come at build time.

MessageFix
`E_MIXIN_MODULE_DESTINATION: <mod>:<row>: <file> is not a file of the game crate (sunrise_client); …`Name a file under crates/sunrise-client/src/.
E_MIXIN_MODULE_SOURCE: <mod>:<row>: <parse error>Fix the Rust error shown in source.
sunrise-mod.toml: module file must be a plain pathWrite file as a relative path without ...
sunrise-mod.toml: module name must be an identifierUse a Rust identifier.
sunrise-mod.toml: module source must be a file under src/Move the file under src/.
sunrise-mod.toml: module visibility must be pub or pub(crate)Use one of the two, or leave it out.
sunrise-mod.toml: empty or duplicate module idGive the row an id no other row uses.

Edit this page on GitHub · Spotted something wrong? Open an issue or ask on Discord.