Skip to content

Instantly share code, notes, and snippets.

@jugeeya
Last active June 21, 2020 03:01
Show Gist options
  • Save jugeeya/dce9eb90f3a12720391604d477a55490 to your computer and use it in GitHub Desktop.
Save jugeeya/dce9eb90f3a12720391604d477a55490 to your computer and use it in GitHub Desktop.
GlobalFrameCounter
macro_rules! c_str {
($l:tt) => { [$l.as_bytes(), "\u{0}".as_bytes()]
.concat()
.as_ptr(); }
}
extern "C" {
#[link_name = "\u{1}nvnBootstrapLoader"]
pub fn nvnBootstrapLoader(arg: *const c_char) -> fn(*mut c_void, *const c_char) -> fn(*mut c_void, *mut c_void, *mut c_void);
}
pub static mut original_nvnQueuePresentTexture : *mut c_void = 0 as *mut c_void;
static mut GLOBAL_FRAME_COUNTER : usize = 0;
pub unsafe fn handle_nvnQueuePresentTexture(arg1: *mut c_void, arg2: *mut c_void, arg3: *mut c_void) {
GLOBAL_FRAME_COUNTER += 1;
println!("Frame: {}", GLOBAL_FRAME_COUNTER);
let callable = core::mem::transmute::<
_,
extern "C" fn(
arg1: *mut c_void,
arg2: *mut c_void,
arg3: *mut c_void,
)>(
original_nvnQueuePresentTexture as *const ()
);
callable(arg1, arg2, arg3)
}
#[skyline::main(name = "global_frame_counter")]
pub fn main() {
println!("Hello.");
unsafe {
let nvnDeviceGetProcAddress = nvnBootstrapLoader(c_str!("nvnDeviceGetProcAddress"));
println!("nvnDeviceGetProcAddress: {:#?}", nvnDeviceGetProcAddress);
let nvnQueuePresentTexture = nvnDeviceGetProcAddress(0 as *mut c_void, c_str!("nvnQueuePresentTexture"));
println!("nvnQueuePresentTexture: {:#?}", nvnQueuePresentTexture);
skyline::hooks::A64HookFunction(
nvnQueuePresentTexture as *const c_void,
handle_nvnQueuePresentTexture as *const c_void,
&mut original_nvnQueuePresentTexture as *mut *mut c_void);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment