diff --git a/emuiibo/Cargo.lock b/emuiibo/Cargo.lock index e530282..0758ff6 100644 --- a/emuiibo/Cargo.lock +++ b/emuiibo/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "arrayvec" -version = "0.5.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "emuiibo" @@ -21,15 +21,15 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "linked_list_allocator" -version = "0.9.1" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "549ce1740e46b291953c4340adcd74c59bcf4308f4cac050fd33ba91b7168f4a" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" [[package]] name = "logpacket" @@ -39,7 +39,7 @@ source = "git+https://github.com/aarch64-switch-rs/logpacket#d807c993fb4578e3809 [[package]] name = "nx" version = "0.1.0" -source = "git+https://github.com/aarch64-switch-rs/nx#6fdf0deb0261fd927313ad2f6e6e3d47ce481cde" +source = "git+https://github.com/aarch64-switch-rs/nx#6a667357275a7700ee98c89fe2e27227261c0fb0" dependencies = [ "arrayvec", "linked_list_allocator", @@ -56,42 +56,42 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] [[package]] name = "ryu" -version = "1.0.15" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "serde" -version = "1.0.188" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", @@ -100,9 +100,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.105" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" dependencies = [ "itoa", "ryu", @@ -117,9 +117,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "syn" -version = "2.0.29" +version = "2.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" dependencies = [ "proc-macro2", "quote", @@ -128,6 +128,6 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/emuiibo/src/amiibo/fmt.rs b/emuiibo/src/amiibo/fmt.rs index e5ab97b..84436e9 100644 --- a/emuiibo/src/amiibo/fmt.rs +++ b/emuiibo/src/amiibo/fmt.rs @@ -1,3 +1,4 @@ +use nx::ipc::sf::ncm; use nx::result::*; use serde::{Serialize, Deserialize}; use alloc::string::String; @@ -132,8 +133,8 @@ pub struct VirtualAmiiboAreaEntry { pub access_id: nfp::AccessId } -// Retail Interactive Display Menu (a quite symbolic ID) -pub const DEFAULY_EMPTY_AREA_PROGRAM_ID: u64 = 0x0100069000078000; +// Retail Interactive Display Menu (quite a symbolic ID) +pub const DEFAULY_EMPTY_AREA_PROGRAM_ID: ncm::ProgramId = ncm::ProgramId(0x0100069000078000); #[derive(Serialize, Deserialize, Clone, Debug)] pub struct VirtualAmiiboAreaInfo { @@ -177,7 +178,7 @@ pub fn generate_areas_json(path: String) -> Result> { let mut areas = VirtualAmiiboAreaInfo::empty(); for access_id in &access_ids { let area_entry = VirtualAmiiboAreaEntry { - program_id: DEFAULY_EMPTY_AREA_PROGRAM_ID, + program_id: DEFAULY_EMPTY_AREA_PROGRAM_ID.0, access_id: *access_id }; areas.areas.push(area_entry); @@ -234,7 +235,7 @@ impl VirtualAmiibo { Ok(mii_charinfo_file.read_val()?) } else { - let mut random_mii = miiext::generate_random_mii()?; + let random_mii = miiext::generate_random_mii()?; let mut mii_charinfo_file = fs::open_file(mii_charinfo_path, fs::FileOpenOption::Create() | fs::FileOpenOption::Write() | fs::FileOpenOption::Append())?; mii_charinfo_file.write_val(&random_mii)?; Ok(random_mii) @@ -257,18 +258,18 @@ impl VirtualAmiibo { } #[inline] - pub fn register_area(&mut self, access_id: nfp::AccessId, program_id: u64) -> bool { + pub fn register_area(&mut self, access_id: nfp::AccessId, program_id: ncm::ProgramId) -> bool { if self.has_application_area(access_id) { false } else { - self.areas.areas.push(VirtualAmiiboAreaEntry { program_id, access_id }); + self.areas.areas.push(VirtualAmiiboAreaEntry { program_id: program_id.0, access_id }); true } } #[inline] - pub fn ensure_area_registered(&mut self, access_id: nfp::AccessId, program_id: u64) { + pub fn ensure_area_registered(&mut self, access_id: nfp::AccessId, program_id: ncm::ProgramId) { self.register_area(access_id, program_id); } @@ -317,12 +318,12 @@ impl VirtualAmiibo { self.notify_written() } - pub fn update_area_program_id(&mut self, access_id: nfp::AccessId, program_id: u64) -> Result<()> { + pub fn update_area_program_id(&mut self, access_id: nfp::AccessId, program_id: ncm::ProgramId) -> Result<()> { self.ensure_area_registered(access_id, DEFAULY_EMPTY_AREA_PROGRAM_ID); for area_entry in &mut self.areas.areas { if area_entry.access_id == access_id { - area_entry.program_id = program_id; + area_entry.program_id = program_id.0; break; } } @@ -422,12 +423,12 @@ impl VirtualAmiibo { let cur_area = self.get_current_area(); let program_id = match cur_area { - Some(ref area_entry) => area_entry.program_id, + Some(ref area_entry) => ncm::ProgramId(area_entry.program_id), None => DEFAULY_EMPTY_AREA_PROGRAM_ID }; let console_family = { // 0x0100 for Switch, 0x0004 for 3DS, 0x0005 for Wii U - match program_id >> 48 { + match program_id.0 >> 48 { 0x0100 => nfp::ConsoleFamily::NintendoSwitch, 0x0004 => nfp::ConsoleFamily::Nintendo3DS, 0x0005 => nfp::ConsoleFamily::NintendoWiiU, diff --git a/emuiibo/src/amiibo/v1.rs b/emuiibo/src/amiibo/v1.rs index 736627e..22e7042 100644 --- a/emuiibo/src/amiibo/v1.rs +++ b/emuiibo/src/amiibo/v1.rs @@ -4,6 +4,7 @@ use crate::fsext; use super::{bin, compat, fmt}; use alloc::string::ToString; use nx::fs; +use nx::ipc::sf::ncm; use nx::result::*; use alloc::string::String; @@ -45,7 +46,7 @@ impl compat::DeprecatedVirtualAmiiboFormat for VirtualAmiibo { // Save application area if present if plain_bin.dec_data.settings.flags.contains(bin::Flags::ApplicationAreaUsed()) { let access_id = plain_bin.dec_data.settings.access_id_be.swap_bytes(); - let program_id = plain_bin.dec_data.settings.program_id_be.swap_bytes(); + let program_id = ncm::ProgramId(plain_bin.dec_data.settings.program_id_be.swap_bytes()); let bin_area = area::ApplicationArea::from(&amiibo, access_id); bin_area.create(plain_bin.dec_data.app_area.as_ptr(), plain_bin.dec_data.app_area.len(), false)?; diff --git a/emuiibo/src/amiibo/v2.rs b/emuiibo/src/amiibo/v2.rs index e5c0c4d..31dc4cc 100644 --- a/emuiibo/src/amiibo/v2.rs +++ b/emuiibo/src/amiibo/v2.rs @@ -1,6 +1,6 @@ use alloc::{string::{String, ToString}, vec::Vec}; use serde::{Serialize, Deserialize}; -use nx::{result::*, service::mii, fs}; +use nx::{fs, ipc::sf::ncm, result::*, service::mii}; use crate::{area, fsext, miiext}; use super::{bin, compat, fmt}; @@ -112,7 +112,7 @@ impl compat::DeprecatedVirtualAmiiboFormat for VirtualAmiibo { // Save application area if present if plain_bin.dec_data.settings.flags.contains(bin::Flags::ApplicationAreaUsed()) { let access_id = plain_bin.dec_data.settings.access_id_be.swap_bytes(); - let program_id = plain_bin.dec_data.settings.program_id_be.swap_bytes(); + let program_id = ncm::ProgramId(plain_bin.dec_data.settings.program_id_be.swap_bytes()); let existing_id = existing_access_id.unwrap_or(0); if existing_access_id.is_none() || (existing_id != access_id) { diff --git a/emuiibo/src/emu.rs b/emuiibo/src/emu.rs index 17ce49e..973983d 100644 --- a/emuiibo/src/emu.rs +++ b/emuiibo/src/emu.rs @@ -1,4 +1,5 @@ use nx::sync; +use nx::ipc::sf::ncm; use alloc::vec::Vec; use crate::amiibo; use crate::fsext; @@ -88,21 +89,21 @@ pub fn set_active_virtual_amiibo_status(status: VirtualAmiiboStatus) { } } -pub fn register_intercepted_application_id(application_id: u64) { +pub fn register_intercepted_application_id(application_id: ncm::ProgramId) { unsafe { - G_INTERCEPTED_APPLICATION_IDS.get().push(application_id); + G_INTERCEPTED_APPLICATION_IDS.get().push(application_id.0); } } -pub fn unregister_intercepted_application_id(application_id: u64) { +pub fn unregister_intercepted_application_id(application_id: ncm::ProgramId) { unsafe { - G_INTERCEPTED_APPLICATION_IDS.get().retain(|&id| id != application_id); + G_INTERCEPTED_APPLICATION_IDS.get().retain(|&id| id != application_id.0); } } -pub fn is_application_id_intercepted(application_id: u64) -> bool { +pub fn is_application_id_intercepted(application_id: ncm::ProgramId) -> bool { unsafe { - G_INTERCEPTED_APPLICATION_IDS.get().contains(&application_id) + G_INTERCEPTED_APPLICATION_IDS.get().contains(&application_id.0) } } diff --git a/emuiibo/src/ipc/emu.rs b/emuiibo/src/ipc/emu.rs index 467a5b2..bf6e1fd 100644 --- a/emuiibo/src/ipc/emu.rs +++ b/emuiibo/src/ipc/emu.rs @@ -1,4 +1,5 @@ use alloc::string::ToString; +use nx::ipc::sf::ncm; use nx::ipc::sf::sm; use nx::result::*; use nx::ipc::sf; @@ -21,7 +22,7 @@ ipc_sf_define_interface_trait! { reset_active_virtual_amiibo [6, version::VersionInterval::all()]: () => (); get_active_virtual_amiibo_status [7, version::VersionInterval::all()]: () => (status: emu::VirtualAmiiboStatus); set_active_virtual_amiibo_status [8, version::VersionInterval::all()]: (status: emu::VirtualAmiiboStatus) => (); - is_application_id_intercepted [9, version::VersionInterval::all()]: (application_id: u64) => (is_intercepted: bool); + is_application_id_intercepted [9, version::VersionInterval::all()]: (application_id: ncm::ProgramId) => (is_intercepted: bool); try_parse_virtual_amiibo [10, version::VersionInterval::all()]: (path: sf::InMapAliasBuffer) => (virtual_amiibo: amiibo::fmt::VirtualAmiiboData); get_active_virtual_amiibo_areas [11, version::VersionInterval::all()]: (out_areas: sf::OutMapAliasBuffer) => (count: u32); get_active_virtual_amiibo_current_area [12, version::VersionInterval::all()]: () => (access_id: nfp::AccessId); @@ -104,8 +105,8 @@ impl IEmulationService for EmulationService { Ok(()) } - fn is_application_id_intercepted(&mut self, application_id: u64) -> Result { - log!("IsApplicationIdIntercepted -- app_id: {:#X}\n", application_id); + fn is_application_id_intercepted(&mut self, application_id: ncm::ProgramId) -> Result { + log!("IsApplicationIdIntercepted -- app_id: {:#X}\n", application_id.0); Ok(emu::is_application_id_intercepted(application_id)) } diff --git a/emuiibo/src/ipc/nfp.rs b/emuiibo/src/ipc/nfp.rs index 7bf7b8b..d42e5b1 100644 --- a/emuiibo/src/ipc/nfp.rs +++ b/emuiibo/src/ipc/nfp.rs @@ -1,6 +1,7 @@ use nx::result::*; use nx::ipc::sf; use nx::ipc::sf::nfp; +use nx::ipc::sf::ncm; use nx::ipc::sf::applet; use nx::wait; use nx::sync; @@ -28,7 +29,7 @@ pub fn get_input_context() -> &'static input::Context { } pub struct EmulationHandler { - application_id: u64, + application_id: ncm::ProgramId, activate_event: wait::SystemEvent, deactivate_event: wait::SystemEvent, availability_change_event: wait::SystemEvent, @@ -40,13 +41,13 @@ pub struct EmulationHandler { } impl EmulationHandler { - pub fn new(application_id: u64) -> Result { - log!("\n[{:#X}] New handler!\n", application_id); + pub fn new(application_id: ncm::ProgramId) -> Result { + log!("\n[{:#X}] New handler!\n", application_id.0); Ok(Self { application_id, activate_event: wait::SystemEvent::new()?, deactivate_event: wait::SystemEvent::new()?, availability_change_event: wait::SystemEvent::new()?, state: sync::Locked::new(false, nfp::State::NonInitialized), device_state: sync::Locked::new(false, nfp::DeviceState::Unavailable), should_end_thread: sync::Locked::new(false, false), emu_handler_thread: thread::Thread::empty(), current_opened_area: area::ApplicationArea::new() }) } #[inline] - pub fn get_application_id(&self) -> u64 { + pub fn get_application_id(&self) -> ncm::ProgramId { self.application_id } @@ -95,10 +96,10 @@ impl EmulationHandler { pub fn initialize(&mut self, aruid: applet::AppletResourceUserId, process_id: sf::ProcessId, mcu_data: sf::InMapAliasBuffer) -> Result<()> { // TODO: make use of aruid or mcu data? result_return_unless!(self.is_state(nfp::State::NonInitialized), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] Initialize -- aruid: {}, process_id: {}, mcu_version_data: (count: {})\n", self.application_id, aruid, process_id.process_id, mcu_data.get_count()); + log!("[{:#X}] Initialize -- aruid: {}, process_id: {}, mcu_version_data: (count: {})\n", self.application_id.0, aruid, process_id.process_id, mcu_data.get_count()); let mcu_ver_datas = mcu_data.get_slice(); for mcu_ver_data in mcu_ver_datas { - log!("[{:#X}] Initialize -- mcu version: {}\n", self.application_id, mcu_ver_data.version); + log!("[{:#X}] Initialize -- mcu version: {}\n", self.application_id.0, mcu_ver_data.version); } self.state.set(nfp::State::Initialized); @@ -113,7 +114,7 @@ impl EmulationHandler { pub fn finalize(&mut self) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] Finalize -- (...)\n", self.application_id); + log!("[{:#X}] Finalize -- (...)\n", self.application_id.0); self.state.set(nfp::State::NonInitialized); self.device_state.set(nfp::DeviceState::Finalized); @@ -122,7 +123,7 @@ impl EmulationHandler { pub fn list_devices(&mut self, out_devices: sf::OutPointerBuffer) -> Result { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] ListDevices -- out_devices: (count: {})\n", self.application_id, out_devices.get_count()); + log!("[{:#X}] ListDevices -- out_devices: (count: {})\n", self.application_id.0, out_devices.get_count()); // Note: a DeviceHandle's id != npad_id on official nfp, but we treat them as the same thing since we don't care about it // Official nfp would store the npad_id somewhere else for the command below which retrieves it @@ -149,7 +150,7 @@ impl EmulationHandler { pub fn start_detection(&mut self, device_handle: nfp::DeviceHandle) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::Initialized) || self.is_device_state(nfp::DeviceState::TagRemoved), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] StartDetection -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] StartDetection -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); self.device_state.set(nfp::DeviceState::SearchingForTag); Ok(()) @@ -157,7 +158,7 @@ impl EmulationHandler { pub fn stop_detection(&mut self, device_handle: nfp::DeviceHandle) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] StopDetection -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] StopDetection -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); self.device_state.set(nfp::DeviceState::Initialized); Ok(()) @@ -165,7 +166,7 @@ impl EmulationHandler { pub fn mount(&mut self, device_handle: nfp::DeviceHandle, model_type: nfp::ModelType, mount_target: nfp::MountTarget) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] Mount -- device_handle: (fake id: {}), model_type: {:?}, mount_target: {:?}\n", self.application_id, device_handle.id, model_type, mount_target); + log!("[{:#X}] Mount -- device_handle: (fake id: {}), model_type: {:?}, mount_target: {:?}\n", self.application_id.0, device_handle.id, model_type, mount_target); self.device_state.set(nfp::DeviceState::TagMounted); Ok(()) @@ -173,7 +174,7 @@ impl EmulationHandler { pub fn unmount(&mut self, device_handle: nfp::DeviceHandle) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] Unmount -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] Unmount -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); self.device_state.set(nfp::DeviceState::TagFound); Ok(()) @@ -182,12 +183,12 @@ impl EmulationHandler { pub fn open_application_area(&mut self, device_handle: nfp::DeviceHandle, access_id: nfp::AccessId) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] OpenApplicationArea -- device_handle: (fake id: {}), access_id: {:#X}\n", self.application_id, device_handle.id, access_id); + log!("[{:#X}] OpenApplicationArea -- device_handle: (fake id: {}), access_id: {:#X}\n", self.application_id.0, device_handle.id, access_id); let amiibo = emu::get_active_virtual_amiibo(); result_return_unless!(amiibo.is_valid(), nfp::rc::ResultDeviceNotFound); - let application_area = area::ApplicationArea::from_id(&amiibo, self.application_id, access_id); + let application_area = area::ApplicationArea::from_id(&amiibo, self.application_id.0, access_id); result_return_unless!(application_area.exists(), nfp::rc::ResultAreaNeedsToBeCreated); amiibo.update_area_program_id(access_id, self.application_id)?; @@ -199,7 +200,7 @@ impl EmulationHandler { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.current_opened_area.exists(), nfp::rc::ResultAreaNeedsToBeCreated); - log!("[{:#X}] GetApplicationArea -- device_handle: (fake id: {}), out_data: (buf_size: {:#X})\n", self.application_id, device_handle.id, out_data.get_size()); + log!("[{:#X}] GetApplicationArea -- device_handle: (fake id: {}), out_data: (buf_size: {:#X})\n", self.application_id.0, device_handle.id, out_data.get_size()); let area_size = self.current_opened_area.get_size()?; let size = core::cmp::min(area_size, out_data.get_size()); @@ -212,7 +213,7 @@ impl EmulationHandler { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.current_opened_area.exists(), nfp::rc::ResultAreaNeedsToBeCreated); - log!("[{:#X}] SetApplicationArea -- device_handle: (fake id: {}), data: (buf_size: {:#X})\n", self.application_id, device_handle.id, data.get_size()); + log!("[{:#X}] SetApplicationArea -- device_handle: (fake id: {}), data: (buf_size: {:#X})\n", self.application_id.0, device_handle.id, data.get_size()); let area_size = self.current_opened_area.get_size()?; let size = core::cmp::min(area_size, data.get_size()); @@ -225,14 +226,14 @@ impl EmulationHandler { pub fn flush(&mut self, device_handle: nfp::DeviceHandle) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] Flush -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] Flush -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); Ok(()) } pub fn restore(&mut self, device_handle: nfp::DeviceHandle) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] Restore -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] Restore -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); Ok(()) } @@ -240,12 +241,12 @@ impl EmulationHandler { pub fn create_application_area(&mut self, device_handle: nfp::DeviceHandle, access_id: nfp::AccessId, data: sf::InMapAliasBuffer) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] CreateApplicationArea -- device_handle: (fake id: {}), access_id: {:#X}, data: (buf_size: {:#X})\n", self.application_id, device_handle.id, access_id, data.get_size()); + log!("[{:#X}] CreateApplicationArea -- device_handle: (fake id: {}), access_id: {:#X}, data: (buf_size: {:#X})\n", self.application_id.0, device_handle.id, access_id, data.get_size()); let amiibo = emu::get_active_virtual_amiibo(); result_return_unless!(amiibo.is_valid(), nfp::rc::ResultDeviceNotFound); - let application_area = area::ApplicationArea::from_id(&amiibo, self.application_id, access_id); + let application_area = area::ApplicationArea::from_id(&amiibo, self.application_id.0, access_id); result_return_if!(application_area.exists(), nfp::rc::ResultAreaNeedsToBeCreated); application_area.create(data.get_address(), data.get_size(), false)?; @@ -256,7 +257,7 @@ impl EmulationHandler { pub fn get_tag_info(&mut self, device_handle: nfp::DeviceHandle, mut out_tag_info: sf::OutFixedPointerBuffer) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagFound) || self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] GetTagInfo -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] GetTagInfo -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); let amiibo = emu::get_active_virtual_amiibo(); result_return_unless!(amiibo.is_valid(), nfp::rc::ResultDeviceNotFound); @@ -269,7 +270,7 @@ impl EmulationHandler { pub fn get_register_info(&mut self, device_handle: nfp::DeviceHandle, mut out_register_info: sf::OutFixedPointerBuffer) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] GetRegisterInfo -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] GetRegisterInfo -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); let amiibo = emu::get_active_virtual_amiibo(); result_return_unless!(amiibo.is_valid(), nfp::rc::ResultDeviceNotFound); @@ -282,7 +283,7 @@ impl EmulationHandler { pub fn get_common_info(&mut self, device_handle: nfp::DeviceHandle, mut out_common_info: sf::OutFixedPointerBuffer) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] GetCommonInfo -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] GetCommonInfo -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); let amiibo = emu::get_active_virtual_amiibo(); result_return_unless!(amiibo.is_valid(), nfp::rc::ResultDeviceNotFound); @@ -295,7 +296,7 @@ impl EmulationHandler { pub fn get_model_info(&mut self, device_handle: nfp::DeviceHandle, mut out_model_info: sf::OutFixedPointerBuffer) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] GetModelInfo -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] GetModelInfo -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); let amiibo = emu::get_active_virtual_amiibo(); result_return_unless!(amiibo.is_valid(), nfp::rc::ResultDeviceNotFound); @@ -307,31 +308,31 @@ impl EmulationHandler { pub fn attach_activate_event(&mut self, device_handle: nfp::DeviceHandle) -> Result { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] AttachActivateEvent -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] AttachActivateEvent -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); Ok(sf::Handle::from(self.activate_event.client_handle)) } pub fn attach_deactivate_event(&mut self, device_handle: nfp::DeviceHandle) -> Result { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] AttachDeactivateEvent -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] AttachDeactivateEvent -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); Ok(sf::Handle::from(self.deactivate_event.client_handle)) } pub fn get_state(&mut self) -> Result { - log!("[{:#X}] GetState -- (...)\n", self.application_id); + log!("[{:#X}] GetState -- (...)\n", self.application_id.0); Ok(self.state.get_val()) } pub fn get_device_state(&mut self, device_handle: nfp::DeviceHandle) -> Result { - log!("[{:#X}] GetDeviceState -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] GetDeviceState -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); Ok(self.device_state.get_val()) } pub fn get_npad_id(&mut self, device_handle: nfp::DeviceHandle) -> Result { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] GetNpadId -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] GetNpadId -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); Ok(unsafe { core::mem::transmute(device_handle.id) }) } @@ -340,7 +341,7 @@ impl EmulationHandler { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.current_opened_area.exists(), nfp::rc::ResultAreaNeedsToBeCreated); - log!("[{:#X}] GetApplicationAreaSize -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] GetApplicationAreaSize -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); let area_size = self.current_opened_area.get_size()?; Ok(area_size as u32) @@ -348,7 +349,7 @@ impl EmulationHandler { pub fn attach_availability_change_event(&mut self) -> Result { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] AttachAvailabilityChangeEvent -- (...)\n", self.application_id); + log!("[{:#X}] AttachAvailabilityChangeEvent -- (...)\n", self.application_id.0); Ok(sf::Handle::from(self.availability_change_event.client_handle)) } @@ -356,19 +357,19 @@ impl EmulationHandler { pub fn recreate_application_area(&mut self, device_handle: nfp::DeviceHandle, access_id: nfp::AccessId, data: sf::InMapAliasBuffer) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] RecreateApplicationArea -- device_handle: (fake id: {}), access_id: {:#X}, data: (buf_size: {:#X})\n", self.application_id, device_handle.id, access_id, data.get_size()); + log!("[{:#X}] RecreateApplicationArea -- device_handle: (fake id: {}), access_id: {:#X}, data: (buf_size: {:#X})\n", self.application_id.0, device_handle.id, access_id, data.get_size()); let amiibo = emu::get_active_virtual_amiibo(); result_return_unless!(amiibo.is_valid(), nfp::rc::ResultDeviceNotFound); - let application_area = area::ApplicationArea::from_id(&amiibo, self.application_id, access_id); + let application_area = area::ApplicationArea::from_id(&amiibo, self.application_id.0, access_id); application_area.create(data.get_address(), data.get_size(), true)?; amiibo.notify_written()?; Ok(()) } pub fn format(&mut self, device_handle: nfp::DeviceHandle) -> Result<()> { - log!("[{:#X}] Format -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] Format -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); Ok(()) } @@ -376,7 +377,7 @@ impl EmulationHandler { pub fn get_admin_info(&mut self, device_handle: nfp::DeviceHandle, mut out_admin_info: sf::OutFixedPointerBuffer) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] GetAdminInfo -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] GetAdminInfo -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); let amiibo = emu::get_active_virtual_amiibo(); result_return_unless!(amiibo.is_valid(), nfp::rc::ResultDeviceNotFound); @@ -389,7 +390,7 @@ impl EmulationHandler { pub fn get_register_info_private(&mut self, device_handle: nfp::DeviceHandle, mut out_register_info_private: sf::OutFixedPointerBuffer) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] GetRegisterInfoPrivate -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] GetRegisterInfoPrivate -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); let amiibo = emu::get_active_virtual_amiibo(); result_return_unless!(amiibo.is_valid(), nfp::rc::ResultDeviceNotFound); @@ -402,7 +403,7 @@ impl EmulationHandler { pub fn set_register_info_private(&mut self, device_handle: nfp::DeviceHandle, register_info_private: sf::InFixedPointerBuffer) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] SetRegisterInfoPrivate -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] SetRegisterInfoPrivate -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); let amiibo = emu::get_active_virtual_amiibo(); result_return_unless!(amiibo.is_valid(), nfp::rc::ResultDeviceNotFound); @@ -414,7 +415,7 @@ impl EmulationHandler { pub fn delete_register_info(&mut self, device_handle: nfp::DeviceHandle) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] DeleteRegisterInfo -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] DeleteRegisterInfo -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); let amiibo = emu::get_active_virtual_amiibo(); result_return_unless!(amiibo.is_valid(), nfp::rc::ResultDeviceNotFound); @@ -426,7 +427,7 @@ impl EmulationHandler { pub fn delete_application_area(&mut self, device_handle: nfp::DeviceHandle) -> Result<()> { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] DeleteApplicationArea -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] DeleteApplicationArea -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); let amiibo = emu::get_active_virtual_amiibo(); result_return_unless!(amiibo.is_valid(), nfp::rc::ResultDeviceNotFound); @@ -438,7 +439,7 @@ impl EmulationHandler { pub fn exists_application_area(&mut self, device_handle: nfp::DeviceHandle) -> Result { result_return_unless!(self.is_state(nfp::State::Initialized), nfp::rc::ResultDeviceNotFound); result_return_unless!(self.is_device_state(nfp::DeviceState::TagMounted), nfp::rc::ResultDeviceNotFound); - log!("[{:#X}] ExistsApplicationArea -- device_handle: (fake id: {})\n", self.application_id, device_handle.id); + log!("[{:#X}] ExistsApplicationArea -- device_handle: (fake id: {})\n", self.application_id.0, device_handle.id); let amiibo = emu::get_active_virtual_amiibo(); result_return_unless!(amiibo.is_valid(), nfp::rc::ResultDeviceNotFound); @@ -448,7 +449,7 @@ impl EmulationHandler { impl Drop for EmulationHandler { fn drop(&mut self) { - log!("[{:#X}] Dropping handler...\n", self.application_id); + log!("[{:#X}] Dropping handler...\n", self.application_id.0); self.should_end_thread.set(true); self.emu_handler_thread.join().unwrap(); } diff --git a/emuiibo/src/ipc/nfp/sys.rs b/emuiibo/src/ipc/nfp/sys.rs index f0b95c9..52b93c9 100644 --- a/emuiibo/src/ipc/nfp/sys.rs +++ b/emuiibo/src/ipc/nfp/sys.rs @@ -1,4 +1,5 @@ use nx::ipc::sf::hid; +use nx::ipc::sf::ncm; use nx::result::*; use nx::mem; use nx::ipc::sf; @@ -18,7 +19,7 @@ pub struct System { } impl System { - pub fn new(application_id: u64) -> Result { + pub fn new(application_id: ncm::ProgramId) -> Result { Ok(Self { handler: EmulationHandler::new(application_id)?, dummy_session: sf::Session::new() diff --git a/emuiibo/src/ipc/nfp/user.rs b/emuiibo/src/ipc/nfp/user.rs index 040dc41..51a30b0 100644 --- a/emuiibo/src/ipc/nfp/user.rs +++ b/emuiibo/src/ipc/nfp/user.rs @@ -4,6 +4,7 @@ use nx::mem; use nx::ipc::sf; use nx::ipc::server; use nx::ipc::sf::applet; +use nx::ipc::sf::ncm; use nx::ipc::sf::nfp; use nx::ipc::sf::nfp::IUser; use nx::ipc::sf::nfp::IUserManager; @@ -18,7 +19,7 @@ pub struct User { } impl User { - pub fn new(application_id: u64) -> Result { + pub fn new(application_id: ncm::ProgramId) -> Result { emu::register_intercepted_application_id(application_id); Ok(Self { diff --git a/emuiibo/src/main.rs b/emuiibo/src/main.rs index 4b3b74e..0f69f48 100644 --- a/emuiibo/src/main.rs +++ b/emuiibo/src/main.rs @@ -1,7 +1,5 @@ #![no_std] #![no_main] -#![feature(core_intrinsics)] -#![feature(const_maybe_uninit_zeroed)] #![feature(const_trait_impl)] #[macro_use] diff --git a/emuiigen/pom.xml b/emuiigen/pom.xml index 409fef7..559be38 100644 --- a/emuiigen/pom.xml +++ b/emuiigen/pom.xml @@ -21,9 +21,6 @@ true 1.8 1.7.10 - - 0.0.5 - 17