diff --git a/src-tauri/build.rs b/src-tauri/build.rs index 4d4f01a..2286366 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -2,17 +2,14 @@ fn main() { cc::Build::new() .include("mhycrypto") .cpp(true) - .file("mhycrypto/memecrypto.cpp") .file("mhycrypto/metadata.cpp") .file("mhycrypto/metadatastringdec.cpp") - .compile("mhycrypto"); - cc::Build::new() + cc::Build::new() .include("mhycrypto") .file("mhycrypto/aes.c") - .compile("mhycrypto-aes"); tauri_build::build() diff --git a/src-tauri/mhycrypto/metadata.cpp b/src-tauri/mhycrypto/metadata.cpp index b517b89..392112b 100644 --- a/src-tauri/mhycrypto/metadata.cpp +++ b/src-tauri/mhycrypto/metadata.cpp @@ -43,7 +43,7 @@ bool gen_global_metadata_key(uint8_t* src, size_t srcn) { uint64_t* key = (uint64_t*)src; - for (int i = 0; i < srcn / sizeof(uint64_t); i++) + for (size_t i = 0; i < srcn / sizeof(uint64_t); i++) key[i] = rand(); *(uint16_t *) (src + 0xc8) = 0xfc2e; // Magic diff --git a/src-tauri/src/file_helpers.rs b/src-tauri/src/file_helpers.rs index bcfeaee..20e6ff4 100644 --- a/src-tauri/src/file_helpers.rs +++ b/src-tauri/src/file_helpers.rs @@ -1,6 +1,6 @@ -use std::fs; use file_diff::diff; -use std::{io::{Read, Write}}; +use std::fs; +use std::io::{Read, Write}; #[tauri::command] pub fn rename(path: String, new_name: String) { @@ -142,7 +142,7 @@ pub fn write_file(path: String, contents: String) { Ok(file) => file, Err(e) => { println!("Failed to open file: {}", e); - + // attempt to create file. otherwise return match fs::File::create(&path_buf) { Ok(file) => file, @@ -159,7 +159,6 @@ pub fn write_file(path: String, contents: String) { Ok(_) => (), Err(e) => { println!("Failed to write to file: {}", e); - return; } } -} \ No newline at end of file +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 3883c69..63c45f9 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -13,12 +13,12 @@ use sysinfo::{System, SystemExt}; mod downloader; mod file_helpers; mod lang; +mod metadata_patcher; mod proxy; mod structs; mod system_helpers; mod unzip; mod web; -mod metadata_patcher; static WATCH_GAME_PROCESS: Lazy> = Lazy::new(|| Mutex::new(String::new())); @@ -73,7 +73,7 @@ fn is_game_running() -> bool { } #[tauri::command] -fn enable_process_watcher(window: tauri::Window,process: String) { +fn enable_process_watcher(window: tauri::Window, process: String) { *WATCH_GAME_PROCESS.lock().unwrap() = process; window.listen("disable_process_watcher", |_e| { diff --git a/src-tauri/src/metadata_patcher.rs b/src-tauri/src/metadata_patcher.rs index c0c40da..d551330 100644 --- a/src-tauri/src/metadata_patcher.rs +++ b/src-tauri/src/metadata_patcher.rs @@ -4,19 +4,25 @@ use std::fs::OpenOptions; use std::io::Read; use std::io::Write; -extern { - fn decrypt_global_metadata(data : *mut u8, size : u64); - fn encrypt_global_metadata(data : *mut u8, size : u64); +extern "C" { + fn decrypt_global_metadata(data: *mut u8, size: u64); + fn encrypt_global_metadata(data: *mut u8, size: u64); } -fn dll_decrypt_global_metadata(data : *mut u8, size : u64) -> Result> { +fn dll_decrypt_global_metadata( + data: *mut u8, + size: u64, +) -> Result> { unsafe { decrypt_global_metadata(data, size); Ok(true) } } -fn dll_encrypt_global_metadata(data : *mut u8, size : u64) -> Result> { +fn dll_encrypt_global_metadata( + data: *mut u8, + size: u64, +) -> Result> { unsafe { encrypt_global_metadata(data, size); Ok(true) @@ -46,7 +52,11 @@ pub fn patch_metadata(metadata_folder: &str) -> bool { } //write encrypted to file - let mut file = match OpenOptions::new().create(true).write(true).open(&(metadata_folder.to_owned() + "\\global-metadata-patched.dat")) { + let mut file = match OpenOptions::new() + .create(true) + .write(true) + .open(&(metadata_folder.to_owned() + "\\global-metadata-patched.dat")) + { Ok(file) => file, Err(e) => { println!("Failed to open global-metadata: {}", e); @@ -55,7 +65,7 @@ pub fn patch_metadata(metadata_folder: &str) -> bool { }; file.write_all(&encrypted).unwrap(); - + true } @@ -82,13 +92,13 @@ fn decrypt_metadata(file_path: &str) -> Vec { match dll_decrypt_global_metadata(data.as_mut_ptr(), data.len().try_into().unwrap()) { Ok(_) => { println!("Successfully decrypted global-metadata"); - return data; + data } Err(e) => { println!("Failed to decrypt global-metadata: {}", e); - return Vec::new(); + Vec::new() } - }; + } } fn replace_keys(data: &[u8]) -> Vec { @@ -143,16 +153,16 @@ fn encrypt_metadata(old_data: &[u8]) -> Vec { match dll_encrypt_global_metadata(data.as_mut_ptr(), data.len().try_into().unwrap()) { Ok(_) => { println!("Successfully encrypted global-metadata"); - return data; + data } Err(e) => { println!("Failed to encrypt global-metadata: {}", e); - return Vec::new(); + Vec::new() } - }; + } } fn do_vecs_match(a: &Vec, b: &Vec) -> bool { let matching = a.iter().zip(b.iter()).filter(|&(a, b)| a == b).count(); matching == a.len() && matching == b.len() -} \ No newline at end of file +}