Skip to content

Commit

Permalink
Remove dependencies on parking_lot and once_cell for modern alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
Raytwo committed Oct 4, 2024
1 parent b555827 commit 5be09f2
Show file tree
Hide file tree
Showing 33 changed files with 461 additions and 355 deletions.
13 changes: 5 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ semver = { version = "1", features = ["serde"] }
num-derive = "0.4.0"
num-traits = "0.2.15"
walkdir = "2.3.3"
parking_lot = "0.12.1"
once_cell = "1.18.0"
# parking_lot = "0.12.1"
thiserror = "1.0.43"
minreq = { version = "2", features = ["https-native", "json-using-serde"], optional = true }
camino = "1"
# Switch utilities
skyline = { git = "https://github.com/Raytwo/skyline-rs", branch="preview" }
skyline-web = "0.1"
skyline-config = { git = "https://github.com/skyline-rs/skyline-config" }
skyline-communicate = { git = "https://github.com/blu-dev/skyline-communicate" }
# For the updater
zip = { version = "0.6", default-features = false, features = ["deflate"], optional = true }
gh-updater = { git = "https://github.com/blu-dev/gh-updater", default-features = false, features = ["native-tls"], optional = true }
Expand Down Expand Up @@ -66,7 +62,7 @@ ninput = { git = "https://github.com/blu-dev/ninput" }
# For Offset Searching
lazysimd = { git = "https://github.com/Raytwo/lazysimd" }
config = { path = "crates/config" }
menus = { path = "crates/menus" }
menus = { path = "crates/menus", optional = true }

[patch.crates-io]
nnsdk = { git = "https://github.com/ultimate-research/nnsdk-rs"}
Expand All @@ -75,8 +71,9 @@ native-tls = { git = "https://github.com/skyline-rs/rust-native-tls", rev = "f20
crc32fast = { git = "https://github.com/srijs/rust-crc32fast", rev = "e9c65bd" }

[features]
default = ["online"]
online = ["zip", "gh-updater", "minreq"]
default = ["online", "ui"]
online = ["zip", "gh-updater"]
ui = ["menus"]

[profile.dev]
panic = "abort"
Expand Down
2 changes: 0 additions & 2 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ skyline-config = { git = "https://github.com/skyline-rs/skyline-config" }
walkdir = "2.3.3"
thiserror = "1.0.43"
semver = { version = "1", features = ["serde"] }
once_cell = "1.18.0"
parking_lot = "0.12.1"
camino = "1"
lazysimd = { git = "https://github.com/Raytwo/lazysimd" }
11 changes: 5 additions & 6 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![feature(lazy_cell)]

use std::{
collections::{HashMap, HashSet},
path::PathBuf,
sync::Mutex,
sync::{LazyLock, Mutex, RwLock},
};

use log::info;
use once_cell::sync::Lazy;
use parking_lot::RwLock;
use semver::Version;
use skyline::nn;
use skyline_config::*;
Expand All @@ -16,9 +16,8 @@ use walkdir::WalkDir;
use crate::utils::env::get_arcropolis_version;

mod utils;
mod offsets;

pub static GLOBAL_CONFIG: Lazy<Mutex<StorageHolder<ArcStorage>>> = Lazy::new(|| {
pub static GLOBAL_CONFIG: LazyLock<Mutex<StorageHolder<ArcStorage>>> = LazyLock::new(|| {
let mut storage = StorageHolder::new(ArcStorage::new());
let version: Result<Version, _> = storage.get_field("version");

Expand Down Expand Up @@ -115,7 +114,7 @@ pub fn skip_title_scene() -> bool {
pub static REGION: RwLock<Region> = RwLock::new(Region::UsEnglish);

pub fn region() -> Region {
*REGION.read()
*REGION.read().unwrap()
}

pub fn logger_level() -> String {
Expand Down
72 changes: 0 additions & 72 deletions crates/config/src/offsets.rs

This file was deleted.

125 changes: 2 additions & 123 deletions crates/config/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use skyline::nn;

pub mod env {
use once_cell::sync::Lazy;
use semver::Version;
use std::str::FromStr;
use std::{str::FromStr, sync::LazyLock};

use super::*;

Expand All @@ -13,7 +12,7 @@ pub mod env {
Emulator,
}

static PLATFORM: Lazy<RunEnvironment> = Lazy::new(|| {
static PLATFORM: LazyLock<RunEnvironment> = LazyLock::new(|| {
let base_addr = unsafe { skyline::hooks::getRegionAddress(skyline::hooks::Region::Text) as u64 };

if base_addr == 0x8004000 || base_addr == 0x8504000 {
Expand Down Expand Up @@ -79,123 +78,3 @@ pub mod paths {
Utf8PathBuf::from("sd:/ultimate/arcropolis/cache").join(get_game_version().to_string())
}
}

pub mod save {
use super::*;
use smash_arc::Region;
use std::io::{Read, Result, Seek, SeekFrom};

#[repr(u8)]
#[derive(Debug)]
pub enum SaveLanguageId {
Japanese = 0,
English,
French,
Spanish,
German,
Italian,
Dutch,
Russian,
Chinese,
Taiwanese,
Korean,
}

impl From<u8> for SaveLanguageId {
fn from(byte: u8) -> Self {
match byte {
0 => Self::Japanese,
1 => Self::English,
2 => Self::French,
3 => Self::Spanish,
4 => Self::German,
5 => Self::Italian,
6 => Self::Dutch,
7 => Self::Russian,
8 => Self::Chinese,
9 => Self::Taiwanese,
10 => Self::Korean,
_ => Self::English,
}
}
}

pub fn mount_save(mount_path: &str) {
// TODO: Call nn::fs::CheckMountName
// This provides a UserHandle and sets the User in a Open state to be used.
let handle = nn::account::try_open_preselected_user().expect("OpenPreselectedUser should not return false");
// Obtain the UID for this user
let uid = nn::account::get_user_id(&handle).expect("GetUserId should return a valid Uid");

unsafe { nn::fs::MountSaveData(skyline::c_str(&format!("{}\0", mount_path)), &uid) };

// This closes the UserHandle, making it unusable, and sets the User in a Closed state.
// Smash will crash if you don't do it.
nn::account::close_user(handle);
}

pub fn unmount_save(mount_path: &str) {
// TODO: Call nn::fs::CheckMountName
unsafe { nn::fs::Unmount(skyline::c_str(&format!("{}\0", mount_path))) };
}

pub fn get_language_id_in_savedata() -> Result<SaveLanguageId> {
let mut file = std::fs::File::open("save:/save_data/system_data.bin")?;
file.seek(SeekFrom::Start(0x3c6098)).unwrap();
let mut language_code = [0u8];
file.read_exact(&mut language_code).unwrap();
drop(file);

Ok(SaveLanguageId::from(language_code[0]))
}

// pub fn get_system_region_from_language_id(language: SaveLanguageId) -> Region {
// let system_locale_id = unsafe { *(skyline::hooks::getRegionAddress(skyline::hooks::Region::Text) as *const u8).add(crate::offsets::system_locale_id()) };

// // let system_region_map = unsafe {
// // std::slice::from_raw_parts(
// // (skyline::hooks::getRegionAddress(skyline::hooks::Region::Text) as *const u32).add(0x4740f90 / 4),
// // 14,
// // )
// // };

// let system_region_map: &[u32] = &[0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4];

// let system_region = system_region_map[system_locale_id as usize];

// match language {
// SaveLanguageId::Japanese => Region::Japanese,
// SaveLanguageId::English => {
// if system_region == 1 {
// // US
// Region::UsEnglish
// } else {
// Region::EuEnglish
// }
// },
// SaveLanguageId::French => {
// if system_region == 1 {
// // US
// Region::UsFrench
// } else {
// Region::EuFrench
// }
// },
// SaveLanguageId::Spanish => {
// if system_region == 1 {
// // US
// Region::UsSpanish
// } else {
// Region::EuSpanish
// }
// },
// SaveLanguageId::German => Region::EuGerman,
// SaveLanguageId::Dutch => Region::EuDutch,
// SaveLanguageId::Italian => Region::EuItalian,
// SaveLanguageId::Russian => Region::EuRussian,
// SaveLanguageId::Chinese => Region::ChinaChinese,
// SaveLanguageId::Taiwanese => Region::TaiwanChinese,
// SaveLanguageId::Korean => Region::Korean,
// }
// }
}
2 changes: 0 additions & 2 deletions crates/menus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ smash-arc = { git = "https://github.com/jam1garner/smash-arc" }
skyline = { git = "https://github.com/Raytwo/skyline-rs", branch="preview" }
config = { path = "../config" }
semver = { version = "1", features = ["serde"] }
once_cell = "1.18.0"
parking_lot = "0.12.1"
camino = "1"
minreq = { version = "2", features = ["https-native", "json-using-serde"] }

Expand Down
2 changes: 2 additions & 0 deletions crates/menus/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(lazy_cell)]

pub mod arcadia;
pub use arcadia::*;
pub mod workspaces;
Expand Down
4 changes: 2 additions & 2 deletions crates/menus/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use skyline::nn;

pub mod env {
use once_cell::sync::Lazy;
use semver::Version;
use std::str::FromStr;
use std::sync::LazyLock;

use super::*;

Expand All @@ -13,7 +13,7 @@ pub mod env {
Emulator,
}

static PLATFORM: Lazy<RunEnvironment> = Lazy::new(|| {
static PLATFORM: LazyLock<RunEnvironment> = LazyLock::new(|| {
let base_addr = unsafe { skyline::hooks::getRegionAddress(skyline::hooks::Region::Text) as u64 };

if base_addr == 0x8004000 || base_addr == 0x8504000 {
Expand Down
8 changes: 2 additions & 6 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ pub extern "C" fn arcrop_api_version() -> &'static ApiVersion {
&API_VERSION
}

pub fn show_dialog(text: &str) {
skyline_web::DialogOk::ok(text);
}

#[no_mangle]
pub extern "C" fn arcrop_require_api_version(major: u32, minor: u32) {
if major > API_VERSION.major || (major == API_VERSION.major && minor > API_VERSION.minor) {
Expand All @@ -47,13 +43,13 @@ pub extern "C" fn arcrop_require_api_version(major: u32, minor: u32) {
}

fn show_arcrop_update_prompt() -> ! {
show_dialog("Your ARCropolis version is older than one of your plugins supports, an update is required");
skyline::error::show_error(69, "ARCropolis API error, press Details.\0", "Your ARCropolis version is older than one of your plugins supports, an update is required");

unsafe { skyline::nn::oe::ExitApplication() }
}

fn show_plugin_update_prompt() -> ! {
show_dialog("Your ARCropolis version is too new for one of your plugins, it must be updated to support this API version");
skyline::error::show_error(69, "ARCropolis API error, press Details.\0", "Your ARCropolis version is too new for one of your plugins, it must be updated to support this API version");

unsafe { skyline::nn::oe::ExitApplication() }
}
Loading

0 comments on commit 5be09f2

Please sign in to comment.