From d939fa3c611bb111b6c719841d30fc3af0ca8a2f Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Fri, 29 Mar 2024 00:54:16 -0400 Subject: [PATCH 1/4] log setup changes --- src/hollow_knight_memory.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/hollow_knight_memory.rs b/src/hollow_knight_memory.rs index 68756868..946cbd58 100644 --- a/src/hollow_knight_memory.rs +++ b/src/hollow_knight_memory.rs @@ -16,6 +16,7 @@ use ugly_widget::store::StoreGui; use std::string::String; use crate::file; +use crate::settings_gui::SettingsGui; // -------------------------------------------------------- @@ -3458,9 +3459,21 @@ impl SceneDataStore { // -------------------------------------------------------- -pub async fn wait_attach_hollow_knight(gui: &mut G) -> Process { +pub async fn wait_attach_hollow_knight(gui: &mut SettingsGui) -> Process { + let mut splits = gui.get_splits(); + let mut timing_method = gui.get_timing_method(); retry(|| { gui.loop_load_update_store(); + let new_timing_method = gui.get_timing_method(); + if new_timing_method != timing_method { + timing_method = new_timing_method; + asr::print_message(&format!("timing_method: {:?}", timing_method)); + } + let new_splits = gui.get_splits(); + if new_splits != splits { + splits = new_splits; + asr::print_message(&format!("splits: {:?}", splits)); + } HOLLOW_KNIGHT_NAMES.into_iter().find_map(Process::attach) }).await } From 479304d499061587453375e637f33caa9a0675c5 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Sun, 31 Mar 2024 23:51:47 -0400 Subject: [PATCH 2/4] Factor out check_timing_method, check_splits --- src/hollow_knight_memory.rs | 14 +++----------- src/lib.rs | 21 ++++++--------------- src/settings_gui.rs | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/hollow_knight_memory.rs b/src/hollow_knight_memory.rs index 946cbd58..25c6f022 100644 --- a/src/hollow_knight_memory.rs +++ b/src/hollow_knight_memory.rs @@ -3460,20 +3460,12 @@ impl SceneDataStore { // -------------------------------------------------------- pub async fn wait_attach_hollow_knight(gui: &mut SettingsGui) -> Process { - let mut splits = gui.get_splits(); let mut timing_method = gui.get_timing_method(); + let mut splits = gui.get_splits(); retry(|| { gui.loop_load_update_store(); - let new_timing_method = gui.get_timing_method(); - if new_timing_method != timing_method { - timing_method = new_timing_method; - asr::print_message(&format!("timing_method: {:?}", timing_method)); - } - let new_splits = gui.get_splits(); - if new_splits != splits { - splits = new_splits; - asr::print_message(&format!("splits: {:?}", splits)); - } + gui.check_timing_method(&mut timing_method); + gui.check_splits(&mut splits); HOLLOW_KNIGHT_NAMES.into_iter().find_map(Process::attach) }).await } diff --git a/src/lib.rs b/src/lib.rs index c25c2b22..c3ad0d95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,11 +56,8 @@ async fn main() { #[cfg(debug_assertions)] asr::print_message(&format!("geo: {:?}", game_manager_finder.get_geo(&process))); - let gui_splits = gui.get_splits(); - if gui_splits != splits { - splits = gui_splits; - asr::print_message(&format!("splits: {:?}", splits)); - auto_reset = splits::auto_reset_safe(&splits); + if let Some(new_splits) = gui.check_splits(&mut splits) { + auto_reset = splits::auto_reset_safe(new_splits); } #[cfg(debug_assertions)] @@ -86,18 +83,12 @@ async fn main() { ticks_since_gui += 1; if TICKS_PER_GUI <= ticks_since_gui && gui.load_update_store_if_unchanged() { if i == 0 && [TimerState::NotRunning, TimerState::Ended].contains(&asr::timer::state()) { - let new_timing_method = gui.get_timing_method(); - if new_timing_method != timing_method { - timing_method = new_timing_method; - *load_remover = TimingMethodLoadRemover::new(timing_method); - asr::print_message(&format!("timing_method: {:?}", timing_method)); + if let Some(new_timing_method) = gui.check_timing_method(&mut timing_method) { + *load_remover = TimingMethodLoadRemover::new(new_timing_method); } } - let gui_splits = gui.get_splits(); - if gui_splits != splits { - splits = gui_splits; - asr::print_message(&format!("splits: {:?}", splits)); - auto_reset = splits::auto_reset_safe(&splits); + if let Some(new_splits) = gui.check_splits(&mut splits) { + auto_reset = splits::auto_reset_safe(new_splits); } ticks_since_gui = 0; } diff --git a/src/settings_gui.rs b/src/settings_gui.rs index 27ebf8f8..fab0c8df 100644 --- a/src/settings_gui.rs +++ b/src/settings_gui.rs @@ -65,6 +65,28 @@ impl SettingsGui { gui.loop_load_update_store(); gui } + + pub fn check_timing_method(&self, timing_method: &mut TimingMethod) -> Option { + let new_timing_method = self.get_timing_method(); + if new_timing_method != *timing_method { + *timing_method = new_timing_method; + asr::print_message(&format!("timing_method: {:?}", timing_method)); + Some(new_timing_method) + } else { + None + } + } + + pub fn check_splits<'a>(&self, splits: &'a mut Vec) -> Option<&'a [Split]> { + let new_splits = self.get_splits(); + if new_splits != *splits { + *splits = new_splits; + asr::print_message(&format!("splits: {:?}", splits)); + Some(splits) + } else { + None + } + } } #[derive(Clone, Copy, Debug, Default, Deserialize, Eq, Gui, Ord, PartialEq, PartialOrd, RadioButtonOptions, Serialize)] From 9597f118602a227ba9b3a8328e7cfef593e47e57 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Mon, 1 Apr 2024 00:09:07 -0400 Subject: [PATCH 3/4] timing_method outside loop --- src/hollow_knight_memory.rs | 11 +++++------ src/lib.rs | 5 +++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hollow_knight_memory.rs b/src/hollow_knight_memory.rs index 25c6f022..4f4835c2 100644 --- a/src/hollow_knight_memory.rs +++ b/src/hollow_knight_memory.rs @@ -16,7 +16,8 @@ use ugly_widget::store::StoreGui; use std::string::String; use crate::file; -use crate::settings_gui::SettingsGui; +use crate::settings_gui::{SettingsGui, TimingMethod}; +use crate::splits::Split; // -------------------------------------------------------- @@ -3459,13 +3460,11 @@ impl SceneDataStore { // -------------------------------------------------------- -pub async fn wait_attach_hollow_knight(gui: &mut SettingsGui) -> Process { - let mut timing_method = gui.get_timing_method(); - let mut splits = gui.get_splits(); +pub async fn wait_attach_hollow_knight(gui: &mut SettingsGui, timing_method: &mut TimingMethod, splits: &mut Vec) -> Process { retry(|| { gui.loop_load_update_store(); - gui.check_timing_method(&mut timing_method); - gui.check_splits(&mut splits); + gui.check_timing_method(timing_method); + gui.check_splits(splits); HOLLOW_KNIGHT_NAMES.into_iter().find_map(Process::attach) }).await } diff --git a/src/lib.rs b/src/lib.rs index c3ad0d95..2c12c694 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,18 +34,19 @@ async fn main() { let mut gui = Box::new(SettingsGui::wait_load_merge_register().await); let mut ticks_since_gui = 0; + let mut timing_method = gui.get_timing_method(); let mut splits = gui.get_splits(); + asr::print_message(&format!("timing_method: {:?}", timing_method)); asr::print_message(&format!("splits: {:?}", splits)); let mut auto_reset: &'static [TimerState] = splits::auto_reset_safe(&splits); loop { - let process = wait_attach_hollow_knight(&mut *gui).await; + let process = wait_attach_hollow_knight(&mut *gui, &mut timing_method, &mut splits).await; process .until_closes(async { // TODO: Load some initial information from the process. let mut scene_store = Box::new(SceneStore::new()); - let mut timing_method = gui.get_timing_method(); let mut load_remover = Box::new(TimingMethodLoadRemover::new(timing_method)); next_tick().await; From 9ffcf153f5d4a9d0e30ca794a113daf925b416e1 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Mon, 1 Apr 2024 00:17:37 -0400 Subject: [PATCH 4/4] Factor out attach_hollow_knight, move wait version --- src/hollow_knight_memory.rs | 14 +++----------- src/lib.rs | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/hollow_knight_memory.rs b/src/hollow_knight_memory.rs index 4f4835c2..3ecc5203 100644 --- a/src/hollow_knight_memory.rs +++ b/src/hollow_knight_memory.rs @@ -5,19 +5,16 @@ use std::cmp::min; use std::mem; use std::collections::BTreeMap; use asr::file_format::{elf, pe}; -use asr::future::{next_tick, retry}; +use asr::future::next_tick; use asr::watcher::Pair; use asr::{Address, PointerSize, Process}; use asr::game_engine::unity::mono::{self, Image, Module, UnityPointer}; use asr::string::ArrayWString; -use ugly_widget::store::StoreGui; #[cfg(debug_assertions)] use std::string::String; use crate::file; -use crate::settings_gui::{SettingsGui, TimingMethod}; -use crate::splits::Split; // -------------------------------------------------------- @@ -3460,13 +3457,8 @@ impl SceneDataStore { // -------------------------------------------------------- -pub async fn wait_attach_hollow_knight(gui: &mut SettingsGui, timing_method: &mut TimingMethod, splits: &mut Vec) -> Process { - retry(|| { - gui.loop_load_update_store(); - gui.check_timing_method(timing_method); - gui.check_splits(splits); - HOLLOW_KNIGHT_NAMES.into_iter().find_map(Process::attach) - }).await +pub fn attach_hollow_knight() -> Option { + HOLLOW_KNIGHT_NAMES.into_iter().find_map(Process::attach) } fn process_pointer_size(process: &Process) -> Option { diff --git a/src/lib.rs b/src/lib.rs index 2c12c694..d0e6c024 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,12 +9,13 @@ mod legacy_xml; mod settings_gui; mod splits; -use asr::{future::next_tick, Process}; +use asr::future::{next_tick, retry}; +use asr::Process; use asr::time::Duration; use asr::timer::TimerState; use settings_gui::{SettingsGui, TimingMethod}; use hollow_knight_memory::*; -use splits::SplitterAction; +use splits::{Split, SplitterAction}; use ugly_widget::store::StoreGui; asr::async_main!(stable); @@ -39,8 +40,6 @@ async fn main() { asr::print_message(&format!("timing_method: {:?}", timing_method)); asr::print_message(&format!("splits: {:?}", splits)); - let mut auto_reset: &'static [TimerState] = splits::auto_reset_safe(&splits); - loop { let process = wait_attach_hollow_knight(&mut *gui, &mut timing_method, &mut splits).await; process @@ -48,6 +47,7 @@ async fn main() { // TODO: Load some initial information from the process. let mut scene_store = Box::new(SceneStore::new()); let mut load_remover = Box::new(TimingMethodLoadRemover::new(timing_method)); + let mut auto_reset: &'static [TimerState] = splits::auto_reset_safe(&splits); next_tick().await; let game_manager_finder = Box::new(GameManagerFinder::wait_attach(&process).await); @@ -57,10 +57,6 @@ async fn main() { #[cfg(debug_assertions)] asr::print_message(&format!("geo: {:?}", game_manager_finder.get_geo(&process))); - if let Some(new_splits) = gui.check_splits(&mut splits) { - auto_reset = splits::auto_reset_safe(new_splits); - } - #[cfg(debug_assertions)] let mut scenes_grub_rescued = game_manager_finder.scenes_grub_rescued(&process); #[cfg(debug_assertions)] @@ -101,6 +97,15 @@ async fn main() { } } +async fn wait_attach_hollow_knight(gui: &mut SettingsGui, timing_method: &mut TimingMethod, splits: &mut Vec) -> Process { + retry(|| { + gui.loop_load_update_store(); + gui.check_timing_method(timing_method); + gui.check_splits(splits); + attach_hollow_knight() + }).await +} + async fn tick_action( process: &Process, splits: &[splits::Split],