mirror of
https://github.com/Mr-X-GTA/YimMenu.git
synced 2025-01-08 02:13:34 +08:00
feat(vehicle): Add turn signals (#239)
* Initial * Tiny update * More small fixes * Run in separate script. * whoops
This commit is contained in:
parent
0f09234130
commit
c081eda4c8
@ -73,6 +73,19 @@ namespace big
|
||||
|
||||
}
|
||||
|
||||
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";
|
||||
|
@ -48,6 +48,7 @@ namespace big
|
||||
static void vehicle_rainbow_paint();
|
||||
static void vehicle_seatbelt();
|
||||
static void vehicle_speedo_meter();
|
||||
static void vehicle_turn_signals();
|
||||
|
||||
static void weapons_ammo_special_type();
|
||||
static void weapons_cage_gun();
|
||||
|
176
BigBaseV2/src/backend/looped/vehicle/turn_signals.cpp
Normal file
176
BigBaseV2/src/backend/looped/vehicle/turn_signals.cpp
Normal file
@ -0,0 +1,176 @@
|
||||
#include "backend/looped/looped.hpp"
|
||||
#include "fiber_pool.hpp"
|
||||
#include "gta/enums.hpp"
|
||||
#include "natives.hpp"
|
||||
#include "script.hpp"
|
||||
#include "windows.h"
|
||||
|
||||
struct key_state
|
||||
{
|
||||
key_state(int v_key) : v_key(v_key) {}
|
||||
|
||||
enum
|
||||
{
|
||||
up,
|
||||
down,
|
||||
just_pressed,
|
||||
just_released,
|
||||
};
|
||||
|
||||
uint8_t state = up;
|
||||
int v_key;
|
||||
};
|
||||
|
||||
inline key_state right_signal_key{ 'L' };
|
||||
inline key_state left_signal_key{ 'J' };
|
||||
inline key_state hazzards_key{ 'K' };
|
||||
|
||||
bool is_key_pressed(int const v_key)
|
||||
{
|
||||
return GetAsyncKeyState(v_key) & 0x8000;
|
||||
}
|
||||
|
||||
void update_key_state(key_state& key_last_tick)
|
||||
{
|
||||
if (is_key_pressed(key_last_tick.v_key))
|
||||
{
|
||||
switch (key_last_tick.state)
|
||||
{
|
||||
case key_state::up:
|
||||
key_last_tick.state = key_state::just_pressed;
|
||||
break;
|
||||
|
||||
case key_state::just_pressed:
|
||||
key_last_tick.state = key_state::down;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (key_last_tick.state)
|
||||
{
|
||||
case key_state::down:
|
||||
key_last_tick.state = key_state::just_released;
|
||||
break;
|
||||
|
||||
case key_state::just_released:
|
||||
key_last_tick.state = key_state::up;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void update_key_states()
|
||||
{
|
||||
update_key_state(left_signal_key);
|
||||
update_key_state(hazzards_key);
|
||||
update_key_state(right_signal_key);
|
||||
}
|
||||
|
||||
struct signal_state {
|
||||
enum
|
||||
{
|
||||
right,
|
||||
left,
|
||||
hazzards
|
||||
};
|
||||
};
|
||||
|
||||
inline void set_turn_signals(int signal_state, bool on)
|
||||
{
|
||||
static constexpr int off = 0;
|
||||
|
||||
if (self::veh && big::g->vehicle.turn_signals)
|
||||
{
|
||||
switch (signal_state)
|
||||
{
|
||||
case signal_state::hazzards:
|
||||
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(self::veh, signal_state::left, on);
|
||||
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(self::veh, signal_state::right, on);
|
||||
break;
|
||||
|
||||
case signal_state::right:
|
||||
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(self::veh, signal_state::left, off);
|
||||
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(self::veh, signal_state::right, on);
|
||||
break;
|
||||
|
||||
case signal_state::left:
|
||||
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(self::veh, signal_state::left, on);
|
||||
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(self::veh, signal_state::right, off);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace big
|
||||
{
|
||||
static bool b_last_turn_signals = false;
|
||||
|
||||
void looped::vehicle_turn_signals()
|
||||
{
|
||||
static bool hazzards = false;
|
||||
bool b_turn_signals = g->vehicle.turn_signals;
|
||||
|
||||
if (!b_turn_signals && b_turn_signals != b_last_turn_signals)
|
||||
{
|
||||
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(PED::GET_VEHICLE_PED_IS_IN(PLAYER::PLAYER_PED_ID(), false), 0, 0);
|
||||
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(PED::GET_VEHICLE_PED_IS_IN(PLAYER::PLAYER_PED_ID(), false), 1, 0);
|
||||
}
|
||||
|
||||
if (g->vehicle.turn_signals)
|
||||
{
|
||||
static bool ran_once = []
|
||||
{
|
||||
g_notification_service->push("Instructions", "Manual: J = Left, L = Right, K = Toggle Hazzards");
|
||||
return true;
|
||||
}();
|
||||
}
|
||||
|
||||
|
||||
update_key_states();
|
||||
|
||||
if (left_signal_key.state == key_state::just_pressed || g->vehicle.auto_turn_signals && PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_LEFT_ONLY))
|
||||
{
|
||||
set_turn_signals(signal_state::left, true);
|
||||
}
|
||||
|
||||
if (right_signal_key.state == key_state::just_pressed || g->vehicle.auto_turn_signals && PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_RIGHT_ONLY))
|
||||
{
|
||||
set_turn_signals(signal_state::right, true);
|
||||
}
|
||||
|
||||
if (hazzards_key.state == key_state::just_pressed && !hazzards)
|
||||
{
|
||||
set_turn_signals(signal_state::hazzards, true);
|
||||
hazzards = true;
|
||||
}
|
||||
else if (hazzards_key.state == key_state::just_pressed && hazzards || !g->vehicle.turn_signals)
|
||||
{
|
||||
set_turn_signals(signal_state::hazzards, false);
|
||||
hazzards = false;
|
||||
}
|
||||
|
||||
|
||||
if (PAD::IS_CONTROL_JUST_RELEASED(0, (int)ControllerInputs::INPUT_VEH_MOVE_LEFT_ONLY))
|
||||
{
|
||||
if (g->vehicle.turn_signals)
|
||||
{
|
||||
script::get_current()->yield(1500ms);
|
||||
}
|
||||
set_turn_signals(signal_state::left, false);
|
||||
}
|
||||
|
||||
if (PAD::IS_CONTROL_JUST_RELEASED(0, (int)ControllerInputs::INPUT_VEH_MOVE_RIGHT_ONLY))
|
||||
{
|
||||
if (g->vehicle.turn_signals)
|
||||
{
|
||||
script::get_current()->yield(1500ms);
|
||||
}
|
||||
set_turn_signals(signal_state::right, false);
|
||||
}
|
||||
|
||||
b_last_turn_signals = g->vehicle.turn_signals;
|
||||
|
||||
}
|
||||
}
|
@ -207,18 +207,20 @@ namespace big
|
||||
|
||||
bool auto_drive_to_waypoint = false;
|
||||
bool auto_drive_wander = false;
|
||||
int auto_drive_speed = 1;
|
||||
bool auto_turn_signals = false;
|
||||
bool drive_on_water = false;
|
||||
int driving_style_id = 0;
|
||||
int driving_style_flags = 525116;
|
||||
bool god_mode = false;
|
||||
bool horn_boost = false;
|
||||
bool instant_brake = false;
|
||||
bool is_targetable = true;
|
||||
bool ls_customs = false; // don't save this to disk
|
||||
bool pv_teleport_into = false;
|
||||
int rainbow_paint = 0;
|
||||
bool seatbelt = false;
|
||||
bool turn_signals = false;
|
||||
int auto_drive_speed = 1;
|
||||
int driving_style_flags = 525116;
|
||||
int driving_style_id = 0;
|
||||
int rainbow_paint = 0;
|
||||
speedo_meter speedo_meter{};
|
||||
fly fly{};
|
||||
};
|
||||
@ -468,10 +470,11 @@ namespace big
|
||||
this->spoofing.username = j["spoofing"]["username"];
|
||||
|
||||
this->vehicle.auto_drive_speed = j["vehicle"]["auto_drive_speed"];
|
||||
this->vehicle.auto_drive_wander = j["vehicle"]["auto_drive_wander"];
|
||||
this->vehicle.auto_drive_to_waypoint = j["vehicle"]["auto_drive_to_waypoint"];
|
||||
this->vehicle.driving_style_id = j["vehicle"]["driving_style"];
|
||||
this->vehicle.auto_drive_wander = j["vehicle"]["auto_drive_wander"];
|
||||
this->vehicle.auto_turn_signals = j["vehicle"]["auto_turn_signals"];
|
||||
this->vehicle.drive_on_water = j["vehicle"]["drive_on_water"];
|
||||
this->vehicle.driving_style_id = j["vehicle"]["driving_style"];
|
||||
this->vehicle.god_mode = j["vehicle"]["god_mode"];
|
||||
this->vehicle.horn_boost = j["vehicle"]["horn_boost"];
|
||||
this->vehicle.instant_brake = j["vehicle"]["instant_brake"];
|
||||
@ -479,6 +482,7 @@ namespace big
|
||||
this->vehicle.pv_teleport_into = j["vehicle"]["pv_teleport_into"];
|
||||
this->vehicle.rainbow_paint = j["vehicle"]["rainbow_paint"];
|
||||
this->vehicle.seatbelt = j["vehicle"]["seatbelt"];
|
||||
this->vehicle.turn_signals = j["vehicle"]["turn_signals"];
|
||||
|
||||
this->vehicle.speedo_meter.type = (SpeedoMeter)j["vehicle"]["speedo_meter"]["type"];
|
||||
this->vehicle.speedo_meter.left_side = j["vehicle"]["speedo_meter"]["left_side"];
|
||||
@ -700,16 +704,18 @@ namespace big
|
||||
{
|
||||
"vehicle", {
|
||||
{ "auto_drive_speed", this->vehicle.auto_drive_speed },
|
||||
{ "auto_drive_wander", this->vehicle.auto_drive_wander },
|
||||
{ "driving_style", this->vehicle.driving_style_id },
|
||||
{ "auto_drive_to_waypoint", this->vehicle.auto_drive_to_waypoint },
|
||||
{ "auto_drive_wander", this->vehicle.auto_drive_wander },
|
||||
{ "auto_turn_signals", this->vehicle.auto_turn_signals },
|
||||
{ "drive_on_water", this->vehicle.drive_on_water },
|
||||
{ "driving_style", this->vehicle.driving_style_id },
|
||||
{ "god_mode", this->vehicle.god_mode },
|
||||
{ "horn_boost", this->vehicle.horn_boost },
|
||||
{ "instant_brake", this->vehicle.instant_brake },
|
||||
{ "is_targetable", this->vehicle.is_targetable },
|
||||
{ "pv_teleport_into", this->vehicle.pv_teleport_into },
|
||||
{ "rainbow_paint", this->vehicle.rainbow_paint },
|
||||
{ "turn_signals", this->vehicle.turn_signals },
|
||||
{ "seatbelt", this->vehicle.seatbelt },
|
||||
{
|
||||
"speedo_meter", {
|
||||
|
@ -47,6 +47,9 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
|
||||
"YimMenu",
|
||||
file_manager_instance->get_project_file("./cout.log")
|
||||
);
|
||||
|
||||
EnableMenuItem(GetSystemMenu(FindWindowA(NULL, "YimMenu"), 0), SC_CLOSE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
|
||||
|
||||
try
|
||||
{
|
||||
LOG(INFO) << "Yim's Menu Initializing";
|
||||
@ -90,6 +93,7 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
|
||||
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>(&context_menu_service::context_menu));
|
||||
LOG(INFO) << "Scripts registered.";
|
||||
|
||||
|
@ -44,6 +44,13 @@ namespace big
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
ImGui::Checkbox("Turn Signals", &g->vehicle.turn_signals);
|
||||
|
||||
if (g->vehicle.turn_signals)
|
||||
{
|
||||
ImGui::Checkbox("Fully Automatic Signal", &g->vehicle.auto_turn_signals);
|
||||
}
|
||||
|
||||
ImGui::EndGroup();
|
||||
|
||||
ImGui::Separator();
|
||||
|
Loading…
x
Reference in New Issue
Block a user