From 9699c9db9ed034358641bf6c47559d440fca8c6c Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 29 Aug 2022 10:50:42 +0100 Subject: [PATCH] Add support for RCT Classic audio files --- src/openrct2/PlatformEnvironment.cpp | 5 +++++ src/openrct2/PlatformEnvironment.h | 1 + src/openrct2/audio/Audio.cpp | 27 ++++++++++++++++++++++++--- src/openrct2/audio/audio.h | 1 + src/openrct2/object/ObjectFactory.cpp | 5 ++++- 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/openrct2/PlatformEnvironment.cpp b/src/openrct2/PlatformEnvironment.cpp index 3b83284de6..cdbe753878 100644 --- a/src/openrct2/PlatformEnvironment.cpp +++ b/src/openrct2/PlatformEnvironment.cpp @@ -111,6 +111,11 @@ public: } } + bool IsUsingClassic() const override + { + return _usingRctClassic; + } + private: static const char* DirectoryNamesRCT2[]; static const u8string DirectoryNamesOpenRCT2[]; diff --git a/src/openrct2/PlatformEnvironment.h b/src/openrct2/PlatformEnvironment.h index 58a68deb92..8d97ca9ddd 100644 --- a/src/openrct2/PlatformEnvironment.h +++ b/src/openrct2/PlatformEnvironment.h @@ -83,6 +83,7 @@ namespace OpenRCT2 virtual u8string GetFilePath(PATHID pathid) const abstract; virtual u8string FindFile(DIRBASE base, DIRID did, u8string_view fileName) const abstract; virtual void SetBasePath(DIRBASE base, u8string_view path) abstract; + virtual bool IsUsingClassic() const abstract; }; [[nodiscard]] std::unique_ptr CreatePlatformEnvironment(DIRBASE_VALUES basePaths); diff --git a/src/openrct2/audio/Audio.cpp b/src/openrct2/audio/Audio.cpp index 4cd5adcafd..ca6933996a 100644 --- a/src/openrct2/audio/Audio.cpp +++ b/src/openrct2/audio/Audio.cpp @@ -12,6 +12,7 @@ #include "../Context.h" #include "../Intro.h" #include "../OpenRCT2.h" +#include "../PlatformEnvironment.h" #include "../config/Config.h" #include "../core/File.h" #include "../core/FileStream.h" @@ -98,11 +99,31 @@ namespace OpenRCT2::Audio void LoadAudioObjects() { auto& objManager = GetContext()->GetObjectManager(); - auto* baseAudio = objManager.LoadObject(AudioObjectIdentifiers::Rct2Base); - if (baseAudio != nullptr) + + Object* baseAudio{}; + + // We have a different audio object for RCT Classic + auto env = GetContext()->GetPlatformEnvironment(); + if (env->IsUsingClassic()) { - _soundsAudioObjectEntryIndex = objManager.GetLoadedObjectEntryIndex(baseAudio); + baseAudio = objManager.LoadObject(AudioObjectIdentifiers::Rct2cBase); + if (baseAudio != nullptr) + { + baseAudio->SetIdentifier(AudioObjectIdentifiers::Rct2Base); + _soundsAudioObjectEntryIndex = objManager.GetLoadedObjectEntryIndex(baseAudio); + } } + + if (baseAudio == nullptr) + { + // Fallback to vanilla RCT2 audio object + baseAudio = objManager.LoadObject(AudioObjectIdentifiers::Rct2Base); + if (baseAudio != nullptr) + { + _soundsAudioObjectEntryIndex = objManager.GetLoadedObjectEntryIndex(baseAudio); + } + } + objManager.LoadObject(AudioObjectIdentifiers::Rct2Circus); } diff --git a/src/openrct2/audio/audio.h b/src/openrct2/audio/audio.h index 302e51b98a..bf6ce96575 100644 --- a/src/openrct2/audio/audio.h +++ b/src/openrct2/audio/audio.h @@ -137,6 +137,7 @@ namespace OpenRCT2::Audio { constexpr std::string_view Rct1Title = "rct1.audio.title"; constexpr std::string_view Rct2Base = "rct2.audio.base"; + constexpr std::string_view Rct2cBase = "rct2.audio.base.rctc"; constexpr std::string_view Rct2Title = "rct2.audio.title"; constexpr std::string_view Rct2Circus = "rct2.audio.circus"; } // namespace AudioObjectIdentifiers diff --git a/src/openrct2/object/ObjectFactory.cpp b/src/openrct2/object/ObjectFactory.cpp index 76f21d88bf..cd7f99be58 100644 --- a/src/openrct2/object/ObjectFactory.cpp +++ b/src/openrct2/object/ObjectFactory.cpp @@ -502,7 +502,10 @@ namespace ObjectFactory std::unique_ptr CreateObjectFromJson( IObjectRepository& objectRepository, json_t& jRoot, const IFileDataRetriever* fileRetriever, bool loadImageTable) { - Guard::Assert(jRoot.is_object(), "ObjectFactory::CreateObjectFromJson expects parameter jRoot to be object"); + if (!jRoot.is_object()) + { + throw std::runtime_error("Object JSON root was not an object"); + } log_verbose("CreateObjectFromJson(...)");