diff --git a/distribution/changelog.txt b/distribution/changelog.txt index a838dc14a5..fe356643b0 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -44,6 +44,7 @@ - Fix: [#17788] Guests could leave queue if another guest rejoins it from the entrance building. - Fix: [#17834] Finance window becomes blank after 4096 years. - Fix: [#17905] The chain button in the map window is enabled for rectangular maps when (re)opened. +- Fix: [#17931] The in-game command ‘count_objects’ crashes the game. 0.4.1 (2022-07-04) ------------------------------------------------------------------------ diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 7ece65ac7a..d5da15d427 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -59,6 +59,7 @@ #include "Viewport.h" #include +#include #include #include #include @@ -1265,25 +1266,42 @@ static int32_t cc_load_object(InteractiveConsole& console, const arguments_t& ar return 0; } +constexpr std::array _objectTypeNames = { + "Rides", + "Small Scenery", + "Large Scenery", + "Walls", + "Banners", + "Paths", + "Path Additions", + "Scenery groups", + "Park entrances", + "Water", + "ScenarioText", + "Terrain Surface", + "Terrain Edges", + "Stations", + "Music", + "Footpath Surface", + "Footpath Railings", + "Audio", +}; +static_assert(_objectTypeNames.size() == EnumValue(ObjectType::Count)); + static int32_t cc_object_count(InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv) { - const utf8* object_type_names[] = { - "Rides", "Small scenery", "Large scenery", "Walls", "Banners", - "Paths", "Path Additions", "Scenery groups", "Park entrances", "Water", - }; - for (auto objectType : ObjectTypes) { int32_t entryGroupIndex = 0; for (; entryGroupIndex < object_entry_group_counts[EnumValue(objectType)]; entryGroupIndex++) { - if (object_entry_get_chunk(objectType, entryGroupIndex) == nullptr) + if (object_entry_get_object(objectType, entryGroupIndex) == nullptr) { break; } } console.WriteFormatLine( - "%s: %d/%d", object_type_names[EnumValue(objectType)], entryGroupIndex, + "%s: %d/%d", _objectTypeNames[EnumValue(objectType)], entryGroupIndex, object_entry_group_counts[EnumValue(objectType)]); }