Skip to content
Open
Show file tree
Hide file tree
Changes from 16 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 @@
{
private bool _disposed;

internal string _version = "<unknown>";

public BasePlugin()
{
RegisterListener<Listeners.OnMapEnd>(() =>
Expand All @@ -52,7 +54,7 @@
}

public abstract string ModuleName { get; }
public abstract string ModuleVersion { get; }
public virtual string ModuleVersion { get => _version; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried loading a plugin compiled with this API against an older version of CS#? Does it complain about the virtual/abstract change when its being invoked or does it generate the same IL code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I recall correctly I did not, but I'll check today

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the other way around would also be good, so old plugin against new CS#.


public virtual string ModuleAuthor { get; }

Expand Down Expand Up @@ -478,7 +480,7 @@
}
}

public void RegisterFakeConVars(Type type, object instance = null)

Check warning on line 483 in managed/CounterStrikeSharp.API/Core/BasePlugin.cs

View workflow job for this annotation

GitHub Actions / build_managed

Cannot convert null literal to non-nullable reference type.

Check warning on line 483 in managed/CounterStrikeSharp.API/Core/BasePlugin.cs

View workflow job for this annotation

GitHub Actions / build_managed

Cannot convert null literal to non-nullable reference type.
{
var convars = type
.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)
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>")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe basePlugin.ModuleVersion instead of the backing field?

{
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