> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leanmenu.cc/llms.txt
> Use this file to discover all available pages before exploring further.

# 💉 | Resource Simulation

> Safely inject code into resources

<Warning>
  This is designed to attempt to fix injection detections and certain native executions, NOT completely bypass native calls like `CreateVehicle`, etc.
</Warning>

Lean provides two simulation methods for injecting code into a resource context. Both aim to reduce detection risk, but differ in reliability and execution consistency/methodology.

## Simulate1 (Safer, but less reliable successful injections)

Execute code within a specific resource context using method 1.

```lua theme={null}
LeanAPI.Simulate1(resourceName, code)
```

### Parameters

* `resourceName` (string) – Name of the target resource, or "any" to target a random found injectable resource
* `code` (string) – Lua code to execute inside the resource context

### Returns

```text theme={null}
Nothing
```

### Example

```lua theme={null}
LeanAPI.Simulate1("lean", [[
    print("wow we injected into " .. GetCurrentResourceName() .. " using method 1")
]])
```

***

## Simulate2 (More reliable, recommended for stability)

Execute code within a specific resource context using method 2.

```lua theme={null}
LeanAPI.Simulate2(resourceName, code)
```

### Parameters

* `resourceName` (string) – Name of the target resource, or "any" to target a random found injectable resource
* `code` (string) – Lua code to execute inside the resource context

### Returns

```text theme={null}
Nothing
```

### Example

```lua theme={null}
LeanAPI.Simulate2("lean", [[
    print("hi " .. GetPlayerName(PlayerId()) ..  " we injected into " .. GetCurrentResourceName())
]])
```

***

## Key Differences

| Method    | Safety Level | Successful Injection Reliability |
| --------- | ------------ | -------------------------------- |
| Simulate1 | Higher       | Lower                            |
| Simulate2 | High         | Higher                           |

***

## Recommendation

* Use **Simulate1** when prioritizing **maximum injection detection avoidance and safety when calling certain natives or funcs**
* Use **Simulate2** when you need **consistent execution and are unlikely to fail, although certain detections can occur due to this being the less safe method.**
