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
2 changes: 1 addition & 1 deletion src/common/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static SESSION_ID: LazyLock<String> = LazyLock::new(|| unsafe {
.expect("Time went backwards")
.as_millis();
let mut session_id_hash = Sha256Hash { hash: [0; 0x20] };
let event_time_bytes: [u8; 16] = std::mem::transmute(event_time.to_be());
let event_time_bytes: [u8; 16] = event_time.to_be_bytes();
let session_id_bytes: [u8; 32] = [event_time_bytes, device_uuid.data]
.concat()
.try_into()
Expand Down
1 change: 1 addition & 0 deletions src/common/input.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(unused_parens)]
use bitflags::bitflags;
use modular_bitfield::{bitfield, specifiers::*};

Expand Down
266 changes: 132 additions & 134 deletions src/common/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,155 +126,153 @@ pub static MENU_RECEIVED_INPUT: RwLock<bool> = RwLock::new(true);
pub static MENU_CLOSE_FRAME_COUNTER: LazyLock<usize> =
LazyLock::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::Real));

pub fn handle_final_input_mapping(
pub unsafe fn handle_final_input_mapping(
player_idx: i32,
controller_struct: &mut SomeControllerStruct,
out: *mut MappedInputs,
) {
unsafe {
if player_idx == 0 {
let p1_controller = &mut *controller_struct.controller;
assign(&P1_CONTROLLER_STYLE, p1_controller.style);
let visual_frame_count = frame_counter::get_frame_count(*MENU_CLOSE_FRAME_COUNTER);
if visual_frame_count > 0 && visual_frame_count < MENU_CLOSE_WAIT_FRAMES {
// If we just closed the menu, kill all inputs to avoid accidental presses
*out = MappedInputs::empty();
p1_controller.current_buttons = ButtonBitfield::default();
p1_controller.previous_buttons = ButtonBitfield::default();
p1_controller.just_down = ButtonBitfield::default();
p1_controller.just_release = ButtonBitfield::default();
} else if visual_frame_count >= MENU_CLOSE_WAIT_FRAMES {
frame_counter::stop_counting(*MENU_CLOSE_FRAME_COUNTER);
frame_counter::reset_frame_count(*MENU_CLOSE_FRAME_COUNTER);
}

if read(&QUICK_MENU_ACTIVE) {
// If we're here, remove all other presses
*out = MappedInputs::empty();

let mut received_input = false;
if player_idx == 0 {
let p1_controller = &mut *controller_struct.controller;
assign(&P1_CONTROLLER_STYLE, p1_controller.style);
let visual_frame_count = frame_counter::get_frame_count(*MENU_CLOSE_FRAME_COUNTER);
if visual_frame_count > 0 && visual_frame_count < MENU_CLOSE_WAIT_FRAMES {
// If we just closed the menu, kill all inputs to avoid accidental presses
*out = MappedInputs::empty();
p1_controller.current_buttons = ButtonBitfield::default();
p1_controller.previous_buttons = ButtonBitfield::default();
p1_controller.just_down = ButtonBitfield::default();
p1_controller.just_release = ButtonBitfield::default();
} else if visual_frame_count >= MENU_CLOSE_WAIT_FRAMES {
frame_counter::stop_counting(*MENU_CLOSE_FRAME_COUNTER);
frame_counter::reset_frame_count(*MENU_CLOSE_FRAME_COUNTER);
}

const DIRECTION_HOLD_REPEAT_FRAMES: u32 = 20;
use DirectionButton::*;
let mut direction_hold_frames = read_clone(&DIRECTION_HOLD_FRAMES); // TODO!("Refactor this, it doesn't need to be a hashmap")
if read(&QUICK_MENU_ACTIVE) {
// If we're here, remove all other presses
*out = MappedInputs::empty();

// Check for all controllers unplugged
let mut potential_controller_ids = (0..8).collect::<Vec<u32>>();
potential_controller_ids.push(0x20);
if potential_controller_ids
.iter()
.all(|i| GetNpadStyleSet(i as *const _).flags == 0)
{
assign(&QUICK_MENU_ACTIVE, false);
return;
}
let mut received_input = false;

let style = p1_controller.style;
let button_presses = p1_controller.just_down;
const DIRECTION_HOLD_REPEAT_FRAMES: u32 = 20;
use DirectionButton::*;
let mut direction_hold_frames = read_clone(&DIRECTION_HOLD_FRAMES); // TODO!("Refactor this, it doesn't need to be a hashmap")

let button_current_held = p1_controller.current_buttons;
direction_hold_frames
.iter_mut()
.for_each(|(direction, frames)| {
let still_held = match direction {
LLeft => button_current_held.l_left(),
RLeft => button_current_held.r_left(),
LDown => button_current_held.l_down(),
RDown => button_current_held.r_down(),
LRight => button_current_held.l_right(),
RRight => button_current_held.r_right(),
LUp => button_current_held.l_up(),
RUp => button_current_held.r_up(),
};
if still_held {
*frames += 1;
} else {
*frames = 0;
}
});
// Check for all controllers unplugged
let mut potential_controller_ids = (0..8).collect::<Vec<u32>>();
potential_controller_ids.push(0x20);
if potential_controller_ids
.iter()
.all(|i| GetNpadStyleSet(i as *const _).flags == 0)
{
assign(&QUICK_MENU_ACTIVE, false);
return;
}

let mut app = lock_write(&QUICK_MENU_APP);
button_config::button_mapping(ButtonConfig::A, style, button_presses).then(|| {
app.on_a();
received_input = true;
});
button_config::button_mapping(ButtonConfig::B, style, button_presses).then(|| {
received_input = true;
app.on_b();
if app.page == AppPage::CLOSE {
// Leave menu.
frame_counter::start_counting(*MENU_CLOSE_FRAME_COUNTER);
assign(&QUICK_MENU_ACTIVE, false);
let menu_json = app.get_serialized_settings_with_defaults();
set_menu_from_json(&menu_json);
let style = p1_controller.style;
let button_presses = p1_controller.just_down;

let mut event_queue_lock = lock_write(&EVENT_QUEUE);
(*event_queue_lock).push(Event::menu_open(menu_json));
drop(event_queue_lock);
let button_current_held = p1_controller.current_buttons;
direction_hold_frames
.iter_mut()
.for_each(|(direction, frames)| {
let still_held = match direction {
LLeft => button_current_held.l_left(),
RLeft => button_current_held.r_left(),
LDown => button_current_held.l_down(),
RDown => button_current_held.r_down(),
LRight => button_current_held.l_right(),
RRight => button_current_held.r_right(),
LUp => button_current_held.l_up(),
RUp => button_current_held.r_up(),
};
if still_held {
*frames += 1;
} else {
*frames = 0;
}
});
button_config::button_mapping(ButtonConfig::X, style, button_presses).then(|| {
app.on_x();
received_input = true;
});
button_config::button_mapping(ButtonConfig::Y, style, button_presses).then(|| {
app.on_y();
received_input = true;
});

button_config::button_mapping(ButtonConfig::ZL, style, button_presses).then(|| {
app.on_zl();
received_input = true;
});
button_config::button_mapping(ButtonConfig::ZR, style, button_presses).then(|| {
app.on_zr();
received_input = true;
});
button_config::button_mapping(ButtonConfig::R, style, button_presses).then(|| {
app.on_r();
received_input = true;
});

let hold_condition = |direction_button| {
direction_hold_frames[direction_button] > DIRECTION_HOLD_REPEAT_FRAMES
};
(button_presses.dpad_left()
|| button_presses.l_left()
|| button_presses.r_left()
|| [LLeft, RLeft].iter().any(hold_condition))
.then(|| {
received_input = true;
app.on_left();
});
(button_presses.dpad_right()
|| button_presses.l_right()
|| button_presses.r_right()
|| [LRight, RRight].iter().any(hold_condition))
.then(|| {
received_input = true;
app.on_right();
});
(button_presses.dpad_up()
|| button_presses.l_up()
|| button_presses.r_up()
|| [LUp, RUp].iter().any(hold_condition))
.then(|| {
received_input = true;
app.on_up();
});
(button_presses.dpad_down()
|| button_presses.l_down()
|| button_presses.r_down()
|| [LDown, RDown].iter().any(hold_condition))
.then(|| {
received_input = true;
app.on_down();
});
let mut app = lock_write(&QUICK_MENU_APP);
button_config::button_mapping(ButtonConfig::A, style, button_presses).then(|| {
app.on_a();
received_input = true;
});
button_config::button_mapping(ButtonConfig::B, style, button_presses).then(|| {
received_input = true;
app.on_b();
if app.page == AppPage::CLOSE {
// Leave menu.
frame_counter::start_counting(*MENU_CLOSE_FRAME_COUNTER);
assign(&QUICK_MENU_ACTIVE, false);
let menu_json = app.get_serialized_settings_with_defaults();
set_menu_from_json(&menu_json);

if received_input {
direction_hold_frames.iter_mut().for_each(|(_, f)| *f = 0);
assign(&MENU_RECEIVED_INPUT, true);
let mut event_queue_lock = lock_write(&EVENT_QUEUE);
(*event_queue_lock).push(Event::menu_open(menu_json));
drop(event_queue_lock);
}
});
button_config::button_mapping(ButtonConfig::X, style, button_presses).then(|| {
app.on_x();
received_input = true;
});
button_config::button_mapping(ButtonConfig::Y, style, button_presses).then(|| {
app.on_y();
received_input = true;
});

button_config::button_mapping(ButtonConfig::ZL, style, button_presses).then(|| {
app.on_zl();
received_input = true;
});
button_config::button_mapping(ButtonConfig::ZR, style, button_presses).then(|| {
app.on_zr();
received_input = true;
});
button_config::button_mapping(ButtonConfig::R, style, button_presses).then(|| {
app.on_r();
received_input = true;
});

let hold_condition = |direction_button| {
direction_hold_frames[direction_button] > DIRECTION_HOLD_REPEAT_FRAMES
};
(button_presses.dpad_left()
|| button_presses.l_left()
|| button_presses.r_left()
|| [LLeft, RLeft].iter().any(hold_condition))
.then(|| {
received_input = true;
app.on_left();
});
(button_presses.dpad_right()
|| button_presses.l_right()
|| button_presses.r_right()
|| [LRight, RRight].iter().any(hold_condition))
.then(|| {
received_input = true;
app.on_right();
});
(button_presses.dpad_up()
|| button_presses.l_up()
|| button_presses.r_up()
|| [LUp, RUp].iter().any(hold_condition))
.then(|| {
received_input = true;
app.on_up();
});
(button_presses.dpad_down()
|| button_presses.l_down()
|| button_presses.r_down()
|| [LDown, RDown].iter().any(hold_condition))
.then(|| {
received_input = true;
app.on_down();
});

if received_input {
direction_hold_frames.iter_mut().for_each(|(_, f)| *f = 0);
assign(&MENU_RECEIVED_INPUT, true);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn is_in_footstool(module_accessor: &mut app::BattleObjectModuleAccessor) ->
(*FIGHTER_STATUS_KIND_TREAD_DAMAGE..=*FIGHTER_STATUS_KIND_TREAD_FALL).contains(&status_kind)
}

pub fn is_shielding(module_accessor: *mut app::BattleObjectModuleAccessor) -> bool {
pub fn is_shielding(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool {
let status_kind = unsafe { StatusModule::status_kind(module_accessor) };

(*FIGHTER_STATUS_KIND_GUARD_ON..=*FIGHTER_STATUS_KIND_GUARD_DAMAGE).contains(&status_kind)
Expand Down
2 changes: 1 addition & 1 deletion src/hitbox_visualizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ unsafe fn mod_handle_handle_set_rebound(
}

// only if we're not shielding
if is_shielding(module_accessor) {
if is_shielding(&mut *module_accessor) {
return;
}

Expand Down
15 changes: 1 addition & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
#![feature(proc_macro_hygiene)]
#![feature(iter_intersperse)]
#![feature(const_mut_refs)]
#![feature(exclusive_range_pattern)]
#![feature(c_variadic)]
#![allow(stable_features)]
#![feature(stmt_expr_attributes)]
#![feature(pointer_byte_offsets)]
#![allow(
clippy::borrow_interior_mutable_const,
clippy::declare_interior_mutable_const,
clippy::not_unsafe_ptr_arg_deref,
clippy::missing_safety_doc,
clippy::wrong_self_convention,
clippy::option_map_unit_fn,
clippy::transmute_num_to_bytes,
clippy::missing_transmute_annotations
)]
#![allow(clippy::missing_safety_doc)]

use std::fs;
use std::path::PathBuf;
Expand Down
14 changes: 8 additions & 6 deletions src/training/character_specific/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ unsafe fn apply_single_item(player_fighter_kind: i32, item: &CharItem) {
cpu_module_accessor
};
let variation = item.variation.as_ref().map(|v| **v).unwrap_or(0);
item.item_kind.as_ref().map(|item_kind| {
if let Some(item_kind) = item.item_kind.as_ref() {
let item_kind = **item_kind;
// For Link, use special article generation to link the bomb for detonation
if item_kind == *ITEM_KIND_LINKBOMB {
Expand Down Expand Up @@ -377,9 +377,9 @@ unsafe fn apply_single_item(player_fighter_kind: i32, item: &CharItem) {
false,
);
}
});
}

item.article_kind.as_ref().map(|article_kind| {
if let Some(article_kind) = item.article_kind.as_ref() {
assign(
&TURNIP_CHOSEN,
if [*ITEM_VARIATION_PEACHDAIKON_8, *ITEM_VARIATION_DAISYDAIKON_8].contains(&variation) {
Expand Down Expand Up @@ -444,7 +444,7 @@ unsafe fn apply_single_item(player_fighter_kind: i32, item: &CharItem) {
assign(&TARGET_PLAYER, None);
}
assign(&TURNIP_CHOSEN, None);
});
}
}

pub unsafe fn apply_item(character_item: CharacterItem) {
Expand All @@ -467,11 +467,13 @@ pub unsafe fn apply_item(character_item: CharacterItem) {
(character_item_num - CharacterItem::CPU_VARIATION_1.as_idx()),
)
};
ALL_CHAR_ITEMS
if let Some(item) = ALL_CHAR_ITEMS
.iter()
.filter(|item| item_fighter_kind == item.fighter_kind)
.nth(variation_idx)
.map(|item| apply_single_item(player_fighter_kind, item));
{
apply_single_item(player_fighter_kind, item)
}
mash::clear_queue();
}

Expand Down
Loading
Loading