Skip to content

Commit

Permalink
Factor out attach_hollow_knight, move wait version
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKnauth committed Apr 19, 2024
1 parent 9597f11 commit 9ffcf15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
14 changes: 3 additions & 11 deletions src/hollow_knight_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

// --------------------------------------------------------

Expand Down Expand Up @@ -3460,13 +3457,8 @@ impl SceneDataStore {

// --------------------------------------------------------

pub async fn wait_attach_hollow_knight(gui: &mut SettingsGui, timing_method: &mut TimingMethod, splits: &mut Vec<Split>) -> 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<Process> {
HOLLOW_KNIGHT_NAMES.into_iter().find_map(Process::attach)
}

fn process_pointer_size(process: &Process) -> Option<PointerSize> {
Expand Down
21 changes: 13 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -39,15 +40,14 @@ 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
.until_closes(async {
// 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);
Expand All @@ -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)]
Expand Down Expand Up @@ -101,6 +97,15 @@ async fn main() {
}
}

async fn wait_attach_hollow_knight(gui: &mut SettingsGui, timing_method: &mut TimingMethod, splits: &mut Vec<Split>) -> 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],
Expand Down

0 comments on commit 9ffcf15

Please sign in to comment.