diff --git a/Cargo.toml b/Cargo.toml index 5286e9f..0ceff10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "skyline-rs-template" +name = "skyline_rs_template" version = "0.1.0" authors = ["jam1garner "] edition = "2018" diff --git a/src/lib.rs b/src/lib.rs index 4513972..98dec29 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,50 +1,30 @@ #![feature(proc_macro_hygiene)] -use skyline::nn::account::{self, Uid, GetLastOpenedUser, GetNickname, Nickname}; -use smash::hash40; +use skyline::{hook, install_hook}; -#[skyline::main(name = "module_name_test")] +extern "C" fn test() -> u32 { + 2 +} + +#[hook(replace = test)] +fn test_replacement() -> u32 { + + let original_test = original!(); + + let val = original_test(); + + println!("[override] original value: {}", val); // 2 + + val + 1 +} + +#[skyline::main(name = "skyline_rs_template")] pub fn main() { println!("Hello from Skyline Rust Plugin!"); - for i in 0..3 { - println!("{}", i); - } + install_hook!(test_replacement); - let nickname = unsafe { get_last_user_nickname() }; + let x = test(); - println!("Last nickname: {}", nickname); - - println!("Contents of file: {:?}", std::fs::read_to_string("sd:/test.txt")); - - println!("Compile-time hash40 of 'accel_x': {:010X}", hash40("accel_x")); - - let string = "accel_x"; - println!("Runtime hash40 of '{}': {:010X}", string, hash40(string)); + println!("[main] test returned: {}", x); // 3 } - -unsafe fn get_last_user_nickname() -> Nickname { - account::Initialize(); - let uid = &mut Uid::new(); - let mut nick = Nickname::new(); - - GetLastOpenedUser(uid); - GetNickname(&mut nick, uid); - - nick -} - - -/* -use skyline::{ - libc::{fopen, FileOpenMode, fwrite_slice, fclose}, - c_str -}; - -fn write_to_file(file: &str, contents: &str) { - unsafe { - let file = fopen(c_str(file), FileOpenMode::Write); - fwrite_slice(contents.as_bytes(), file); - fclose(file); - } -}*/