From 3ff8225bb9a4c2ba6e2bdb9f22d4d029522d09fd Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 12 Feb 2022 19:44:01 +0100 Subject: [PATCH 1/3] Replace some uint8_t in Ride.cpp --- src/openrct2-ui/windows/Ride.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index d963285362..6717f8a503 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -1043,7 +1043,7 @@ static void WindowRideDrawTabVehicle(rct_drawpixelinfo* dpi, rct_window* w) screenCoords.y /= 4; } - const uint8_t vehicle = ride_entry_get_vehicle_at_position( + const auto vehicle = ride_entry_get_vehicle_at_position( ride->subtype, ride->num_cars_per_train, rideEntry->tab_vehicle); rct_ride_entry_vehicle* rideVehicleEntry = &rideEntry->vehicles[vehicle]; @@ -2016,8 +2016,8 @@ static void WindowRideShowRideTypeDropdown(rct_window* w, rct_widget* widget) w->colours[1], Dropdown::Flag::StayOpen, RIDE_TYPE_COUNT); // Find the current ride type in the ordered list. - uint8_t pos = 0; - for (uint8_t i = 0; i < RIDE_TYPE_COUNT; i++) + int32_t pos = 0; + for (int32_t i = 0; i < RIDE_TYPE_COUNT; i++) { if (RideDropdownData[i].ride_type_id == ride->type) { @@ -2159,8 +2159,8 @@ static void WindowRideShowVehicleTypeDropdown(rct_window* w, rct_widget* widget) w->colours[1], 0, Dropdown::Flag::StayOpen, numItems, widget->right - dropdownWidget->left); // Find the current vehicle type in the ordered list. - uint8_t pos = 0; - for (uint8_t i = 0; i < VehicleDropdownData.size(); i++) + int32_t pos = 0; + for (int32_t i = 0; i < static_cast(VehicleDropdownData.size()); i++) { if (VehicleDropdownData[i].subtype_id == ride->subtype) { @@ -2263,8 +2263,8 @@ static void WindowRideMainDropdown(rct_window* w, rct_widgetindex widgetIndex, i case WIDX_RIDE_TYPE_DROPDOWN: if (dropdownIndex != -1 && dropdownIndex < RIDE_TYPE_COUNT) { - uint8_t rideLabelId = std::clamp(dropdownIndex, 0, RIDE_TYPE_COUNT - 1); - uint8_t rideType = RideDropdownData[rideLabelId].ride_type_id; + auto rideLabelId = std::clamp(dropdownIndex, 0, RIDE_TYPE_COUNT - 1); + auto rideType = RideDropdownData[rideLabelId].ride_type_id; if (rideType < RIDE_TYPE_COUNT) { auto rideSetSetting = RideSetSettingAction(w->rideId, RideSetSetting::RideType, rideType); From 49ccc21d8445643c23f9e62b138ab542e1686441 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 12 Feb 2022 20:12:12 +0100 Subject: [PATCH 2/3] Fix #16576: Cannot select vehicle types with entry index >= 256 --- src/openrct2-ui/windows/Ride.cpp | 2 +- src/openrct2/actions/RideSetVehicleAction.cpp | 5 +++-- src/openrct2/actions/RideSetVehicleAction.h | 6 ++++-- src/openrct2/ride/Ride.cpp | 6 +++--- src/openrct2/ride/Ride.h | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 6717f8a503..e21d77ff37 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -926,7 +926,7 @@ static std::vector RideDropdownData; // Used for sorting the vehicle type dropdown. struct VehicleTypeLabel { - int32_t subtype_id; + ObjectEntryIndex subtype_id; rct_string_id label_id; const char* label_string; }; diff --git a/src/openrct2/actions/RideSetVehicleAction.cpp b/src/openrct2/actions/RideSetVehicleAction.cpp index 5a9b351ab8..d146d4d2d3 100644 --- a/src/openrct2/actions/RideSetVehicleAction.cpp +++ b/src/openrct2/actions/RideSetVehicleAction.cpp @@ -31,7 +31,7 @@ constexpr static rct_string_id SetVehicleTypeErrorTitle[] = { STR_RIDE_SET_VEHICLE_TYPE_FAIL, }; -RideSetVehicleAction::RideSetVehicleAction(RideId rideIndex, RideSetVehicleType type, uint8_t value, uint8_t colour) +RideSetVehicleAction::RideSetVehicleAction(RideId rideIndex, RideSetVehicleType type, uint16_t value, uint8_t colour) : _rideIndex(rideIndex) , _type(type) , _value(value) @@ -152,7 +152,8 @@ GameActions::Result RideSetVehicleAction::Execute() const log_warning("Invalid ride entry, ride->subtype = %d", ride->subtype); return GameActions::Result(GameActions::Status::InvalidParameters, errTitle, STR_NONE); } - auto clampValue = _value; + uint8_t clampValue = _value; + static_assert(sizeof(clampValue) == sizeof(ride->proposed_num_cars_per_train)); if (!gCheatsDisableTrainLengthLimit) { clampValue = std::clamp(clampValue, rideEntry->min_cars_in_train, rideEntry->max_cars_in_train); diff --git a/src/openrct2/actions/RideSetVehicleAction.h b/src/openrct2/actions/RideSetVehicleAction.h index 78278607f3..588679d142 100644 --- a/src/openrct2/actions/RideSetVehicleAction.h +++ b/src/openrct2/actions/RideSetVehicleAction.h @@ -24,12 +24,12 @@ class RideSetVehicleAction final : public GameActionBase= sizeof(ObjectEntryIndex)); }; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index d03c1aa8ad..7d5ed7b4a0 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -5146,10 +5146,10 @@ void Ride::UpdateNumberOfCircuits() } } -void Ride::SetRideEntry(int32_t rideEntry) +void Ride::SetRideEntry(ObjectEntryIndex entryIndex) { - auto colour = ride_get_unused_preset_vehicle_colour(rideEntry); - auto rideSetVehicleAction = RideSetVehicleAction(id, RideSetVehicleType::RideEntry, rideEntry, colour); + auto colour = ride_get_unused_preset_vehicle_colour(entryIndex); + auto rideSetVehicleAction = RideSetVehicleAction(id, RideSetVehicleType::RideEntry, entryIndex, colour); GameActions::Execute(&rideSetVehicleAction); } diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index b9a9a7a881..2159dfbdfe 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -298,7 +298,7 @@ public: void Delete(); void Crash(uint8_t vehicleIndex); void SetToDefaultInspectionInterval(); - void SetRideEntry(int32_t rideEntry); + void SetRideEntry(ObjectEntryIndex entryIndex); void SetNumVehicles(int32_t numVehicles); void SetNumCarsPerVehicle(int32_t numCarsPerVehicle); From 9441d4b24fdfefab1f07525204c1be8ac023a421 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 13 Feb 2022 21:11:18 +0100 Subject: [PATCH 3/3] Bump network version --- src/openrct2/network/NetworkBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index d67db78273..b21f424f5b 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -42,7 +42,7 @@ // This string specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "14" +#define NETWORK_STREAM_VERSION "15" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static Peep* _pickup_peep = nullptr;