Skip to content

Commit

Permalink
Proper implementation of the adjustments for the new schema
Browse files Browse the repository at this point in the history
  • Loading branch information
WolverinDEV committed Apr 4, 2024
1 parent 0dae7f7 commit a15b5de
Show file tree
Hide file tree
Showing 8 changed files with 58,029 additions and 147,967 deletions.
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ To access Valthruns settings overlay press `PAUSE`.
# How to use / Getting started
Please follow this guide to get started:
https://wiki.valth.run/getting-started/

# Troubleshooting
If you are having issues mapping the kernel driver or starting the controller, please take a look [here](https://wiki.valth.run/category/troubleshooting):
https://wiki.valth.run/category/troubleshooting
Expand Down
6 changes: 4 additions & 2 deletions controller/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,22 +399,24 @@ enum AppCommand {
#[derive(Debug, Args)]
struct SchemaDumpArgs {
pub target_file: PathBuf,

#[clap(long, short, default_value_t = false)]
pub all_classes: bool,
}

fn is_console_invoked() -> bool {
let console_count = unsafe {
let mut result = [0u32; 128];
GetConsoleProcessList(&mut result)
};

console_count > 1
}

fn main_schema_dump(args: &SchemaDumpArgs) -> anyhow::Result<()> {
log::info!("Dumping schema. Please wait...");

let cs2 = CS2Handle::create(true)?;
let schema = cs2::dump_schema(&cs2, false)?;
let schema = cs2::dump_schema(&cs2, !args.all_classes)?;

let output = File::options()
.create(true)
Expand Down
6 changes: 3 additions & 3 deletions cs2-schema/cutl/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
mod tshash;
pub use tshash::*;

mod vector;
pub use vector::*;

Expand All @@ -9,3 +6,6 @@ pub use string::*;

mod memory;
pub use memory::*;

mod rbtree;
pub use rbtree::*;
102 changes: 102 additions & 0 deletions cs2-schema/cutl/src/rbtree.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
use std::marker::PhantomData;

use cs2_schema_declaration::{
MemoryHandle,
Ptr,
SchemaValue,
};

// UtlRBTree has the following layout:
// pub struct UtlRBTree<T> {
// pub elements: Ptr<[UtlRBTreeNode<T>]> = 0x08,
// pub start_node: i16 = 0x18,
// pub entry_count: u16 = 0x1A,
// }
pub struct UtlRBTree<T> {
memory: MemoryHandle,
_dummy: PhantomData<T>,
}

impl<T> UtlRBTree<T> {
pub fn elements(&self) -> anyhow::Result<Ptr<[UtlRBTreeNode<T>]>> {
self.memory.reference_schema(0x08)
}

pub fn start_node(&self) -> anyhow::Result<u16> {
self.memory.reference_schema(0x18)
}

pub fn entry_count(&self) -> anyhow::Result<u16> {
self.memory.reference_schema(0x1A)
}
}

impl<T: SchemaValue> UtlRBTree<T> {
pub fn value(&self) -> anyhow::Result<T> {
self.memory.reference_schema(0x08)
}
}

impl<T: SchemaValue> SchemaValue for UtlRBTree<T> {
fn value_size() -> Option<u64> {
Some(0x20)
}

fn from_memory(memory: MemoryHandle) -> anyhow::Result<Self> {
Ok(Self {
memory,
_dummy: Default::default(),
})
}
}

/// UtlRBTreeNode has the following layout:
/// struct UtlRBTreeNode<T> {
/// pub left: i16, // 0x0000
/// pub right: i16, // 0x0002
/// pub parent: i16 // 0x0004
/// pub tag: i16, // 0x0006
/// pub value: T // 0x0008
/// }
/// N is most likel 256 (u8) large
pub struct UtlRBTreeNode<T> {
memory: MemoryHandle,
_dummy: PhantomData<T>,
}

impl<T> UtlRBTreeNode<T> {
pub fn left_node(&self) -> anyhow::Result<i16> {
self.memory.reference_schema(0x00)
}

pub fn right_node(&self) -> anyhow::Result<i16> {
self.memory.reference_schema(0x02)
}

pub fn parent_node(&self) -> anyhow::Result<i16> {
self.memory.reference_schema(0x04)
}

pub fn tag(&self) -> anyhow::Result<i16> {
self.memory.reference_schema(0x06)
}
}

impl<T: SchemaValue> UtlRBTreeNode<T> {
pub fn value(&self) -> anyhow::Result<T> {
self.memory.reference_schema(0x08)
}
}

impl<T: SchemaValue> SchemaValue for UtlRBTreeNode<T> {
fn value_size() -> Option<u64> {
Some(T::value_size().expect("T to have a size") + 0x08)
}

fn from_memory(memory: MemoryHandle) -> anyhow::Result<Self> {
Ok(Self {
memory,
_dummy: Default::default(),
})
}
}
176 changes: 0 additions & 176 deletions cs2-schema/cutl/src/tshash.rs

This file was deleted.

Loading

0 comments on commit a15b5de

Please sign in to comment.