mirror of
https://github.com/a2x/cs2-dumper.git
synced 2025-10-07 22:50:03 +08:00
Remove redundant doc comments
This commit is contained in:
@@ -1,40 +1,24 @@
|
||||
use super::{generate_files, Entries, Entry};
|
||||
|
||||
use crate::builder::FileBuilderEnum;
|
||||
use crate::util::{Address, Process};
|
||||
use std::ffi::c_char;
|
||||
use std::mem::offset_of;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use simplelog::{debug, info};
|
||||
|
||||
use std::ffi::c_char;
|
||||
use std::mem::offset_of;
|
||||
use super::{generate_files, Entries, Entry};
|
||||
|
||||
use crate::builder::FileBuilderEnum;
|
||||
use crate::util::{Address, Process};
|
||||
|
||||
/// Represents a node in a linked list of interfaces.
|
||||
#[derive(Debug)]
|
||||
#[repr(C)]
|
||||
struct InterfaceNode {
|
||||
/// Used to instantiate an instance of the interface.
|
||||
pub create_fn: *const (),
|
||||
|
||||
/// Pointer to the name of the interface.
|
||||
pub name: *const c_char,
|
||||
|
||||
/// Pointer to the next entry in the linked list.
|
||||
pub next: *mut InterfaceNode,
|
||||
}
|
||||
|
||||
impl InterfaceNode {
|
||||
/// Returns the instance of the interface.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `&self` - A reference to the `InterfaceNode` struct.
|
||||
/// * `process` - A reference to the `Process` struct.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<Address>` - A `Result` containing the instance of the interface if successful, or an error if the memory read fails.
|
||||
fn instance(&self, process: &Process) -> Result<Address> {
|
||||
process
|
||||
.read_memory::<usize>(
|
||||
@@ -43,18 +27,6 @@ impl InterfaceNode {
|
||||
.map(|ptr| ptr.into())
|
||||
}
|
||||
|
||||
/// Returns the name of the interface with the version number appended.
|
||||
///
|
||||
/// E.g. "Source2Client002".
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `&self` - A reference to the `InterfaceNode` struct.
|
||||
/// * `process` - A reference to the `Process` struct.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<String>` - A `Result` containing the name of the interface if successful, or an error if the memory read fails.
|
||||
fn name(&self, process: &Process) -> Result<String> {
|
||||
let name_ptr = process.read_memory::<usize>(
|
||||
(self as *const _ as usize + offset_of!(InterfaceNode, name)).into(),
|
||||
@@ -63,16 +35,6 @@ impl InterfaceNode {
|
||||
process.read_string(name_ptr.into())
|
||||
}
|
||||
|
||||
/// Returns a pointer to the next `InterfaceNode` in the linked list.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `&self` - A reference to the `InterfaceNode` struct.
|
||||
/// * `process` - A reference to the `Process` struct.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<*mut InterfaceNode>` - A `Result` containing a pointer to the next `InterfaceNode` if successful, or an error if the memory read fails.
|
||||
fn next(&self, process: &Process) -> Result<*mut InterfaceNode> {
|
||||
process.read_memory::<*mut InterfaceNode>(
|
||||
(self as *const _ as usize + offset_of!(InterfaceNode, next)).into(),
|
||||
@@ -80,18 +42,6 @@ impl InterfaceNode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Dumps all interfaces and writes the results to a file.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `process` - A reference to the `Process` struct.
|
||||
/// * `builders` - A mutable reference to a vector of `FileBuilderEnum`.
|
||||
/// * `file_path` - A string slice representing the path to the file to write the results to.
|
||||
/// * `indent` - The number of spaces to use for indentation in the output file.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<()>` - A `Result` indicating the outcome of the operation.
|
||||
pub fn dump_interfaces(
|
||||
process: &Process,
|
||||
builders: &mut Vec<FileBuilderEnum>,
|
||||
@@ -100,13 +50,12 @@ pub fn dump_interfaces(
|
||||
) -> Result<()> {
|
||||
let mut entries = Entries::new();
|
||||
|
||||
// Iterate over all modules in the process, excluding crashhandler64.dll.
|
||||
for module in process
|
||||
.modules()?
|
||||
.iter()
|
||||
.filter(|m| m.name != "crashhandler64.dll")
|
||||
{
|
||||
if let Some(create_interface_export) = module.get_export_by_name("CreateInterface") {
|
||||
if let Some(create_interface_export) = module.export_by_name("CreateInterface") {
|
||||
info!("Dumping interfaces in <blue>{}</>...", module.name);
|
||||
|
||||
let create_interface_address =
|
||||
@@ -114,7 +63,6 @@ pub fn dump_interfaces(
|
||||
|
||||
let mut node = process.read_memory::<*mut InterfaceNode>(create_interface_address)?;
|
||||
|
||||
// Iterate over each node in the linked list.
|
||||
while !node.is_null() {
|
||||
let instance = unsafe { (*node).instance(process) }?;
|
||||
let name = unsafe { (*node).name(process) }?;
|
||||
@@ -138,7 +86,6 @@ pub fn dump_interfaces(
|
||||
indent: Some(indent),
|
||||
});
|
||||
|
||||
// Get the next node in the linked list.
|
||||
node = unsafe { (*node).next(process) }?;
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,3 @@
|
||||
use crate::builder::{FileBuilder, FileBuilderEnum};
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use chrono::Utc;
|
||||
|
||||
pub use interfaces::dump_interfaces;
|
||||
pub use offsets::dump_offsets;
|
||||
pub use schemas::dump_schemas;
|
||||
@@ -12,51 +6,32 @@ use std::collections::BTreeMap;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use chrono::Utc;
|
||||
|
||||
use crate::builder::{FileBuilder, FileBuilderEnum};
|
||||
|
||||
pub mod interfaces;
|
||||
pub mod offsets;
|
||||
pub mod schemas;
|
||||
|
||||
/// Represents an entry in the generated file.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Entry {
|
||||
/// The name of the entry.
|
||||
pub name: String,
|
||||
|
||||
/// The value of the entry.
|
||||
pub value: usize,
|
||||
|
||||
/// An optional comment associated with the entry.
|
||||
pub comment: Option<String>,
|
||||
|
||||
/// An optional indentation level for the entry.
|
||||
pub indent: Option<usize>,
|
||||
}
|
||||
|
||||
/// A container for entries, which consists of data and an optional comment.
|
||||
#[derive(Default)]
|
||||
pub struct EntriesContainer {
|
||||
/// The data associated with the container.
|
||||
pub data: Vec<Entry>,
|
||||
|
||||
/// An optional comment associated with the container.
|
||||
pub comment: Option<String>,
|
||||
}
|
||||
|
||||
/// A type alias for a `BTreeMap` that maps `String` keys to `EntriesContainer` values.
|
||||
pub type Entries = BTreeMap<String, EntriesContainer>;
|
||||
|
||||
/// Generates a file using the given `builder`, `entries`, `file_path`, and `file_name`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `builder` - A mutable reference to the `FileBuilderEnum`.
|
||||
/// * `entries` - A reference to the `Entries` struct.
|
||||
/// * `file_path` - A string slice representing the path to the file.
|
||||
/// * `file_name` - A string slice representing the name of the file.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<()>` - A `Result` indicating the outcome of the operation.
|
||||
pub fn generate_file(
|
||||
builder: &mut FileBuilderEnum,
|
||||
entries: &Entries,
|
||||
@@ -96,18 +71,6 @@ pub fn generate_file(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Generate files using the given `builders`, `entries`, `file_path`, and `file_name`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `builders` - A mutable slice of `FileBuilderEnum` objects.
|
||||
/// * `entries` - A reference to the `Entries` struct.
|
||||
/// * `file_path` - A string slice representing the path to the file.
|
||||
/// * `file_name` - A string slice representing the name of the file.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<()>` - A `Result` indicating the outcome of the operation.
|
||||
pub fn generate_files(
|
||||
builders: &mut [FileBuilderEnum],
|
||||
entries: &Entries,
|
||||
@@ -119,16 +82,6 @@ pub fn generate_files(
|
||||
.try_for_each(|builder| generate_file(builder, entries, file_path, file_name))
|
||||
}
|
||||
|
||||
/// Writes the banner to the given file based on the file extension.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `file` - A mutable reference to the file to write the banner to.
|
||||
/// * `file_extension` - A string slice representing the file extension of the file.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<()>` - A `Result` indicating the outcome of the operation.
|
||||
fn write_banner_to_file(file: &mut File, file_extension: &str) -> Result<()> {
|
||||
const REPO_URL: &str = "https://github.com/a2x/cs2-dumper";
|
||||
|
||||
@@ -137,12 +90,12 @@ fn write_banner_to_file(file: &mut File, file_extension: &str) -> Result<()> {
|
||||
let banner = match file_extension {
|
||||
"json" => None,
|
||||
"py" => Some(format!(
|
||||
"'''\nCreated using {}\n{}\n'''\n\n",
|
||||
"'''\nGenerated using {}\n{}\n'''\n\n",
|
||||
REPO_URL, time_now
|
||||
)),
|
||||
"yaml" => None,
|
||||
_ => Some(format!(
|
||||
"/*\n * Created using {}\n * {}\n */\n\n",
|
||||
"/*\n * Generated using {}\n * {}\n */\n\n",
|
||||
REPO_URL, time_now
|
||||
)),
|
||||
};
|
||||
|
@@ -1,3 +1,9 @@
|
||||
use std::fs::File;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use simplelog::{debug, error, info};
|
||||
|
||||
use super::{generate_files, Entries, Entry};
|
||||
|
||||
use crate::builder::FileBuilderEnum;
|
||||
@@ -5,24 +11,6 @@ use crate::config::Config;
|
||||
use crate::config::Operation::*;
|
||||
use crate::util::Process;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use simplelog::{debug, error, info};
|
||||
|
||||
use std::fs::File;
|
||||
|
||||
/// Dumps all offsets specified in the `config.json` file and writes the results to a file.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `process` - A reference to the `Process` struct.
|
||||
/// * `builders` - A mutable reference to a vector of `FileBuilderEnum`.
|
||||
/// * `file_path` - A string slice representing the path to the file to write the results to.
|
||||
/// * `indent` - The number of spaces to use for indentation in the output file.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<()>` - A `Result` indicating the outcome of the operation.
|
||||
pub fn dump_offsets(
|
||||
process: &Process,
|
||||
builders: &mut Vec<FileBuilderEnum>,
|
||||
|
@@ -1,25 +1,13 @@
|
||||
use anyhow::Result;
|
||||
|
||||
use simplelog::{debug, info};
|
||||
|
||||
use super::{generate_files, Entries, Entry};
|
||||
|
||||
use crate::builder::FileBuilderEnum;
|
||||
use crate::sdk::SchemaSystem;
|
||||
use crate::util::Process;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use simplelog::{debug, info};
|
||||
|
||||
/// Dumps all schema system classes and writes the results to a file.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `process` - A reference to the `Process` struct.
|
||||
/// * `builders` - A mutable reference to a vector of `FileBuilderEnum`.
|
||||
/// * `file_path` - A string slice representing the path to the file to write the results to.
|
||||
/// * `indent` - The number of spaces to use for indentation in the output file.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<()>` - A `Result` indicating the outcome of the operation.
|
||||
pub fn dump_schemas(
|
||||
process: &Process,
|
||||
builders: &mut Vec<FileBuilderEnum>,
|
||||
|
Reference in New Issue
Block a user