Skip to content

Commit

Permalink
Merge pull request #30 from Naxdy/work/13.0.3-text
Browse files Browse the repository at this point in the history
fix: update offset for `set_text_string`, re-enable text
  • Loading branch information
Naxdy authored Oct 13, 2024
2 parents c6252fa + 3e16376 commit 9de0963
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "latency-slider-de"
version = "0.3.0-pre"
version = "0.3.0"
authors = []
edition = "2021"

Expand Down
81 changes: 40 additions & 41 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ use offsets::{
};
use skyline::hooks::InlineCtx;
use skyline::nn::ui2d::{Layout, Pane};
use smash::ui2d::{SmashPane, SmashTextBox};
use smash::ui2d::SmashPane;

mod offsets;

#[skyline::from_offset(0x37a1ef0)]
#[skyline::from_offset(0x37a1f10)]
unsafe fn set_text_string(pane: u64, string: *const u8);

static mut CURRENT_PANE_HANDLE: usize = 0;
static mut CURRENT_ARENA_ID: String = String::new();
static mut CURRENT_INPUT_BUFFER: isize = 4;
static mut MOST_RECENT_AUTO: isize = -1;
static mut STEALTH_MODE: bool = false;
static mut _ORIG_VIP_TEXT: String = String::new();
static mut ORIG_VIP_TEXT: String = String::new();
static mut IS_CSS: bool = false;

const MAX_INPUT_BUFFER: isize = 25;
Expand Down Expand Up @@ -86,38 +86,37 @@ unsafe fn non_hdr_update_room_hook(_: &skyline::hooks::InlineCtx) {
IS_CSS = false;
}

// TODO: Reevaluate functionality after update to 19.0.0
// if STEALTH_MODE {
// set_text_string(
// CURRENT_PANE_HANDLE as u64,
// format!("ID: {}\0", CURRENT_ARENA_ID).as_ptr(),
// );
// } else if CURRENT_INPUT_BUFFER == -1 {
// if MOST_RECENT_AUTO == -1 {
// set_text_string(
// CURRENT_PANE_HANDLE as u64,
// format!("ID: {}\nInput Latency: Auto\0", CURRENT_ARENA_ID).as_ptr(),
// );
// } else {
// set_text_string(
// CURRENT_PANE_HANDLE as u64,
// format!(
// "ID: {}\nInput Latency: Auto ({})\0",
// CURRENT_ARENA_ID, MOST_RECENT_AUTO
// )
// .as_ptr(),
// )
// }
// } else {
// set_text_string(
// CURRENT_PANE_HANDLE as u64,
// format!(
// "ID: {}\nInput Latency: {}\0",
// CURRENT_ARENA_ID, CURRENT_INPUT_BUFFER
// )
// .as_ptr(),
// );
// }
if STEALTH_MODE {
set_text_string(
CURRENT_PANE_HANDLE as u64,
format!("ID: {}\0", CURRENT_ARENA_ID).as_ptr(),
);
} else if CURRENT_INPUT_BUFFER == -1 {
if MOST_RECENT_AUTO == -1 {
set_text_string(
CURRENT_PANE_HANDLE as u64,
format!("ID: {}\nInput Latency: Auto\0", CURRENT_ARENA_ID).as_ptr(),
);
} else {
set_text_string(
CURRENT_PANE_HANDLE as u64,
format!(
"ID: {}\nInput Latency: Auto ({})\0",
CURRENT_ARENA_ID, MOST_RECENT_AUTO
)
.as_ptr(),
)
}
} else {
set_text_string(
CURRENT_PANE_HANDLE as u64,
format!(
"ID: {}\nInput Latency: {}\0",
CURRENT_ARENA_ID, CURRENT_INPUT_BUFFER
)
.as_ptr(),
);
}
}

#[skyline::hook(offset = LOC_DRAW.get_offset_in_memory().unwrap())]
Expand All @@ -126,7 +125,7 @@ unsafe fn handle_draw_hook(layout: *mut Layout, draw_info: u64, cmd_buffer: u64)
let root_pane = &mut *(*layout).root_pane;

// TODO: Reevaluate functionality after update to 19.0.0
// draw_ui(root_pane);
draw_ui(root_pane);
}

call_original!(layout, draw_info, cmd_buffer);
Expand Down Expand Up @@ -187,14 +186,14 @@ unsafe fn ingame_scene_hook(_: &InlineCtx) {
IS_CSS = false;
}

unsafe fn _draw_ui(root_pane: &Pane) {
unsafe fn draw_ui(root_pane: &Pane) {
let vip_pane_00 = root_pane.find_pane_by_name_recursive("txt_vip_title_00");
let vip_pane_01 = root_pane.find_pane_by_name_recursive("txt_vip_title_01");

if _ORIG_VIP_TEXT.is_empty() {
if ORIG_VIP_TEXT.is_empty() {
match (vip_pane_00, vip_pane_01) {
(Some(x), _) | (_, Some(x)) => {
_ORIG_VIP_TEXT = dbg!(String::from_utf16(std::slice::from_raw_parts(
ORIG_VIP_TEXT = dbg!(String::from_utf16(std::slice::from_raw_parts(
x.as_textbox().text_buf as *mut u16,
x.as_textbox().text_buf_len as usize,
))
Expand All @@ -212,12 +211,12 @@ unsafe fn _draw_ui(root_pane: &Pane) {
format!("Input Latency: Auto ({})", MOST_RECENT_AUTO)
}
} else {
_ORIG_VIP_TEXT.clone()
ORIG_VIP_TEXT.clone()
};

[x, y]
.into_iter()
.for_each(|e| e.as_textbox().set_text_string(s.as_str()));
.for_each(|e| set_text_string(e as *mut Pane as u64, s.as_str().as_ptr()));
}
}

Expand Down
27 changes: 26 additions & 1 deletion src/offsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn byte_search(needle: &[u8]) -> Option<usize> {
let search_space = unsafe {
let start = skyline::hooks::getRegionAddress(skyline::hooks::Region::Text) as *const u8;
let end = skyline::hooks::getRegionAddress(skyline::hooks::Region::Rodata) as *const u8;

let length = end.offset_from(start) as usize;

std::slice::from_raw_parts(start, length)
Expand Down Expand Up @@ -66,7 +67,17 @@ pub struct SSBUMemoryLocation<'a> {
impl SSBUMemoryLocation<'_> {
pub fn get_offset_in_memory(&self) -> Option<usize> {
*self.cached_offset.get_or_init(|| unsafe {
Some(((byte_search(self.signature)? as *const u8).offset(self.start_offset)) as usize)
let r = byte_search(self.signature)
.map(|e| (e as *const u8).offset(self.start_offset) as usize);

if let Some(r) = r {
println!(
"[latency-slider-de] Found {} at {r:#09x?}",
self.location_name
);
}

r
})
}
}
Expand Down Expand Up @@ -194,3 +205,17 @@ pub static LOC_UPDATE_ROOM: SSBUMemoryLocation = SSBUMemoryLocation {
location_name: "update_room",
cached_offset: OnceCell::new(),
};

// TODO: not findable atm, probably need to change search algo.
// this and `find_pane_by_name_recursive` are currently the only hardcoded offsets
// pub static LOC_SET_TEXT_STRING: SSBUMemoryLocation = SSBUMemoryLocation {
// signature: &[
// 0xfc, 0x0f, 0x1d, 0xf8, 0xf4, 0x4f, 0x01, 0xa9, 0xfd, 0x7b, 0x02, 0xa9, 0xfd, 0x83, 0x00,
// 0x91, 0xff, 0x07, 0x40, 0xd1, 0xf4, 0x03, 0x01, 0xaa, 0xf3, 0x03, 0x00, 0xaa, 0xe0, 0x03,
// 0x00, 0x91, 0xe2, 0x03, 0x14, 0x32, 0xe1, 0x03, 0x1f, 0x2a, 0x76, 0x76, 0x08, 0x94, 0xf4,
// 0x04, 0x00, 0xb4, 0x8b, 0x02, 0x40, 0x39, 0xeb, 0x04, 0x00, 0x34, 0xe8, 0x03, 0x00, 0x32,
// ],
// start_offset: 0,
// location_name: "set_text_string",
// cached_offset: OnceCell::new(),
// };

0 comments on commit 9de0963

Please sign in to comment.