Fix rulesets potentially being marked `Available` even when methods are missing

Came up when running the game after the recent breaking changes
(https://github.com/ppy/osu/pull/16722), where two template rulesets I
had loaded were erroring on startup but still being marked as available,
allowing them to crash the game on attempting to initiate relpay logic.

These cases are already handled for first-time ruleset loading via the
`GetTypes()` enumeration in `RulesetStore.addRuleset`, but when
consistency checking already present rulesets the only runtime
validation being done was `ruleset.CreateInstance()`, which does not
handle missing types or methods.
This commit is contained in:
Dean Herbert 2022-02-02 14:51:55 +09:00
parent 6d962e7925
commit 0c5da9370a
1 changed files with 4 additions and 0 deletions

View File

@ -149,6 +149,10 @@ private void addMissingRulesets()
var instanceInfo = (Activator.CreateInstance(resolvedType) as Ruleset)?.RulesetInfo
?? throw new RulesetLoadException(@"Instantiation failure");
// If a ruleset isn't up-to-date with the API, it could cause a crash at an arbitrary point of execution.
// To eagerly handle cases of missing implementations, enumerate all types here and mark as non-available on throw.
resolvedType.Assembly.GetTypes();
r.Name = instanceInfo.Name;
r.ShortName = instanceInfo.ShortName;
r.InstantiationInfo = instanceInfo.InstantiationInfo;