Skip to content

Commit

Permalink
Fix OpenRCT2#19517: Crash when peeps try to exit or enter a hacked ride
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt committed Feb 28, 2023
1 parent 291a778 commit 6f7e3fc
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/openrct2/entity/Guest.cpp
Expand Up @@ -3627,9 +3627,12 @@ void Guest::UpdateRideLeaveEntranceWaypoints(const Ride& ride)
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;
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 / 4;
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 / 4;
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 6f7e3fc

Please sign in to comment.