cs2-dumper

repository·main·Indexed 24 days ago

https://github.com/a2x/cs2-dumper

An external tool for dumping offsets and interfaces from Counter-Strike 2 on Windows and Linux. It leverages the memflow framework for memory reading and can generate output files in C#, C++, Rust, Zig, and JSON formats. The tool includes a CLI for specifying memflow connectors and provides a comprehensive analysis system to extract buttons, interfaces, offsets, and Source 2 schema metadata (classes and enums) from the game process.

Tokens
4K
Snippets
13
Records
20
Agent score
80%

What's inside cs2-dumper

  1. Run cs2-dumper with different memflow connectors

    main

    By default, cs2-dumper uses the memflow-native OS layer to read game memory. However, you can specify alternative memflow connectors (like pcileech or kvm) using the -c or --connector flag. If the connector requires arguments, use the -a or --connector-args flag.

    Important Permissions: Certain connectors require elevated privileges:

    • Linux: Run the executable with sudo (e.g., for the kvm connector).
    • Windows: Run the executable as an Administrator (e.g., for pcileech or winio connectors).

    Connectors can be managed using the memflowup tool.

    cs2-dumper -c pcileech -a :device=FPGA -vv
  2. Get started with cs2-dumper

    main

    To use cs2-dumper, you can either download a pre-compiled release or build it from source.

    Prerequisites:

    • If compiling from source, you must have Rust version 1.74.0 or newer installed.

    Steps:

    1. Download the latest release from the Releases page.
    2. Ensure Counter-Strike 2 is running (being in the main menu is sufficient).
    3. Run the cs2-dumper executable.
    cargo test -- --nocapture
  3. Use the cs2-dumper CLI

    main

    The cs2-dumper CLI tool extracts game data from a running process (defaulting to cs2.exe) using a memflow connector and generates various file formats (C++, C#, Rust, Zig, JSON, etc.).

    Basic Usage

    To run the dumper with default settings (outputting to the output directory), ensure the game process is running and execute the binary:

    cs2-dumper

    Specifying a Connector

    You can specify a specific memflow connector using the --connector flag. If you provide a connector, you can also pass additional arguments to it using --connector-args.

    cs2-dumper --connector <connector_name> --connector-args <args>

    Controlling Output

    You can customize the generated files and their formatting using the following flags:

    • --file-types: A comma-separated list of formats to generate. Defaults to cs,hpp,json,rs,zig.
    • --indent-size: The number of spaces per indentation level. Defaults to 4.
    • --output: The directory where files will be written. Defaults to output.
    • --process-name: The name of the target process. Defaults to cs2.exe.

    Logging and Verbosity

    • -v, --verbose: Increase logging verbosity. This can be used multiple times (e.g., -vv for Info, -vvv for Debug).
    • --no-log-file: Prevents the creation of the cs2-dumper.log file.
  4. Reference the cs2-dumper CLI arguments

    main

    The following arguments are available for the cs2-dumper executable:

    ArgumentLong FlagDescription
    -c--connector <connector>The name of the memflow connector to use.
    -a--connector-args <args>Additional arguments to pass to the memflow connector.
    -f--file-types <types>The types of files to generate. Default: cs, hpp, json, rs, zig.
    -i--indent-size <size>The number of spaces to use per indentation level. Default: 4.
    -o--output <output>The output directory to write the generated files to. Default: output.
    -p--process-name <name>The name of the game process. Default: cs2.exe.
    -v(multiple)Increase logging verbosity.
    -h--helpPrint help.
    -V--versionPrint version.
  5. Extract schema maps using schemas()

    main

    The schemas function is the primary entry point for extracting the game's type system (classes and enums) from a running process. It returns a SchemaMap, which is a mapping where keys are module names (e.g., client.dll) and values are tuples containing a list of Class objects and a list of Enum objects found within that module.

    To use this, you must provide a type that implements the memflow::prelude::v1::Process and MemoryView traits.

  6. Understand the SchemaType structure

    main

    The SchemaType struct is the primary representation of a type within the Source2 schema system. It contains metadata such as the type name, its scope, its category, and a union containing the actual type data.

    To correctly parse a SchemaType, you must first check type_category and atomic_category to determine which field of the SchemaTypeUnion is valid.

    pub struct SchemaType {
        pub name: Pointer64<ReprCString>,
        pub type_scope: Pointer64<SchemaSystemTypeScope>,
        pub type_category: SchemaTypeCategory,
        pub atomic_category: SchemaAtomicCategory,
        pub value: SchemaTypeUnion,
    }
  7. Perform full analysis with analyze_all()

    main
    The analyze_all function performs a comprehensive analysis of the target process, extracting buttons, interfaces, offsets, and schemas. It requires a process object that implements the Process and MemoryView traits from the memflow crate. The function returns an AnalysisResult containing maps for each category of extracted data. If any specific analysis step fails, it logs an error and returns a default value for that specific category rather than failing the entire operation.
  8. Reference the SchemaTypeUnion variants

    main

    The SchemaTypeUnion is a union that holds the specific data for a SchemaType. The valid variant depends on the type_category and atomic_category fields of the parent SchemaType struct.

    Available variants:

    • r#type: Pointer to another SchemaType (for recursive types).
    • class_binding: Pointer to a SchemaClassBinding.
    • enum_binding: Pointer to a SchemaEnumBinding.
    • array: A SchemaArrayT structure.
    • atomic: A SchemaAtomicT structure.
    • atomic_tt: A SchemaAtomicTT structure.
    • atomic_tf: A SchemaAtomicTF structure.
    • atomic_ttf: A SchemaAtomicTTF structure.
    • atomic_i: A SchemaAtomicI structure.
    pub union SchemaTypeUnion {
        pub r#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,
    }
  9. SchemaNetworkValueUnion field definitions

    main

    The SchemaNetworkValueUnion is a C-style union used to store different types of network values within the Source 2 schema. Depending on the context, the union can represent a string pointer, a numeric value, a generic pointer, a variable name, or a fixed-size character array.

    #[repr(C)]
    pub union SchemaNetworkValueUnion {
        pub name_ptr: Pointer64<ReprCString>,
        pub int_value: i32,
        pub float_value: f32,
        pub ptr_value: Pointer64<()>,
        pub var_value: SchemaVarName,
        pub name_value: [c_char; 32],
    }
  10. Reference the SchemaAtomicCategory enumeration

    main

    The SchemaAtomicCategory enum specifies the specific sub-type of an atomic schema element, providing details on how the underlying data is structured (e.g., whether it is a simple type T, a collection CollectionOfT, or a template-based type TTF).

    pub enum SchemaAtomicCategory {
        Basic = 0,
        T,
        CollectionOfT,
        TF,
        TT,
        TTF,
        I,
        None,
    }
  11. Reference the ClassMetadata enum variants

    main

    The ClassMetadata enum provides specialized information extracted from the schema system for certain classes:

    • Unknown { name: String }: A fallback for metadata that doesn't match known patterns.
    • NetworkChangeCallback { name: String }: Indicates a callback for network changes.
    • NetworkVarNames { name: String, type_name: String }: Provides the name and type of a network variable.
    #[derive(Clone, Debug, Deserialize, Serialize)]
    pub enum ClassMetadata {
        Unknown { name: String },
        NetworkChangeCallback { name: String },
        NetworkVarNames { name: String, type_name: String },
    }