mirror of
https://github.com/ppy/osu
synced 2025-01-18 12:00:58 +00:00
Add basic check for correct ruleset API version
This commit is contained in:
parent
f5710d8000
commit
758a554180
@ -77,9 +77,16 @@ namespace osu.Game.Rulesets
|
||||
continue;
|
||||
}
|
||||
|
||||
var instanceInfo = (Activator.CreateInstance(resolvedType) as Ruleset)?.RulesetInfo
|
||||
var instance = (Activator.CreateInstance(resolvedType) as Ruleset);
|
||||
var instanceInfo = instance?.RulesetInfo
|
||||
?? throw new RulesetLoadException(@"Instantiation failure");
|
||||
|
||||
if (!checkRulesetUpToDate(instance))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(instance.RulesetAPIVersionSupported),
|
||||
$"Ruleset API version is too old (was {instance.RulesetAPIVersionSupported}, expected {Ruleset.CURRENT_RULESET_API_VERSION})");
|
||||
}
|
||||
|
||||
// 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();
|
||||
@ -104,6 +111,25 @@ namespace osu.Game.Rulesets
|
||||
});
|
||||
}
|
||||
|
||||
private bool checkRulesetUpToDate(Ruleset instance)
|
||||
{
|
||||
switch (instance.RulesetAPIVersionSupported)
|
||||
{
|
||||
// The default `virtual` implementation leaves the version string empty.
|
||||
// Consider rulesets which haven't override the version as up-to-date for now.
|
||||
// At some point (once ruleset devs add versioning), we'll probably want to disallow this for deployed builds.
|
||||
case @"":
|
||||
// Rulesets which are bundled with the game. Saves having to update their versions each bump.
|
||||
case @"internal":
|
||||
// Ruleset is up-to-date, all good.
|
||||
case Ruleset.CURRENT_RULESET_API_VERSION:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void testRulesetCompatibility(RulesetInfo rulesetInfo)
|
||||
{
|
||||
// do various operations to ensure that we are in a good state.
|
||||
|
Loading…
Reference in New Issue
Block a user