> 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/ru/api-reference/il2cpp.md).

# IL2CPP

Взаимодействие с IL2CPP классами и игровыми объектами.

`il2cpp` предоставляет доступ к игровым классам и объектам.

Вызовы IL2CPP доступны только внутри **`on_update`**. В `on_paint` и при загрузке скрипта этот API недоступен.

## il2cpp.available

`il2cpp.available(): boolean`

Проверяет, можно ли сейчас использовать IL2CPP.

```lua
register_callback("on_update", function()
    if il2cpp.available() then
        local avatar = il2cpp.root("local_avatar")
        if avatar and avatar:valid() then
            local class_name = avatar:class():name()
        end
    end
end)
```

## il2cpp.root

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

Возвращает зарегистрированный игровой объект по имени.

Доступный root: `"local_avatar"`. Если объекта сейчас нет, возвращается `nil`.

```lua
register_callback("on_update", function()
    local avatar = il2cpp.root("local_avatar")

    if not avatar or not avatar:valid() then
        return
    end

    local class_name = avatar:class():name()
end)
```

## il2cpp.find\_class

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

Находит игровой класс по имени. Если класс не найден, возвращает `nil`.

## Методы il2cpp\_object

| Метод                             | Описание                 |
| --------------------------------- | ------------------------ |
| `:valid(): boolean`               | Проверяет объект         |
| `:class(): il2cpp_class`          | Возвращает класс объекта |
| `:get(field: string): any`        | Читает поле              |
| `:set(field: string, value: any)` | Изменяет поле            |
| `:call(method: string, ...): any` | Вызывает метод           |

## Методы il2cpp\_class

| Метод                                  | Описание                   |
| -------------------------------------- | -------------------------- |
| `:name(): string`                      | Имя класса                 |
| `:namespace(): string`                 | Пространство имён          |
| `:fields(): table`                     | Список доступных полей     |
| `:methods(): table`                    | Список доступных методов   |
| `:has_field(name: string): boolean`    | Проверяет наличие поля     |
| `:call_static(name: string, ...): any` | Вызывает статический метод |

## Пример: вывести название класса в меню

```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" %}
**Объекты действуют только внутри текущего callback.** Объекты `il2cpp_object` нельзя сохранять между кадрами.
{% endhint %}

Изменение полей (`:set`) и вызовы методов (`:call`, `:call_static`) требуют включённой настройки **Allow unsafe scripts**. Некоторые классы и поля могут быть недоступны.


---

# 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/ru/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.
