|
| 1 | +// Copyright 2026 Fred Emmott <fred@fredemmott.com> |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +#include <fmt/core.h> |
| 5 | + |
| 6 | +#include <unordered_set> |
| 7 | + |
| 8 | +#include "APILayerStore.hpp" |
| 9 | +#include "Linter.hpp" |
| 10 | + |
| 11 | +// Warn about a registry value that is not a DWORD |
| 12 | +namespace FredEmmott::OpenXRLayers { |
| 13 | + |
| 14 | +class ViveLayersLinter final : public Linter { |
| 15 | + std::vector<std::shared_ptr<LintError>> Lint( |
| 16 | + const APILayerStore* store, |
| 17 | + const std::vector<std::tuple<APILayer, APILayerDetails>>& layers) override { |
| 18 | + const auto arch = store->GetArchitectures().get_only(); |
| 19 | + if (arch == Architecture::Invalid) { |
| 20 | + return {}; |
| 21 | + } |
| 22 | + const auto runtime = Platform::Get().GetActiveRuntime(arch); |
| 23 | + if (!runtime) { |
| 24 | + return {}; |
| 25 | + } |
| 26 | + if (runtime->mName == "SteamVR") { |
| 27 | + return {}; |
| 28 | + } |
| 29 | + const auto runtimeName = runtime->mName.value_or(runtime->mPath.string()); |
| 30 | + |
| 31 | + static const std::unordered_set<std::string_view> LayerNames { |
| 32 | + "XR_APILAYER_VIVE_hand_tracking", |
| 33 | + "XR_APILAYER_VIVE_facial_tracking", |
| 34 | + "XR_APILAYER_VIVE_srworks", |
| 35 | + }; |
| 36 | + |
| 37 | + std::vector<std::shared_ptr<LintError>> ret; |
| 38 | + for (const auto& [layer, details]: layers) { |
| 39 | + if (!LayerNames.contains(details.mName)) { |
| 40 | + continue; |
| 41 | + } |
| 42 | + ret.push_back( |
| 43 | + std::make_shared<InvalidLayerStateLintError>( |
| 44 | + fmt::format( |
| 45 | + "{} requires the SteamVR runtime, but you are currently using " |
| 46 | + "'{}'; this can cause game crashes or other issues.", |
| 47 | + details.mName, |
| 48 | + runtimeName), |
| 49 | + layer)); |
| 50 | + } |
| 51 | + return ret; |
| 52 | + } |
| 53 | +}; |
| 54 | + |
| 55 | +static ViveLayersLinter gInstance; |
| 56 | + |
| 57 | +}// namespace FredEmmott::OpenXRLayers |
0 commit comments