rpkg_rs/lib.rs
1#![doc(html_root_url = "https://docs.rs/rpkg-rs/1.2.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//! - Utilize the included functionality to read configuration files like `thumbs.ini` and `packagedefintion.txt`.
10//! - Perform various operations on thumbs files, including setting new variables, modifying existing variables, adding new include files, and more.
11//! - Mount all rpkg files associated with a game, providing a unified interface for accessing game resources.
12//! - Access API methods to mount individual ResourcePartitions or ResourcePackages, allowing better control over resource access.
13//!
14//! rpkg-rs aims to streamline the process of working with Hitman game resources, offering a robust set of features to read ResourcePackage files.
15
16use thiserror::Error;
17
18#[cfg(feature = "serde")]
19use serde::{Deserialize, Serialize};
20
21pub mod encryption;
22pub mod misc;
23pub mod resource;
24pub mod utils;
25
26#[derive(Debug, PartialEq, Clone, Copy)]
27#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
28pub enum WoaVersion {
29 HM2016,
30 HM2,
31 HM3,
32}
33
34#[derive(Debug, Error)]
35pub enum GlacierResourceError {
36 #[error("Error reading the file: {0}")]
37 IoError(#[from] std::io::Error),
38
39 #[error("Couldn't read the resource {0}")]
40 ReadError(String),
41
42 #[error("Couldn't write the resource {0}")]
43 WriteError(String),
44}
45
46pub trait GlacierResource: Sized {
47 type Output;
48 fn process_data<R: AsRef<[u8]>>(
49 woa_version: WoaVersion,
50 data: R,
51 ) -> Result<Self::Output, GlacierResourceError>;
52
53 fn serialize(&self, woa_version: WoaVersion) -> Result<Vec<u8>, GlacierResourceError>;
54
55 fn resource_type() -> [u8; 4];
56 fn video_memory_requirement(&self) -> u64;
57 fn system_memory_requirement(&self) -> u64;
58 fn should_scramble(&self) -> bool;
59 fn should_compress(&self) -> bool;
60}