From 815d493530380d3ba011ac49ccb8f5abe05a1465 Mon Sep 17 00:00:00 2001 From: Yimura Date: Fri, 14 Jan 2022 16:12:30 +0100 Subject: [PATCH] feat(Vehicle): Added trigger LS Customs anywhere --- BigBaseV2/src/backend/backend.cpp | 5 ++ BigBaseV2/src/backend/looped/looped.hpp | 1 + .../src/backend/looped/vehicle/ls_customs.cpp | 81 +++++++++++++++++++ BigBaseV2/src/core/globals.hpp | 1 + BigBaseV2/src/gui/window/main/tab_vehicle.cpp | 10 +++ BigBaseV2/src/util/scripts.hpp | 47 +++++++++++ 6 files changed, 145 insertions(+) create mode 100644 BigBaseV2/src/backend/looped/vehicle/ls_customs.cpp create mode 100644 BigBaseV2/src/util/scripts.hpp diff --git a/BigBaseV2/src/backend/backend.cpp b/BigBaseV2/src/backend/backend.cpp index a19c733f..3aa40593 100644 --- a/BigBaseV2/src/backend/backend.cpp +++ b/BigBaseV2/src/backend/backend.cpp @@ -71,5 +71,10 @@ namespace big looped::vehicle_horn_boost(); looped::vehicle_speedo_meter(); }QUEUE_JOB_END_CLAUSE + + QUEUE_JOB_BEGIN_CLAUSE() + { + looped::vehicle_ls_customs(); + }QUEUE_JOB_END_CLAUSE } } \ No newline at end of file diff --git a/BigBaseV2/src/backend/looped/looped.hpp b/BigBaseV2/src/backend/looped/looped.hpp index 8a3d435e..7e5f9272 100644 --- a/BigBaseV2/src/backend/looped/looped.hpp +++ b/BigBaseV2/src/backend/looped/looped.hpp @@ -30,6 +30,7 @@ namespace big static void vehicle_despawn_bypass(); static void vehicle_god_mode(); static void vehicle_horn_boost(); + static void vehicle_ls_customs(); static void vehicle_speedo_meter(); static void weapons_cage_gun(); diff --git a/BigBaseV2/src/backend/looped/vehicle/ls_customs.cpp b/BigBaseV2/src/backend/looped/vehicle/ls_customs.cpp new file mode 100644 index 00000000..085362c1 --- /dev/null +++ b/BigBaseV2/src/backend/looped/vehicle/ls_customs.cpp @@ -0,0 +1,81 @@ +#include "backend/looped/looped.hpp" +#include "gta_util.hpp" +#include "script_local.hpp" +#include "util/math.hpp" +#include "util/notify.hpp" +#include "util/scripts.hpp" + +namespace big +{ + static bool state = false; + static bool busy = false; + + void looped::vehicle_ls_customs() + { + if (busy) return; + busy = true; + + constexpr int hash = RAGE_JOAAT("carmod_shop"); + if (g.vehicle.ls_customs && g.vehicle.ls_customs == state) + { + if ( + auto carmod_shop_thread = gta_util::find_script_thread(hash); + carmod_shop_thread && + *script_local(carmod_shop_thread, 726).at(11).as() != 4 + ) + { + g.vehicle.ls_customs = false; + + *script_local(carmod_shop_thread, 726).as() = 1; // cleanup + } + } + + if (g.vehicle.ls_customs && g.vehicle.ls_customs != state) + { + Vehicle veh = PED::GET_VEHICLE_PED_IS_USING(PLAYER::PLAYER_PED_ID()); + if (!ENTITY::DOES_ENTITY_EXIST(veh) || ENTITY::IS_ENTITY_DEAD(veh, false)) + { + busy = false; + g.vehicle.ls_customs = false; + + notify::above_map("You aren't in a vehicle."); + + return; + } + + scripts::request_script(hash); + if (scripts::wait_till_loaded(hash)) + { + int args[] = { 45, 0, 9 }; + scripts::start_script_with_args(hash, args, 3, 3600); + + scripts::wait_till_running(hash); + } + + if (scripts::is_running(hash)) + { + if (auto carmod_shop_thread = gta_util::find_script_thread(hash); carmod_shop_thread) + { + Vector3 loc = ENTITY::GET_ENTITY_COORDS(veh, 1); + Vector3 rot = ENTITY::GET_ENTITY_ROTATION(veh, 0); + float heading = ENTITY::GET_ENTITY_HEADING(veh); + + *script_local(carmod_shop_thread, 726).at(406).as() = veh; + *script_local(carmod_shop_thread, 2110).as() = false; // skips cutscene that's invisible + + *script_local(carmod_shop_thread, 726).at(11).as() = 4; + + for (int i = 0; math::distance_between_vectors(loc, ENTITY::GET_ENTITY_COORDS(veh, 1)) < 5.f && i < 300; i++) + script::get_current()->yield(10ms); + + ENTITY::SET_ENTITY_COORDS(veh, loc.x, loc.y, loc.z, 0, 0, 0, 0); + ENTITY::SET_ENTITY_HEADING(veh, heading); + VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(veh, 5.f); + } + } + } + + busy = false; + state = g.vehicle.ls_customs; + } +} \ No newline at end of file diff --git a/BigBaseV2/src/core/globals.hpp b/BigBaseV2/src/core/globals.hpp index fa9b4227..d8db4827 100644 --- a/BigBaseV2/src/core/globals.hpp +++ b/BigBaseV2/src/core/globals.hpp @@ -94,6 +94,7 @@ struct globals { bool god_mode = false; bool horn_boost = false; + bool ls_customs = false; // don't save this to disk speedo_meter speedo_meter{}; }; diff --git a/BigBaseV2/src/gui/window/main/tab_vehicle.cpp b/BigBaseV2/src/gui/window/main/tab_vehicle.cpp index c23c483b..65b4ba31 100644 --- a/BigBaseV2/src/gui/window/main/tab_vehicle.cpp +++ b/BigBaseV2/src/gui/window/main/tab_vehicle.cpp @@ -41,6 +41,16 @@ namespace big ImGui::TreePop(); } + if (ImGui::TreeNode("LS Customs")) + { + if (ImGui::Button("Start LS Customs")) + { + g.vehicle.ls_customs = true; + } + + ImGui::TreePop(); + } + if (ImGui::TreeNode("Speedo Meter")) { SpeedoMeter selected = g.vehicle.speedo_meter.type; diff --git a/BigBaseV2/src/util/scripts.hpp b/BigBaseV2/src/util/scripts.hpp new file mode 100644 index 00000000..50aaf165 --- /dev/null +++ b/BigBaseV2/src/util/scripts.hpp @@ -0,0 +1,47 @@ +#pragma once +#include "fiber_pool.hpp" +#include "natives.hpp" +#include "script.hpp" + +namespace big::scripts +{ + inline bool is_loaded(int hash) + { + return SCRIPT::HAS_SCRIPT_WITH_NAME_HASH_LOADED(hash); + } + + inline bool is_running(int hash) + { + return SCRIPT::DOES_SCRIPT_WITH_NAME_HASH_EXIST(hash); + } + + inline void request_script(int hash) + { + SCRIPT::REQUEST_SCRIPT_WITH_NAME_HASH(hash); + } + + inline int start_script_with_args(int hash, int* args, int arg_size, int stack_size) + { + int thread_id = SYSTEM::START_NEW_SCRIPT_WITH_NAME_HASH_AND_ARGS(hash, args, arg_size, stack_size); + SCRIPT::SET_SCRIPT_WITH_NAME_HASH_AS_NO_LONGER_NEEDED(hash); + return thread_id; + } + + inline bool wait_till_loaded(int hash) + { + if (is_loaded(hash)) return true; + for (int i = 0; i < 150 && !is_loaded(hash); i++) + script::get_current()->yield(10ms); + if (is_loaded(hash)) return true; + return false; + } + + inline bool wait_till_running(int hash) + { + if (is_running(hash)) return true; + for (int i = 0; i < 150 && !is_running(hash); i++) + script::get_current()->yield(10ms); + if (is_running(hash)) return true; + return false; + } +} \ No newline at end of file