Skip to content

Commit

Permalink
Fix #19517: Crash when peeps try to exit or enter a hacked ride (#19518)
Browse files Browse the repository at this point in the history
* Fix #19517: Crash when peeps try to exit or enter a hacked ride

* Update changelog.txt
  • Loading branch information
ZehMatt committed Mar 1, 2023
1 parent 2a88720 commit c3bd837
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions distribution/changelog.txt
Expand Up @@ -55,6 +55,7 @@
- Fix: [#19380] Startup crash when no sequences are installed and random sequences are enabled.
- Fix: [#19391] String corruption caused by an improper buffer handling in ‘GfxWrapString’.
- Fix: [#19475] Cannot increase loan when more than £1000 in debt.
- Fix: [#19517] Crash when peeps try to exit or enter hacked rides that have no waypoints specified.

0.4.3 (2022-12-14)
------------------------------------------------------------------------
Expand Down
38 changes: 26 additions & 12 deletions src/openrct2/entity/Guest.cpp
Expand Up @@ -3626,10 +3626,13 @@ void Guest::UpdateRideLeaveEntranceWaypoints(const Ride& ride)
const auto& rtd = ride.GetRideTypeDescriptor();
CoordsXY waypoint = rtd.GetGuestWaypointLocation(*vehicle, ride, CurrentRideStation);

const auto waypointIndex = Var37 / 4;
Guard::Assert(carEntry->peep_loading_waypoints.size() >= static_cast<size_t>(waypointIndex));
waypoint.x += carEntry->peep_loading_waypoints[waypointIndex][0].x;
waypoint.y += carEntry->peep_loading_waypoints[waypointIndex][0].y;
const auto waypointIndex = Var37 / 4U;
if (waypointIndex < carEntry->peep_loading_waypoints.size())
{
Guard::Assert(carEntry->peep_loading_waypoints.size() >= static_cast<size_t>(waypointIndex));
waypoint.x += carEntry->peep_loading_waypoints[waypointIndex][0].x;
waypoint.y += carEntry->peep_loading_waypoints[waypointIndex][0].y;
}

SetDestination(waypoint);
RideSubState = PeepRideSubState::ApproachVehicleWaypoints;
Expand Down Expand Up @@ -4265,19 +4268,26 @@ void Guest::UpdateRideLeaveVehicle()
return;

Var37 = ((exitLocation.direction | GetWaypointedSeatLocation(*ride, carEntry, station_direction) * 4) * 4) | 1;
Guard::Assert(carEntry->peep_loading_waypoints.size() >= static_cast<size_t>(Var37 / 4));

CoordsXYZ exitWaypointLoc = waypointLoc;

exitWaypointLoc.x += carEntry->peep_loading_waypoints[Var37 / 4][2].x;
exitWaypointLoc.y += carEntry->peep_loading_waypoints[Var37 / 4][2].y;
const auto waypointIndex = Var37 / 4U;
if (waypointIndex < carEntry->peep_loading_waypoints.size())
{
exitWaypointLoc.x += carEntry->peep_loading_waypoints[waypointIndex][2].x;
exitWaypointLoc.y += carEntry->peep_loading_waypoints[waypointIndex][2].y;
}

if (ride->type == RIDE_TYPE_MOTION_SIMULATOR)
exitWaypointLoc.z += 15;

MoveTo(exitWaypointLoc);

waypointLoc.x += carEntry->peep_loading_waypoints[Var37 / 4][1].x;
waypointLoc.y += carEntry->peep_loading_waypoints[Var37 / 4][1].y;
if (waypointIndex < carEntry->peep_loading_waypoints.size())
{
waypointLoc.x += carEntry->peep_loading_waypoints[waypointIndex][1].x;
waypointLoc.y += carEntry->peep_loading_waypoints[waypointIndex][1].y;
}

SetDestination(waypointLoc, 2);
RideSubState = PeepRideSubState::ApproachExitWaypoints;
Expand Down Expand Up @@ -4429,9 +4439,13 @@ void Guest::UpdateRideApproachVehicleWaypoints()
}

const auto& vehicle_type = rideEntry->Cars[vehicle->vehicle_type];
Guard::Assert(waypoint < 3);
targetLoc.x += vehicle_type.peep_loading_waypoints[Var37 / 4][waypoint].x;
targetLoc.y += vehicle_type.peep_loading_waypoints[Var37 / 4][waypoint].y;
const auto waypointIndex = Var37 / 4U;
if (waypointIndex < vehicle_type.peep_loading_waypoints.size())
{
Guard::Assert(waypoint < 3);
targetLoc.x += vehicle_type.peep_loading_waypoints[waypointIndex][waypoint].x;
targetLoc.y += vehicle_type.peep_loading_waypoints[waypointIndex][waypoint].y;
}

SetDestination(targetLoc);
}
Expand Down

0 comments on commit c3bd837

Please sign in to comment.