diff --git a/managed/CounterStrikeSharp.API/Core/BasePlugin.cs b/managed/CounterStrikeSharp.API/Core/BasePlugin.cs index 600a9ee59..fd45fbb4a 100644 --- a/managed/CounterStrikeSharp.API/Core/BasePlugin.cs +++ b/managed/CounterStrikeSharp.API/Core/BasePlugin.cs @@ -40,6 +40,8 @@ public abstract class BasePlugin : IPlugin { private bool _disposed; + internal string _version = ""; + public BasePlugin() { RegisterListener(() => @@ -52,7 +54,7 @@ public BasePlugin() } public abstract string ModuleName { get; } - public abstract string ModuleVersion { get; } + public virtual string ModuleVersion { get => _version; } public virtual string ModuleAuthor { get; } diff --git a/managed/CounterStrikeSharp.API/Core/Plugin/PluginContext.cs b/managed/CounterStrikeSharp.API/Core/Plugin/PluginContext.cs index 5b6326a48..fa8689fef 100644 --- a/managed/CounterStrikeSharp.API/Core/Plugin/PluginContext.cs +++ b/managed/CounterStrikeSharp.API/Core/Plugin/PluginContext.cs @@ -204,6 +204,26 @@ public void Load(bool hotReload = false) if (Plugin == null) throw new Exception("Unable to create plugin instance"); + /* Version Priority order: + * ModuleVersion override + * Assembly.GetName().Version + * "" + */ + if (Plugin is BasePlugin basePlugin) + { + // if no override we look for assembly version + if (basePlugin._version == "") + { + Version? assemblyVersion = defaultAssembly.GetName().Version; + + // if its set, we use that, otherwise it remains "" + if (assemblyVersion != null) + { + basePlugin._version = assemblyVersion.ToString(); + } + } + } + State = PluginState.Loading; Plugin.ModulePath = _path; @@ -241,4 +261,4 @@ public void Unload(bool hotReload = false) _logger.LogInformation("Finished unloading plugin {Name}", cachedName); } } -} \ No newline at end of file +}