Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print setup logs before game is open #67

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/hollow_knight_memory.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

Check failure on line 1 in src/hollow_knight_memory.rs

View workflow job for this annotation

GitHub Actions / Check formatting

Diff in /home/runner/work/hollowknight-autosplit-wasm/hollowknight-autosplit-wasm/src/hollow_knight_memory.rs
use core::cell::OnceCell;
use core::iter::FusedIterator;
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;
Expand Down Expand Up @@ -1140,7 +1139,7 @@
} else {
self.pointers.ui_state_vanilla.deref(process, &self.module, &self.image).ok()?
}
} else {

Check warning on line 1142 in src/hollow_knight_memory.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

this `else { if .. }` block can be collapsed
if let Ok(ui) = self.pointers.ui_state_vanilla.deref(process, &self.module, &self.image) {
self.modded.set(false).ok();
ui
Expand Down Expand Up @@ -2705,10 +2704,10 @@

pub fn sly_shop_finished(&mut self, p: &Process, g: &GameManagerFinder) -> bool {
if !g.is_game_state_non_menu(p) {
return self.map_bool.get("sly_shop_finished").unwrap_or(&false).clone();

Check warning on line 2707 in src/hollow_knight_memory.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

using `clone` on type `bool` which implements the `Copy` trait
};
let Some(b) = g.sly_shop_finished(p) else {
return self.map_bool.get("sly_shop_finished").unwrap_or(&false).clone();

Check warning on line 2710 in src/hollow_knight_memory.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

using `clone` on type `bool` which implements the `Copy` trait
};
self.map_bool.insert("sly_shop_finished", b);
b
Expand Down Expand Up @@ -2787,10 +2786,10 @@

pub fn grub_waterways_isma(&mut self, p: &Process, g: &GameManagerFinder) -> bool {
if !g.is_game_state_non_menu(p) {
return self.map_bool.get("grub_waterways_isma").unwrap_or(&false).clone();

Check warning on line 2789 in src/hollow_knight_memory.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

using `clone` on type `bool` which implements the `Copy` trait
};
let Some(b) = g.grub_waterways_isma(p) else {
return self.map_bool.get("grub_waterways_isma").unwrap_or(&false).clone();

Check warning on line 2792 in src/hollow_knight_memory.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

using `clone` on type `bool` which implements the `Copy` trait
};
self.map_bool.insert("grub_waterways_isma", b);
b
Expand Down Expand Up @@ -3458,11 +3457,8 @@

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

pub async fn wait_attach_hollow_knight<G: StoreGui>(gui: &mut G) -> Process {
retry(|| {
gui.loop_load_update_store();
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 Expand Up @@ -3495,10 +3491,10 @@

fn read_string_object<const N: usize>(process: &Process, offsets: &StringListOffsets, a: Address) -> Option<String> {
let n: u32 = process.read(a + offsets.string_len).ok()?;
if !(n < 2048) { return None; }

Check warning on line 3494 in src/hollow_knight_memory.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

this boolean expression can be simplified
let w: ArrayWString<N> = process.read(a + offsets.string_contents).ok()?;
if !(w.len() == min(n as usize, N)) { return None; }

Check warning on line 3496 in src/hollow_knight_memory.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

this boolean expression can be simplified
String::from_utf16(&w.to_vec()).ok()

Check warning on line 3497 in src/hollow_knight_memory.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

unnecessary use of `to_vec`
}

fn list_object_iter<'a>(process: &'a Process, offsets: &'a StringListOffsets, a: Address) -> Option<impl FusedIterator<Item = Address> + 'a> {
Expand Down Expand Up @@ -3558,7 +3554,7 @@
}

pub fn starts_with_any(full: &str, prefixes: &[&str]) -> bool {
prefixes.into_iter().any(|prefix| full.starts_with(prefix))

Check warning on line 3557 in src/hollow_knight_memory.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice`
}

// --------------------------------------------------------
43 changes: 20 additions & 23 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 @@ -34,19 +35,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));
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 @@ -56,13 +57,6 @@ 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);
}

#[cfg(debug_assertions)]
let mut scenes_grub_rescued = game_manager_finder.scenes_grub_rescued(&process);
#[cfg(debug_assertions)]
Expand All @@ -86,18 +80,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;
}
Expand All @@ -109,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
22 changes: 22 additions & 0 deletions src/settings_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ impl SettingsGui {
gui.loop_load_update_store();
gui
}

pub fn check_timing_method(&self, timing_method: &mut TimingMethod) -> Option<TimingMethod> {
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<Split>) -> 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)]
Expand Down
Loading