Fix #18087: gCash clamped to 32-bit integer every transaction

This commit is contained in:
Michael Steenbeek 2022-09-28 12:20:44 +02:00 committed by GitHub
parent 9e5bdd4f2f
commit a0dd6a3aa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 21 additions and 15 deletions

View File

@ -83,6 +83,7 @@
- Fix: [#18035] Favourited servers dont get their online status updated.
- Fix: [#18051] Visual glitch with Mine Ride's large unbanked turn (original bug).
- Fix: [#18059] [Plugin] Width and height of custom window not changeable via script.
- Fix: [#18087] Bank balance is clamped to a 32-bit integer every transaction.
0.4.1 (2022-07-04)
------------------------------------------------------------------------

View File

@ -17,7 +17,7 @@
#include "../ui/WindowManager.h"
#include "../windows/Intent.h"
ParkSetLoanAction::ParkSetLoanAction(money32 value)
ParkSetLoanAction::ParkSetLoanAction(money64 value)
: _value(value)
{
}

View File

@ -18,7 +18,7 @@ private:
public:
ParkSetLoanAction() = default;
ParkSetLoanAction(money32 value);
ParkSetLoanAction(money64 value);
void AcceptParameters(GameActionParameterVisitor& visitor) override;

View File

@ -517,7 +517,7 @@ void SetCheatAction::SetScenarioNoMoney(bool enabled) const
window_invalidate_by_class(WindowClass::Cheats);
}
void SetCheatAction::SetMoney(money32 amount) const
void SetCheatAction::SetMoney(money64 amount) const
{
gCash = amount;
@ -525,9 +525,9 @@ void SetCheatAction::SetMoney(money32 amount) const
window_invalidate_by_class(WindowClass::BottomToolbar);
}
void SetCheatAction::AddMoney(money32 amount) const
void SetCheatAction::AddMoney(money64 amount) const
{
gCash = add_clamp_money32(gCash, amount);
gCash = add_clamp_money64(gCash, amount);
window_invalidate_by_class(WindowClass::Finances);
window_invalidate_by_class(WindowClass::BottomToolbar);

View File

@ -44,8 +44,8 @@ private:
void ResetRideCrashStatus() const;
void Set10MinuteInspection() const;
void SetScenarioNoMoney(bool enabled) const;
void SetMoney(money32 amount) const;
void AddMoney(money32 amount) const;
void SetMoney(money64 amount) const;
void AddMoney(money64 amount) const;
void ClearLoan() const;
void GenerateGuests(int32_t count) const;
void SetGuestParameter(int32_t parameter, int32_t value) const;

View File

@ -108,6 +108,11 @@ constexpr money32 ToMoney32FromGBP(double money) noexcept
return money * 10;
}
constexpr money64 ToMoney64FromGBP(double money) noexcept
{
return money * 10;
}
#define MONEY16_UNDEFINED static_cast<money16>(static_cast<uint16_t>(0xFFFF))
#define MONEY32_UNDEFINED (static_cast<money32>(0x80000000))
#define MONEY64_UNDEFINED (static_cast<money64>(0x8000000000000000))

View File

@ -762,7 +762,7 @@ static int32_t cc_set(InteractiveConsole& console, const arguments_t& argv)
if (argv[0] == "money" && invalidArguments(&invalidArgs, double_valid[0]))
{
money32 money = ToMoney32FromGBP(double_val[0]);
money32 money = ToMoney64FromGBP(double_val[0]);
if (gCash != money)
{
auto setCheatAction = SetCheatAction(CheatType::SetMoney, money);
@ -796,7 +796,7 @@ static int32_t cc_set(InteractiveConsole& console, const arguments_t& argv)
auto scenarioSetSetting = ScenarioSetSettingAction(
ScenarioSetSetting::InitialLoan,
std::clamp<money64>(
ToMoney32FromGBP(int_val[0]) - ToMoney32FromGBP(int_val[0] % 1000), 0.00_GBP, gMaxBankLoan));
ToMoney64FromGBP(int_val[0]) - ToMoney64FromGBP(int_val[0] % 1000), 0.00_GBP, gMaxBankLoan));
scenarioSetSetting.SetCallback([&console](const GameAction*, const GameActions::Result* res) {
if (res->Error != GameActions::Status::Ok)
console.WriteLineError("set current_loan command failed, likely due to permissions.");

View File

@ -73,7 +73,7 @@ bool finance_check_money_required(uint32_t flags)
* @param cost.
* @param flags game command flags.
*/
bool finance_check_affordability(money32 cost, uint32_t flags)
bool finance_check_affordability(money64 cost, uint32_t flags)
{
return !finance_check_money_required(flags) || cost <= 0 || cost <= gCash;
}
@ -84,10 +84,10 @@ bool finance_check_affordability(money32 cost, uint32_t flags)
* @param amount (eax)
* @param type passed via global var 0x0141F56C (RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE), our type is that var/4.
*/
void finance_payment(money32 amount, ExpenditureType type)
void finance_payment(money64 amount, ExpenditureType type)
{
// overflow check
gCash = add_clamp_money32(gCash, -amount);
gCash = add_clamp_money64(gCash, -amount);
gExpenditureTable[0][static_cast<int32_t>(type)] -= amount;
if (dword_988E60[static_cast<int32_t>(type)] & 1)

View File

@ -60,8 +60,8 @@ extern money64 gParkValueHistory[FINANCE_GRAPH_SIZE];
extern money64 gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][static_cast<int32_t>(ExpenditureType::Count)];
bool finance_check_money_required(uint32_t flags);
bool finance_check_affordability(money32 cost, uint32_t flags);
void finance_payment(money32 amount, ExpenditureType type);
bool finance_check_affordability(money64 cost, uint32_t flags);
void finance_payment(money64 amount, ExpenditureType type);
void finance_pay_wages();
void finance_pay_research();
void finance_pay_interest();

View File

@ -42,7 +42,7 @@
// This string specifies which version of network stream current build uses.
// It is used for making sure only compatible builds get connected, even within
// single OpenRCT2 version.
#define NETWORK_STREAM_VERSION "20"
#define NETWORK_STREAM_VERSION "21"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
static Peep* _pickup_peep = nullptr;