-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
273 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} |