diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index 839901883..cb5f48257 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -1,3 +1,5 @@ +#![feature(lazy_cell)] + use std::{ collections::{HashMap, HashSet}, path::PathBuf, diff --git a/src/api/lua.rs b/src/api/lua.rs index 4a43c19e1..60e6f7555 100644 --- a/src/api/lua.rs +++ b/src/api/lua.rs @@ -5,14 +5,14 @@ use std::ffi::CString; pub extern "C" fn arcorp_add_lua_menu_manager(name: *mut i8, reg_vec_ptr: *mut luaL_Reg_from_api, reg_vec_size: usize, reg_vec_cap: usize) -> bool { debug!("arcorp_add_lua_menu_manager -> Function called"); unsafe { - match CString::from_raw(name).to_str() { + match CString::from_raw(name as _).to_str() { Ok(s) => { let name = s.to_string(); let registry = Vec::from_raw_parts(reg_vec_ptr, reg_vec_size, reg_vec_cap); let functions = registry.iter().map(|x| { luaL_Reg_container { - name: CString::from_raw(x.name).to_str().unwrap().to_string(), + name: CString::from_raw(x.name as _).to_str().unwrap().to_string(), func: x.func } }).collect::>(); @@ -31,14 +31,14 @@ pub extern "C" fn arcorp_add_lua_menu_manager(name: *mut i8, reg_vec_ptr: *mut l pub extern "C" fn arcorp_add_lua_ingame_manager(name: *mut i8, reg_vec_ptr: *mut luaL_Reg_from_api, reg_vec_size: usize, reg_vec_cap: usize) -> bool { debug!("arcorp_add_lua_ingame_manager -> Function called"); unsafe { - match CString::from_raw(name).to_str() { + match CString::from_raw(name as _).to_str() { Ok(s) => { let name = s.to_string(); let registry = Vec::from_raw_parts(reg_vec_ptr, reg_vec_size, reg_vec_cap); let functions = registry.iter().map(|x| { luaL_Reg_container { - name: CString::from_raw(x.name).to_str().unwrap().to_string(), + name: CString::from_raw(x.name as _).to_str().unwrap().to_string(), func: x.func } }).collect::>(); @@ -97,5 +97,5 @@ pub extern "C" fn arcrop_lua_state_push_nil(lua_state: &mut lua_state) { #[no_mangle] pub extern "C" fn arcrop_lua_state_push_string(lua_state: &mut lua_state, str: *mut i8) { debug!("arcrop_lua_state_push_string -> Function called"); - unsafe { lua_state.push_string(CString::from_raw(str).to_str().expect("Failed to get string from str pointer!")); } + unsafe { lua_state.push_string(CString::from_raw(str as _).to_str().expect("Failed to get string from str pointer!")); } } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index a1a3dca0b..9fc7f00de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,8 @@ // #![feature(fs_try_exists)] #![feature(int_roundings)] +#![feature(lazy_cell)] + use std::{ collections::HashMap, fmt, io::{BufWriter, Write}, path::{Path, PathBuf}, str::FromStr, sync::{LazyLock, RwLock} }; diff --git a/src/offsets.rs b/src/offsets.rs index e6dc68513..3614ac4c9 100644 --- a/src/offsets.rs +++ b/src/offsets.rs @@ -429,6 +429,21 @@ static LUA_PUSHSTRING_CODE: (&[u8], isize) = ( -0x38, ); +static LOAD_STREAM_CODE: (&[u8], isize) = ( + &[ + 0xfc, 0x6f, 0xba, 0xa9, + 0xfa, 0x67, 0x01, 0xa9, + 0xf8, 0x5f, 0x02, 0xa9, + 0xf6, 0x57, 0x03, 0xa9, + 0xf4, 0x4f, 0x04, 0xa9, + 0xfd, 0x7b, 0x05, 0xa9, + 0xfd, 0x43, 0x01, 0x91, + 0xff, 0xc3, 0x1b, 0xd1, + 0xe8, 0x63, 0x05, 0x91 + ], + 0 +); + #[allow(clippy::inconsistent_digit_grouping)] fn offset_from_adrp(adrp_offset: usize) -> usize { unsafe { @@ -536,6 +551,7 @@ generate_members! { declare_namespace: usize, add_method: usize, lua_pushstring: usize, + load_stream: usize, } } @@ -584,6 +600,7 @@ impl Offsets { let declare_namespace = get_offset_neon(text, DECLARE_NAMESPACE_CODE); let add_method = get_offset_neon(text, ADD_METHOD_CODE); let lua_pushstring = get_offset_neon(text, LUA_PUSHSTRING_CODE); + let load_stream = get_offset_neon(text, LOAD_STREAM_CODE); let filesystem_info = { let adrp = get_offset_neon(text, FILESYSTEM_INFO_ADRP_SEARCH_CODE); @@ -671,6 +688,7 @@ impl Offsets { declare_namespace, add_method, lua_pushstring, + load_stream }) } } diff --git a/src/replacement/stream.rs b/src/replacement/stream.rs index 84e95d540..0bc597252 100644 --- a/src/replacement/stream.rs +++ b/src/replacement/stream.rs @@ -38,5 +38,11 @@ fn lookup_stream_hash(out_path: *mut c_char, loaded_arc: &LoadedArc, size_out: & } pub fn install() { + let base = offsets::load_stream(); + + skyline::patching::Patch::in_text(base + 0x84).nop().unwrap(); // Patch out first `offset_out == 0` check + skyline::patching::Patch::in_text(base + 0x154).nop().unwrap(); // Patch out second `offset_out == 0` check + skyline::patching::Patch::in_text(base + 0x230).nop().unwrap(); // Patch out third `offfset_out == 0` check + skyline::install_hooks!(lookup_stream_hash); }