GameSense Documentation

website·Indexed 31 days ago

https://docs.gamesense.gs/

Developer documentation for GameSense, featuring a comprehensive library of source events (such as player_death, player_spawn, and game_newmap), FFI snippets including a Trampoline Hooking Library and Material System Adapter, and rendering utilities for 2D and 3D shapes.

Tokens
69.9K
Snippets
565
Records
741
Agent score
52%

What's inside GameSense

  1. Overview of GameSense API namespaces

    The GameSense API organizes its functions into namespaces based on their utility. Key namespaces include:

    • client: General game and cheat-related functions.
    • config: GameSense configuration management.
    • cvar: Utilities for interacting with game console variables (cvars).
    • database: Persistent storage engine for saving values across reloads and injects.
    • entity: Interaction with game entities.
    • globals: Access to game and cheat-related global variables.
    • json: JSON data utilities (based on lua-cjson).
    • materialsystem: Control over the game's material system (modulation, swapping, removing, and setting).
    • panorama: Interaction with the game engine's Panorama UI.
    • plist: Interaction with the player list.
    • renderer: Drawing and visual interaction functions.
    • ui: Interfacing with the GameSense user interface.
    • vector: Built-in vector library.
    • bit: LuaJIT library for bitwise operations.
    • Global Functions: API functions that do not belong to a specific namespace.
  2. Access GPU adapter information using the Material System Adapter

    Use this snippet to retrieve hardware details about the current render adapter (GPU) by interfacing with materialsystem.dll. It defines the RenderAdapterInfo_t structure and provides helper functions to fetch the current adapter and its associated metadata, such as driver name, vendor ID, and device ID.
    local ffi = require "ffi"
    
    local RenderAdapterInfo_t = ffi.typeof([[
        struct {
            char __m_pDriverName[512];
            unsigned int __m_VendorID;
            unsigned int __m_DeviceID;
            unsigned int __m_SubSysID;
            unsigned int __m_Revision;
            int __m_nDXSupportLevel;
            int __m_nMinDXSupportLevel;
            int __m_nMaxDXSupportLevel;
            unsigned int __m_nDriverVersionHigh;
            unsigned int __m_nDriverVersionLow;
            int64_t pad_0;
        }
    ]])
    
    local RenderAdapterInfo_mt = { __index = {} }
    
    local native_GetCurrentAdapter = vtable_bind("materialsystem.dll", "VMaterialSystem080", 25, "int(__thiscall*)(void*)")
    local native_GetAdapterInfo = vtable_bind("materialsystem.dll", "VMaterialSystem080", 26, "void(__thiscall*)(void*, int, $*)", RenderAdapterInfo_t)
    
    function get_current_adapter()
        return native_GetCurrentAdapter()
    end
    
    local fallback = {
        drivername = function(self) return ffi.string(self.__m_pDriverName) end,
        vendorid = function(self) return string.match(tostring(self.__m_VendorID), "%d+") end,
        deviceid = function(self) return string.match(tostring(self.__m_DeviceID), "%d+") end,
        subsysid = function(self) return string.match(tostring(self.__m_SubSysID), "%d+") end,
        revision = function(self) return string.match(tostring(self.__m_Revision), "%d+") end
    }
    
    function RenderAdapterInfo_mt:__index(index)
        local fallback_fn = fallback[index]
        if not fallback_fn then return nil end
    
        return fallback[index](self)
    end
    
    ffi.metatype(RenderAdapterInfo_t, RenderAdapterInfo_mt)
    
    function get_adapter_info(adapter)
        local info = RenderAdapterInfo_t()
        native_GetAdapterInfo(adapter, info)
    
        return info
    end
  3. Handle the enter_buyzone event in CS:GO

    The enter_buyzone event is triggered when a player enters the buy zone. It provides information about the player and whether they are permitted to purchase items.

    Arguments:

    • userid (short): The ID of the user entering the buy zone.
    • canbuy (bool): Whether the player is allowed to buy items.
  4. Handle the player\team event

    The player\team event is triggered whenever a player changes their team on the server. It provides details about the user, the new and old team IDs, and specific flags for disconnects or automatic assignments.

    Arguments:

    • userid (short): The user ID of the player on the server.
    • team (byte): The ID of the new team.
    • oldteam (byte): The ID of the previous team.
    • disconnect (bool): True if the team change occurred because the player disconnected.
    • autoteam (bool): True if the player was automatically assigned to the team (Observer only).
    • silent (bool): True if the team join message is suppressed (Observer only).
    • name (string): The name of the player (Observer only).
  5. Handle the player_blind event in CS:GO

    The player_blind event is triggered every time a player is blinded by a flashbang. It provides details about the blinded player, the attacker who threw the flashbang, the specific flashbang entity, and the duration of the blindness.

    Arguments:

    • userid (short): The ID of the player who was blinded.
    • attacker (short): The user ID of the player who threw the flashbang.
    • entityid (short): The ID of the flashbang entity that detonated.
    • blind_duration (float): The duration of the blindness effect.
  6. Handle the CS:GO round_end event

    The round_end event is triggered when a round concludes. It provides details about the winner, the reason for the round ending, and player statistics.

    Arguments:

    • winner (byte): The ID of the winning team or user.
    • reason (byte): The reason why the team won.
    • message (string): The end-of-round message.
    • legacy (byte): Server-generated legacy value.
    • player_count (short): Total number of players alive at the end of the round (used for statistics).
    • nomusic (byte): If set, suppresses the round-end music because action is still ongoing.
  7. Store and retrieve persistent data using the database API

    The database API provides persistent storage for Lua values, including tables, which allows data to be maintained between script or cheat reloads. To optimize performance, avoid calling database.write frequently; the recommended pattern is to call database.read during script load and database.write during the 'shutdown' event.
  8. Handle the aim_hit event

    The aim_hit event is fired whenever the rage aimbot successfully hits a player. It provides detailed information about the shot, including the target player, the hitgroup, the damage dealt, and the shot ID (which matches the corresponding aim_fire event).
    local hitgroup_names = {"generic", "head", "chest", "stomach", "left arm", "right arm", "left leg", "right leg", "neck", "?", "gear"}
    
    local function aim_hit(e)
        local group = hitgroup_names[e.hitgroup + 1] or "?"
    
        print(string.format(
            "Hit %s in the %s for %d damage (%d health remaining)",
            entity.get_player_name(e.target), group, e.damage,
            entity.get_prop(e.target, "m_iHealth")
        ))
    end
    
    client.set_event_callback("aim_hit", aim_hit)
  9. Use the math library for common mathematical operations

    The math library is a standard library providing common mathematical functions for numbers. It includes utilities for absolute values, rounding, trigonometry, and power/root calculations.
  10. Understand FFI in GameSense

    Foreign Function Interface (FFI) allows Lua to interact with low-level languages like C/C++. In GameSense, FFI is primarily used to interface directly with the CS:GO process memory. This enables developers to call game functions and access memory without relying solely on the provided Lua API middleman. Using FFI requires an understanding of low-level memory management and C-style pointers.
  11. Handle the other_death event in CS:GO

    The other_death event is triggered when a non-player entity (such as a chicken) dies. It provides details about the attacker, the weapon used, and specific kill conditions like headshots or flashbang blindness.

    Event Arguments

    TypeNameDescription
    shortotheridID of the entity that died
    stringothertypeType of the entity that died
    shortattackerUser ID of the attacker
    stringweaponName of the weapon used (if not the world)
    stringweapon_itemidInventory item ID of the weapon used
    stringweapon_fauxitemidFaux item ID of the weapon used
    stringweapon_originalowner_xuidXUID of the original owner of the weapon
    boolheadshotTrue if the kill was a headshot
    shortpenetratedNumber of objects penetrated before killing target
    boolnoscopeTrue if the kill happened without a scope
    boolthrusmokeTrue if a hitscan weapon went through a smoke grenade
    boolattackerblindTrue if the attacker was blind from a flashbang
  12. Handle the show_freezepanel event in CS:GO

    The show_freezepanel event is triggered when the freeze panel is displayed. It provides detailed information about the victim, the killer, and the combat statistics associated with the kill.

    Arguments for show_freezepanel:

    • victim (short): endindex of the one who was killed
    • killer (short): entindex of the killer entity
    • hits_taken (short): Number of hits the victim took
    • damage_taken (short): Total damage the victim took
    • hits_given (short): Number of hits the killer dealt
    • damage_given (short): Total damage the killer dealt