rpkg_rs/
lib.rs

1#![doc(html_root_url = "https://docs.rs/rpkg-rs/1.3.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#[derive(Debug, PartialEq, Clone, Copy)]
25#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
26pub enum WoaVersion {
27    HM2016,
28    HM2,
29    HM3,
30}
31
32#[derive(Debug, Error)]
33pub enum GlacierResourceError {
34    #[error("Error reading the file: {0}")]
35    IoError(#[from] std::io::Error),
36
37    #[error("Couldn't read the resource {0}")]
38    ReadError(String),
39    
40    #[error("Couldn't write the resource {0}")]
41    WriteError(String),
42}
43
44pub trait GlacierResource: Sized {
45    type Output;
46    fn process_data<R: AsRef<[u8]>>(
47        woa_version: WoaVersion,
48        data: R,
49    ) -> Result<Self::Output, GlacierResourceError>;
50
51    fn serialize(&self, woa_version: WoaVersion) -> Result<Vec<u8>, GlacierResourceError>;
52
53    fn resource_type() -> [u8; 4];
54    fn video_memory_requirement(&self) -> u64;
55    fn system_memory_requirement(&self) -> u64;
56    fn should_scramble(&self) -> bool;
57    fn should_compress(&self) -> bool;
58}