Experimental fix for latest update

This commit is contained in:
a2x
2024-04-04 23:42:40 +10:00
parent 3a935f5d73
commit 9362b0c113
106 changed files with 21261 additions and 27319 deletions

View File

@@ -120,7 +120,7 @@ fn read_class_binding_fields(
process: &mut IntoProcessInstanceArcBox<'_>,
binding: &SchemaClassBinding,
) -> Result<Vec<ClassField>> {
(0..binding.fields_count)
(0..binding.num_fields)
.map(|i| {
let field_ptr: Pointer64<SchemaClassFieldData> = binding
.fields
@@ -157,7 +157,7 @@ fn read_class_binding_metadata(
return Err(Error::Other("class metadata is null"));
}
(0..binding.static_metadata_count)
(0..binding.num_static_metadata)
.map(|i| {
let metadata_ptr: Pointer64<SchemaMetadataEntryData> =
binding.static_metadata.offset(i as _).into();
@@ -199,6 +199,7 @@ fn read_enum_binding(
) -> Result<Enum> {
let binding = binding_ptr.read(process)?;
let name = binding.name.read_string(process)?.to_string();
let members = read_enum_binding_members(process, &binding)?;
debug!(
@@ -271,6 +272,43 @@ fn read_schema_system(process: &mut IntoProcessInstanceArcBox<'_>) -> Result<Sch
Ok(schema_system)
}
fn read_class_bindings(
process: &mut IntoProcessInstanceArcBox<'_>,
type_scope_ptr: Pointer64<SchemaSystemTypeScope>,
) -> Result<Vec<Class>> {
let tree: UtlRbTree = process.read(type_scope_ptr.address() + 0x4C8)?;
let classes = (0..1000) // TODO: `num_elements` doesn't seem to work for all modules.
.filter_map(|i| {
let element = tree.elements.at(i as _).read(process).ok()?;
let binding_ptr = Pointer64::<SchemaTypeDeclaredClass>::from(element.data.address())
.read(process)
.ok()?
.binding;
if binding_ptr.is_null() {
return None;
}
read_class_binding(process, binding_ptr).ok()
})
.collect();
Ok(classes)
}
fn read_enum_bindings(
process: &mut IntoProcessInstanceArcBox<'_>,
type_scope_ptr: Pointer64<SchemaSystemTypeScope>,
) -> Result<Vec<Enum>> {
let _tree: UtlRbTree = process.read(type_scope_ptr.address() + 0x4F8)?;
// TODO: Implement this.
Ok(Vec::new())
}
fn read_type_scopes(
process: &mut IntoProcessInstanceArcBox<'_>,
schema_system: &SchemaSystem,
@@ -279,28 +317,18 @@ fn read_type_scopes(
(0..type_scopes.size)
.map(|i| {
let type_scope = type_scopes.get(process, i as _)?.read(process)?;
let type_scope_ptr = type_scopes.get(process, i as _)?;
let type_scope = type_scope_ptr.read(process)?;
let name = unsafe { CStr::from_ptr(type_scope.name.as_ptr()) }
.to_string_lossy()
.to_string();
let classes: Vec<_> = type_scope
.class_bindings
.elements(process)?
.iter()
.filter_map(|ptr| read_class_binding(process, *ptr).ok())
.collect();
let enums: Vec<_> = type_scope
.enum_bindings
.elements(process)?
.iter()
.filter_map(|ptr| read_enum_binding(process, *ptr).ok())
.collect();
let classes = read_class_bindings(process, type_scope_ptr)?;
let enums = read_enum_bindings(process, type_scope_ptr)?;
debug!(
"found type scope: {} (classes: {}) (enums: {})",
"found type scope: {} (classes count: {}) (enums count: {})",
name,
classes.len(),
enums.len()

View File

@@ -2,12 +2,12 @@ use memflow::prelude::v1::*;
#[repr(C)]
pub struct KeyboardKey {
pad_0000: [u8; 0x8],
pub name: Pointer64<ReprCString>,
pad_0010: [u8; 0x20],
pub state: u32,
pad_0034: [u8; 0x50],
pub next: Pointer64<KeyboardKey>,
pad_0000: [u8; 0x8], // 0x0000
pub name: Pointer64<ReprCString>, // 0x0008
pad_0010: [u8; 0x20], // 0x0010
pub state: u32, // 0x0030
pad_0034: [u8; 0x54], // 0x0034
pub next: Pointer64<KeyboardKey>, // 0x0088
}
unsafe impl Pod for KeyboardKey {}

View File

@@ -1,6 +1,7 @@
pub use schema_base_class_info_data::*;
pub use schema_class_field_data::*;
pub use schema_class_info_data::*;
pub use schema_declared_class::*;
pub use schema_enum_info_data::*;
pub use schema_enumerator_info_data::*;
pub use schema_metadata_entry_data::*;
@@ -8,10 +9,13 @@ pub use schema_static_field_data::*;
pub use schema_system::*;
pub use schema_system_type_scope::*;
pub use schema_type::*;
pub use schema_type_declared_class::*;
pub use schema_type_declared_enum::*;
pub mod schema_base_class_info_data;
pub mod schema_class_field_data;
pub mod schema_class_info_data;
pub mod schema_declared_class;
pub mod schema_enum_info_data;
pub mod schema_enumerator_info_data;
pub mod schema_metadata_entry_data;
@@ -19,3 +23,5 @@ pub mod schema_static_field_data;
pub mod schema_system;
pub mod schema_system_type_scope;
pub mod schema_type;
pub mod schema_type_declared_class;
pub mod schema_type_declared_enum;

View File

@@ -4,8 +4,9 @@ use super::SchemaClassInfoData;
#[repr(C)]
pub struct SchemaBaseClassInfoData {
pub offset: u32,
pub prev: Pointer64<SchemaClassInfoData>,
pub offset: u32, // 0x0000
pad_0004: [u8; 0x4], // 0x0004
pub prev: Pointer64<SchemaClassInfoData>, // 0x0008
}
unsafe impl Pod for SchemaBaseClassInfoData {}

View File

@@ -4,11 +4,11 @@ use super::{SchemaMetadataEntryData, SchemaType};
#[repr(C)]
pub struct SchemaClassFieldData {
pub name: Pointer64<ReprCString>,
pub type_: Pointer64<SchemaType>,
pub offset: u32,
pub metadata_count: u32,
pub metadata: Pointer64<SchemaMetadataEntryData>,
pub name: Pointer64<ReprCString>, // 0x0000
pub type_: Pointer64<SchemaType>, // 0x0008
pub offset: u32, // 0x0010
pub num_metadata: u32, // 0x0014
pub metadata: Pointer64<SchemaMetadataEntryData>, // 0x0018
}
unsafe impl Pod for SchemaClassFieldData {}

View File

@@ -7,27 +7,28 @@ use super::{
pub type SchemaClassBinding = SchemaClassInfoData;
#[rustfmt::skip]
#[repr(C)]
pub struct SchemaClassInfoData {
pub base: Pointer64<SchemaClassInfoData>,
pub name: Pointer64<ReprCString>,
pub module_name: Pointer64<ReprCString>,
pub size: u32,
pub fields_count: u16,
pub static_fields_count: u16,
pub static_metadata_count: u16,
pub alignment: u8,
pub has_base_class: bool,
pub total_class_size: u16,
pub derived_class_size: u16,
pub fields: Pointer64<SchemaClassFieldData>,
pub static_fields: Pointer64<SchemaStaticFieldData>,
pub base_classes: Pointer64<SchemaBaseClassInfoData>,
pad_0040: [u8; 0x8],
pub static_metadata: Pointer64<SchemaMetadataEntryData>,
pub type_scope: Pointer64<SchemaSystemTypeScope>,
pub type_: Pointer64<SchemaType>,
pad_0060: [u8; 0x10],
pub base: Pointer64<SchemaClassInfoData>, // 0x0000
pub name: Pointer64<ReprCString>, // 0x0008
pub module_name: Pointer64<ReprCString>, // 0x0010
pub size: u32, // 0x0018
pub num_fields: u16, // 0x001C
pub num_static_fields: u16, // 0x001E
pub num_static_metadata: u16, // 0x0020
pub alignment: u8, // 0x0022
pub has_base_class: bool, // 0x0023
pub total_class_size: u16, // 0x0024
pub derived_class_size: 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 type_: Pointer64<SchemaType>, // 0x0058
pad_0060: [u8; 0x10], // 0x0060
}
unsafe impl Pod for SchemaClassInfoData {}

View File

@@ -0,0 +1,21 @@
use memflow::prelude::v1::*;
use super::SchemaSystemTypeScope;
#[repr(C)]
pub struct SchemaDeclaredClass {
pad_0000: [u8; 0x8], // 0x0000
pub name: Pointer64<ReprCString>, // 0x0008
pub type_scope: Pointer64<SchemaSystemTypeScope>, // 0x0010
pad_0018: [u8; 0x10], // 0x0018
}
unsafe impl Pod for SchemaDeclaredClass {}
#[repr(C)]
pub struct SchemaDeclaredClassEntry {
pad_0000: [u8; 0x10], // 0x0000
pub declared_class: Pointer64<SchemaDeclaredClass>, // 0x0010
}
unsafe impl Pod for SchemaDeclaredClassEntry {}

View File

@@ -4,19 +4,20 @@ use super::{SchemaEnumeratorInfoData, SchemaMetadataEntryData, SchemaSystemTypeS
pub type SchemaEnumBinding = SchemaEnumInfoData;
#[rustfmt::skip]
#[repr(C)]
pub struct SchemaEnumInfoData {
pub base: Pointer64<SchemaEnumInfoData>,
pub name: Pointer64<ReprCString>,
pub module_name: Pointer64<ReprCString>,
pub alignment: u8,
pad_0019: [u8; 0x3],
pub size: u16,
pub static_metadata_count: u16,
pub enum_info: Pointer64<SchemaEnumeratorInfoData>,
pub static_metadata: Pointer64<SchemaMetadataEntryData>,
pub type_scope: Pointer64<SchemaSystemTypeScope>,
pad_0038: [u8; 0xC],
pub base: Pointer64<SchemaEnumInfoData>, // 0x0000
pub name: Pointer64<ReprCString>, // 0x0008
pub module_name: Pointer64<ReprCString>, // 0x0010
pub alignment: u8, // 0x0018
pad_0019: [u8; 0x3], // 0x0019
pub size: u16, // 0x001C
pub num_static_metadata: u16, // 0x001E
pub enum_info: Pointer64<SchemaEnumeratorInfoData>, // 0x0020
pub static_metadata: Pointer64<SchemaMetadataEntryData>, // 0x0028
pub type_scope: Pointer64<SchemaSystemTypeScope>, // 0x0030
pad_0038: [u8; 0x10], // 0x0038
}
unsafe impl Pod for SchemaEnumInfoData {}

View File

@@ -4,10 +4,10 @@ use super::SchemaMetadataEntryData;
#[repr(C)]
pub struct SchemaEnumeratorInfoData {
pub name: Pointer64<ReprCString>,
pub u: SchemaEnumeratorInfoDataUnion,
pub metadata_count: u32,
pub metadata: Pointer64<SchemaMetadataEntryData>,
pub name: Pointer64<ReprCString>, // 0x0000
pub u: SchemaEnumeratorInfoDataUnion, // 0x0008
pub num_metadata: u32, // 0x0010
pub metadata: Pointer64<SchemaMetadataEntryData>, // 0x0018
}
unsafe impl Pod for SchemaEnumeratorInfoData {}

View File

@@ -4,15 +4,15 @@ use memflow::prelude::v1::*;
#[repr(C)]
pub struct SchemaMetadataEntryData {
pub name: Pointer64<ReprCString>,
pub network_value: Pointer64<SchemaNetworkValue>,
pub name: Pointer64<ReprCString>, // 0x0000
pub network_value: Pointer64<SchemaNetworkValue>, // 0x0008
}
unsafe impl Pod for SchemaMetadataEntryData {}
#[repr(C)]
pub struct SchemaNetworkValue {
pub u: SchemaNetworkValueUnion,
pub u: SchemaNetworkValueUnion, // 0x0000
}
unsafe impl Pod for SchemaNetworkValue {}
@@ -30,6 +30,6 @@ pub union SchemaNetworkValueUnion {
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaVarName {
pub name: Pointer64<ReprCString>,
pub ty: Pointer64<ReprCString>,
pub name: Pointer64<ReprCString>, // 0x0000
pub ty: Pointer64<ReprCString>, // 0x0008
}

View File

@@ -4,10 +4,10 @@ use super::SchemaType;
#[repr(C)]
pub struct SchemaStaticFieldData {
pub name: Pointer64<ReprCString>,
pub type_: Pointer64<SchemaType>,
pub instance: Address,
pad_0018: [u8; 0x10],
pub name: Pointer64<ReprCString>, // 0x0000
pub type_: Pointer64<SchemaType>, // 0x0008
pub instance: Address, // 0x0010
pad_0018: [u8; 0x10], // 0x0018
}
unsafe impl Pod for SchemaStaticFieldData {}

View File

@@ -6,10 +6,10 @@ use crate::source2::UtlVector;
#[repr(C)]
pub struct SchemaSystem {
pad_0000: [u8; 0x190],
pub type_scopes: UtlVector<Pointer64<SchemaSystemTypeScope>>,
pad_01a0: [u8; 0x120],
pub num_registrations: u32,
pad_0000: [u8; 0x190], // 0x0000
pub type_scopes: UtlVector<Pointer64<SchemaSystemTypeScope>>, // 0x0190
pad_01a0: [u8; 0x120], // 0x01A0
pub num_registrations: u32, // 0x02C0
}
unsafe impl Pod for SchemaSystem {}

View File

@@ -2,18 +2,17 @@ use std::ffi::c_char;
use memflow::prelude::v1::*;
use super::{SchemaClassBinding, SchemaEnumBinding};
use crate::source2::UtlTsHash;
use super::SchemaDeclaredClassEntry;
#[repr(C)]
pub struct SchemaSystemTypeScope {
pad_0000: [u8; 0x8],
pub name: [c_char; 256],
pad_0108: [u8; 0x4B0],
pub class_bindings: UtlTsHash<Pointer64<SchemaClassBinding>>,
pad_05f0: [u8; 0x2810],
pub enum_bindings: UtlTsHash<Pointer64<SchemaEnumBinding>>,
pad_0000: [u8; 0x8], // 0x0000
pub name: [c_char; 256], // 0x0008
pub global_scope: Pointer64<SchemaSystemTypeScope>, // 0x0108
pad_0110: [u8; 0x3C0], // 0x0110
pub declared_class: Pointer64<SchemaDeclaredClassEntry>, // 0x04D0
pad_04d8: [u8; 0xe], // 0x04D8
pub num_declared_classes: u16, // 0x04E6
}
unsafe impl Pod for SchemaSystemTypeScope {}

View File

@@ -31,56 +31,56 @@ pub enum SchemaTypeCategory {
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaArray {
pub array_size: u32,
pad_0004: [u8; 0x4],
pub element_type: Pointer64<SchemaType>,
pub array_size: u32, // 0x0000
pad_0004: [u8; 0x4], // 0x0004
pub element_type: Pointer64<SchemaType>, // 0x0008
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomic {
pub element_type: Pointer64<SchemaType>,
pad_0008: [u8; 0x8],
pub template_ty: Pointer64<SchemaType>,
pub element_type: Pointer64<SchemaType>, // 0x0000
pad_0008: [u8; 0x8], // 0x0008
pub template_type: Pointer64<SchemaType>, // 0x0010
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicI {
pad_0000: [u8; 0x10],
pub value: u64,
pad_0000: [u8; 0x10], // 0x0000
pub value: u64, // 0x0010
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicTF {
pad_0000: [u8; 0x10],
pub template_ty: Pointer64<SchemaType>,
pub size: u32,
pad_0000: [u8; 0x10], // 0x0000
pub template_type: Pointer64<SchemaType>, // 0x0010
pub size: u32, // 0x0018
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicTT {
pad_0000: [u8; 0x10],
pub templates: [Pointer64<SchemaType>; 2],
pad_0000: [u8; 0x10], // 0x0000
pub templates: [Pointer64<SchemaType>; 2], // 0x0010
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicTTF {
pad_0000: [u8; 0x10],
pub templates: [Pointer64<SchemaType>; 2],
pub size: u32,
pad_0000: [u8; 0x10], // 0x0000
pub templates: [Pointer64<SchemaType>; 2], // 0x0010
pub size: u32, // 0x0020
}
#[repr(C)]
pub struct SchemaType {
pad_0000: [u8; 0x8],
pub name: Pointer64<ReprCString>,
pub type_scope: Pointer64<SchemaSystemTypeScope>,
pub type_category: SchemaTypeCategory,
pub atomic_category: SchemaAtomicCategory,
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
}
unsafe impl Pod for SchemaType {}

View File

@@ -0,0 +1,15 @@
use memflow::prelude::v1::*;
use super::{SchemaClassBinding, SchemaSystemTypeScope};
#[repr(C)]
pub struct SchemaTypeDeclaredClass {
pad_0000: [u8; 0x8], // 0x0000
pub name: Pointer64<ReprCString>, // 0x0008
pub type_scope: Pointer64<SchemaSystemTypeScope>, // 0x0010
pad_0018: [u8; 0x8], // 0x0018
pub binding: Pointer64<SchemaClassBinding>, // 0x0020
pad_0028: [u8; 0x8], // 0x0028
}
unsafe impl Pod for SchemaTypeDeclaredClass {}

View File

@@ -0,0 +1,15 @@
use memflow::prelude::v1::*;
use super::{SchemaEnumBinding, SchemaSystemTypeScope};
#[repr(C)]
pub struct SchemaTypeDeclaredEnum {
pad_0000: [u8; 0x8], // 0x0000
pub name: Pointer64<ReprCString>, // 0x0008
pub type_scope: Pointer64<SchemaSystemTypeScope>, // 0x0010
pad_0018: [u8; 0x8], // 0x0018
pub binding: Pointer64<SchemaEnumBinding>, // 0x0020
pad_0028: [u8; 0x8], // 0x0028
}
unsafe impl Pod for SchemaTypeDeclaredEnum {}

View File

@@ -2,9 +2,9 @@ use memflow::prelude::v1::*;
#[repr(C)]
pub struct InterfaceReg {
pub create_fn: Address,
pub name: Pointer64<ReprCString>,
pub next: Pointer64<InterfaceReg>,
pub create_fn: Address, // 0x0000
pub name: Pointer64<ReprCString>, // 0x0008
pub next: Pointer64<InterfaceReg>, // 0x0010
}
unsafe impl Pod for InterfaceReg {}

View File

@@ -1,7 +1,7 @@
pub use interface::*;
pub use utl_ts_hash::*;
pub use utl_rb_tree::*;
pub use utl_vector::*;
pub mod interface;
pub mod utl_ts_hash;
pub mod utl_rb_tree;
pub mod utl_vector;

View File

@@ -0,0 +1,27 @@
use memflow::prelude::v1::*;
use crate::source2::SchemaTypeDeclaredClass;
#[repr(C)]
pub struct UtlRbTree {
pad_0000: [u8; 0x8], // 0x0000
pub elements: Pointer64<[UtlRbTreeNode]>, // 0x0008
pad_0010: [u8; 0x8], // 0x0010
pub root: u16, // 0x0018
pub num_elements: u16, // 0x001A
pad_001c: [u8; 0x10], // 0x001C
}
unsafe impl Pod for UtlRbTree {}
#[repr(C)]
pub struct UtlRbTreeNode {
pub left: u16, // 0x0000
pub right: u16, // 0x0002
pub parent: u16, // 0x0004
pub tag: u16, // 0x0006
pad_0008: [u8; 0x4], // 0x0008
pub data: Pointer64<()>, // 0x000A
}
unsafe impl Pod for UtlRbTreeNode {}

View File

@@ -1,102 +0,0 @@
use memflow::prelude::v1::*;
use crate::error::Result;
pub trait HashData: Copy + Sized + Pod {}
impl<T: Copy + Sized + Pod> HashData for T {}
pub trait HashKey: Copy + Sized + Pod {}
impl<K: Copy + Sized + Pod> HashKey for K {}
#[repr(C)]
struct HashFixedDataInternal<T: HashData, K: HashKey> {
ui_key: K,
next: Pointer64<HashFixedDataInternal<T, K>>,
data: T,
}
unsafe impl<T: HashData, K: HashKey> Pod for HashFixedDataInternal<T, K> {}
#[repr(C)]
struct HashBucketDataInternal<T: HashData, K: HashKey> {
data: T,
next: Pointer64<HashFixedDataInternal<T, K>>,
ui_key: K,
}
unsafe impl<T: HashData, K: HashKey> Pod for HashBucketDataInternal<T, K> {}
#[repr(C)]
struct HashAllocatedData<T: HashData, K: HashKey> {
pad_0000: [u8; 0x18],
list: [HashFixedDataInternal<T, K>; 128],
}
unsafe impl<T: HashData, K: HashKey> Pod for HashAllocatedData<T, K> {}
#[repr(C)]
struct HashUnallocatedData<T: HashData, K: HashKey> {
next: Pointer64<HashUnallocatedData<T, K>>,
unk_1: K,
ui_key: K,
unk_2: K,
block_list: [HashBucketDataInternal<T, K>; 256],
}
unsafe impl<T: HashData, K: HashKey> Pod for HashUnallocatedData<T, K> {}
#[repr(C)]
struct HashBucket<T: HashData, K: HashKey> {
pad_0000: [u8; 0x10],
allocated_data: Pointer64<HashAllocatedData<T, K>>,
unallocated_data: Pointer64<HashUnallocatedData<T, K>>,
}
unsafe impl<T: HashData, K: HashKey> Pod for HashBucket<T, K> {}
#[repr(C)]
struct UtlMemoryPool {
block_size: u32,
blocks_per_blob: u32,
grow_mode: u32,
blocks_alloc: u32,
block_alloc_size: u32,
peak_alloc: u32,
}
#[repr(C)]
pub struct UtlTsHash<T: HashData, K: HashKey = u64> {
entry: UtlMemoryPool,
buckets: HashBucket<T, K>,
}
impl<T: HashData, K: HashKey> UtlTsHash<T, K> {
pub fn elements(&self, process: &mut IntoProcessInstanceArcBox<'_>) -> Result<Vec<T>> {
let mut element_ptr = self.buckets.unallocated_data;
let min_size =
(self.entry.blocks_per_blob as usize).min(self.entry.block_alloc_size as usize);
let mut list = Vec::with_capacity(min_size);
while !element_ptr.is_null() {
let element = element_ptr.read(process)?;
for i in 0..min_size {
if list.len() >= self.entry.block_alloc_size as usize {
return Ok(list);
}
list.push(element.block_list[i].data);
}
element_ptr = element.next;
}
Ok(list)
}
}
unsafe impl<T: HashData, K: HashKey> Pod for UtlTsHash<T, K> {}

View File

@@ -6,8 +6,8 @@ use crate::error::{Error, Result};
#[repr(C)]
pub struct UtlVector<T: Copy + Sized + Pod> {
pub size: u32,
pub mem: Pointer64<T>,
pub size: u32, // 0x0000
pub mem: Pointer64<T>, // 0x0008
}
impl<T: Copy + Sized + Pod> UtlVector<T> {