Skip to main content

rpkg_rs/
lib.rs

1#![doc(html_root_url = "https://docs.rs/rpkg-rs/1.4.0")]
2//! `rpkg-rs` provides comprehensive functionality for interacting with `ResourcePackage` (rpkg) files found within Hitman games.
3//! This crate facilitates parsing of these files, enabling seamless access to the contained resource files.
4//! By parsing configuration files such as `thumbs.ini` and `packagedefintion.txt`, rpkg-rs offers extensive support for reading and manipulating these packages.
5//!
6//! With rpkg-rs, you can:
7//!
8//! - Parse ResourcePackage (rpkg) files, allowing access to the resources stored within.
9//! - Mount all rpkg files associated with a game, providing a unified interface for accessing game resources.
10//! - Access API methods to mount individual ResourcePartitions or ResourcePackages, allowing better control over resource access.
11//!
12//! rpkg-rs aims to streamline the process of working with Hitman game resources, offering a robust set of features to read ResourcePackage files.
13
14use 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}