Counter-Strike 2

Functions for accessing game data, entities, bone positions, and game interfaces.

trace.cast

Signature: trace.cast(startx, starty, startz, endx, endy, endz)

Description: Performs a raycast from the start point to the end point, checking for collisions.

Parameters:

  • startx (number): X coordinate of the start point

  • starty (number): Y coordinate of the start point

  • startz (number): Z coordinate of the start point

  • endx (number): X coordinate of the end point

  • endy (number): Y coordinate of the end point

  • endz (number): Z coordinate of the end point

Returns:

  • boolean: true if the endpoint is hit/visible, false otherwise

Example:

local start_x, start_y, start_z = 100, 100, 100  -- Start position
local end_x, end_y, end_z = 200, 200, 200        -- End position

local hit = trace.cast(start_x, start_y, start_z, end_x, end_y, end_z)

if hit then
    engine.log("Line of sight exists between the points", 0, 255, 0, 255)
else
    engine.log("Line of sight is blocked", 255, 0, 0, 255)
end

cs2.get_interface

Signature: cs2.get_interface(module_name, interface_name)

Description: Retrieves a pointer to a game interface by name.

Parameters:

  • module_name (string): Name of the module containing the interface

  • interface_name (string): Name of the interface

Returns:

  • integer: Pointer to the requested interface

Example:

local client_interface = cs2.get_interface("client.dll", "VClient018")

if client_interface == 0 then
    engine.log("Failed to retrieve client interface", 255, 0, 0, 255)
    return
end

engine.log("Client interface: 0x" .. string.format("%X", client_interface), 0, 255, 0, 255)

cs2.get_cvar

Signature: cs2.get_cvar(cvar_name)

Description: Retrieves a pointer to a console variable (cvar) by name.

Parameters:

  • cvar_name (string): Name of the console variable

Returns:

  • integer: Pointer to the requested cvar

Example:

local sv_cheats = cs2.get_cvar("sv_cheats")

if sv_cheats == 0 then
    engine.log("Failed to retrieve sv_cheats cvar", 255, 0, 0, 255)
    return
end

engine.log("sv_cheats cvar: 0x" .. string.format("%X", sv_cheats), 0, 255, 0, 255)

cs2.get_entity_list

Signature: cs2.get_entity_list()

Description: Returns a pointer to the entity list.

Parameters: None

Returns:

  • integer: Pointer to the entity list

Example:

local entity_list = cs2.get_entity_list()

if entity_list == 0 then
    engine.log("Failed to retrieve entity list", 255, 0, 0, 255)
    return
end

engine.log("Entity list: 0x" .. string.format("%X", entity_list), 0, 255, 0, 255)

cs2.get_entity_system

Signature: cs2.get_entity_system()

Description: Returns a pointer to the entity system.

Parameters: None

Returns:

  • integer: Pointer to the entity system

Example:

local entity_system = cs2.get_entity_system()

if entity_system == 0 then
    engine.log("Failed to retrieve entity system", 255, 0, 0, 255)
    return
end

engine.log("Entity system: 0x" .. string.format("%X", entity_system), 0, 255, 0, 255)

cs2.get_highest_entity_index

Signature: cs2.get_highest_entity_index()

Description: Returns the highest entity index currently in use.

Parameters: None

Returns:

  • integer: The highest entity index

Example:

local highest_index = cs2.get_highest_entity_index()
engine.log("Highest entity index: " .. highest_index, 0, 255, 0, 255)

cs2.get_global_vars

Signature: cs2.get_global_vars()

Description: Returns a pointer to the global variables.

Parameters: None

Returns:

  • integer: Pointer to the global variables

Example:

local global_vars = cs2.get_global_vars()

if global_vars == 0 then
    engine.log("Failed to retrieve global vars", 255, 0, 0, 255)
    return
end

engine.log("Global vars: 0x" .. string.format("%X", global_vars), 0, 255, 0, 255)

cs2.get_game_rules

Signature: cs2.get_game_rules()

Description: Returns a pointer to the game rules.

Parameters: None

Returns:

  • integer: Pointer to the game rules

Example:

local game_rules = cs2.get_game_rules()

if game_rules == 0 then
    engine.log("Failed to retrieve game rules", 255, 0, 0, 255)
    return
end

engine.log("Game rules: 0x" .. string.format("%X", game_rules), 0, 255, 0, 255)

cs2.get_planted_c4

Signature: cs2.get_planted_c4()

Description: Returns a pointer to the planted C4 bomb, if one exists.

Parameters: None

Returns:

  • integer: Pointer to the planted C4 bomb, or 0 if no bomb is planted

Example:

local c4 = cs2.get_planted_c4()

if c4 == 0 then
    engine.log("No C4 is currently planted", 255, 255, 0, 255)
    return
end

engine.log("Planted C4: 0x" .. string.format("%X", c4), 0, 255, 0, 255)

cs2.get_view_matrix

Signature: cs2.get_view_matrix()

Description: Returns a pointer to the view matrix, which can be used for world-to-screen transformations.

Parameters: None

Returns:

  • integer: Pointer to the view matrix

Example:

local view_matrix = cs2.get_view_matrix()

if view_matrix == 0 then
    engine.log("Failed to retrieve view matrix", 255, 0, 0, 255)
    return
end

engine.log("View matrix: 0x" .. string.format("%X", view_matrix), 0, 255, 0, 255)

cs2.world_to_screen

Signature: cs2.world_to_screen(x, y, z)

Description: Converts 3D world coordinates to 2D screen coordinates.

Parameters:

  • x (number): X coordinate in world space

  • y (number): Y coordinate in world space

  • z (number): Z coordinate in world space

Returns:

  • x (number): X coordinate in screen space

  • y (number): Y coordinate in screen space

Returns nil if the conversion fails (e.g., if the point is behind the camera).

Example:

local world_x, world_y, world_z = 100, 200, 300
local screen_x, screen_y = cs2.world_to_screen(world_x, world_y, world_z)

if screen_x and screen_y then
    engine.log("World (" .. world_x .. ", " .. world_y .. ", " .. world_z .. ") -> Screen (" .. screen_x .. ", " .. screen_y .. ")", 0, 255, 0, 255)
    
    -- Draw a marker at the screen position
    render.draw_circle(screen_x, screen_y, 5, 255, 0, 0, 255, 1, true)
else
    engine.log("Point is not visible on screen", 255, 0, 0, 255)
end

cs2.get_bone_position

Signature: cs2.get_bone_position(bone_array, bone_id)

Description: Returns the world position of the specified bone.

Parameters:

  • bone_array (integer): Pointer to the bone array

  • bone_id (integer): ID of the bone to get the position of

Returns:

  • x (number): X coordinate of the bone in world space

  • y (number): Y coordinate of the bone in world space

  • z (number): Z coordinate of the bone in world space

Returns nil if the function fails.

Example:

local local_player = cs2.get_local_player()

if not local_player or local_player.bone_array == 0 then
    engine.log("Local player bone array not available", 255, 0, 0, 255)
    return
end

-- Head bone ID is typically 6 in CS2
local head_bone_id = 6
local head_x, head_y, head_z = cs2.get_bone_position(local_player.bone_array, head_bone_id)

if head_x then
    engine.log("Head position: (" .. head_x .. ", " .. head_y .. ", " .. head_z .. ")", 0, 255, 0, 255)
    
    -- Convert to screen coordinates
    local screen_x, screen_y = cs2.world_to_screen(head_x, head_y, head_z)
    if screen_x and screen_y then
        render.draw_circle(screen_x, screen_y, 5, 255, 0, 0, 255, 1, true)
    end
else
    engine.log("Failed to get head bone position", 255, 0, 0, 255)
end

cs2.get_player_list

Signature: cs2.get_player_list()

Description: Returns a table containing information about all players in the game.

Parameters: None

Returns:

  • table: A table of player data, where each entry contains:

    • controller (integer): Pointer to the player's controller

    • pawn (integer): Pointer to the player's pawn

    • clipping_weapon (integer): Pointer to the player's current weapon

    • bone_array (integer): Pointer to the player's bone array

    • is_teammate (boolean): Whether the player is on the same team as the local player

Returns nil if the player list is not available.

Example:

local players = cs2.get_player_list()

if players == nil then
    engine.log("No player list found.", 255, 0, 0, 255)
    return
end

for index, player in pairs(players) do
    engine.log("Player " .. index, 255, 255, 0, 255)
    engine.log("  controller = 0x" .. string.format("%X", player.controller), 200, 200, 200, 255)
    engine.log("  pawn = 0x" .. string.format("%X", player.pawn), 200, 200, 200, 255)
    engine.log("  is_teammate = " .. tostring(player.is_teammate), 200, 200, 200, 255)
    
    -- Skip drawing for teammates if desired
    if not player.is_teammate and player.bone_array ~= 0 then
        -- Example: Draw head ESP
        local head_x, head_y, head_z = cs2.get_bone_position(player.bone_array, 6) -- Head bone
        if head_x then
            local screen_x, screen_y = cs2.world_to_screen(head_x, head_y, head_z)
            if screen_x and screen_y then
                render.draw_circle(screen_x, screen_y, 5, 255, 0, 0, 255, 1, true)
            end
        end
    end
end

cs2.get_local_player

Signature: cs2.get_local_player()

Description: Returns information about the local player.

Parameters: None

Returns:

  • table: A table containing the following fields:

    • controller (integer): Pointer to the local player's controller

    • pawn (integer): Pointer to the local player's pawn

    • clipping_weapon (integer): Pointer to the local player's current weapon

    • bone_array (integer): Pointer to the local player's bone array

Returns nil if the local player information is not available.

Example:

local local_player = cs2.get_local_player()

if local_player == nil then
    engine.log("Local player not available.", 255, 0, 0, 255)
    return
end

engine.log("Local Player Info", 0, 255, 0, 255)
engine.log("  controller = 0x" .. string.format("%X", local_player.controller), 200, 200, 200, 255)
engine.log("  pawn = 0x" .. string.format("%X", local_player.pawn), 200, 200, 200, 255)
engine.log("  clipping_weapon = 0x" .. string.format("%X", local_player.clipping_weapon), 200, 200, 200, 255)
engine.log("  bone_array = 0x" .. string.format("%X", local_player.bone_array), 200, 200, 200, 255)

cs2.get_schema_dump

Signature: cs2.get_schema_dump()

Description: Returns a table containing the dumped schema fields for Counter-Strike 2. Each entry in the table includes the field name and associated memory offset.

Parameters: None

Returns:

  • table: A table of schema fields with the following structure:

    {
        [1] = { name = "CCSPlayer_MovementServices::m_bInStuckTest", offset = 0x25A },
        [2] = { name = "CCSPlayer_MovementServices::m_flStuckCheckTime", offset = 0x268 },
        [3] = { name = "CCSPlayer_MovementServices::m_nTraceCount", offset = 0x468 },
        ...
    }

Returns nil if no schema dump is available (e.g., if the process is not attached).

Example:

-- Basic usage
local dump = cs2.get_schema_dump()

if dump == nil then
    engine.log("Schema dump not available.", 255, 0, 0, 255)
    return
end

engine.log("Schema dump contains " .. #dump .. " entries", 0, 255, 0, 255)

-- Print the first 5 entries as a sample
for i = 1, 5 do
    if dump[i] then
        engine.log(string.format("%s = 0x%X", dump[i].name, dump[i].offset), 0, 255, 0, 255)
    end
end

-- Save to file
local dump = cs2.get_schema_dump()

if dump == nil then
    engine.log("No schema dump available or process not attached.", 255, 0, 0, 255)
    return
end

local lines = {}

for i, entry in ipairs(dump) do
    table.insert(lines, string.format("%s = 0x%X", entry.name, entry.offset))
end

local text = table.concat(lines, "\n")

fs.write_to_file("offset_dump.txt", text)
engine.log("Offset dump written to offset_dump.txt", 0, 255, 0, 255)

Last updated

Was this helpful?