Add world model spawning (#451)

This commit is contained in:
Quentin E. / iDeath 2022-09-20 14:51:43 +02:00 committed by GitHub
parent 3327be9772
commit 96cbfe3b70
4 changed files with 63 additions and 14 deletions

View File

@ -92,6 +92,12 @@ namespace big
m_model_spawn_bypass = ptr.add(8).as<PVOID>();
});
// World Model Spawn Bypass
main_batch.add("WMSB", "48 85 C0 0F 84 ? ? ? ? 8B 48 50", [this](memory::handle ptr)
{
m_world_model_spawn_bypass = ptr.as<PVOID>();
});
// New pointers
// Native Return Spoofer

View File

@ -45,6 +45,7 @@ namespace big
PVOID m_blame_explode;
PVOID m_model_spawn_bypass;
PVOID m_world_model_spawn_bypass;
PVOID m_native_return;
PVOID m_network_group_override;
PUSHORT m_spectator_check;

View File

@ -1,5 +1,6 @@
#include "persist_car_service.hpp"
#include "util/vehicle.hpp"
#include "util/world_model.hpp"
#include "pointers.hpp"
@ -96,15 +97,16 @@ namespace big
for (const auto& j : model_attachments)
{
const auto attachment = j.get<model_attachment>();
STREAMING::REQUEST_MODEL(attachment.model_hash);
const auto object = OBJECT::CREATE_OBJECT(attachment.model_hash, 0, 0, 0, true, false, false);
const auto object = big::world_model::spawn(attachment.model_hash);
if (object)
{
ENTITY::ATTACH_ENTITY_TO_ENTITY(
object, vehicle,
0,
attachment.position.x, attachment.position.y, attachment.position.z,
attachment.rotation.x, attachment.rotation.y, attachment.rotation.z,
false, false, false, false, 0, true);
STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(attachment.model_hash);
}
}
std::vector<nlohmann::json> vehicle_attachments = vehicle_json[vehicle_attachments_key];

View File

@ -0,0 +1,40 @@
#pragma once
#include "natives.hpp"
#include "script.hpp"
#include "pointers.hpp"
namespace big::world_model
{
constexpr size_t patch_size = 24;
static inline std::once_flag once_flag;
static inline std::array<byte, patch_size> backup;
static inline void setup_backup()
{
memcpy(backup.data(), g_pointers->m_world_model_spawn_bypass, patch_size);
}
inline Object spawn(Hash hash, Vector3 location = Vector3(), bool is_networked = true)
{
STREAMING::REQUEST_MODEL(hash);
for (int i = 0; i < 100 && !STREAMING::HAS_MODEL_LOADED(hash); i++)
{
script::get_current()->yield();
}
if (!STREAMING::HAS_MODEL_LOADED(hash))
{
LOG(WARNING) << "Failed to load model " << HEX_TO_UPPER(hash);
return 0;
}
std::call_once(once_flag, setup_backup);
memset(g_pointers->m_world_model_spawn_bypass, 0x90, patch_size);
const auto object = OBJECT::CREATE_OBJECT(hash, location.x, location.y, location.z, is_networked, false, false);
memcpy(g_pointers->m_world_model_spawn_bypass, backup.data(), patch_size);
STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(hash);
return object;
}
}