rpkg-rs 1.3.1

Parse Glacier ResourcePackage (rpkg) files, allowing access to the resources stored within.
Documentation
use std::io::Write;
use std::path::Path;
use std::io;
use rpkg_rs::resource::package_builder::PackageResourceBuilder;
use rpkg_rs::resource::partition_manager::{PartitionManager, PartitionState};
use rpkg_rs::resource::pdefs::{GamePaths, PackageDefinitionSource};
use rpkg_rs::resource::resource_package::{ResourceReferenceFlags, ResourceReferenceFlagsStandard};
use rpkg_rs::resource::runtime_resource_id::RuntimeResourceID;
use rpkg_rs::WoaVersion;

fn main() {
    let game_version = WoaVersion::HM2;
    let retail_path = Path::new("/media/dafitius/980 PRO/SteamLibrary/steamapps/common/HITMAN2/Retail/").to_path_buf();
    // let game_version = WoaVersion::HM3;
    // let retail_path = Path::new("/media/dafitius/980 PRO/SteamLibrary/steamapps/common/HITMAN 3/Retail/").to_path_buf();

    // Discover the game paths.
    let game_paths = GamePaths::from_retail_directory(retail_path.clone()).unwrap_or_else(|e| {
        eprintln!("failed to discover game paths: {}", e);
        std::process::exit(0);
    });

    // Read and parse the package definition.
    let package_definition_source =
        PackageDefinitionSource::from_file(game_paths.package_definition_path, game_version)
            .unwrap_or_else(|e| {
                eprintln!("failed to parse package definition: {}", e);
                std::process::exit(0);
            });

    let mut partition_infos = package_definition_source.read().unwrap_or_else(|e| {
        eprintln!("failed to read package definition: {}", e);
        std::process::exit(0);
    });

    // Ignore modded patches.
    for partition in partition_infos.iter_mut() {
        partition.set_max_patch_level(9);
    }

    let mut package_manager =
        PartitionManager::new(game_paths.runtime_path, &package_definition_source).unwrap_or_else(
            |e| {
                eprintln!("failed to init package manager: {}", e);
                std::process::exit(0);
            },
        );

    //read the packagedefs here
    let mut last_index = 0;
    let mut progress = 0.0;
    let progress_callback = |current, state: &PartitionState| {
        if current != last_index {
            last_index = current;
            print!("Mounting partition {} ", current);
        }
        if !state.installing && !state.mounted {
            println!("[Failed to mount this partition. Is it installed?]");
        }
        let install_progress = (state.install_progress * 10.0).ceil() / 10.0;

        let chars_to_add = (install_progress * 10.0 - progress * 10.0) as usize * 2;
        let chars_to_add = std::cmp::min(chars_to_add, 20);
        print!("{}", "".repeat(chars_to_add));
        io::stdout().flush().unwrap();

        progress = install_progress;

        if progress == 1.0 {
            progress = 0.0;

            if state.mounted {
                println!(" done :)");
            } else {
                println!(" failed :(");
            }
        }
    };

    package_manager
        .mount_partitions(progress_callback)
        .unwrap_or_else(|e| {
            eprintln!("failed to mount partitions: {}", e);
            std::process::exit(0);
        });
    
    for resource in package_manager.iter_all_runtime_resource_ids(){
        let partitions = package_manager.partitions_with_resource(resource);
        if partitions.len() > 1{
            println!("Found {} in multiple partitions", resource);
            for partition in partitions{
                println!("Should be in {}", partition)
            }
            for attempt in package_manager.partitions.iter(){
                let partition_attempt = &attempt.partition_info().id;
                if let Ok((info, partition)) = package_manager.resolve_resource_from(partition_attempt.clone(), resource){
                    let mut r = PackageResourceBuilder::from_memory(RuntimeResourceID::from_hex_string("00ACBDEF12345").unwrap(), &"TEST", vec![], Some(12), false).unwrap();
                    r.with_references(info.references());
                    println!("From {} you can find {} in {}", partition_attempt, info.rrid(), partition);
                };
            }
        }
    }
}