From 62b6a61cf8884b31c97f65c62419cc42a6070446 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 4 Sep 2024 21:39:14 -0700 Subject: [PATCH] Add options to override the vendor, version, and renderer strings --- al/state.cpp | 15 ++++++++++++--- alc/alc.cpp | 27 +++++++++++++++++++++++++++ alc/device.h | 4 ++++ alsoftrc.sample | 12 ++++++++++++ docs/env-vars.txt | 12 ++++++++++++ 5 files changed, 67 insertions(+), 3 deletions(-) diff --git a/al/state.cpp b/al/state.cpp index f0216b22..44f9cb59 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -472,9 +472,18 @@ FORCE_ALIGN const ALchar* AL_APIENTRY alGetStringDirect(ALCcontext *context, ALe { switch(pname) { - case AL_VENDOR: return GetVendorString(); - case AL_VERSION: return GetVersionString(); - case AL_RENDERER: return GetRendererString(); + case AL_VENDOR: + if(auto device = context->mALDevice.get(); !device->mVendorOverride.empty()) + return device->mVendorOverride.c_str(); + return GetVendorString(); + case AL_VERSION: + if(auto device = context->mALDevice.get(); !device->mVersionOverride.empty()) + return device->mVersionOverride.c_str(); + return GetVersionString(); + case AL_RENDERER: + if(auto device = context->mALDevice.get(); !device->mRendererOverride.empty()) + return device->mRendererOverride.c_str(); + return GetRendererString(); case AL_EXTENSIONS: return context->mExtensionsString.c_str(); case AL_NO_ERROR: return GetNoErrorString(); case AL_INVALID_NAME: return GetInvalidNameString(); diff --git a/alc/alc.cpp b/alc/alc.cpp index ce5bd1be..a18801c7 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2957,6 +2957,18 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) noexcep return nullptr; } + auto checkopt = [&device](const char *envname, const std::string_view optname) + { + if(auto optval = al::getenv(envname)) return optval; + return device->configValue("game_compat", optname); + }; + if(auto overrideopt = checkopt("__ALSOFT_VENDOR_OVERRIDE", "vendor-override"sv)) + device->mVendorOverride = *overrideopt; + if(auto overrideopt = checkopt("__ALSOFT_VERSION_OVERRIDE", "version-override"sv)) + device->mVersionOverride = *overrideopt; + if(auto overrideopt = checkopt("__ALSOFT_RENDERER_OVERRIDE", "renderer-override"sv)) + device->mRendererOverride = *overrideopt; + { std::lock_guard listlock{ListLock}; auto iter = std::lower_bound(DeviceList.cbegin(), DeviceList.cend(), device.get()); @@ -3508,6 +3520,21 @@ FORCE_ALIGN ALCboolean ALC_APIENTRY alcReopenDeviceSOFT(ALCdevice *device, dev->mDeviceState = DeviceState::Unprepared; TRACE("Reopened device %p, \"%s\"\n", voidp{dev.get()}, dev->DeviceName.c_str()); + std::string{}.swap(device->mVendorOverride); + std::string{}.swap(device->mVersionOverride); + std::string{}.swap(device->mRendererOverride); + auto checkopt = [&device](const char *envname, const std::string_view optname) + { + if(auto optval = al::getenv(envname)) return optval; + return device->configValue("game_compat", optname); + }; + if(auto overrideopt = checkopt("__ALSOFT_VENDOR_OVERRIDE", "vendor-override"sv)) + device->mVendorOverride = *overrideopt; + if(auto overrideopt = checkopt("__ALSOFT_VERSION_OVERRIDE", "version-override"sv)) + device->mVersionOverride = *overrideopt; + if(auto overrideopt = checkopt("__ALSOFT_RENDERER_OVERRIDE", "renderer-override"sv)) + device->mRendererOverride = *overrideopt; + /* Always return true even if resetting fails. It shouldn't fail, but this * is primarily to avoid confusion by the app seeing the function return * false while the device is on the new output anyway. We could try to diff --git a/alc/device.h b/alc/device.h index 47a5513f..9a84f6a9 100644 --- a/alc/device.h +++ b/alc/device.h @@ -89,6 +89,10 @@ struct ALCdevice : public al::intrusive_ref, DeviceBase { std::unordered_map mEffectNames; std::unordered_map mFilterNames; + std::string mVendorOverride; + std::string mVersionOverride; + std::string mRendererOverride; + ALCdevice(DeviceType type); ~ALCdevice(); diff --git a/alsoftrc.sample b/alsoftrc.sample index dd3ff866..564e9f49 100644 --- a/alsoftrc.sample +++ b/alsoftrc.sample @@ -686,3 +686,15 @@ ## reverse-z: (global) # Reverses the local Z (front-back) position of 3D sound sources. #reverse-z = false + +## vendor-override: +# Overrides the string returned by alGetString(AL_VENDOR). +#vendor-override = + +## version-override: +# Overrides the string returned by alGetString(AL_VERSION). +#version-override = + +## renderer-override: +# Overrides the string returned by alGetString(AL_RENDERER). +#renderer-override = diff --git a/docs/env-vars.txt b/docs/env-vars.txt index 0c15cbe9..c687ad02 100644 --- a/docs/env-vars.txt +++ b/docs/env-vars.txt @@ -78,6 +78,18 @@ Same as for __ALSOFT_REVERSE_Z, but for Y (up/down) panning. __ALSOFT_REVERSE_X Same as for __ALSOFT_REVERSE_Z, but for X (left/right) panning. +__ALSOFT_VENDOR_OVERRIDE +Overrides the value returned by alGetString(AL_VENDOR), for apps that misbehave +without particular values. + +__ALSOFT_VERSION_OVERRIDE +Overrides the value returned by alGetString(AL_VERSION), for apps that +misbehave without particular values. + +__ALSOFT_RENDERER_OVERRIDE +Overrides the value returned by alGetString(AL_RENDERER), for apps that +misbehave without particular values. + __ALSOFT_DEFAULT_ERROR Applications that erroneously call alGetError prior to setting a context as current may not like that OpenAL Soft returns 0xA004 (AL_INVALID_OPERATION), -- 2.11.4.GIT