1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-26 16:24:35 +01:00

Fix #3330: Current number of passengers overflows

This commit is contained in:
Gymnasiast
2018-02-05 22:39:18 +01:00
committed by Michael Steenbeek
parent 35b86e3aa1
commit 02196a1919
3 changed files with 23 additions and 7 deletions

View File

@@ -1792,7 +1792,7 @@ void peep_decrement_num_riders(rct_peep * peep)
{
Ride * ride = get_ride(peep->current_ride);
ride->num_riders--;
ride->num_riders = std::max(0, ride->num_riders - 1);
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST;
}
}

View File

@@ -49,6 +49,7 @@
#include "../world/Entrance.h"
#include "../world/MapAnimation.h"
#include "../world/Park.h"
#include "../world/Sprite.h"
class ObjectLoadException : public std::runtime_error
{
@@ -471,7 +472,7 @@ public:
void ImportRides()
{
for (uint16 index = 0; index < RCT12_MAX_RIDES_IN_PARK; index++)
for (uint8 index = 0; index < RCT12_MAX_RIDES_IN_PARK; index++)
{
auto src = &_s6.rides[index];
auto dst = get_ride(index);
@@ -482,12 +483,12 @@ public:
}
else
{
ImportRide(dst, src);
ImportRide(dst, src, index);
}
}
}
void ImportRide(Ride * dst, const rct2_ride * src)
void ImportRide(Ride * dst, const rct2_ride * src, const uint8 rideIndex)
{
memset(dst, 0, sizeof(Ride));
@@ -629,7 +630,21 @@ public:
dst->popularity = src->popularity;
dst->popularity_time_out = src->popularity_time_out;
dst->popularity_next = src->popularity_next;
dst->num_riders = src->num_riders;
// The number of riders might have overflown or underflow. Re-calculate the value.
uint16 numRiders = 0;
for (const rct_sprite sprite : _s6.sprites)
{
if (sprite.unknown.sprite_identifier == SPRITE_IDENTIFIER_PEEP)
{
if (sprite.peep.state == PEEP_STATE_ON_RIDE && sprite.peep.current_ride == rideIndex)
{
numRiders++;
}
}
}
dst->num_riders = numRiders;
dst->music_tune_id = src->music_tune_id;
dst->slide_in_use = src->slide_in_use;
// Includes maze_tiles

View File

@@ -268,7 +268,7 @@ typedef struct Ride {
uint8 popularity; // 0x158
uint8 popularity_time_out; // 0x159 Updated every purchase and ?possibly by time?
uint8 popularity_next; // 0x15A When timeout reached this will be the next popularity
uint8 num_riders; // 0x15B
uint8 num_riders_rct2; // 0x15B
uint8 music_tune_id; // 0x15C
uint8 slide_in_use; // 0x15D
union {
@@ -341,7 +341,8 @@ typedef struct Ride {
uint8 pad_1FD; // 0x1FD
uint16 cable_lift; // 0x1FE
uint16 queue_length[MAX_STATIONS]; // 0x200
uint8 pad_208[0x58]; // 0x208
uint16 num_riders; // 0x208
uint8 pad_210[0x56]; // 0x210
} Ride;
assert_struct_size(Ride, 0x260);