Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion managed/CounterStrikeSharp.API/Core/BasePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public abstract class BasePlugin : IPlugin
{
private bool _disposed;

internal string _version = "<unknown>";

public BasePlugin()
{
RegisterListener<Listeners.OnMapEnd>(() =>
Expand All @@ -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; }

Expand Down
22 changes: 21 additions & 1 deletion managed/CounterStrikeSharp.API/Core/Plugin/PluginContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
* "<unknown>"
*/
if (Plugin is BasePlugin basePlugin)
{
// if no override we look for assembly version
if (basePlugin._version == "<unknown>")
{
Version? assemblyVersion = defaultAssembly.GetName().Version;

// if its set, we use that, otherwise it remains "<unknown>"
if (assemblyVersion != null)
{
basePlugin._version = assemblyVersion.ToString();
}
}
}

State = PluginState.Loading;

Plugin.ModulePath = _path;
Expand Down Expand Up @@ -241,4 +261,4 @@ public void Unload(bool hotReload = false)
_logger.LogInformation("Finished unloading plugin {Name}", cachedName);
}
}
}
}
Loading