From a9dbfdd138c521c22f20c0abeccfe7a8acc3c9eb Mon Sep 17 00:00:00 2001 From: Maddy <59680197+xM4ddy@users.noreply.github.com> Date: Tue, 24 May 2022 15:59:25 -0400 Subject: [PATCH] Improved auto drive (#196) * Improved logic to handle changes mid drive. Changed default styles. Split to waypoint and wander into two separate files for readability * Fixed type to remove the hideous warnings * Fixes * wfvaenhiuefcsnhiojmfhnevioshnuefvsihnoijmefmvschnfvecshnfevSC * iNcLuDeS aLpHaBeTiCaLlY --- BigBaseV2/src/backend/backend.cpp | 6 +- BigBaseV2/src/backend/backend.hpp | 9 +- BigBaseV2/src/backend/looped/looped.hpp | 3 +- .../src/backend/looped/vehicle/auto_drive.cpp | 115 ------------------ .../looped/vehicle/auto_drive_to_waypoint.cpp | 95 +++++++++++++++ .../looped/vehicle/auto_drive_wander.cpp | 70 +++++++++++ BigBaseV2/src/core/globals.hpp | 2 +- BigBaseV2/src/util/vehicle.hpp | 6 +- BigBaseV2/src/views/vehicle/view_vehicle.cpp | 25 ++-- 9 files changed, 193 insertions(+), 138 deletions(-) delete mode 100644 BigBaseV2/src/backend/looped/vehicle/auto_drive.cpp create mode 100644 BigBaseV2/src/backend/looped/vehicle/auto_drive_to_waypoint.cpp create mode 100644 BigBaseV2/src/backend/looped/vehicle/auto_drive_wander.cpp diff --git a/BigBaseV2/src/backend/backend.cpp b/BigBaseV2/src/backend/backend.cpp index 29d08543..0ffd9d1e 100644 --- a/BigBaseV2/src/backend/backend.cpp +++ b/BigBaseV2/src/backend/backend.cpp @@ -16,9 +16,9 @@ namespace big if (g_local_player != nullptr && !api::util::signed_in()) { g_thread_pool->push([] - { - looped::api_login_session(); - }); + { + looped::api_login_session(); + }); } } } diff --git a/BigBaseV2/src/backend/backend.hpp b/BigBaseV2/src/backend/backend.hpp index 888b53db..bef22c8f 100644 --- a/BigBaseV2/src/backend/backend.hpp +++ b/BigBaseV2/src/backend/backend.hpp @@ -56,7 +56,8 @@ namespace big LOG(INFO) << "Starting script: Vehicles"; while (g_running) { - looped::vehicle_auto_drive(); + looped::vehicle_auto_drive_to_waypoint(); + looped::vehicle_auto_drive_wander(); looped::vehicle_despawn_bypass(); looped::vehicle_drive_on_water(); looped::vehicle_god_mode(); @@ -66,7 +67,7 @@ namespace big looped::vehicle_rainbow_paint(); looped::vehicle_seatbelt(); looped::vehicle_speedo_meter(); - + script::get_current()->yield(); } @@ -105,7 +106,7 @@ namespace big LOG(INFO) << "Starting script: Miscellaneous"; while (g_running) { - + looped::hud_transition_state(); looped::tunables_disable_phone(); looped::tunables_no_idle_kick(); @@ -170,4 +171,4 @@ namespace big } }; -} \ No newline at end of file +} diff --git a/BigBaseV2/src/backend/looped/looped.hpp b/BigBaseV2/src/backend/looped/looped.hpp index c3dc2eaf..1d97e40e 100644 --- a/BigBaseV2/src/backend/looped/looped.hpp +++ b/BigBaseV2/src/backend/looped/looped.hpp @@ -36,7 +36,8 @@ namespace big static void system_self_globals(); static void system_update_pointers(); - static void vehicle_auto_drive(); + static void vehicle_auto_drive_to_waypoint(); + static void vehicle_auto_drive_wander(); static void vehicle_despawn_bypass(); static void vehicle_drive_on_water(); static void vehicle_fly(); diff --git a/BigBaseV2/src/backend/looped/vehicle/auto_drive.cpp b/BigBaseV2/src/backend/looped/vehicle/auto_drive.cpp deleted file mode 100644 index b48d3e83..00000000 --- a/BigBaseV2/src/backend/looped/vehicle/auto_drive.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include "backend/looped/looped.hpp" -#include "natives.hpp" -#include "util/blip.hpp" -#include "util/entity.hpp" -#include "gta/enums.hpp" - -namespace big -{ - void looped::vehicle_auto_drive() - { - Vehicle vehicle = self::veh; - Ped ped = self::ped; - static Vector3 location; - static bool running = true; - static bool wandering = true; - static bool ran_once = false; - - if (g->vehicle.auto_drive_to_waypoint) - { - running = false; - ran_once = true; - - if (!blip::get_blip_location(location, (int)BlipIcons::Waypoint)) - { - g_notification_service->push_warning("Warning", "No Waypoint found please set one first."); - g->vehicle.auto_drive_to_waypoint = false; - } - else if (!vehicle) - { - g_notification_service->push_warning("Warning", "Please be in a car first then try again."); - } - else - { - blip::get_blip_location(location, (int)BlipIcons::Waypoint); - - g_notification_service->push_warning("Auto Drive", "Starting Route To Destination"); - - g_notification_service->push_warning("Auto Drive", "Start driving or leave car to take back control."); - - TASK::CLEAR_VEHICLE_TASKS_(vehicle); - - TASK::TASK_VEHICLE_DRIVE_TO_COORD(ped, vehicle, location.x, location.y, location.z, - static_cast(g->vehicle.auto_drive_speed), 5, ENTITY::GET_ENTITY_MODEL(vehicle), g->vehicle.driving_style_flags, 20, true); - - g->vehicle.auto_drive_to_waypoint = false; - - running = true; - } - } - - if (g->vehicle.auto_drive_wander) - { - ran_once = true; - wandering = false; - - if (!vehicle) - { - g_notification_service->push_warning("Warning", "Please be in a car first then try again."); - - g->vehicle.auto_drive_wander = false; - - TASK::CLEAR_VEHICLE_TASKS_(vehicle); - } - else - { - g->vehicle.auto_drive_wander = false; - - TASK::CLEAR_VEHICLE_TASKS_(vehicle); - - TASK::CLEAR_PED_TASKS(ped); - - TASK::TASK_VEHICLE_DRIVE_WANDER(ped, vehicle, static_cast(g->vehicle.auto_drive_speed), g->vehicle.driving_style_flags); - - wandering = true; - - g_notification_service->push_warning("Starting Wondering", "Start driving or leave car to take back control."); - } - } - - if (wandering && ran_once) - { - if (PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_LEFT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_RIGHT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_ACCELERATE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_BRAKE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_EXIT) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_HANDBRAKE)) - { - TASK::CLEAR_VEHICLE_TASKS_(vehicle); - TASK::CLEAR_PED_TASKS(ped); - g_notification_service->push_warning("Warning", "Wandering Stopped"); - g->vehicle.auto_drive_wander = false; - wandering = false; - } - } - - if (running) - { - if (!blip::get_blip_location(location, (int)BlipIcons::Waypoint) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_LEFT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_RIGHT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_ACCELERATE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_BRAKE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_EXIT) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_HANDBRAKE)) - { - if (!blip::get_blip_location(location, (int)BlipIcons::Waypoint)) - { - VEHICLE::SET_VEHICLE_FORWARD_SPEED(vehicle, 8); - } - - g->vehicle.auto_drive_to_waypoint = false; - - if (ran_once) - { - g_notification_service->push_warning("Warning", "Autodrive Stopped"); - } - - TASK::CLEAR_VEHICLE_TASKS_(vehicle); - TASK::CLEAR_PED_TASKS(ped); - - running = false; - } - } - } -} \ No newline at end of file diff --git a/BigBaseV2/src/backend/looped/vehicle/auto_drive_to_waypoint.cpp b/BigBaseV2/src/backend/looped/vehicle/auto_drive_to_waypoint.cpp new file mode 100644 index 00000000..07965c21 --- /dev/null +++ b/BigBaseV2/src/backend/looped/vehicle/auto_drive_to_waypoint.cpp @@ -0,0 +1,95 @@ +#include "backend/looped/looped.hpp" +#include "gta/enums.hpp" +#include "natives.hpp" +#include "util/blip.hpp" +#include "util/entity.hpp" +#include "util/vehicle.hpp" + +namespace big +{ + void looped::vehicle_auto_drive_to_waypoint() + { + static Vector3 location; + static bool driving_to_wp = true; + static bool ran_once = false; + static int changing_driving_styles = false; + static int current_driving_style = false; + static int current_speed; + + if (g->vehicle.auto_drive_to_waypoint) + { + ran_once = true; + driving_to_wp = false; + + if (!blip::get_blip_location(location, (int)BlipIcons::Waypoint)) + { + g_notification_service->push_warning("Warning", "No Waypoint found please set one first."); + g->vehicle.auto_drive_to_waypoint = false; + } + else if (!self::veh) + { + g_notification_service->push_warning("Warning", "Please be in a car first then try again."); + g->vehicle.auto_drive_to_waypoint = false; + } + else + { + blip::get_blip_location(location, (int)BlipIcons::Waypoint); + + if (!changing_driving_styles) + { + g_notification_service->push_warning("Auto Drive", "Starting Route To Destination"); + g_notification_service->push_warning("Auto Drive", "Start driving or leave car to take back control."); + } + + TASK::CLEAR_VEHICLE_TASKS_(self::veh); + TASK::CLEAR_PED_TASKS(self::ped); + TASK::TASK_VEHICLE_DRIVE_TO_COORD(self::ped, self::veh, location.x, location.y, location.z, static_cast(g->vehicle.auto_drive_speed), 5, ENTITY::GET_ENTITY_MODEL(self::veh), g->vehicle.driving_style_flags, 20, true); + + current_driving_style = g->vehicle.driving_style_flags; + current_speed = g->vehicle.auto_drive_speed; + + g->vehicle.auto_drive_to_waypoint = false; + + driving_to_wp = true; + } + } + + if (driving_to_wp) + { + if (!blip::get_blip_location(location, (int)BlipIcons::Waypoint) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_LEFT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_RIGHT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_ACCELERATE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_BRAKE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_EXIT) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_HANDBRAKE)) + { + if (!blip::get_blip_location(location, (int)BlipIcons::Waypoint)) + { + VEHICLE::SET_VEHICLE_FORWARD_SPEED(self::veh, 8); + } + + g->vehicle.auto_drive_to_waypoint = false; + + if (ran_once) + { + g_notification_service->push_warning("Warning", "Autodrive Stopped"); + } + + TASK::CLEAR_VEHICLE_TASKS_(self::veh); + TASK::CLEAR_PED_TASKS(self::ped); + + driving_to_wp = false; + } + + if (!ran_once) + { + TASK::CLEAR_VEHICLE_TASKS_(self::veh); + TASK::CLEAR_PED_TASKS(self::ped); + driving_to_wp = false; + } + else + { + if ((current_driving_style != g->vehicle.driving_style_flags) || (current_speed != g->vehicle.auto_drive_speed)) + { + changing_driving_styles = true; + g->vehicle.auto_drive_to_waypoint = true; + } + } + } + } +} diff --git a/BigBaseV2/src/backend/looped/vehicle/auto_drive_wander.cpp b/BigBaseV2/src/backend/looped/vehicle/auto_drive_wander.cpp new file mode 100644 index 00000000..69387387 --- /dev/null +++ b/BigBaseV2/src/backend/looped/vehicle/auto_drive_wander.cpp @@ -0,0 +1,70 @@ +#include "backend/looped/looped.hpp" +#include "gta/enums.hpp" +#include "natives.hpp" +#include "util/blip.hpp" +#include "util/entity.hpp" +#include "util/vehicle.hpp" + +namespace big +{ + void looped::vehicle_auto_drive_wander() + { + static Vector3 location; + static bool wandering = true; + static bool ran_once = false; + static int changing_driving_styles = false; + static int current_driving_style = false; + static int current_speed; + + if (g->vehicle.auto_drive_wander) + { + ran_once = true; + wandering = false; + + if (!self::veh) + { + g_notification_service->push_warning("Warning", "Please be in a car first then try again."); + + g->vehicle.auto_drive_wander = false; + + TASK::CLEAR_VEHICLE_TASKS_(self::veh); + } + else + { + g->vehicle.auto_drive_wander = false; + + TASK::CLEAR_VEHICLE_TASKS_(self::veh); + TASK::CLEAR_PED_TASKS(self::ped); + TASK::TASK_VEHICLE_DRIVE_WANDER(self::ped, self::veh, static_cast(g->vehicle.auto_drive_speed), g->vehicle.driving_style_flags); + + current_driving_style = g->vehicle.driving_style_flags; + current_speed = g->vehicle.auto_drive_speed; + + wandering = true; + + if (!changing_driving_styles) + { + g_notification_service->push_warning("Starting Wondering", "Start driving or leave car to take back control."); + } + } + } + + if (wandering && ran_once) + { + if (PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_LEFT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_RIGHT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_ACCELERATE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_BRAKE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_EXIT) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_HANDBRAKE)) + { + TASK::CLEAR_VEHICLE_TASKS_(self::veh); + TASK::CLEAR_PED_TASKS(self::ped); + + g_notification_service->push_warning("Warning", "Wandering Stopped"); + g->vehicle.auto_drive_wander = false; + wandering = false; + } + if ((current_driving_style != g->vehicle.driving_style_flags) || (current_speed != g->vehicle.auto_drive_speed)) + { + changing_driving_styles = true; + g->vehicle.auto_drive_wander = true; + } + } + } +} diff --git a/BigBaseV2/src/core/globals.hpp b/BigBaseV2/src/core/globals.hpp index 4bdc1c17..00770730 100644 --- a/BigBaseV2/src/core/globals.hpp +++ b/BigBaseV2/src/core/globals.hpp @@ -218,7 +218,7 @@ namespace big bool seatbelt = false; bool turn_signals = false; int auto_drive_speed = 1; - int driving_style_flags = 525116; + int driving_style_flags = 443; int driving_style_id = 0; int rainbow_paint = 0; speedo_meter speedo_meter{}; diff --git a/BigBaseV2/src/util/vehicle.hpp b/BigBaseV2/src/util/vehicle.hpp index ca778cf1..3011022f 100644 --- a/BigBaseV2/src/util/vehicle.hpp +++ b/BigBaseV2/src/util/vehicle.hpp @@ -114,6 +114,6 @@ namespace big::vehicle static constexpr char const* rgb_types[] = { "Off", "Fade", "Spasm" }; - static constexpr int driving_styles[] = { 444, 525116, 787260 }; - static constexpr char const* driving_style_names[] = { "Safe-ish", "Normal", "Hit Everything" }; -} \ No newline at end of file + static constexpr int driving_styles[] = { 443, 524861 }; + static constexpr char const* driving_style_names[] = { "Law-Abiding", "The Road Is Yours" }; +} diff --git a/BigBaseV2/src/views/vehicle/view_vehicle.cpp b/BigBaseV2/src/views/vehicle/view_vehicle.cpp index d11055b1..e3f7dcc5 100644 --- a/BigBaseV2/src/views/vehicle/view_vehicle.cpp +++ b/BigBaseV2/src/views/vehicle/view_vehicle.cpp @@ -24,13 +24,13 @@ namespace big components::button("Repair", [] { vehicle::repair(self::veh); - }); + }); components::button("Instant in personal vehicle", [] { if (!*g_pointers->m_is_session_started) return g_notification_service->push_warning("WARNING", "Go into GTA V Online to use this option"); vehicle::go_into_personal_vehicle(); - }); + }); if (ImGui::TreeNode("Paint")) { @@ -58,24 +58,27 @@ namespace big components::small_text("Auto Drive"); components::button("Drive To Waypoint", [] { + g->vehicle.auto_drive_to_waypoint = true; - }); + }); components::button("Wander", [] { + g->vehicle.auto_drive_wander = true; - }); + }); ImGui::SliderInt("Top Speed", &g->vehicle.auto_drive_speed, 1, 200); components::button("E-Stop", [] { - g->vehicle.auto_drive_to_waypoint = false; - g->vehicle.auto_drive_wander = false; - VEHICLE::SET_VEHICLE_FORWARD_SPEED(self::veh, 0); - TASK::CLEAR_VEHICLE_TASKS_(self::veh); - TASK::CLEAR_PED_TASKS(self::ped); - }); - if (ImGui::ListBox("Driving Style", &g->vehicle.driving_style_id, vehicle::driving_style_names, 3)) + g->vehicle.auto_drive_to_waypoint = false; + g->vehicle.auto_drive_wander = false; + VEHICLE::SET_VEHICLE_FORWARD_SPEED(self::veh, 0); + TASK::CLEAR_VEHICLE_TASKS_(self::veh); + TASK::CLEAR_PED_TASKS(self::ped); + }); + + if (ImGui::ListBox("Driving Style", &g->vehicle.driving_style_id, vehicle::driving_style_names, 2)) { g->vehicle.driving_style_flags = vehicle::driving_styles[g->vehicle.driving_style_id]; g_notification_service->push_warning("Auto Drive", fmt::format("Driving style set to {}.", vehicle::driving_style_names[g->vehicle.driving_style_id]));