Skip to main content

Host

Struct Host 

Source
pub struct Host { /* private fields */ }
Expand description

The loader’s services for this mod, valid for the life of the process.

Each mod DLL links its own copy of this crate, so host always answers for the mod that calls it.

§Examples

if let Some(host) = enshwick::host() {
    host.log(enshwick::abi::Level::INFO, "ready");
}

Implementations§

Source§

impl Host

Source

pub fn game_resource(&self, key: ResourceKey) -> Option<Vec<u8>>

A vanilla resource’s bytes from the game’s archive; see game_resource.

§Examples
use enshwick::content::{Guid, types};

if let Some(host) = enshwick::host() {
    let chest = Guid::parse("6943053a-32c1-4718-ae22-e61427ddf54d");
    if let Ok(key) = chest.key(types::ITEM_INFO) {
        let _ = host.game_resource(key);
    }
}
Source§

impl Host

Source

pub fn api(&self) -> &'static HostApi

The raw table, for calls the safe layer does not wrap.

§Examples
if let Some(host) = enshwick::host() {
    assert_eq!(host.api().header.abi_major, enshwick::abi::ABI_MAJOR);
}
Source

pub fn handle(&self) -> ModHandle

This mod’s handle.

§Examples
if let Some(host) = enshwick::host() {
    assert_ne!(host.handle(), enshwick::abi::ModHandle::NONE);
}
Source

pub fn build(&self) -> BuildInfo

The running game: side, image base and build fingerprint.

§Examples
if let Some(host) = enshwick::host() {
    let build = host.build();
    assert_ne!(build.base, 0);
}
Source

pub fn hosting(&self) -> bool

Whether this process runs a game server now: always on the dedicated server; on the client while it hosts a game, solo play included, from the built-in server’s first step until the game stops.

§Examples
if let Some(host) = enshwick::host() {
    let acts = host.hosting();
}
Source

pub fn log(&self, level: Level, message: &str)

Writes message to the log under this mod’s id.

Not for hot paths: a hook logs once per event worth knowing.

§Examples

See Host.

Source

pub fn log_level(&self) -> Level

The most detailed level the loader keeps for this mod’s lines, from mod-configs/enshwick.toml.

§Examples
use enshwick::abi::Level;

if let Some(host) = enshwick::host() {
    let verbose = host.log_level() >= Level::DEBUG;
}
Source

pub fn fault(&self, reason: &str)

Reports that this mod failed at run time. The loader unlinks every hook of the mod, so the game runs vanilla where the mod was.

§Examples
if let Some(host) = enshwick::host() {
    host.fault("the altar table is corrupt");
}
Source

pub fn caller_frame(&self) -> CallerFrame

The game caller’s context at entry of the running hook chain, for hooks declared with HookFlags::CALLER_FRAME.

Valid until the hook calls anything hooked.

§Examples
if let Some(host) = enshwick::host() {
    let frame = host.caller_frame();
    let _ = frame.stack();
}
Source§

impl Host

Source

pub fn language(&self) -> Language

The language the player reads the game in; see language.

§Examples
if let Some(host) = enshwick::host() {
    enshwick::info!("texts in {}", host.language().code());
}
Source§

impl Host

Source

pub fn game_text(&self, id: u32, language: Language) -> Option<&'static str>

The game’s own text of tag id in language; see game_text_in.

§Examples
use enshwick::i18n::Language;

if let Some(host) = enshwick::host() {
    let _ = host.game_text(0x8f21_95d5, Language::DE_DE);
}

Trait Implementations§

Source§

impl Clone for Host

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Host

Source§

impl Debug for Host

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl EngineFacts for Host

Source§

fn offset(&self, id: &str) -> Result<usize, Off>

The byte offset the id names. Read more
Source§

fn size(&self, id: &str) -> Result<usize, Off>

The size of the type the id names. Read more
Source§

fn hash(&self, id: &str) -> Result<u32, Off>

The hash of the type the id names. Read more

Auto Trait Implementations§

§

impl Freeze for Host

§

impl RefUnwindSafe for Host

§

impl Send for Host

§

impl Sync for Host

§

impl Unpin for Host

§

impl UnsafeUnpin for Host

§

impl UnwindSafe for Host

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.