feat(Services): Added Vehicle service

This commit is contained in:
Yimura 2021-08-08 15:10:08 +02:00
parent a5b12f1c17
commit 956509d747
No known key found for this signature in database
GPG Key ID: 3D8FF4397E768682
4 changed files with 62 additions and 1 deletions

View File

@ -52,8 +52,8 @@
#include "core/globals.hpp"
#include "core/class/CPed.hpp"
#include "gta/player.hpp"
#include "services/vehicle_service.hpp"
namespace big
{

View File

@ -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<vehicle_service>();
while (g_running)
{
std::this_thread::sleep_for(500ms);

View File

@ -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;
}
}

View File

@ -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<Hash, CHandlingData> m_handling_backup;
};
inline vehicle_service* g_vehicle_service;
}