Skip to content

Commit

Permalink
add resiliancy to fast pickup/drop in cat tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
gmjosack committed Sep 29, 2022
1 parent e6322fb commit 550cbc9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions libs/mem_reader/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ pub struct GameState {
pub player_data: PlayerData,
pub player_ducking: bool,
pub player_ledge_grabbing: bool,
pub player_animation_type: u32,
pub player_animation_frame: u32,
pub player_held_entity: Option<PartialEntity>,

pub inputs: HashSet<Input>,
Expand Down Expand Up @@ -769,6 +771,8 @@ impl CategoryTrackerPayload {
} as usize;
let player_data_offset = global_state_offset + (0x440694 + (0x14a4 * active_player));
let player_data = get_player_data(process, player_data_offset)?;
let player_animation_type = process.read_u32(player_ptr + 0x134)?;
let player_animation_frame = process.read_u32(player_ptr + 0x138)?;
let player_ducking = process.read_u8(player_ptr + 0x206)? != 0;
let player_ledge_grabbing = process.read_u8(player_ptr + 0x207)? != 0;
let player_held_entity =
Expand Down Expand Up @@ -813,6 +817,8 @@ impl CategoryTrackerPayload {
total_money,
respawn_level,

player_animation_type,
player_animation_frame,
player_ducking,
player_ledge_grabbing,
player_held_entity,
Expand Down
2 changes: 1 addition & 1 deletion libs/show_procs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use winapi::um::tlhelp32::{
CreateToolhelp32Snapshot, Process32First, Process32Next, PROCESSENTRY32, TH32CS_SNAPPROCESS,
};

fn get_lunky_procs() -> Result<Vec<String>, anyhow::Error> {
fn _get_lunky_procs() -> Result<Vec<String>, anyhow::Error> {
let mut procs = vec![];

let process_snap = unsafe { CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) };
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "Apache 2"
name = "hd-toolbox"
repository = ""
rust-version = "1.57"
version = "0.5.1"
version = "0.5.2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
39 changes: 36 additions & 3 deletions src-tauri/src/tasks/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ struct RunState {
hell_failed: bool,
max_failed: bool,
failed_low_if_not_hell: bool,

frames_since_down: u32,
}

impl Default for RunState {
Expand Down Expand Up @@ -69,6 +71,8 @@ impl Default for RunState {
hell_failed: false,
max_failed: false,
failed_low_if_not_hell: false,

frames_since_down: 0,
}
}
}
Expand All @@ -82,13 +86,14 @@ impl RunState {
}

fn update(&mut self, prev_gamestate: &GameState, gamestate: &GameState) {
self.update_down_state(gamestate);
self.update_on_level_start(prev_gamestate, gamestate);
self.update_no_gold(gamestate);
self.update_pacifist(gamestate);
self.update_starting_resources(prev_gamestate, gamestate);
self.update_has_item(gamestate);
self.update_held_item(gamestate);
self.update_used_item(gamestate);
self.update_used_item(prev_gamestate, gamestate);
self.update_no_transition(gamestate);
self.update_visited(gamestate);
self.update_hell(gamestate);
Expand All @@ -97,6 +102,17 @@ impl RunState {
self.process_victory(gamestate);
}

fn update_down_state(&mut self, gamestate: &GameState) {
if Self::is_ducking(gamestate) || gamestate.inputs.contains(&Input::Down) {
self.frames_since_down = 0
} else {
if self.frames_since_down == u32::MAX {
return;
}
self.frames_since_down += 1
}
}

fn update_on_level_start(&mut self, prev_gamestate: &GameState, gamestate: &GameState) {
if prev_gamestate.level != gamestate.level {
self.level_started = true;
Expand Down Expand Up @@ -272,7 +288,7 @@ impl RunState {
}
}

fn update_used_item(&mut self, gamestate: &GameState) {
fn update_used_item(&mut self, prev_gamestate: &GameState, gamestate: &GameState) {
let banned_low_items = [
EntityType::Mattock,
EntityType::Boomerang,
Expand All @@ -293,8 +309,10 @@ impl RunState {

if banned_low_items.contains(&held_entity.entity_type)
&& gamestate.inputs.contains(&Input::Whip)
&& !gamestate.player_ducking
&& !Self::is_ducking(gamestate)
&& !Self::is_ducking(prev_gamestate)
&& !gamestate.player_ledge_grabbing
&& self.frames_since_down > 8
{
self.fail_low();
if &held_entity.entity_type == &EntityType::Teleporter {
Expand All @@ -303,6 +321,21 @@ impl RunState {
}
}

fn is_ducking(gamestate: &GameState) -> bool {
if gamestate.player_ducking {
return true;
}

// 25 - Ducking
// 6 - Ducked
// 7 - Crawling
if [25, 6, 7].contains(&gamestate.player_animation_type) {
return true;
}

return false;
}

fn update_no_transition(&mut self, gamestate: &GameState) {
if gamestate.screen_state != ScreenState::LevelCompleted {
return;
Expand Down

0 comments on commit 550cbc9

Please sign in to comment.