From 800c7b656fa2aa391434862e4d19e514c8d3add1 Mon Sep 17 00:00:00 2001 From: freezy Date: Tue, 17 Nov 2026 21:24:16 +0100 Subject: [PATCH] plugin: don't fault on game keys that can't name a colorization folder Some gamelogic engines put a version in their game keys, like game/1.0, and the colorization lookup threw on them, so settings validation faulted the plugin and the game ran without its display. Such games now simply have no colorizations; staging still refuses those keys. --- Tests/Player/ColorizationCatalogTests.cs | 12 ++++++++++++ .../Runtime/Plugins/ColorizationCatalog.cs | 10 +++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Tests/Player/ColorizationCatalogTests.cs b/Tests/Player/ColorizationCatalogTests.cs index d78e0c5..3bd18de 100644 --- a/Tests/Player/ColorizationCatalogTests.cs +++ b/Tests/Player/ColorizationCatalogTests.cs @@ -62,6 +62,18 @@ public void VariantsHaveStableIdsAndKeepPaletteAnimationsTogether() Assert.That(assets.Single(asset => asset.Id == "game/third/pin2dmd.pac").RequiresKey, Is.True); } [Test] + public void GamesWhoseKeyCantNameAFolderHaveNoColorizations() + { + // a key with a version, like game/1.0: no library folder is theirs, nothing throws + Asset("game/1.0/game.crz"); + var game = new GameIdentity("example", "game/1.0"); + Assert.That(ColorizationCatalog.IsFolderName(game.Key), Is.False); + Assert.That(ColorizationCatalog.Read(_root, game.Key), Is.Empty); + Assert.That(ColorizationCatalog.Select(_root, Path.Combine(_root, "Table.vpe"), game, "auto", false), Is.Null); + Assert.That(ColorizationCatalog.Read(_root, ".."), Is.Empty); + Assert.Throws(() => ColorizationCatalog.Stage(new ColorizationAsset("x", "x", Asset("game/game.crz")), Path.Combine(_root, "cache"), game.Key, out _)); + } + [Test] public void AmbiguousAutomaticAndMissingManualChoicesNeverFallBack() { // Variants in subfolders aren't what DmdDevice loads, so automatic selection refuses to guess. diff --git a/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/ColorizationCatalog.cs b/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/ColorizationCatalog.cs index a289eaa..62ffd9d 100644 --- a/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/ColorizationCatalog.cs +++ b/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/ColorizationCatalog.cs @@ -22,10 +22,14 @@ internal sealed class ColorizationAsset } internal static class ColorizationCatalog { + /// Whether a game key can be the name of its folder in a colorization library. + internal static bool IsFolderName(string game) => !string.IsNullOrWhiteSpace(game) && game == Path.GetFileName(game) && game != "." && game != ".." + && game.IndexOfAny(Path.GetInvalidFileNameChars()) < 0; + internal static IReadOnlyList Read(string root, string game) { - if (string.IsNullOrWhiteSpace(root) || string.IsNullOrWhiteSpace(game)) return Array.Empty(); - if (game != Path.GetFileName(game) || game == "." || game == "..") throw new ArgumentException("Invalid game key."); + // a game whose key can't name a folder, like one with a version (game/1.0), has no colorizations + if (string.IsNullOrWhiteSpace(root) || !IsFolderName(game)) return Array.Empty(); root = Path.GetFullPath(root); string directory = Path.Combine(root, game); if (!Directory.Exists(directory)) return Array.Empty(); @@ -107,7 +111,7 @@ internal static ColorizationAsset Select(string root, string game, string select /// LibDmd accepts a game folder. An owned cache presents exactly the selected files, leaving the library unchanged. internal static IDisposable Stage(ColorizationAsset asset, string cache, string game, out string root) { - if (game != Path.GetFileName(game) || game == "." || game == "..") throw new ArgumentException("Invalid game key."); + if (!IsFolderName(game)) throw new ArgumentException("Invalid game key."); root = Path.GetFullPath(Path.Combine(cache, Guid.NewGuid().ToString("N"))); string owned = root; if (!owned.StartsWith(Path.GetFullPath(cache) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)) throw new InvalidOperationException("Invalid cache location.");