1#![doc(html_root_url = "https://docs.rs/rpkg-rs/1.4.0")]
2use thiserror::Error;
15
16#[cfg(feature = "serde")]
17use serde::{Deserialize, Serialize};
18
19pub mod encryption;
20pub mod misc;
21pub mod resource;
22pub(crate) mod utils;
23
24
25#[non_exhaustive]
26#[derive(Debug, PartialEq, Clone, Copy)]
27#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
28pub enum GlacierGame {
29 HM2016,
30 HM2,
31 HM3,
32 Bond,
33}
34
35impl From<WoaVersion> for GlacierGame {
36 fn from(version: WoaVersion) -> Self {
37 match version {
38 WoaVersion::HM2016 => GlacierGame::HM2016,
39 WoaVersion::HM2 => GlacierGame::HM2,
40 WoaVersion::HM3 => GlacierGame::HM3,
41 }
42 }
43}
44
45#[derive(Debug, PartialEq, Clone, Copy)]
46#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
47pub enum WoaVersion {
48 HM2016,
49 HM2,
50 HM3,
51}
52
53#[derive(Debug, Error)]
54pub enum GlacierResourceError {
55 #[error("Error reading the file: {0}")]
56 IoError(#[from] std::io::Error),
57
58 #[error("Couldn't read the resource {0}")]
59 ReadError(String),
60
61 #[error("Couldn't write the resource {0}")]
62 WriteError(String),
63}
64
65pub trait GlacierResource: Sized {
66 type Output;
67 fn process_data<R: AsRef<[u8]>>(
68 woa_version: WoaVersion,
69 data: R,
70 ) -> Result<Self::Output, GlacierResourceError>;
71
72 fn serialize(&self, woa_version: WoaVersion) -> Result<Vec<u8>, GlacierResourceError>;
73
74 fn resource_type() -> [u8; 4];
75 fn video_memory_requirement(&self) -> u64;
76 fn system_memory_requirement(&self) -> u64;
77 fn should_scramble(&self) -> bool;
78 fn should_compress(&self) -> bool;
79}