This commit is contained in:
Quentin
2023-07-02 00:59:02 +02:00
committed by GitHub
parent f96356960a
commit 3bdd0796f4
56 changed files with 2804 additions and 24 deletions

View File

@ -5,25 +5,42 @@
namespace lua::command
{
// Lua API: Table
// Name: command
// Table for calling menu commands.
// Lua API: Function
// Table: command
// Name: call
// Param: command_name: string: The name of the command that will be called.
// Param: _args: table: Optional. List of arguments for the command.
// Call a menu command.
static void call(const std::string& command_name, std::optional<sol::table> _args)
{
auto args = convert_sequence<uint64_t>(_args.value_or(sol::table()));
const auto args = convert_sequence<uint64_t>(_args.value_or(sol::table()));
auto command = big::command::get(rage::joaat(command_name));
const auto command = big::command::get(rage::joaat(command_name));
if (command)
command->call(args, {});
}
// Lua API: Function
// Table: command
// Name: call_player
// Param: player_idx: integer: Index of the player on which the menu command will be executed.
// Param: command_name: string: The name of the command that will be called.
// Param: _args: table: Optional. List of arguments for the command.
// Call a menu command on a given player.
static void call_player(int player_idx, const std::string& command_name, std::optional<sol::table> _args)
{
auto args = convert_sequence<uint64_t>(_args.value_or(sol::table()));
const auto args = convert_sequence<uint64_t>(_args.value_or(sol::table()));
auto command = (big::player_command*)big::command::get(rage::joaat(command_name));
const auto command = (big::player_command*)big::command::get(rage::joaat(command_name));
if (command)
{
auto player = big::g_player_service->get_by_id(player_idx);
const auto player = big::g_player_service->get_by_id(player_idx);
if (player)
{

View File

@ -5,17 +5,109 @@
namespace lua::event
{
static void register_handler(const std::string& name, sol::function func, sol::this_state state)
{
auto module = sol::state_view(state)["!this"].get<big::lua_module*>();
// Lua API: Table
// Name: menu_event
// Table containing all possible events to which you can respond.
auto hash = rage::joaat(name);
module->m_event_callbacks.emplace(hash, std::vector<sol::function>());
module->m_event_callbacks[hash].push_back(func);
// Lua API: Field
// Table: menu_event
// Field: PlayerLeave: integer
// Event that is triggered when a player leave the game session.
// **Exemple Usage:**
// ```lua
// event.register_handler(menu_event.PlayerLeave, function (player_name)
// log.info(player_name)
// end)
// ```
// Lua API: Field
// Table: menu_event
// Field: PlayerJoin: integer
// Event that is triggered when a player join the game session.
// **Exemple Usage:**
// ```lua
// event.register_handler(menu_event.PlayerJoin, function (player_name, player_id)
// log.info(player_name)
// log.info(player_id)
// end)
// ```
// Lua API: Field
// Table: menu_event
// Field: PlayerMgrInit: integer
// Event that is triggered when the player manager initialize. Usually called when we are joining a session.
// **Exemple Usage:**
// ```lua
// event.register_handler(menu_event.PlayerMgrInit, function ()
// log.info("Player manager inited, we just joined a session.")
// end)
// ```
// Lua API: Field
// Table: menu_event
// Field: PlayerMgrShutdown: integer
// Event that is triggered when the player manager shutdown. Usually called when we are leaving a session.
// **Exemple Usage:**
// ```lua
// event.register_handler(menu_event.PlayerMgrShutdown, function ()
// log.info("Player manager inited, we just joined a session.")
// end)
// ```
// Lua API: Field
// Table: menu_event
// Field: ChatMessageReceived: integer
// Event that is triggered when we receive a in-game chat message.
// **Exemple Usage:**
// ```lua
// event.register_handler(menu_event.ChatMessageReceived, function (player_id, chat_message)
// log.info(player_id)
// log.info(chat_message)
// end)
// ```
// Lua API: Field
// Table: menu_event
// Field: ScriptedGameEventReceived: integer
// Event that is triggered when we receive a scripted game event.
// **Exemple Usage:**
// ```lua
// event.register_handler(menu_event.ScriptedGameEventReceived, function (player_id, script_event_args)
// log.info(player_id)
// log.info(script_event_args)
// end)
// ```
// Lua API: Table
// Name: event
// Table for responding to various events. The list of events is available in the menu_event table.
// Lua API: Function
// Table: event
// Name: register_handler
// Param: menu_event: menu_event: The menu_event that we want to respond to.
// Param: func: function: The function that will be called.
// Register a function that will be called each time the corresponding menu_event is triggered.
static void register_handler(const menu_event& menu_event, sol::function func, sol::this_state state)
{
const auto module = sol::state_view(state)["!this"].get<big::lua_module*>();
module->m_event_callbacks[menu_event].push_back(func);
}
static void bind(sol::state& state)
{
state.new_enum<menu_event>("menu_event",
{
{"PlayerLeave", menu_event::PlayerLeave},
{"PlayerJoin", menu_event::PlayerJoin},
{"PlayerMgrInit", menu_event::PlayerMgrInit},
{"PlayerMgrShutdown", menu_event::PlayerMgrShutdown},
{"ChatMessageReceived", menu_event::ChatMessageReceived},
{"ScriptedGameEventReceived", menu_event::ScriptedGameEventReceived},
});
auto ns = state["event"].get_or_create<sol::table>();
ns["register_handler"] = register_handler;
// TODO: triggering events through script?

View File

@ -0,0 +1,20 @@
#pragma once
#include "lua/sol.hpp"
namespace lua::global_table
{
// Lua API: Table
// Name: Global Table
// Custom fields, functions, etc added to The Lua [Global Table](https://www.lua.org/pil/15.4.html).
// Lua API: Function
// Table: Global Table
// Name: joaat
// Param: str: string: The string that needs to be joaat hashed.
// Returns: integer: The joaat hashed input string.
static void bind(sol::state& state)
{
state["joaat"] = rage::joaat;
}
}

View File

@ -4,36 +4,82 @@
namespace lua::globals
{
// Lua API: Table
// Name: globals
// Table containing functions for manipulating gta script globals.
// Lua API: Function
// Table: globals
// Name: get_int
// Param: global: integer: index of the global
// Returns: integer: value of the global
// Retrieves an int global value.
static int get_int(int global)
{
return *big::script_global(global).as<int*>();
}
// Lua API: Function
// Table: globals
// Name: get_float
// Param: global: integer: index of the global
// Returns: float: value of the global
// Retrieves a float global value.
static int get_float(int global)
{
return *big::script_global(global).as<float*>();
}
// Lua API: Function
// Table: globals
// Name: get_string
// Param: global: integer: index of the global
// Returns: string: value of the global
// Retrieves a string global value.
static std::string get_string(int global)
{
return std::string(big::script_global(global).as<char*>());
}
// Lua API: Function
// Table: globals
// Name: set_int
// Param: global: integer: index of the global
// Param: val: integer: new value for the global
// Sets an int global value.
static void set_int(int global, int val)
{
*big::script_global(global).as<int*>() = val;
}
// Lua API: Function
// Table: globals
// Name: set_float
// Param: global: integer: index of the global
// Param: val: float: new value for the global
// Sets a float global value.
static void set_float(int global, float val)
{
*big::script_global(global).as<float*>() = val;
}
// Lua API: Function
// Table: globals
// Name: set_string
// Param: global: integer: index of the global
// Param: str: string: new value for the global
// Sets a string global value.
static void set_string(int global, const std::string& str, int max_length)
{
strncpy(big::script_global(global).as<char*>(), str.data(), max_length);
}
// Lua API: Function
// Table: globals
// Name: get_pointer
// Param: global: integer: index of the global
// Returns: pointer: value of the global
// Retrieves a pointer global.
static memory::pointer get_pointer(int global)
{
return memory::pointer((uint64_t)big::script_global(global).as<void*>());

View File

@ -22,6 +22,9 @@ namespace lua::gui
module->m_gui[hash].push_back(std::move(element));
}
// Lua API: Class
// Name: tab
// Class for representing a tab within the GUI.
class tab
{
rage::joaat_t m_tab_hash;
@ -32,6 +35,12 @@ namespace lua::gui
{
}
// Lua API: Function
// Class: tab
// Name: add_button
// Param: name: string: Text written inside the button.
// Param: callback: function: function that will be called when the button is clicked.
// Add a button to the gui tab.
std::shared_ptr<lua::gui::button> add_button(const std::string& name, sol::function callback, sol::this_state state)
{
auto element = std::make_shared<lua::gui::button>(name, callback);
@ -39,6 +48,12 @@ namespace lua::gui
return element;
}
// Lua API: Function
// Class: tab
// Name: add_text
// Param: name: string: Text that will be written.
// Returns: text: The text object instance.
// Add text to the gui tab.
std::shared_ptr<lua::gui::text> add_text(const std::string& name, sol::this_state state)
{
auto element = std::make_shared<lua::gui::text>(name);
@ -46,6 +61,12 @@ namespace lua::gui
return element;
}
// Lua API: Function
// Class: tab
// Name: add_checkbox
// Param: name: string: Text that will be written next to the checkbox.
// Returns: checkbox: The checkbox object instance.
// Add a checkbox widget to the gui tab.
std::shared_ptr<lua::gui::checkbox> add_checkbox(const std::string& name, sol::this_state state)
{
auto element = std::make_shared<lua::gui::checkbox>(name);
@ -53,6 +74,11 @@ namespace lua::gui
return element;
}
// Lua API: Function
// Class: tab
// Name: add_sameline
// Returns: sameline: The sameline object instance.
// Add a ImGui::SameLine.
std::shared_ptr<lua::gui::sameline> add_sameline(sol::this_state state)
{
auto element = std::make_shared<lua::gui::sameline>();
@ -60,6 +86,11 @@ namespace lua::gui
return element;
}
// Lua API: Function
// Class: tab
// Name: add_separator
// Returns: separator: The separator object instance.
// Add a ImGui::Separator.
std::shared_ptr<lua::gui::separator> add_separator(sol::this_state state)
{
auto element = std::make_shared<lua::gui::separator>();
@ -67,6 +98,12 @@ namespace lua::gui
return element;
}
// Lua API: Function
// Class: tab
// Name: add_input_int
// Param: name: string: Text that will be written next to the input field.
// Returns: input_int: The input_int object instance.
// Add a ImGui::InputInt.
std::shared_ptr<lua::gui::input_int> add_input_int(const std::string& name, sol::this_state state)
{
auto element = std::make_shared<lua::gui::input_int>(name);
@ -74,6 +111,12 @@ namespace lua::gui
return element;
}
// Lua API: Function
// Class: tab
// Name: add_input_float
// Param: name: string: Text that will be written next to the input field.
// Returns: input_float: The input_float object instance.
// Add a ImGui::InputFloat.
std::shared_ptr<lua::gui::input_float> add_input_float(const std::string& name, sol::this_state state)
{
auto element = std::make_shared<lua::gui::input_float>(name);
@ -81,6 +124,12 @@ namespace lua::gui
return element;
}
// Lua API: Function
// Class: tab
// Name: add_input_string
// Param: name: string: Text that will be written next to the input field.
// Returns: input_string: The input_string object instance.
// Add a ImGui::InputText.
std::shared_ptr<lua::gui::input_string> add_input_string(const std::string& name, sol::this_state state)
{
auto element = std::make_shared<lua::gui::input_string>(name);
@ -89,26 +138,57 @@ namespace lua::gui
}
};
// Lua API: Table
// Name: gui
// Table containing functions for modifying the menu GUI.
// Lua API: Function
// Table: gui
// Name: get_tab
// Param: tab_name: string: Name of the tab to get.
// Returns: tab: A tab instance which corresponds to the tab in the GUI.
static tab get_tab(const std::string& tab_name)
{
return tab(rage::joaat(tab_name));
}
// Lua API: Function
// Table: gui
// Name: show_message
// Param: title: string
// Param: message: string
// Shows a message to the user with the given title and message.
static void show_message(const std::string& title, const std::string& message)
{
big::g_notification_service->push(title, message);
}
// Lua API: Function
// Table: gui
// Name: show_warning
// Param: title: string
// Param: message: string
// Shows a warning to the user with the given title and message.
static void show_warning(const std::string& title, const std::string& message)
{
big::g_notification_service->push_warning(title, message);
}
// Lua API: Function
// Table: gui
// Name: show_error
// Param: title: string
// Param: message: string
// Shows an error to the user with the given title and message.
static void show_error(const std::string& title, const std::string& message)
{
big::g_notification_service->push_error(title, message);
}
// Lua API: Function
// Table: gui
// Name: is_open
// Returns: bool: Returns true if the GUI is open.
bool is_open();
static void bind(sol::state& state)

View File

@ -3,6 +3,10 @@
namespace lua::gui
{
// Lua API: Class
// Name: base_text_element
// Class representing a gui text element.
class base_text_element : public gui_element
{
protected:
@ -11,7 +15,16 @@ namespace lua::gui
public:
base_text_element(std::string text);
// Lua API: Function
// Class: base_text_element
// Name: set_text
// Param: new_text: string: The new text for that gui text element.
void set_text(std::string new_text);
// Lua API: Function
// Class: base_text_element
// Name: get_text
// Returns: string: Returns the current text for that gui text element.
std::string get_text();
};
}

View File

@ -4,6 +4,10 @@
namespace lua::gui
{
// Lua API: Class
// Name: button
// Inherit: base_text_element
// Class representing a gui button.
class button : public base_text_element
{
sol::function m_callback;

View File

@ -3,6 +3,10 @@
namespace lua::gui
{
// Lua API: Class
// Name: checkbox
// Inherit: base_text_element
// Class representing a gui checkbox.
class checkbox : public base_text_element
{
bool m_enabled = false;
@ -12,7 +16,16 @@ namespace lua::gui
void draw() override;
// Lua API: Function
// Class: checkbox
// Name: is_enabled
// Returns: boolean: Is the checkbox checked?
bool is_enabled();
// Lua API: Function
// Class: checkbox
// Name: set_enabled
// Param: enabled: boolean: The desired enabled state of the checkbox.
void set_enabled(bool enabled);
};
}

View File

@ -3,6 +3,10 @@
namespace lua::gui
{
// Lua API: Class
// Name: input_float
// Inherit: base_text_element
// Class for representing an input field for editing a float value within the GUI.
class input_float : public base_text_element
{
bool m_enabled = false;
@ -13,7 +17,16 @@ namespace lua::gui
void draw() override;
// Lua API: Function
// Class: input_float
// Name: get_value
// Returns: float: Get the value currently written inside the input field.
int get_value();
// Lua API: Function
// Class: input_float
// Name: set_value
// Param: val: float: Set the value currently written inside the input field.
void set_value(float val);
};
}

View File

@ -3,6 +3,10 @@
namespace lua::gui
{
// Lua API: Class
// Name: input_int
// Inherit: base_text_element
// Class for representing an input field for editing an integer value within the GUI.
class input_int : public base_text_element
{
bool m_enabled = false;
@ -13,7 +17,16 @@ namespace lua::gui
void draw() override;
// Lua API: Function
// Class: input_int
// Name: get_value
// Returns: integer: Get the value currently written inside the input field.
int get_value();
// Lua API: Function
// Class: input_int
// Name: set_value
// Param: val: integer: Set the value currently written inside the input field.
void set_value(int val);
};
}

View File

@ -3,6 +3,10 @@
namespace lua::gui
{
// Lua API: Class
// Name: input_string
// Inherit: base_text_element
// Class for representing an input field for editing a string value within the GUI.
class input_string : public base_text_element
{
bool m_enabled = false;
@ -13,7 +17,16 @@ namespace lua::gui
void draw() override;
// Lua API: Function
// Class: input_string
// Name: get_value
// Returns: string: Get the value currently written inside the input field.
std::string get_value();
// Lua API: Function
// Class: input_string
// Name: set_value
// Param: val: string: Set the value currently written inside the input field.
void set_value(std::string val);
};
}

View File

@ -3,6 +3,9 @@
namespace lua::gui
{
// Lua API: Class
// Name: sameline
// Class for ImGui::SameLine() - Puts a sameline between widgets or groups to layout them horizontally.
class sameline : public gui_element
{
public:

View File

@ -3,6 +3,9 @@
namespace lua::gui
{
// Lua API: Class
// Name: separator
// Class for ImGui::Separator() - separator, generally horizontal. Inside a menu bar or in horizontal layout mode, this becomes a vertical separator.
class separator : public gui_element
{
public:

View File

@ -4,6 +4,10 @@
namespace lua::gui
{
// Lua API: Class
// Name: text
// Inherit: base_text_element
// Class representing an imgui text element.
class text : public base_text_element
{
ImFont* m_font = nullptr;
@ -12,6 +16,11 @@ namespace lua::gui
text(std::string text);
void draw() override;
// Lua API: Function
// Class: text
// Name: set_font
// Param: font: string: The new font name for that imgui text element.
void set_font(std::string font);
};
}

View File

@ -5,6 +5,10 @@
namespace lua::locals
{
// Lua API: Table
// Name: locals
// Table for manipulating GTA scripts locals.
template<typename T>
inline T get(const std::string& script, int index)
{
@ -16,26 +20,56 @@ namespace lua::locals
return &null;
}
// Lua API: Function
// Table: locals
// Name: get_int
// Param: script: string: The name of the script
// Param: index: index: Index of the script local.
// Returns: integer: The value of the given local.
static int get_int(const std::string& script, int index)
{
return *get<int*>(script, index);
}
// Lua API: Function
// Table: locals
// Name: get_float
// Param: script: string: The name of the script
// Param: index: index: Index of the script local.
// Returns: float: The value of the given local.
static int get_float(const std::string& script, int index)
{
return *get<float*>(script, index);
}
// Lua API: Function
// Table: locals
// Name: set_int
// Param: script: string: The name of the script
// Param: index: index: Index of the script local.
// Param: val: integer: The new value of the given local.
static void set_int(const std::string& script, int index, int val)
{
*get<int*>(script, index) = val;
}
// Lua API: Function
// Table: locals
// Name: set_float
// Param: script: string: The name of the script
// Param: index: index: Index of the script local.
// Param: val: float: The new value of the given local.
static void set_float(const std::string& script, int index, float val)
{
*get<float*>(script, index) = val;
}
// Lua API: Function
// Table: locals
// Name: get_pointer
// Param: script: string: The name of the script
// Param: index: index: Index of the script local.
// Returns: pointer: The pointer to the given local.
static memory::pointer get_pointer(const std::string& script, int index)
{
return memory::pointer((uint64_t)get<int*>(script, index));

View File

@ -1,17 +1,37 @@
#pragma once
#include "lua/sol.hpp"
namespace lua::log
{
// Lua API: Table
// Name: log
// Table containing functions for printing to console / log file.
// Lua API: Function
// Table: log
// Name: info
// Param: data: string
// Logs an informational message.
static void info(const std::string& data, sol::this_state state)
{
LOG(INFO) << sol::state_view(state)["!module_name"].get<std::string>() << ": " << data;
}
// Lua API: Function
// Table: log
// Name: warning
// Param: data: string
// Logs a warning message.
static void warning(const std::string& data, sol::this_state state)
{
LOG(WARNING) << sol::state_view(state)["!module_name"].get<std::string>() << ": " << data;
}
// Lua API: Function
// Table: log
// Name: debug
// Param: data: string
// Logs a debug message.
static void debug(const std::string& data, sol::this_state state)
{
LOG(VERBOSE) << sol::state_view(state)["!module_name"].get<std::string>() << ": " << data;

View File

@ -6,12 +6,21 @@
namespace lua::memory
{
// Lua API: Class
// Name: pointer
// Class representing a 64-bit memory address.
struct pointer
{
private:
std::uint64_t m_address;
public:
// Lua API: Constructor
// Class: pointer
// Param: address: integer: Address
// Returns a memory instance, with the given address.
explicit pointer(std::uint64_t address) :
m_address(address)
{
@ -22,43 +31,167 @@ namespace lua::memory
{
}
// Lua API: Function
// Class: pointer
// Name: add
// Param: offset: integer: offset
// Returns: pointer: new pointer object.
// Adds an offset to the current memory address and returns a new pointer object.
pointer add(uint64_t offset)
{
return pointer(m_address + offset);
}
// Lua API: Function
// Class: pointer
// Name: sub
// Param: offset: integer: offset
// Returns: pointer: new pointer object.
// Subs an offset to the current memory address and returns a new pointer object.
pointer sub(uint64_t offset)
{
return pointer(m_address - offset);
}
// Lua API: Function
// Class: pointer
// Name: rip
// Param: offset: integer: offset
// Returns: pointer: new pointer object.
// Rips the current memory address and returns a new pointer object.
pointer rip()
{
return add(*(std::int32_t*)m_address).add(4);
}
// Lua API: Function
// Class: pointer
// Name: get_byte
// Returns: number: the value stored at the memory address as the specified type.
// Retrieves the value stored at the memory address as the specified type.
// Lua API: Function
// Class: pointer
// Name: get_word
// Returns: number: the value stored at the memory address as the specified type.
// Retrieves the value stored at the memory address as the specified type.
// Lua API: Function
// Class: pointer
// Name: get_dword
// Returns: number: the value stored at the memory address as the specified type.
// Retrieves the value stored at the memory address as the specified type.
// Lua API: Function
// Class: pointer
// Name: get_float
// Returns: float: the value stored at the memory address as the specified type.
// Retrieves the value stored at the memory address as the specified type.
// Lua API: Function
// Class: pointer
// Name: get_qword
// Returns: number: the value stored at the memory address as the specified type.
// Retrieves the value stored at the memory address as the specified type.
template<typename T>
T get()
{
return *(T*)m_address;
}
// Lua API: Function
// Class: pointer
// Name: set_byte
// Param: value: number: new value.
// Sets the value at the memory address to the specified value of the given type.
// Lua API: Function
// Class: pointer
// Name: set_word
// Param: value: number: new value.
// Sets the value at the memory address to the specified value of the given type.
// Lua API: Function
// Class: pointer
// Name: set_dword
// Param: value: number: new value.
// Sets the value at the memory address to the specified value of the given type.
// Lua API: Function
// Class: pointer
// Name: set_float
// Param: value: float: new value.
// Sets the value at the memory address to the specified value of the given type.
// Lua API: Function
// Class: pointer
// Name: set_qword
// Param: value: number: new value.
// Sets the value at the memory address to the specified value of the given type.
template<typename T>
void set(T value)
{
*(T*)m_address = value;
}
// Lua API: Function
// Class: pointer
// Name: get_string
// Returns: string: the value stored at the memory address as the specified type.
// Retrieves the value stored at the memory address as the specified type.
std::string get_string()
{
return std::string((char*)m_address);
}
// Lua API: Function
// Class: pointer
// Name: set_string
// Param: value: string: new value.
// Sets the value at the memory address to the specified value of the given type.
void set_string(const std::string& string, int max_length)
{
strncpy((char*)m_address, string.data(), max_length);
}
// Lua API: Function
// Class: pointer
// Name: patch_byte
// Param: value: number: new value.
// Returns: lua_patch: memory patch instance for modifying the value at the memory address with the specified value. Can call apply / restore on the object.
// Creates a memory patch for modifying the value at the memory address with the specified value.
// The modified value is applied when you call the apply function on the lua_patch object.
// The original value is restored when you call the restore function on the lua_patch object.
// Lua API: Function
// Class: pointer
// Name: patch_word
// Param: value: number: new value.
// Returns: lua_patch: memory patch instance for modifying the value at the memory address with the specified value. Can call apply / restore on the object.
// Creates a memory patch for modifying the value at the memory address with the specified value.
// The modified value is applied when you call the apply function on the lua_patch object.
// The original value is restored when you call the restore function on the lua_patch object.
// Lua API: Function
// Class: pointer
// Name: patch_dword
// Param: value: number: new value.
// Returns: lua_patch: memory patch instance for modifying the value at the memory address with the specified value. Can call apply / restore on the object.
// Creates a memory patch for modifying the value at the memory address with the specified value.
// The modified value is applied when you call the apply function on the lua_patch object.
// The original value is restored when you call the restore function on the lua_patch object.
// Lua API: Function
// Class: pointer
// Name: patch_qword
// Param: value: number: new value.
// Returns: lua_patch: memory patch instance for modifying the value at the memory address with the specified value. Can call apply / restore on the object.
// Creates a memory patch for modifying the value at the memory address with the specified value.
// The modified value is applied when you call the apply function on the lua_patch object.
// The original value is restored when you call the restore function on the lua_patch object.
template<typename T>
big::lua_patch* patch(T value, sol::this_state state)
{
@ -69,31 +202,82 @@ namespace lua::memory
return raw;
}
// Lua API: Function
// Class: pointer
// Name: is_null
// Returns: boolean: Returns true if the address is null.
bool is_null()
{
return m_address == 0;
}
// Lua API: Function
// Class: pointer
// Name: is_valid
// Returns: boolean: Returns true if the address is not null.
bool is_valid()
{
return !is_null();
}
// Lua API: Function
// Class: pointer
// Name: deref
// Returns: pointer: A new pointer object pointing to the value at that address.
// Dereferences the memory address and returns a new pointer object pointing to the value at that address.
pointer deref()
{
return pointer(*(uint64_t*)m_address);
}
// Lua API: Function
// Class: pointer
// Name: get_address
// Returns: number: The memory address stored in the pointer object as a number.
// Retrieves the memory address stored in the pointer object.
uint64_t get_address() const
{
return m_address;
}
};
// Lua API: Table
// Name: memory
// Table containing helper functions related to process memory.
// Lua API: Function
// Table: memory
// Name: scan_pattern
// Param: pattern: string: byte pattern (IDA format)
// Returns: pointer: A pointer to the found address.
// Scans the specified memory pattern within the "GTA5.exe" module and returns a pointer to the found address.
pointer scan_pattern(const std::string& pattern);
// Lua API: Function
// Table: memory
// Name: handle_to_ptr
// Param: entity: number: script game entity handle
// Returns: pointer: A rage::CDynamicEntity pointer to the script game entity handle
pointer handle_to_ptr(int entity);
// Lua API: Function
// Table: memory
// Name: ptr_to_handle
// Param: mem_addr: pointer: A rage::CDynamicEntity pointer.
// Returns: number: The script game entity handle linked to the given rage::CDynamicEntity pointer.
int ptr_to_handle(pointer mem_addr);
// Lua API: Function
// Table: memory
// Name: allocate
// Param: size: integer: The number of bytes to allocate on the heap.
// Returns: pointer: A pointer to the newly allocated memory.
pointer allocate(int size, sol::this_state state);
// Lua API: Function
// Table: memory
// Name: free
// Param: ptr: pointer: The pointer that must be freed.
void free(pointer ptr, sol::this_state state);
static void bind(sol::state& state)

View File

@ -20,15 +20,84 @@ inline std::vector<elementType> convert_sequence(sol::table t)
namespace lua::network
{
// Lua API: Table
// Name: network
// Table containing helper functions for network related features.
// Lua API: Function
// Table: network
// Name: trigger_script_event
// Param: bitset: integer
// Param: _args: table
// Call trigger_script_event (TSE)
void trigger_script_event(int bitset, sol::table _args);
// Lua API: Function
// Table: network
// Name: give_pickup_rewards
// Param: player: integer: Index of the player.
// Param: reward: integer: Index of the reward pickup.
// Give the given pickup reward to the given player.
void give_pickup_rewards(int player, int reward);
// Lua API: Function
// Table: network
// Name: set_player_coords
// Param: player_idx: integer: Index of the player.
// Param: x: float: New x position.
// Param: y: float: New y position.
// Param: z: float: New z position.
// Teleport the given player to the given position.
void set_player_coords(int player_idx, float x, float y, float z);
// Lua API: Function
// Table: network
// Name: set_all_player_coords
// Param: x: float: New x position.
// Param: y: float: New y position.
// Param: z: float: New z position.
// Teleport all players to the given position.
void set_all_player_coords(float x, float y, float z);
// Lua API: Function
// Table: network
// Name: get_selected_player
// Returns: integer: Returns the index of the currently selected player in the GUI.
int get_selected_player();
// Lua API: Function
// Table: network
// Name: get_selected_database_player_rockstar_id
// Returns: integer: Returns the rockstar id of the currently selected player in the GUI.
int get_selected_database_player_rockstar_id();
// Lua API: Function
// Table: network
// Name: flag_player_as_modder
// Param: player_idx: integer: Index of the player.
// Flags the given player as a modder in our local database.
void flag_player_as_modder(int player_idx);
// Lua API: Function
// Table: network
// Name: is_player_flagged_as_modder
// Param: player_idx: integer: Index of the player.
// Returns: boolean: Returns true if the given player is flagged as a modder.
bool is_player_flagged_as_modder(int player_idx);
// 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.
void force_script_host(const std::string& script_name);
// Lua API: Function
// Table: network
// Name: send_chat_message
// Param: msg: string: Message to be sent.
// Param: team_only: boolean: Should be true if the msg should only be sent to our team.
// Sends a message to the in game chat.
void send_chat_message(const std::string& msg, bool team_only);
static void bind(sol::state& state)

View File

@ -6,6 +6,16 @@
namespace lua::script
{
// Lua API: Table
// Name: script
// Table containing helper functions related to gta scripts.
// Lua API: Function
// Table: script
// Name: register_looped
// Param: name: string: name of your new looped script
// Param: func: function: function that will be executed in a forever loop.
// Registers a function that will be looped as a gta script.
static void register_looped(const std::string& name, sol::function func, sol::this_state state)
{
auto module = sol::state_view(state)["!this"].get<big::lua_module*>();
@ -24,6 +34,11 @@ namespace lua::script
name)));
}
// Lua API: Function
// Table: script
// Name: run_in_fiber
// Param: func: function: function that will be executed once in the fiber pool, you can call natives inside it.
// Executes a function inside the fiber pool, you can call natives inside it.
static void run_in_fiber(sol::function func)
{
big::g_fiber_pool->queue_job([func] {
@ -33,11 +48,20 @@ namespace lua::script
});
}
// Lua API: Function
// Table: script
// Name: yield
// Yield execution.
static void yield()
{
big::script::get_current()->yield();
}
// Lua API: Function
// Table: script
// Name: sleep
// Param: ms: integer: The amount of time in milliseconds that we will sleep for.
// Sleep for the given amount of time, time is in milliseconds.
static void sleep(int ms)
{
big::script::get_current()->yield(std::chrono::milliseconds(ms));

View File

@ -3,6 +3,28 @@
namespace lua::tunables
{
// Lua API: Table
// Name: tunables
// Table for manipulating gta tunables.
// Lua API: Function
// Table: tunables
// Name: get_int
// Param: tunable_name: string: The name of the tunable.
// Returns: integer: The value of the given tunable.
// Lua API: Function
// Table: tunables
// Name: get_float
// Param: tunable_name: string: The name of the tunable.
// Returns: float: The value of the given tunable.
// Lua API: Function
// Table: tunables
// Name: get_bool
// Param: tunable_name: string: The name of the tunable.
// Returns: boolean: The value of the given tunable.
template<typename T>
static T get(const std::string tunable_name)
{
@ -12,6 +34,24 @@ namespace lua::tunables
return T();
}
// Lua API: Function
// Table: tunables
// Name: set_int
// Param: tunable_name: string: The name of the tunable.
// Param: val: integer: The new value of the given tunable.
// Lua API: Function
// Table: tunables
// Name: set_float
// Param: tunable_name: string: The name of the tunable.
// Param: val: float: The new value of the given tunable.
// Lua API: Function
// Table: tunables
// Name: set_bool
// Param: tunable_name: string: The name of the tunable.
// Param: val: boolean: The new value of the given tunable.
template<typename T>
static void set(const std::string tunable_name, T val)
{

View File

@ -3,6 +3,32 @@
namespace lua::vector
{
// Lua API: Class
// Name: vec3
// Class representing a 3D vector.
// Lua API: Constructor
// Class: vec3
// Param: x: float: x component of the vector.
// Param: y: float: y component of the vector.
// Param: z: float: z component of the vector.
// Returns a vector that contains the x, y, and z values.
// Lua API: Field
// Class: vec3
// Field: x: float
// x component of the vector.
// Lua API: Field
// Class: vec3
// Field: y: float
// y component of the vector.
// Lua API: Field
// Class: vec3
// Field: z: float
// z component of the vector.
static void bind(sol::state& state)
{
//clang-format off