From b1bf477d1fb046e663d931b7b5b86b933ef938ef Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:29:42 -0400 Subject: [PATCH] Added formatting to money on HUD. (#2957) --- src/gta_pointers.hpp | 2 ++ src/hooking/hooking.cpp | 2 ++ src/hooking/hooking.hpp | 2 ++ src/hooks/misc/format_int.cpp | 26 ++++++++++++++++++++++++++ src/pointers.cpp | 9 +++++++++ 5 files changed, 41 insertions(+) create mode 100644 src/hooks/misc/format_int.cpp diff --git a/src/gta_pointers.hpp b/src/gta_pointers.hpp index 086d134e..edfe6928 100644 --- a/src/gta_pointers.hpp +++ b/src/gta_pointers.hpp @@ -366,6 +366,8 @@ namespace big CWeaponInfoManager* m_weapon_info_manager; functions::can_create_vehicle m_can_create_vehicle; + + PVOID m_format_int; }; #pragma pack(pop) static_assert(sizeof(gta_pointers) % 8 == 0, "Pointers are not properly aligned"); diff --git a/src/hooking/hooking.cpp b/src/hooking/hooking.cpp index af3ce54a..439b419e 100644 --- a/src/hooking/hooking.cpp +++ b/src/hooking/hooking.cpp @@ -142,6 +142,8 @@ namespace big detour_hook_helper::add("CCV", g_pointers->m_gta.m_can_create_vehicle); + detour_hook_helper::add("FI", g_pointers->m_gta.m_format_int); + g_hooking = this; } diff --git a/src/hooking/hooking.hpp b/src/hooking/hooking.hpp index da9e5d8a..10446659 100644 --- a/src/hooking/hooking.hpp +++ b/src/hooking/hooking.hpp @@ -193,6 +193,8 @@ namespace big static bool sync_reader_serialize_array(void* _this, void* array, int size); static bool can_create_vehicle(); + + static void format_int(int64_t integer_to_format, char* format_string, size_t size_always_64, bool use_commas); }; class minhook_keepalive diff --git a/src/hooks/misc/format_int.cpp b/src/hooks/misc/format_int.cpp new file mode 100644 index 00000000..011ef9d1 --- /dev/null +++ b/src/hooks/misc/format_int.cpp @@ -0,0 +1,26 @@ +#include "hooking/hooking.hpp" + +namespace big +{ + static inline std::string format_money(int64_t amount) + { + std::stringstream ss; + ss.imbue(std::locale("")); + ss << "$" << std::put_money(static_cast(amount) * 100, false); + std::string money = ss.str(); + return money.substr(0, money.size() - 3); + } + + void hooks::format_int(int64_t integer_to_format, char* format_string, size_t size_always_64, bool use_commas) + { + auto return_address = _ReturnAddress(); + auto return_bytes = static_cast(return_address); + if (return_bytes[0] == 0x48 && return_bytes[1] == 0x8D && return_bytes[2] == 0x15) //lea rdx, aHcGreenlightFo ; "~HC_GREENLIGHT~ " + { + auto money_format = format_money(integer_to_format); + std::strcpy(format_string, money_format.c_str()); + return; + } + g_hooking->get_original()(integer_to_format, format_string, size_always_64, use_commas); + } +} \ No newline at end of file diff --git a/src/pointers.cpp b/src/pointers.cpp index bdbbde1c..71fb18ff 100644 --- a/src/pointers.cpp +++ b/src/pointers.cpp @@ -1772,6 +1772,15 @@ namespace big { g_pointers->m_gta.m_can_create_vehicle = ptr.as(); } + }, + // Format Integer + { + "FI", + "48 83 EC ? 44 88 4C 24", + [](memory::handle ptr) + { + g_pointers->m_gta.m_format_int = ptr.as(); + } } >(); // don't leave a trailing comma at the end