diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index 6c9342c..c9c3ee9 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -9,12 +9,31 @@ extern crate widestring; extern crate ctru_sys as libctru; /// Call this somewhere to force Rust to link some required crates -/// (ex. pthread-3ds). The call doesn't need to execute, just exist. +/// This is also a setup for some crate integration only available at runtime /// /// See https://github.com/rust-lang/rust/issues/47384 pub fn init() { linker_fix_3ds::init(); pthread_3ds::init(); + + use std::panic::PanicInfo; + + // Panic Hook setup + let default_hook = std::panic::take_hook(); + let new_hook = Box::new( move |info: &PanicInfo| { + println!("\x1b[1;31m\n--------------------------------------------------"); + default_hook(info); + println!("\nPress SELECT to exit the software"); + let hid = services::hid::Hid::init().unwrap(); + + loop { + hid.scan_input(); + if hid.keys_down().contains(services::hid::KeyPad::KEY_SELECT) { + break; + } + } + }); + std::panic::set_hook(new_hook); } pub mod applets;