From d41c90eb131a9782896fa8779eeae35cafa08ec4 Mon Sep 17 00:00:00 2001 From: ManlyMarco Date: Wed, 28 Aug 2019 13:05:21 +0200 Subject: [PATCH] Make BepInDependency implement ICacheable and hide ICacheable implementations --- BepInEx/Contract/Attributes.cs | 27 +++++++++++++++++---------- BepInEx/Contract/PluginInfo.cs | 17 +++++++++-------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/BepInEx/Contract/Attributes.cs b/BepInEx/Contract/Attributes.cs index a26427b..f655fc5 100644 --- a/BepInEx/Contract/Attributes.cs +++ b/BepInEx/Contract/Attributes.cs @@ -1,10 +1,9 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; -using System.Reflection; -using BepInEx.Logging; +using BepInEx.Bootstrap; using Mono.Cecil; -using Mono.Collections.Generic; namespace BepInEx { @@ -66,7 +65,7 @@ namespace BepInEx /// This attribute specifies any dependencies that this plugin has on other plugins. /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] - public class BepInDependency : Attribute + public class BepInDependency : Attribute, ICacheable { public enum DependencyFlags { @@ -120,12 +119,6 @@ namespace BepInEx MinimumVersion = new Version(MinimumDependencyVersion); } - internal BepInDependency(string DependencyGUID, DependencyFlags Flags, string MinimumDependencyVersion) : this(DependencyGUID, Flags) - { - if (!string.IsNullOrEmpty(MinimumDependencyVersion)) - MinimumVersion = new Version(MinimumDependencyVersion); - } - internal static IEnumerable FromCecilType(TypeDefinition td) { var attrs = MetadataHelper.GetCustomAttributes(td, true); @@ -137,6 +130,20 @@ namespace BepInEx return new BepInDependency(dependencyGuid, (DependencyFlags)secondArg); }).ToList(); } + + void ICacheable.Save(BinaryWriter bw) + { + bw.Write(DependencyGUID); + bw.Write((int)Flags); + bw.Write(MinimumVersion.ToString()); + } + + void ICacheable.Load(BinaryReader br) + { + DependencyGUID = br.ReadString(); + Flags = (DependencyFlags)br.ReadInt32(); + MinimumVersion = new Version(br.ReadString()); + } } /// diff --git a/BepInEx/Contract/PluginInfo.cs b/BepInEx/Contract/PluginInfo.cs index 2e73b7f..8add2b0 100644 --- a/BepInEx/Contract/PluginInfo.cs +++ b/BepInEx/Contract/PluginInfo.cs @@ -19,7 +19,7 @@ namespace BepInEx.Contract internal string TypeName { get; set; } - public void Save(BinaryWriter bw) + void ICacheable.Save(BinaryWriter bw) { bw.Write(TypeName); @@ -35,14 +35,10 @@ namespace BepInEx.Contract var depList = Dependencies.ToList(); bw.Write(depList.Count); foreach (var bepInDependency in depList) - { - bw.Write(bepInDependency.DependencyGUID); - bw.Write((int)bepInDependency.Flags); - bw.Write(bepInDependency.MinimumVersion.ToString()); - } + ((ICacheable)bepInDependency).Save(bw); } - public void Load(BinaryReader br) + void ICacheable.Load(BinaryReader br) { TypeName = br.ReadString(); @@ -57,7 +53,12 @@ namespace BepInEx.Contract var depCount = br.ReadInt32(); var depList = new List(depCount); for (int i = 0; i < depCount; i++) - depList.Add(new BepInDependency(br.ReadString(), (BepInDependency.DependencyFlags) br.ReadInt32(), br.ReadString())); + { + var dep = new BepInDependency(""); + ((ICacheable)dep).Load(br); + depList.Add(dep); + } + Dependencies = depList; } }