PluginSide from AssemblyMetadataAttribute

This commit is contained in:
js6pak committed 2021-10-23 21:44:03 +02:00
1 parent 1107480ea2
commit 179cb84da2
2 files changed
+20 -2

No files matched your search

+1 -2
View File
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using BepInEx.IL2CPP;
namespace Reactor.Networking
@@ -32,7 +31,7 @@ namespace Reactor.Networking
i++,
plugin.Metadata.GUID,
plugin.Metadata.Version.Clean(),
plugin.Instance.GetType().GetCustomAttribute<ReactorPluginSideAttribute>()?.Side ?? PluginSide.Both
ReactorPluginSideAttribute.GetPluginSide(plugin.Instance.GetType())
))
.ToHashSet();
+19
View File
@@ -1,4 +1,6 @@
using System;
using System.Linq;
using System.Reflection;
namespace Reactor
{
@@ -14,5 +16,22 @@ namespace Reactor
{
Side = side;
}
public static PluginSide GetPluginSide(Type type)
{
var attribute = type.GetCustomAttribute<ReactorPluginSideAttribute>();
if (attribute != null)
{
return attribute.Side;
}
var metadataAttribute = type.Assembly.GetCustomAttributes<AssemblyMetadataAttribute>().SingleOrDefault(x => x.Key == "Reactor.PluginSide");
if (metadataAttribute != null)
{
return Enum.Parse<PluginSide>(metadataAttribute.Value, true);
}
return PluginSide.Both;
}
}
}