From 71ff9bf6d60812d0aa94f76a00009e0aa0b1b9ce Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Wed, 28 Jul 2021 21:25:51 +0200 Subject: [PATCH] Allow loading images from .pob files (#15122) --- src/openrct2/FileClassifier.cpp | 2 +- src/openrct2/object/ImageTable.cpp | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/openrct2/FileClassifier.cpp b/src/openrct2/FileClassifier.cpp index 6aa2b7b3f9..49dc9dd019 100644 --- a/src/openrct2/FileClassifier.cpp +++ b/src/openrct2/FileClassifier.cpp @@ -165,7 +165,7 @@ static bool TryClassifyAsTD4_TD6(OpenRCT2::IStream* stream, ClassifiedFileInfo* uint32_t get_file_extension_type(const utf8* path) { auto extension = Path::GetExtension(path); - if (String::Equals(extension, ".dat", true)) + if (String::Equals(extension, ".dat", true) || String::Equals(extension, ".pob", true)) return FILE_EXTENSION_DAT; if (String::Equals(extension, ".sc4", true)) return FILE_EXTENSION_SC4; diff --git a/src/openrct2/object/ImageTable.cpp b/src/openrct2/object/ImageTable.cpp index ab2e033ba3..fcf243bc6c 100644 --- a/src/openrct2/object/ImageTable.cpp +++ b/src/openrct2/object/ImageTable.cpp @@ -270,15 +270,32 @@ std::string ImageTable::FindLegacyObject(const std::string& name) const auto env = GetContext()->GetPlatformEnvironment(); auto objectsPath = env->GetDirectoryPath(DIRBASE::RCT2, DIRID::OBJECT); auto objectPath = Path::Combine(objectsPath, name); + if (File::Exists(objectPath)) + { + return objectPath; + } + + std::string altName = name; + auto rangeStart = name.find(".DAT"); + if (rangeStart != std::string::npos) + { + altName.replace(rangeStart, 4, ".POB"); + } + objectPath = Path::Combine(objectsPath, altName); + if (File::Exists(objectPath)) + { + return objectPath; + } + if (!File::Exists(objectPath)) { // Search recursively for any file with the target name (case insensitive) - auto filter = Path::Combine(objectsPath, "*.dat"); + auto filter = Path::Combine(objectsPath, "*.dat;*.pob"); auto scanner = Path::ScanDirectory(filter, true); while (scanner->Next()) { auto currentName = Path::GetFileName(scanner->GetPathRelative()); - if (String::Equals(currentName, name, true)) + if (String::Equals(currentName, name, true) || String::Equals(currentName, altName, true)) { objectPath = scanner->GetPath(); break;