Skip to content

Commit

Permalink
use function signatures instead of hardcoded offsets, fix #28
Browse files Browse the repository at this point in the history
  • Loading branch information
Naxdy committed Oct 9, 2024
1 parent f771f07 commit 938736d
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 44 deletions.
25 changes: 16 additions & 9 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "zlatency-slider-de"
name = "latency-slider-de"
version = "0.2.4"
authors = []
edition = "2021"
Expand All @@ -14,6 +14,7 @@ crate-type = ["cdylib"]
ninput = { git = "https://github.com/blu-dev/ninput", version = "0.1.0" }
skyline_smash = { git = "https://github.com/jugeeya/skyline-smash.git", branch = "patch-2" }
skyline = { git = "https://github.com/ultimate-research/skyline-rs.git" }
once_cell = { version = "1.20.2" }

[profile.dev]
panic = "abort"
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ Refer to the original author's explanation in [the original README](README_orig.
You will need a moddable switch with atmosphere already installed on it. If you don't have this yet (or don't even know what I'm talking about), look into Switch modding in general first, then come back here.

1. Download and install [Skyline](https://github.com/skyline-dev/skyline) by copying the `exefs` directory into the folder `atmosphere/contents/01006A800016E000` (create if it doesn't exist yet)
2. Download the latest `libzlatency_slider_de.nro` from [this page](https://github.com/xNaxdy/latency-slider-de/releases)
2. Download the latest `liblatency_slider_de.nro` from [this page](https://github.com/xNaxdy/latency-slider-de/releases)

> [!NOTE]
> This project supports reproducible builds. If you want to ensure that the `.nro` uploaded to the Releases page is actually built from the source available, you can build the project yourself very easily. See the instructions in the "Building" section below.
3. Copy the `libzlatency_slider_de.nro` to your SD card, into the folder `atmosphere/contents/01006A800016E000/romfs/skyline/plugins` (create if it doesn't exist yet)
3. Copy the `liblatency_slider_de.nro` to your SD card, into the folder `atmosphere/contents/01006A800016E000/romfs/skyline/plugins` (create if it doesn't exist yet)
4. Boot up the game, go online, and open up an arena. Confirm the mod is working by observing the room id text in the top right (it should show you your input latency now).

Congratulations, Smash Ultimate online is now actually playable!
Expand All @@ -49,7 +49,7 @@ nix build .#
nix build github:Naxdy/latency-slider-de
```

Nix will take care of the rest, that is downloading the necessary toolchain, build tools, and dependencies, as well as compile everything for you. The resulting library will be put in `./result/lib/libzlatency_slider_de.nro`, which you can then upload to your Switch, or copy to your SD card as usual.
Nix will take care of the rest, that is downloading the necessary toolchain, build tools, and dependencies, as well as compile everything for you. The resulting library will be put in `./result/lib/liblatency_slider_de.nro`, which you can then upload to your Switch, or copy to your SD card as usual.

## Contributing

Expand Down Expand Up @@ -85,14 +85,6 @@ Like the original, the mod doesn't send any extra network packets (arenas or oth

No. See above.

#### Is this mod compatible with the training mode modpack?

Yesn't. `latency-slider-de` and `training-modpack` both hook the draw function of the game in the same place. While this hasn't caused any issues for me or anyone else I've talked to running both mods at once (since v0.2.1), this isn't technically supported. If you notice getting crashes, I suggest disabling one of the two, depending on your current use case.

### Is this mod compatible with "The CSK Collection"?

Not really, but maybe. See https://github.com/Naxdy/latency-slider-de/issues/26 and https://github.com/Naxdy/latency-slider-de/issues/22 for more info.

#### Is this mod compatible with the original arena latency slider, or other latency slider mods?

NO. These essentially do the same thing but differently, running multiple of these mods at the same time is very likely to cause your game to crash. If you want to run this mod, you should remove / disable all other "latency slider" type mods first.
Expand All @@ -101,6 +93,14 @@ NO. These essentially do the same thing but differently, running multiple of the

The VSync mod, aka "1 frame less delay", aka `less-delay` is compatible with this mod. I maintain a repo for that one as well, over here: https://github.com/xNaxdy/less-delay

#### Is this mod compatible with [insert other mod here]?

Don't know, don't care. SSBU modding is kind of like chemistry, except you don't know the chemicals you're using. Any concoction has the chance to blow up in your face. The answer is: Try it. If it works, great. If not, you'll have to pick which mod you want enabled.

I _highly_ suggest using a mod manager of some sort to enable / disable mods as you need, to avoid potential complications.

Unfortunately I can't really invest any time into ensuring that latency-slider-de is compatible with each and every mod out there. However, if you submit a PR that improves compatibility with other mods, I will happily accept it!

#### Are you fine with people using this mod to cheat in online tournaments, or on qp?

The short answer is "how people use this mod is up to them". The long answer is this: First, for quickplay, I don't view using this mod as cheating, but rather making the game playable, since there's nothing on the line (if you think GSP holds any meaningful value, I suggest an immediate and thorough psych evaluation), same as in arenas.
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@

latency-slider-de-nro = pkgs.runCommandLocal "latency-slider-de-nro-${self.packages.${system}.latency-slider-de.version}" { } ''
mkdir -p $out/lib
${self.packages.${system}.linkle}/bin/linkle nro ${self.packages.${system}.latency-slider-de}/lib/libzlatency_slider_de.so $out/lib/libzlatency_slider_de.nro
${self.packages.${system}.linkle}/bin/linkle nro ${self.packages.${system}.latency-slider-de}/lib/liblatency_slider_de.so $out/lib/liblatency_slider_de.nro
'';

latency-slider-de =
Expand Down
66 changes: 44 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#![feature(restricted_std)]

use offsets::{
LOC_DISPLAY_CSS, LOC_DRAW, LOC_INGAME_SCENE, LOC_MAIN_MENU_SCENE,
LOC_MELEE_NORMAL_SEQUENCE_SCENE, LOC_ONLINE_MELEE_ANY_SCENE, LOC_SET_ONLINE_LATENCY,
LOC_SET_ROOM_ID, LOC_UPDATE_CSS, LOC_UPDATE_ROOM,
};
use skyline::hooks::InlineCtx;
use skyline::nn::ui2d::{Layout, Pane};
use smash::ui2d::{SmashPane, SmashTextBox};

mod offsets;

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

Expand Down Expand Up @@ -71,7 +78,7 @@ unsafe fn handle_user_input(on_css: bool) {
CURRENT_INPUT_BUFFER = CURRENT_INPUT_BUFFER.clamp(MIN_INPUT_BUFFER, MAX_INPUT_BUFFER);
}

#[skyline::hook(offset = 0x18881d0, inline)]
#[skyline::hook(offset = LOC_UPDATE_ROOM.get_offset_in_memory().unwrap(), inline)]
unsafe fn non_hdr_update_room_hook(_: &skyline::hooks::InlineCtx) {
handle_user_input(false);

Expand Down Expand Up @@ -112,7 +119,7 @@ unsafe fn non_hdr_update_room_hook(_: &skyline::hooks::InlineCtx) {
}
}

#[skyline::hook(offset = 0x004b620)]
#[skyline::hook(offset = LOC_DRAW.get_offset_in_memory().unwrap())]
unsafe fn handle_draw_hook(layout: *mut Layout, draw_info: u64, cmd_buffer: u64) {
if IS_CSS {
let root_pane = &mut *(*layout).root_pane;
Expand All @@ -123,14 +130,14 @@ unsafe fn handle_draw_hook(layout: *mut Layout, draw_info: u64, cmd_buffer: u64)
call_original!(layout, draw_info, cmd_buffer);
}

#[skyline::hook(offset = 0x1a12f40)]
#[skyline::hook(offset = LOC_UPDATE_CSS.get_offset_in_memory().unwrap())]
unsafe fn update_css_hook(arg: u64) {
handle_user_input(true);

call_original!(arg)
}

#[skyline::hook(offset = 0x1887afc, inline)]
#[skyline::hook(offset = LOC_SET_ROOM_ID.get_offset_in_memory().unwrap(), inline)]
unsafe fn non_hdr_set_room_id(ctx: &skyline::hooks::InlineCtx) {
let panel = *((*((*ctx.registers[0].x.as_ref() + 8) as *const u64) + 0x10) as *const u64);
CURRENT_PANE_HANDLE = panel as usize;
Expand All @@ -141,7 +148,7 @@ unsafe fn non_hdr_set_room_id(ctx: &skyline::hooks::InlineCtx) {
.unwrap());
}

#[skyline::hook(offset = 0x16ccc58, inline)]
#[skyline::hook(offset = LOC_SET_ONLINE_LATENCY.get_offset_in_memory().unwrap(), inline)]
unsafe fn non_hdr_set_online_latency(ctx: &InlineCtx) {
let auto = *(*ctx.registers[19].x.as_ref() as *mut u8);

Expand All @@ -151,29 +158,29 @@ unsafe fn non_hdr_set_online_latency(ctx: &InlineCtx) {
}
}

#[skyline::hook(offset = 0x19f0540, inline)]
#[skyline::hook(offset = LOC_DISPLAY_CSS.get_offset_in_memory().unwrap(), inline)]
unsafe fn display_css_hook(_: &InlineCtx) {
if !STEALTH_MODE {
IS_CSS = true;
}
}

#[skyline::hook(offset = 0x22dbe10, inline)]
#[skyline::hook(offset = LOC_MELEE_NORMAL_SEQUENCE_SCENE.get_offset_in_memory().unwrap(), inline)]
unsafe fn melee_normal_sequence_scene_hook(_: &InlineCtx) {
IS_CSS = false;
}

#[skyline::hook(offset = 0x235a628, inline)]
#[skyline::hook(offset = LOC_MAIN_MENU_SCENE.get_offset_in_memory().unwrap(), inline)]
unsafe fn main_menu_scene_hook(_: &InlineCtx) {
IS_CSS = false;
}

#[skyline::hook(offset = 0x236757c, inline)]
#[skyline::hook(offset = LOC_ONLINE_MELEE_ANY_SCENE.get_offset_in_memory().unwrap(), inline)]
unsafe fn online_melee_any_scene_hook(_: &InlineCtx) {
IS_CSS = false;
}

#[skyline::hook(offset = 0x2318210, inline)]
#[skyline::hook(offset = LOC_INGAME_SCENE.get_offset_in_memory().unwrap(), inline)]
unsafe fn ingame_scene_hook(_: &InlineCtx) {
IS_CSS = false;
}
Expand Down Expand Up @@ -214,16 +221,31 @@ unsafe fn draw_ui(root_pane: &Pane) {

#[skyline::main(name = "latency-slider-de")]
pub fn main() {
skyline::install_hooks!(
non_hdr_set_room_id,
non_hdr_update_room_hook,
non_hdr_set_online_latency,
update_css_hook,
handle_draw_hook,
display_css_hook,
melee_normal_sequence_scene_hook,
main_menu_scene_hook,
online_melee_any_scene_hook,
ingame_scene_hook
);
// make sure that all hooks are findable
// and don't crash the game if they're not
if ensure_hooks!(
LOC_UPDATE_ROOM,
LOC_UPDATE_CSS,
LOC_SET_ROOM_ID,
LOC_DISPLAY_CSS,
LOC_DRAW,
LOC_SET_ONLINE_LATENCY,
LOC_INGAME_SCENE,
LOC_ONLINE_MELEE_ANY_SCENE,
LOC_MAIN_MENU_SCENE,
LOC_MELEE_NORMAL_SEQUENCE_SCENE
) {
skyline::install_hooks!(
non_hdr_set_room_id,
non_hdr_update_room_hook,
non_hdr_set_online_latency,
update_css_hook,
handle_draw_hook,
display_css_hook,
melee_normal_sequence_scene_hook,
main_menu_scene_hook,
online_melee_any_scene_hook,
ingame_scene_hook
);
}
}
Loading

0 comments on commit 938736d

Please sign in to comment.