feat: Metric Logging (#483)

This commit is contained in:
Yimura 2022-10-21 13:37:18 +02:00 committed by GitHub
parent 005ce81c4d
commit 657d292e07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 124 additions and 5 deletions

View File

@ -53,7 +53,13 @@ namespace big
m_received_clone_sync_hook("RCS", g_pointers->m_received_clone_sync, &hooks::received_clone_sync),
//Get Network Event Data
m_get_network_event_data_hook("GNED", g_pointers->m_get_network_event_data, &hooks::get_network_event_data),
m_write_player_gamer_data_node_hook("WPGDN", g_pointers->m_write_player_gamer_data_node, &hooks::write_player_gamer_data_node)
m_write_player_gamer_data_node_hook("WPGDN", g_pointers->m_write_player_gamer_data_node, &hooks::write_player_gamer_data_node),
// Send Metrics
m_send_metric_a("SMA", g_pointers->m_send_metric_a, &hooks::send_metric_a),
m_send_metric_b1("SMB1", g_pointers->m_send_metric_b_1, &hooks::send_metric_b1),
m_send_metric_b2("SMB2", g_pointers->m_send_metric_b_2, &hooks::send_metric_b2),
m_send_metric_c("SMC", g_pointers->m_send_metric_c, &hooks::send_metric_c)
{
m_swapchain_hook.hook(hooks::swapchain_present_index, &hooks::swapchain_present);
m_swapchain_hook.hook(hooks::swapchain_resizebuffers_index, &hooks::swapchain_resizebuffers);

View File

@ -9,6 +9,7 @@
#include "MinHook.h"
#include "gta/enums.hpp"
#include "datanodes/player/CPlayerGamerDataNode.hpp"
#include "rage/rlMetric.hpp"
namespace big
{
@ -55,6 +56,11 @@ namespace big
static void* assign_physical_index(CNetworkPlayerMgr* netPlayerMgr, CNetGamePlayer* player, uint8_t new_index);
static bool send_metric_a(void* metric_mgr, rage::rlMetric* metric);
static bool send_metric_b1(void* metric_mgr, rage::rlMetric* metric);
static bool send_metric_b2(void* metric_mgr, rage::rlMetric* metric);
static bool send_metric_c(void* metric_mgr, rage::rlMetric* metric);
//SYNC
static int64_t received_clone_sync(CNetworkObjectMgr* mgr, CNetGamePlayer* src, CNetGamePlayer* dst, eObjType sync_type, uint16_t obj_id, rage::datBitBuffer* bufer, uint16_t unk, uint32_t timestamp);
@ -113,6 +119,11 @@ namespace big
detour_hook m_receive_net_message_hook;
detour_hook m_get_network_event_data_hook;
detour_hook m_send_metric_a;
detour_hook m_send_metric_b1;
detour_hook m_send_metric_b2;
detour_hook m_send_metric_c;
detour_hook m_write_player_gamer_data_node_hook;
};

View File

@ -0,0 +1,74 @@
#include "hooking.hpp"
namespace rage
{
#pragma pack(push, 1)
class json_serializer
{
uint32_t unk0; // 0x00
uint32_t unk1; // 0x00
char* buffer; // 0x08
uint32_t curlen; // 0x10
uint32_t maxlen; // 0x14
uint32_t unk4; // 0x18
uint8_t flags; // 0x1C
public:
json_serializer(char* _buffer, uint32_t _length) :
buffer(_buffer),
maxlen(_length)
{
unk0 = 0;
unk1 = 0;
curlen = 0;
unk4 = 1;
flags = 0;
}
inline char* get_string() const
{
return buffer;
}
};
static_assert(sizeof(json_serializer) == 0x1D); // size is actually 0x20
#pragma pack(pop)
}
namespace big
{
void log_metric(rage::rlMetric* metric)
{
char buffer[256]{};
rage::json_serializer serializer(buffer, sizeof(buffer));
metric->serialize(&serializer);
LOG(WARNING) << "METRIC: " << metric->get_name() << "; DATA: " << serializer.get_string();
}
using send_metric_f = bool(*)(void* metric_mgr, rage::rlMetric*);
bool hooks::send_metric_a(void* metric_mgr, rage::rlMetric* metric)
{
log_metric(metric);
return g_hooking->m_send_metric_a.get_original<send_metric_f>()(metric_mgr, metric);
}
bool hooks::send_metric_b1(void* metric_mgr, rage::rlMetric* metric)
{
log_metric(metric);
return g_hooking->m_send_metric_b1.get_original<send_metric_f>()(metric_mgr, metric);
}
bool hooks::send_metric_b2(void* metric_mgr, rage::rlMetric* metric)
{
log_metric(metric);
return g_hooking->m_send_metric_b2.get_original<send_metric_f>()(metric_mgr, metric);
}
bool hooks::send_metric_c(void* metric_mgr, rage::rlMetric* metric)
{
log_metric(metric);
return g_hooking->m_send_metric_c.get_original<send_metric_f>()(metric_mgr, metric);
}
}

View File

@ -94,8 +94,6 @@ namespace big
m_world_model_spawn_bypass = ptr.as<PVOID>();
});
// New pointers
// Native Return Spoofer
main_batch.add("NRF", "FF E3", [this](memory::handle ptr)
{
@ -394,13 +392,38 @@ namespace big
m_online_version = ptr.add(0x24).rip().add(0x20).as<const char*>();
});
// Send Metric a
main_batch.add("SMA", "48 89 5C 24 08 57 48 83 EC 20 48 8B D9 33 C9 48 8B FA E8 ? ? ? ? 48", [this](memory::handle ptr)
{
m_send_metric_a = ptr.as<PVOID>();
});
// Send Metric b1
main_batch.add("SMB1", "4C 8B DC 49 89 5B 08 49 89 6B 10 49 89 73 18 49 89 7B 20 41 56 48 83 EC 30 33 C0 4C 8B F2 48 63 D9 49 89 43 E8 49 89 43 F0 66 89 44 24 ? 85 C9 0F 85", [this](memory::handle ptr)
{
m_send_metric_b_1 = ptr.as<PVOID>();
*reinterpret_cast<uint8_t*>(m_send_metric_b_1) = 0x90; // mangle
});
// Send Metric b2
main_batch.add("SMB2", "4C 8B DC 49 89 5B 08 49 89 6B 10 49 89 73 18 49 89 7B 20 41 56 48 83 EC 30 33 C0 4C 8B F2 48 63 D9 49 89 43 E8 49 89 43 F0 66 89 44 24 ? 85 C9 0F 85", [this](memory::handle ptr)
{
m_send_metric_b_2 = ptr.as<PVOID>();
*reinterpret_cast<uint8_t*>(m_send_metric_b_1) = 0x4C; // restore
});
// Send Metric c
main_batch.add("SMC", "48 8B C4 48 89 58 08 48 89 68 10 48 89 70 18 48 89 78 20 41 56 48 83 EC 30 83 3D", [this](memory::handle ptr)
{
m_send_metric_c = ptr.as<PVOID>();
});
auto mem_region = memory::module(nullptr);
main_batch.run(mem_region);
/**
* Freemode thread restorer through VM patch
*/
*/
if (auto pat1 = mem_region.bruteforce_scan("3b 0a 0f 83 ? ? ? ? 48 ff c7"))
{
memory::byte_patch::make(pat1.add(2).as<uint32_t*>(), 0xc9310272);

View File

@ -102,6 +102,11 @@ namespace big
PVOID m_get_network_event_data{};
PVOID m_assign_physical_index{};
PVOID m_send_metric_a;
PVOID m_send_metric_b_1;
PVOID m_send_metric_b_2;
PVOID m_send_metric_c;
Network** m_network;
functions::reset_network_complaints m_reset_network_complaints{};