Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13.0.2 Support #565

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/fixes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@ fn install_added_color_patches() {
*/
// OFFSETS ARE CURRENTLY HARDCODED TO VERSION 13.0.1
static ADDED_COLOR_PATCHES: &[(usize, u32)] = &[
(0x1834b0c, 0xF104027F), // cmp x19, #256 (Issue related to Aegis)
(0x18347bc, 0xF104027F), // cmp x19, #256 (Issue related to Aegis)
(0x1834b28, 0xF104011F), // cmp x8, #256 (Issue related to Aegis)
(0x1834ef8, 0xF10402FF), // cmp x23, #256 (Issue related to Aegis)
(0x183538c, 0xF104011F), // cmp x8, #256 (Issue related to Aegis)
(0x1835ae4, 0xF104027F), // cmp x19, #256 (Issue related to Aegis)
(0x1835e00, 0xF104013F), // cmp x9, #256 (Issue related to Aegis)
(0x1a1c2f0, 0xF104011F), // cmp x8, #256 (Issue related to Aegis)
(0x1a1c334, 0xF104011F), // cmp x8, #256 (Issue related to Aegis)
(0x14de340, 0x7104013F), // cmp w9, #256 (Issue related to Terry)
(0x14e1410, 0x710402FF), // cmp w23, #256 (Issue related to Terry)
(0x14e159c, 0x7104011F), // cmp w8, #256 (Issue related to Terry)
(0x1a55584, 0x52800020), // mov w0, #1 (Issue related to Tourney Mode Crash)
(0x1a556b4, 0xF104011F), // cmp x8, #256 (Issue related to Tourney Mode Crash)
(0x1a54f74, 0x7104015F), // cmp w10, #256 (Issue related to Tourney Mode Crash)
(0x1a5500c, 0x7104001F), // cmp w0, #256 (Issue related to Tourney Mode Crash)
(0x1a55038, 0xF104001F), // cmp x0, #256 (Issue related to Tourney Mode Crash)
(0x1a54fa0, 0xF104001F), // cmp x0, #256 (Issue related to Tourney Mode Crash)
(0x1a54fd4, 0x7104017F), // cmp w11, #256 (Issue related to Tourney Mode Crash)
(0x18355dc, 0xF104027F), // cmp x19, #256 (Issue related to Aegis)
(0x183529c, 0xF104027F), // cmp x19, #256 (Issue related to Aegis)
(0x1835608, 0xF104011F), // cmp x8, #256 (Issue related to Aegis)
(0x18359d8, 0xF10402FF), // cmp x23, #256 (Issue related to Aegis)
(0x1835e6c, 0xF104011F), // cmp x8, #256 (Issue related to Aegis)
(0x18365c4, 0xF104027F), // cmp x19, #256 (Issue related to Aegis)
(0x18368e0, 0xF104013F), // cmp x9, #256 (Issue related to Aegis)
(0x1a1cdd0, 0xF104011F), // cmp x8, #256 (Issue related to Aegis)
(0x1a1ce14, 0xF104011F), // cmp x8, #256 (Issue related to Aegis)
(0x14dee20, 0x7104013F), // cmp w9, #256 (Issue related to Terry)
(0x14e1ef0, 0x710402FF), // cmp w23, #256 (Issue related to Terry)
(0x14e207c, 0x7104011F), // cmp w8, #256 (Issue related to Terry)
(0x1a56064, 0x52800020), // mov w0, #1 (Issue related to Tourney Mode Crash)
(0x1a56194, 0xF104011F), // cmp x8, #256 (Issue related to Tourney Mode Crash)
(0x1a55a54, 0x7104015F), // cmp w10, #256 (Issue related to Tourney Mode Crash)
(0x1a55aec, 0x7104001F), // cmp w0, #256 (Issue related to Tourney Mode Crash)
(0x1a55b18, 0xF104001F), // cmp x0, #256 (Issue related to Tourney Mode Crash)
(0x1a55a80, 0xF104001F), // cmp x0, #256 (Issue related to Tourney Mode Crash)
(0x1a55ab4, 0x7104017F), // cmp w11, #256 (Issue related to Tourney Mode Crash)
];

for entry in ADDED_COLOR_PATCHES {
Expand Down Expand Up @@ -116,7 +116,7 @@ fn install_lazy_loading_patches() {
pub fn get_ui_chara_path_from_hash_color_and_type(ui_chara_hash: u64, color_slot: u32, ui_type: u32) -> u64;

// This takes the character_database and the ui_chara_hash to get the color_num
#[from_offset(offsets::get_color_num_from_hash())]
#[from_offset(0x3262110)]
pub fn get_color_num_from_hash(character_database: u64, ui_chara_hash: u64) -> u8;

// This takes the character_database and the ui_chara_hash to get the chara's respective echo (for loading it at the same time)
Expand Down
15 changes: 8 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#![feature(string_remove_matches)]
// #![feature(fs_try_exists)]
#![feature(int_roundings)]
#![feature(stdsimd)]

use std::{
collections::HashMap,
Expand Down Expand Up @@ -437,13 +438,13 @@ pub fn main() {
);
}));

if utils::env::get_game_version() != semver::Version::new(13, 0, 1) {
skyline_web::DialogOk::ok(
"ARCropolis cannot currently run on a Smash version lower than 13.0.1<br/>Consider updating your game or uninstalling ARCropolis.",
);
// Do not perform any of the hook installation and let the game proceed as normal.
return;
}
// if utils::env::get_game_version() != semver::Version::new(13, 0, 1) {
Coolsonickirby marked this conversation as resolved.
Show resolved Hide resolved
// skyline_web::DialogOk::ok(
// "ARCropolis cannot currently run on a Smash version lower than 13.0.1<br/>Consider updating your game or uninstalling ARCropolis.",
// );
// // Do not perform any of the hook installation and let the game proceed as normal.
// return;
// }

// Initialize the time for the logger
init_time();
Expand Down
6 changes: 3 additions & 3 deletions src/lua/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ fn lua_getfield(lua_state: &mut lua_state, lua_registry: *const TValue, name: *c
#[from_offset(offsets::lua_setmetatable())]
fn lua_setmetatable(lua_state: &mut lua_state, obj_idx: i32);

#[from_offset(offsets::lua_tonumberx())]
#[from_offset(0x38f68b0)]
fn lua_tonumberx(lua_state: &mut lua_state, idx: i32, unk: *const u64) -> f32;

#[from_offset(offsets::lua_tointegerx())]
#[from_offset(0x38f3c00)]
fn lua_tointegerx(lua_state: &mut lua_state, idx: i32, unk: *const u64) -> u64;

#[from_offset(offsets::lua_tolstring())]
#[from_offset(0x38f3d80)]
fn lua_tolstring(lua_state: &mut lua_state, idx: i32, unk: *const u64) -> *const u8;

#[from_offset(offsets::declare_namespace())]
Expand Down
56 changes: 8 additions & 48 deletions src/offsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,6 @@ static GET_UI_CHARA_PATH_FROM_HASH_SEARCH: (&[u8], isize) = (
0x0,
);

static GET_COLOR_NUM_SEARCH_CODE: (&[u8], isize) = (
&[
0x68, 0x26, 0x40, 0xf9, 0x6e, 0x0e, 0x40, 0xf9, 0x0c, 0x9d, 0x40, 0x92, 0x28, 0x51, 0x80, 0xb8, 0xcd, 0x39, 0x42, 0xa9, 0xeb, 0x03, 0x1f,
0x2a, 0xce, 0x01, 0x08, 0x8b, 0xe8, 0xa6, 0x00, 0xd0, 0x08, 0x2d, 0x3c, 0x91, 0x4f, 0x01, 0x0b, 0x0b, 0xff, 0x01, 0x00, 0x71, 0xef, 0xa5,
0x8f, 0x1a, 0xef, 0x7d, 0x01, 0x13, 0xd0, 0xcd, 0x2f, 0x8b, 0x11, 0x02, 0x40, 0xb9, 0xb1, 0x79, 0x71, 0xf8, 0x3f, 0x02, 0x0c, 0xeb,
],
0x104,
);

static GET_ECHO_FROM_HASH_SEARCH_CODE: (&[u8], isize) = (
&[
0xf6, 0x03, 0x00, 0x2a, 0x82, 0xef, 0x81, 0xd2, 0x02, 0x97, 0xaf, 0xf2, 0x82, 0x01, 0xc0, 0xf2, 0xe0, 0x03, 0x13, 0xaa, 0xe1, 0x03, 0x16,
Expand Down Expand Up @@ -383,33 +374,6 @@ static LUA_SETMETATABLE_CODE: (&[u8], isize) = (
-0x468,
);

static LUA_TONUMBERX_CODE: (&[u8], isize) = (
&[
0x29, 0xb9, 0x36, 0x91, 0x2b, 0x7d, 0x40, 0x92, 0x6a, 0xf6, 0x99, 0x52, 0x2a, 0xa4, 0xa6, 0x72, 0x6a, 0x7d, 0x0a, 0x9b, 0x4a, 0xfd, 0x60,
0xd3, 0x2c, 0x01, 0x0a, 0x4b, 0x4a, 0x05, 0x4c, 0x0b, 0x68, 0x0e, 0x40, 0xf9, 0x4a, 0x7d, 0x05, 0x53, 0xac, 0x06, 0x80, 0x52, 0x4a, 0xa5,
0x0c, 0x1b, 0x0a, 0x51, 0x2a, 0x8b, 0x40, 0xf5, 0x40, 0xf9, 0x0d, 0x60, 0x40, 0x39,
],
-0x640,
);

static LUA_TOINTEGERX_CODE: (&[u8], isize) = (
&[
0x29, 0xb9, 0x36, 0x91, 0x2b, 0x7d, 0x40, 0x92, 0x6a, 0xf6, 0x99, 0x52, 0x2a, 0xa4, 0xa6, 0x72, 0x6a, 0x7d, 0x0a, 0x9b, 0x4a, 0xfd, 0x60,
0xd3, 0x2c, 0x01, 0x0a, 0x4b, 0x4a, 0x05, 0x4c, 0x0b, 0x68, 0x0e, 0x40, 0xf9, 0x4a, 0x7d, 0x05, 0x53, 0xac, 0x06, 0x80, 0x52, 0x4a, 0xa5,
0x0c, 0x1b, 0x0a, 0x51, 0x2a, 0x8b, 0x40, 0xf5, 0x40, 0xf9, 0x0d, 0x60, 0x40, 0x39,
],
-0x4d0,
);

static LUA_TOLSTRING_CODE: (&[u8], isize) = (
&[
0x29, 0xb9, 0x36, 0x91, 0x2b, 0x7d, 0x40, 0x92, 0x6a, 0xf6, 0x99, 0x52, 0x2a, 0xa4, 0xa6, 0x72, 0x6a, 0x7d, 0x0a, 0x9b, 0x4a, 0xfd, 0x60,
0xd3, 0x2c, 0x01, 0x0a, 0x4b, 0x4a, 0x05, 0x4c, 0x0b, 0x68, 0x0e, 0x40, 0xf9, 0x4a, 0x7d, 0x05, 0x53, 0xac, 0x06, 0x80, 0x52, 0x4a, 0xa5,
0x0c, 0x1b, 0x0a, 0x51, 0x2a, 0x8b, 0x40, 0xf5, 0x40, 0xf9, 0x0d, 0x60, 0x40, 0x39,
],
-0x350,
);

static LUA_UI2D_BINDINGS_CODE: (&[u8], isize) = (
&[
0x21, 0x78, 0x27, 0x91, 0x09, 0x29, 0x41, 0xa9, 0xe9, 0x2b, 0x01, 0xa9, 0xe0, 0x03, 0x13, 0xaa, 0x09, 0x29, 0x40, 0xa9, 0xe9, 0x2b, 0x00,
Expand Down Expand Up @@ -550,7 +514,6 @@ generate_members! {
load_chara_1_for_all_costumes: usize,
load_ui_file: usize,
get_ui_chara_path_from_hash: usize,
get_color_num_from_hash: usize,
get_echo_from_hash: usize,
load_stock_icon_for_portrait_menu: usize,
css_set_selected_character_ui: usize,
Expand All @@ -567,11 +530,9 @@ generate_members! {
lua_h_new: usize,
lua_getfield: usize,
lua_setmetatable: usize,
lua_tonumberx: usize,
lua_tointegerx: usize,
lua_tolstring: usize,
lua_ui2d_bindings: usize,
lua_nil: usize,
system_locale_id: usize,
lua_ingame_bindings: usize,
declare_namespace: usize,
add_method: usize,
Expand Down Expand Up @@ -605,7 +566,6 @@ impl Offsets {
let load_chara_1_for_all_costumes = get_offset_neon(text, LOAD_CHARA_1_FOR_ALL_COSTUMES_SEARCH_CODE);
let load_ui_file = get_offset_neon(text, LOAD_UI_FILE_SEARCH_CODE);
let get_ui_chara_path_from_hash = get_offset_neon(text, GET_UI_CHARA_PATH_FROM_HASH_SEARCH);
let get_color_num_from_hash = get_offset_neon(text, GET_COLOR_NUM_SEARCH_CODE);
let get_echo_from_hash = get_offset_neon(text, GET_ECHO_FROM_HASH_SEARCH_CODE);
let load_stock_icon_for_portrait_menu = get_offset_neon(text, LOAD_STOCK_ICON_FOR_PORTRAIT_MENU_SEARCH_CODE);
let css_set_selected_character_ui = get_offset_neon(text, CSS_SET_SELECTED_CHARACTER_UI_SEARCH_CODE);
Expand All @@ -620,9 +580,6 @@ impl Offsets {
let lua_h_new = get_offset_neon(text, LUA_H_NEW_CODE);
let lua_getfield = get_offset_neon(text, LUA_GETFIELD_CODE);
let lua_setmetatable = get_offset_neon(text, LUA_SETMETATABLE_CODE);
let lua_tonumberx = get_offset_neon(text, LUA_TONUMBERX_CODE);
let lua_tointegerx = get_offset_neon(text, LUA_TOINTEGERX_CODE);
let lua_tolstring = get_offset_neon(text, LUA_TOLSTRING_CODE);
let lua_ui2d_bindings = get_offset_neon(text, LUA_UI2D_BINDINGS_CODE);
let lua_ingame_bindings = get_offset_neon(text, LUA_INGAME_BINDINGS_CODE);
let declare_namespace = get_offset_neon(text, DECLARE_NAMESPACE_CODE);
Expand Down Expand Up @@ -659,6 +616,12 @@ impl Offsets {
let strb_offset = offset_from_strb_unsigned_immediate(adrp + 4);
adrp_offset + strb_offset
};
let system_locale_id = {
let adrp = get_ui_chara_path_from_hash + (4 * 23); // Skip 24 instructions to get to the REGION_NUM ADRP
let adrp_offset = offset_from_adrp(adrp);
let ldr_offset = offset_from_ldr(adrp + 4);
adrp_offset + ldr_offset
};

Some(Self {
lookup_stream_hash,
Expand Down Expand Up @@ -686,7 +649,6 @@ impl Offsets {
load_chara_1_for_all_costumes,
load_ui_file,
get_ui_chara_path_from_hash,
get_color_num_from_hash,
get_echo_from_hash,
load_stock_icon_for_portrait_menu,
css_set_selected_character_ui,
Expand All @@ -703,11 +665,9 @@ impl Offsets {
lua_h_new,
lua_getfield,
lua_setmetatable,
lua_tonumberx,
lua_tointegerx,
lua_tolstring,
lua_ui2d_bindings,
lua_nil,
system_locale_id,
lua_ingame_bindings,
declare_namespace,
add_method,
Expand Down
18 changes: 10 additions & 8 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,16 @@ pub mod save {
}

pub fn get_system_region_from_language_id(language: SaveLanguageId) -> Region {
let system_locale_id = unsafe { *(skyline::hooks::getRegionAddress(skyline::hooks::Region::Text) as *const u8).add(0x523b00c) };

let system_region_map = unsafe {
std::slice::from_raw_parts(
(skyline::hooks::getRegionAddress(skyline::hooks::Region::Text) as *const u32).add(0x4740f90 / 4),
14,
)
};
let system_locale_id = unsafe { *(skyline::hooks::getRegionAddress(skyline::hooks::Region::Text) as *const u8).add(crate::offsets::system_locale_id()) };

// let system_region_map = unsafe {
// std::slice::from_raw_parts(
// (skyline::hooks::getRegionAddress(skyline::hooks::Region::Text) as *const u32).add(0x4740f90 / 4),
// 14,
// )
// };

let system_region_map: &[u32] = &[0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4];

let system_region = system_region_map[system_locale_id as usize];

Expand Down
Loading