From e2364ff5e182cc264befc3628df2d15e771553e6 Mon Sep 17 00:00:00 2001 From: Lena Date: Sat, 17 Feb 2024 16:42:31 +0100 Subject: [PATCH] implement chainloader --- ctru-rs/src/services/am.rs | 5 +++++ ctru-rs/src/services/apt.rs | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/ctru-rs/src/services/am.rs b/ctru-rs/src/services/am.rs index f4b6e6a..2bcd47a 100644 --- a/ctru-rs/src/services/am.rs +++ b/ctru-rs/src/services/am.rs @@ -51,6 +51,11 @@ impl<'a> Title<'a> { pub fn version(&self) -> u16 { self.version } + + /// Returns this title's media type + pub fn media_type(&self) -> MediaType { + self.mediatype + } } /// Handle to the Application Manager service. diff --git a/ctru-rs/src/services/apt.rs b/ctru-rs/src/services/apt.rs index 2a3b7fb..5df178b 100644 --- a/ctru-rs/src/services/apt.rs +++ b/ctru-rs/src/services/apt.rs @@ -132,3 +132,44 @@ impl Drop for Apt { unsafe { ctru_sys::aptExit() }; } } + +pub struct Chainloader<'a> { + _apt: &'a Apt, +} + +impl<'a> Chainloader<'a> { + /// Gets a handle to the chainloader + pub fn new(apt: &'a Apt) -> Self { + Self { _apt: apt } + } + + /// Checks if the chainloader is set + #[doc(alias = "aptIsChainload")] + pub fn is_set(&mut self) { + //unsafe { ctru_sys::aptIsChainload() } + } + + /// Clears the chainloader state. + #[doc(alias = "aptClearChainloader")] + pub fn clear(&mut self) { + unsafe { ctru_sys::aptClearChainloader() } + } + + /// Configures the chainloader to launch a specific application. + #[doc(alias = "aptSetChainloader")] + pub fn set_chainloader(&mut self, title: &super::am::Title<'_>) { + unsafe { ctru_sys::aptSetChainloader(title.id(), title.media_type() as u8) } + } + + /// Configures the chainloader to launch the previous application. + #[doc(alias = "aptSetChainloaderToCaller")] + pub fn set_chainloader_to_caller(&mut self) { + unsafe { ctru_sys::aptSetChainloaderToCaller() } + } + + /// Configures the chainloader to relaunch the current application (i.e. soft-reset) + #[doc(alias = "aptSetChainloaderToSelf")] + pub fn set_chainloader_to_self(&mut self) { + unsafe { ctru_sys::aptSetChainloaderToSelf() } + } +}