Skip to content

Commit

Permalink
add debug
Browse files Browse the repository at this point in the history
  • Loading branch information
blu-dev committed May 5, 2023
1 parent 56eae03 commit 5197a91
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 68 deletions.
Binary file added .DS_Store
Binary file not shown.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
skyline = { git = "https://github.com/ultimate-research/skyline-rs" }
skyline = "0.2.1"
smash_macro = { path = "./smash-macro" }
bitflags = "1.3.2"
hash40 = { git = "https://github.com/BenHall-7/hash40-rs" }
Expand All @@ -18,4 +18,5 @@ thiserror = "1.0.37"
[features]
default = ["type_assert"]
type_assert = ["memoffset"]
extras = [] # This feature is for exposing extra information based on research, not symbols
extras = [
] # This feature is for exposing extra information based on research, not symbols
133 changes: 67 additions & 66 deletions src/app/modules/attack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,33 @@ pub struct AttackAbsoluteData {
pub no_effect: bool,
unused: u8,
pub region: app::AttackRegion,
pub catch: bool
pub catch: bool,
}

#[cfg(feature = "type_assert")]
impl AttackAbsoluteData {
pub fn assert() {
assert_eq!(size_of!(AttackAbsoluteData), 0x30);
assert_eq!(offset_of!(AttackAbsoluteData, power), 0x0);
assert_eq!(offset_of!(AttackAbsoluteData, vector), 0x4);
assert_eq!(offset_of!(AttackAbsoluteData, r_eff), 0x8);
assert_eq!(offset_of!(AttackAbsoluteData, r_fix), 0xC);
assert_eq!(offset_of!(AttackAbsoluteData, r_add), 0x10);
assert_eq!(offset_of!(AttackAbsoluteData, slip), 0x14);
assert_eq!(offset_of!(AttackAbsoluteData, stop_frame), 0x18);
assert_eq!(offset_of!(AttackAbsoluteData, stop_delay), 0x1C);
assert_eq!(offset_of!(AttackAbsoluteData, attr), 0x20);
assert_eq!(offset_of!(AttackAbsoluteData, power), 0x0);
assert_eq!(offset_of!(AttackAbsoluteData, vector), 0x4);
assert_eq!(offset_of!(AttackAbsoluteData, r_eff), 0x8);
assert_eq!(offset_of!(AttackAbsoluteData, r_fix), 0xC);
assert_eq!(offset_of!(AttackAbsoluteData, r_add), 0x10);
assert_eq!(offset_of!(AttackAbsoluteData, slip), 0x14);
assert_eq!(offset_of!(AttackAbsoluteData, stop_frame), 0x18);
assert_eq!(offset_of!(AttackAbsoluteData, stop_delay), 0x1C);
assert_eq!(offset_of!(AttackAbsoluteData, attr), 0x20);
assert_eq!(offset_of!(AttackAbsoluteData, sound_level), 0x28);
assert_eq!(offset_of!(AttackAbsoluteData, sound_attr), 0x29);
assert_eq!(offset_of!(AttackAbsoluteData, lr_check), 0x2A);
assert_eq!(offset_of!(AttackAbsoluteData, no_stop), 0x2B);
assert_eq!(offset_of!(AttackAbsoluteData, no_effect), 0x2C);
assert_eq!(offset_of!(AttackAbsoluteData, region), 0x2E);
assert_eq!(offset_of!(AttackAbsoluteData, catch), 0x2F);
assert_eq!(offset_of!(AttackAbsoluteData, sound_attr), 0x29);
assert_eq!(offset_of!(AttackAbsoluteData, lr_check), 0x2A);
assert_eq!(offset_of!(AttackAbsoluteData, no_stop), 0x2B);
assert_eq!(offset_of!(AttackAbsoluteData, no_effect), 0x2C);
assert_eq!(offset_of!(AttackAbsoluteData, region), 0x2E);
assert_eq!(offset_of!(AttackAbsoluteData, catch), 0x2F);
}
}

#[derive(Debug)]
#[repr(C)]
pub struct AttackData {
pub offset: phx::Vector3f,
Expand Down Expand Up @@ -101,62 +102,62 @@ pub struct AttackData {
pub r_fix_damage_speed_up: bool,
unused2: u8,
pub captured_same_time_attack: bool,
unknown: [u8; 0x59] // 0xA7
unknown: [u8; 0x59], // 0xA7
}

#[cfg(feature = "type_assert")]
impl AttackData {
pub fn assert() {
assert_eq!(size_of!(AttackData), 0x100);
assert_eq!(offset_of!(AttackData, offset), 0x0);
assert_eq!(offset_of!(AttackData, offset2), 0x10);
assert_eq!(offset_of!(AttackData, power), 0x20);
assert_eq!(offset_of!(AttackData, size), 0x24);
assert_eq!(offset_of!(AttackData, vector), 0x28);
assert_eq!(offset_of!(AttackData, r_eff), 0x2C);
assert_eq!(offset_of!(AttackData, r_fix), 0x30);
assert_eq!(offset_of!(AttackData, r_add), 0x34);
assert_eq!(offset_of!(AttackData, slip), 0x38);
assert_eq!(offset_of!(AttackData, stop_frame), 0x3C);
assert_eq!(offset_of!(AttackData, stop_delay), 0x40);
assert_eq!(offset_of!(AttackData, node), 0x48);
assert_eq!(offset_of!(AttackData, target_category), 0x50);
assert_eq!(offset_of!(AttackData, target_situation), 0x52);
assert_eq!(offset_of!(AttackData, target_lr), 0x53);
assert_eq!(offset_of!(AttackData, target_part), 0x54);
assert_eq!(offset_of!(AttackData, attr), 0x58);
assert_eq!(offset_of!(AttackData, sound_level), 0x60);
assert_eq!(offset_of!(AttackData, sound_attr), 0x61);
assert_eq!(offset_of!(AttackData, set_off), 0x62);
assert_eq!(offset_of!(AttackData, no_scale), 0x63);
assert_eq!(offset_of!(AttackData, shield), 0x64);
assert_eq!(offset_of!(AttackData, reflector), 0x65);
assert_eq!(offset_of!(AttackData, absorber), 0x66);
assert_eq!(offset_of!(AttackData, direct), 0x67);
assert_eq!(offset_of!(AttackData, no_invincible), 0x68);
assert_eq!(offset_of!(AttackData, no_xlu), 0x69);
assert_eq!(offset_of!(AttackData, lr_check), 0x6A);
assert_eq!(offset_of!(AttackData, catch), 0x6B);
assert_eq!(offset_of!(AttackData, no_team), 0x6C);
assert_eq!(offset_of!(AttackData, no_stop), 0x6D);
assert_eq!(offset_of!(AttackData, no_effect), 0x6E);
assert_eq!(offset_of!(AttackData, speed), 0x70);
assert_eq!(offset_of!(AttackData, region), 0x71);
assert_eq!(offset_of!(AttackData, ignore_down), 0x72);
assert_eq!(offset_of!(AttackData, check_type), 0x73);
assert_eq!(offset_of!(AttackData, sub_shield), 0x74);
assert_eq!(offset_of!(AttackData, camera_quake), 0x76);
assert_eq!(offset_of!(AttackData, serial_hit_frame), 0x78);
assert_eq!(offset_of!(AttackData, force_reaction), 0x7C);
assert_eq!(offset_of!(AttackData, no_attacker_log), 0x7D);
assert_eq!(offset_of!(AttackData, no_weight_reaction), 0x7E);
assert_eq!(offset_of!(AttackData, no_reaction_search), 0x7F);
assert_eq!(offset_of!(AttackData, keep_rumble), 0x80);
assert_eq!(offset_of!(AttackData, composition_speed), 0x81);
assert_eq!(offset_of!(AttackData, target_pos_node), 0x88);
assert_eq!(offset_of!(AttackData, target_pos_offset), 0x90);
assert_eq!(offset_of!(AttackData, target_pos_frame), 0xA0);
assert_eq!(offset_of!(AttackData, r_fix_damage_speed_up), 0xA4);
assert_eq!(offset_of!(AttackData, offset), 0x0);
assert_eq!(offset_of!(AttackData, offset2), 0x10);
assert_eq!(offset_of!(AttackData, power), 0x20);
assert_eq!(offset_of!(AttackData, size), 0x24);
assert_eq!(offset_of!(AttackData, vector), 0x28);
assert_eq!(offset_of!(AttackData, r_eff), 0x2C);
assert_eq!(offset_of!(AttackData, r_fix), 0x30);
assert_eq!(offset_of!(AttackData, r_add), 0x34);
assert_eq!(offset_of!(AttackData, slip), 0x38);
assert_eq!(offset_of!(AttackData, stop_frame), 0x3C);
assert_eq!(offset_of!(AttackData, stop_delay), 0x40);
assert_eq!(offset_of!(AttackData, node), 0x48);
assert_eq!(offset_of!(AttackData, target_category), 0x50);
assert_eq!(offset_of!(AttackData, target_situation), 0x52);
assert_eq!(offset_of!(AttackData, target_lr), 0x53);
assert_eq!(offset_of!(AttackData, target_part), 0x54);
assert_eq!(offset_of!(AttackData, attr), 0x58);
assert_eq!(offset_of!(AttackData, sound_level), 0x60);
assert_eq!(offset_of!(AttackData, sound_attr), 0x61);
assert_eq!(offset_of!(AttackData, set_off), 0x62);
assert_eq!(offset_of!(AttackData, no_scale), 0x63);
assert_eq!(offset_of!(AttackData, shield), 0x64);
assert_eq!(offset_of!(AttackData, reflector), 0x65);
assert_eq!(offset_of!(AttackData, absorber), 0x66);
assert_eq!(offset_of!(AttackData, direct), 0x67);
assert_eq!(offset_of!(AttackData, no_invincible), 0x68);
assert_eq!(offset_of!(AttackData, no_xlu), 0x69);
assert_eq!(offset_of!(AttackData, lr_check), 0x6A);
assert_eq!(offset_of!(AttackData, catch), 0x6B);
assert_eq!(offset_of!(AttackData, no_team), 0x6C);
assert_eq!(offset_of!(AttackData, no_stop), 0x6D);
assert_eq!(offset_of!(AttackData, no_effect), 0x6E);
assert_eq!(offset_of!(AttackData, speed), 0x70);
assert_eq!(offset_of!(AttackData, region), 0x71);
assert_eq!(offset_of!(AttackData, ignore_down), 0x72);
assert_eq!(offset_of!(AttackData, check_type), 0x73);
assert_eq!(offset_of!(AttackData, sub_shield), 0x74);
assert_eq!(offset_of!(AttackData, camera_quake), 0x76);
assert_eq!(offset_of!(AttackData, serial_hit_frame), 0x78);
assert_eq!(offset_of!(AttackData, force_reaction), 0x7C);
assert_eq!(offset_of!(AttackData, no_attacker_log), 0x7D);
assert_eq!(offset_of!(AttackData, no_weight_reaction), 0x7E);
assert_eq!(offset_of!(AttackData, no_reaction_search), 0x7F);
assert_eq!(offset_of!(AttackData, keep_rumble), 0x80);
assert_eq!(offset_of!(AttackData, composition_speed), 0x81);
assert_eq!(offset_of!(AttackData, target_pos_node), 0x88);
assert_eq!(offset_of!(AttackData, target_pos_offset), 0x90);
assert_eq!(offset_of!(AttackData, target_pos_frame), 0xA0);
assert_eq!(offset_of!(AttackData, r_fix_damage_speed_up), 0xA4);
assert_eq!(offset_of!(AttackData, captured_same_time_attack), 0xA6);
}
}
39 changes: 39 additions & 0 deletions src/app/singletons/executable_object_manager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::*;

#[repr(C)]
pub struct ExecutableObject {
name: *const u8,
category: i32,
padding: u32,
run_on_frame_advance: bool,
padding: [u8; 0x2F],
function: *mut ExecutableFunction,
}

#[repr(C)]
pub struct ExecutableFunctionVTable {
destructor: extern "C" fn(&mut ExecutableFunction),
deleter: extern "C" fn(&mut ExecutableFunction),
copy_into: extern "C" fn(&ExecutableFunction, &mut ExecutableFunction),
copy_from: extern "C" fn(&mut ExecutableFunction, &ExecutableFunction),
destructor2: extern "C" fn(&mut ExecutableFunction),
deleter2: extern "C" fn(&mut ExecutableFunction),
call: extern "C" fn(&ExecutableFunction),
}

#[repr(C)]
pub struct ExecutableFunction {
vtable: &'static ExecutableFunctionVTable,
unk: u64,
abs_function_or_vtable_offset: u64,
shift_and_is_virtual: u64,
object: u64,
}

#[repr(C)]
pub struct ExecutableObjectManager {
pub current_category: i32,
pub should_category_run: [i32; 10],
pub unk_category: [i32; 10],
pub objects_by_category: [cpp::Deque<cpp::SharedPtr<ExecutableObject>>; 10],
}
145 changes: 145 additions & 0 deletions src/cpp/deque.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
use std::ops::{Index, IndexMut};

#[repr(C)]
pub struct SplitBuffer<T> {
first: *mut *mut T,
begin: *mut *mut T,
end: *mut *mut T,
end_cap: *mut *mut T,
}

impl<T> SplitBuffer<T> {
pub const fn block_size() -> usize {
if std::mem::size_of::<T>() < 0x100 {
0x1000 / std::mem::size_of::<T>()
} else {
0x10
}
}

pub fn len(&self) -> usize {
unsafe { self.end.offset_from(self.begin) as usize }
}

pub fn is_empty(&self) -> bool {
self.len() == 0
}

pub fn capacity(&self) -> usize {
unsafe { self.end_cap.offset_from(self.first) as usize }
}

pub fn get_buffer(&self, idx: usize) -> Option<&[T]> {
if idx >= self.len() {
None
} else {
Some(unsafe {
std::slice::from_raw_parts(
*self.begin.add(idx),
Self::block_size()
)
})
}
}

pub fn get_buffer_mut(&mut self, idx: usize) -> Option<&mut [T]> {
if idx >= self.len() {
None
} else {
Some(unsafe {
std::slice::from_raw_parts_mut(
*self.begin.add(idx),
Self::block_size()
)
})
}
}
}

#[repr(C)]
pub struct Deque<T> {
buffer: SplitBuffer<T>,
start_index: usize,
length: usize
}

impl<T> Deque<T> {
const fn split_index(index: usize) -> (usize, usize) {
let block_size = SplitBuffer::<T>::block_size();
(index / block_size, index % block_size)
}

pub fn len(&self) -> usize {
self.length
}

pub fn is_empty(&self) -> bool {
self.length == 0
}

pub fn get(&self, index: usize) -> Option<&T> {
if index >= self.length {
None
} else {
let (block, item) = Self::split_index(index);
self.buffer
.get_buffer(block)
.and_then(|buffer| buffer.get(item))
}
}

pub fn get_mut(&mut self, index: usize) -> Option<&mut T> {
if index >= self.length {
None
} else {
let (block, item) = Self::split_index(index);
self.buffer
.get_buffer_mut(block)
.and_then(|buffer| buffer.get_mut(item))
}
}
}

struct DequeIterator<'a, T> {
deque: &'a Deque<T>,
current: usize,
}

struct DequeIteratorMut<'a, T> {
deque: &'a mut Deque<T>,
current: usize
}

impl<'a, T> Iterator for DequeIterator<'a, T> {
type Item = &'a T;

fn next(&mut self) -> Option<Self::Item> {
let output = self.deque.get(self.current);
self.current += 1;
output
}
}

impl<'a, T> Iterator for DequeIteratorMut<'a, T> {
type Item = &'a mut T;

fn next(&mut self) -> Option<Self::Item> {
let output = self.deque.get_mut(self.current);
self.current += 1;
unsafe { std::mem::transmute::<Option<&mut T>, Option<&'a mut T>>(output) }
}
}

impl<T> Index<usize> for Deque<T> {
type Output = T;

fn index(&self, index: usize) -> &Self::Output {
self.get(index).unwrap()
}
}

impl<T> IndexMut<usize> for Deque<T> {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
self.get_mut(index).unwrap()
}
}
19 changes: 19 additions & 0 deletions src/cpp/shared_ptr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#[repr(C)]
pub struct SharedPtr<T> {
data: *mut T,
shared_weak_count: *mut ()
}

impl<T> std::ops::Deref for SharedPtr<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
unsafe { &*self.data }
}
}

impl<T> std::ops::DerefMut for SharedPtr<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *self.data }
}
}

0 comments on commit 5197a91

Please sign in to comment.