feat(Lua)!: New Lua bindings (#3563)

* feat(Lua): Make independent imgui independent.
feat(Lua): Add a `pointer:set_address` binding.
feat(Lua): Added `menu_event.Wndproc` event.
fix(Lua): Fix `ImGui.SliderFloat3` binding.
fix(Lua Docs): Partially fixed auto generated documentation.
* fix(gui.cpp): include `lua_manager.hpp`.
* fix(lua_manager.hpp): Added `draw_less_dependent_gui` function.
* chore(Lua): Rename `add_independent_imgui` to `add_always_draw_imgui`.
* docs(menu_event): Added docs for Wndporc event.
* docs: Fixed a few more errors.
* add reasoning and use native underlying format

Co-authored-by: tupoy-ya <tupoy-ya@users.noreply.github.com>
Co-authored-by: xiaoxiao921 <837334+xiaoxiao921@users.noreply.github.com>
This commit is contained in:
tupoy-ya
2024-08-14 06:40:09 +00:00
committed by GitHub
parent e4e1b6b63b
commit eecd20beaf
22 changed files with 380 additions and 113 deletions

View File

@ -16,7 +16,7 @@ Returns a memory instance, with the given address.
myInstance = pointer:new(address)
```
## Functions (23)
## Functions (26)
### `add(offset)`
@ -63,18 +63,6 @@ Rips the current memory address and returns a new pointer object.
pointer = pointer:rip(offset)
```
### `get_int()`
Retrieves the value stored at the memory address as the specified type.
- **Returns:**
- `number`: the value stored at the memory address as the specified type.
**Example Usage:**
```lua
number = pointer:get_int()
```
### `get_byte()`
Retrieves the value stored at the memory address as the specified type.
@ -99,6 +87,18 @@ Retrieves the value stored at the memory address as the specified type.
number = pointer:get_word()
```
### `get_int()`
Retrieves the value stored at the memory address as the specified type.
- **Returns:**
- `number`: the value stored at the memory address as the specified type.
**Example Usage:**
```lua
number = pointer:get_int()
```
### `get_dword()`
Retrieves the value stored at the memory address as the specified type.
@ -135,18 +135,6 @@ Retrieves the value stored at the memory address as the specified type.
number = pointer:get_qword()
```
### `set_int(value)`
Sets the value at the memory address to the specified value of the given type.
- **Parameters:**
- `value` (number): new value.
**Example Usage:**
```lua
pointer:set_int(value)
```
### `set_byte(value)`
Sets the value at the memory address to the specified value of the given type.
@ -171,6 +159,18 @@ Sets the value at the memory address to the specified value of the given type.
pointer:set_word(value)
```
### `set_int(value)`
Sets the value at the memory address to the specified value of the given type.
- **Parameters:**
- `value` (number): new value.
**Example Usage:**
```lua
pointer:set_int(value)
```
### `set_dword(value)`
Sets the value at the memory address to the specified value of the given type.
@ -343,4 +343,16 @@ Retrieves the memory address stored in the pointer object.
number = pointer:get_address()
```
### `set_address(address)`
Sets the memory address stored in the pointer object.
- **Parameters:**
- `address` (integer): new address.
**Example Usage:**
```lua
pointer:set_address(address)
```

View File

@ -23,13 +23,19 @@ Clear the tab of all its custom lua content that you own.
tab:clear()
```
### `add_tab()`
### `add_tab(tab_name)`
Add a sub tab to this tab.
- **Parameters:**
- `tab_name` (string): Name of the tab to add.
- **Returns:**
- `tab`: A tab instance which corresponds to the new tab in the GUI.
**Example Usage:**
```lua
tab:add_tab()
tab = tab:add_tab(tab_name)
```
### `add_button(name, callback)`

View File

@ -26,7 +26,7 @@ z component of the vector.
### `new(x, y, z)`
Returns a vector that contains the x, y, and z values.
Returns: vec3: a vector that contains the x, y, and z values.
- **Parameters:**
- `x` (float): x component of the vector.

View File

@ -2,7 +2,7 @@
Table containing functions for modifying the menu GUI.
## Functions (8)
## Functions (12)
### `get_tab(tab_name)`
@ -92,6 +92,38 @@ gui.show_error(title, message)
bool = gui.is_open()
```
### `toggle(toggle)`
Opens and closes the gui.
- **Parameters:**
- `toggle` (boolean)
**Example Usage:**
```lua
gui.toggle(toggle)
```
### `mouse_override()`
- **Returns:**
- `bool`: Returns true if the mouse is overridden.
**Example Usage:**
```lua
bool = gui.mouse_override()
```
### `override_mouse(override)`
- **Parameters:**
- `override` (boolean)
**Example Usage:**
```lua
gui.override_mouse(override)
```
### `add_imgui(imgui_rendering)`
Registers a function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info.
@ -118,4 +150,30 @@ end)
gui.add_imgui(imgui_rendering)
```
### `add_always_draw_imgui(imgui_rendering)`
Registers a function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info. This function will be called even when the menu is closed.
**Example Usage:**
```lua
gui.add_always_draw_imgui(function()
if ImGui.Begin("My Custom Window") then
if ImGui.Button("Label") then
script.run_in_fiber(function(script)
-- call natives in there
end)
end
ImGui.End()
end
end)
``
- **Parameters:**
- `imgui_rendering` (function): Function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info.
**Example Usage:**
```lua
gui.add_always_draw_imgui(imgui_rendering)
```

View File

@ -2,7 +2,7 @@
Table containing all possible events to which you can respond.
## Fields (8)
## Fields (9)
### `PlayerLeave`
@ -103,3 +103,16 @@ end)
- Type: `integer`
### `Wndproc`
Event that is triggered when Wndproc is called
**Example Usage:**
```lua
event.register_handler(menu_event.Wndproc, function (hwnd, msg, wparam, lparam)
if msg == 132 then return end
log.debug("hwnd = " .. tostring(hwnd) .. ", msg = " .. tostring(msg) .. ", wparam = " .. tostring(wparam) .. ", lparam = " .. tostring(lparam))
end)
```
- Type: `integer`

View File

@ -2,7 +2,7 @@
Table containing helper functions for network related features.
## Functions (17)
## Functions (22)
### `trigger_script_event(bitset, _args)`
@ -146,7 +146,7 @@ string = network.get_flagged_modder_reason(player_idx)
Try to force ourself to be host for the given GTA Script. Needs to be called in the fiber pool or a loop.
- **Parameters:**
- `script_name` (string): Name of the script
- `script_name` (string): Name of the script.
**Example Usage:**
```lua
@ -164,7 +164,7 @@ Forces the given GTA script to be started on a player. Needs to be called in the
**Example Usage:**
```lua
network.force_script_on_player(script_name)
network.force_script_on_player(player_idx, script_name, instance_id)
```
### `send_chat_message(msg, team_only)`
@ -198,14 +198,14 @@ network.send_chat_message_to_player(player_idx, msg)
Call get_player_rank(playerID)
- **Parameters:**
- `pid` (int)
- `pid` (integer): Index of the player.
- **Returns:**
- `int`: Returns an integer which contains the players rank.
- `integer`: An integer which contains the players rank.
**Example Usage:**
```lua
network.get_player_rank(pid)
integer = network.get_player_rank(pid)
```
### `get_player_rp(pid)`
@ -213,14 +213,14 @@ network.get_player_rank(pid)
Call get_player_rp(playerID)
- **Parameters:**
- `pid` (int)
- `pid` (integer): Index of the player.
- **Returns:**
- `int`: Returns an integer which contains the players rp.
- `integer`: An integer which contains the players rp.
**Example Usage:**
```lua
network.get_player_rp(pid)
integer = network.get_player_rp(pid)
```
### `get_player_money(pid)`
@ -228,14 +228,14 @@ network.get_player_rp(pid)
Call get_player_money(playerID)
- **Parameters:**
- `pid` (int)
- `pid` (integer): Index of the player.
- **Returns:**
- `int`: Returns an integer which contains the players money.
- `integer`: An integer which contains the players money.
**Example Usage:**
```lua
network.get_player_money(pid)
integer = network.get_player_money(pid)
```
### `get_player_wallet(pid)`
@ -243,14 +243,14 @@ network.get_player_money(pid)
Call get_player_wallet(playerID)
- **Parameters:**
- `pid` (int)
- `pid` (integer): Index of the player.
- **Returns:**
- `int`: Returns an integer which contains the players wallet.
- `integer`: An integer which contains the players wallet.
**Example Usage:**
```lua
network.get_player_wallet(pid)
integer = network.get_player_wallet(pid)
```
### `get_player_bank(pid)`
@ -258,14 +258,14 @@ network.get_player_wallet(pid)
Call get_player_bank(playerID)
- **Parameters:**
- `pid` (int)
- `pid` (integer): Index of the player.
- **Returns:**
- `int`: Returns an integer which contains the players bank.
- `integer`: An integer which contains the players bank.
**Example Usage:**
```lua
network.get_player_bank(pid)
integer = network.get_player_bank(pid)
```
### `get_player_language_id(pid)`
@ -273,14 +273,14 @@ network.get_player_bank(pid)
Call get_player_language_id(playerID)
- **Parameters:**
- `pid` (int)
- `pid` (integer): Index of the player.
- **Returns:**
- `int`: Returns an integer which contains the players language id.
- `integer`: An integer which contains the players language id.
**Example Usage:**
```lua
network.get_player_language_id(pid)
integer = network.get_player_language_id(pid)
```
### `get_player_language_name(pid)`
@ -288,12 +288,14 @@ network.get_player_language_id(pid)
Call get_player_language_name(playerID)
- **Parameters:**
- `pid` (int)
- `pid` (integer): Index of the player.
- **Returns:**
- `string`: Returns a string which contains the players language name.
- `string`: A string which contains the players language name.
**Example Usage:**
```lua
network.get_player_language_name(pid)
```
string = network.get_player_language_name(pid)
```

View File

@ -1,43 +1,52 @@
# Table: scr_function
Table for calling GTA script functions. Needs to be called in the fiber pool or a GTA script. Only call the function when necessary.
Table for calling GTA script functions. Needs to be called in the fiber pool. Only call the function when necessary.
## Functions (2)
### `call_script_function(script_name, function_name, pattern, return_type_string, args_)`
Calls a script function with the given arguments. Returns the return value as the given type.
**Example Usage:**
```lua
local value = scr_function.call_script_function("freemode", "wear_sunglasses_at_night", "69 42 06 66", "bool", {
{ "int", 69 },
{ "float", 4.20 },
{ "int", 666 }
})
```
- **Parameters:**
- `script_name` (string): Name of the script.
- `function_name` (string): Name of the function. This parameter needs to be unique.
- `pattern` (string): Pattern to scan for within the script.
- `return_type_string` (string): Return type of the function. Supported types are **"int"**, **"bool"**, **"const char\*/string"**, **"ptr/pointer/*"**, **"float"**, and **"vector3"**. Anything different will be rejected.
- `_args` (table): Arguments to pass to the function. Supported types are the same as return types.
- `args_` (table): Arguments to pass to the function. Supported types are the same as return types.
**Example Usage:**
```lua
local value = scr_function.call_script_function("freemode", "wear_sunglasses_at_night", "69 42 06 66", "bool", {
{ "int", 69 },
{ "float", 4.20 },
{ "int", 666 }
})
scr_function.call_script_function(script_name, function_name, pattern, return_type_string, args_)
```
### `call_script_function(script_name, instruction_pointer, return_type_string, args_)`
Calls a script function directly using the function position with the given arguments. Returns the return value as the given type.
**Example Usage:**
```lua
local value = scr_function.call_script_function("freemode", 0xE792, "string", {
{ "int", 191 }
})
```
- **Parameters:**
- `script_name` (string): Name of the script.
- `function_name` (string): Name of the function.
- `instruction_pointer` (integer): Position of the function within the script.
- `return_type_string` (string): Return type of the function. Supported types are **"int"**, **"bool"**, **"const char\*/string"**, **"ptr/pointer/*"**, **"float"**, and **"vector3"**. Anything different will be rejected.
- `_args` (table): Arguments to pass to the function. Supported types are the same as return types.
- `args_` (table): Arguments to pass to the function. Supported types are the same as return types.
**Example Usage:**
```lua
local value = scr_function.call_script_function("freemode", 0xE792, "string", {
{ "int", 191 }
})
```
scr_function.call_script_function(script_name, instruction_pointer, return_type_string, args_)
```

View File

@ -2,16 +2,11 @@
Table containing helper functions related to gta scripts.
## Functions (7)
## Functions (6)
### `register_looped(name, func)`
Registers a function that will be looped as a gta script.
- **Parameters:**
- `name` (string): name of your new looped script
- `func` (function): function that will be executed in a forever loop.
**Example Usage:**
```lua
script.register_looped("nameOfMyLoopedScript", function (script)
@ -36,13 +31,18 @@ script.register_looped("nameOfMyLoopedScript", function (script)
end)
```
- **Parameters:**
- `name` (string): name of your new looped script
- `func` (function): function that will be executed in a forever loop.
**Example Usage:**
```lua
script.register_looped(name, func)
```
### `run_in_fiber(func)`
Executes a function once inside the fiber pool, you can call natives inside it and yield or sleep.
- **Parameters:**
- `func` (function): function that will be executed once in the fiber pool.
**Example Usage:**
```lua
script.run_in_fiber(function (script)
@ -67,16 +67,28 @@ script.run_in_fiber(function (script)
end)
```
- **Parameters:**
- `func` (function): function that will be executed once in the fiber pool.
**Example Usage:**
```lua
script.run_in_fiber(func)
```
### `is_active(script_name)`
Returns true if the specified script is currently active/running.
**Example Usage:**
```lua
local is_freemode_active = script.is_active("freemode")
```
- **Parameters:**
- `script_name` (string): The name of the script.
**Example Usage:**
```lua
local is_freemode_active = script.is_active("freemode")
script.is_active(script_name)
```
### `execute_as_script(script_name, func)`
@ -93,29 +105,39 @@ script.execute_as_script(script_name, func)
### `add_patch(script_name, name, pattern, offset, _patch)`
Adds a patch for the specified script.
- **Parameters:**
- `script_name` (string): The name of the script.
- `name` (string): The name of the patch.
- `pattern` (string): Pattern to scan for within the script.
- `offset` (integer): The position within the pattern.
- `_patch` (table): The bytes to be written into the script's bytecode.
**Example Usage:**
```lua
script.add_patch("fm_content_xmas_truck", "Flickering Fix", "56 ? ? 4F ? ? 40 ? 5D ? ? ? 74", 0, {0x2B, 0x00, 0x00})
```
### `start_launcher_script(script_name)`
Tries to start a launcher script. Needs to be called in the fiber pool or a loop.
- **Parameters:**
- `name` (string): The name of the script.
- `script_name` (string): The name of the script.
- `name` (string): The name of the patch.
- `pattern` (string): The pattern to scan for within the script.
- `offset` (integer): The position within the pattern.
- `_patch` (table): The bytes to be written into the script's bytecode.
**Example Usage:**
```lua
script.add_patch(script_name, name, pattern, offset, _patch)
```
### `start_launcher_script(script_name)`
Tries to start a launcher script. Needs to be called in the fiber pool or a loop.
**Example Usage:**
```lua
script.run_in_fiber(function()
script.start_launcher_script("am_hunt_the_beast")
script.start_launcher_script("am_hunt_the_beast")
end)
```
```
- **Parameters:**
- `script_name` (string): The name of the script.
**Example Usage:**
```lua
script.start_launcher_script(script_name)
```