Skip to content

Commit

Permalink
splitting for agnea and optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Eein committed Apr 3, 2023
1 parent eb6f8e9 commit 9230b41
Show file tree
Hide file tree
Showing 8 changed files with 395 additions and 32 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
asr = { git = "https://github.com/CryZe/asr", features = ["integer-vars", "strings"] }
asr = { git = "https://github.com/CryZe/asr", features = ["integer-vars", "strings", "derive"] }
bitflags = "1.3.2"
bytemuck = "1.12.1"
spinning_top = "0.2.3"
Expand Down
2 changes: 1 addition & 1 deletion src/data/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod zone;

2 changes: 2 additions & 0 deletions src/data/zone.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use phf::phf_map;
use crate::Character;

pub struct ZoneDescription {
name: &'static str,
character: Character;
region: &'static str,
ring: u8,
}
Expand Down
77 changes: 47 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
use spinning_top::{const_spinlock, Spinlock};
use std::collections::HashSet;
use std::fmt::{Display, Formatter, Result};
use std::env;
mod data;
mod settings;
mod splits;
use settings::Settings;

use bytemuck::Pod;

use asr::{
get_os,
timer::{self, TimerState},
watcher::Pair,
Address, Process,
get_os
};

// mod data;
Expand Down Expand Up @@ -42,6 +45,8 @@ struct Game {
module: u64,
splits: HashSet<String>,
game_state: Watcher<u8>,
agnea_progress: Watcher<u16>,
settings: Settings,
start: Watcher<u8>,
}

Expand All @@ -51,7 +56,9 @@ impl Game {
process,
module,
start: Watcher::new(vec![0x5219628, 0xA8]),
settings: Settings::register(),
game_state: Watcher::new(vec![0x4F7AB68, 0x234]),
agnea_progress: Watcher::new(vec![0x4F7AB30, 0x2D8, 0x708, 0x690 + 0xEC]),
splits: HashSet::new(),
};
Some(game)
Expand All @@ -61,6 +68,8 @@ impl Game {
Some(Vars {
start: self.start.update(&self.process, self.module)?,
game_state: self.game_state.update(&self.process, self.module)?,
agnea_progress: self.agnea_progress.update(&self.process, self.module)?,
settings: &self.settings,
splits: &mut self.splits,
})
}
Expand All @@ -70,7 +79,7 @@ pub struct State {
game: Option<Game>,
}

// This enum maps to the SavePlayerCharacterData
// This enum maps to the SavePlayerCharacterData
#[derive(Default, PartialEq)]
pub enum Character {
#[default]
Expand Down Expand Up @@ -101,26 +110,37 @@ impl Display for Character {
}
}

#[derive(Default)]
pub struct Flags {
char_chapter_ending: Character,
}
// #[derive(Default)]
// pub struct Flags {
// char_chapter_ending: Character,
// }

#[allow(unused)]
struct Vars<'a> {
pub struct Vars<'a> {
start: &'a Pair<u8>,
game_state: &'a Pair<u8>,
agnea_progress: &'a Pair<u16>,
settings: &'a Settings,
splits: &'a mut HashSet<String>,
}

impl Vars<'_> {
fn split(&mut self, key: &str) -> Option<String> {
fn split(&mut self, key: &str, settings_field: bool) -> Option<String> {
if self.splits.contains(key) {
return None;
}

self.splits.insert(key.to_string());

Some(key.to_string())
// only split if in settings
if settings_field {
return Some(key.to_string());
}

None
}
fn clear_splits(&mut self) {
self.splits.clear()
}
}

Expand All @@ -134,7 +154,7 @@ pub extern "C" fn update() {
let process_for_os = match os.as_str() {
"windows" => "Octopath_Traveler2",
"linux" => "Octopath_Travel",
_ => "Octopath_Traveler2"
_ => "Octopath_Traveler2",
};
match Process::attach(process_for_os) {
Some(process) => {
Expand All @@ -156,38 +176,35 @@ pub extern "C" fn update() {
state.game = None;
return;
}
if let Some(vars) = game.update_vars() {
// timer::set_variable_int("Encounters", *vars.encounters);
// timer::set_variable_int("Deaths", *vars.deaths);

if let Some(mut vars) = game.update_vars() {
match timer::state() {
TimerState::NotRunning => {
if vars.game_state.current == 1 && vars.start.old == 0 && vars.start.current == 1 {
// *vars.deaths = 0;
// *vars.encounters = 0;
// *vars.splits = Default::default();
// *vars.flags = Default::default();
vars.clear_splits();
if vars.game_state.current == 1
&& vars.start.old == 0
&& vars.start.current == 1
{
timer::start()
}
}
TimerState::Running => {
// if let Some(reason) = should_split(&mut vars) {
// asr::print_message(&reason);
// timer::split();
// }
// if vars.game_state.current == 6 && vars.game_state.old == 2 {
// *vars.encounters = *vars.encounters + 1;
// }
// if vars.game_state.current == 7 && vars.game_state.old == 6 {
// *vars.deaths = *vars.deaths + 1;
// }
if let Some(reason) = should_split(&mut vars) {
asr::print_message(&reason);
timer::split();
}
}
_ => {}
}
}

}
}

fn should_split(vars: &mut Vars) -> Option<String> {
// Agnea
if let Some(split) = splits::agnea::AgneaSplits::chapter_split(vars) {
return Some(split);
}

None
}
Loading

0 comments on commit 9230b41

Please sign in to comment.