feat(Vehicle): Added trigger LS Customs anywhere

This commit is contained in:
Yimura 2022-01-14 16:12:30 +01:00
parent 5ae57e75e4
commit d6929d4efc
No known key found for this signature in database
GPG Key ID: 3D8FF4397E768682
6 changed files with 145 additions and 0 deletions

View File

@ -71,5 +71,10 @@ namespace big
looped::vehicle_horn_boost(); looped::vehicle_horn_boost();
looped::vehicle_speedo_meter(); looped::vehicle_speedo_meter();
}QUEUE_JOB_END_CLAUSE }QUEUE_JOB_END_CLAUSE
QUEUE_JOB_BEGIN_CLAUSE()
{
looped::vehicle_ls_customs();
}QUEUE_JOB_END_CLAUSE
} }
} }

View File

@ -30,6 +30,7 @@ namespace big
static void vehicle_despawn_bypass(); static void vehicle_despawn_bypass();
static void vehicle_god_mode(); static void vehicle_god_mode();
static void vehicle_horn_boost(); static void vehicle_horn_boost();
static void vehicle_ls_customs();
static void vehicle_speedo_meter(); static void vehicle_speedo_meter();
static void weapons_cage_gun(); static void weapons_cage_gun();

View File

@ -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<int*>() != 4
)
{
g.vehicle.ls_customs = false;
*script_local(carmod_shop_thread, 726).as<int*>() = 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<int*>() = veh;
*script_local(carmod_shop_thread, 2110).as<bool*>() = false; // skips cutscene that's invisible
*script_local(carmod_shop_thread, 726).at(11).as<int*>() = 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;
}
}

View File

@ -94,6 +94,7 @@ struct globals {
bool god_mode = false; bool god_mode = false;
bool horn_boost = false; bool horn_boost = false;
bool ls_customs = false; // don't save this to disk
speedo_meter speedo_meter{}; speedo_meter speedo_meter{};
}; };

View File

@ -41,6 +41,16 @@ namespace big
ImGui::TreePop(); 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")) if (ImGui::TreeNode("Speedo Meter"))
{ {
SpeedoMeter selected = g.vehicle.speedo_meter.type; SpeedoMeter selected = g.vehicle.speedo_meter.type;

View File

@ -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;
}
}