From 1063aa548218c6555d92df0b38e39e66ba059dbf Mon Sep 17 00:00:00 2001
From: sidschingis <SijingYou92@gmail.com>
Date: Wed, 29 Jul 2020 21:34:34 +0200
Subject: [PATCH] Update Mash (#118)

* Update mash.rs

Use StatusModule::change_status_request_from_script

* Extract Method

* Fix Air Dodge

* Add Reset Trigger

* Update Mash

Split up buffering and performing the action

Moved performing hook to fix being a frame late
---
 src/training/mash.rs | 20 +++++++++++++++++++-
 src/training/mod.rs  |  1 +
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/training/mash.rs b/src/training/mash.rs
index 6ef5b26..d68b655 100644
--- a/src/training/mash.rs
+++ b/src/training/mash.rs
@@ -97,11 +97,29 @@ pub unsafe fn get_command_flag_cat(
 
     check_buffer(module_accessor);
 
-    perform_action(module_accessor)
+    return 0;
+}
+
+pub fn handle_mash(module_accessor: &mut app::BattleObjectModuleAccessor){
+    unsafe{
+        if !is_operation_cpu(module_accessor) {
+            return;
+        }
+
+        perform_action(module_accessor);
+    }
 }
 
 unsafe fn check_buffer(module_accessor: &mut app::BattleObjectModuleAccessor) {
     if QUEUE.len() > 0 {
+        /*
+         Reset when CPU is idle to prevent deadlocks
+         and to reset when using the training mode reset
+        */
+        if is_idle(module_accessor) {
+            reset();
+        }
+
         return;
     }
 
diff --git a/src/training/mod.rs b/src/training/mod.rs
index a20fa9e..14798c5 100644
--- a/src/training/mod.rs
+++ b/src/training/mod.rs
@@ -101,6 +101,7 @@ pub unsafe fn get_stick_y_no_clamp(module_accessor: &mut app::BattleObjectModule
  */
 #[skyline::hook(replace = ControlModule::get_stick_x)]
 pub unsafe fn get_stick_x(module_accessor: &mut app::BattleObjectModuleAccessor) -> f32 {
+    mash::handle_mash(module_accessor);
     left_stick::mod_get_stick_x(module_accessor).unwrap_or_else(|| original!()(module_accessor))
 }