From 8f53c6dbd3e395ca2984f9d08eaac6f985eeb2f5 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Mon, 22 May 2023 08:46:15 +0100 Subject: [PATCH 1/6] Remove bad identifier users Note this doesn't actually do anything under the hood it will do the same thing for now --- src/openrct2/object/BannerObject.cpp | 3 +-- src/openrct2/object/Object.h | 2 +- src/openrct2/object/PathAdditionObject.cpp | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/openrct2/object/BannerObject.cpp b/src/openrct2/object/BannerObject.cpp index 2f591f6146..a375091f91 100644 --- a/src/openrct2/object/BannerObject.cpp +++ b/src/openrct2/object/BannerObject.cpp @@ -41,10 +41,9 @@ void BannerObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* st // Add banners to 'Signs and items for footpaths' group, rather than lumping them in the Miscellaneous tab. // Since this is already done the other way round for original items, avoid adding those to prevent duplicates. - auto identifier = GetLegacyIdentifier(); auto& objectRepository = context->GetObjectRepository(); - auto item = objectRepository.FindObjectLegacy(identifier); + auto item = objectRepository.FindObject(GetDescriptor()); if (item != nullptr) { auto sourceGame = item->GetFirstSourceGame(); diff --git a/src/openrct2/object/Object.h b/src/openrct2/object/Object.h index 71bda63dc3..c01bd6a75c 100644 --- a/src/openrct2/object/Object.h +++ b/src/openrct2/object/Object.h @@ -265,7 +265,7 @@ public: return _usesFallbackImages; } - // Legacy data structures + // DONOT USE THIS CAN LEAD TO OBJECT COLLISIONS std::string_view GetLegacyIdentifier() const { return _descriptor.GetName(); diff --git a/src/openrct2/object/PathAdditionObject.cpp b/src/openrct2/object/PathAdditionObject.cpp index 8230d01863..c3f5b2eb68 100644 --- a/src/openrct2/object/PathAdditionObject.cpp +++ b/src/openrct2/object/PathAdditionObject.cpp @@ -45,10 +45,9 @@ void PathAdditionObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStre // Add path additions to 'Signs and items for footpaths' group, rather than lumping them in the Miscellaneous tab. // Since this is already done the other way round for original items, avoid adding those to prevent duplicates. - auto identifier = GetLegacyIdentifier(); auto& objectRepository = context->GetObjectRepository(); - auto item = objectRepository.FindObjectLegacy(identifier); + auto item = objectRepository.FindObject(GetDescriptor()); if (item != nullptr) { auto sourceGame = item->GetFirstSourceGame(); From b58a17c7311342603bacf431e194f39713fdc8b1 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Mon, 22 May 2023 08:50:19 +0100 Subject: [PATCH 2/6] Remove localisation object overrides --- src/openrct2/localisation/LanguagePack.cpp | 57 ------------------- src/openrct2/localisation/LanguagePack.h | 1 - .../localisation/LocalisationService.cpp | 9 --- .../localisation/LocalisationService.h | 1 - src/openrct2/object/Object.cpp | 21 +------ src/openrct2/object/Object.h | 1 - 6 files changed, 1 insertion(+), 89 deletions(-) diff --git a/src/openrct2/localisation/LanguagePack.cpp b/src/openrct2/localisation/LanguagePack.cpp index 51efc6209c..8fec52df7a 100644 --- a/src/openrct2/localisation/LanguagePack.cpp +++ b/src/openrct2/localisation/LanguagePack.cpp @@ -182,27 +182,6 @@ public: return nullptr; } - StringId GetObjectOverrideStringId(std::string_view legacyIdentifier, uint8_t index) override - { - Guard::Assert(index < ObjectOverrideMaxStringCount); - - int32_t ooIndex = 0; - for (const ObjectOverride& objectOverride : _objectOverrides) - { - if (std::string_view(objectOverride.name, 8) == legacyIdentifier) - { - if (objectOverride.strings[index].empty()) - { - return STR_NONE; - } - return ObjectOverrideBase + (ooIndex * ObjectOverrideMaxStringCount) + index; - } - ooIndex++; - } - - return STR_NONE; - } - StringId GetScenarioOverrideStringId(const utf8* scenarioFilename, uint8_t index) override { Guard::ArgumentNotNull(scenarioFilename); @@ -226,17 +205,6 @@ public: } private: - ObjectOverride* GetObjectOverride(const std::string& objectIdentifier) - { - for (auto& oo : _objectOverrides) - { - if (strncmp(oo.name, objectIdentifier.c_str(), 8) == 0) - { - return &oo; - } - } - return nullptr; - } ScenarioOverride* GetScenarioOverride(const std::string& scenarioIdentifier) { @@ -376,31 +344,6 @@ private: } sb.Append(codepoint); } - - if (closedCorrectly) - { - while (sb.GetLength() < 8) - { - sb.Append(' '); - } - if (sb.GetLength() == 8) - { - _currentGroup = sb.GetStdString(); - _currentObjectOverride = GetObjectOverride(_currentGroup); - _currentScenarioOverride = nullptr; - if (_currentObjectOverride == nullptr) - { - if (_objectOverrides.size() == MAX_OBJECT_OVERRIDES) - { - LOG_WARNING("Maximum number of localised object strings exceeded."); - } - - _objectOverrides.emplace_back(); - _currentObjectOverride = &_objectOverrides[_objectOverrides.size() - 1]; - std::copy_n(_currentGroup.c_str(), 8, _currentObjectOverride->name); - } - } - } } void ParseGroupScenario(IStringReader* reader) diff --git a/src/openrct2/localisation/LanguagePack.h b/src/openrct2/localisation/LanguagePack.h index f5b8b9e8be..45ba2b7ef2 100644 --- a/src/openrct2/localisation/LanguagePack.h +++ b/src/openrct2/localisation/LanguagePack.h @@ -26,7 +26,6 @@ struct ILanguagePack virtual void RemoveString(StringId stringId) abstract; virtual void SetString(StringId stringId, const std::string& str) abstract; virtual const utf8* GetString(StringId stringId) const abstract; - virtual StringId GetObjectOverrideStringId(std::string_view legacyIdentifier, uint8_t index) abstract; virtual StringId GetScenarioOverrideStringId(const utf8* scenarioFilename, uint8_t index) abstract; }; diff --git a/src/openrct2/localisation/LocalisationService.cpp b/src/openrct2/localisation/LocalisationService.cpp index 6716223312..a8985a5232 100644 --- a/src/openrct2/localisation/LocalisationService.cpp +++ b/src/openrct2/localisation/LocalisationService.cpp @@ -153,15 +153,6 @@ std::tuple LocalisationService::GetLocalisedScenar return std::make_tuple(result0, result1, result2); } -StringId LocalisationService::GetObjectOverrideStringId(std::string_view legacyIdentifier, uint8_t index) const -{ - if (_loadedLanguages.empty()) - { - return STR_NONE; - } - return _loadedLanguages[0]->GetObjectOverrideStringId(legacyIdentifier, index); -} - StringId LocalisationService::AllocateObjectString(const std::string& target) { if (_availableObjectStringIds.empty()) diff --git a/src/openrct2/localisation/LocalisationService.h b/src/openrct2/localisation/LocalisationService.h index d7b76b4c52..0bd2661299 100644 --- a/src/openrct2/localisation/LocalisationService.h +++ b/src/openrct2/localisation/LocalisationService.h @@ -59,7 +59,6 @@ namespace OpenRCT2::Localisation const char* GetString(StringId id) const; std::tuple GetLocalisedScenarioStrings(const std::string& scenarioFilename) const; - StringId GetObjectOverrideStringId(std::string_view legacyIdentifier, uint8_t index) const; std::string GetLanguagePath(uint32_t languageId) const; void OpenLanguage(int32_t id); diff --git a/src/openrct2/object/Object.cpp b/src/openrct2/object/Object.cpp index 94a3aff0e9..46f46d59db 100644 --- a/src/openrct2/object/Object.cpp +++ b/src/openrct2/object/Object.cpp @@ -115,28 +115,9 @@ void Object::PopulateTablesFromJson(IReadObjectContext* context, json_t& root) _usesFallbackImages = _imageTable.ReadJson(context, root); } -std::string Object::GetOverrideString(uint8_t index) const -{ - auto legacyIdentifier = GetLegacyIdentifier(); - const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService(); - auto stringId = localisationService.GetObjectOverrideStringId(legacyIdentifier, index); - - const utf8* result = nullptr; - if (stringId != STR_NONE) - { - result = LanguageGetString(stringId); - } - return String::ToStd(result); -} - std::string Object::GetString(ObjectStringID index) const { - auto sz = GetOverrideString(static_cast(index)); - if (sz.empty()) - { - sz = GetStringTable().GetString(index); - } - return sz; + return GetStringTable().GetString(index); } std::string Object::GetString(int32_t language, ObjectStringID index) const diff --git a/src/openrct2/object/Object.h b/src/openrct2/object/Object.h index c01bd6a75c..e5eab6d27e 100644 --- a/src/openrct2/object/Object.h +++ b/src/openrct2/object/Object.h @@ -220,7 +220,6 @@ protected: */ void PopulateTablesFromJson(IReadObjectContext* context, json_t& root); - std::string GetOverrideString(uint8_t index) const; std::string GetString(ObjectStringID index) const; std::string GetString(int32_t language, ObjectStringID index) const; From dbb04f6a94b6150e35ba35b06766bd42221b0725 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Mon, 22 May 2023 08:52:43 +0100 Subject: [PATCH 3/6] Further removal --- src/openrct2/localisation/LanguagePack.cpp | 5 +---- test/tests/LanguagePackTest.cpp | 3 --- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/openrct2/localisation/LanguagePack.cpp b/src/openrct2/localisation/LanguagePack.cpp index 8fec52df7a..db00510c9d 100644 --- a/src/openrct2/localisation/LanguagePack.cpp +++ b/src/openrct2/localisation/LanguagePack.cpp @@ -323,14 +323,13 @@ private: void ParseGroupObject(IStringReader* reader) { - auto sb = StringBuilder(); + // THIS IS NO LONGER USED SO WE ARE JUST SKIPPING OVER codepoint_t codepoint; // Should have already deduced that the next codepoint is a [ reader->Skip(); // Read string up to ] or line end - bool closedCorrectly = false; while (reader->TryPeek(&codepoint)) { if (IsNewLine(codepoint)) @@ -339,10 +338,8 @@ private: reader->Skip(); if (codepoint == ']') { - closedCorrectly = true; break; } - sb.Append(codepoint); } } diff --git a/test/tests/LanguagePackTest.cpp b/test/tests/LanguagePackTest.cpp index 5cc668eafd..b2f1ded9ed 100644 --- a/test/tests/LanguagePackTest.cpp +++ b/test/tests/LanguagePackTest.cpp @@ -47,12 +47,10 @@ TEST_F(LanguagePackTest, language_pack_simple) ASSERT_STREQ(lang->GetString(2), "Spiral Roller Coaster"); ASSERT_EQ(lang->GetScenarioOverrideStringId("Arid Heights", 0), 0x7000); ASSERT_STREQ(lang->GetString(0x7000), "Arid Heights scenario string"); - ASSERT_EQ(lang->GetObjectOverrideStringId("CONDORRD", 0), 0x6000); ASSERT_STREQ(lang->GetString(0x6000), "my test ride"); // Test some negatives too ASSERT_EQ(lang->GetString(1000), nullptr); ASSERT_EQ(lang->GetScenarioOverrideStringId("No such park", 0), STR_NONE); - ASSERT_EQ(lang->GetObjectOverrideStringId(" ", 0), STR_NONE); } TEST_F(LanguagePackTest, language_pack_multibyte) @@ -65,7 +63,6 @@ TEST_F(LanguagePackTest, language_pack_multibyte) ASSERT_EQ(lang->GetScenarioOverrideStringId("Forest Frontiers", 2), 0x7002); ASSERT_STREQ(lang->GetString(0x7000), "Forest Frontiers"); ASSERT_STREQ(lang->GetString(0x7002), u8"在隱藏於森林深處的清空範圍中, 建造一個很受歡迎的樂園"); - ASSERT_EQ(lang->GetObjectOverrideStringId("CONDORRD", 0), 0x6000); ASSERT_STREQ(lang->GetString(0x6000), u8"神鷹暢遊"); } From 86c02b839fe174af09761e23e2f953009a39333b Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Mon, 22 May 2023 08:59:39 +0100 Subject: [PATCH 4/6] Format and fix tests --- src/openrct2/localisation/LanguagePack.cpp | 1 - test/tests/LanguagePackTest.cpp | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/openrct2/localisation/LanguagePack.cpp b/src/openrct2/localisation/LanguagePack.cpp index db00510c9d..f6d676d3f6 100644 --- a/src/openrct2/localisation/LanguagePack.cpp +++ b/src/openrct2/localisation/LanguagePack.cpp @@ -205,7 +205,6 @@ public: } private: - ScenarioOverride* GetScenarioOverride(const std::string& scenarioIdentifier) { for (auto& so : _scenarioOverrides) diff --git a/test/tests/LanguagePackTest.cpp b/test/tests/LanguagePackTest.cpp index b2f1ded9ed..3d0d8a4b97 100644 --- a/test/tests/LanguagePackTest.cpp +++ b/test/tests/LanguagePackTest.cpp @@ -47,7 +47,6 @@ TEST_F(LanguagePackTest, language_pack_simple) ASSERT_STREQ(lang->GetString(2), "Spiral Roller Coaster"); ASSERT_EQ(lang->GetScenarioOverrideStringId("Arid Heights", 0), 0x7000); ASSERT_STREQ(lang->GetString(0x7000), "Arid Heights scenario string"); - ASSERT_STREQ(lang->GetString(0x6000), "my test ride"); // Test some negatives too ASSERT_EQ(lang->GetString(1000), nullptr); ASSERT_EQ(lang->GetScenarioOverrideStringId("No such park", 0), STR_NONE); @@ -63,7 +62,6 @@ TEST_F(LanguagePackTest, language_pack_multibyte) ASSERT_EQ(lang->GetScenarioOverrideStringId("Forest Frontiers", 2), 0x7002); ASSERT_STREQ(lang->GetString(0x7000), "Forest Frontiers"); ASSERT_STREQ(lang->GetString(0x7002), u8"在隱藏於森林深處的清空範圍中, 建造一個很受歡迎的樂園"); - ASSERT_STREQ(lang->GetString(0x6000), u8"神鷹暢遊"); } const utf8* LanguagePackTest::LanguageEnGB = "# STR_XXXX part is read and XXXX becomes the string id number.\n" From 3f2126662fd0ccb6f2b10c03c89bbaea776073fe Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 23 May 2023 21:43:52 +0100 Subject: [PATCH 5/6] Properly remove the object override code --- src/openrct2/localisation/LanguagePack.cpp | 36 ++-------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/src/openrct2/localisation/LanguagePack.cpp b/src/openrct2/localisation/LanguagePack.cpp index f6d676d3f6..44a57b5038 100644 --- a/src/openrct2/localisation/LanguagePack.cpp +++ b/src/openrct2/localisation/LanguagePack.cpp @@ -28,21 +28,11 @@ // Don't try to load more than language files that exceed 64 MiB constexpr uint64_t MAX_LANGUAGE_SIZE = 64 * 1024 * 1024; -constexpr uint64_t MAX_OBJECT_OVERRIDES = 4096; constexpr uint64_t MAX_SCENARIO_OVERRIDES = 4096; -constexpr StringId ObjectOverrideBase = 0x6000; -constexpr int32_t ObjectOverrideMaxStringCount = 3; - constexpr StringId ScenarioOverrideBase = 0x7000; constexpr int32_t ScenarioOverrideMaxStringCount = 3; -struct ObjectOverride -{ - char name[8] = { 0 }; - std::string strings[ObjectOverrideMaxStringCount]; -}; - struct ScenarioOverride { std::string filename; @@ -54,14 +44,12 @@ class LanguagePack final : public ILanguagePack private: uint16_t const _id; std::vector _strings; - std::vector _objectOverrides; std::vector _scenarioOverrides; /////////////////////////////////////////////////////////////////////////// // Parsing work data /////////////////////////////////////////////////////////////////////////// std::string _currentGroup; - ObjectOverride* _currentObjectOverride = nullptr; ScenarioOverride* _currentScenarioOverride = nullptr; public: @@ -112,7 +100,6 @@ public: // Clean up the parsing work data _currentGroup.clear(); - _currentObjectOverride = nullptr; _currentScenarioOverride = nullptr; } @@ -159,21 +146,6 @@ public: return nullptr; } - if (stringId >= ObjectOverrideBase) - { - int32_t offset = stringId - ObjectOverrideBase; - int32_t ooIndex = offset / ObjectOverrideMaxStringCount; - int32_t ooStringIndex = offset % ObjectOverrideMaxStringCount; - - if (_objectOverrides.size() > static_cast(ooIndex) - && !_objectOverrides[ooIndex].strings[ooStringIndex].empty()) - { - return _objectOverrides[ooIndex].strings[ooStringIndex].c_str(); - } - - return nullptr; - } - if ((_strings.size() > static_cast(stringId)) && !_strings[stringId].empty()) { return _strings[stringId].c_str(); @@ -340,6 +312,7 @@ private: break; } } + _currentGroup.clear(); } void ParseGroupScenario(IStringReader* reader) @@ -369,7 +342,6 @@ private: if (closedCorrectly) { _currentGroup = sb.GetStdString(); - _currentObjectOverride = nullptr; _currentScenarioOverride = GetScenarioOverride(_currentGroup); if (_currentScenarioOverride == nullptr) { @@ -496,11 +468,7 @@ private: } else { - if (_currentObjectOverride != nullptr) - { - _currentObjectOverride->strings[stringId] = s; - } - else + if (_currentScenarioOverride != nullptr) { _currentScenarioOverride->strings[stringId] = std::move(s); } From ccdb97a3bf1e9999a962809c965ed518f20b7a9c Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 23 May 2023 21:45:54 +0100 Subject: [PATCH 6/6] Remove object override from en-gb --- data/language/en-GB.txt | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index 399108a25d..5269239a1f 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -4138,17 +4138,6 @@ STR_SCNR :Fort Anachronism STR_PARK :Fort Anachronism STR_DTLS : -########### -# Scenery # -########### - -## Start OpenRCT2 Official - -[TTPIRF05] -STR_NAME :Roof - -## End OpenRCT2 Official - ############################################################################### ## RCT2 Scenarios ###############################################################################