Refactor format money to use manual methods of comma addition. (#3020)

This commit is contained in:
gir489 2024-05-01 17:30:25 -04:00 committed by GitHub
parent 435963d3b6
commit d13b49ca0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 15 deletions

View File

@ -2,14 +2,14 @@
namespace big namespace big
{ {
static inline std::string format_money(int64_t amount) /*static inline std::string format_money(int64_t amount)
{ {
std::stringstream ss; std::stringstream ss;
ss.imbue(std::locale("en_US.UTF-8")); ss.imbue(std::locale("en_US.UTF-8"));
ss << "$" << std::put_money(static_cast<long double>(amount) * 100, false); ss << "$" << std::put_money(static_cast<long double>(amount) * 100, false);
std::string money = ss.str(); std::string money = ss.str();
return money.substr(0, money.size() - 3); 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) void hooks::format_int(int64_t integer_to_format, char* format_string, size_t size_always_64, bool use_commas)
{ {
@ -17,12 +17,8 @@ namespace big
auto return_bytes = static_cast<unsigned char*>(return_address); auto return_bytes = static_cast<unsigned char*>(return_address);
if (g.window.gui.format_money && return_bytes[0] == 0x48 && return_bytes[1] == 0x8D && return_bytes[2] == 0x15) //lea rdx, aHcGreenlightFo ; "~HC_GREENLIGHT~ <font size='20'>" if (g.window.gui.format_money && return_bytes[0] == 0x48 && return_bytes[1] == 0x8D && return_bytes[2] == 0x15) //lea rdx, aHcGreenlightFo ; "~HC_GREENLIGHT~ <font size='20'>"
{ {
auto money_format = format_money(integer_to_format); use_commas = true;
std::strncpy(format_string, money_format.c_str(), size_always_64);
}
else
{
g_hooking->get_original<format_int>()(integer_to_format, format_string, size_always_64, use_commas);
} }
g_hooking->get_original<format_int>()(integer_to_format, format_string, size_always_64, use_commas);
} }
} }

View File

@ -6,13 +6,14 @@ namespace big
{ {
namespace shop_controller namespace shop_controller
{ {
static inline std::string format_money(int64_t amount) inline std::string format_chips(int value)
{ {
std::stringstream ss; std::string formatted = std::to_string(value);
ss.imbue(std::locale("en_US.UTF-8")); for (int i = formatted.size() - 3; i > 0; i -= 3)
ss << std::put_money(static_cast<long double>(amount) * 100, false); {
std::string money = ss.str(); formatted.insert(i, ",");
return money.substr(0, money.size() - 3); }
return formatted;
} }
void SET_WARNING_MESSAGE_WITH_HEADER(rage::scrNativeCallContext* src) void SET_WARNING_MESSAGE_WITH_HEADER(rage::scrNativeCallContext* src)
@ -43,7 +44,7 @@ namespace big
STATS::STAT_GET_INT(casino_chips, &player_chips, -1); STATS::STAT_GET_INT(casino_chips, &player_chips, -1);
if (arg0 == player_chips && player_chips >= 1000) if (arg0 == player_chips && player_chips >= 1000)
{ {
auto chips_format = format_money(player_chips); auto chips_format = format_chips(player_chips);
return GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_PLAYER_NAME_STRING(chips_format.c_str()); return GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_PLAYER_NAME_STRING(chips_format.c_str());
} }
} }