Skip to content

Commit

Permalink
Patch out offset_out checks for Smash Appeal files
Browse files Browse the repository at this point in the history
Change some stuff to get compilation working
  • Loading branch information
Coolsonickirby committed Jan 28, 2025
1 parent 65e9f49 commit 9d0b854
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(lazy_cell)]

use std::{
collections::{HashMap, HashSet},
path::PathBuf,
Expand Down
10 changes: 5 additions & 5 deletions src/api/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<luaL_Reg_container>>();
Expand All @@ -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::<Vec<luaL_Reg_container>>();
Expand Down Expand Up @@ -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!")); }
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
};
Expand Down
18 changes: 18 additions & 0 deletions src/offsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -536,6 +551,7 @@ generate_members! {
declare_namespace: usize,
add_method: usize,
lua_pushstring: usize,
load_stream: usize,
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -671,6 +688,7 @@ impl Offsets {
declare_namespace,
add_method,
lua_pushstring,
load_stream
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/replacement/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 9d0b854

Please sign in to comment.