> Agent-readable docs index: /llms.txt. Download /docs.zip to grep all markdown files locally.

---
title: Memory
icon: microchip
---

# <ApiPageIcon icon="microchip" />Memory

<Heading level={2} id="memory-1">
  memory

  <ApiTag label="global table" />
</Heading>

Finds game interfaces and searches the memory of loaded modules for byte patterns.

<Warning>
  These functions are for advanced users. They return raw native addresses. If you use a wrong
  pattern or a wrong address, the game will crash. The script must list `ffi` in the requirements
  of its `extension.json`. Without it, these functions are **nil**.
</Warning>

<ApiMembers>
  <ApiMember kind="fn" name="memory.CreateInterface" summary="Returns a game interface that a loaded module exports. Returns **nil** if the module is not loaded or does not export an interface with this name." args="module, interface" sig="[{&#x22;s&#x22;:&#x22;memory.CreateInterface&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;module&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;interface&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;userdata&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#userdata&#x22;},{&#x22;s&#x22;:&#x22;?&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;userdata&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#userdata&#x22;},{&#x22;s&#x22;:&#x22;?&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;module&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The name of a loaded module, for example `engine2.dll`.&#x22;},{&#x22;n&#x22;:&#x22;interface&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The name of the interface, for example `Source2EngineToClient001`.&#x22;}]" nodiscard>
    <ApiNotes>
      Interface names can change after game updates.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="memory.FindPattern" summary="Searches a loaded module for a byte pattern and returns the addresses where it is found. By default, only the first match is returned. If the module is not loaded, nothing is returned." args="module, pattern, find_all?" sig="[{&#x22;s&#x22;:&#x22;memory.FindPattern&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;module&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;pattern&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;[, &#x22;},{&#x22;s&#x22;:&#x22;find_all&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;userdata&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#userdata&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;userdata&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#userdata&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;module&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The name of a loaded module.&#x22;},{&#x22;n&#x22;:&#x22;pattern&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;A byte pattern in IDA style, for example `48 8B ? ?`. Use `?` for a byte that can have any value.&#x22;},{&#x22;n&#x22;:&#x22;find_all&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}],&#x22;d&#x22;:&#x22;Pass `true` to search the whole module and return every match. This is much slower. The default is `false`, which stops at the first match.&#x22;,&#x22;o&#x22;:true}]" returns="[{&#x22;n&#x22;:&#x22;...&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;userdata&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#userdata&#x22;}],&#x22;d&#x22;:&#x22;Each match is a separate return value, in order from the lowest address to the highest. If the pattern is not found, nothing is returned. Use `local results = {memory.FindPattern(module, pattern, true)}` to put all matches in a table.&#x22;}]" nodiscard />

  <ApiMember kind="fn" name="memory.BindVirtual" summary="Creates a Lua function that calls a virtual function of an interface." args="module, interface, index, ...?" sig="[{&#x22;s&#x22;:&#x22;memory.BindVirtual&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;module&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;interface&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;index&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;[, &#x22;},{&#x22;s&#x22;:&#x22;...&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;ffi.ct*&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/ffi#ffi-ct&#x22;},{&#x22;s&#x22;:&#x22;*&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;function&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#function&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;function&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#function&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;module&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The name of a loaded module, for example `client.dll`.&#x22;},{&#x22;n&#x22;:&#x22;interface&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The name of the interface, for example `Source2EngineToClient001`.&#x22;},{&#x22;n&#x22;:&#x22;index&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],&#x22;d&#x22;:&#x22;The slot index of the function in the virtual table.&#x22;},{&#x22;n&#x22;:&#x22;...&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;ffi.ct*&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/ffi#ffi-ct&#x22;},{&#x22;s&#x22;:&#x22;*&#x22;}],&#x22;d&#x22;:&#x22;The C type of the function, given as the arguments that `ffi.typeof` takes. This is a declaration string, which can be followed by values for its `$` parameters.&#x22;,&#x22;o&#x22;:true}]" nodiscard>
    <ApiNotes>
      The function finds `interface` in `module`, reads the function pointer at slot `index` of the
      virtual table of the interface, and casts it to the given C type. The interface instance is
      stored in the returned function, so you do not pass the `this` pointer when you call it.

      Throws an error if the interface is not found or the C type is not valid. The slot index and
      the C type must match the interface in the loaded module.

      This function exists only in scripts that have access to `ffi`.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="memory.VirtualThunk" summary="Creates a Lua function that calls a virtual function on any instance that you pass to it." args="index, ...?" sig="[{&#x22;s&#x22;:&#x22;memory.VirtualThunk&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;index&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;[, &#x22;},{&#x22;s&#x22;:&#x22;...&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;ffi.ct*&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/ffi#ffi-ct&#x22;},{&#x22;s&#x22;:&#x22;*&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;function&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#function&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;function&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#function&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;index&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],&#x22;d&#x22;:&#x22;The slot index of the function in the virtual table.&#x22;},{&#x22;n&#x22;:&#x22;...&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;ffi.ct*&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/ffi#ffi-ct&#x22;},{&#x22;s&#x22;:&#x22;*&#x22;}],&#x22;d&#x22;:&#x22;The C type of the function, given as the arguments that `ffi.typeof` takes. This is a declaration string, which can be followed by values for its `$` parameters.&#x22;,&#x22;o&#x22;:true}]" nodiscard>
    <ApiNotes>
      The returned function takes the instance pointer as its first argument. When you call it, it
      reads slot `index` of the virtual table of that instance. You can use it with every object
      that has the same virtual table layout. `memory.BindVirtual` instead stores one instance in
      the returned function.

      Throws an error if the C type is not valid. The returned function throws an error if the
      instance is nil or a null pointer. The slot index and the C type must match every instance
      that you pass.

      This function exists only in scripts that have access to `ffi`.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="memory.BindPattern" summary="Creates a Lua function that calls a function found by an IDA style byte pattern." args="module, interface, signature, ...?" sig="[{&#x22;s&#x22;:&#x22;memory.BindPattern&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;module&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;interface&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;signature&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;[, &#x22;},{&#x22;s&#x22;:&#x22;...&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;ffi.ct*&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/ffi#ffi-ct&#x22;},{&#x22;s&#x22;:&#x22;*&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;function&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#function&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;function&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#function&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;module&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The name of a loaded module, for example `client.dll`.&#x22;},{&#x22;n&#x22;:&#x22;interface&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The name of the interface, for example `Source2EngineToClient001`.&#x22;},{&#x22;n&#x22;:&#x22;signature&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;An IDA style byte pattern with `?` wildcards, for example `48 8B ? ?`.&#x22;},{&#x22;n&#x22;:&#x22;...&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;ffi.ct*&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/ffi#ffi-ct&#x22;},{&#x22;s&#x22;:&#x22;*&#x22;}],&#x22;d&#x22;:&#x22;The C type of the function, given as the arguments that `ffi.typeof` takes. This is a declaration string, which can be followed by values for its `$` parameters.&#x22;,&#x22;o&#x22;:true}]" nodiscard>
    <ApiNotes>
      The function finds `interface` in `module` to get the instance. Then it searches `module` for
      `signature` to find the address of the function and casts that address to the given C type.
      The interface instance is stored in the returned function and is passed as the first argument
      when you call it.

      Throws an error if the interface is not found, the pattern is not found, or the C type is not
      valid. The pattern and the C type must match the function in the loaded module.

      This function exists only in scripts that have access to `ffi`.
    </ApiNotes>
  </ApiMember>
</ApiMembers>
