From 956509d7476bdfc8aca868c9f2a69785af67b757 Mon Sep 17 00:00:00 2001 From: Yimura Date: Sun, 8 Aug 2021 15:10:08 +0200 Subject: [PATCH] feat(Services): Added Vehicle service --- BigBaseV2/src/common.hpp | 2 +- BigBaseV2/src/main.cpp | 2 ++ BigBaseV2/src/services/vehicle_service.cpp | 40 ++++++++++++++++++++++ BigBaseV2/src/services/vehicle_service.hpp | 19 ++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 BigBaseV2/src/services/vehicle_service.cpp create mode 100644 BigBaseV2/src/services/vehicle_service.hpp diff --git a/BigBaseV2/src/common.hpp b/BigBaseV2/src/common.hpp index 6e54c262..74ee062d 100644 --- a/BigBaseV2/src/common.hpp +++ b/BigBaseV2/src/common.hpp @@ -52,8 +52,8 @@ #include "core/globals.hpp" #include "core/class/CPed.hpp" -#include "gta/player.hpp" +#include "services/vehicle_service.hpp" namespace big { diff --git a/BigBaseV2/src/main.cpp b/BigBaseV2/src/main.cpp index aa948d87..cbc3fbbc 100644 --- a/BigBaseV2/src/main.cpp +++ b/BigBaseV2/src/main.cpp @@ -47,6 +47,8 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID) g_hooking->enable(); LOG(INFO) << "Hooking enabled."; + auto vehicle_service_instance = std::make_unique(); + while (g_running) { std::this_thread::sleep_for(500ms); diff --git a/BigBaseV2/src/services/vehicle_service.cpp b/BigBaseV2/src/services/vehicle_service.cpp new file mode 100644 index 00000000..00c42d45 --- /dev/null +++ b/BigBaseV2/src/services/vehicle_service.cpp @@ -0,0 +1,40 @@ +#include "vehicle_service.hpp" + +namespace big +{ + vehicle_service::vehicle_service() + { + g_vehicle_service = this; + } + + vehicle_service::~vehicle_service() + { + g_vehicle_service = nullptr; + } + + int vehicle_service::attempt_save() + { + if (g_local_player == nullptr || g_local_player->m_in_vehicle == 0x10 || g_local_player->m_vehicle == nullptr) + return -1; + if (m_handling_backup.find(g_local_player->m_vehicle->m_handling->m_model_hash) != m_handling_backup.end()) + return 0; + + CHandlingData handling = *g_local_player->m_vehicle->m_handling; + + m_handling_backup.emplace(g_local_player->m_vehicle->m_handling->m_model_hash, handling); + + return 1; + } + + bool vehicle_service::restore_vehicle() + { + if (auto it = m_handling_backup.find(g_local_player->m_vehicle->m_handling->m_model_hash); it != m_handling_backup.end()) + { + *g_local_player->m_vehicle->m_handling = it->second; + + return true; + } + + return false; + } +} \ No newline at end of file diff --git a/BigBaseV2/src/services/vehicle_service.hpp b/BigBaseV2/src/services/vehicle_service.hpp new file mode 100644 index 00000000..c3b2aa10 --- /dev/null +++ b/BigBaseV2/src/services/vehicle_service.hpp @@ -0,0 +1,19 @@ +#pragma once +#include "common.hpp" + +namespace big +{ + class vehicle_service + { + public: + vehicle_service(); + ~vehicle_service(); + + int attempt_save(); + bool restore_vehicle(); + private: + inline static std::unordered_map m_handling_backup; + }; + + inline vehicle_service* g_vehicle_service; +} \ No newline at end of file