# How to Use Tunables to Modify GTA Game Behavior at Runtime with YimMenuV2

> Discover how to modify GTA V's runtime behavior using Tunables in YimMenuV2. This guide explains real-time memory patching techniques for game modification.

- Repository: [YimMenu/YimMenuV2](https://github.com/YimMenu/YimMenuV2)
- Tags: how-to-guide
- Published: 2026-07-16

---

**YimMenuV2 exposes a Lua-based Tunables library that enables scripts to read and write GTA V's internal tunable values in real-time by directly patching memory addresses resolved from hash identifiers.**

YimMenuV2 is a GTA V mod menu that provides deep runtime manipulation capabilities through its modular scripting interface. The **Tunables** system allows Lua scripts to modify live game parameters—ranging from vehicle handling characteristics to mission timers—without requiring a game restart or file modification.

## Architecture of the Tunables System

The implementation separates the user-facing scripting API from the low-level memory management backend, ensuring type safety while enabling direct hardware-level memory access.

### Lua Library Interface ([`src/game/scripting/libraries/Tunables.cpp`](https://github.com/YimMenu/YimMenuV2/blob/main/src/game/scripting/libraries/Tunables.cpp))

The scripting layer resides in [`src/game/scripting/libraries/Tunables.cpp`](https://github.com/YimMenu/YimMenuV2/blob/main/src/game/scripting/libraries/Tunables.cpp), where the class inherits from `LuaLibrary` to register six typed functions under the global Lua table `tunables`. These functions expose **setters** (`set_int`, `set_bool`, `set_float`) and **getters** (`get_int`, `get_bool`, `get_float`) that accept a hash value as the first argument.

```lua
-- Global table registration makes tunables available to all scripts
tunables.set_float(0x3A8B5F2A, 2.5)

```

### Backend Resolution Engine ([`src/game/backend/Tunables.cpp`](https://github.com/YimMenu/YimMenuV2/blob/main/src/game/backend/Tunables.cpp))

The core logic lives in [`src/game/backend/Tunables.cpp`](https://github.com/YimMenu/YimMenuV2/blob/main/src/game/backend/Tunables.cpp), which implements the `Tunable` helper class. This class lazily resolves hash identifiers into memory addresses using the game's native interfaces (such as `GET_TUNABLE_INT` or `SET_TUNABLE_INT` equivalents). Once resolved, it caches the pointer and reports readiness via the `IsReady()` method. The **Set\<T\>** template writes directly to the resolved address, while **Get\<T\>** performs typed reads.

### Infrastructure Helpers ([`src/core/scripting/LuaLibrary.hpp`](https://github.com/YimMenu/YimMenuV2/blob/main/src/core/scripting/LuaLibrary.hpp) and [`src/core/scripting/LuaUtils.hpp`](https://github.com/YimMenu/YimMenuV2/blob/main/src/core/scripting/LuaUtils.hpp))

The library extends the base `LuaLibrary` class defined in [`src/core/scripting/LuaLibrary.hpp`](https://github.com/YimMenu/YimMenuV2/blob/main/src/core/scripting/LuaLibrary.hpp) to handle function registration. Utility functions in [`src/core/scripting/LuaUtils.hpp`](https://github.com/YimMenu/YimMenuV2/blob/main/src/core/scripting/LuaUtils.hpp)—such as `GetHashArgument` and `CheckBooleanSafe`—validate inputs before they reach the backend, enforcing that `set_bool` only receives boolean values and hashes are properly formatted.

## Runtime Memory Patching Mechanism

Understanding how the system bridges high-level Lua calls to low-level game memory reveals why changes take effect immediately.

### Hash-Based Address Resolution

Each tunable in GTA V is identified by a 32-bit hash (e.g., `0x3A8B5F2A` for stamina regeneration rates). When a script calls a setter, the `Tunable` class queries the game's native hash table to locate the corresponding memory offset. This resolution happens once and is cached for subsequent accesses to minimize overhead.

### Immediate Memory Writes

Because **Set\<T\>** patches the underlying memory location directly, any game logic that queries the tunable during the next update cycle sees the modified value immediately. This architecture bypasses the need for game restarts or asset reloading, enabling real-time adjustments to AI aggressiveness, loot drop rates, or vehicle traction parameters.

### Type Enforcement and Validation

The Lua layer enforces strict type safety before invoking backend methods. A call to `tunables.set_int` will reject non-integer inputs at the scripting boundary, preventing type confusion errors in the game's memory space.

## Practical Implementation Examples

The following Lua snippets demonstrate common use cases for modifying GTA V behavior at runtime.

```lua
-- Double the player's sprint stamina regeneration rate
local staminaHash = 0x3A8B5F2A
tunables.set_float(staminaHash, 2.5)

-- Enable "Police Ignore" mode by setting a boolean tunable
local policeIgnoreHash = 0x7F1C4D9E
tunables.set_bool(policeIgnoreHash, true)

-- Verify current value by reading back the float
local currentRegen = tunables.get_float(staminaHash)
print("Current stamina regen multiplier:", currentRegen)

```

## Safety Mechanisms and Edge Cases

The system includes defensive programming patterns to maintain stability when tunables are unavailable or game updates shift memory layouts.

### Availability Checking with IsReady()

If the backend cannot resolve a hash to a valid memory address—commonly occurring after game updates that rearrange data structures—the `IsReady()` method returns *false*. In this state, setter and getter calls become no-ops rather than crashing the process by writing to invalid memory.

### Graceful Degradation

When resolution fails, the `Tunable` class prevents null pointer dereferences by checking the cached address pointer before every operation. This ensures that scripts referencing obsolete or patched-out tunables continue running without raising access violations.

## Summary

- **[`src/game/scripting/libraries/Tunables.cpp`](https://github.com/YimMenu/YimMenuV2/blob/main/src/game/scripting/libraries/Tunables.cpp)** exposes six typed functions under the global `tunables` Lua table for reading and writing game values.
- **[`src/game/backend/Tunables.cpp`](https://github.com/YimMenu/YimMenuV2/blob/main/src/game/backend/Tunables.cpp)** implements the `Tunable` class, which resolves hashes to memory addresses via native game interfaces and provides `Set<T>()` and `Get<T>()` methods.
- Changes apply immediately because the system writes directly to resolved memory locations, affecting game logic on the next update cycle.
- The architecture enforces type safety at the Lua boundary and validates hash resolution via `IsReady()` before memory access.
- Unavailable tunables trigger no-ops rather than crashes through defensive `IsReady()` checks.

## Frequently Asked Questions

### Where is the Tunables Lua library implemented in YimMenuV2?

The user-facing Lua functions are implemented in [`src/game/scripting/libraries/Tunables.cpp`](https://github.com/YimMenu/YimMenuV2/blob/main/src/game/scripting/libraries/Tunables.cpp), which inherits from the `LuaLibrary` base class to register `set_int`, `set_bool`, `set_float`, `get_int`, `get_bool`, and `get_float` under the global `tunables` table.

### How does the mod menu prevent crashes when a tunable cannot be resolved?

The backend `Tunable` class in [`src/game/backend/Tunables.cpp`](https://github.com/YimMenu/YimMenuV2/blob/main/src/game/backend/Tunables.cpp) implements an `IsReady()` method that verifies the hash has been successfully resolved to a valid memory address. If resolution fails, all get and set operations become no-ops, preventing writes to invalid memory.

### What types of game parameters can be modified using tunables?

Tunables can modify virtually any runtime-configurable value exposed by GTA V's internal configuration system, including vehicle handling parameters, mission timer durations, AI difficulty settings, weapon damage multipliers, and loot drop rates.

### How are tunable values identified in the game engine?

Each tunable is referenced by a 32-bit hash identifier (e.g., `0x3A8B5F2A`). The `Tunable` class passes this hash to native game functions such as `GET_TUNABLE_INT` to retrieve the current memory address where the value is stored.