From afecfcc48c9e097b38f9ee238ef511337364dffa Mon Sep 17 00:00:00 2001 From: jugeeya Date: Fri, 8 Mar 2024 15:12:48 -0800 Subject: [PATCH] Fix Clippy --- .devcontainer/devcontainer.json | 6 ++---- src/common/dev_config.rs | 1 - src/common/menu.rs | 12 ++++++------ src/common/release.rs | 1 - src/training/air_dodge_direction.rs | 2 +- src/training/combo.rs | 2 -- src/training/directional_influence.rs | 6 +++--- src/training/full_hop.rs | 4 ---- src/training/mod.rs | 8 +++++--- src/training/sdi.rs | 2 +- src/training/ui/display.rs | 8 +++++--- src/training/ui/notifications.rs | 14 ++++++++------ 12 files changed, 31 insertions(+), 35 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 08fde9d..65f5d85 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,10 +2,8 @@ // https://github.com/microsoft/vscode-dev-containers/tree/v0.140.1/containers/docker-from-docker { "name": "Cargo Skyline", - "image": "jugeeya/cargo-skyline:3.2.0-no-dkp", - "mounts": [ - "source=ultimatetrainingmodpack-bashhistory,target=/commandhistory,type=volume" - ], + "image": "rust:1.73", + "mounts": [], // // Use this environment variable if you need to bind mount your local source code into a new container. "remoteEnv": { "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" diff --git a/src/common/dev_config.rs b/src/common/dev_config.rs index c72d195..322d16a 100644 --- a/src/common/dev_config.rs +++ b/src/common/dev_config.rs @@ -3,7 +3,6 @@ use std::fs; use lazy_static::lazy_static; use parking_lot::Mutex; use serde::Deserialize; -use toml; use crate::common::input::*; use crate::consts::DEV_TOML_PATH; diff --git a/src/common/menu.rs b/src/common/menu.rs index 340f7f7..9ddac59 100644 --- a/src/common/menu.rs +++ b/src/common/menu.rs @@ -2,16 +2,14 @@ use once_cell::sync::Lazy; use std::collections::HashMap; use std::fs; use std::io::BufReader; +use std::ptr::addr_of; use lazy_static::lazy_static; use parking_lot::Mutex; use skyline::nn::hid::GetNpadStyleSet; -use training_mod_consts::{create_app, MenuJsonStruct}; -use training_mod_tui::AppPage; use crate::common::button_config::button_mapping; use crate::common::*; -use crate::consts::MENU_OPTIONS_PATH; use crate::events::{Event, EVENT_QUEUE}; use crate::input::*; use crate::logging::*; @@ -53,9 +51,11 @@ pub fn load_from_file() { info!("Setting initial menu selections..."); unsafe { let mut app = QUICK_MENU_APP.lock(); - app.serialized_default_settings = - serde_json::to_string(&DEFAULTS_MENU).expect("Could not serialize DEFAULTS_MENU"); - app.update_all_from_json(&serde_json::to_string(&MENU).expect("Could not serialize MENU")); + app.serialized_default_settings = serde_json::to_string(&*addr_of!(DEFAULTS_MENU)) + .expect("Could not serialize DEFAULTS_MENU"); + app.update_all_from_json( + &serde_json::to_string(&*addr_of!(MENU)).expect("Could not serialize MENU"), + ); } } diff --git a/src/common/release.rs b/src/common/release.rs index 7a7b1d8..cd8967d 100644 --- a/src/common/release.rs +++ b/src/common/release.rs @@ -2,7 +2,6 @@ use crate::common::dialog; use crate::consts::*; use crate::logging::*; -use crate::MENU; use anyhow::{anyhow, Result}; use lazy_static::lazy_static; use parking_lot::Mutex; diff --git a/src/training/air_dodge_direction.rs b/src/training/air_dodge_direction.rs index 029b0e4..5206113 100644 --- a/src/training/air_dodge_direction.rs +++ b/src/training/air_dodge_direction.rs @@ -33,7 +33,7 @@ unsafe fn get_angle(module_accessor: &mut app::BattleObjectModuleAccessor) -> Op STICK_DIRECTION = MENU.air_dodge_dir.get_random(); STICK_DIRECTION.into_angle().map(|angle| { - if !should_reverse_angle(&STICK_DIRECTION) { + if !should_reverse_angle(STICK_DIRECTION) { // Direction is LEFT/RIGHT, so don't perform any adjustment angle } else { diff --git a/src/training/combo.rs b/src/training/combo.rs index 0b683b4..e850072 100644 --- a/src/training/combo.rs +++ b/src/training/combo.rs @@ -1,8 +1,6 @@ use skyline::nn::ui2d::ResColor; -use smash::app::BattleObjectModuleAccessor; use training_mod_consts::OnOff; -use crate::common::consts::FighterId; use crate::common::*; use crate::training::*; diff --git a/src/training/directional_influence.rs b/src/training/directional_influence.rs index cf5946e..9b44a98 100644 --- a/src/training/directional_influence.rs +++ b/src/training/directional_influence.rs @@ -58,7 +58,7 @@ unsafe fn mod_handle_di(fighter: &L2CFighterCommon, _arg1: L2CValue) { roll_di_case(); let angle_tuple = DI_CASE.into_angle().map_or((0.0, 0.0), |angle| { - let a = if should_reverse_angle(&DI_CASE) { + let a = if should_reverse_angle(DI_CASE) { PI - angle } else { angle @@ -70,12 +70,12 @@ unsafe fn mod_handle_di(fighter: &L2CFighterCommon, _arg1: L2CValue) { set_x_y(module_accessor, angle_tuple.0 as f32, angle_tuple.1 as f32); } -pub fn should_reverse_angle(direction: &Direction) -> bool { +pub fn should_reverse_angle(direction: Direction) -> bool { let cpu_module_accessor = get_module_accessor(FighterId::CPU); let player_module_accessor = get_module_accessor(FighterId::Player); unsafe { PostureModule::pos_x(player_module_accessor) > PostureModule::pos_x(cpu_module_accessor) - && ![Direction::LEFT, Direction::RIGHT].contains(direction) + && ![Direction::LEFT, Direction::RIGHT].contains(&direction) } } diff --git a/src/training/full_hop.rs b/src/training/full_hop.rs index ebeeb41..088f6ab 100644 --- a/src/training/full_hop.rs +++ b/src/training/full_hop.rs @@ -17,8 +17,6 @@ pub fn roll_full_hop() { } } -/** - */ pub unsafe fn check_button_on( module_accessor: &mut app::BattleObjectModuleAccessor, button: i32, @@ -29,8 +27,6 @@ pub unsafe fn check_button_on( Some(true) } -/** - */ pub unsafe fn check_button_off( module_accessor: &mut app::BattleObjectModuleAccessor, button: i32, diff --git a/src/training/mod.rs b/src/training/mod.rs index dd75bc7..a0eaf2c 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -1,3 +1,5 @@ +use std::ptr::addr_of_mut; + use crate::common::button_config; use crate::common::consts::{BuffOption, FighterId, MENU}; use crate::common::offsets::*; @@ -836,21 +838,21 @@ pub fn training_mods() { unsafe { LookupSymbol( - &mut FIGHTER_MANAGER_ADDR, + addr_of_mut!(FIGHTER_MANAGER_ADDR), "_ZN3lib9SingletonIN3app14FighterManagerEE9instance_E\u{0}" .as_bytes() .as_ptr(), ); LookupSymbol( - &mut STAGE_MANAGER_ADDR, + addr_of_mut!(STAGE_MANAGER_ADDR), "_ZN3lib9SingletonIN3app12StageManagerEE9instance_E\u{0}" .as_bytes() .as_ptr(), ); LookupSymbol( - &mut ITEM_MANAGER_ADDR, + addr_of_mut!(ITEM_MANAGER_ADDR), "_ZN3lib9SingletonIN3app11ItemManagerEE9instance_E\0" .as_bytes() .as_ptr(), diff --git a/src/training/sdi.rs b/src/training/sdi.rs index c39f652..41e232e 100644 --- a/src/training/sdi.rs +++ b/src/training/sdi.rs @@ -20,7 +20,7 @@ pub fn roll_direction() { unsafe fn get_sdi_direction() -> Option { DIRECTION.into_angle().map(|angle| { - if directional_influence::should_reverse_angle(&DIRECTION) { + if directional_influence::should_reverse_angle(DIRECTION) { PI - angle } else { angle diff --git a/src/training/ui/display.rs b/src/training/ui/display.rs index fc9f132..58c2042 100644 --- a/src/training/ui/display.rs +++ b/src/training/ui/display.rs @@ -1,3 +1,5 @@ +use std::ptr::addr_of_mut; + use skyline::nn::ui2d::*; use smash::ui2d::{SmashPane, SmashTextBox}; @@ -24,8 +26,8 @@ macro_rules! display_txt_fmt { pub unsafe fn draw(root_pane: &Pane) { let notification_idx = 0; - let queue = &mut ui::notifications::QUEUE; - let notification = queue.first_mut(); + let queue = addr_of_mut!(ui::notifications::QUEUE); + let notification = (*queue).first_mut(); root_pane .find_pane_by_name_recursive(display_parent_fmt!(notification_idx)) @@ -58,6 +60,6 @@ pub unsafe fn draw(root_pane: &Pane) { let has_completed = notification.check_completed(); if has_completed { - queue.remove(0); + (*queue).remove(0); } } diff --git a/src/training/ui/notifications.rs b/src/training/ui/notifications.rs index f137495..d2fa7d1 100644 --- a/src/training/ui/notifications.rs +++ b/src/training/ui/notifications.rs @@ -1,3 +1,5 @@ +use std::ptr::addr_of_mut; + use skyline::nn::ui2d::ResColor; pub static mut QUEUE: Vec = vec![]; @@ -45,8 +47,8 @@ impl Notification { pub fn notification(header: String, message: String, len: u32) { unsafe { - let queue = &mut QUEUE; - queue.push(Notification::new( + let queue = addr_of_mut!(QUEUE); + (*queue).push(Notification::new( header, message, len, @@ -62,14 +64,14 @@ pub fn notification(header: String, message: String, len: u32) { pub fn color_notification(header: String, message: String, len: u32, color: ResColor) { unsafe { - let queue = &mut QUEUE; - queue.push(Notification::new(header, message, len, color)); + let queue = addr_of_mut!(QUEUE); + (*queue).push(Notification::new(header, message, len, color)); } } pub fn clear_notifications(header: &'static str) { unsafe { - let queue = &mut QUEUE; - queue.retain(|notif| notif.header != header); + let queue = addr_of_mut!(QUEUE); + (*queue).retain(|notif| notif.header != header); } }