feat(Services): Added Vehicle service
This commit is contained in:
parent
a5b12f1c17
commit
956509d747
@ -52,8 +52,8 @@
|
||||
|
||||
#include "core/globals.hpp"
|
||||
#include "core/class/CPed.hpp"
|
||||
#include "gta/player.hpp"
|
||||
|
||||
#include "services/vehicle_service.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
|
@ -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);
|
||||
|
40
BigBaseV2/src/services/vehicle_service.cpp
Normal file
40
BigBaseV2/src/services/vehicle_service.cpp
Normal 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;
|
||||
}
|
||||
}
|
19
BigBaseV2/src/services/vehicle_service.hpp
Normal file
19
BigBaseV2/src/services/vehicle_service.hpp
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user