fix call_hook crash with FSL and script function hook improvements (#223)

This commit is contained in:
Arthur
2026-04-24 18:59:09 +03:00
committed by GitHub
parent 02a079e92a
commit 29953b1bda
7 changed files with 252 additions and 46 deletions
+64 -1
View File
@@ -2,7 +2,21 @@
Class for wrapping arguments and return values of GTA script functions, used by add_script_function_hook.
## Functions (6)
## Functions (10)
### `get_count()`
Get the total number of elements in the wrapper.
- **Returns:**
- `int`: The number of elements in the wrapper.
**Example Usage:**
```lua
count = scr_value_wrapper:get_count()
```
---
### `get_int()`
@@ -36,6 +50,38 @@ scr_value_wrapper:set_int(0, 42)
---
### `get_uns()`
Get the unsigned int value currently contained by the wrapper.
- **Parameters:**
- `index` (int): The index to access.
- **Returns:**
- `int`: The current unsigned value.
**Example Usage:**
```lua
value = scr_value_wrapper:get_uns(0)
```
---
### `set_uns()`
Set the unsigned int value contained by the wrapper.
- **Parameters:**
- `index` (int): The index to access.
- `value` (int): The new unsigned value.
**Example Usage:**
```lua
scr_value_wrapper:set_uns(0, 42)
```
---
### `get_float()`
Get the float value currently contained by the wrapper.
@@ -96,4 +142,21 @@ Set the string value contained by the wrapper.
**Example Usage:**
```lua
scr_value_wrapper:set_string(0, "hello")
```
---
### `get_reference()`
Get the reference value currently contained by the wrapper.
- **Parameters:**
- `index` (int): The index to access.
- **Returns:**
- `class`: The current value.
**Example Usage:**
```lua
value = scr_value_wrapper:get_reference(0)
```
+24 -2
View File
@@ -2,7 +2,7 @@
Table for calling and hooking GTA script functions. Calls must be made in the fiber pool.
## Functions (4)
## Functions (5)
### `call_script_function(script_name, function_name, pattern, return_type_string, args_)`
@@ -57,7 +57,7 @@ Hooks a script function. If the callback returns `false`, the original function
- `script_name` (string): Name of the script.
- `hook_name` (string): Name of the hook. This parameter needs to be unique.
- `pattern` (string): Pattern to scan for within the script.
- `hook_func` (string): The callback function. It receives args and rets, which can be read or set via `get/set_int/float/string` methods. Return value determines whether to skip or execute the original function.
- `hook_func` (string): The callback function. It receives args and rets, which can be read or set via `get/set_int/uns/float/string/reference` methods. Return value determines whether to skip or execute the original function.
**Example Usage:**
```lua
@@ -71,6 +71,28 @@ scr_function.add_script_function_hook("some_script", "my_hook", "2D 00 ? ? 00 61
end)
```
### `add_script_function_hook(script_name, hook_name, instruction_pointer, hook_func)`
Hooks a script function directly using the function position. If the callback returns `false`, the original function is skipped, and values in `rets` are pushed to the stack. If `true`, the original function executes normally.
- **Parameters:**
- `script_name` (string): Name of the script.
- `hook_name` (string): Name of the hook. This parameter needs to be unique.
- `instruction_pointer` (int): Position of the function within the script.
- `hook_func` (string): The callback function. It receives args and rets, which can be read or set via `get/set_int/uns/float/string/reference` methods. Return value determines whether to skip or execute the original function.
**Example Usage:**
```lua
scr_function.add_script_function_hook("some_script", "my_hook", 0x10BE, function(args, rets)
local val = args:get_int(0)
if val == 1 then
rets:set_int(0, 100)
return false
end
return true
end)
```
### `remove_script_function_hook(script_name, hook_name)`
Removes an existing script function hook.