Skip to content

Commit

Permalink
Update for latest libs
Browse files Browse the repository at this point in the history
  • Loading branch information
XorTroll committed Apr 13, 2024
1 parent 550e5c8 commit 4cb95fb
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 94 deletions.
46 changes: 23 additions & 23 deletions emuiibo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions emuiibo/src/amiibo/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use nx::ipc::sf::ncm;
use nx::result::*;
use serde::{Serialize, Deserialize};
use alloc::string::String;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -177,7 +178,7 @@ pub fn generate_areas_json(path: String) -> Result<Option<nfp::AccessId>> {
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);
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion emuiibo/src/amiibo/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)?;

Expand Down
4 changes: 2 additions & 2 deletions emuiibo/src/amiibo/v2.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 7 additions & 6 deletions emuiibo/src/emu.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use nx::sync;
use nx::ipc::sf::ncm;
use alloc::vec::Vec;
use crate::amiibo;
use crate::fsext;
Expand Down Expand Up @@ -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)
}
}

Expand Down
7 changes: 4 additions & 3 deletions emuiibo/src/ipc/emu.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<u8>) => (virtual_amiibo: amiibo::fmt::VirtualAmiiboData);
get_active_virtual_amiibo_areas [11, version::VersionInterval::all()]: (out_areas: sf::OutMapAliasBuffer<amiibo::fmt::VirtualAmiiboAreaEntry>) => (count: u32);
get_active_virtual_amiibo_current_area [12, version::VersionInterval::all()]: () => (access_id: nfp::AccessId);
Expand Down Expand Up @@ -104,8 +105,8 @@ impl IEmulationService for EmulationService {
Ok(())
}

fn is_application_id_intercepted(&mut self, application_id: u64) -> Result<bool> {
log!("IsApplicationIdIntercepted -- app_id: {:#X}\n", application_id);
fn is_application_id_intercepted(&mut self, application_id: ncm::ProgramId) -> Result<bool> {
log!("IsApplicationIdIntercepted -- app_id: {:#X}\n", application_id.0);
Ok(emu::is_application_id_intercepted(application_id))
}

Expand Down
Loading

0 comments on commit 4cb95fb

Please sign in to comment.