Name and status variables for the Script system. (#244)
Co-authored-by: Yimura <andreas.maerten@scarlet.be>
This commit is contained in:
parent
a64f016412
commit
7bfc04bea0
@ -19,4 +19,176 @@ namespace big
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void backend::self_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Self";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::self_clean_player();
|
||||
looped::self_free_cam();
|
||||
looped::self_godmode();
|
||||
looped::self_invisibility();
|
||||
looped::self_no_ragdoll();
|
||||
looped::self_off_radar();
|
||||
looped::self_police();
|
||||
looped::self_super_run();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
void backend::weapons_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Weapons";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::weapons_ammo_special_type();
|
||||
looped::weapons_cage_gun();
|
||||
looped::weapons_delete_gun();
|
||||
looped::weapons_force_crosshairs();
|
||||
looped::weapons_gravity_gun();
|
||||
looped::weapons_increased_damage();
|
||||
looped::weapons_infinite_ammo();
|
||||
looped::weapons_infinite_mag();
|
||||
looped::weapons_no_recoil();
|
||||
looped::weapons_no_spread();
|
||||
looped::weapons_repair_gun();
|
||||
looped::weapons_steal_vehicle_gun();
|
||||
looped::weapons_vehicle_gun();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
void backend::vehicles_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Vehicles";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::vehicle_auto_drive_to_waypoint();
|
||||
looped::vehicle_auto_drive_wander();
|
||||
looped::vehicle_despawn_bypass();
|
||||
looped::vehicle_drive_on_water();
|
||||
looped::vehicle_god_mode();
|
||||
looped::vehicle_horn_boost();
|
||||
looped::vehicle_jump();
|
||||
looped::vehicle_instant_brake();
|
||||
looped::vehicle_is_targetable();
|
||||
looped::vehicle_rainbow_paint();
|
||||
looped::vehicle_seatbelt();
|
||||
looped::vehicle_speedo_meter();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
void backend::turnsignal_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: turnsignal";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::vehicle_turn_signals();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
void backend::rgbrandomizer_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: rgbrandomizer";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::rgb_synced_fade();
|
||||
looped::rgb_synced_spasm();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
void backend::misc_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Miscellaneous";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::hud_transition_state();
|
||||
looped::tunables_disable_phone();
|
||||
looped::tunables_no_idle_kick();
|
||||
looped::session_local_time();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
void backend::remote_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Remote";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::player_never_wanted();
|
||||
looped::player_spectate();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
void backend::noclip_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: No clip";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::self_noclip();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
void backend::lscustoms_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Ls customs";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::vehicle_ls_customs();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
void backend::vehiclefly_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Vehicle fly";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::vehicle_fly();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
void backend::disable_control_action_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Disable Control Action";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::self_free_cam_disable_control_action();
|
||||
looped::self_noclip_disable_control_action();
|
||||
|
||||
looped::custom_gun_disable_control_action();
|
||||
|
||||
context_menu_service::disable_control_action_loop();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,177 +10,16 @@ namespace big
|
||||
{
|
||||
public:
|
||||
static void loop();
|
||||
|
||||
static void self_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Self";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::self_clean_player();
|
||||
looped::self_free_cam();
|
||||
looped::self_godmode();
|
||||
looped::self_invisibility();
|
||||
looped::self_no_ragdoll();
|
||||
looped::self_off_radar();
|
||||
looped::self_police();
|
||||
looped::self_super_run();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
static void weapons_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Weapons";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::weapons_ammo_special_type();
|
||||
looped::weapons_cage_gun();
|
||||
looped::weapons_delete_gun();
|
||||
looped::weapons_force_crosshairs();
|
||||
looped::weapons_gravity_gun();
|
||||
looped::weapons_increased_damage();
|
||||
looped::weapons_infinite_ammo();
|
||||
looped::weapons_infinite_mag();
|
||||
looped::weapons_no_recoil();
|
||||
looped::weapons_no_spread();
|
||||
looped::weapons_repair_gun();
|
||||
looped::weapons_steal_vehicle_gun();
|
||||
looped::weapons_vehicle_gun();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
static void vehicles_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Vehicles";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::vehicle_auto_drive_to_waypoint();
|
||||
looped::vehicle_auto_drive_wander();
|
||||
looped::vehicle_despawn_bypass();
|
||||
looped::vehicle_drive_on_water();
|
||||
looped::vehicle_god_mode();
|
||||
looped::vehicle_horn_boost();
|
||||
looped::vehicle_jump();
|
||||
looped::vehicle_instant_brake();
|
||||
looped::vehicle_is_targetable();
|
||||
looped::vehicle_rainbow_paint();
|
||||
looped::vehicle_seatbelt();
|
||||
looped::vehicle_speedo_meter();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
static void turnsignal_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: turnsignal";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::vehicle_turn_signals();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
static void rgbrandomizer_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: rgbrandomizer";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::rgb_synced_fade();
|
||||
looped::rgb_synced_spasm();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
static void misc_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Miscellaneous";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::hud_transition_state();
|
||||
looped::tunables_disable_phone();
|
||||
looped::tunables_no_idle_kick();
|
||||
looped::session_local_time();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
static void remote_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Remote";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::player_never_wanted();
|
||||
looped::player_spectate();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
static void noclip_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: No clip";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::self_noclip();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
static void lscustoms_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Ls customs";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::vehicle_ls_customs();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
static void vehiclefly_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Vehicle fly";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::vehicle_fly();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
||||
static void disable_control_action_loop()
|
||||
{
|
||||
LOG(INFO) << "Starting script: Disable Control Action";
|
||||
|
||||
while (g_running)
|
||||
{
|
||||
looped::self_free_cam_disable_control_action();
|
||||
looped::self_noclip_disable_control_action();
|
||||
|
||||
looped::custom_gun_disable_control_action();
|
||||
|
||||
context_menu_service::disable_control_action_loop();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
static void self_loop();
|
||||
static void weapons_loop();
|
||||
static void vehicles_loop();
|
||||
static void turnsignal_loop();
|
||||
static void rgbrandomizer_loop();
|
||||
static void misc_loop();
|
||||
static void remote_loop();
|
||||
static void noclip_loop();
|
||||
static void lscustoms_loop();
|
||||
static void vehiclefly_loop();
|
||||
static void disable_control_action_loop();
|
||||
};
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "common.hpp"
|
||||
#include "common.hpp"
|
||||
#include "core/globals.hpp"
|
||||
#include "features.hpp"
|
||||
#include "fiber_pool.hpp"
|
||||
@ -81,21 +81,21 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
|
||||
auto gui_service_instance = std::make_unique<gui_service>();
|
||||
LOG(INFO) << "Registered service instances...";
|
||||
|
||||
g_script_mgr.add_script(std::make_unique<script>(&features::script_func));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&gui::script_func));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&features::script_func, "Backend Main", false));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&gui::script_func, "GUI", false));
|
||||
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::self_loop));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::weapons_loop));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::vehicles_loop));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::misc_loop));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::remote_loop));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::noclip_loop));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::lscustoms_loop));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::vehiclefly_loop));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::rgbrandomizer_loop));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::turnsignal_loop));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::disable_control_action_loop));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&context_menu_service::context_menu));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::self_loop, "Self"));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::weapons_loop, "Weapon"));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::vehicles_loop, "Vehicle"));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::misc_loop, "Miscellaneous"));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::remote_loop, "Remote"));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::noclip_loop, "No Clip"));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::lscustoms_loop, "LS Customs"));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::vehiclefly_loop, "Vehicle Fly"));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::rgbrandomizer_loop, "RGB Randomizer"));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::turnsignal_loop, "Turn Signals"));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&backend::disable_control_action_loop, "Disable Controls"));
|
||||
g_script_mgr.add_script(std::make_unique<script>(&context_menu_service::context_menu, "Context Menu"));
|
||||
LOG(INFO) << "Scripts registered.";
|
||||
|
||||
auto native_hooks_instance = std::make_unique<native_hooks>();
|
||||
|
@ -18,10 +18,19 @@ namespace big
|
||||
LOG(FATAL) << "Exception Code: " << HEX_TO_UPPER(exp->ExceptionRecord->ExceptionCode) << " Exception Offset: " << HEX_TO_UPPER(offset) << " Fault Module Name: " << buffer;
|
||||
}
|
||||
|
||||
script::script(func_t func, std::optional<std::size_t> stack_size) :
|
||||
m_func(func),
|
||||
script::script(const func_t func, const std::string_view name, const bool toggleable, const std::optional<std::size_t> stack_size) :
|
||||
script(func, stack_size)
|
||||
{
|
||||
m_name = name;
|
||||
m_toggleable = toggleable;
|
||||
}
|
||||
|
||||
script::script(const func_t func, const std::optional<std::size_t> stack_size) :
|
||||
m_enabled(true),
|
||||
m_toggleable(false),
|
||||
m_script_fiber(nullptr),
|
||||
m_main_fiber(nullptr)
|
||||
m_main_fiber(nullptr),
|
||||
m_func(func)
|
||||
{
|
||||
m_script_fiber = CreateFiber(stack_size.has_value() ? stack_size.value() : 0, [](void* param)
|
||||
{
|
||||
@ -36,6 +45,32 @@ namespace big
|
||||
DeleteFiber(m_script_fiber);
|
||||
}
|
||||
|
||||
const char* script::name() const
|
||||
{
|
||||
return m_name.data();
|
||||
}
|
||||
|
||||
bool script::is_enabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
void script::set_enabled(const bool toggle)
|
||||
{
|
||||
if (m_toggleable)
|
||||
m_enabled = toggle;
|
||||
}
|
||||
|
||||
bool* script::toggle_ptr()
|
||||
{
|
||||
return &m_enabled;
|
||||
}
|
||||
|
||||
bool script::is_toggleable() const
|
||||
{
|
||||
return m_toggleable;
|
||||
}
|
||||
|
||||
void script::tick()
|
||||
{
|
||||
m_main_fiber = GetCurrentFiber();
|
||||
@ -71,7 +106,6 @@ namespace big
|
||||
m_func();
|
||||
}
|
||||
EXCEPT_CLAUSE
|
||||
|
||||
[]() {
|
||||
LOG(INFO) << "Script finished!";
|
||||
}();
|
||||
|
@ -5,18 +5,33 @@ namespace big
|
||||
{
|
||||
class script
|
||||
{
|
||||
std::string_view m_name;
|
||||
bool m_enabled;
|
||||
bool m_toggleable;
|
||||
|
||||
public:
|
||||
using func_t = void(*)();
|
||||
|
||||
public:
|
||||
explicit script(func_t func, std::optional<std::size_t> stack_size = std::nullopt);
|
||||
explicit script(const func_t func, const std::string_view name, const bool toggleable = true, const std::optional<std::size_t> stack_size = std::nullopt);
|
||||
explicit script(const func_t func, const std::optional<std::size_t> stack_size = std::nullopt);
|
||||
~script();
|
||||
|
||||
[[nodiscard]] const char* name() const;
|
||||
[[nodiscard]] bool is_enabled() const;
|
||||
void set_enabled(const bool toggle);
|
||||
[[nodiscard]] bool* toggle_ptr();
|
||||
|
||||
[[nodiscard]] bool is_toggleable() const;
|
||||
|
||||
void tick();
|
||||
void yield(std::optional<std::chrono::high_resolution_clock::duration> time = std::nullopt);
|
||||
static script* get_current();
|
||||
static void script_exception_handler(PEXCEPTION_POINTERS exp);
|
||||
|
||||
private:
|
||||
void fiber_func();
|
||||
|
||||
private:
|
||||
void* m_script_fiber;
|
||||
void* m_main_fiber;
|
||||
|
@ -21,6 +21,11 @@ namespace big
|
||||
m_scripts.clear();
|
||||
}
|
||||
|
||||
script_list& script_mgr::scripts()
|
||||
{
|
||||
return m_scripts;
|
||||
}
|
||||
|
||||
void script_mgr::tick()
|
||||
{
|
||||
gta_util::execute_as_script(RAGE_JOAAT("main_persistent"), std::mem_fn(&script_mgr::tick_internal), this);
|
||||
@ -33,8 +38,7 @@ namespace big
|
||||
|
||||
std::lock_guard lock(m_mutex);
|
||||
for (auto const& script : m_scripts)
|
||||
{
|
||||
if (script->is_enabled())
|
||||
script->tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
namespace big
|
||||
{
|
||||
using script_list = std::vector<std::unique_ptr<script>>;
|
||||
|
||||
class script_mgr
|
||||
{
|
||||
public:
|
||||
@ -13,12 +15,14 @@ namespace big
|
||||
void add_script(std::unique_ptr<script> script);
|
||||
void remove_all_scripts();
|
||||
|
||||
script_list& scripts();
|
||||
|
||||
void tick();
|
||||
private:
|
||||
void tick_internal();
|
||||
private:
|
||||
std::recursive_mutex m_mutex;
|
||||
std::vector<std::unique_ptr<script>> m_scripts;
|
||||
script_list m_scripts;
|
||||
};
|
||||
|
||||
inline script_mgr g_script_mgr;
|
||||
|
@ -185,24 +185,16 @@ namespace big
|
||||
const auto cm = g_context_menu_service->get_context_menu();
|
||||
if (cm == nullptr)
|
||||
{
|
||||
script::get_current()->yield();
|
||||
|
||||
continue;
|
||||
g_context_menu_service->enabled = !g_context_menu_service->enabled;
|
||||
}
|
||||
|
||||
if (PAD::IS_DISABLED_CONTROL_JUST_PRESSED(0, (int)ControllerInputs::INPUT_WEAPON_WHEEL_NEXT))
|
||||
cm->current_option = cm->options.size() <= cm->current_option + 1 ? 0 : cm->current_option + 1;
|
||||
if (PAD::IS_DISABLED_CONTROL_JUST_PRESSED(0, (int)ControllerInputs::INPUT_WEAPON_WHEEL_PREV))
|
||||
cm->current_option = 0 > cm->current_option - 1 ? static_cast<int>(cm->options.size()) - 1 : cm->current_option - 1;
|
||||
if (PAD::IS_DISABLED_CONTROL_JUST_PRESSED(0, (int)ControllerInputs::INPUT_ATTACK) ||
|
||||
PAD::IS_DISABLED_CONTROL_JUST_PRESSED(0, (int)ControllerInputs::INPUT_SPECIAL_ABILITY))
|
||||
if (g_context_menu_service->enabled)
|
||||
{
|
||||
if (!g_context_menu_service->m_pointer)
|
||||
continue;
|
||||
cm->options.at(cm->current_option).command();
|
||||
}
|
||||
}
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,30 @@
|
||||
#include "views/view.hpp"
|
||||
#include "widgets/imgui_hotkey.hpp"
|
||||
#include "script_mgr.hpp"
|
||||
#include "services/notification_service.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
void view::settings() {
|
||||
void scripts_popupmodal()
|
||||
{
|
||||
ImGui::BeginGroup();
|
||||
components::small_text("Scripts");
|
||||
ImGui::SameLine(ImGui::GetWindowWidth() - 100);
|
||||
if (ImGui::Button("Close")) ImGui::CloseCurrentPopup();
|
||||
ImGui::Spacing();
|
||||
components::small_text("These scripts are responsible for all looped features.\nOnly disable if you know what you are doing.");
|
||||
|
||||
for (const auto& script : g_script_mgr.scripts()) {
|
||||
if (script->is_toggleable())
|
||||
if (ImGui::Checkbox(script->name(), script->toggle_ptr()))
|
||||
g_notification_service->push(std::string(script->name()).append(" script"), script->is_enabled() ? "Resumed" : "Halted");
|
||||
}
|
||||
|
||||
ImGui::EndGroup();
|
||||
}
|
||||
|
||||
void view::settings()
|
||||
{
|
||||
components::small_text("Hotkeys");
|
||||
|
||||
ImGui::PushItemWidth(350.f);
|
||||
@ -15,5 +36,19 @@ namespace big
|
||||
ImGui::Hotkey("Teleport to waypoint", &g->settings.hotkeys.teleport_waypoint);
|
||||
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::Button("Manage scripts"))
|
||||
ImGui::OpenPopup("Scripts");
|
||||
|
||||
ImGui::SetNextWindowPos({ 780,228 }, ImGuiCond_FirstUseEver);
|
||||
if (ImGui::BeginPopupModal("Scripts", nullptr, ImGuiWindowFlags_AlwaysAutoResize))
|
||||
{
|
||||
scripts_popupmodal();
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user