Files
H3VR-TNH-Quality-of-Life-Im…/Assets/MeatKit/Editor/BuildPipeline/BuildItem.cs
T
2022-01-22 20:13:49 -08:00

52 lines
1.8 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using BepInEx;
using Mono.Cecil;
using Mono.Cecil.Cil;
using UnityEditor;
using UnityEngine;
namespace MeatKit
{
public abstract class BuildItem : ScriptableObject, IValidatable
{
public abstract IEnumerable<string> RequiredDependencies { get; }
public virtual Dictionary<string, BuildMessage> Validate()
{
return new Dictionary<string, BuildMessage>();
}
public virtual List<AssetBundleBuild> ConfigureBuild()
{
return null;
}
public virtual void GenerateLoadAssets(TypeDefinition plugin, ILProcessor il)
{
}
protected void EnsurePluginDependsOn(TypeDefinition plugin, string pluginGuid, string pluginVersion)
{
// Check if the plugin already has this dependency
var alreadyDependsOn = plugin.CustomAttributes
.Where(a => a.AttributeType.Name == "BepInDependency")
.Any(attribute => (string) attribute.ConstructorArguments[0].Value == pluginGuid);
// If it doesn't we need to add it.
if (!alreadyDependsOn)
{
MethodBase constructor =
typeof(BepInDependency).GetConstructor(new[] {typeof(string), typeof(string)});
var attribute = new CustomAttribute(plugin.Module.ImportReference(constructor));
plugin.CustomAttributes.Add(attribute);
var str = plugin.Module.TypeSystem.String;
attribute.ConstructorArguments.Add(new CustomAttributeArgument(str, pluginGuid));
attribute.ConstructorArguments.Add(new CustomAttributeArgument(str, pluginVersion));
}
}
}
}