Skip to main content

hao_il2cpp_runtime/
error.rs

1use thiserror::Error;
2
3/// A result whose error is [`Error`](enum@Error).
4pub type Result<T> = std::result::Result<T, Error>;
5
6#[derive(Error, Debug)]
7/// What went wrong loading the game binary, finding things in it, or calling
8/// and hooking its methods.
9pub enum Error {
10    /// The game binary couldn't be opened, or isn't loaded in this process.
11    #[error("could not load the game binary: {0}")]
12    Load(libloading::Error),
13    /// An `il2cpp_*` function this crate needs isn't exported by the game
14    /// binary, e.g. the binary isn't an Il2Cpp `GameAssembly`.
15    #[error("the game binary does not export {0}: {1}")]
16    MissingExport(&'static str, libloading::Error),
17    /// The game binary is for another platform, e.g. a Windows build running
18    /// under Wine/Proton seen from a Linux mod.
19    #[error("{0}")]
20    UnsupportedBinary(String),
21    /// A hook's or call's Rust types don't match the method's real signature.
22    #[error("signature mismatch, {0}")]
23    Signature(String),
24    /// `il2cpp_init` returned failure in [`Il2Cpp::init_standalone`](crate::Il2Cpp::init_standalone).
25    #[error("il2cpp_init failed")]
26    Init,
27    /// An assembly, class, method, field or object wasn't found, or couldn't be allocated.
28    #[error("could not find {0}")]
29    NotFound(String),
30    /// A name passed to the runtime contains a nul byte, so it can't be a C string.
31    #[error("{0} contains a nul byte")]
32    Nul(String),
33    /// Installing or removing a hook failed.
34    #[error("hooking failed: {0:?}")]
35    Hook(hooking::error::HookingError),
36    /// The called method threw a managed exception; holds its `ToString()`.
37    #[error("{0}")]
38    Exception(String),
39}