Skip to content

Commit

Permalink
update quite a few things
Browse files Browse the repository at this point in the history
  • Loading branch information
blu-dev committed Jul 22, 2023
1 parent 5197a91 commit 6d8d0cf
Show file tree
Hide file tree
Showing 15 changed files with 841 additions and 372 deletions.
33 changes: 30 additions & 3 deletions src/app/battle_object.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::*;

use std::ops::{Deref, DerefMut};

#[repr(C)]
#[vtable_impl(BattleObject)]
// #[derive(TypeAssert)]
pub(crate) struct BattleObjectVTable {}
pub(crate) struct BattleObjectVTable {
destructor: extern "C" fn(this: &mut BattleObject),
}

#[repr(C)]
pub struct BattleObject {
Expand All @@ -12,8 +16,17 @@ pub struct BattleObject {
pub kind: i32,
pub entry_id: i32,
pub agent_kind: phx::Hash40,
pub module_accessor: *const app::BattleObjectModuleAccessor,
_x28: [u8; 0x38],
pub module_accessor: *mut app::BattleObjectModuleAccessor,
pub previous: *mut BattleObject,
pub next: *mut BattleObject,
pub unknown_byte1: u8,
pub unknown_byte2: u8,
pub status: u8,
pub other_status: u8,
pub mutex: cpp::Mutex,
pub unknown_byte3: u8,
pub unknown_byte4: u8,
padding: [u8; 6],
}

#[repr(C)]
Expand All @@ -22,6 +35,20 @@ pub struct Fighter {
// ...
}

impl Deref for Fighter {
type Target = BattleObject;

fn deref(&self) -> &Self::Target {
&self.parent
}
}

impl DerefMut for Fighter {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.parent
}
}

#[repr(C)]
pub struct Weapon {
parent: BattleObject,
Expand Down
165 changes: 103 additions & 62 deletions src/app/module_accessors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,81 +8,123 @@ use app::*;
#[derive(TypeAssert)]
#[size = 0x190]
pub struct ModuleAccessor {
#[offset = 0x000] event_manager: lib::EventManager,
#[offset = 0x028] posture_module: *mut Module,
#[offset = 0x030] status_module: *mut StatusModule,
#[offset = 0x038] control_module: *mut Module,
#[offset = 0x040] work_module: *mut WorkModule,
#[offset = 0x048] ground_module: *mut Module,
#[offset = 0x050] camera_module: *mut Module,
#[offset = 0x058] kinetic_module: *mut Module,
#[offset = 0x060] color_blend_module: *mut Module,
#[offset = 0x068] model_module: *mut Module,
#[offset = 0x070] physics_module: *mut Module,
#[offset = 0x078] motion_module: *mut Module,
#[offset = 0x080] stop_module: *mut Module,
#[offset = 0x088] article_module: *mut Module,
#[offset = 0x090] attack_module: *mut Module,
#[offset = 0x098] damage_module: *mut Module,
#[offset = 0x0A0] hit_module: *mut Module,
#[offset = 0x0A8] combo_module: *mut Module,
#[offset = 0x0B0] area_module: *mut Module,
#[offset = 0x0B8] item_module: *mut Module,
#[offset = 0x0C0] link_module: *mut Module,
#[offset = 0x0C8] team_module: *mut Module,
#[offset = 0x0D0] search_module: *mut Module,
#[offset = 0x0D8] unk_module_1: *mut Module,
#[offset = 0x0E0] turn_module: *mut Module,
#[offset = 0x0E8] reflect_module: *mut Module,
#[offset = 0x0F0] shield_module: *mut Module,
#[offset = 0x0F8] reflector_module: *mut Module,
#[offset = 0x100] absorber_module: *mut Module,
#[offset = 0x108] jostle_module: *mut Module,
#[offset = 0x110] catch_module: *mut Module,
#[offset = 0x118] cancel_module: *mut CancelModule,
#[offset = 0x120] unk_module_2: *mut Module, // appears to have to do with spirits
#[offset = 0x128] capture_module: *mut Module,
#[offset = 0x130] effect_module: *mut Module,
#[offset = 0x138] sound_module: *mut Module,
#[offset = 0x140] visibility_module: *mut Module,
#[offset = 0x148] grab_module: *mut Module,
#[offset = 0x150] slope_module: *mut Module,
#[offset = 0x158] shake_module: *mut Module,
#[offset = 0x160] slow_module: *mut Module,
#[offset = 0x168] unk_module_3: *mut Module,
#[offset = 0x170] shadow_module: *mut Module,
#[offset = 0x178] motion_animcmd_module: *mut Module,
#[offset = 0x180] lua_module: *mut LuaModule,
#[offset = 0x188] ink_paint_module: *mut Module,
#[offset = 0x000]
event_manager: lib::EventManager,
#[offset = 0x028]
posture_module: *mut PostureModule,
#[offset = 0x030]
status_module: *mut StatusModule,
#[offset = 0x038]
control_module: *mut Module,
#[offset = 0x040]
work_module: *mut WorkModule,
#[offset = 0x048]
ground_module: *mut Module,
#[offset = 0x050]
camera_module: *mut Module,
#[offset = 0x058]
kinetic_module: *mut Module,
#[offset = 0x060]
color_blend_module: *mut Module,
#[offset = 0x068]
model_module: *mut Module,
#[offset = 0x070]
physics_module: *mut Module,
#[offset = 0x078]
motion_module: *mut Module,
#[offset = 0x080]
stop_module: *mut Module,
#[offset = 0x088]
article_module: *mut Module,
#[offset = 0x090]
attack_module: *mut Module,
#[offset = 0x098]
damage_module: *mut Module,
#[offset = 0x0A0]
hit_module: *mut Module,
#[offset = 0x0A8]
combo_module: *mut Module,
#[offset = 0x0B0]
area_module: *mut Module,
#[offset = 0x0B8]
item_module: *mut Module,
#[offset = 0x0C0]
link_module: *mut Module,
#[offset = 0x0C8]
team_module: *mut Module,
#[offset = 0x0D0]
search_module: *mut Module,
#[offset = 0x0D8]
unk_module_1: *mut Module,
#[offset = 0x0E0]
turn_module: *mut Module,
#[offset = 0x0E8]
reflect_module: *mut Module,
#[offset = 0x0F0]
shield_module: *mut Module,
#[offset = 0x0F8]
reflector_module: *mut Module,
#[offset = 0x100]
absorber_module: *mut Module,
#[offset = 0x108]
jostle_module: *mut Module,
#[offset = 0x110]
catch_module: *mut Module,
#[offset = 0x118]
cancel_module: *mut CancelModule,
#[offset = 0x120]
unk_module_2: *mut Module, // appears to have to do with spirits
#[offset = 0x128]
capture_module: *mut Module,
#[offset = 0x130]
effect_module: *mut Module,
#[offset = 0x138]
sound_module: *mut Module,
#[offset = 0x140]
visibility_module: *mut Module,
#[offset = 0x148]
grab_module: *mut Module,
#[offset = 0x150]
slope_module: *mut Module,
#[offset = 0x158]
shake_module: *mut Module,
#[offset = 0x160]
slow_module: *mut Module,
#[offset = 0x168]
unk_module_3: *mut Module,
#[offset = 0x170]
shadow_module: *mut Module,
#[offset = 0x178]
motion_animcmd_module: *mut Module,
#[offset = 0x180]
lua_module: *mut LuaModule,
#[offset = 0x188]
ink_paint_module: *mut Module,
}

impl ModuleAccessor {
pub fn event_manager(&mut self) -> &mut lib::EventManager {
&mut self.event_manager
}


pub fn posture<'a>(&'a self) -> &'a mut PostureModule {
unsafe { &mut *self.posture_module }
}

pub fn work<'a>(&'a self) -> &'a mut WorkModule {
unsafe {
&mut *self.work_module
}
unsafe { &mut *self.work_module }
}

pub fn cancel<'a>(&'a self) -> &'a mut CancelModule {
unsafe {
&mut *self.cancel_module
}
unsafe { &mut *self.cancel_module }
}

pub fn status<'a>(&'a self) -> &'a mut StatusModule {
unsafe {
&mut *self.status_module
}
unsafe { &mut *self.status_module }
}

pub fn lua<'a>(&'a self) -> &'a mut LuaModule {
unsafe {
&mut *self.lua_module
}
unsafe { &mut *self.lua_module }
}
}

Expand All @@ -91,13 +133,12 @@ impl ModuleAccessor {
#[derive(TypeAssert)]
#[size = 0x38]
pub(crate) struct BattleObjectModuleAccessorVTable {

/// Checks if this module accessor is implemented
///
///
/// ### Returns
/// * `true` - The module accessor is **not** implemented
/// * `false` - The module accessor **is** implemented
///
///
/// ### Notes
/// If the module accessor is not implemented, there should be no attempt to
/// use any of its modules as if they were implemented, and there should be
Expand Down
23 changes: 13 additions & 10 deletions src/app/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod damage;
mod item;
mod lua;
mod motion_animcmd;
mod posture;
mod status;
mod work;

Expand All @@ -15,6 +16,7 @@ pub use damage::*;
pub use item::*;
pub use lua::*;
pub use motion_animcmd::*;
pub use posture::*;
pub use status::*;
pub use work::*;

Expand All @@ -25,44 +27,45 @@ struct ModuleVTable {
deleter: extern "C" fn(this: &mut Module),
is_virtual: extern "C" fn(this: &Module) -> bool,
handle_int_msc_cmd: extern "C" fn(this: &mut Module, command: &lib::MscCommand) -> lib::TValue,
handle_float_msc_cmd: extern "C" fn(this: &mut Module, command: &lib::MscCommand) -> lib::TValue,
handle_float_msc_cmd:
extern "C" fn(this: &mut Module, command: &lib::MscCommand) -> lib::TValue,
}

/// The fundamental base type for the majority of Smash Ultimate's modules.
///
///
/// Smash Ultimate takes its module system from Smash 4 and expands upon it.
///
///
/// Due to the nature of fighter/weapon code being written primarily in Lua, transpiled to C++,
/// and then compiled into relocatable character modules (the NRO files), many calls in Ultimate
/// are exported as symbols. However, the MSC environment still exists in Ultimate even though it
/// is wrapped up nicely in Lua and overall very hidden away.
///
///
/// Every module (for most objects there are ~50 modules) inherits from a base class (named here
/// simply as `Module`)lib:: and must support the following operations:
/// 1. Check if it is implemented or an empty module. If it is an empty module, `Module::is_virtual` will
/// return true.
/// 2. Handle MSC commands that will return an integer
/// 3. Handle MSC commands that will return a float
///
///
/// Not every module actually has an implementation which will handle the MSC commands, and some don't
/// really need to. That being said, when they do it can provide insights into their *non*-exported methods.
///
///
/// For example, all that is exported by the main executable for [`CancelModule`] is [`CancelModule::is_enable_cancel`]
/// and [`CancelModule::enable_cancel`]. You can access two more methods through the use of the following MSC commands
/// via `app::sv_module_access::cancel`:
/// * `MA_MSC_CMD_CANCEL_UNABLE_CANCEL` -> [`CancelModule::unable_cancel`]
/// * `MA_MSC_CMD_CANCEL_UNABLE_CANCEL_STATUS` -> [`CancelModule::unable_cancel_status`]
///
///
/// In addition to the three operations specified above, every module also has the following methods:
/// * `initialize` - Called when the object is created/constructed
/// * `finalize` - Called when the object is destroyed
/// * `start_module` - Called when the object enters into play. For example, `Module::initialize` will be called
/// on Mario's fireballs at the start of the game, but `Module::start_module` will be called when they are summoned
/// during his neutral special, and `Module::end_module` will be called when they disappear
/// * `end_module` - Called when the object exits play.
///
///
/// These are usually the first methods in the Module's vtable immediately following the required implementations.
#[repr(C)]
pub struct Module {
vtable: &'static ModuleVTable
}
vtable: &'static ModuleVTable,
}
Loading

0 comments on commit 6d8d0cf

Please sign in to comment.