mirror of
https://github.com/a2x/cs2-dumper.git
synced 2025-10-08 15:10:02 +08:00
Simplify some code
This commit is contained in:
@@ -6,8 +6,8 @@ use super::{SchemaMetadataEntryData, SchemaType};
|
||||
#[repr(C)]
|
||||
pub struct SchemaClassFieldData {
|
||||
pub name: Pointer64<ReprCString>, // 0x0000
|
||||
pub schema_type: Pointer64<SchemaType>, // 0x0008
|
||||
pub single_inheritance_offset: i32, // 0x0010
|
||||
pub r#type: Pointer64<SchemaType>, // 0x0008
|
||||
pub offset: i32, // 0x0010
|
||||
pub metadata_count: i32, // 0x0014
|
||||
pub metadata: Pointer64<SchemaMetadataEntryData>, // 0x0018
|
||||
}
|
||||
|
@@ -1,9 +1,6 @@
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use super::{
|
||||
SchemaBaseClassInfoData, SchemaClassFieldData, SchemaMetadataEntryData, SchemaStaticFieldData,
|
||||
SchemaSystemTypeScope, SchemaType,
|
||||
};
|
||||
use super::*;
|
||||
|
||||
pub type SchemaClassBinding = SchemaClassInfoData;
|
||||
|
||||
@@ -28,6 +25,6 @@ pub struct SchemaClassInfoData {
|
||||
pad_0040: [u8; 0x8], // 0x0040
|
||||
pub static_metadata: Pointer64<[SchemaMetadataEntryData]>, // 0x0048
|
||||
pub type_scope: Pointer64<SchemaSystemTypeScope>, // 0x0050
|
||||
pub schema_type: Pointer64<SchemaType>, // 0x0058
|
||||
pub r#type: Pointer64<SchemaType>, // 0x0058
|
||||
pad_0060: [u8; 0x10], // 0x0060
|
||||
}
|
||||
|
@@ -14,11 +14,11 @@ pub struct SchemaEnumInfoData {
|
||||
pub size: u8, // 0x0018
|
||||
pub align_of: u8, // 0x0019
|
||||
pad_001a: [u8; 0x2], // 0x001A
|
||||
pub enumerator_count: u16, // 0x001C
|
||||
pub enum_count: u16, // 0x001C
|
||||
pub static_metadata_count: u16, // 0x001E
|
||||
pub enumerators: Pointer64<[SchemaEnumeratorInfoData]>, // 0x0020
|
||||
pub enums: 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
|
||||
pub min_enum_value: i64, // 0x0038
|
||||
pub max_enum_value: i64, // 0x0040
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ use super::{SchemaMetadataEntryData, SchemaType};
|
||||
#[repr(C)]
|
||||
pub struct SchemaStaticFieldData {
|
||||
pub name: Pointer64<ReprCString>, // 0x0000
|
||||
pub type_: Pointer64<SchemaType>, // 0x0008
|
||||
pub r#type: Pointer64<SchemaType>, // 0x0008
|
||||
pub instance: Pointer64<()>, // 0x0010
|
||||
pub metadata_count: i32, // 0x0018
|
||||
pad_001c: [u8; 0x4], // 0x001C
|
||||
|
@@ -9,10 +9,10 @@ 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; 0x3F0], // 0x0110
|
||||
pub class_bindings: UtlTsHash<Pointer64<SchemaClassBinding>>, // 0x0500
|
||||
pub enum_bindings: UtlTsHash<Pointer64<SchemaEnumBinding>>, // 0x2D90
|
||||
pad_0000: [u8; 0x8], // 0x0000
|
||||
pub name: [c_char; 256], // 0x0008
|
||||
pub global_scope: Pointer64<SchemaSystemTypeScope>, // 0x0108
|
||||
pad_0110: [u8; 0x3F0], // 0x0110
|
||||
pub class_bindings: UtlTsHash<SchemaClassBinding>, // 0x0500
|
||||
pub enum_bindings: UtlTsHash<SchemaEnumBinding>, // 0x2D90
|
||||
}
|
||||
|
@@ -85,7 +85,7 @@ pub struct SchemaType {
|
||||
unsafe impl Pod for SchemaType {}
|
||||
|
||||
pub union SchemaTypeUnion {
|
||||
pub schema_type: Pointer64<SchemaType>,
|
||||
pub r#type: Pointer64<SchemaType>,
|
||||
pub class_binding: Pointer64<SchemaClassBinding>,
|
||||
pub enum_binding: Pointer64<SchemaEnumBinding>,
|
||||
pub array: SchemaArrayT,
|
||||
|
@@ -1,5 +1,3 @@
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
#[repr(C)]
|
||||
@@ -10,26 +8,16 @@ pub struct UtlMemory<T> {
|
||||
}
|
||||
|
||||
impl<T: Pod> UtlMemory<T> {
|
||||
#[inline]
|
||||
pub fn count(&self) -> i32 {
|
||||
self.alloc_count
|
||||
}
|
||||
|
||||
pub fn element(&self, process: &mut IntoProcessInstanceArcBox<'_>, idx: usize) -> Result<T> {
|
||||
if idx >= self.count() as _ {
|
||||
bail!("index out of bounds");
|
||||
}
|
||||
|
||||
process
|
||||
.read_ptr(self.mem.at(idx as _))
|
||||
.data_part()
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_externally_allocated(&self) -> bool {
|
||||
self.grow_size < 0
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: 'static> Pod for UtlMemory<T> {}
|
||||
pub fn element(&self, mem: &mut impl MemoryView, index: usize) -> Result<T> {
|
||||
if index >= self.alloc_count as usize {
|
||||
return Err(ErrorKind::OutOfBounds.into());
|
||||
}
|
||||
|
||||
mem.read_ptr(self.mem.at(index as _)).data_part()
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ pub struct UtlMemoryPoolBase {
|
||||
pub grow_mode: MemoryPoolGrowType, // 0x0008
|
||||
pub blocks_alloc: i32, // 0x000C
|
||||
pub peak_alloc: i32, // 0x0010
|
||||
pub alignment: u16, // 0x0014
|
||||
pub align_of: u16, // 0x0014
|
||||
pub blob_count: u16, // 0x0016
|
||||
pub free_list_tail: Pointer64<Pointer64<FreeList>>, // 0x0018
|
||||
pub free_list_head: Pointer64<FreeList>, // 0x0020
|
||||
@@ -38,10 +38,3 @@ pub struct UtlMemoryPoolBase {
|
||||
pub total_size: i32, // 0x0078
|
||||
pad_007c: [u8; 0x4], // 0x007C
|
||||
}
|
||||
|
||||
impl UtlMemoryPoolBase {
|
||||
#[inline]
|
||||
pub fn size(&self) -> i32 {
|
||||
self.total_size
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,12 @@
|
||||
use anyhow::Result;
|
||||
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use super::UtlMemoryPoolBase;
|
||||
|
||||
use crate::mem::PointerExt;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct HashAllocatedBlob<D> {
|
||||
pub next: Pointer64<HashAllocatedBlob<D>>, // 0x0000
|
||||
pad_0008: [u8; 0x8], // 0x0008
|
||||
pub data: D, // 0x0010
|
||||
pub data: Pointer64<D>, // 0x0010
|
||||
pad_0018: [u8; 0x8], // 0x0018
|
||||
}
|
||||
|
||||
@@ -27,7 +23,7 @@ pub struct HashBucket<D, K> {
|
||||
pub struct HashFixedDataInternal<D, K> {
|
||||
pub ui_key: K, // 0x0000
|
||||
pub next: Pointer64<HashFixedDataInternal<D, K>>, // 0x0008
|
||||
pub data: D, // 0x0010
|
||||
pub data: Pointer64<D>, // 0x0010
|
||||
}
|
||||
|
||||
unsafe impl<D: 'static, K: 'static> Pod for HashFixedDataInternal<D, K> {}
|
||||
@@ -40,11 +36,7 @@ pub struct UtlTsHash<D, const C: usize = 256, K = u64> {
|
||||
pad_2881: [u8; 0xF], // 0x2881
|
||||
}
|
||||
|
||||
impl<D, const C: usize, K> UtlTsHash<D, C, K>
|
||||
where
|
||||
D: Pod + PointerExt,
|
||||
K: Pod,
|
||||
{
|
||||
impl<D: Pod, const C: usize, K: Pod> UtlTsHash<D, C, K> {
|
||||
#[inline]
|
||||
pub fn blocks_alloc(&self) -> i32 {
|
||||
self.entry_mem.blocks_alloc
|
||||
@@ -60,7 +52,7 @@ where
|
||||
self.entry_mem.peak_alloc
|
||||
}
|
||||
|
||||
pub fn elements(&self, process: &mut IntoProcessInstanceArcBox<'_>) -> Result<Vec<D>> {
|
||||
pub fn elements(&self, mem: &mut impl MemoryView) -> Result<Vec<Pointer64<D>>> {
|
||||
let blocks_alloc = self.blocks_alloc() as usize;
|
||||
let peak_alloc = self.peak_count() as usize;
|
||||
|
||||
@@ -71,7 +63,7 @@ where
|
||||
let mut cur_element = bucket.first_uncommitted;
|
||||
|
||||
while !cur_element.is_null() {
|
||||
let element = process.read_ptr(cur_element).data_part()?;
|
||||
let element = mem.read_ptr(cur_element).data_part()?;
|
||||
|
||||
if !element.data.is_null() {
|
||||
allocated_list.push(element.data);
|
||||
@@ -89,7 +81,7 @@ where
|
||||
Pointer64::<HashAllocatedBlob<D>>::from(self.entry_mem.free_list_head.address());
|
||||
|
||||
while !cur_blob.is_null() {
|
||||
let blob = process.read_ptr(cur_blob).data_part()?;
|
||||
let blob = mem.read_ptr(cur_blob).data_part()?;
|
||||
|
||||
if !blob.data.is_null() {
|
||||
unallocated_list.push(blob.data);
|
||||
|
@@ -1,5 +1,3 @@
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
#[repr(C)]
|
||||
@@ -10,20 +8,12 @@ pub struct UtlVector<T> {
|
||||
}
|
||||
|
||||
impl<T: Pod> UtlVector<T> {
|
||||
#[inline]
|
||||
pub fn count(&self) -> i32 {
|
||||
self.size
|
||||
}
|
||||
|
||||
pub fn element(&self, process: &mut IntoProcessInstanceArcBox<'_>, idx: usize) -> Result<T> {
|
||||
if idx >= self.count() as usize {
|
||||
bail!("index out of bounds");
|
||||
pub fn element(&self, mem: &mut impl MemoryView, index: usize) -> Result<T> {
|
||||
if index >= self.size as usize {
|
||||
return Err(ErrorKind::OutOfBounds.into());
|
||||
}
|
||||
|
||||
process
|
||||
.read_ptr(self.mem.at(idx as _))
|
||||
.data_part()
|
||||
.map_err(Into::into)
|
||||
mem.read_ptr(self.mem.at(index as _)).data_part()
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user