mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 10:54:38 +00:00
break get_oodle into separate package
This commit is contained in:
parent
63396ac9f6
commit
6805b5c142
5 changed files with 56 additions and 49 deletions
|
@ -14,6 +14,7 @@ aes = "0.8.2"
|
||||||
base64 = "0.21.0"
|
base64 = "0.21.0"
|
||||||
strum = { version = "0.24", features = ["derive"] }
|
strum = { version = "0.24", features = ["derive"] }
|
||||||
sha1 = "0.10"
|
sha1 = "0.10"
|
||||||
|
hex = "0.4"
|
||||||
|
|
||||||
# generated by 'cargo dist init'
|
# generated by 'cargo dist init'
|
||||||
[profile.dist]
|
[profile.dist]
|
||||||
|
|
16
get_oodle/Cargo.toml
Normal file
16
get_oodle/Cargo.toml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
[package]
|
||||||
|
name = "get_oodle"
|
||||||
|
repository.workspace = true
|
||||||
|
authors.workspace = true
|
||||||
|
license.workspace = true
|
||||||
|
version.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
repak = { path = "../repak" }
|
||||||
|
sha1 = { workspace = true }
|
||||||
|
ureq = "2.6"
|
||||||
|
once_cell = "1.17"
|
||||||
|
hex-literal = "0.4"
|
||||||
|
libloading = "0.7"
|
||||||
|
hex = { workspace = true }
|
35
get_oodle/src/lib.rs
Normal file
35
get_oodle/src/lib.rs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
pub fn decompress() -> repak::Decompress {
|
||||||
|
*unsafe { OODLE.as_ref().unwrap().get(b"OodleLZ_Decompress") }.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
|
static OODLE: Lazy<Result<libloading::Library, String>> =
|
||||||
|
Lazy::new(|| get_oodle().map_err(|e| e.to_string()));
|
||||||
|
static OODLE_HASH: [u8; 20] = hex_literal::hex!("4bcc73614cb8fd2b0bce8d0f91ee5f3202d9d624");
|
||||||
|
|
||||||
|
fn get_oodle() -> Result<libloading::Library, repak::Error> {
|
||||||
|
use sha1::{Digest, Sha1};
|
||||||
|
|
||||||
|
let oodle = std::env::current_exe()?.with_file_name("oo2core_9_win64.dll");
|
||||||
|
if !oodle.exists() {
|
||||||
|
let mut data = vec![];
|
||||||
|
ureq::get("https://cdn.discordapp.com/attachments/817251677086285848/992648087371792404/oo2core_9_win64.dll")
|
||||||
|
.call().map_err(|e| repak::Error::Other(e.to_string()))?
|
||||||
|
.into_reader().read_to_end(&mut data)?;
|
||||||
|
|
||||||
|
std::fs::write(&oodle, data)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut hasher = Sha1::new();
|
||||||
|
hasher.update(std::fs::read(&oodle)?);
|
||||||
|
let hash = hasher.finalize();
|
||||||
|
(hash[..] == OODLE_HASH).then_some(()).ok_or_else(|| {
|
||||||
|
repak::Error::Other(format!(
|
||||||
|
"oodle hash mismatch expected: {} got: {} ",
|
||||||
|
hex::encode(OODLE_HASH),
|
||||||
|
hex::encode(hash)
|
||||||
|
))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
unsafe { libloading::Library::new(oodle) }.map_err(|_| repak::Error::OodleFailed)
|
||||||
|
}
|
|
@ -12,20 +12,16 @@ path = "src/main.rs"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
repak = { path = "../repak", features = ["oodle"] }
|
repak = { path = "../repak", features = ["oodle"] }
|
||||||
sha1 = { workspace = true }
|
|
||||||
ureq = "2.6"
|
|
||||||
once_cell = "1.17"
|
|
||||||
hex-literal = "0.4"
|
|
||||||
libloading = "0.7"
|
|
||||||
|
|
||||||
[target.'cfg(not(windows))'.dependencies]
|
[target.'cfg(not(windows))'.dependencies]
|
||||||
repak = { path = "../repak" }
|
repak = { path = "../repak" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
get_oodle = { path = "../get_oodle" }
|
||||||
aes = { workspace = true }
|
aes = { workspace = true }
|
||||||
base64 = { workspace = true }
|
base64 = { workspace = true }
|
||||||
clap = { version = "4.1.4", features = ["derive"] }
|
clap = { version = "4.1.4", features = ["derive"] }
|
||||||
hex = "0.4.3"
|
hex = { workspace = true }
|
||||||
indicatif = { version = "0.17.3", features = ["rayon"] }
|
indicatif = { version = "0.17.3", features = ["rayon"] }
|
||||||
path-clean = "0.1.0"
|
path-clean = "0.1.0"
|
||||||
path-slash = "0.2.1"
|
path-slash = "0.2.1"
|
||||||
|
|
|
@ -284,7 +284,7 @@ fn unpack(aes_key: Option<aes::Aes256>, action: ActionUnpack) -> Result<(), repa
|
||||||
for input in &action.input {
|
for input in &action.input {
|
||||||
let mut builder = repak::PakBuilder::new();
|
let mut builder = repak::PakBuilder::new();
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
builder.oodle(decompress);
|
builder.oodle(get_oodle::decompress);
|
||||||
if let Some(aes_key) = aes_key.clone() {
|
if let Some(aes_key) = aes_key.clone() {
|
||||||
builder.key(aes_key)
|
builder.key(aes_key)
|
||||||
}
|
}
|
||||||
|
@ -457,7 +457,7 @@ fn get(aes_key: Option<aes::Aes256>, args: ActionGet) -> Result<(), repak::Error
|
||||||
let mut reader = BufReader::new(File::open(&args.input)?);
|
let mut reader = BufReader::new(File::open(&args.input)?);
|
||||||
let mut builder = repak::PakBuilder::new();
|
let mut builder = repak::PakBuilder::new();
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
builder.oodle(decompress);
|
builder.oodle(get_oodle::decompress);
|
||||||
if let Some(aes_key) = aes_key {
|
if let Some(aes_key) = aes_key {
|
||||||
builder.key(aes_key)
|
builder.key(aes_key)
|
||||||
}
|
}
|
||||||
|
@ -477,44 +477,3 @@ fn get(aes_key: Option<aes::Aes256>, args: ActionGet) -> Result<(), repak::Error
|
||||||
std::io::stdout().write_all(&pak.get(&file.to_slash_lossy(), &mut reader)?)?;
|
std::io::stdout().write_all(&pak.get(&file.to_slash_lossy(), &mut reader)?)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn decompress() -> repak::Decompress {
|
|
||||||
*unsafe { OODLE.as_ref().unwrap().get(b"OodleLZ_Decompress") }.unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
#[cfg(windows)]
|
|
||||||
static OODLE: Lazy<Result<libloading::Library, String>> =
|
|
||||||
Lazy::new(|| get_oodle().map_err(|e| e.to_string()));
|
|
||||||
#[cfg(windows)]
|
|
||||||
static OODLE_HASH: [u8; 20] = hex_literal::hex!("4bcc73614cb8fd2b0bce8d0f91ee5f3202d9d624");
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn get_oodle() -> Result<libloading::Library, repak::Error> {
|
|
||||||
use sha1::{Digest, Sha1};
|
|
||||||
|
|
||||||
let oodle = std::env::current_exe()?.with_file_name("oo2core_9_win64.dll");
|
|
||||||
if !oodle.exists() {
|
|
||||||
let mut data = vec![];
|
|
||||||
ureq::get("https://cdn.discordapp.com/attachments/817251677086285848/992648087371792404/oo2core_9_win64.dll")
|
|
||||||
.call().map_err(|e| repak::Error::Other(e.to_string()))?
|
|
||||||
.into_reader().read_to_end(&mut data)?;
|
|
||||||
|
|
||||||
std::fs::write(&oodle, data)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut hasher = Sha1::new();
|
|
||||||
hasher.update(std::fs::read(&oodle)?);
|
|
||||||
let hash = hasher.finalize();
|
|
||||||
(hash[..] == OODLE_HASH).then_some(()).ok_or_else(|| {
|
|
||||||
repak::Error::Other(format!(
|
|
||||||
"oodle hash mismatch expected: {} got: {} ",
|
|
||||||
hex::encode(OODLE_HASH),
|
|
||||||
hex::encode(hash)
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
unsafe { libloading::Library::new(oodle) }.map_err(|_| repak::Error::OodleFailed)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue