mirror of
https://github.com/Mr-X-GTA/YimMenu.git
synced 2025-06-25 17:52:55 +08:00
feat(Personal Vehicle): Added clone personal vehicle feature. (#326)
This commit is contained in:
151
BigBaseV2/src/views/vehicle/view_pv.cpp
Normal file
151
BigBaseV2/src/views/vehicle/view_pv.cpp
Normal file
@ -0,0 +1,151 @@
|
||||
#include "views/view.hpp"
|
||||
#include "fiber_pool.hpp"
|
||||
#include "natives.hpp"
|
||||
#include "services/mobile/mobile_service.hpp"
|
||||
#include "services/vehicle_preview/vehicle_preview_service.hpp"
|
||||
#include "util/vehicle.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
void view::pv() {
|
||||
ImGui::SetWindowSize({ 0.f, (float)*g_pointers->m_resolution_y }, ImGuiCond_Always);
|
||||
|
||||
ImGui::Checkbox("Preview", &g->clone_pv.preview_vehicle);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Spawn In", &g->clone_pv.spawn_inside);
|
||||
ImGui::SameLine();
|
||||
|
||||
static char plate[9] = { 0 };
|
||||
int num_of_rows = 2;
|
||||
|
||||
ImGui::Checkbox("Spawn Clone", &g->clone_pv.spawn_clone);
|
||||
if (g->clone_pv.spawn_clone)
|
||||
{
|
||||
num_of_rows = 4;
|
||||
|
||||
ImGui::Checkbox("Spawn Maxed", &g->clone_pv.spawn_maxed);
|
||||
|
||||
ImGui::SameLine();
|
||||
strncpy(plate, g->clone_pv.plate.c_str(), 9);
|
||||
ImGui::Checkbox("Clone PV Plate", &g->clone_pv.clone_plate);
|
||||
if (g->clone_pv.clone_plate)
|
||||
{
|
||||
num_of_rows = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::SetNextItemWidth(300.f);
|
||||
|
||||
components::input_text_with_hint("Plate", "Plate Number", plate, sizeof(plate), ImGuiInputTextFlags_None, [] {
|
||||
g->clone_pv.plate = plate;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static char search[64];
|
||||
static std::string lower_search;
|
||||
|
||||
ImGui::SetNextItemWidth(300.f);
|
||||
components::input_text_with_hint("Model Name", "Search", search, sizeof(search), ImGuiInputTextFlags_None, [] {
|
||||
lower_search = search;
|
||||
std::transform(lower_search.begin(), lower_search.end(), lower_search.begin(), tolower);
|
||||
});
|
||||
|
||||
g_mobile_service->refresh_personal_vehicles();
|
||||
if (ImGui::ListBoxHeader("##personal_veh_list", { 300, static_cast<float>(*g_pointers->m_resolution_y - 184 - 38 * num_of_rows) }))
|
||||
{
|
||||
|
||||
if (g_mobile_service->personal_vehicles().empty())
|
||||
{
|
||||
ImGui::Text("No personal vehicles found, \nare you online?");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
for (const auto& it : g_mobile_service->personal_vehicles())
|
||||
{
|
||||
const auto& label = it.first;
|
||||
const auto& personal_veh = it.second;
|
||||
auto item = g_vehicle_preview_service->find_vehicle_item_by_hash(personal_veh->get_hash());
|
||||
|
||||
std::string display_name = label;
|
||||
std::string display_manufacturer = item.display_manufacturer;
|
||||
std::transform(display_name.begin(), display_name.end(), display_name.begin(), ::tolower);
|
||||
std::transform(display_manufacturer.begin(), display_manufacturer.end(), display_manufacturer.begin(), ::tolower);
|
||||
|
||||
if (
|
||||
display_name.find(lower_search) != std::string::npos ||
|
||||
display_manufacturer.find(lower_search) != std::string::npos
|
||||
) {
|
||||
ImGui::PushID(personal_veh->get_id());
|
||||
if (ImGui::Selectable(label.c_str(), false)) {
|
||||
|
||||
if (g->clone_pv.spawn_clone)
|
||||
{
|
||||
g_fiber_pool->queue_job([&personal_veh] {
|
||||
auto vehicle_idx = personal_veh->get_vehicle_idx();
|
||||
auto veh_data = vehicle::get_vehicle_data_from_vehicle_idx(vehicle_idx);
|
||||
|
||||
float y_offset = 0;
|
||||
|
||||
if (PED::IS_PED_IN_ANY_VEHICLE(self::ped, false))
|
||||
{
|
||||
y_offset = 10.f;
|
||||
}
|
||||
else if (!g->spawn.spawn_inside)
|
||||
{
|
||||
y_offset = 5.f;
|
||||
}
|
||||
|
||||
auto spawn_location = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(self::ped, 0.f, y_offset, 0.f);
|
||||
float spawn_heading = ENTITY::GET_ENTITY_HEADING(self::ped);
|
||||
|
||||
const char* spawn_plate = plate;
|
||||
if (g->clone_pv.clone_plate)
|
||||
{
|
||||
spawn_plate = personal_veh->get_plate();
|
||||
}
|
||||
|
||||
auto veh = vehicle::clone(veh_data, spawn_location, spawn_heading);
|
||||
|
||||
if (g->clone_pv.spawn_inside)
|
||||
{
|
||||
vehicle::telport_into_veh(veh);
|
||||
}
|
||||
|
||||
if (g->clone_pv.spawn_maxed)
|
||||
{
|
||||
vehicle::max_vehicle(veh);
|
||||
}
|
||||
|
||||
vehicle::set_plate(veh, spawn_plate);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(search, "");
|
||||
lower_search = search;
|
||||
|
||||
g_fiber_pool->queue_job([&personal_veh] {
|
||||
personal_veh->summon();
|
||||
});
|
||||
}
|
||||
}
|
||||
ImGui::PopID();
|
||||
|
||||
if (g->clone_pv.preview_vehicle && ImGui::IsItemHovered())
|
||||
{
|
||||
g_vehicle_preview_service->set_preview_vehicle(item);
|
||||
}
|
||||
else if (g->clone_pv.preview_vehicle && !ImGui::IsAnyItemHovered())
|
||||
{
|
||||
g_vehicle_preview_service->stop_preview();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::ListBoxFooter();
|
||||
}
|
||||
}
|
||||
}
|
@ -6,15 +6,6 @@
|
||||
|
||||
namespace big
|
||||
{
|
||||
static char model[12] = "";
|
||||
|
||||
bool does_search_match(std::string& input, const std::string& search)
|
||||
{
|
||||
std::transform(input.begin(), input.end(), input.begin(), ::tolower);
|
||||
|
||||
return input.find(search) != std::string::npos;
|
||||
}
|
||||
|
||||
void view::spawn() {
|
||||
ImGui::SetWindowSize({ 0.f, (float)*g_pointers->m_resolution_y }, ImGuiCond_Always);
|
||||
|
||||
@ -24,48 +15,61 @@ namespace big
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Spawn Maxed", &g->spawn.spawn_maxed);
|
||||
|
||||
components::input_text_with_hint("Model Name", "Search", model, sizeof(model), ImGuiInputTextFlags_EnterReturnsTrue, []
|
||||
{
|
||||
const auto ped = self::ped;
|
||||
static char plate[9] = { 0 };
|
||||
strncpy(plate, g->spawn.plate.c_str(), 9);
|
||||
|
||||
const auto location = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(ped, 2.f, 2.f, 0.f);
|
||||
const auto veh = vehicle::spawn(model, location, g_local_player->m_player_info->m_ped->m_navigation->m_right.x + 90.f);
|
||||
|
||||
if (g->spawn.spawn_inside)
|
||||
PED::SET_PED_INTO_VEHICLE(PLAYER::PLAYER_PED_ID(), veh, -1);
|
||||
|
||||
if (g->spawn.spawn_maxed)
|
||||
vehicle::max_vehicle(veh);
|
||||
ImGui::SetNextItemWidth(300.f);
|
||||
components::input_text_with_hint("Plate", "Plate Number", plate, sizeof(plate), ImGuiInputTextFlags_None, [] {
|
||||
g->spawn.plate = plate;
|
||||
});
|
||||
|
||||
static char search[64];
|
||||
static std::string lower_search;
|
||||
|
||||
ImGui::SetNextItemWidth(300.f);
|
||||
components::input_text_with_hint("Model Name", "Search", search, sizeof(search), ImGuiInputTextFlags_None, [] {
|
||||
lower_search = search;
|
||||
std::transform(lower_search.begin(), lower_search.end(), lower_search.begin(), tolower);
|
||||
});
|
||||
|
||||
// arbitrary subtraction this looked nice so idc, works for all resolutions as well
|
||||
if (ImGui::ListBoxHeader("###vehicles", { 0, static_cast<float>(*g_pointers->m_resolution_y - 260)}))
|
||||
if (ImGui::ListBoxHeader("###vehicles", { 300, static_cast<float>(*g_pointers->m_resolution_y - 184 - 38 * 3) }))
|
||||
{
|
||||
if (!g_vehicle_preview_service->get_vehicle_list().is_null())
|
||||
|
||||
auto item_arr = g_vehicle_preview_service->get_vehicle_preview_item_arr();
|
||||
|
||||
if (item_arr.size() > 0)
|
||||
{
|
||||
for (auto& item : g_vehicle_preview_service->get_vehicle_list())
|
||||
{
|
||||
if (item["Name"].is_null() || item["DisplayName"].is_null())
|
||||
continue;
|
||||
|
||||
std::string name = item["Name"];
|
||||
std::string display_name = item["DisplayName"];
|
||||
for (auto& item : item_arr) {
|
||||
std::string display_name = item.display_name;
|
||||
std::string display_manufacturer = item.display_manufacturer;
|
||||
|
||||
std::string manufacturer;
|
||||
std::string search = model;
|
||||
std::transform(search.begin(), search.end(), search.begin(), ::tolower);
|
||||
std::transform(display_name.begin(), display_name.end(), display_name.begin(), ::tolower);
|
||||
std::transform(display_manufacturer.begin(), display_manufacturer.end(), display_manufacturer.begin(), ::tolower);
|
||||
|
||||
if (!item["ManufacturerDisplayName"].is_null())
|
||||
manufacturer = item["ManufacturerDisplayName"];
|
||||
if (
|
||||
display_name.find(lower_search) != std::string::npos ||
|
||||
display_manufacturer.find(lower_search) != std::string::npos
|
||||
) {
|
||||
//ImGui::PushID(item.hash);
|
||||
components::selectable(item.display_name, false, [item] {
|
||||
|
||||
if (search.empty() ||
|
||||
does_search_match(name, search) ||
|
||||
does_search_match(display_name, search) ||
|
||||
does_search_match(manufacturer, search))
|
||||
{
|
||||
components::selectable(item["DisplayName"], item["Name"] == search, [&item]
|
||||
{
|
||||
const auto location = self::pos;
|
||||
const Vehicle veh = vehicle::spawn(item["Name"], location, 0.f);
|
||||
float y_offset = 0;
|
||||
|
||||
if (PED::IS_PED_IN_ANY_VEHICLE(self::ped, false))
|
||||
{
|
||||
y_offset = 10.f;
|
||||
}
|
||||
else if (!g->spawn.spawn_inside)
|
||||
{
|
||||
y_offset = 5.f;
|
||||
}
|
||||
|
||||
Vector3 spawn_location = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(self::ped, 0.f, y_offset, 0.f);
|
||||
float spawn_heading = ENTITY::GET_ENTITY_HEADING(self::ped);
|
||||
|
||||
const Vehicle veh = vehicle::spawn(item.hash, spawn_location, spawn_heading);
|
||||
|
||||
if (g->spawn.spawn_inside)
|
||||
{
|
||||
@ -77,17 +81,27 @@ namespace big
|
||||
vehicle::max_vehicle(veh);
|
||||
}
|
||||
|
||||
vehicle::set_plate(veh, plate);
|
||||
|
||||
g_vehicle_preview_service->stop_preview();
|
||||
});
|
||||
//ImGui::PopID();
|
||||
|
||||
if (g->spawn.preview_vehicle && ImGui::IsItemHovered())
|
||||
{
|
||||
g_vehicle_preview_service->set_preview_vehicle(item);
|
||||
}
|
||||
else if (g->spawn.preview_vehicle && !ImGui::IsAnyItemHovered())
|
||||
{
|
||||
g_vehicle_preview_service->stop_preview();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else ImGui::Text("No vehicles in registry.");
|
||||
else
|
||||
{
|
||||
ImGui::Text("No vehicles in registry.");
|
||||
}
|
||||
ImGui::ListBoxFooter();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user