From faa65ffbc2e3f2813b70ac3cfd881ee2e9e7f686 Mon Sep 17 00:00:00 2001 From: freezy Date: Tue, 17 Nov 2026 14:35:40 +0100 Subject: [PATCH 1/2] plugin: take the colorization of the ROM PinMAME plays PinMAME can play a compatible ROM in place of the one the table was made for. Automatic selection now looks for that ROM's colorization first, then the table ROM's. The plugin prepares after PinMAME, which decides the ROM. --- .../Runtime/Plugins/DmdPlugin.cs | 47 ++++++++++++++++--- .../Runtime/Plugins/DmdPluginFactory.cs | 4 +- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/DmdPlugin.cs b/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/DmdPlugin.cs index a4e68e3..eab4148 100644 --- a/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/DmdPlugin.cs +++ b/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/DmdPlugin.cs @@ -47,21 +47,25 @@ public override Task PrepareGameAsync(PluginGameContext game, CancellationToken var scene = game.Capabilities.Require(UnityPluginCapability.GameScene); var effective = WithDmdDeviceIni(game); var settings = DmdPluginFactory.Settings(effective); - settings.RomName = game.Identity.Key; _gameSettings = effective; - _colorizationLibrary = DmdPluginFactory.Library(effective, game.Identity.Key); - var asset = ColorizationCatalog.Select(_colorizationLibrary, game.PackagePath, game.Identity, - effective.String("Colorization", "auto"), effective.String("VniKey").Length > 0); + // PinMAME can play a compatible ROM in place of the table's own: its colorization first, else the table ROM's. A + // colorization selected in the settings is one of the table ROM's. + string rom = RunningRom(scene, game.Identity), colorization = effective.String("Colorization", "auto"); + string key = colorization == "auto" ? rom : game.Identity.Key; + var asset = key == game.Identity.Key ? SelectColorization(game, effective, key, colorization) : SubstituteColorization(game, effective, key); + if (asset == null && key != game.Identity.Key) asset = SelectColorization(game, effective, key = game.Identity.Key, colorization); + if (asset == null && key != rom) _colorizationLibrary = DmdPluginFactory.Library(effective, key = rom); + settings.RomName = key; settings.EnableColorization = asset != null; _asset = asset; _settings = settings; - _noColorizationReason = asset != null ? null : NoColorizationReason(game.Identity.Key, effective); + _noColorizationReason = asset != null ? null : NoColorizationReason(key, effective); _colorizationAsset = asset != null ? asset.Id + " (" + asset.Label + ")" : "none"; if (asset != null) { - _nativeResources.Own(ColorizationCatalog.Stage(asset, Path.Combine(_application.Configuration.DirectoryFor(_application.Plugin), "cache", "colorizations"), game.Identity.Key, out string staged)); + _nativeResources.Own(ColorizationCatalog.Stage(asset, Path.Combine(_application.Configuration.DirectoryFor(_application.Plugin), "cache", "colorizations"), key, out string staged)); settings.AltColorPath = staged; _stagedColorization = staged; } - _application.Logger.Info($"Colorization for {game.Identity.Key}: {_colorizationAsset}, source {asset?.Files[0] ?? _colorizationLibrary}."); + _application.Logger.Info($"Colorization for {key}{(key == game.Identity.Key ? "" : $" (table ROM {game.Identity.Key})")}: {_colorizationAsset}, source {asset?.Files[0] ?? _colorizationLibrary}."); ConfigureCabinetOutputs(game, effective, settings); _root = new GameObject("DMD plugin"); _root.SetActive(false); _root.transform.SetParent(scene.Table.transform, false); game.Lifetime.Own(new Subscription(() => { if (_root != null) UnityEngine.Object.Destroy(_root); })); @@ -90,6 +94,35 @@ public override Task PrepareGameAsync(PluginGameContext game, CancellationToken return Task.CompletedTask; } + /// The ROM the gamelogic engine plays, which PinMAME prepares first; the game's key for other engines. + private static string RunningRom(IUnityGameScene scene, GameIdentity game) + { + if (game.Provider != "pinmame") return game.Key; + string rom = scene.Table.GetComponentInChildren(true)?.RomName?.Trim().ToLowerInvariant(); + return string.IsNullOrEmpty(rom) || rom != Path.GetFileName(rom) || rom == "." || rom == ".." ? game.Key : rom; + } + + /// + /// The substitute ROM's colorization, or null when it has none or several: the user can only pick among the table ROM's, so + /// an ambiguous folder falls back to those. + /// + private ColorizationAsset SubstituteColorization(PluginGameContext game, PluginSettingsSnapshot settings, string key) + { + try { + return SelectColorization(game, settings, key, "auto"); + } catch (InvalidOperationException error) { + _application.Logger.Info($"Not using the colorizations of {key}: {error.Message}"); + return null; + } + } + + private ColorizationAsset SelectColorization(PluginGameContext game, PluginSettingsSnapshot settings, string key, string selection) + { + _colorizationLibrary = DmdPluginFactory.Library(settings, key); + var identity = key == game.Identity.Key ? game.Identity : new GameIdentity(game.Identity.Provider, key); + return ColorizationCatalog.Select(_colorizationLibrary, game.PackagePath, identity, selection, settings.String("VniKey").Length > 0); + } + /// /// The game's settings with DmdDevice.ini underneath what the user saved: values in the global settings or the game's profile /// win, every other one comes from the ini when it has it. diff --git a/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/DmdPluginFactory.cs b/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/DmdPluginFactory.cs index 49e4ed6..53c3f88 100644 --- a/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/DmdPluginFactory.cs +++ b/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/DmdPluginFactory.cs @@ -32,7 +32,9 @@ internal sealed partial class DmdPluginFactory : IPlayerPluginFactory, IPluginSe internal const string Id = "org.visualpinball.dmd"; public IReadOnlyList CabinetRoles { get; } = Array.AsReadOnly(new[] { CabinetOutputRole.Dmd }); private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public PluginDescriptor Descriptor { get; } = new PluginDescriptor(Id, "DMD", "Colorizations, your in-scene DMD and native displays, with optional cabinet hardware.") { EnabledByDefault = true, Category = "Displays", Order = 20 }; + public PluginDescriptor Descriptor { get; } = new PluginDescriptor(Id, "DMD", "Colorizations, your in-scene DMD and native displays, with optional cabinet hardware.") { EnabledByDefault = true, Category = "Displays", Order = 20, + // PinMAME first: it decides which ROM plays, and the colorization follows it + After = new[] { "org.visualpinball.pinmame" } }; internal static readonly PluginSettingsSchema SettingsSchema = BuildSchema(); public PluginSettingsSchema Schema => SettingsSchema; public IPluginSettingsProvider SettingsProvider => this; From e5e27040b40dc229e330b7b26eb90548a56e6627 Mon Sep 17 00:00:00 2001 From: freezy Date: Tue, 17 Nov 2026 15:35:18 +0100 Subject: [PATCH 2/2] plugin: look up each ROM's own colorization library The library imported from DmdDevice.ini is the table ROM's, so it hid the altcolor of the ROM that plays. The library is now resolved per ROM: the one the user saved, else that ROM's section of the ini, else the default. --- VisualPinball.Engine.DMD.Unity/Runtime/Plugins/DmdPlugin.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/DmdPlugin.cs b/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/DmdPlugin.cs index eab4148..0c5ae09 100644 --- a/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/DmdPlugin.cs +++ b/VisualPinball.Engine.DMD.Unity/Runtime/Plugins/DmdPlugin.cs @@ -54,7 +54,7 @@ public override Task PrepareGameAsync(PluginGameContext game, CancellationToken string key = colorization == "auto" ? rom : game.Identity.Key; var asset = key == game.Identity.Key ? SelectColorization(game, effective, key, colorization) : SubstituteColorization(game, effective, key); if (asset == null && key != game.Identity.Key) asset = SelectColorization(game, effective, key = game.Identity.Key, colorization); - if (asset == null && key != rom) _colorizationLibrary = DmdPluginFactory.Library(effective, key = rom); + if (asset == null && key != rom) _colorizationLibrary = DmdPluginFactory.Library(game.Settings, key = rom); settings.RomName = key; settings.EnableColorization = asset != null; _asset = asset; _settings = settings; @@ -118,7 +118,8 @@ private ColorizationAsset SubstituteColorization(PluginGameContext game, PluginS private ColorizationAsset SelectColorization(PluginGameContext game, PluginSettingsSnapshot settings, string key, string selection) { - _colorizationLibrary = DmdPluginFactory.Library(settings, key); + // the library the user saved, else the ROM's own altcolor in DmdDevice.ini: the imported one is the table ROM's + _colorizationLibrary = DmdPluginFactory.Library(game.Settings, key); var identity = key == game.Identity.Key ? game.Identity : new GameIdentity(game.Identity.Provider, key); return ColorizationCatalog.Select(_colorizationLibrary, game.PackagePath, identity, selection, settings.String("VniKey").Length > 0); }