rpkg_rs/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#![doc(html_root_url = "https://docs.rs/rpkg-rs/1.1.2")]
//! `rpkg-rs` provides comprehensive functionality for interacting with `ResourcePackage` (rpkg) files found within Hitman games.
//! This crate facilitates parsing of these files, enabling seamless access to the contained resource files.
//! By parsing configuration files such as `thumbs.ini` and `packagedefintion.txt`, rpkg-rs offers extensive support for reading and manipulating these packages.
//!
//! With rpkg-rs, you can:
//!
//! - Parse ResourcePackage (rpkg) files, allowing access to the resources stored within.
//! - Utilize the included functionality to read configuration files like `thumbs.ini` and `packagedefintion.txt`.
//! - Perform various operations on thumbs files, including setting new variables, modifying existing variables, adding new include files, and more.
//! - Mount all rpkg files associated with a game, providing a unified interface for accessing game resources.
//! - Access API methods to mount individual ResourcePartitions or ResourcePackages, allowing better control over resource access.
//!
//! rpkg-rs aims to streamline the process of working with Hitman game resources, offering a robust set of features to read ResourcePackage files.

use thiserror::Error;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

pub mod encryption;
pub mod misc;
pub mod resource;
pub mod utils;

#[derive(Debug, PartialEq, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub enum WoaVersion {
    HM2016,
    HM2,
    HM3,
}

#[derive(Debug, Error)]
pub enum GlacierResourceError {
    #[error("Error reading the file: {0}")]
    IoError(#[from] std::io::Error),

    #[error("Couldn't read the resource {0}")]
    ReadError(String),
    
    #[error("Couldn't write the resource {0}")]
    WriteError(String),
}

pub trait GlacierResource: Sized {
    type Output;
    fn process_data<R: AsRef<[u8]>>(
        woa_version: WoaVersion,
        data: R,
    ) -> Result<Self::Output, GlacierResourceError>;

    fn serialize(&self, woa_version: WoaVersion) -> Result<Vec<u8>, GlacierResourceError>;

    fn resource_type() -> [u8; 4];
    fn video_memory_requirement(&self) -> u64;
    fn system_memory_requirement(&self) -> u64;
    fn should_scramble(&self) -> bool;
    fn should_compress(&self) -> bool;
}