Skip to content

Commit

Permalink
hook: add feature flag to edit version string
Browse files Browse the repository at this point in the history
  • Loading branch information
roccodev committed Apr 13, 2023
1 parent 7069c2e commit cbf0233
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 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.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xc3-file-loader"
version = "0.1.0"
version = "1.0.0"
authors = ["RoccoDev <[email protected]>"]
edition = "2021"
license = "gpl-3.0"
Expand All @@ -15,6 +15,10 @@ custom-npdm = "res/npdm/xc3.npdm"
[lib]
crate-type = ["cdylib"]

[features]
# Adds an "F" to the game version in the title screen. Useful to check whether the mod is active
edit-version = []

[dependencies]
skyline = { git = "https://github.com/ultimate-research/skyline-rs.git" }

Expand Down
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ macro_rules! dbg_println {
mod hash;
mod loader;

#[cfg(feature = "edit-version")]
mod edit_version {
use skyline::hooks::InlineCtx;

static VERSION_TEMPLATE: &[u8] = b"%s %sF\0";

// Look for usages of nn::oe::GetDisplayVersion
#[skyline::hook(offset = 0x007bd574, inline)]
pub unsafe fn edit_version(ctx: &mut InlineCtx) {
*ctx.registers[1].x.as_mut() = VERSION_TEMPLATE.as_ptr() as u64;
}
}

// ml::DevFileArchiver::getFileInfo
#[hook(offset = 0x01164f58)]
unsafe fn block_file_load(p1: u64, p2: u32, name: *const u8, p4: u64) -> u32 {
Expand Down Expand Up @@ -48,6 +61,8 @@ pub fn main() {
}

skyline::install_hooks!(block_file_load);
#[cfg(feature = "edit-version")]
skyline::install_hook!(edit_version::edit_version);

dbg_println!("[XC3-Files] Loaded!");
}

0 comments on commit cbf0233

Please sign in to comment.