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,8 +92,14 @@ namespace big
m_model_spawn_bypass = ptr.add(8).as<PVOID>(); 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 // New pointers
// Native Return Spoofer // Native Return Spoofer
main_batch.add("NRF", "FF E3", [this](memory::handle ptr) main_batch.add("NRF", "FF E3", [this](memory::handle ptr)
{ {
@ -119,7 +125,7 @@ namespace big
}); });
// Received Event Signatures START // Received Event Signatures START
// Received Event Hook // Received Event Hook
main_batch.add("REH", "66 41 83 F9 ? 0F 83", [this](memory::handle ptr) main_batch.add("REH", "66 41 83 F9 ? 0F 83", [this](memory::handle ptr)
{ {
@ -159,7 +165,7 @@ namespace big
}); });
// Read Bitbuffer Array // Read Bitbuffer Array
main_batch.add("RBA", "48 89 5C 24 ? 57 48 83 EC 30 41 8B F8 4C", [this](memory::handle ptr) main_batch.add("RBA", "48 89 5C 24 ? 57 48 83 EC 30 41 8B F8 4C", [this](memory::handle ptr)
{ {
m_read_bitbuf_array = ptr.as<decltype(m_read_bitbuf_array)>(); m_read_bitbuf_array = ptr.as<decltype(m_read_bitbuf_array)>();
}); });

View File

@ -45,6 +45,7 @@ namespace big
PVOID m_blame_explode; PVOID m_blame_explode;
PVOID m_model_spawn_bypass; PVOID m_model_spawn_bypass;
PVOID m_world_model_spawn_bypass;
PVOID m_native_return; PVOID m_native_return;
PVOID m_network_group_override; PVOID m_network_group_override;
PUSHORT m_spectator_check; PUSHORT m_spectator_check;
@ -65,7 +66,7 @@ namespace big
functions::get_gameplay_cam_coords m_get_gameplay_cam_coords; functions::get_gameplay_cam_coords m_get_gameplay_cam_coords;
functions::give_pickup_rewards m_give_pickup_rewards{}; functions::give_pickup_rewards m_give_pickup_rewards{};
functions::trigger_script_event m_trigger_script_event{}; functions::trigger_script_event m_trigger_script_event{};
// Bitbuffer Read/Write START // Bitbuffer Read/Write START
@ -80,7 +81,7 @@ namespace big
functions::write_bitbuf_bool m_write_bitbuf_bool{}; functions::write_bitbuf_bool m_write_bitbuf_bool{};
functions::write_bitbuf_array m_write_bitbuf_array{}; functions::write_bitbuf_array m_write_bitbuf_array{};
// Bitbuffer Read/Write END // Bitbuffer Read/Write END
// Received Event Signatures START // Received Event Signatures START
PVOID m_received_event{}; PVOID m_received_event{};
functions::send_event_ack m_send_event_ack{}; functions::send_event_ack m_send_event_ack{};

View File

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