Skip to content

Commit

Permalink
fix(junowen): Not working at release build
Browse files Browse the repository at this point in the history
  • Loading branch information
progre committed Oct 20, 2023
1 parent 2cdb9c2 commit e7bf119
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
6 changes: 5 additions & 1 deletion junowen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ extern "thiscall" fn fn_from_1243f0_0320(this: *const Selection) -> u8 {
}

extern "fastcall" fn on_rewrite_controller_assignments() {
state::on_rewrite_controller_assignments(state_mut(), props().old_fn_from_13f9d0_0345);
// NOTE: old_fn() modifies th19 outside of Rust.
// This reference makes Rust aware of the change.
state::on_rewrite_controller_assignments(state_mut(), |_: &mut Th19| {
props().old_fn_from_13f9d0_0345
});
}

extern "thiscall" fn on_loaded_game_settings(this: *const c_void, arg1: u32) -> u32 {
Expand Down
6 changes: 3 additions & 3 deletions junowen/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ pub fn on_round_over(state: &mut State) {
}
}

pub fn on_rewrite_controller_assignments(state: &mut State, old_fn: Fn10f720) {
pub fn on_rewrite_controller_assignments(state: &mut State, old_fn: fn(&mut Th19) -> Fn10f720) {
if state.session.is_none() {
old_fn();
old_fn(state.th19_mut())();
return;
}
in_session::on_rewrite_controller_assignments(state.th19_mut().input_devices_mut(), old_fn);
in_session::on_rewrite_controller_assignments(state.th19_mut(), old_fn);
}

pub fn on_loaded_game_settings(state: &mut State) {
Expand Down
21 changes: 16 additions & 5 deletions junowen/src/state/in_session.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ffi::c_void;

use junowen_lib::{Fn10f720, InputDevices, RenderingText};
use junowen_lib::{Fn10f720, RenderingText, Th19};
use tracing::trace;

use crate::session::Session;
Expand Down Expand Up @@ -51,12 +51,23 @@ pub fn on_render_texts(session: &Session, state: &State, text_renderer: *const c
th19.render_text(text_renderer, &text);
}

pub fn on_rewrite_controller_assignments(input_devices: &mut InputDevices, old_fn: Fn10f720) {
trace!("on_rewrite_controller_assignments",);

pub fn on_rewrite_controller_assignments(th19: &mut Th19, old_fn: fn(&mut Th19) -> Fn10f720) {
let input_devices = th19.input_devices_mut();
let old_p1_idx = input_devices.p1_idx();
old_fn();
trace!(
"on_rewrite_controller_assignments: before old_p1_idx={}",
old_p1_idx
);
old_fn(th19)();
if old_p1_idx == 0 && input_devices.p1_idx() != 0 {
trace!(
"on_rewrite_controller_assignments: after input_devices.p1_idx()={}",
input_devices.p1_idx()
);
input_devices.set_p1_idx(0);
trace!(
"on_rewrite_controller_assignments: fixed input_devices.p1_idx()={}",
input_devices.p1_idx()
);
}
}

0 comments on commit e7bf119

Please sign in to comment.