From 248fd36542e35c6ec2ab54ceed5aa4f6c5f86d28 Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Wed, 19 Jul 2023 18:08:29 -0400 Subject: [PATCH] Added Teleport to Selected Blip and associated hotkey. (#1774) --- scripts/gtav-classes.cmake | 2 +- .../teleport/teleport_to_highlighted_blip.cpp | 18 ++++++++ src/backend/looped/vehicle/invisibility.cpp | 1 + src/backend/looped/world/nearby/ignore.cpp | 1 + src/core/settings.hpp | 1 + src/gta/enums.hpp | 25 ++++------- src/gta_pointers.hpp | 3 ++ src/pointers.cpp | 9 ++++ src/services/hotkey/hotkey_service.cpp | 1 + src/util/blip.hpp | 17 +++++++ src/util/teleport.hpp | 25 +++++++++++ src/views/self/view_custom_teleport.cpp | 45 ++++++++++++++++++- src/views/self/view_teleport.cpp | 2 + 13 files changed, 130 insertions(+), 20 deletions(-) create mode 100644 src/backend/commands/teleport/teleport_to_highlighted_blip.cpp diff --git a/scripts/gtav-classes.cmake b/scripts/gtav-classes.cmake index 8b1d8ca7..566d05e4 100644 --- a/scripts/gtav-classes.cmake +++ b/scripts/gtav-classes.cmake @@ -3,7 +3,7 @@ include(FetchContent) FetchContent_Declare( gtav_classes GIT_REPOSITORY https://github.com/Yimura/GTAV-Classes.git - GIT_TAG 3267288d55ca84272da3a9511dc8e4d3b433abe3 + GIT_TAG 5ef3545feb947a1bd143a84d15fdc624e1366c18 GIT_PROGRESS TRUE CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/src/backend/commands/teleport/teleport_to_highlighted_blip.cpp b/src/backend/commands/teleport/teleport_to_highlighted_blip.cpp new file mode 100644 index 00000000..8f377f4e --- /dev/null +++ b/src/backend/commands/teleport/teleport_to_highlighted_blip.cpp @@ -0,0 +1,18 @@ +#include "backend/command.hpp" +#include "natives.hpp" +#include "util/teleport.hpp" + +namespace big +{ + class teleport_to_highlighted_blip : command + { + using command::command; + + virtual void execute(const std::vector&, const std::shared_ptr ctx) + { + teleport::to_highlighted_blip(); + } + }; + + teleport_to_highlighted_blip g_teleport_to_highlighted_blip("highlighttp", "Teleport to Selected Blip", "Teleports you to whichever blip you have in your crosshairs on the map.", 0); +} \ No newline at end of file diff --git a/src/backend/looped/vehicle/invisibility.cpp b/src/backend/looped/vehicle/invisibility.cpp index 6e596c76..af09fc47 100644 --- a/src/backend/looped/vehicle/invisibility.cpp +++ b/src/backend/looped/vehicle/invisibility.cpp @@ -2,6 +2,7 @@ #include "backend/looped_command.hpp" #include "fiber_pool.hpp" #include "natives.hpp" +#include "gta/enums.hpp" namespace big { diff --git a/src/backend/looped/world/nearby/ignore.cpp b/src/backend/looped/world/nearby/ignore.cpp index 29be2d70..841f7ab1 100644 --- a/src/backend/looped/world/nearby/ignore.cpp +++ b/src/backend/looped/world/nearby/ignore.cpp @@ -2,6 +2,7 @@ #include "natives.hpp" #include "pointers.hpp" #include "util/entity.hpp" +#include "gta/enums.hpp" namespace big { diff --git a/src/core/settings.hpp b/src/core/settings.hpp index cbdae38c..2cc551ef 100644 --- a/src/core/settings.hpp +++ b/src/core/settings.hpp @@ -432,6 +432,7 @@ namespace big int teleport_waypoint = 0; int teleport_objective = 0; int teleport_pv = 0; + int teleport_selected = 0; int noclip = 0; int vehicle_flymode = 0; int bringvehicle = 0; diff --git a/src/gta/enums.hpp b/src/gta/enums.hpp index 257a1831..1ab47db5 100644 --- a/src/gta/enums.hpp +++ b/src/gta/enums.hpp @@ -1027,24 +1027,15 @@ enum class BlipColors WaypointColor = 0x54 }; -enum class BlipDisplayBits +enum BlipDisplayBits { - BlipIsBright = (1 << 1), - BlipEngageFlashing = (1 << 3), - BlipFlashForRoute = (1 << 5), - BlipIsOnMinimap = (1 << 6), - BlipIsHighDetail = (1 << 8), - BlipUseBlipColorForDirection = (1 << 9), - BlipIsSmall = (1 << 10), - BlipShowCone = (1 << 11), - BlipIsMissionCreatorBlip = (1 << 12), - BlipShowCheckmark = (1 << 15), - BlipShowDollarSign = (1 << 16), - BlipShowHeadingIndicator = (1 << 17), - BlipShowFullCircle = (1 << 18), - BlipIsFriend = (1 << 19), - BlipIsCrew = (1 << 20), - BlipIsSelected = (1 << 22), + BlipShowCheckmark = (1 << 16), + BlipShowDollarSign = (1 << 17), + BlipShowHeadingIndicator = (1 << 18), + BlipShowFullCircle = (1 << 19), + BlipIsFriend = (1 << 20), + BlipIsCrew = (1 << 21), + BlipIsSelected = (1 << 23), }; enum class BlipRenderBits diff --git a/src/gta_pointers.hpp b/src/gta_pointers.hpp index 5e6fc196..62e7505a 100644 --- a/src/gta_pointers.hpp +++ b/src/gta_pointers.hpp @@ -11,6 +11,7 @@ class GenericPool; class VehiclePool; class CVehicleSeatMetadataMgr; class CVehicleDriveByMetadataMgr; +class CBlipList; namespace rage { @@ -281,6 +282,8 @@ namespace big CVehicleSeatMetadataMgr* m_vehicle_layout_metadata_mgr{}; CVehicleDriveByMetadataMgr* m_driveby_metadata_mgr{}; + + CBlipList* m_blip_list{}; }; #pragma pack(pop) static_assert(sizeof(gta_pointers) % 8 == 0, "Pointers are not properly aligned"); diff --git a/src/pointers.cpp b/src/pointers.cpp index 758ff1bd..a9dff42d 100644 --- a/src/pointers.cpp +++ b/src/pointers.cpp @@ -1391,6 +1391,15 @@ namespace big g_pointers->m_gta.m_driveby_metadata_mgr = ptr.as(); g_pointers->m_gta.m_vehicle_layout_metadata_mgr = ptr.add(0x20).as(); } + }, + // Blip List + { + "BLPLST", + "4C 8D 05 ? ? ? ? 0F B7 C1", + [](memory::handle ptr) + { + g_pointers->m_gta.m_blip_list = ptr.add(3).rip().as(); + } } >(); // don't leave a trailing comma at the end diff --git a/src/services/hotkey/hotkey_service.cpp b/src/services/hotkey/hotkey_service.cpp index f55d709d..16ad1d34 100644 --- a/src/services/hotkey/hotkey_service.cpp +++ b/src/services/hotkey/hotkey_service.cpp @@ -34,6 +34,7 @@ namespace big register_hotkey("vehiclecontroller", g.settings.hotkeys.open_vehicle_controller, RAGE_JOAAT("vehiclecontrol")); register_hotkey("vehiclefly", g.settings.hotkeys.vehicle_flymode, RAGE_JOAAT("vehiclefly")); register_hotkey("waypoint", g.settings.hotkeys.teleport_waypoint, RAGE_JOAAT("waypointtp")); + register_hotkey("highlighttp", g.settings.hotkeys.teleport_selected, RAGE_JOAAT("highlighttp")); g_renderer->add_wndproc_callback([this](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { wndproc(static_cast(msg), wparam); diff --git a/src/util/blip.hpp b/src/util/blip.hpp index 97438c04..18f30b39 100644 --- a/src/util/blip.hpp +++ b/src/util/blip.hpp @@ -2,6 +2,9 @@ #include "gta/enums.hpp" #include "natives.hpp" #include "script.hpp" +#include "pointers.hpp" +#include "ui/blip_t.hpp" +#include "ui/CBlipList.hpp" namespace big::blip { @@ -45,4 +48,18 @@ namespace big::blip return false; } + + inline rage::Blip_t* get_selected_blip() + { + for (int i = 0; i < 1500; i++) + { + + auto blip = g_pointers->m_gta.m_blip_list->m_Blips[i].m_pBlip; + if (blip && (blip->m_display_bits & BlipDisplayBits::BlipIsSelected)) + { + return blip; + } + } + return nullptr; + } } \ No newline at end of file diff --git a/src/util/teleport.hpp b/src/util/teleport.hpp index fe3215ce..4e400f64 100644 --- a/src/util/teleport.hpp +++ b/src/util/teleport.hpp @@ -199,6 +199,31 @@ namespace big::teleport return false; } + inline bool to_highlighted_blip() + { + if (!*g_pointers->m_gta.m_is_session_started) + { + g_notification_service->push_warning("TELEPORT"_T.data(), "TELEPORT_NOT_ONLINE"_T.data()); + return false; + } + + auto blip = blip::get_selected_blip(); + if (blip == nullptr) + { + g_notification_service->push_warning("TELEPORT"_T.data(), "TELEPORT_NOTHING_SELECTED"_T.data()); + return false; + } + Entity entity = self::ped; + if (PED::GET_PED_CONFIG_FLAG(self::ped, 62, TRUE)) + { + entity = self::veh; + } + ENTITY::SET_ENTITY_COORDS_NO_OFFSET(entity, blip->m_x, blip->m_y, blip->m_z, FALSE, FALSE, TRUE); + ENTITY::SET_ENTITY_HEADING(entity, blip->m_rotation); + + return false; + } + inline bool tp_on_top(Entity ent, bool match_velocity) { if (!ENTITY::DOES_ENTITY_EXIST(ent)) diff --git a/src/views/self/view_custom_teleport.cpp b/src/views/self/view_custom_teleport.cpp index ddea06dc..52986246 100644 --- a/src/views/self/view_custom_teleport.cpp +++ b/src/views/self/view_custom_teleport.cpp @@ -1,6 +1,7 @@ #include "services/custom_teleport/custom_teleport_service.hpp" #include "util/math.hpp" #include "util/teleport.hpp" +#include "util/blip.hpp" #include "views/view.hpp" namespace big @@ -38,7 +39,7 @@ namespace big void view::custom_teleport() { ImGui::BeginGroup(); - static std::string new_location_name; + static std::string new_location_name{}; static std::string category = "Default"; static telelocation deletion_telelocation; static std::string filter{}; @@ -74,8 +75,14 @@ namespace big ImGui::PopItemWidth(); components::button("Save current location", [] { - if (g_custom_teleport_service.get_saved_location_by_name(new_location_name)) + if (new_location_name.empty()) + { + g_notification_service->push_warning("Custom Teleport", "Please enter a valid name."); + } + else if (g_custom_teleport_service.get_saved_location_by_name(new_location_name)) + { g_notification_service->push_warning("Custom Teleport", std::format("Location with the name {} already exists", new_location_name)); + } else { telelocation teleport_location; @@ -93,6 +100,40 @@ namespace big g_custom_teleport_service.save_new_location(category, teleport_location); } }); + ImGui::SameLine(); + components::button("Save current selected blip", [] { + if (new_location_name.empty()) + { + g_notification_service->push_warning("Custom Teleport", "Please enter a valid name."); + } + else if (g_custom_teleport_service.get_saved_location_by_name(new_location_name)) + { + g_notification_service->push_warning("Custom Teleport", std::format("Location with the name {} already exists", new_location_name)); + } + else if (!*g_pointers->m_gta.m_is_session_started) + { + g_notification_service->push_warning("Custom Teleport", "TELEPORT_NOT_ONLINE"_T.data()); + return; + } + else + { + telelocation teleport_location; + auto blip = blip::get_selected_blip(); + if (blip == nullptr) + { + g_notification_service->push_warning("Custom Teleport", std::format("Cannot find selected blip.")); + return; + } + teleport_location.name = new_location_name; + teleport_location.x = blip->m_x; + teleport_location.y = blip->m_y; + teleport_location.z = blip->m_z; + teleport_location.yaw = blip->m_rotation; + teleport_location.pitch = 0.0f; + teleport_location.roll = 0.0f; + g_custom_teleport_service.save_new_location(category, teleport_location); + } + }); ImGui::Separator(); diff --git a/src/views/self/view_teleport.cpp b/src/views/self/view_teleport.cpp index f77c7bb7..958b4fc4 100644 --- a/src/views/self/view_teleport.cpp +++ b/src/views/self/view_teleport.cpp @@ -16,6 +16,8 @@ namespace big components::command_button<"waypointtp">({}, "Waypoint"); ImGui::SameLine(); components::command_button<"objectivetp">({}, "Objective"); + ImGui::SameLine(); + components::command_button<"highlighttp">({}, "Selected"); components::command_checkbox<"autotptowp">(); ImGui::SeparatorText("Movement");