Refactor Debug Threads & Expose More Functions (#3408)

- Added a search box for the script names in Debug -> Threads.
- Added `is_session_started` and `force_script_on_player` functions to the Lua network class.
- Added `is_active` and `start_launcher_script` functions to the Lua script class.
- Moved `view_stat_editor.cpp` to `src/views/network` from `src/views/settings`.
- Added a help text for directly editing the sliders in outfit editor.
This commit is contained in:
Arthur
2024-07-23 16:34:30 +03:00
committed by GitHub
parent e08ab4ca80
commit f16f35d6e0
7 changed files with 820 additions and 699 deletions

View File

@ -40,6 +40,15 @@ namespace lua::network
big::g_pointers->m_gta.m_trigger_script_event(1, actual_args.data(), actual_args.size(), bitset, args[0]);
}
// Lua API: Function
// Table: network
// Name: is_session_started
// Returns true if the local player is in a multiplayer session.
static bool is_session_started()
{
return *big::g_pointers->m_gta.m_is_session_started;
}
// Lua API: Function
// Table: network
// Name: give_pickup_rewards
@ -171,13 +180,26 @@ namespace lua::network
// Lua API: Function
// Table: network
// Name: force_script_host
// Param: script_name: string: Name of the script
// Try to force ourself to be host for the given GTA Script.
// Param: script_name: string: Name of the script.
// Try to force ourself to be host for the given GTA Script. Needs to be called in the fiber pool or a loop.
static void force_script_host(const std::string& script_name)
{
big::scripts::force_host(rage::joaat(script_name));
}
// Lua API: function
// Table: script
// Name: force_script_on_player
// Param: player_idx: integer: Index of the player.
// Param: script_name: string: Name of the script.
// Param: script_name: integer: Instance ID of the script.
// Forces the given GTA script to be started on a player. Needs to be called in the fiber pool or a loop.
static void force_script_on_player(int player_idx, const std::string& script_name, int instance_id)
{
if (auto player = big::g_player_service->get_by_id(player_idx))
big::scripts::force_script_on_player(player, rage::joaat(script_name), instance_id);
}
// Lua API: Function
// Table: network
// Name: send_chat_message
@ -335,6 +357,7 @@ namespace lua::network
auto ns = state["network"].get_or_create<sol::table>();
ns["trigger_script_event"] = trigger_script_event;
ns["is_session_started"] = is_session_started;
ns["give_pickup_rewards"] = give_pickup_rewards;
ns["set_player_coords"] = set_player_coords;
ns["set_all_player_coords"] = set_all_player_coords;
@ -345,6 +368,7 @@ namespace lua::network
ns["is_player_friend"] = is_player_friend;
ns["get_flagged_modder_reason"] = get_flagged_modder_reason;
ns["force_script_host"] = force_script_host;
ns["force_script_on_player"] = force_script_on_player;
ns["send_chat_message"] = send_chat_message;
ns["send_chat_message_to_player"] = send_chat_message_to_player;
ns["get_player_rank"] = get_player_rank;

View File

@ -7,6 +7,7 @@
#include "lua/bindings/network.hpp"
#include "memory/pattern.hpp"
#include "services/script_patcher/script_patcher_service.hpp"
#include "util/scripts.hpp"
namespace lua::script
{
@ -155,6 +156,23 @@ namespace lua::script
module->m_registered_scripts.push_back(std::move(lua_script));
}
// Lua API: function
// Table: script
// Name: is_active
// Param: script_name: string: The name of the script.
// Returns true if the specified script is currently active/running.
// **Example Usage:**
// ```lua
// local is_freemode_active = script.is_active("freemode")
// ```
static bool is_active(const std::string& script_name)
{
if (auto script = big::gta_util::find_script_thread(rage::joaat(script_name)))
return true;
return false;
}
// Lua API: function
// Table: script
// Name: execute_as_script
@ -175,9 +193,9 @@ namespace lua::script
// Param _patch: table: The bytes to be written into the script's bytecode.
// Adds a patch for the specified script.
// **Example Usage:**
//```lua
//script.add_patch("fm_content_xmas_truck", "Flickering Fix", "56 ? ? 4F ? ? 40 ? 5D ? ? ? 74", 0, {0x2B, 0x00, 0x00})
//```
// ```lua
// script.add_patch("fm_content_xmas_truck", "Flickering Fix", "56 ? ? 4F ? ? 40 ? 5D ? ? ? 74", 0, {0x2B, 0x00, 0x00})
// ```
static void add_patch(const std::string& script_name, const std::string& name, const std::string& pattern, int offset, sol::table _patch)
{
auto patch = convert_sequence<uint8_t>(_patch);
@ -197,9 +215,9 @@ namespace lua::script
// Param _args: table: The arguments to pass to the script function.
// Calls a function from the specified script.
// **Example Usage:**
//```lua
//script.call_function("Collect Collectible", "freemode", "2D 05 33 00 00", 0, {17, 0, 1, 1, 0})
//```
// ```lua
// script.call_function("Collect Collectible", "freemode", "2D 05 33 00 00", 0, {17, 0, 1, 1, 0})
// ```
static void call_function(const std::string& name, const std::string& script_name, const std::string& pattern, int offset, sol::table _args)
{
auto args = convert_sequence<uint64_t>(_args);
@ -208,14 +226,32 @@ namespace lua::script
script_function(args);
}
// Lua API: function
// Table: script
// Name: start_launcher_script
// Param: script_name: string: The name of the script.
// 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")
// end)
// ```
static void start_launcher_script(const std::string& script_name)
{
big::scripts::start_launcher_script(rage::joaat(script_name));
}
void bind(sol::state& state)
{
auto ns = state["script"].get_or_create<sol::table>();
ns["register_looped"] = register_looped;
ns["run_in_fiber"] = run_in_fiber;
ns["execute_as_script"] = execute_as_script;
ns["add_patch"] = add_patch;
ns["call_function"] = call_function;
auto ns = state["script"].get_or_create<sol::table>();
ns["register_looped"] = register_looped;
ns["run_in_fiber"] = run_in_fiber;
ns["is_active"] = is_active;
ns["execute_as_script"] = execute_as_script;
ns["add_patch"] = add_patch;
ns["call_function"] = call_function;
ns["start_launcher_script"] = start_launcher_script;
auto usertype = state.new_usertype<script_util>("script_util");