From 7c8aa753ee602273d91e45678ae6d1ddea758fc5 Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:14:41 -0400 Subject: [PATCH] Fixed format_money not working. (#2969) --- cmake/git.cmake | 6 +++++ src/core/settings.hpp | 9 ++++++- src/hooks/misc/format_int.cpp | 12 ++++++---- src/native_hooks/native_hooks.cpp | 1 + src/native_hooks/shop_controller.hpp | 30 +++++++++++++++++++++++- src/views/settings/view_gui_settings.cpp | 2 ++ 6 files changed, 53 insertions(+), 7 deletions(-) diff --git a/cmake/git.cmake b/cmake/git.cmake index cc02c0d9..5bd3187a 100644 --- a/cmake/git.cmake +++ b/cmake/git.cmake @@ -33,6 +33,12 @@ if(Git_FOUND) OUTPUT_VARIABLE GIT_BRANCH ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + # Check if GIT_BRANCH is empty + if(NOT GIT_BRANCH) + # If GIT_BRANCH is empty, use GITHUB_HEAD_REF + set(GIT_BRANCH "$ENV{GITHUB_HEAD_REF}") + endif() + # generate version.cpp configure_file("${SRC_DIR}/version.cpp.in" "${SRC_DIR}/version.cpp" @ONLY) endif() \ No newline at end of file diff --git a/src/core/settings.hpp b/src/core/settings.hpp index 74723fd1..4787d508 100644 --- a/src/core/settings.hpp +++ b/src/core/settings.hpp @@ -947,7 +947,14 @@ namespace big NLOHMANN_DEFINE_TYPE_INTRUSIVE(vehicle_control, operation_animation, render_distance_on_veh, show_info) } vehicle_control{}; - NLOHMANN_DEFINE_TYPE_INTRUSIVE(window, background_color, demo, text_color, button_color, frame_color, gui_scale, switched_view, ingame_overlay, vehicle_control, ingame_overlay_indicators) + struct gui + { + bool format_money = true; + + NLOHMANN_DEFINE_TYPE_INTRUSIVE(gui, format_money) + } gui{}; + + NLOHMANN_DEFINE_TYPE_INTRUSIVE(window, background_color, demo, text_color, button_color, frame_color, gui_scale, switched_view, ingame_overlay, vehicle_control, ingame_overlay_indicators, gui) } window{}; struct context_menu diff --git a/src/hooks/misc/format_int.cpp b/src/hooks/misc/format_int.cpp index 011ef9d1..e4c98aaf 100644 --- a/src/hooks/misc/format_int.cpp +++ b/src/hooks/misc/format_int.cpp @@ -5,7 +5,7 @@ namespace big static inline std::string format_money(int64_t amount) { std::stringstream ss; - ss.imbue(std::locale("")); + ss.imbue(std::locale("en_US.UTF-8")); ss << "$" << std::put_money(static_cast(amount) * 100, false); std::string money = ss.str(); return money.substr(0, money.size() - 3); @@ -15,12 +15,14 @@ namespace big { 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~ " + if (g.window.gui.format_money && 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; + std::strncpy(format_string, money_format.c_str(), size_always_64); + } + else + { + g_hooking->get_original()(integer_to_format, format_string, size_always_64, use_commas); } - g_hooking->get_original()(integer_to_format, format_string, size_always_64, use_commas); } } \ No newline at end of file diff --git a/src/native_hooks/native_hooks.cpp b/src/native_hooks/native_hooks.cpp index 1a86d60a..5e2b4cac 100644 --- a/src/native_hooks/native_hooks.cpp +++ b/src/native_hooks/native_hooks.cpp @@ -103,6 +103,7 @@ namespace big add_native_detour("shop_controller"_J, NativeIndex::IS_PED_SHOOTING, all_scripts::RETURN_FALSE); // prevent exploit reports add_native_detour("shop_controller"_J, NativeIndex::SET_WARNING_MESSAGE_WITH_HEADER, shop_controller::SET_WARNING_MESSAGE_WITH_HEADER); + add_native_detour("shop_controller"_J, NativeIndex::SCALEFORM_MOVIE_METHOD_ADD_PARAM_INT, shop_controller::SCALEFORM_MOVIE_METHOD_ADD_PARAM_INT); add_native_detour("carmod_shop"_J, NativeIndex::SET_ENTITY_COORDS, carmod_shop::SET_ENTITY_COORDS); add_native_detour("carmod_shop"_J, NativeIndex::SET_ENTITY_HEADING, carmod_shop::SET_ENTITY_HEADING); diff --git a/src/native_hooks/shop_controller.hpp b/src/native_hooks/shop_controller.hpp index ee68b37c..da505ec0 100644 --- a/src/native_hooks/shop_controller.hpp +++ b/src/native_hooks/shop_controller.hpp @@ -6,7 +6,16 @@ namespace big { namespace shop_controller { - inline void SET_WARNING_MESSAGE_WITH_HEADER(rage::scrNativeCallContext* src) + static inline std::string format_money(int64_t amount) + { + std::stringstream ss; + ss.imbue(std::locale("en_US.UTF-8")); + ss << std::put_money(static_cast(amount) * 100, false); + std::string money = ss.str(); + return money.substr(0, money.size() - 3); + } + + void SET_WARNING_MESSAGE_WITH_HEADER(rage::scrNativeCallContext* src) { if (auto entry_line = src->get_arg(1); !strcmp(entry_line, "CTALERT_F_2")) { @@ -22,5 +31,24 @@ namespace big HUD::SET_WARNING_MESSAGE_WITH_HEADER(src->get_arg(0), src->get_arg(1), src->get_arg(2), src->get_arg(3), src->get_arg(4), src->get_arg(5), src->get_arg(6), src->get_arg(7), src->get_arg(8), src->get_arg(9)); } + + void SCALEFORM_MOVIE_METHOD_ADD_PARAM_INT(rage::scrNativeCallContext* src) + { + if (g.window.gui.format_money) + { + auto arg0 = src->get_arg(0); + Hash casino_chips = self::char_index ? "MP1_CASINO_CHIPS"_J : "MP0_CASINO_CHIPS"_J; + int player_chips; + + STATS::STAT_GET_INT(casino_chips, &player_chips, -1); + if (arg0 == player_chips && player_chips >= 1000) + { + auto chips_format = format_money(player_chips); + return GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_PLAYER_NAME_STRING(chips_format.c_str()); + } + } + + GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_INT(src->get_arg(0)); + } } } diff --git a/src/views/settings/view_gui_settings.cpp b/src/views/settings/view_gui_settings.cpp index 8adb9368..daad5e3e 100644 --- a/src/views/settings/view_gui_settings.cpp +++ b/src/views/settings/view_gui_settings.cpp @@ -59,6 +59,8 @@ namespace big ImGui::EndGroup(); + ImGui::Checkbox("VIEW_GUI_FORMAT_MONEY"_T.data(), &g.window.gui.format_money); + if (g.window.ingame_overlay.show_indicators) { if (ImGui::TreeNode("VIEW_GUI_SETTINGS_OVERLAY_INDICATORS"_T.data()))