> For the complete documentation index, see [llms.txt](https://docs.gamesense.biz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gamesense.biz/pt-br/api-reference/il2cpp.md).

# IL2CPP

Acesso a objetos e classes do jogo.

O módulo `il2cpp` permite acessar classes e objetos do jogo que estejam disponíveis.

As operações IL2CPP devem ocorrer dentro de **`on_update`**. O módulo não fica disponível durante o carregamento inicial do script nem em `on_paint`.

## il2cpp.available

`il2cpp.available(): boolean`

Verifica se o acesso a IL2CPP está disponível no momento.

```lua
register_callback("on_update", function()
    if not il2cpp.available() then return end

    local avatar = il2cpp.root("local_avatar")
    if avatar and avatar:valid() then
        local class_name = avatar:class():name()
    end
end)
```

## il2cpp.root

`il2cpp.root(name: string): il2cpp_object | nil`

Retorna um objeto registrado pelo nome ou `nil` caso não esteja disponível.

Root disponível: `"local_avatar"`.

## il2cpp.find\_class

`il2cpp.find_class(name: string): il2cpp_class | nil`

Procura uma classe pelo nome. Retorna `nil` caso não seja encontrada.

## Métodos de il2cpp\_object

| Método                            | Descrição                      |
| --------------------------------- | ------------------------------ |
| `:valid(): boolean`               | Verifica se o objeto é válido  |
| `:class(): il2cpp_class`          | Retorna a classe do objeto     |
| `:get(field: string): any`        | Lê um campo                    |
| `:set(field: string, value: any)` | Altera um campo                |
| `:call(method: string, ...): any` | Executa um método de instância |

## Métodos de il2cpp\_class

| Método                                 | Descrição                         |
| -------------------------------------- | --------------------------------- |
| `:name(): string`                      | Nome da classe                    |
| `:namespace(): string`                 | Namespace                         |
| `:fields(): table`                     | Campos disponíveis                |
| `:methods(): table`                    | Métodos disponíveis               |
| `:has_field(name: string): boolean`    | Verifica a existência de um campo |
| `:call_static(name: string, ...): any` | Executa um método estático        |

## Exemplo: exibir a classe do objeto

```lua
local status = menu.label("Avatar: unknown")

register_callback("on_update", function()
    if not il2cpp.available() then return end

    local avatar = il2cpp.root("local_avatar")
    if avatar and avatar:valid() then
        status:set("Avatar: " .. avatar:class():name())
    end
end)
```

{% hint style="warning" %}
**Os objetos IL2CPP só são válidos dentro do callback no qual foram obtidos.** Não armazene referências `il2cpp_object` entre callbacks.
{% endhint %}

A alteração de campos (`:set`) e a execução de métodos (`:call` e `:call_static`) exigem a opção **Allow unsafe scripts**. Algumas classes e campos podem não estar disponíveis.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.gamesense.biz/pt-br/api-reference/il2cpp.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
