From bf4d42b9bd1883f5581b424030207cf73147f790 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Fri, 24 Oct 2025 21:32:04 +0200 Subject: [PATCH] Write out flags and checksums when exporting DAT files --- distribution/changelog.txt | 1 + src/openrct2/object/ObjectRepository.cpp | 73 +++++++++++++----------- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 80c0e26c82..8fc55808e9 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -4,6 +4,7 @@ - Feature: [#26178] Port of the Spinning Cars from RollerCoaster Tycoon 1. - Improved: [#25314] Add unbanked and banked quarter helices to the Alpine, Corkscrew, Giga, Hybrid, Looping, Mine Ride, Mini, Multi-Dimension, Single Rail, Stand Up and Twister tracks. - Improved: [#26044] Simplify Android installation by bundling OpenRCT2 assets in APK. +- Improved: [#26293] Objects extracted from saves now have more information in their filenames. - Change: [#25962] The station style dropdown now shows entrance icons next to the labels for easier selection. - Change: [#26175] The ride colour tab is made more compact by collapsing unavailable sections instead of only hiding them. - Change: [#26178] Symmetric spinning trains and legacy ‘pre-reversed’ trains can no longer be reversed. diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index 957634e2cc..27ed50bdde 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -295,7 +295,7 @@ namespace OpenRCT2 else { LOG_VERBOSE("Adding object: [%s]", objectName); - auto path = GetPathForNewObject(ObjectGeneration::DAT, objectName); + auto path = GetPathForNewObject(*objectEntry); try { SaveObject(path, objectEntry, data, dataSize); @@ -312,7 +312,16 @@ namespace OpenRCT2 ObjectGeneration generation, std::string_view objectName, const void* data, size_t dataSize) override { LOG_VERBOSE("Adding object: [%s]", std::string(objectName).c_str()); - auto path = GetPathForNewObject(generation, objectName); + u8string path; + if (generation == ObjectGeneration::JSON) + { + path = GetPathForNewObject(objectName); + } + else + { + const RCTObjectEntry* entry = reinterpret_cast(data); + path = GetPathForNewObject(*entry); + } try { File::WriteAllBytes(path, data, dataSize); @@ -569,53 +578,53 @@ namespace OpenRCT2 return salt; } - std::string GetPathForNewObject(ObjectGeneration generation, std::string_view name) + u8string updateFileName(u8string fileName, u8string extension) { // Get object directory and create it if it doesn't exist auto userObjPath = _env.GetDirectoryPath(DirBase::user, DirId::objects); Path::CreateDirectory(userObjPath); - // Find a unique file name - auto fileName = GetFileNameForNewObject(generation, name); - auto extension = (generation == ObjectGeneration::DAT ? u8".DAT" : u8".parkobj"); auto fullPath = Path::Combine(userObjPath, fileName + extension); auto counter = 1u; while (File::Exists(fullPath)) { counter++; - fullPath = Path::Combine(userObjPath, String::stdFormat("%s-%02X%s", fileName.c_str(), counter, extension)); + fullPath = Path::Combine( + userObjPath, String::stdFormat("%s-%02X%s", fileName.c_str(), counter, extension.c_str())); } return fullPath; } - std::string GetFileNameForNewObject(ObjectGeneration generation, std::string_view name) + std::string GetPathForNewObject(const RCTObjectEntry& entry) { - if (generation == ObjectGeneration::DAT) - { - // Trim name - char normalisedName[9] = { 0 }; - auto maxLength = std::min(name.size(), 8); - for (size_t i = 0; i < maxLength; i++) - { - if (name[i] != ' ') - { - normalisedName[i] = toupper(name[i]); - } - else - { - normalisedName[i] = '\0'; - break; - } - } + auto fileName = GetFileNameForNewObject(entry); + auto extension = u8string(u8".DAT"); + return updateFileName(fileName, extension); + } - // Convert to UTF-8 filename - return String::convertToUtf8(normalisedName, CodePage::CP_1252); - } - else - { - return std::string(name); - } + std::string GetPathForNewObject(std::string_view jsonIdentifier) + { + // Get object directory and create it if it doesn't exist + auto userObjPath = _env.GetDirectoryPath(DirBase::user, DirId::objects); + Path::CreateDirectory(userObjPath); + + auto fileName = u8string(jsonIdentifier); + auto extension = u8string(u8".parkobj"); + return updateFileName(fileName, extension); + } + + std::string GetFileNameForNewObject(const RCTObjectEntry& entry) + { + utf8 flagsBuffer[10]; + std::snprintf(flagsBuffer, 9, "%08X", entry.flags); + utf8 checksumBuffer[10]; + std::snprintf(checksumBuffer, 9, "%08X", entry.checksum); + + // Needs to be converted to string first because convertToUtf8() does not properly handle the string view length. + auto cp1252name = std::string(entry.GetName()); + auto name = String::convertToUtf8(cp1252name, CodePage::CP_1252); + return name + "." + u8string(flagsBuffer) + '.' + u8string(checksumBuffer); } };