Widens TotalRideValue to fix overflow reported in #19292 (#19326)

* Widens TotalRideValue to 64 bits

* Adds name to contributors file

* Adds totalRideValue overflow fix to changelog
This commit is contained in:
eaeiv authored and GitHub committed 2023-02-09 21:51:03 +00:00
1 parent 4591ad2f4e
commit 96bfa633fe
11 files changed
+23 -12

No files matched your search

+1
View File
@@ -208,6 +208,7 @@ The following people are not part of the development team, but have been contrib
* Michael Bickerton (mdbckrtn)
* Nehemiah Negussie (nehemiah-negussie)
* (zzril)
* Ernest Elgin (eaeiv)
## Toolchain
+1
View File
@@ -37,6 +37,7 @@
- Fix: [#19114] [Plugin] GameActionResult does not comply to API specification.
- Fix: [#19136] SV6 saves with experimental RCT1 paths not imported correctly.
- Fix: [#19250] MusicObjects do not free their preview images
- Fix: [#19292] Overflow in totalRideValue
0.4.3 (2022-12-14)
------------------------------------------------------------------------
+10 -1
View File
@@ -828,7 +828,16 @@ namespace OpenRCT2
cs.ReadWrite(gWeeklyProfitAverageDivisor);
cs.ReadWrite(gTotalAdmissions);
cs.ReadWrite(gTotalIncomeFromAdmissions);
cs.ReadWrite(gTotalRideValueForMoney);
if (version <= 16)
{
money16 legacyTotalRideValueForMoney = 0;
cs.ReadWrite(legacyTotalRideValueForMoney);
gTotalRideValueForMoney = legacyTotalRideValueForMoney;
}
else
{
cs.ReadWrite(gTotalRideValueForMoney);
}
cs.ReadWrite(gNumGuestsInParkLastWeek);
cs.ReadWrite(gGuestChangeModifier);
cs.ReadWrite(_guestGenerationProbability);
+2 -2
View File
@@ -8,10 +8,10 @@ struct ObjectRepositoryItem;
namespace OpenRCT2
{
// Current version that is saved.
constexpr uint32_t PARK_FILE_CURRENT_VERSION = 16;
constexpr uint32_t PARK_FILE_CURRENT_VERSION = 17;
// The minimum version that is forwards compatible with the current version.
constexpr uint32_t PARK_FILE_MIN_VERSION = 14;
constexpr uint32_t PARK_FILE_MIN_VERSION = 17;
// The minimum version that is backwards compatible with the current version.
// If this is increased beyond 0, uncomment the checks in ParkFile.cpp and Context.cpp!
+1 -1
View File
@@ -999,7 +999,7 @@ Ride* GetOrAllocateRide(RideId index);
const RideObjectEntry* GetRideEntryByIndex(ObjectEntryIndex index);
std::string_view GetRideEntryName(ObjectEntryIndex index);
extern money16 gTotalRideValueForMoney;
extern money64 gTotalRideValueForMoney;
extern const StringId ColourSchemeNames[4];
+1 -1
View File
@@ -50,7 +50,7 @@
using namespace OpenRCT2::TrackMetaData;
money16 gTotalRideValueForMoney;
money64 gTotalRideValueForMoney;
money32 _currentTrackPrice;
+1 -1
View File
@@ -242,7 +242,7 @@ void ScenarioSuccessSubmitName(const char* name)
*/
static void ScenarioCheckEntranceFeeTooHigh()
{
const auto max_fee = AddClamp_money16(gTotalRideValueForMoney, gTotalRideValueForMoney / 2);
const auto max_fee = AddClamp_money64(gTotalRideValueForMoney, gTotalRideValueForMoney / 2);
if ((gParkFlags & PARK_FLAGS_PARK_OPEN) && ParkGetEntranceFee() > max_fee)
{
@@ -191,7 +191,7 @@ namespace OpenRCT2::Scripting
}
}
money16 ScPark::totalRideValueForMoney_get() const
money64 ScPark::totalRideValueForMoney_get() const
{
return gTotalRideValueForMoney;
}
@@ -59,7 +59,7 @@ namespace OpenRCT2::Scripting
money64 companyValue_get() const;
void companyValue_set(money64 value);
money16 totalRideValueForMoney_get() const;
money64 totalRideValueForMoney_get() const;
uint32_t totalAdmissions_get() const;
void totalAdmissions_set(uint32_t value);
+3 -3
View File
@@ -516,9 +516,9 @@ money64 Park::CalculateCompanyValue() const
return result;
}
money16 Park::CalculateTotalRideValueForMoney() const
money64 Park::CalculateTotalRideValueForMoney() const
{
money16 totalRideValue = 0;
money64 totalRideValue = 0;
bool ridePricesUnlocked = ParkRidePricesUnlocked() && !(gParkFlags & PARK_FLAGS_NO_MONEY);
for (auto& ride : GetRideManager())
{
@@ -532,7 +532,7 @@ money16 Park::CalculateTotalRideValueForMoney() const
// Add ride value
if (ride.value != RIDE_VALUE_UNDEFINED)
{
money16 rideValue = static_cast<money16>(ride.value);
money64 rideValue = static_cast<money64>(ride.value);
if (ridePricesUnlocked)
{
rideValue -= ride.price[0];
+1 -1
View File
@@ -81,7 +81,7 @@ namespace OpenRCT2
private:
money64 CalculateRideValue(const Ride& ride) const;
money16 CalculateTotalRideValueForMoney() const;
money64 CalculateTotalRideValueForMoney() const;
uint32_t CalculateSuggestedMaxGuests() const;
uint32_t CalculateGuestGenerationProbability() const;