mirror of
https://github.com/a2x/cs2-dumper.git
synced 2025-09-18 12:50:01 +08:00
Improve schema parsing
This commit is contained in:
@@ -8,9 +8,9 @@ use pelite::pe64::{Pe, PeView};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use crate::source2::KeyboardKey;
|
||||
use crate::source2::KeyButton;
|
||||
|
||||
/// Represents a key button.
|
||||
/// Represents a keyboard button.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Button {
|
||||
pub name: String,
|
||||
@@ -29,7 +29,7 @@ pub fn buttons(process: &mut IntoProcessInstanceArcBox<'_>) -> Result<Vec<Button
|
||||
.scanner()
|
||||
.finds_code(pattern!("488b15${'} 4885d2 74? 0f1f40"), &mut save)
|
||||
{
|
||||
return Err(Error::Other("unable to find button list signature"));
|
||||
return Err(Error::Other("unable to find button list pattern"));
|
||||
}
|
||||
|
||||
read_buttons(process, &module, module.base + save[1])
|
||||
@@ -42,14 +42,13 @@ fn read_buttons(
|
||||
) -> Result<Vec<Button>> {
|
||||
let mut buttons = Vec::new();
|
||||
|
||||
let mut key_ptr = Pointer64::<KeyboardKey>::from(process.read_addr64(list_addr)?);
|
||||
let mut key_ptr = Pointer64::<KeyButton>::from(process.read_addr64(list_addr)?);
|
||||
|
||||
while !key_ptr.is_null() {
|
||||
let key = key_ptr.read(process)?;
|
||||
let name = key.name.read_string(process)?.to_string();
|
||||
|
||||
let value =
|
||||
((key_ptr.address() - module.base) + offset_of!(KeyboardKey.state) as i64) as u32;
|
||||
let value = ((key_ptr.address() - module.base) + offset_of!(KeyButton.state) as i64) as u32;
|
||||
|
||||
debug!(
|
||||
"found button: {} at {:#X} ({} + {:#X})",
|
||||
|
@@ -54,13 +54,12 @@ fn read_interfaces(
|
||||
) -> Result<Vec<Interface>> {
|
||||
let mut ifaces = Vec::new();
|
||||
|
||||
let mut reg_ptr = Pointer64::<InterfaceReg>::from(process.read_addr64(list_addr)?);
|
||||
let mut cur_reg = Pointer64::<InterfaceReg>::from(process.read_addr64(list_addr)?);
|
||||
|
||||
while !reg_ptr.is_null() {
|
||||
let reg = reg_ptr.read(process)?;
|
||||
while !cur_reg.is_null() {
|
||||
let reg = cur_reg.read(process)?;
|
||||
let name = reg.name.read_string(process)?.to_string();
|
||||
|
||||
let value = (reg.create_fn - module.base) as u32;
|
||||
let value = (reg.create_fn.address() - module.base) as u32;
|
||||
|
||||
debug!(
|
||||
"found interface: {} at {:#X} ({} + {:#X})",
|
||||
@@ -72,7 +71,7 @@ fn read_interfaces(
|
||||
|
||||
ifaces.push(Interface { name, value });
|
||||
|
||||
reg_ptr = reg.next;
|
||||
cur_reg = reg.next;
|
||||
}
|
||||
|
||||
// Sort interfaces by name.
|
||||
|
@@ -128,13 +128,13 @@ pub fn offsets(process: &mut IntoProcessInstanceArcBox<'_>) -> Result<OffsetMap>
|
||||
("matchmaking.dll", matchmaking::offsets),
|
||||
];
|
||||
|
||||
for (module_name, callback) in &modules {
|
||||
for (module_name, offsets) in &modules {
|
||||
let module = process.module_by_name(module_name)?;
|
||||
let buf = process.read_raw(module.base, module.size as _)?;
|
||||
|
||||
let view = PeView::from_bytes(&buf)?;
|
||||
|
||||
map.insert(module_name.to_string(), callback(view));
|
||||
map.insert(module_name.to_string(), offsets(view));
|
||||
}
|
||||
|
||||
Ok(map)
|
||||
|
@@ -17,14 +17,14 @@ use crate::source2::*;
|
||||
|
||||
pub type SchemaMap = BTreeMap<String, (Vec<Class>, Vec<Enum>)>;
|
||||
|
||||
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub enum ClassMetadata {
|
||||
Unknown { name: String },
|
||||
NetworkChangeCallback { name: String },
|
||||
NetworkVarNames { name: String, ty: String },
|
||||
NetworkVarNames { name: String, type_name: String },
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub struct Class {
|
||||
pub name: String,
|
||||
pub module_name: String,
|
||||
@@ -33,14 +33,14 @@ pub struct Class {
|
||||
pub fields: Vec<ClassField>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub struct ClassField {
|
||||
pub name: String,
|
||||
pub ty: String,
|
||||
pub type_name: String,
|
||||
pub offset: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub struct Enum {
|
||||
pub name: String,
|
||||
pub alignment: u8,
|
||||
@@ -48,13 +48,13 @@ pub struct Enum {
|
||||
pub members: Vec<EnumMember>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub struct EnumMember {
|
||||
pub name: String,
|
||||
pub value: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub struct TypeScope {
|
||||
pub name: String,
|
||||
pub classes: Vec<Class>,
|
||||
@@ -120,6 +120,10 @@ fn read_class_binding_fields(
|
||||
process: &mut IntoProcessInstanceArcBox<'_>,
|
||||
binding: &SchemaClassBinding,
|
||||
) -> Result<Vec<ClassField>> {
|
||||
if binding.fields.is_null() {
|
||||
return Err(Error::Other("schema class fields is null"));
|
||||
}
|
||||
|
||||
(0..binding.num_fields)
|
||||
.map(|i| {
|
||||
let field_ptr: Pointer64<SchemaClassFieldData> = binding
|
||||
@@ -131,18 +135,18 @@ fn read_class_binding_fields(
|
||||
let field = field_ptr.read(process)?;
|
||||
|
||||
if field.type_.is_null() {
|
||||
return Err(Error::Other("field schema type is null"));
|
||||
return Err(Error::Other("schema field type is null"));
|
||||
}
|
||||
|
||||
let name = field.name.read_string(process)?.to_string();
|
||||
let type_ = field.type_.read(process)?;
|
||||
|
||||
// TODO: Parse this properly.
|
||||
let ty = type_.name.read_string(process)?.replace(" ", "");
|
||||
let type_name = type_.name.read_string(process)?.replace(" ", "");
|
||||
|
||||
Ok(ClassField {
|
||||
name,
|
||||
ty,
|
||||
type_name,
|
||||
offset: field.offset,
|
||||
})
|
||||
})
|
||||
@@ -154,18 +158,18 @@ fn read_class_binding_metadata(
|
||||
binding: &SchemaClassBinding,
|
||||
) -> Result<Vec<ClassMetadata>> {
|
||||
if binding.static_metadata.is_null() {
|
||||
return Err(Error::Other("class metadata is null"));
|
||||
return Err(Error::Other("schema class metadata is null"));
|
||||
}
|
||||
|
||||
(0..binding.num_static_metadata)
|
||||
.map(|i| {
|
||||
let metadata_ptr: Pointer64<SchemaMetadataEntryData> =
|
||||
binding.static_metadata.offset(i as _).into();
|
||||
let metadata_ptr =
|
||||
Pointer64::<SchemaMetadataEntryData>::from(binding.static_metadata.offset(i as _));
|
||||
|
||||
let metadata = metadata_ptr.read(process)?;
|
||||
|
||||
if metadata.network_value.is_null() {
|
||||
return Err(Error::Other("class metadata network value is null"));
|
||||
return Err(Error::Other("schema class metadata network value is null"));
|
||||
}
|
||||
|
||||
let name = metadata.name.read_string(process)?.to_string();
|
||||
@@ -181,9 +185,9 @@ fn read_class_binding_metadata(
|
||||
let var_value = network_value.u.var_value;
|
||||
|
||||
let name = var_value.name.read_string(process)?.to_string();
|
||||
let ty = var_value.ty.read_string(process)?.replace(" ", "");
|
||||
let type_name = var_value.ty.read_string(process)?.replace(" ", "");
|
||||
|
||||
ClassMetadata::NetworkVarNames { name, ty }
|
||||
ClassMetadata::NetworkVarNames { name, type_name }
|
||||
},
|
||||
_ => ClassMetadata::Unknown { name },
|
||||
};
|
||||
@@ -260,10 +264,10 @@ fn read_schema_system(process: &mut IntoProcessInstanceArcBox<'_>) -> Result<Sch
|
||||
.scanner()
|
||||
.finds_code(pattern!("488905${'} 4c8d45"), &mut save)
|
||||
{
|
||||
return Err(Error::Other("unable to find schema system signature"));
|
||||
return Err(Error::Other("unable to find schema system pattern"));
|
||||
}
|
||||
|
||||
let schema_system: SchemaSystem = process.read(module.base + save[1]).data_part()?;
|
||||
let schema_system: SchemaSystem = process.read(module.base + save[1])?;
|
||||
|
||||
if schema_system.num_registrations == 0 {
|
||||
return Err(Error::Other("no schema system registrations found"));
|
||||
@@ -272,43 +276,6 @@ 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,
|
||||
@@ -317,22 +284,26 @@ fn read_type_scopes(
|
||||
|
||||
(0..type_scopes.size)
|
||||
.map(|i| {
|
||||
let type_scope_ptr = type_scopes.get(process, i as _)?;
|
||||
let type_scope_ptr = type_scopes.element(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 = read_class_bindings(process, type_scope_ptr)?;
|
||||
let enums = read_enum_bindings(process, type_scope_ptr)?;
|
||||
let classes: Vec<_> = type_scope
|
||||
.class_bindings
|
||||
.elements(process)?
|
||||
.iter()
|
||||
.filter_map(|ptr| read_class_binding(process, *ptr).ok())
|
||||
.collect();
|
||||
|
||||
debug!(
|
||||
"found type scope: {} (classes count: {}) (enums count: {})",
|
||||
name,
|
||||
classes.len(),
|
||||
enums.len()
|
||||
);
|
||||
let enums: Vec<_> = type_scope
|
||||
.enum_bindings
|
||||
.elements(process)?
|
||||
.iter()
|
||||
.filter_map(|ptr| read_enum_binding(process, *ptr).ok())
|
||||
.collect();
|
||||
|
||||
Ok(TypeScope {
|
||||
name,
|
||||
|
@@ -17,9 +17,6 @@ pub enum Error {
|
||||
#[error(transparent)]
|
||||
Serde(#[from] serde_json::Error),
|
||||
|
||||
#[error("index {idx} is out of bounds for array with length {len}")]
|
||||
OutOfBounds { idx: usize, len: usize },
|
||||
|
||||
#[error("{0}")]
|
||||
Other(&'static str),
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ use output::Results;
|
||||
|
||||
mod analysis;
|
||||
mod error;
|
||||
mod mem;
|
||||
mod output;
|
||||
mod source2;
|
||||
|
||||
|
13
src/mem.rs
Normal file
13
src/mem.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use memflow::types::Pointer64;
|
||||
|
||||
pub trait IsNull {
|
||||
fn is_null(&self) -> bool;
|
||||
}
|
||||
|
||||
impl<T> IsNull for Pointer64<T> {
|
||||
/// Returns `true` if the pointer is null.
|
||||
#[inline]
|
||||
fn is_null(&self) -> bool {
|
||||
self.inner == 0
|
||||
}
|
||||
}
|
@@ -79,6 +79,7 @@ impl CodeGen for Vec<Button> {
|
||||
fmt.block("pub mod buttons", false, |fmt| {
|
||||
for button in self {
|
||||
let mut name = button.name.clone();
|
||||
|
||||
if name == "use" {
|
||||
name = format!("r#{}", name);
|
||||
}
|
||||
|
@@ -42,16 +42,12 @@ impl<'a> Item<'a> {
|
||||
}
|
||||
|
||||
trait CodeGen {
|
||||
/// Converts an [`Item`] to formatted C# code.
|
||||
fn to_cs(&self, results: &Results, indent_size: usize) -> Result<String>;
|
||||
|
||||
/// Converts an [`Item`] to formatted C++ code.
|
||||
fn to_hpp(&self, results: &Results, indent_size: usize) -> Result<String>;
|
||||
|
||||
/// Converts an [`Item`] to formatted JSON.
|
||||
fn to_json(&self, results: &Results, indent_size: usize) -> Result<String>;
|
||||
|
||||
/// Converts an [`Item`] to formatted Rust code.
|
||||
fn to_rs(&self, results: &Results, indent_size: usize) -> Result<String>;
|
||||
|
||||
#[inline]
|
||||
@@ -126,7 +122,7 @@ pub struct Results {
|
||||
/// Map of offsets to dump.
|
||||
pub offsets: OffsetMap,
|
||||
|
||||
/// Map of schema classes and enums to dump.
|
||||
/// Map of schema classes/enums to dump.
|
||||
pub schemas: SchemaMap,
|
||||
}
|
||||
|
||||
@@ -152,10 +148,8 @@ impl Results {
|
||||
out_dir: P,
|
||||
indent_size: usize,
|
||||
) -> Result<()> {
|
||||
// TODO: Make this user-configurable.
|
||||
const FILE_EXTS: &[&str] = &["cs", "hpp", "json", "rs"];
|
||||
|
||||
// Create the output directory if it doesn't exist.
|
||||
fs::create_dir_all(&out_dir)?;
|
||||
|
||||
let items = [
|
||||
@@ -164,18 +158,12 @@ impl Results {
|
||||
("offsets", Item::Offsets(&self.offsets)),
|
||||
];
|
||||
|
||||
self.dump_items(&items, out_dir.as_ref(), indent_size, FILE_EXTS)?;
|
||||
|
||||
// Write a new file for each module.
|
||||
for (module_name, (classes, enums)) in &self.schemas {
|
||||
let schemas = [(module_name.clone(), (classes.clone(), enums.clone()))].into();
|
||||
|
||||
let item = Item::Schemas(&schemas);
|
||||
|
||||
self.dump_item(&item, out_dir.as_ref(), indent_size, FILE_EXTS, module_name)?;
|
||||
for (file_name, item) in &items {
|
||||
self.dump_item(item, &out_dir, indent_size, FILE_EXTS, file_name)?;
|
||||
}
|
||||
|
||||
self.dump_info_file(process, out_dir)?;
|
||||
self.dump_schemas(&out_dir, indent_size, FILE_EXTS)?;
|
||||
self.dump_info(process, &out_dir)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -194,19 +182,6 @@ impl Results {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn dump_info_file<P: AsRef<Path>>(
|
||||
&self,
|
||||
process: &mut IntoProcessInstanceArcBox<'_>,
|
||||
out_dir: P,
|
||||
) -> Result<()> {
|
||||
let content = &serde_json::to_string_pretty(&json!({
|
||||
"timestamp": self.timestamp.to_rfc3339(),
|
||||
"build_number": self.read_build_number(process).unwrap_or(0),
|
||||
}))?;
|
||||
|
||||
self.dump_file(out_dir.as_ref(), "info", "json", &content)
|
||||
}
|
||||
|
||||
fn dump_item<P: AsRef<Path>>(
|
||||
&self,
|
||||
item: &Item,
|
||||
@@ -218,21 +193,36 @@ impl Results {
|
||||
for ext in file_exts {
|
||||
let content = item.generate(self, indent_size, ext)?;
|
||||
|
||||
self.dump_file(out_dir.as_ref(), file_name, ext, &content)?;
|
||||
self.dump_file(&out_dir, file_name, ext, &content)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn dump_items<P: AsRef<Path>>(
|
||||
fn dump_info<P: AsRef<Path>>(
|
||||
&self,
|
||||
process: &mut IntoProcessInstanceArcBox<'_>,
|
||||
out_dir: P,
|
||||
) -> Result<()> {
|
||||
let content = &serde_json::to_string_pretty(&json!({
|
||||
"timestamp": self.timestamp.to_rfc3339(),
|
||||
"build_number": self.read_build_number(process).unwrap_or(0),
|
||||
}))?;
|
||||
|
||||
self.dump_file(&out_dir, "info", "json", &content)
|
||||
}
|
||||
|
||||
fn dump_schemas<P: AsRef<Path>>(
|
||||
&self,
|
||||
items: &[(&str, Item)],
|
||||
out_dir: P,
|
||||
indent_size: usize,
|
||||
file_exts: &[&str],
|
||||
) -> Result<()> {
|
||||
for (file_name, item) in items {
|
||||
self.dump_item(item, out_dir.as_ref(), indent_size, file_exts, file_name)?;
|
||||
for (module_name, (classes, enums)) in &self.schemas {
|
||||
let map = SchemaMap::from([(module_name.clone(), (classes.clone(), enums.clone()))]);
|
||||
let item = Item::Schemas(&map);
|
||||
|
||||
self.dump_item(&item, &out_dir, indent_size, file_exts, &module_name)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -242,10 +232,10 @@ impl Results {
|
||||
self.offsets
|
||||
.iter()
|
||||
.find_map(|(module_name, offsets)| {
|
||||
let offset = offsets.iter().find(|(name, _)| *name == "dwBuildNumber")?;
|
||||
let (_name, value) = offsets.iter().find(|(name, _)| *name == "dwBuildNumber")?;
|
||||
let module = process.module_by_name(module_name).ok()?;
|
||||
|
||||
process.read(module.base + offset.1).ok()
|
||||
process.read(module.base + value).ok()
|
||||
})
|
||||
.ok_or(Error::Other("unable to read build number"))
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ impl CodeGen for SchemaMap {
|
||||
false,
|
||||
|fmt| {
|
||||
for enum_ in enums {
|
||||
let ty = match enum_.alignment {
|
||||
let type_name = match enum_.alignment {
|
||||
1 => "byte",
|
||||
2 => "ushort",
|
||||
4 => "uint",
|
||||
@@ -47,7 +47,7 @@ impl CodeGen for SchemaMap {
|
||||
&format!(
|
||||
"public enum {} : {}",
|
||||
Self::sanitize_name(&enum_.name),
|
||||
ty
|
||||
type_name
|
||||
),
|
||||
false,
|
||||
|fmt| {
|
||||
@@ -90,7 +90,7 @@ impl CodeGen for SchemaMap {
|
||||
writeln!(
|
||||
fmt,
|
||||
"public const nint {} = {:#X}; // {}",
|
||||
field.name, field.offset, field.ty
|
||||
field.name, field.offset, field.type_name
|
||||
)?;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ impl CodeGen for SchemaMap {
|
||||
false,
|
||||
|fmt| {
|
||||
for enum_ in enums {
|
||||
let ty = match enum_.alignment {
|
||||
let type_name = match enum_.alignment {
|
||||
1 => "uint8_t",
|
||||
2 => "uint16_t",
|
||||
4 => "uint32_t",
|
||||
@@ -151,7 +151,7 @@ impl CodeGen for SchemaMap {
|
||||
&format!(
|
||||
"enum class {} : {}",
|
||||
Self::sanitize_name(&enum_.name),
|
||||
ty
|
||||
type_name
|
||||
),
|
||||
true,
|
||||
|fmt| {
|
||||
@@ -191,7 +191,7 @@ impl CodeGen for SchemaMap {
|
||||
writeln!(
|
||||
fmt,
|
||||
"constexpr std::ptrdiff_t {} = {:#X}; // {}",
|
||||
field.name, field.offset, field.ty
|
||||
field.name, field.offset, field.type_name
|
||||
)?;
|
||||
}
|
||||
|
||||
@@ -236,10 +236,10 @@ impl CodeGen for SchemaMap {
|
||||
"type": "NetworkChangeCallback",
|
||||
"name": name,
|
||||
}),
|
||||
ClassMetadata::NetworkVarNames { name, ty } => json!({
|
||||
ClassMetadata::NetworkVarNames { name, type_name } => json!({
|
||||
"type": "NetworkVarNames",
|
||||
"name": name,
|
||||
"ty": ty,
|
||||
"type_name": type_name,
|
||||
}),
|
||||
ClassMetadata::Unknown { name } => json!({
|
||||
"type": "Unknown",
|
||||
@@ -268,7 +268,7 @@ impl CodeGen for SchemaMap {
|
||||
.map(|member| (&member.name, member.value))
|
||||
.collect();
|
||||
|
||||
let ty = match enum_.alignment {
|
||||
let type_name = match enum_.alignment {
|
||||
1 => "uint8",
|
||||
2 => "uint16",
|
||||
4 => "uint32",
|
||||
@@ -280,7 +280,7 @@ impl CodeGen for SchemaMap {
|
||||
Self::sanitize_name(&enum_.name),
|
||||
json!({
|
||||
"alignment": enum_.alignment,
|
||||
"type": ty,
|
||||
"type": type_name,
|
||||
"members": members,
|
||||
}),
|
||||
)
|
||||
@@ -324,7 +324,7 @@ impl CodeGen for SchemaMap {
|
||||
false,
|
||||
|fmt| {
|
||||
for enum_ in enums {
|
||||
let ty = match enum_.alignment {
|
||||
let type_name = match enum_.alignment {
|
||||
1 => "u8",
|
||||
2 => "u16",
|
||||
4 => "u32",
|
||||
@@ -338,7 +338,7 @@ impl CodeGen for SchemaMap {
|
||||
fmt.block(
|
||||
&format!(
|
||||
"#[repr({})]\npub enum {}",
|
||||
ty,
|
||||
type_name,
|
||||
Self::sanitize_name(&enum_.name),
|
||||
),
|
||||
false,
|
||||
@@ -381,7 +381,7 @@ impl CodeGen for SchemaMap {
|
||||
writeln!(
|
||||
fmt,
|
||||
"pub const {}: usize = {:#X}; // {}",
|
||||
field.name, field.offset, field.ty
|
||||
field.name, field.offset, field.type_name
|
||||
)?;
|
||||
}
|
||||
|
||||
@@ -417,8 +417,8 @@ fn write_metadata(fmt: &mut Formatter<'_>, metadata: &[ClassMetadata]) -> fmt::R
|
||||
ClassMetadata::NetworkChangeCallback { name } => {
|
||||
writeln!(fmt, "// NetworkChangeCallback: {}", name)?;
|
||||
}
|
||||
ClassMetadata::NetworkVarNames { name, ty } => {
|
||||
writeln!(fmt, "// NetworkVarNames: {} ({})", name, ty)?;
|
||||
ClassMetadata::NetworkVarNames { name, type_name } => {
|
||||
writeln!(fmt, "// NetworkVarNames: {} ({})", name, type_name)?;
|
||||
}
|
||||
ClassMetadata::Unknown { name } => {
|
||||
writeln!(fmt, "// {}", name)?;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
/// Represents a keyboard button.
|
||||
#[derive(Pod)]
|
||||
#[repr(C)]
|
||||
pub struct KeyboardKey {
|
||||
pub struct KeyButton {
|
||||
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
|
||||
pub next: Pointer64<KeyButton>, // 0x0088
|
||||
}
|
||||
|
||||
unsafe impl Pod for KeyboardKey {}
|
||||
|
@@ -1,27 +1,242 @@
|
||||
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::*;
|
||||
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::*;
|
||||
use std::ffi::c_char;
|
||||
|
||||
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;
|
||||
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;
|
||||
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: u32, // 0x0000
|
||||
pad_0004: [u8; 0x4], // 0x0004
|
||||
pub prev: Pointer64<SchemaClassInfoData>, // 0x0008
|
||||
}
|
||||
|
||||
#[derive(Pod)]
|
||||
#[repr(C)]
|
||||
pub struct SchemaClassFieldData {
|
||||
pub name: Pointer64<ReprCString>, // 0x0000
|
||||
pub type_: Pointer64<SchemaType>, // 0x0008
|
||||
pub offset: u32, // 0x0010
|
||||
pub num_metadata: u32, // 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: 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: u8, // 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
|
||||
}
|
||||
|
||||
#[derive(Pod)]
|
||||
#[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; 0x10],
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
|
@@ -1,12 +0,0 @@
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use super::SchemaClassInfoData;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct SchemaBaseClassInfoData {
|
||||
pub offset: u32, // 0x0000
|
||||
pad_0004: [u8; 0x4], // 0x0004
|
||||
pub prev: Pointer64<SchemaClassInfoData>, // 0x0008
|
||||
}
|
||||
|
||||
unsafe impl Pod for SchemaBaseClassInfoData {}
|
@@ -1,14 +0,0 @@
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use super::{SchemaMetadataEntryData, SchemaType};
|
||||
|
||||
#[repr(C)]
|
||||
pub struct SchemaClassFieldData {
|
||||
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 {}
|
@@ -1,34 +0,0 @@
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use super::{
|
||||
SchemaBaseClassInfoData, SchemaClassFieldData, SchemaMetadataEntryData, SchemaStaticFieldData,
|
||||
SchemaSystemTypeScope, SchemaType,
|
||||
};
|
||||
|
||||
pub type SchemaClassBinding = SchemaClassInfoData;
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[repr(C)]
|
||||
pub struct SchemaClassInfoData {
|
||||
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 {}
|
@@ -1,21 +0,0 @@
|
||||
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 {}
|
@@ -1,23 +0,0 @@
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use super::{SchemaEnumeratorInfoData, SchemaMetadataEntryData, SchemaSystemTypeScope};
|
||||
|
||||
pub type SchemaEnumBinding = SchemaEnumInfoData;
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[repr(C)]
|
||||
pub struct SchemaEnumInfoData {
|
||||
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 {}
|
@@ -1,21 +0,0 @@
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use super::SchemaMetadataEntryData;
|
||||
|
||||
#[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,
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
use std::ffi::c_char;
|
||||
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct SchemaMetadataEntryData {
|
||||
pub name: Pointer64<ReprCString>, // 0x0000
|
||||
pub network_value: Pointer64<SchemaNetworkValue>, // 0x0008
|
||||
}
|
||||
|
||||
unsafe impl Pod for SchemaMetadataEntryData {}
|
||||
|
||||
#[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(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct SchemaVarName {
|
||||
pub name: Pointer64<ReprCString>, // 0x0000
|
||||
pub ty: Pointer64<ReprCString>, // 0x0008
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use super::SchemaType;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct SchemaStaticFieldData {
|
||||
pub name: Pointer64<ReprCString>, // 0x0000
|
||||
pub type_: Pointer64<SchemaType>, // 0x0008
|
||||
pub instance: Address, // 0x0010
|
||||
pad_0018: [u8; 0x10], // 0x0018
|
||||
}
|
||||
|
||||
unsafe impl Pod for SchemaStaticFieldData {}
|
@@ -1,15 +0,0 @@
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use super::SchemaSystemTypeScope;
|
||||
|
||||
use crate::source2::UtlVector;
|
||||
|
||||
#[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
|
||||
}
|
||||
|
||||
unsafe impl Pod for SchemaSystem {}
|
@@ -1,18 +0,0 @@
|
||||
use std::ffi::c_char;
|
||||
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use super::SchemaDeclaredClassEntry;
|
||||
|
||||
#[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; 0x3C0], // 0x0110
|
||||
pub declared_class: Pointer64<SchemaDeclaredClassEntry>, // 0x04D0
|
||||
pad_04d8: [u8; 0xe], // 0x04D8
|
||||
pub num_declared_classes: u16, // 0x04E6
|
||||
}
|
||||
|
||||
unsafe impl Pod for SchemaSystemTypeScope {}
|
@@ -1,99 +0,0 @@
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use super::{SchemaClassBinding, SchemaEnumBinding, SchemaSystemTypeScope};
|
||||
|
||||
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
#[repr(u8)]
|
||||
pub enum SchemaAtomicCategory {
|
||||
Basic = 0,
|
||||
T,
|
||||
CollectionOfT,
|
||||
TF,
|
||||
TT,
|
||||
TTF,
|
||||
I,
|
||||
None,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
#[repr(u8)]
|
||||
pub enum SchemaTypeCategory {
|
||||
BuiltIn = 0,
|
||||
Ptr,
|
||||
Bitfield,
|
||||
FixedArray,
|
||||
Atomic,
|
||||
DeclaredClass,
|
||||
DeclaredEnum,
|
||||
None,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct SchemaArray {
|
||||
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>, // 0x0000
|
||||
pad_0008: [u8; 0x8], // 0x0008
|
||||
pub template_type: Pointer64<SchemaType>, // 0x0010
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct SchemaAtomicI {
|
||||
pad_0000: [u8; 0x10], // 0x0000
|
||||
pub value: u64, // 0x0010
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct SchemaAtomicTF {
|
||||
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], // 0x0000
|
||||
pub templates: [Pointer64<SchemaType>; 2], // 0x0010
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct SchemaAtomicTTF {
|
||||
pad_0000: [u8; 0x10], // 0x0000
|
||||
pub templates: [Pointer64<SchemaType>; 2], // 0x0010
|
||||
pub size: u32, // 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
|
||||
}
|
||||
|
||||
unsafe impl Pod for SchemaType {}
|
||||
|
||||
#[repr(C)]
|
||||
pub union SchemaTypeUnion {
|
||||
pub schema_type: Pointer64<SchemaType>,
|
||||
pub class_binding: Pointer64<SchemaClassBinding>,
|
||||
pub enum_binding: Pointer64<SchemaEnumBinding>,
|
||||
pub array: SchemaArray,
|
||||
pub atomic: SchemaAtomic,
|
||||
pub atomic_tt: SchemaAtomicTT,
|
||||
pub atomic_tf: SchemaAtomicTF,
|
||||
pub atomic_ttf: SchemaAtomicTTF,
|
||||
pub atomic_i: SchemaAtomicI,
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
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 {}
|
@@ -1,15 +0,0 @@
|
||||
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 {}
|
@@ -1,10 +1,10 @@
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
/// Represents a node in the linked list of exposed interfaces.
|
||||
#[derive(Pod)]
|
||||
#[repr(C)]
|
||||
pub struct InterfaceReg {
|
||||
pub create_fn: Address, // 0x0000
|
||||
pub name: Pointer64<ReprCString>, // 0x0008
|
||||
pub next: Pointer64<InterfaceReg>, // 0x0010
|
||||
pub create_fn: Pointer64<()>,
|
||||
pub name: Pointer64<ReprCString>,
|
||||
pub next: Pointer64<InterfaceReg>,
|
||||
}
|
||||
|
||||
unsafe impl Pod for InterfaceReg {}
|
||||
|
@@ -1,7 +1,11 @@
|
||||
pub use interface::*;
|
||||
pub use utl_rb_tree::*;
|
||||
pub use utl_memory::*;
|
||||
pub use utl_memory_pool::*;
|
||||
pub use utl_ts_hash::*;
|
||||
pub use utl_vector::*;
|
||||
|
||||
pub mod interface;
|
||||
pub mod utl_rb_tree;
|
||||
pub mod utl_memory;
|
||||
pub mod utl_memory_pool;
|
||||
pub mod utl_ts_hash;
|
||||
pub mod utl_vector;
|
||||
|
37
src/source2/tier1/utl_memory.rs
Normal file
37
src/source2/tier1/utl_memory.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
|
||||
/// Represents a growable memory class that doubles in size by default.
|
||||
#[repr(C)]
|
||||
pub struct UtlMemory<T> {
|
||||
pub mem: Pointer64<[T]>, // 0x0000
|
||||
pub alloc_count: i32, // 0x0008
|
||||
pub grow_size: i32, // 0x000C
|
||||
}
|
||||
|
||||
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> {
|
||||
// Check if the index is out of bounds.
|
||||
if idx >= self.count() as usize {
|
||||
return Err(Error::Other("index out of bounds"));
|
||||
}
|
||||
|
||||
self.mem.at(idx as _).read(process).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Returns `true` if the memory is externally allocated.
|
||||
#[inline]
|
||||
pub fn is_externally_allocated(&self) -> bool {
|
||||
self.grow_size < 0
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: 'static> Pod for UtlMemory<T> {}
|
30
src/source2/tier1/utl_memory_pool.rs
Normal file
30
src/source2/tier1/utl_memory_pool.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
/// Represents an optimized pool memory allocator.
|
||||
#[repr(C)]
|
||||
pub struct UtlMemoryPool {
|
||||
pub block_size: i32, // 0x0000
|
||||
pub blocks_per_blob: i32, // 0x0004
|
||||
pub grow_mode: i32, // 0x0008
|
||||
pub blocks_alloc: i32, // 0x000C
|
||||
pub block_alloc_size: i32, // 0x0010
|
||||
pub peak_alloc: i32, // 0x0014
|
||||
}
|
||||
|
||||
impl UtlMemoryPool {
|
||||
/// Returns the size of a block.
|
||||
#[inline]
|
||||
pub fn block_size(&self) -> i32 {
|
||||
self.block_size
|
||||
}
|
||||
|
||||
/// Returns the number of allocated blocks per blob.
|
||||
#[inline]
|
||||
pub fn count(&self) -> i32 {
|
||||
self.blocks_per_blob
|
||||
}
|
||||
|
||||
/// Returns the maximum number of allocated blocks.
|
||||
#[inline]
|
||||
pub fn peak_count(&self) -> i32 {
|
||||
self.peak_alloc
|
||||
}
|
||||
}
|
@@ -1,27 +0,0 @@
|
||||
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 {}
|
96
src/source2/tier1/utl_ts_hash.rs
Normal file
96
src/source2/tier1/utl_ts_hash.rs
Normal file
@@ -0,0 +1,96 @@
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use super::UtlMemoryPool;
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::mem::IsNull;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct HashAllocatedBlob<D> {
|
||||
pub next: Pointer64<HashAllocatedBlob<D>>, // 0x0000
|
||||
pad_0008: [u8; 0x8], // 0x0008
|
||||
pub data: D, // 0x0010
|
||||
pad_0018: [u8; 0x8], // 0x0018
|
||||
}
|
||||
|
||||
unsafe impl<D: 'static> Pod for HashAllocatedBlob<D> {}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct HashBucket<D, K> {
|
||||
pad_0000: [u8; 0x18], // 0x0000,
|
||||
pub first: Pointer64<HashFixedData<D, K>>, // 0x0018
|
||||
pub first_uncommited: Pointer64<HashFixedData<D, K>>, // 0x0020
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct HashFixedData<D, K> {
|
||||
pub ui_key: K, // 0x0000
|
||||
pub next: Pointer64<HashFixedData<D, K>>, // 0x0008
|
||||
pub data: D, // 0x0010
|
||||
}
|
||||
|
||||
unsafe impl<D: 'static, K: 'static> Pod for HashFixedData<D, K> {}
|
||||
|
||||
/// Represents a thread-safe hash table.
|
||||
#[repr(C)]
|
||||
pub struct UtlTsHash<D, const C: usize = 256, K = u64> {
|
||||
pub entry_mem: UtlMemoryPool, // 0x0000
|
||||
pad_0018: [u8; 0x8], // 0x0018
|
||||
pub blobs: Pointer64<HashAllocatedBlob<D>>, // 0x0020
|
||||
pad_0028: [u8; 0x58], // 0x0028
|
||||
pub buckets: [HashBucket<D, K>; C], // 0x0080
|
||||
pad_2880: [u8; 0x10], // 0x2880
|
||||
}
|
||||
|
||||
impl<D: Pod + IsNull, const C: usize, K: Pod> UtlTsHash<D, C, K> {
|
||||
/// Returns all elements in the hash table.
|
||||
pub fn elements(&self, process: &mut IntoProcessInstanceArcBox<'_>) -> Result<Vec<D>> {
|
||||
let mut elements: Vec<_> = self
|
||||
.buckets
|
||||
.iter()
|
||||
.flat_map(|bucket| {
|
||||
let mut element_ptr = bucket.first;
|
||||
|
||||
let mut list = Vec::new();
|
||||
|
||||
while !element_ptr.is_null() {
|
||||
if let Ok(element) = element_ptr.read(process) {
|
||||
if !element.data.is_null() {
|
||||
list.push(element.data);
|
||||
}
|
||||
|
||||
element_ptr = element.next;
|
||||
}
|
||||
}
|
||||
|
||||
list
|
||||
})
|
||||
.collect();
|
||||
|
||||
if let Ok(blob) = self.blobs.read(process) {
|
||||
let mut unallocated_data = blob.next;
|
||||
|
||||
if !unallocated_data.is_null() {
|
||||
if !blob.data.is_null() {
|
||||
elements.push(blob.data);
|
||||
}
|
||||
|
||||
while !unallocated_data.is_null() {
|
||||
if let Ok(element) = unallocated_data.read(process) {
|
||||
if !element.data.is_null() {
|
||||
elements.push(element.data);
|
||||
}
|
||||
|
||||
unallocated_data = element.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Separate allocated and unallocated data.
|
||||
|
||||
Ok(elements)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<D: 'static, const C: usize, K: 'static> Pod for UtlTsHash<D, C, K> {}
|
@@ -1,29 +1,30 @@
|
||||
use std::mem;
|
||||
|
||||
use memflow::prelude::v1::*;
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
|
||||
/// Represents a growable array class that doubles in size by default.
|
||||
#[repr(C)]
|
||||
pub struct UtlVector<T: Copy + Sized + Pod> {
|
||||
pub size: u32, // 0x0000
|
||||
pub mem: Pointer64<T>, // 0x0008
|
||||
pub struct UtlVector<T> {
|
||||
pub size: i32, // 0x0000
|
||||
pub mem: Pointer64<[T]>, // 0x0008
|
||||
}
|
||||
|
||||
impl<T: Copy + Sized + Pod> UtlVector<T> {
|
||||
impl<T: Pod> UtlVector<T> {
|
||||
/// Returns the number of elements in the vector.
|
||||
#[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,
|
||||
});
|
||||
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> {
|
||||
// Check if the index is out of bounds.
|
||||
if idx >= self.count() as usize {
|
||||
return Err(Error::Other("index out of bounds"));
|
||||
}
|
||||
|
||||
let ptr = Pointer64::from(self.mem.address() + (idx * mem::size_of::<T>()));
|
||||
|
||||
Ok(ptr.read(process)?)
|
||||
self.mem.at(idx as _).read(process).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: Copy + Sized + Pod> Pod for UtlVector<T> {}
|
||||
unsafe impl<T: 'static> Pod for UtlVector<T> {}
|
||||
|
Reference in New Issue
Block a user