From 453e508716a9b38156479675fd5c7b9f99dcd798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sun, 18 Sep 2016 20:00:38 +0200 Subject: [PATCH 1/2] Check access to duck_move_offset --- src/ride/vehicle.c | 3 ++- src/world/duck.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index b06cac3aba..3bddb023bd 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -6997,7 +6997,7 @@ static void sub_6DB807(rct_vehicle *vehicle) sprite_move(x, y, z, (rct_sprite*)vehicle); } -extern const rct_xy16 duck_move_offset[]; +extern const rct_xy16 duck_move_offset[4]; /** * Collision Detection @@ -7101,6 +7101,7 @@ static bool vehicle_update_motion_collision_detection( if (direction < 0x14) continue; + assert(((4 + vehicle->sprite_direction) >> 3) < countof(duck_move_offset)); uint32 next_x_diff = abs(x + duck_move_offset[(4 + vehicle->sprite_direction) >> 3].x - collideVehicle->x); uint32 next_y_diff = abs(y + duck_move_offset[(4 + vehicle->sprite_direction) >> 3].y - collideVehicle->y); diff --git a/src/world/duck.c b/src/world/duck.c index ebafc1caf2..c1b467b3ed 100644 --- a/src/world/duck.c +++ b/src/world/duck.c @@ -35,7 +35,7 @@ static void duck_update_double_drink(rct_duck *duck); static void duck_update_fly_away(rct_duck *duck); // rct2: 0x009A3B04 -const rct_xy16 duck_move_offset[] = { +const rct_xy16 duck_move_offset[4] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, From 2258652e8307a4c3acc343fad7d64ffc5bca3a12 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 18 Sep 2016 21:49:58 +0100 Subject: [PATCH 2/2] Wrap direction in vehicle_update_motion_collision_detection --- src/ride/vehicle.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 3bddb023bd..8c7510af86 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -7101,9 +7101,10 @@ static bool vehicle_update_motion_collision_detection( if (direction < 0x14) continue; - assert(((4 + vehicle->sprite_direction) >> 3) < countof(duck_move_offset)); - uint32 next_x_diff = abs(x + duck_move_offset[(4 + vehicle->sprite_direction) >> 3].x - collideVehicle->x); - uint32 next_y_diff = abs(y + duck_move_offset[(4 + vehicle->sprite_direction) >> 3].y - collideVehicle->y); + uint32 offsetSpriteDirection = (vehicle->sprite_direction + 4) & 31; + uint32 offsetDirection = offsetSpriteDirection >> 3; + uint32 next_x_diff = abs(x + duck_move_offset[offsetDirection].x - collideVehicle->x); + uint32 next_y_diff = abs(y + duck_move_offset[offsetDirection].y - collideVehicle->y); if (next_x_diff + next_y_diff < x_diff + y_diff){ mayCollide = true;