mirror of
https://github.com/a2x/cs2-dumper.git
synced 2025-11-05 17:40:03 +08:00
Refactor and move Linux code to separate branch
This commit is contained in:
10
src/source2/tier1/interface.rs
Normal file
10
src/source2/tier1/interface.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct InterfaceReg {
|
||||
pub create_fn: Address,
|
||||
pub name: Pointer64<ReprCString>,
|
||||
pub next: Pointer64<InterfaceReg>,
|
||||
}
|
||||
|
||||
unsafe impl Pod for InterfaceReg {}
|
||||
7
src/source2/tier1/mod.rs
Normal file
7
src/source2/tier1/mod.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
pub use interface::*;
|
||||
pub use utl_ts_hash::*;
|
||||
pub use utl_vector::*;
|
||||
|
||||
pub mod interface;
|
||||
pub mod utl_ts_hash;
|
||||
pub mod utl_vector;
|
||||
102
src/source2/tier1/utl_ts_hash.rs
Normal file
102
src/source2/tier1/utl_ts_hash.rs
Normal file
@@ -0,0 +1,102 @@
|
||||
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> {}
|
||||
29
src/source2/tier1/utl_vector.rs
Normal file
29
src/source2/tier1/utl_vector.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use std::mem;
|
||||
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
|
||||
#[repr(C)]
|
||||
pub struct UtlVector<T: Copy + Sized + Pod> {
|
||||
pub size: u32,
|
||||
pub mem: Pointer64<T>,
|
||||
}
|
||||
|
||||
impl<T: Copy + Sized + Pod> UtlVector<T> {
|
||||
#[inline]
|
||||
pub fn get(&self, process: &mut IntoProcessInstanceArcBox<'_>, idx: usize) -> Result<T> {
|
||||
if idx >= self.size as usize {
|
||||
return Err(Error::OutOfBounds {
|
||||
idx,
|
||||
len: self.size as usize,
|
||||
});
|
||||
}
|
||||
|
||||
let ptr = Pointer64::from(self.mem.address() + (idx * mem::size_of::<T>()));
|
||||
|
||||
Ok(ptr.read(process)?)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: Copy + Sized + Pod> Pod for UtlVector<T> {}
|
||||
Reference in New Issue
Block a user