Skip to main content

hao_il2cpp/
error.rs

1use thiserror::Error;
2
3/// A `Result` whose error is this crate's [`Error`](enum@Error).
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// Why reading a game, its metadata or its binary failed.
7#[derive(Error, Debug)]
8pub enum Error {
9    /// The file doesn't start with IL2CPP's metadata magic (`0xFAB11BAF`),
10    /// so it isn't a `global-metadata.dat` (or it's encrypted).
11    #[error("not an il2cpp metadata file (bad sanity value {0:#x})")]
12    BadSanity(u32),
13    /// The metadata's version has no known layout (supported: 29, 31 and 39).
14    #[error("metadata version {0} is not supported")]
15    UnsupportedVersion(u32),
16    /// A section of the metadata header points outside the file, or its size
17    /// isn't a whole number of entries.
18    #[error("metadata section {0} is out of bounds or misaligned")]
19    BadSection(&'static str),
20    /// An index into a metadata table (named by the first field) is out of range.
21    #[error("index {1} is out of range for {0}")]
22    BadIndex(&'static str, i64),
23    /// The game binary couldn't be parsed, its registration structs weren't
24    /// found, or a type in its table couldn't be read.
25    #[error("binary: {0}")]
26    Binary(String),
27    /// [`Game::open`](crate::Game::open) couldn't find `global-metadata.dat`
28    /// or `GameAssembly` in the game folder.
29    #[error("could not find {0}")]
30    NotFound(String),
31    /// Building or writing a declaration assembly failed in hao.
32    #[error(transparent)]
33    Hao(#[from] hao::error::HaoError),
34    /// A file couldn't be read or written.
35    #[error("io error: {0}")]
36    Io(#[from] std::io::Error),
37}