Skip to content

Commit

Permalink
Hide Notifications when Combo Counter is Off (#662)
Browse files Browse the repository at this point in the history
* Hides all notifications

* Working Notification Hiding

* Add and use PauseMenu structure

* Cargo fmt

* Clean-up

* Access Fields instead of magic offsets, use struct ptr instead of retyping
  • Loading branch information
GradualSyrup authored Jan 29, 2024
1 parent bf94573 commit 312363d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub static mut BASE_MENU: TrainingModpackMenu = unsafe { DEFAULTS_MENU };
pub static mut FIGHTER_MANAGER_ADDR: usize = 0;
pub static mut ITEM_MANAGER_ADDR: usize = 0;
pub static mut STAGE_MANAGER_ADDR: usize = 0;
pub static mut TRAINING_MENU_ADDR: *mut PauseMenu = core::ptr::null_mut();

#[cfg(not(feature = "outside_training_mode"))]
extern "C" {
Expand All @@ -36,6 +37,17 @@ pub fn is_training_mode() -> bool {
true
}

#[repr(C)]
// FUN_71013e7be0 sets this up (13.0.1) so look here if more values are needed
// If you need full size use gdb to look at allocator
pub struct PauseMenu {
padding: [u8; 0xb60], // Unknown Values
pub stale_move_toggle: u32, // Handles if Stale Moves are on, 0 for off, 1 for on
unknown1: u32,
unknown2: u32,
pub combo_display_toggle: u32, // Handles if Combo Counter displays, 0 for off, 1 for on
}

#[skyline::from_offset(*OFFSET_GET_BATTLE_OBJECT_FROM_ID as isize)]
pub fn get_battle_object_from_id(battle_object_id: u32) -> *mut app::BattleObject;

Expand Down
8 changes: 4 additions & 4 deletions src/training/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::common::button_config;
use crate::common::consts::{BuffOption, FighterId, MENU};
use crate::common::offsets::*;
use crate::common::{
dev_config, get_module_accessor, is_operation_cpu, is_training_mode, menu,
FIGHTER_MANAGER_ADDR, ITEM_MANAGER_ADDR, STAGE_MANAGER_ADDR,
dev_config, get_module_accessor, is_operation_cpu, is_training_mode, menu, PauseMenu,
FIGHTER_MANAGER_ADDR, ITEM_MANAGER_ADDR, STAGE_MANAGER_ADDR, TRAINING_MENU_ADDR,
};
use crate::hitbox_visualizer;
use crate::input::*;
Expand Down Expand Up @@ -423,8 +423,8 @@ pub unsafe fn handle_add_damage(
#[skyline::hook(offset = *OFFSET_STALE, inline)]
unsafe fn stale_handle(ctx: &mut InlineCtx) {
let x22 = ctx.registers[22].x.as_mut();
let training_structure_address = (*x22 + 0xb60) as *mut u8;
*training_structure_address = 1;
TRAINING_MENU_ADDR = (*x22) as *mut PauseMenu;
(*TRAINING_MENU_ADDR).stale_move_toggle = 1;
}

// Set Stale Moves to On in the menu text
Expand Down
14 changes: 11 additions & 3 deletions src/training/ui/display.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use skyline::nn::ui2d::*;
use smash::ui2d::{SmashPane, SmashTextBox};

use crate::{common::menu::QUICK_MENU_ACTIVE, training::ui};

use crate::common::{menu::QUICK_MENU_ACTIVE, TRAINING_MENU_ADDR};
use crate::training::ui;
macro_rules! display_parent_fmt {
($x:ident) => {
format!("TrModDisp{}", $x).as_str()
Expand All @@ -22,6 +22,8 @@ macro_rules! display_txt_fmt {
}

pub unsafe fn draw(root_pane: &Pane) {
// Make sure the combo counter is being displayed before we draw
let cc_displayed = (*TRAINING_MENU_ADDR).combo_display_toggle != 0;
let notification_idx = 0;

let queue = &mut ui::notifications::QUEUE;
Expand All @@ -30,14 +32,20 @@ pub unsafe fn draw(root_pane: &Pane) {
root_pane
.find_pane_by_name_recursive(display_parent_fmt!(notification_idx))
.unwrap()
.set_visible(notification.is_some() && !QUICK_MENU_ACTIVE);
.set_visible(notification.is_some() && !QUICK_MENU_ACTIVE && cc_displayed);
if notification.is_none() {
return;
}

let notification = notification.unwrap();
let color = notification.color;

if !cc_displayed {
// Set the notification to drawn so we don't draw it
notification.set_drawn();
notification.force_complete();
}

if !notification.has_drawn() {
notification.set_drawn();
root_pane
Expand Down
5 changes: 5 additions & 0 deletions src/training/ui/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ impl Notification {
self.length -= 1;
}

// Used to force the notification to be removed from queue
pub fn force_complete(&mut self) {
self.length = 0;
}

// Returns: has_completed
pub fn check_completed(&mut self) -> bool {
if self.length <= 1 {
Expand Down

0 comments on commit 312363d

Please sign in to comment.