Skip to content
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
74 changes: 7 additions & 67 deletions src/hollow_knight_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use alloc::string::ToString;
use alloc::vec;
use alloc::vec::Vec;
#[cfg(not(target_os = "unknown"))]
use asr::file_format::{elf, pe};
use asr::future::{next_tick, retry};
use asr::game_engine::unity::mono::{self, Image, Module, UnityPointer};
use asr::game_engine::unity::scene_manager::{self, SceneManager};
Expand All @@ -17,9 +15,6 @@
use core::iter::FusedIterator;
use core::mem;

#[cfg(not(target_os = "unknown"))]
use crate::file;

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

static HOLLOW_KNIGHT_NAMES: [&str; 5] = [
Expand Down Expand Up @@ -2504,13 +2499,9 @@
}

impl GameManagerFinder {
fn new(
pointer_size: PointerSize,
module: mono::Module,
image: mono::Image,
) -> GameManagerFinder {
fn new(module: mono::Module, image: mono::Image) -> GameManagerFinder {
GameManagerFinder {
string_list_offests: Box::new(StringListOffsets::new(pointer_size)),
string_list_offests: Box::new(StringListOffsets::new(module.get_pointer_size())),
module: Box::new(module),
image,
pointers: Box::new(GameManagerPointers::new()),
Expand All @@ -2523,29 +2514,6 @@
}

pub async fn wait_attach(process: &Process) -> GameManagerFinder {
#[cfg(not(target_os = "unknown"))]
let pointer_size = match process_pointer_size(process) {
Some(s) => {
asr::print_message(&format!(
"GameManagerFinder wait_attach: pointer_size = {:?}",
s
));
s
}
None => {
asr::print_message(&format!(
"GameManagerFinder wait_attach: pointer_size not found, guessing Bit64"
));
PointerSize::Bit64
}
};
#[cfg(target_os = "unknown")]
let pointer_size = {
asr::print_message(&format!(
"GameManagerFinder wait_attach: unknown, guessing Bit64"
));
PointerSize::Bit64
};
asr::print_message("GameManagerFinder wait_attach: Module wait_attach_auto_detect...");
next_tick().await;
let mut found_module = false;
Expand All @@ -2559,9 +2527,12 @@
}
for _ in 0..0x10 {
if let Some(image) = module.get_default_image(process) {
asr::print_message("GameManagerFinder wait_attach: got module and image");
asr::print_message(&format!(
"GameManagerFinder wait_attach: got module and image, pointer_size = {:?}",
module.get_pointer_size()
));
next_tick().await;
return GameManagerFinder::new(pointer_size, module, image);
return GameManagerFinder::new(module, image);
}
next_tick().await;
}
Expand Down Expand Up @@ -2683,7 +2654,7 @@
.deref(process, &self.module, &self.image)
.ok()?
}
} else {

Check warning on line 2657 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
Expand Down Expand Up @@ -5374,14 +5345,14 @@

pub fn sly_shop_finished(&mut self, p: &Process, g: &GameManagerFinder) -> bool {
if !g.is_game_state_non_menu(p) {
return self

Check warning on line 5348 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
.map_bool
.get("sly_shop_finished")
.unwrap_or(&false)
.clone();
};
let Some(b) = g.sly_shop_finished(p) else {
return self

Check warning on line 5355 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
.map_bool
.get("sly_shop_finished")
.unwrap_or(&false)
Expand Down Expand Up @@ -5493,14 +5464,14 @@

pub fn grub_waterways_isma(&mut self, p: &Process, g: &GameManagerFinder) -> bool {
if !g.is_game_state_non_menu(p) {
return self

Check warning on line 5467 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
.map_bool
.get("grub_waterways_isma")
.unwrap_or(&false)
.clone();
};
let Some(b) = g.grub_waterways_isma(p) else {
return self

Check warning on line 5474 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
.map_bool
.get("grub_waterways_isma")
.unwrap_or(&false)
Expand Down Expand Up @@ -7317,7 +7288,7 @@
"guardians_defeated",
&gmf.player_data_pointers.guardians_defeated,
) {
if !(p.old < p.current) {

Check warning on line 7291 in src/hollow_knight_memory.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

this boolean expression can be simplified
return false;
}
asr::timer::set_variable("item", &format!("Dreamer {}", p.current));
Expand Down Expand Up @@ -7437,37 +7408,6 @@
HOLLOW_KNIGHT_NAMES.into_iter().find_map(Process::attach)
}

#[cfg(not(target_os = "unknown"))]
fn process_pointer_size(process: &Process) -> Option<PointerSize> {
let path = process.get_path().ok()?;
let bytes = file::file_read_all_bytes(path).ok()?;
if bytes.starts_with(&[0x4D, 0x5A]) {
// PE
let mono_addr = ["mono.dll", "mono-2.0-bdwgc.dll"]
.into_iter()
.find_map(|mono_name| process.get_module_address(mono_name).ok())?;
pe::MachineType::read(process, mono_addr)?.pointer_size()
} else if bytes.starts_with(&[0x7F, 0x45, 0x4C, 0x46]) {
// ELF
let mono_addr = ["libmono.so", "libmonobdwgc-2.0.so"]
.into_iter()
.find_map(|mono_name| process.get_module_address(mono_name).ok())?;
elf::pointer_size(process, mono_addr)
} else if bytes.starts_with(&[0xFE, 0xED, 0xFA, 0xCE])
| bytes.starts_with(&[0xCE, 0xFA, 0xED, 0xFE])
{
// MachO 32-bit
Some(PointerSize::Bit32)
} else if bytes.starts_with(&[0xFE, 0xED, 0xFA, 0xCF])
| bytes.starts_with(&[0xCF, 0xFA, 0xED, 0xFE])
{
// MachO 64-bit
Some(PointerSize::Bit64)
} else {
None
}
}

async fn wait_attach_auto_detect(process: &Process) -> mono::Module {
retry(|| attach_auto_detect(process)).await
}
Expand Down
3 changes: 3 additions & 0 deletions src/timer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(feature = "unstable")]
use alloc::format;

use asr::timer::TimerState;

use crate::unstable::maybe_timer_current_split_index;
Expand Down
Loading