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 @@ -26,7 +26,7 @@ static SESSION_ID: LazyLock<String> = LazyLock::new(|| unsafe {
let session_id_bytes: [u8; 32] = [event_time_bytes, device_uuid.data]
.concat()
.try_into()
.unwrap();
.expect("Session_id_bytes not the correct length");

GenerateSha256Hash(
&mut session_id_hash as *mut _ as *mut c_void,
Expand Down
3 changes: 2 additions & 1 deletion src/common/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ pub fn set_menu_from_json(message: &str) {
std::thread::spawn(move || {
fs::write(
MENU_OPTIONS_PATH,
serde_json::to_string_pretty(&message_json).unwrap(),
serde_json::to_string_pretty(&message_json)
.expect("Could not serialize menu settings"),
)
.expect("Failed to write menu settings file");
});
Expand Down
13 changes: 6 additions & 7 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ pub unsafe fn try_get_battle_object(battle_object_id: u32) -> Option<&'static ap
battle_object_ptr.as_ref()
}

pub fn get_module_accessor(fighter_id: FighterId) -> *mut app::BattleObjectModuleAccessor {
try_get_module_accessor(fighter_id).unwrap()
}

pub fn try_get_module_accessor(
fighter_id: FighterId,
) -> Option<*mut app::BattleObjectModuleAccessor> {
Expand Down Expand Up @@ -284,7 +280,8 @@ pub unsafe fn entry_count() -> i32 {
}

pub unsafe fn get_player_dmg_digits(p: FighterId) -> (u8, u8, u8, u8) {
let module_accessor = get_module_accessor(p);
let module_accessor =
try_get_module_accessor(p).expect("Could not get module accessor in get_player_dmg_digits");
let dmg = DamageModule::damage(module_accessor, 0);
let hundreds = dmg as u16 / 100;
let tens = (dmg as u16 - hundreds * 100) / 10;
Expand All @@ -294,11 +291,13 @@ pub unsafe fn get_player_dmg_digits(p: FighterId) -> (u8, u8, u8, u8) {
}

pub unsafe fn get_fighter_distance() -> f32 {
let player_module_accessor = get_module_accessor(FighterId::Player);
let player_module_accessor = try_get_module_accessor(FighterId::Player)
.expect("Could not get player_module_accessor in get_fighter_distance");
if StatusModule::status_kind(player_module_accessor) == *FIGHTER_STATUS_KIND_NONE {
return f32::MAX;
}
let cpu_module_accessor = get_module_accessor(FighterId::CPU);
let cpu_module_accessor = try_get_module_accessor(FighterId::CPU)
.expect("Could not get CPU module_accessor in get_fighter_distance");
let player_pos = *PostureModule::pos(player_module_accessor);
let cpu_pos = *PostureModule::pos(cpu_module_accessor);
app::sv_math::vec3_distance(
Expand Down
6 changes: 3 additions & 3 deletions src/common/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ pub fn perform_version_check() {
}
_ => panic!("Invalid value in perform_version_check: {}", update_policy),
};
if release_to_apply.is_ok() {
let published_at = release_to_apply.as_ref().unwrap().published_at.clone();
if let Ok(release) = release_to_apply.as_ref() {
let published_at = release.published_at.clone();
info!("Current version: {}", *CURRENT_VERSION);
info!("Github version: {}", published_at);
if release_to_apply.as_ref().unwrap().is_older_than_installed() {
if release.is_older_than_installed() {
release_to_apply = Err(anyhow!(
"Github version is not newer than the current installed version.",
))
Expand Down
14 changes: 8 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn main() {
&complete_error_message,
);
}));
init_logger().unwrap();
init_logger().expect("Could not initialize logger");

info!("Initialized.");

Expand All @@ -93,15 +93,17 @@ pub fn main() {
hitbox_visualizer::hitbox_visualization();
hazard_manager::hazard_manager();
training::training_mods();
nro::add_hook(nro_main).unwrap();
nro::add_hook(nro_main).expect("Did not find nro_hook plugin!");

fs::create_dir_all(TRAINING_MODPACK_ROOT)
.expect("Could not create Training Modpack root folder!");

// Migrate legacy if exists
if fs::metadata(LEGACY_TRAINING_MODPACK_ROOT).is_ok() {
for entry in fs::read_dir(LEGACY_TRAINING_MODPACK_ROOT).unwrap() {
let entry = entry.unwrap();
for entry in
fs::read_dir(LEGACY_TRAINING_MODPACK_ROOT).expect("Couldn't read legacy folder")
{
let entry = entry.expect("Couldn't read legacy file during migration");
let src_path = &entry.path();
let dest_path = &PathBuf::from(TRAINING_MODPACK_ROOT).join(entry.file_name());
fs::rename(src_path, dest_path).unwrap_or_else(|e| {
Expand All @@ -119,7 +121,7 @@ pub fn main() {
.spawn(move || {
menu::load_from_file();
})
.unwrap();
.expect("Couldn't create data loader thread");
let _result = data_loader.join();

if !is_emulator() {
Expand All @@ -129,7 +131,7 @@ pub fn main() {
.spawn(move || {
release::perform_version_check();
})
.unwrap();
.expect("Couldn't create version check thread");
let _result = _updater.join();
} else {
info!("Skipping version check because we are using an emulator");
Expand Down
49 changes: 26 additions & 23 deletions src/training/buff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,26 @@ unsafe fn buff_hero_single(
}
let spell_index = get_buff_rem(module_accessor) - 1;
// Used to get spell from our vector
let spell_option = buff_vec.get(spell_index);
if spell_option.is_none() {
// There are no spells selected, or something went wrong with making the vector
return;
}
let real_spell_value = spell_option.unwrap().into_int().unwrap();
if status != FIGHTER_BRAVE_STATUS_KIND_SPECIAL_LW_START {
WorkModule::set_int(
module_accessor,
real_spell_value,
*FIGHTER_BRAVE_INSTANCE_WORK_ID_INT_SPECIAL_LW_DECIDE_COMMAND,
);
StatusModule::change_status_force(
module_accessor,
*FIGHTER_BRAVE_STATUS_KIND_SPECIAL_LW_START,
true,
// True to prevent Shielding over the spells
);
}
if status == FIGHTER_BRAVE_STATUS_KIND_SPECIAL_LW_START {
MotionModule::set_rate(module_accessor, 50.0);
if let Some(spell_option) = buff_vec.get(spell_index) {
let real_spell_value = spell_option
.into_int()
.expect("Invalid option for spell_option");
if status != FIGHTER_BRAVE_STATUS_KIND_SPECIAL_LW_START {
WorkModule::set_int(
module_accessor,
real_spell_value,
*FIGHTER_BRAVE_INSTANCE_WORK_ID_INT_SPECIAL_LW_DECIDE_COMMAND,
);
StatusModule::change_status_force(
module_accessor,
*FIGHTER_BRAVE_STATUS_KIND_SPECIAL_LW_START,
true,
// True to prevent Shielding over the spells
);
}
if status == FIGHTER_BRAVE_STATUS_KIND_SPECIAL_LW_START {
MotionModule::set_rate(module_accessor, 50.0);
}
}
}

Expand Down Expand Up @@ -267,7 +266,9 @@ unsafe fn buff_wario(module_accessor: &mut app::BattleObjectModuleAccessor) -> b
);
WorkModule::set_int(
module_accessor,
waft_level.into_int().unwrap(),
waft_level
.into_int()
.expect("Invalid option for waft_level"),
*FIGHTER_WARIO_INSTANCE_WORK_ID_INT_GASS_LEVEL,
);
}
Expand All @@ -293,7 +294,9 @@ unsafe fn buff_shulk(module_accessor: &mut app::BattleObjectModuleAccessor, stat
if status != FIGHTER_SHULK_STATUS_KIND_SPECIAL_N_ACTION {
WorkModule::set_int(
module_accessor,
current_art.into_int().unwrap(),
current_art
.into_int()
.expect("Invalid option for current_art"),
*FIGHTER_SHULK_INSTANCE_WORK_ID_INT_SPECIAL_N_TYPE_SELECT,
);
WorkModule::set_int(
Expand Down
12 changes: 8 additions & 4 deletions src/training/character_specific/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,10 @@ pub const ALL_CHAR_ITEMS: [CharItem; 45] = [
];

unsafe fn apply_single_item(player_fighter_kind: i32, item: &CharItem) {
let player_module_accessor = get_module_accessor(FighterId::Player);
let cpu_module_accessor = get_module_accessor(FighterId::CPU);
let player_module_accessor = try_get_module_accessor(FighterId::Player)
.expect("Could not get player module accessor in apply_single_item");
let cpu_module_accessor = try_get_module_accessor(FighterId::CPU)
.expect("Could not get CPU module accessor in apply_single_item");
// Now we make sure the module_accessor we use to generate the item/article is the correct character
let generator_module_accessor = if item.fighter_kind == player_fighter_kind {
player_module_accessor
Expand Down Expand Up @@ -446,8 +448,10 @@ unsafe fn apply_single_item(player_fighter_kind: i32, item: &CharItem) {
}

pub unsafe fn apply_item(character_item: CharacterItem) {
let player_module_accessor = get_module_accessor(FighterId::Player);
let cpu_module_accessor = get_module_accessor(FighterId::CPU);
let player_module_accessor = try_get_module_accessor(FighterId::Player)
.expect("Could not get player module accessor in apply_item");
let cpu_module_accessor = try_get_module_accessor(FighterId::CPU)
.expect("Could not get CPU module accessor in apply_item");
let player_fighter_kind = app::utility::get_kind(&mut *player_module_accessor);
let cpu_fighter_kind = app::utility::get_kind(&mut *cpu_module_accessor);
let character_item_num = character_item.as_idx();
Expand Down
18 changes: 14 additions & 4 deletions src/training/charge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::common::consts::FighterId;
use crate::common::offsets::OFFSET_COPY_SETUP;
use crate::common::{get_module_accessor, try_get_battle_object};
use crate::common::{try_get_battle_object, try_get_module_accessor};
use crate::training::character_specific::{kirby, pikmin};
use serde::{Deserialize, Serialize};
use smash::app::{self, lua_bind::*, ArticleOperationTarget, FighterFacial, FighterUtil};
Expand Down Expand Up @@ -497,8 +497,10 @@ pub unsafe fn handle_charge(
// Kirby Copy Abilities
else if fighter_kind == FIGHTER_KIND_KIRBY {
charge.has_charge.map(|_has_copy_ability| {
let cpu_module_accessor = &mut *get_module_accessor(FighterId::CPU);
let player_module_accessor = &mut *get_module_accessor(FighterId::Player);
let cpu_module_accessor = &mut *try_get_module_accessor(FighterId::CPU)
.expect("Could not get CPU module accessor for Kirby copy ability charge setup");
let player_module_accessor = &mut *try_get_module_accessor(FighterId::Player)
.expect("Could not get Player module accessor for Kirby copy ability charge setup");
let opponent_module_accessor: &mut app::BattleObjectModuleAccessor =
if ptr::eq(module_accessor, player_module_accessor) {
cpu_module_accessor
Expand All @@ -509,7 +511,15 @@ pub unsafe fn handle_charge(
let opponent_matches_fighter =
kirby::is_kirby_hat_okay(opponent_module_accessor, charge.int_z);
if opponent_matches_fighter == Some(true) {
copy_setup(module_accessor, 1, charge.int_z.unwrap(), true, false);
copy_setup(
module_accessor,
1,
charge
.int_z
.expect("charge.int_z is None in handle_charge::Kirby"),
true,
false,
);
//kirby::handle_kirby_hat_charge(module_accessor, charge.int_z.unwrap(), charge);
}
});
Expand Down
8 changes: 5 additions & 3 deletions src/training/combo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use smash::app::BattleObjectModuleAccessor;
use smash::lib::lua_const::*;

use crate::consts::Action;
use crate::get_module_accessor;
use crate::training::frame_counter;
use crate::training::ui::notifications;
use crate::try_get_module_accessor;

use training_mod_consts::{FighterId, OnOff, MENU};
use training_mod_sync::*;
Expand Down Expand Up @@ -91,8 +91,10 @@ pub unsafe fn once_per_frame(module_accessor: &mut BattleObjectModuleAccessor) {
if entry_id_int != (FighterId::Player as i32) {
return;
}
let player_module_accessor = get_module_accessor(FighterId::Player);
let cpu_module_accessor = get_module_accessor(FighterId::CPU);
let player_module_accessor = try_get_module_accessor(FighterId::Player)
.expect("Could not get player module accessor in once_per_frame");
let cpu_module_accessor = try_get_module_accessor(FighterId::CPU)
.expect("Could not get CPU module accessor in once_per_frame");
let player_is_actionable = is_actionable(player_module_accessor);
let player_was_actionable = read(&PLAYER_WAS_ACTIONABLE);
let player_just_actionable = !player_was_actionable && player_is_actionable;
Expand Down
6 changes: 4 additions & 2 deletions src/training/directional_influence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ unsafe fn mod_handle_di(fighter: &L2CFighterCommon, _arg1: L2CValue) {
}

pub fn should_reverse_angle(direction: Direction) -> bool {
let cpu_module_accessor = get_module_accessor(FighterId::CPU);
let player_module_accessor = get_module_accessor(FighterId::Player);
let cpu_module_accessor = try_get_module_accessor(FighterId::CPU)
.expect("Could not get CPU module accessor in should_reverse_angle");
let player_module_accessor = try_get_module_accessor(FighterId::Player)
.expect("Could not get player module accessor in should_reverse_angle");
unsafe {
PostureModule::pos_x(player_module_accessor) > PostureModule::pos_x(cpu_module_accessor)
&& ![Direction::LEFT, Direction::RIGHT].contains(&direction)
Expand Down
Loading
Loading