Reorganize schema system structures into separate files

This commit is contained in:
a2x
2024-04-21 00:31:51 +10:00
parent 13b764854e
commit d0c40c50cd
22 changed files with 325 additions and 280 deletions

View File

@@ -1,244 +1,21 @@
use std::ffi::c_char;
pub use schema_base_class_info_data::*;
pub use schema_class_field_data::*;
pub use schema_class_info_data::*;
pub use schema_enum_info_data::*;
pub use schema_enumerator_info_data::*;
pub use schema_metadata_entry_data::*;
pub use schema_static_field_data::*;
pub use schema_system::*;
pub use schema_system_type_scope::*;
pub use schema_type::*;
use memflow::prelude::v1::*;
use super::{UtlTsHash, UtlVector};
pub type SchemaClassBinding = SchemaClassInfoData;
pub type SchemaEnumBinding = SchemaEnumInfoData;
pub type SchemaTypeDeclaredClass = SchemaType;
pub type SchemaTypeDeclaredEnum = SchemaType;
#[repr(u8)]
pub enum SchemaAtomicCategory {
Basic = 0,
T,
CollectionOfT,
TF,
TT,
TTF,
I,
None,
}
#[repr(u8)]
pub enum SchemaTypeCategory {
BuiltIn = 0,
Ptr,
Bitfield,
FixedArray,
Atomic,
DeclaredClass,
DeclaredEnum,
None,
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaArrayT {
pub array_size: u32, // 0x0000
pad_0004: [u8; 0x4], // 0x0004
pub element: Pointer64<SchemaType>, // 0x0008
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicI {
pad_0000: [u8; 0x10], // 0x0000
pub value: u64, // 0x0010
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicT {
pub element: Pointer64<SchemaType>, // 0x0000
pad_0008: [u8; 0x8], // 0x0008
pub template: Pointer64<SchemaType>, // 0x0010
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicTT {
pad_0000: [u8; 0x10], // 0x0000
pub templates: [Pointer64<SchemaType>; 2], // 0x0010
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicTF {
pad_0000: [u8; 0x10], // 0x0000
pub template: Pointer64<SchemaType>, // 0x0010
pub size: i32, // 0x0018
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicTTF {
pad_0000: [u8; 0x10], // 0x0000
pub templates: [Pointer64<SchemaType>; 2], // 0x0010
pub size: i32, // 0x0020
}
#[derive(Pod)]
#[repr(C)]
pub struct SchemaBaseClassInfoData {
pub offset: i32, // 0x0000
pad_0004: [u8; 0x4], // 0x0004
pub prev: Pointer64<SchemaClassInfoData>, // 0x0008
}
#[derive(Pod)]
#[repr(C)]
pub struct SchemaClassFieldData {
pub name: Pointer64<ReprCString>, // 0x0000
pub schema_type: Pointer64<SchemaType>, // 0x0008
pub offset: i32, // 0x0010
pub num_metadata: i32, // 0x0014
pub metadata: Pointer64<SchemaMetadataEntryData>, // 0x0018
}
#[rustfmt::skip]
#[derive(Pod)]
#[repr(C)]
pub struct SchemaClassInfoData {
pub base: Pointer64<SchemaClassInfoData>, // 0x0000
pub name: Pointer64<ReprCString>, // 0x0008
pub module_name: Pointer64<ReprCString>, // 0x0010
pub size: i32, // 0x0018
pub num_fields: i16, // 0x001C
pub num_static_fields: i16, // 0x001E
pub num_static_metadata: i16, // 0x0020
pub alignment: u8, // 0x0022
pub has_base_class: u8, // 0x0023
pub total_class_size: i16, // 0x0024
pub derived_class_size: i16, // 0x0026
pub fields: Pointer64<[SchemaClassFieldData]>, // 0x0028
pub static_fields: Pointer64<[SchemaStaticFieldData]>, // 0x0030
pub base_classes: Pointer64<SchemaBaseClassInfoData>, // 0x0038
pad_0040: [u8; 0x8], // 0x0040
pub static_metadata: Pointer64<[SchemaMetadataEntryData]>, // 0x0048
pub type_scope: Pointer64<SchemaSystemTypeScope>, // 0x0050
pub schema_type: Pointer64<SchemaType>, // 0x0058
pad_0060: [u8; 0x10], // 0x0060
}
#[rustfmt::skip]
#[derive(Pod)]
#[repr(C)]
pub struct SchemaEnumInfoData {
pub base: Pointer64<SchemaEnumInfoData>, // 0x0000
pub name: Pointer64<ReprCString>, // 0x0008
pub module_name: Pointer64<ReprCString>, // 0x0010
pub size: u8, // 0x0018
pub alignment: u8, // 0x0019
pad_001a: u16, // 0x001A
pub num_enumerators: i16, // 0x001C
pub num_static_metadata: i16, // 0x001E
pub enumerators: Pointer64<[SchemaEnumeratorInfoData]>, // 0x0020
pub static_metadata: Pointer64<SchemaMetadataEntryData>, // 0x0028
pub type_scope: Pointer64<SchemaSystemTypeScope>, // 0x0030
pad_0038: [u8; 0x10], // 0x0038
}
#[repr(C)]
pub struct SchemaEnumeratorInfoData {
pub name: Pointer64<ReprCString>, // 0x0000
pub u: SchemaEnumeratorInfoDataUnion, // 0x0008
pub num_metadata: u32, // 0x0010
pub metadata: Pointer64<SchemaMetadataEntryData>, // 0x0018
}
unsafe impl Pod for SchemaEnumeratorInfoData {}
#[repr(C)]
pub union SchemaEnumeratorInfoDataUnion {
pub uchar: u8,
pub ushort: u16,
pub uint: u32,
pub ulong: u64,
}
#[derive(Pod)]
#[repr(C)]
pub struct SchemaMetadataEntryData {
pub name: Pointer64<ReprCString>, // 0x0000
pub network_value: Pointer64<SchemaNetworkValue>, // 0x0008
}
#[repr(C)]
pub struct SchemaNetworkValue {
pub u: SchemaNetworkValueUnion, // 0x0000
}
unsafe impl Pod for SchemaNetworkValue {}
#[repr(C)]
pub union SchemaNetworkValueUnion {
pub name_ptr: Pointer64<ReprCString>,
pub int_value: i32,
pub float_value: f32,
pub ptr: Pointer64<()>,
pub var_value: SchemaVarName,
pub name_value: [c_char; 32],
}
#[derive(Pod)]
#[repr(C)]
pub struct SchemaStaticFieldData {
pub name: Pointer64<ReprCString>, // 0x0000
pub type_: Pointer64<SchemaType>, // 0x0008
pub instance: Pointer64<()>, // 0x0010
pad_0018: [u8; 0x10], // 0x0018
}
#[derive(Pod)]
#[repr(C)]
pub struct SchemaSystem {
pad_0000: [u8; 0x190], // 0x0000
pub type_scopes: UtlVector<Pointer64<SchemaSystemTypeScope>>, // 0x0190
pad_01a0: [u8; 0x120], // 0x01A0
pub num_registrations: u32, // 0x02C0
pad_02c4: [u8; 0x4], // 0x02C4
}
#[derive(Pod)]
#[repr(C)]
pub struct SchemaSystemTypeScope {
pad_0000: [u8; 0x8], // 0x0000
pub name: [c_char; 256], // 0x0008
pub global_scope: Pointer64<SchemaSystemTypeScope>, // 0x0108
pad_0110: [u8; 0x4B0], // 0x0110
pub class_bindings: UtlTsHash<Pointer64<SchemaClassBinding>>, // 0x05C0
pub enum_bindings: UtlTsHash<Pointer64<SchemaEnumBinding>>, // 0x2E50
}
#[repr(C)]
pub struct SchemaType {
pad_0000: [u8; 0x8], // 0x0000
pub name: Pointer64<ReprCString>, // 0x0008
pub type_scope: Pointer64<SchemaSystemTypeScope>, // 0x0010
pub type_category: SchemaTypeCategory, // 0x0018
pub atomic_category: SchemaAtomicCategory, // 0x0019
pub u: SchemaTypeUnion, // 0x0020
}
unsafe impl Pod for SchemaType {}
pub union SchemaTypeUnion {
pub schema_type: Pointer64<SchemaType>,
pub class_binding: Pointer64<SchemaClassBinding>,
pub enum_binding: Pointer64<SchemaEnumBinding>,
pub array: SchemaArrayT,
pub atomic: SchemaAtomicT,
pub atomic_tt: SchemaAtomicTT,
pub atomic_tf: SchemaAtomicTF,
pub atomic_ttf: SchemaAtomicTTF,
pub atomic_i: SchemaAtomicI,
}
#[derive(Pod, Clone, Copy)]
#[repr(C)]
pub struct SchemaVarName {
pub name: Pointer64<ReprCString>, // 0x0000
pub type_name: Pointer64<ReprCString>, // 0x0008
}
pub mod schema_base_class_info_data;
pub mod schema_class_field_data;
pub mod schema_class_info_data;
pub mod schema_enum_info_data;
pub mod schema_enumerator_info_data;
pub mod schema_metadata_entry_data;
pub mod schema_static_field_data;
pub mod schema_system;
pub mod schema_system_type_scope;
pub mod schema_type;

View File

@@ -0,0 +1,11 @@
use memflow::prelude::v1::*;
use super::SchemaClassInfoData;
#[derive(Pod)]
#[repr(C)]
pub struct SchemaBaseClassInfoData {
pub offset: u32, // 0x0000
pad_0004: [u8; 4], // 0x0004
pub prev: Pointer64<SchemaClassInfoData>, // 0x0008
}

View File

@@ -0,0 +1,13 @@
use memflow::prelude::v1::*;
use super::{SchemaMetadataEntryData, SchemaType};
#[derive(Pod)]
#[repr(C)]
pub struct SchemaClassFieldData {
pub name: Pointer64<ReprCString>, // 0x0000
pub schema_type: Pointer64<SchemaType>, // 0x0008
pub single_inheritance_offset: i32, // 0x0010
pub static_metadata_count: i32, // 0x0014
pub static_metadata: Pointer64<SchemaMetadataEntryData>, // 0x0018
}

View File

@@ -0,0 +1,30 @@
use memflow::prelude::v1::*;
use super::*;
pub type SchemaClassBinding = SchemaClassInfoData;
#[rustfmt::skip]
#[derive(Pod)]
#[repr(C)]
pub struct SchemaClassInfoData {
pub base: Pointer64<SchemaClassInfoData>, // 0x0000
pub name: Pointer64<ReprCString>, // 0x0008
pub module_name: Pointer64<ReprCString>, // 0x0010
pub size: i32, // 0x0018
pub field_count: u16, // 0x001C
pub static_field_count: u16, // 0x001E
pub static_metadata_count: u16, // 0x0020
pub alignment: u8, // 0x0022
pub base_class_count: u8, // 0x0023
pub multiple_inheritance_depth: u16, // 0x0024
pub single_inheritance_depth: u16, // 0x0026
pub fields: Pointer64<[SchemaClassFieldData]>, // 0x0028
pub static_fields: Pointer64<[SchemaStaticFieldData]>, // 0x0030
pub base_classes: Pointer64<SchemaBaseClassInfoData>, // 0x0038
pad_0040: [u8; 0x8], // 0x0040
pub static_metadata: Pointer64<[SchemaMetadataEntryData]>, // 0x0048
pub type_scope: Pointer64<SchemaSystemTypeScope>, // 0x0050
pub schema_type: Pointer64<SchemaType>, // 0x0058
pad_0060: [u8; 0x10], // 0x0060
}

View File

@@ -0,0 +1,24 @@
use memflow::prelude::v1::*;
use super::{SchemaEnumeratorInfoData, SchemaMetadataEntryData, SchemaSystemTypeScope};
pub type SchemaEnumBinding = SchemaEnumInfoData;
#[rustfmt::skip]
#[derive(Pod)]
#[repr(C)]
pub struct SchemaEnumInfoData {
pub base: Pointer64<SchemaEnumInfoData>, // 0x0000
pub name: Pointer64<ReprCString>, // 0x0008
pub module_name: Pointer64<ReprCString>, // 0x0010
pub size: u8, // 0x0018
pub alignment: u8, // 0x0019
pub flags: u16, // 0x001A
pub enumerator_count: u16, // 0x001C
pub static_metadata_count: u16, // 0x001E
pub enumerators: Pointer64<[SchemaEnumeratorInfoData]>, // 0x0020
pub static_metadata: Pointer64<SchemaMetadataEntryData>, // 0x0028
pub type_scope: Pointer64<SchemaSystemTypeScope>, // 0x0030
pub min_enumerator_value: i64, // 0x0038
pub max_enumerator_value: i64, // 0x0040
}

View File

@@ -0,0 +1,23 @@
use memflow::prelude::v1::*;
use super::SchemaMetadataEntryData;
#[derive(Pod)]
#[repr(C)]
pub struct SchemaEnumeratorInfoData {
pub name: Pointer64<ReprCString>, // 0x0000
pub value: SchemaEnumeratorInfoDataUnion, // 0x0008
pub static_metadata_count: i32, // 0x0010
pad_0014: [u8; 0x4], // 0x0014
pub static_metadata: Pointer64<SchemaMetadataEntryData>, // 0x0018
}
#[repr(C)]
pub union SchemaEnumeratorInfoDataUnion {
pub uchar: u8,
pub ushort: u16,
pub uint: u32,
pub ulong: u64,
}
unsafe impl Pod for SchemaEnumeratorInfoDataUnion {}

View File

@@ -0,0 +1,35 @@
use std::ffi::c_char;
use memflow::prelude::v1::*;
#[derive(Pod)]
#[repr(C)]
pub struct SchemaMetadataEntryData {
pub name: Pointer64<ReprCString>, // 0x0000
pub data: Pointer64<SchemaNetworkValue>, // 0x0008
}
#[derive(Pod)]
#[repr(C)]
pub struct SchemaNetworkValue {
pub value: SchemaNetworkValueUnion, // 0x0000
}
#[repr(C)]
pub union SchemaNetworkValueUnion {
pub name_ptr: Pointer64<ReprCString>,
pub int_value: i32,
pub float_value: f32,
pub ptr: Pointer64<()>,
pub var_value: SchemaVarName,
pub name_value: [c_char; 32],
}
unsafe impl Pod for SchemaNetworkValueUnion {}
#[derive(Clone, Copy, Pod)]
#[repr(C)]
pub struct SchemaVarName {
pub name: Pointer64<ReprCString>, // 0x0000
pub type_name: Pointer64<ReprCString>, // 0x0008
}

View File

@@ -0,0 +1,14 @@
use memflow::prelude::v1::*;
use super::{SchemaMetadataEntryData, SchemaType};
#[derive(Pod)]
#[repr(C)]
pub struct SchemaStaticFieldData {
pub name: Pointer64<ReprCString>, // 0x0000
pub type_: Pointer64<SchemaType>, // 0x0008
pub instance: Pointer64<()>, // 0x0010
pub static_metadata_count: i32, // 0x0018
pad_001c: [u8; 0x4], // 0x001C
pub static_metadata: Pointer64<SchemaMetadataEntryData>, // 0x0020
}

View File

@@ -0,0 +1,15 @@
use memflow::prelude::v1::*;
use super::SchemaSystemTypeScope;
use crate::source2::UtlVector;
#[derive(Pod)]
#[repr(C)]
pub struct SchemaSystem {
pad_0000: [u8; 0x190], // 0x0000
pub type_scopes: UtlVector<Pointer64<SchemaSystemTypeScope>>, // 0x0190
pad_01a0: [u8; 0x120], // 0x01A0
pub num_registrations: u32, // 0x02C0
pad_02c4: [u8; 0xAC], // 0x02C4
}

View File

@@ -0,0 +1,18 @@
use std::ffi::c_char;
use memflow::prelude::v1::*;
use super::{SchemaClassBinding, SchemaEnumBinding};
use crate::source2::UtlTsHash;
#[derive(Pod)]
#[repr(C)]
pub struct SchemaSystemTypeScope {
pad_0000: [u8; 0x8], // 0x0000
pub name: [c_char; 256], // 0x0008
pub global_scope: Pointer64<SchemaSystemTypeScope>, // 0x0108
pad_0110: [u8; 0x4B0], // 0x0110
pub class_bindings: UtlTsHash<Pointer64<SchemaClassBinding>>, // 0x05C0
pub enum_bindings: UtlTsHash<Pointer64<SchemaEnumBinding>>, // 0x2E50
}

View File

@@ -0,0 +1,97 @@
use memflow::prelude::v1::*;
use super::{SchemaClassBinding, SchemaEnumBinding, SchemaSystemTypeScope};
#[repr(u8)]
pub enum SchemaAtomicCategory {
Basic = 0,
T,
CollectionOfT,
TF,
TT,
TTF,
I,
None,
}
#[repr(u8)]
pub enum SchemaTypeCategory {
BuiltIn = 0,
Ptr,
Bitfield,
FixedArray,
Atomic,
DeclaredClass,
DeclaredEnum,
None,
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaArrayT {
pub array_size: u32, // 0x0000
pad_0004: [u8; 0x4], // 0x0004
pub element: Pointer64<SchemaType>, // 0x0008
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicI {
pad_0000: [u8; 0x10], // 0x0000
pub value: u64, // 0x0010
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicT {
pub element: Pointer64<SchemaType>, // 0x0000
pad_0008: [u8; 0x8], // 0x0008
pub template: Pointer64<SchemaType>, // 0x0010
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicTT {
pad_0000: [u8; 0x10], // 0x0000
pub templates: [Pointer64<SchemaType>; 2], // 0x0010
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicTF {
pad_0000: [u8; 0x10], // 0x0000
pub template: Pointer64<SchemaType>, // 0x0010
pub size: i32, // 0x0018
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicTTF {
pad_0000: [u8; 0x10], // 0x0000
pub templates: [Pointer64<SchemaType>; 2], // 0x0010
pub size: i32, // 0x0020
}
#[repr(C)]
pub struct SchemaType {
pad_0000: [u8; 0x8], // 0x0000
pub name: Pointer64<ReprCString>, // 0x0008
pub type_scope: Pointer64<SchemaSystemTypeScope>, // 0x0010
pub type_category: SchemaTypeCategory, // 0x0018
pub atomic_category: SchemaAtomicCategory, // 0x0019
pub value: SchemaTypeUnion, // 0x0020
}
unsafe impl Pod for SchemaType {}
pub union SchemaTypeUnion {
pub schema_type: Pointer64<SchemaType>,
pub class_binding: Pointer64<SchemaClassBinding>,
pub enum_binding: Pointer64<SchemaEnumBinding>,
pub array: SchemaArrayT,
pub atomic: SchemaAtomicT,
pub atomic_tt: SchemaAtomicTT,
pub atomic_tf: SchemaAtomicTF,
pub atomic_ttf: SchemaAtomicTTF,
pub atomic_i: SchemaAtomicI,
}

View File

@@ -10,13 +10,11 @@ pub struct UtlMemory<T> {
}
impl<T: Pod> UtlMemory<T> {
/// Returns the number of allocated elements.
#[inline]
pub fn count(&self) -> i32 {
self.alloc_count
}
/// Returns the element at the specified index.
pub fn element(&self, process: &mut IntoProcessInstanceArcBox<'_>, idx: usize) -> Result<T> {
if idx >= self.count() as usize {
return Err(Error::Other("index out of bounds"));
@@ -25,7 +23,6 @@ impl<T: Pod> UtlMemory<T> {
self.mem.at(idx as _).read(process).map_err(Into::into)
}
/// Returns `true` if the memory was externally allocated.
#[inline]
pub fn is_externally_allocated(&self) -> bool {
self.grow_size < 0

View File

@@ -30,7 +30,7 @@ pub struct UtlMemoryPoolBase {
pub blocks_alloc: i32, // 0x000C
pub peak_alloc: i32, // 0x0010
pub alignment: u16, // 0x0014
pub num_blobs: u16, // 0x0016
pub blob_count: u16, // 0x0016
pub free_list_tail: Pointer64<Pointer64<FreeList>>, // 0x0018
pub free_list_head: Pointer64<FreeList>, // 0x0020
pad_0028: [u8; 0x44], // 0x0028
@@ -40,7 +40,6 @@ pub struct UtlMemoryPoolBase {
}
impl UtlMemoryPoolBase {
/// Returns the total size of the memory pool.
#[inline]
pub fn size(&self) -> i32 {
self.total_size

View File

@@ -44,25 +44,21 @@ where
D: Pod + PointerExt,
K: Pod,
{
/// Returns the number of allocated blocks.
#[inline]
pub fn blocks_alloc(&self) -> i32 {
self.entry_mem.blocks_alloc
}
/// Returns the size of a block.
#[inline]
pub fn block_size(&self) -> i32 {
self.entry_mem.block_size
}
/// Returns the maximum number of allocated blocks.
#[inline]
pub fn peak_count(&self) -> i32 {
self.entry_mem.peak_alloc
}
/// Returns a list of allocated or unallocated elements.
pub fn elements(&self, process: &mut IntoProcessInstanceArcBox<'_>) -> Result<Vec<D>> {
let blocks_alloc = self.blocks_alloc() as usize;
let peak_alloc = self.peak_count() as usize;

View File

@@ -9,13 +9,11 @@ pub struct UtlVector<T> {
}
impl<T: Pod> UtlVector<T> {
/// Returns the number of elements in the vector.
#[inline]
pub fn count(&self) -> i32 {
self.size
}
/// Returns the element at the specified index.
pub fn element(&self, process: &mut IntoProcessInstanceArcBox<'_>, idx: usize) -> Result<T> {
if idx >= self.count() as usize {
return Err(Error::Other("index out of bounds"));