From 640cf9a83d03c9b99a9961ab0a48fc68665b780b Mon Sep 17 00:00:00 2001 From: Bugisoft <58910128+BugisoftRSG@users.noreply.github.com> Date: Fri, 30 Dec 2022 11:49:39 +0100 Subject: [PATCH] feat(Metric): Reimplementing metrics (#778) --- scripts/gtav-classes.cmake | 2 +- src/hooking.cpp | 1 + src/hooking.hpp | 2 + src/hooks/info/prepare_metric_for_sending.cpp | 46 +++++++++++++++++++ src/pointers.cpp | 6 +++ src/pointers.hpp | 1 + 6 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/hooks/info/prepare_metric_for_sending.cpp diff --git a/scripts/gtav-classes.cmake b/scripts/gtav-classes.cmake index f43ca942..5b5707a7 100644 --- a/scripts/gtav-classes.cmake +++ b/scripts/gtav-classes.cmake @@ -3,7 +3,7 @@ include(FetchContent) FetchContent_Declare( gtav_classes GIT_REPOSITORY https://github.com/Yimura/GTAV-Classes.git - GIT_TAG 5ab30af647d7e64404d76ea6168e7f78f5e365af + GIT_TAG 985d0dcc4042ffb24dcb18c34ad5f42b10232510 GIT_PROGRESS TRUE CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/src/hooking.cpp b/src/hooking.cpp index e77e660c..ceada7ca 100644 --- a/src/hooking.cpp +++ b/src/hooking.cpp @@ -99,6 +99,7 @@ namespace big detour_hook_helper::add("RBGH", g_pointers->m_read_bitbuffer_gamer_handle); detour_hook_helper::add("QD", g_pointers->m_queue_dependency); + detour_hook_helper::add("PMFS", g_pointers->m_prepare_metric_for_sending); g_hooking = this; } diff --git a/src/hooking.hpp b/src/hooking.hpp index 25f2c462..45c778ba 100644 --- a/src/hooking.hpp +++ b/src/hooking.hpp @@ -33,6 +33,7 @@ namespace rage class rlGamerHandle; class netConnectionManager; class datBitBuffer; + class rlMetric; namespace netConnection { @@ -136,6 +137,7 @@ namespace big static int nt_query_virtual_memory(void* _this, HANDLE handle, PVOID base_addr, int info_class, MEMORY_BASIC_INFORMATION* info, int size, size_t* return_len); static void queue_dependency(void* dependency); + static void prepare_metric_for_sending(rage::datBitBuffer* bit_buffer, int unk, int time, rage::rlMetric* metric); }; class minhook_keepalive diff --git a/src/hooks/info/prepare_metric_for_sending.cpp b/src/hooks/info/prepare_metric_for_sending.cpp new file mode 100644 index 00000000..bcecc685 --- /dev/null +++ b/src/hooks/info/prepare_metric_for_sending.cpp @@ -0,0 +1,46 @@ +#include "hooking.hpp" +#include "rage/rlMetric.hpp" + +namespace big +{ +#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) + + void hooks::prepare_metric_for_sending(rage::datBitBuffer* bit_buffer, int unk, int time, rage::rlMetric* metric) + { + char buffer[256]{}; + json_serializer serializer(buffer, sizeof(buffer)); + + metric->serialize(&serializer); + + LOG(INFO) << "METRIC: " << metric->get_name() << "; DATA: " << serializer.get_string(); + } +} diff --git a/src/pointers.cpp b/src/pointers.cpp index 1454dd0c..dea6090a 100644 --- a/src/pointers.cpp +++ b/src/pointers.cpp @@ -774,6 +774,12 @@ namespace big memory::byte_patch::make(ptr.add(13).as(), bytes)->apply(); }); + // Metric + main_batch.add("PMFS", "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 49 8B E8 4C 8D 40 EC 49 8B F1 48 8B D9 40 32 FF E8", [this](memory::handle ptr) + { + m_prepare_metric_for_sending = ptr.as(); + }); + auto mem_region = memory::module("GTA5.exe"); main_batch.run(mem_region); diff --git a/src/pointers.hpp b/src/pointers.hpp index 49c9e3f8..2b98ce74 100644 --- a/src/pointers.hpp +++ b/src/pointers.hpp @@ -201,6 +201,7 @@ namespace big memory::byte_patch* m_broadcast_patch; rage::atSingleton* m_security; + PVOID m_prepare_metric_for_sending; PVOID m_queue_dependency; PVOID m_interval_check_func;