Skip to content

Commit 64e231c

Browse files
committed
Bumped version and rustfmt 🌈
1 parent a536415 commit 64e231c

File tree

11 files changed

+114
-95
lines changed

11 files changed

+114
-95
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rpkg-rs"
3-
version = "1.1.0"
3+
version = "1.1.1"
44
edition = "2021"
55
license = "Apache-2.0"
66
categories = ["game-development", "data-structures", "parser-implementations"]

examples/mount_game_files.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use itertools::Itertools;
12
use std::io::{stdin, Write};
23
use std::path::PathBuf;
34
use std::str::FromStr;
45
use std::{env, io};
5-
use itertools::Itertools;
66

77
use rpkg_rs::misc::resource_id::ResourceID;
88
use rpkg_rs::resource::partition_manager::{PartitionManager, PartitionState};
@@ -64,18 +64,18 @@ fn main() {
6464
},
6565
);
6666

67-
//read the packagedefs here
68-
let mut last_index = 0;
69-
let mut progress = 0.0;
70-
let progress_callback = |current, state: &PartitionState| {
71-
if current != last_index {
72-
last_index = current;
73-
print!("Mounting partition {} ", current);
74-
}
75-
if !state.installing && !state.mounted {
76-
println!("[Failed to mount this partition. Is it installed?]");
77-
}
78-
let install_progress = (state.install_progress * 10.0).ceil() / 10.0;
67+
//read the packagedefs here
68+
let mut last_index = 0;
69+
let mut progress = 0.0;
70+
let progress_callback = |current, state: &PartitionState| {
71+
if current != last_index {
72+
last_index = current;
73+
print!("Mounting partition {} ", current);
74+
}
75+
if !state.installing && !state.mounted {
76+
println!("[Failed to mount this partition. Is it installed?]");
77+
}
78+
let install_progress = (state.install_progress * 10.0).ceil() / 10.0;
7979

8080
let chars_to_add = (install_progress * 10.0 - progress * 10.0) as usize * 2;
8181
let chars_to_add = std::cmp::min(chars_to_add, 20);
@@ -124,8 +124,7 @@ fn main() {
124124
for partition in &package_manager.partitions {
125125
let mut last_occurence: Option<&ResourceInfo> = None;
126126

127-
let size =
128-
|info: &ResourceInfo| info.compressed_size().unwrap_or(info.size());
127+
let size = |info: &ResourceInfo| info.compressed_size().unwrap_or(info.size());
129128

130129
let changes = partition.resource_patch_indices(&rrid);
131130
let deletions = partition.resource_removal_indices(&rrid);

examples/rebuild_game.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ fn main() {
6767
}
6868

6969
builder
70-
.build(
71-
package.version(),
72-
output_path.join(&output_name).as_path()
73-
)
70+
.build(package.version(), output_path.join(&output_name).as_path())
7471
.unwrap_or_else(|e| {
7572
eprintln!("failed to build package '{}': {}", output_name, e);
7673
std::process::exit(0);

src/encryption/xtea.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::encryption::xtea::XteaError::InvalidInput;
2+
use byteorder::{LittleEndian, WriteBytesExt};
23
use extended_tea::XTEA;
34
use std::io::Cursor;
4-
use byteorder::{LittleEndian, WriteBytesExt};
55
use thiserror::Error;
66

77
/// Errors that can occur during XTEA encryption or decryption.
@@ -17,7 +17,7 @@ pub enum XteaError {
1717
InvalidInput(String),
1818

1919
#[error("Xtea encoding error: {0}")]
20-
XteaEncodingError(std::io::Error)
20+
XteaEncodingError(std::io::Error),
2121
}
2222

2323
/// Implementation of XTEA encryption and decryption methods.
@@ -53,7 +53,7 @@ impl Xtea {
5353
if !input_buffer.starts_with(&Self::DEFAULT_ENCRYPTED_HEADER) {
5454
return Err(InvalidInput("Header mismatch".to_string()));
5555
}
56-
let checksum =&input_buffer[payload_start-4..payload_start];
56+
let checksum = &input_buffer[payload_start - 4..payload_start];
5757
let input = &input_buffer[payload_start..];
5858

5959
if input.len() % 8 != 0 {
@@ -71,12 +71,14 @@ impl Xtea {
7171
xtea.decipher_stream::<LittleEndian, _, _>(&mut input_reader, &mut ouput_writer)
7272
.map_err(XteaError::CipherError)?;
7373

74-
let output = String::from_utf8(ouput_writer.get_mut().to_owned()).map_err(XteaError::TextEncodingError)?;
74+
let output = String::from_utf8(ouput_writer.get_mut().to_owned())
75+
.map_err(XteaError::TextEncodingError)?;
7576

76-
let result_checksum = crc32fast::hash(output.trim_end_matches('\0').as_bytes()).to_le_bytes();
77-
match result_checksum == checksum{
77+
let result_checksum =
78+
crc32fast::hash(output.trim_end_matches('\0').as_bytes()).to_le_bytes();
79+
match result_checksum == checksum {
7880
true => Ok(output),
79-
false => Err(InvalidInput("CRC checksum mismatched!".to_string()))
81+
false => Err(InvalidInput("CRC checksum mismatched!".to_string())),
8082
}
8183
}
8284

@@ -102,8 +104,7 @@ impl Xtea {
102104
String::from_utf8(ouput_writer.get_mut().to_owned()).map_err(XteaError::TextEncodingError)
103105
}
104106

105-
pub fn encrypt_text_file(input_string: String) -> Result<Vec<u8>, XteaError>{
106-
107+
pub fn encrypt_text_file(input_string: String) -> Result<Vec<u8>, XteaError> {
107108
//get the input buffer and trim any trailing zeros
108109
let mut input_buffer = input_string.trim_end_matches('\0').as_bytes().to_vec();
109110
let checksum = crc32fast::hash(&input_buffer);
@@ -124,7 +125,8 @@ impl Xtea {
124125
let mut final_buffer = Vec::new();
125126
final_buffer.extend_from_slice(&Self::DEFAULT_ENCRYPTED_HEADER);
126127

127-
final_buffer.write_u32::<LittleEndian>(checksum)
128+
final_buffer
129+
.write_u32::<LittleEndian>(checksum)
128130
.map_err(XteaError::XteaEncodingError)?;
129131

130132
final_buffer.extend_from_slice(&out_buffer);

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![doc(html_root_url = "https://docs.rs/rpkg-rs/1.1.0")]
1+
#![doc(html_root_url = "https://docs.rs/rpkg-rs/1.1.1")]
22
//! `rpkg-rs` provides comprehensive functionality for interacting with `ResourcePackage` (rpkg) files found within Hitman games.
33
//! This crate facilitates parsing of these files, enabling seamless access to the contained resource files.
44
//! By parsing configuration files such as `thumbs.ini` and `packagedefintion.txt`, rpkg-rs offers extensive support for reading and manipulating these packages.

src/resource/package_builder.rs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use indexmap::{IndexMap, IndexSet};
2121
use lzzzz::{lz4, lz4_hc};
2222
use thiserror::Error;
2323

24-
/// `PackageResourceBlob` is an enum representing various types of package resource stores, which can
24+
/// `PackageResourceBlob` is an enum representing various types of package resource stores, which can
2525
/// include files, file sections, and memory buffers, optionally compressed or scrambled.
2626
enum PackageResourceBlob {
2727
File {
@@ -450,8 +450,8 @@ impl PackageBuilder {
450450
Self {
451451
partition_id: PartitionId {
452452
part_type: match chunk_type {
453-
ChunkType::Standard => { PartitionType::Standard }
454-
ChunkType::Addon => { PartitionType::Addon }
453+
ChunkType::Standard => PartitionType::Standard,
454+
ChunkType::Addon => PartitionType::Addon,
455455
},
456456
index: chunk_id as usize,
457457
},
@@ -467,10 +467,7 @@ impl PackageBuilder {
467467
/// # Arguments
468468
/// * `partition_id` - The partition id of the package.
469469
/// * `patch_id` - The patch id of the package.
470-
pub fn new_with_patch_id(
471-
partition_id: PartitionId,
472-
patch_id: PatchId,
473-
) -> Self {
470+
pub fn new_with_patch_id(partition_id: PartitionId, patch_id: PatchId) -> Self {
474471
Self {
475472
partition_id,
476473
patch_id,
@@ -498,9 +495,10 @@ impl PackageBuilder {
498495
.metadata
499496
.as_ref()
500497
.map(|m| m.chunk_type)
501-
.unwrap_or_default() {
502-
ChunkType::Standard => { PartitionType::Standard }
503-
ChunkType::Addon => { PartitionType::Addon }
498+
.unwrap_or_default()
499+
{
500+
ChunkType::Standard => PartitionType::Standard,
501+
ChunkType::Addon => PartitionType::Addon,
504502
},
505503
index: resource_package
506504
.metadata
@@ -512,9 +510,10 @@ impl PackageBuilder {
512510
.metadata
513511
.as_ref()
514512
.map(|m| m.patch_id)
515-
.unwrap_or_default() {
513+
.unwrap_or_default()
514+
{
516515
0 => PatchId::Base,
517-
x => PatchId::Patch(x as usize)
516+
x => PatchId::Patch(x as usize),
518517
},
519518
use_legacy_references: false,
520519
resources: IndexMap::new(),
@@ -533,7 +532,7 @@ impl PackageBuilder {
533532
resource.compressed_size(),
534533
resource.is_scrambled(),
535534
)
536-
.map_err(|e| PackageBuilderError::CannotDuplicateResource(*rrid, e))?
535+
.map_err(|e| PackageBuilderError::CannotDuplicateResource(*rrid, e))?
537536
}
538537

539538
ResourcePackageSource::Memory(source_data) => {
@@ -557,7 +556,7 @@ impl PackageBuilder {
557556
decompressed_size,
558557
resource.is_scrambled(),
559558
)
560-
.map_err(|e| PackageBuilderError::CannotDuplicateResource(*rrid, e))?
559+
.map_err(|e| PackageBuilderError::CannotDuplicateResource(*rrid, e))?
561560
}
562561
};
563562

@@ -625,7 +624,7 @@ impl PackageBuilder {
625624
data: &T,
626625
) -> Result<(), PackageBuilderError>
627626
where
628-
for<'a> T::Args<'a>: Required,
627+
for<'a> T::Args<'a>: Required,
629628
{
630629
let current_offset = writer
631630
.stream_position()
@@ -813,12 +812,12 @@ impl PackageBuilder {
813812
unknown: 1,
814813
chunk_id: self.partition_id.index as u8,
815814
chunk_type: match self.partition_id.part_type {
816-
PartitionType::Addon => { ChunkType::Addon }
817-
_ => { ChunkType::Standard }
815+
PartitionType::Addon => ChunkType::Addon,
816+
_ => ChunkType::Standard,
818817
},
819818
patch_id: match self.patch_id {
820-
PatchId::Base => { 0 }
821-
PatchId::Patch(x) => { x as u8 }
819+
PatchId::Base => 0,
820+
PatchId::Patch(x) => x as u8,
822821
},
823822
language_tag: *b"xx",
824823
}),
@@ -839,7 +838,8 @@ impl PackageBuilder {
839838
.map_err(PackageBuilderError::SerializationError)?;
840839

841840
let offset_table_result = self.write_offset_table(writer)?;
842-
let metadata_table_result = self.write_metadata_table(writer, self.use_legacy_references)?;
841+
let metadata_table_result =
842+
self.write_metadata_table(writer, self.use_legacy_references)?;
843843

844844
// Now that we're done writing the tables, let's patch the header.
845845
header.header.offset_table_size = offset_table_result.offset_table_size;
@@ -1014,8 +1014,8 @@ impl PackageBuilder {
10141014
output_path: &Path,
10151015
) -> Result<(), PackageBuilderError> {
10161016
let output_file = match output_path.is_dir() {
1017-
true => { output_path.join(self.partition_id.to_filename(self.patch_id)) }
1018-
false => { output_path.to_path_buf() }
1017+
true => output_path.join(self.partition_id.to_filename(self.patch_id)),
1018+
false => output_path.to_path_buf(),
10191019
};
10201020

10211021
let mut file = File::create(output_file).map_err(PackageBuilderError::IoError)?;
@@ -1028,10 +1028,7 @@ impl PackageBuilder {
10281028
/// * `version` - The version of the package to build.
10291029
/// * `is_patch` - Whether the package is a patch package.
10301030
/// * `legacy_references` - Whether to use the legacy references format.
1031-
pub fn build_in_memory(
1032-
self,
1033-
version: PackageVersion,
1034-
) -> Result<Vec<u8>, PackageBuilderError> {
1031+
pub fn build_in_memory(self, version: PackageVersion) -> Result<Vec<u8>, PackageBuilderError> {
10351032
let mut writer = Cursor::new(vec![]);
10361033
self.build_internal(version, &mut writer)?;
10371034
Ok(writer.into_inner())

src/resource/partition_manager.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,18 @@ impl PartitionManager {
279279
}
280280
}
281281

282-
#[deprecated(since="1.0.0", note="prefer direct access through the partitions field")]
283-
pub fn partitions(&self) -> &Vec<ResourcePartition>{
282+
#[deprecated(
283+
since = "1.0.0",
284+
note = "prefer direct access through the partitions field"
285+
)]
286+
pub fn partitions(&self) -> &Vec<ResourcePartition> {
284287
&self.partitions
285288
}
286289

287-
#[deprecated(since="1.1.0", note="please implement this yourself, it is out of scope for this struct")]
290+
#[deprecated(
291+
since = "1.1.0",
292+
note = "please implement this yourself, it is out of scope for this struct"
293+
)]
288294
pub fn print_resource_changelog(&self, rrid: &RuntimeResourceID) {
289295
println!("Resource: {rrid}");
290296

src/resource/pdefs/mod.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use thiserror::Error;
1010
use crate::encryption::xtea::XteaError;
1111
use crate::misc::ini_file_system::{IniFileError, IniFileSystem};
1212
use crate::misc::resource_id::ResourceID;
13+
use crate::resource::pdefs::GameDiscoveryError::InvalidRuntimePath;
1314
use crate::resource::pdefs::PackageDefinitionSource::{HM2, HM2016, HM3};
1415
use crate::resource::pdefs::PartitionType::{Dlc, LanguageDlc, LanguageStandard, Standard};
1516
use crate::resource::resource_partition::PatchId;
1617
use crate::{utils, WoaVersion};
17-
use crate::resource::pdefs::GameDiscoveryError::InvalidRuntimePath;
1818

1919
pub mod h2016_parser;
2020
pub mod hm2_parser;
@@ -192,34 +192,40 @@ impl PartitionInfo {
192192
self.id.to_filename(patch_index)
193193
}
194194

195-
#[deprecated(since="1.1.0", note="you can push to the roots field directly")]
195+
#[deprecated(since = "1.1.0", note = "you can push to the roots field directly")]
196196
pub fn add_root(&mut self, resource_id: ResourceID) {
197197
self.roots.push(resource_id);
198198
}
199-
#[deprecated(since="1.1.0", note="prefer direct access through the roots field")]
199+
#[deprecated(since = "1.1.0", note = "prefer direct access through the roots field")]
200200
pub fn roots(&self) -> &Vec<ResourceID> {
201201
&self.roots
202202
}
203203

204-
#[deprecated(since="1.1.0", note="prefer direct access through the name field")]
204+
#[deprecated(since = "1.1.0", note = "prefer direct access through the name field")]
205205
pub fn name(&self) -> &Option<String> {
206206
&self.name
207207
}
208-
209-
#[deprecated(since="1.1.0", note="prefer direct access through the parent field")]
208+
209+
#[deprecated(
210+
since = "1.1.0",
211+
note = "prefer direct access through the parent field"
212+
)]
210213
pub fn parent(&self) -> &Option<PartitionId> {
211214
&self.parent
212215
}
213216

214-
#[deprecated(since="1.1.0", note="prefer direct access through the id field")]
217+
#[deprecated(since = "1.1.0", note = "prefer direct access through the id field")]
215218
pub fn id(&self) -> PartitionId {
216219
self.id.clone()
217220
}
218-
#[deprecated(since="1.1.0", note="prefer direct access through the patch_level field")]
221+
#[deprecated(
222+
since = "1.1.0",
223+
note = "prefer direct access through the patch_level field"
224+
)]
219225
pub fn max_patch_level(&self) -> usize {
220226
self.patch_level
221227
}
222-
228+
223229
pub fn set_max_patch_level(&mut self, patch_level: usize) {
224230
self.patch_level = patch_level
225231
}
@@ -293,7 +299,7 @@ pub enum GameDiscoveryError {
293299

294300
#[error("No PROJECT_PATH found in thumbs.dat")]
295301
NoProjectPath,
296-
302+
297303
#[error("The Runtime path cannot be found")]
298304
InvalidRuntimePath,
299305

@@ -325,11 +331,15 @@ impl GamePaths {
325331
let mut runtime_path = retail_directory
326332
.join(project_path.replace("\\", "/"))
327333
.join(relative_runtime_path);
328-
if !runtime_path.exists(){
329-
runtime_path = retail_directory.join(project_path.replace("\\", "/")).join(utils::uppercase_first_letter(relative_runtime_path));
334+
if !runtime_path.exists() {
335+
runtime_path = retail_directory
336+
.join(project_path.replace("\\", "/"))
337+
.join(utils::uppercase_first_letter(relative_runtime_path));
330338
}
331-
332-
runtime_path = runtime_path.canonicalize().map_err(|_| InvalidRuntimePath)?;
339+
340+
runtime_path = runtime_path
341+
.canonicalize()
342+
.map_err(|_| InvalidRuntimePath)?;
333343
let package_definition_path = runtime_path.join("packagedefinition.txt");
334344

335345
Ok(Self {

0 commit comments

Comments
 (0)