Repository navigation
Offer compatible ROMs when the table's ROM is missing #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
VisualPinball.Engine.PinMAME.Unity/Editor/PinMameCompatibleRomsExport.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Visual Pinball Engine | ||
| // Copyright (C) 2026 freezy and VPE Team | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // ReSharper disable CheckNamespace | ||
|
|
||
| using System; | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using UnityEditor; | ||
| using UnityEngine; | ||
|
|
||
| namespace VisualPinball.Engine.PinMAME.Editor | ||
| { | ||
| /// <summary> | ||
| /// Looks up the ROMs compatible with a table's ROM in the machine catalog when the table is | ||
| /// exported, so the player can offer them when the table's ROM isn't there. | ||
| /// </summary> | ||
| [InitializeOnLoad] | ||
| internal static class PinMameCompatibleRomsExport | ||
| { | ||
| // the export waits for it; a cached catalog answers at once | ||
| private static readonly TimeSpan Timeout = TimeSpan.FromSeconds(15); | ||
|
|
||
| static PinMameCompatibleRomsExport() | ||
| { | ||
| PinMameGamelogicEngine.ResolveCompatibleRoms = Resolve; | ||
| } | ||
|
|
||
| private static PinMameCompatibleRom[] Resolve(PinMameGamelogicEngine engine) | ||
| { | ||
| if (!engine || string.IsNullOrWhiteSpace(engine.machineId) || string.IsNullOrWhiteSpace(engine.romId)) { | ||
| return null; | ||
| } | ||
| try { | ||
| using var cancellation = new CancellationTokenSource(Timeout); | ||
| PinMameGameDefinitionCatalogClient.EnsureCacheRoot(); | ||
| var catalog = PinMameGameDefinitionCatalogClient.GetCatalogAsync(false, cancellation.Token) | ||
| .ConfigureAwait(false).GetAwaiter().GetResult().Value; | ||
| var machine = catalog.Machines.FirstOrDefault(entry => string.Equals(entry.Id, engine.machineId, StringComparison.Ordinal)); | ||
| if (machine == null || string.IsNullOrWhiteSpace(machine.Detail)) { | ||
| return null; | ||
| } | ||
| var definition = PinMameGameDefinitionCatalogClient.GetDefinitionAsync(machine, false, cancellation.Token) | ||
| .ConfigureAwait(false).GetAwaiter().GetResult(); | ||
| var roms = PinMameGameDefinitionConverter.ReadCompatibleRoms(definition.Value, engine.romId); | ||
| Debug.Log($"[PinMAME] Exporting {roms.Length} ROM(s) compatible with {engine.romId}: {string.Join(", ", roms.Select(rom => rom.Id))}."); | ||
| return roms; | ||
| } catch (Exception exception) { | ||
| Debug.LogWarning($"[PinMAME] Could not look up the ROMs compatible with {engine.romId} in the machine catalog; exporting the {engine.CompatibleRoms.Count} saved with the table. {exception.Message}"); | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
VisualPinball.Engine.PinMAME.Unity/Editor/PinMameCompatibleRomsExport.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
VisualPinball.Engine.PinMAME.Unity/Runtime/PinMameCompatibleRom.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Visual Pinball Engine | ||
| // Copyright (C) 2026 freezy and VPE Team | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
| // Licensed under MIT. See https://opensource.org/license/mit. | ||
|
|
||
| using System; | ||
|
|
||
| namespace VisualPinball.Engine.PinMAME | ||
| { | ||
| /// <summary> | ||
| /// How closely a ROM matches the physical machine a table was made for, as the machine catalog | ||
| /// at games.visualpinball.org tells. | ||
| /// </summary> | ||
| public enum PinMameRomCompatibility | ||
| { | ||
| /// <summary> | ||
| /// Another revision of the same game: switches, coils, lamps and displays are wired the same. | ||
| /// </summary> | ||
| Identical = 0, | ||
|
|
||
| /// <summary> | ||
| /// Runs on the same machine, but isn't just a revision of the table's ROM, e.g. a community | ||
| /// fix or alternative firmware. | ||
| /// </summary> | ||
| Compatible = 1, | ||
|
|
||
| /// <summary> | ||
| /// A ROM of the same machine that nobody has confirmed runs it the same way. | ||
| /// </summary> | ||
| Unverified = 2, | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A ROM that can run a table in place of the one its author chose. | ||
| /// </summary> | ||
| [Serializable] | ||
| public struct PinMameCompatibleRom | ||
| { | ||
| public string Id; | ||
| public string Description; | ||
| public PinMameRomCompatibility Compatibility; | ||
|
|
||
| public PinMameCompatibleRom(string id, string description, PinMameRomCompatibility compatibility) | ||
| { | ||
| Id = id; | ||
| Description = description ?? string.Empty; | ||
| Compatibility = compatibility; | ||
| } | ||
|
|
||
| public override string ToString() => string.IsNullOrWhiteSpace(Description) ? Id : $"{Id} ({Description})"; | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
VisualPinball.Engine.PinMAME.Unity/Runtime/PinMameCompatibleRom.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.