From 2815d1958cb70b7e02fae11625a852b675e06cab Mon Sep 17 00:00:00 2001 From: Michael Steenbeek <1478678+Gymnasiast@users.noreply.github.com> Date: Thu, 26 Jun 2025 12:57:40 +0200 Subject: [PATCH] Fix #18080: Obsolote .DAT objects can be loaded accidentally --- distribution/changelog.txt | 1 + src/openrct2/object/ObjectRepository.cpp | 37 ++++++++++++++---------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index d008b5e503..92cc41db57 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -14,6 +14,7 @@ - Fix: [#15846] Rightclicking on track piece when there is construction below does not work. - Fix: [#16176, #23113] Animated tile elements do not always redraw when there is over 2000. - Fix: [#17365] The slope of new land surfaces is only correct on one side when shifting and resizing the map. +- Fix: [#18080] Obsolete official .DAT files can be loaded accidentally. - Fix: [#21703] Scenery wall doors get stuck open if the game is saved and loaded whilst they are open. - Fix: [#24456] Zoomed out vehicles on the ride window tab can sometimes draw incorrectly. - Fix: [#24458] Vehicles in the ride window vehicle tab are offset differently than vanilla RCT2, and the sprites are cut off at the bottom. diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index 7adba16cba..187f6b01f3 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -111,24 +111,29 @@ public: object = ObjectFactory::CreateObjectFromLegacyFile(_objectRepository, path.c_str(), false); } - if (object != nullptr) + // All official DAT files have a JSON object counterpart. Avoid loading the obsolete .DAT versions, + // which can happen if the user copies the official DAT objects to their custom content folder. + if (object == nullptr + || (object->GetGeneration() == ObjectGeneration::DAT + && object->GetObjectEntry().GetSourceGame() != ObjectSourceGame::Custom)) { - ObjectRepositoryItem item = {}; - item.Type = object->GetObjectType(); - item.Generation = object->GetGeneration(); - item.Identifier = object->GetIdentifier(); - item.ObjectEntry = object->GetObjectEntry(); - item.Version = object->GetVersion(); - item.Path = path; - item.Name = object->GetName(); - item.Authors = object->GetAuthors(); - item.Sources = object->GetSourceGames(); - if (object->IsCompatibilityObject()) - item.Flags |= ObjectItemFlags::IsCompatibilityObject; - object->SetRepositoryItem(&item); - return item; + return std::nullopt; } - return std::nullopt; + + ObjectRepositoryItem item = {}; + item.Type = object->GetObjectType(); + item.Generation = object->GetGeneration(); + item.Identifier = object->GetIdentifier(); + item.ObjectEntry = object->GetObjectEntry(); + item.Version = object->GetVersion(); + item.Path = path; + item.Name = object->GetName(); + item.Authors = object->GetAuthors(); + item.Sources = object->GetSourceGames(); + if (object->IsCompatibilityObject()) + item.Flags |= ObjectItemFlags::IsCompatibilityObject; + object->SetRepositoryItem(&item); + return item; } protected: