Decompiled source of CessilCellsCeaChells v0.3.6

BepInEx/patchers/CessilCellsCeaChells/CessilCellsCeaChells.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using CessilCellsCeaChells.CeaChore;
using CessilCellsCeaChells.Internal;
using CessilCellsCeaChells.Merges;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
using Mono.Collections.Generic;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("www_Day_Dream")]
[assembly: AssemblyConfiguration("Mono10")]
[assembly: AssemblyFileVersion("0.3.6.0")]
[assembly: AssemblyInformationalVersion("0.3.6+7d89ac2f0f27f18bdede1a7a48d74cf17c6333f1")]
[assembly: AssemblyProduct("CessilCellsCeaChells")]
[assembly: AssemblyTitle("CessilCellsCeaChells")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.6.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CessilCellsCeaChells
{
	public class CessilMerger : IDisposable
	{
		public readonly List<AssemblyDefinition> AssembliesToDispose = new List<AssemblyDefinition>();

		public IAssemblyResolver? TypeResolver { get; set; }

		public string CachePath { get; set; } = Path.GetDirectoryName(typeof(CessilMerger).Assembly.Location) ?? "";


		public IEnumerable<string> TargetDLLFileNames => Merges.Select((CessilMerge merge) => merge.TargetAssemblyName).Distinct();

		private List<CessilMerge> Merges { get; } = new List<CessilMerge>();


		public static event Action<object>? LogDebug;

		public static event Action<object>? LogWarn;

		public static void LogDebugSafe(object o)
		{
			CessilMerger.LogDebug?.Invoke(o);
		}

		public static void LogWarnSafe(object o)
		{
			CessilMerger.LogWarn?.Invoke(o);
		}

		public bool LoadMergesFrom(string dllPath, out int count)
		{
			count = 0;
			if (!AssemblyCacheHandler.TryLoadCachedMerges(dllPath, this, out CessilMerge[] merges))
			{
				return false;
			}
			Merges.AddRange(merges);
			count = merges.Length;
			return true;
		}

		public void MergeInto(AssemblyDefinition assembly)
		{
			AssemblyDefinition assembly2 = assembly;
			foreach (CessilMerge item in Merges.Where((CessilMerge merge) => merge.TargetAssemblyName == ((AssemblyNameReference)assembly2.Name).Name + ".dll"))
			{
				TypeDefinition type = assembly2.MainModule.GetType(((MemberReference)item.TargetTypeRef).FullName);
				IMemberDefinition memberDefinition;
				if (type == null)
				{
					LogWarnSafe("Disregarding merge as it's target type doesn't exist!");
				}
				else if (item.TryMergeInto(type, out memberDefinition))
				{
					LogDebugSafe("Successfully merged '" + ((memberDefinition != null) ? memberDefinition.FullName : null) + "' into '" + ((MemberReference)type).FullName + "'");
				}
			}
		}

		public void Dispose()
		{
			LogDebugSafe("Disposing of loaded AssemblyDefinitions..");
			foreach (AssemblyDefinition item in AssembliesToDispose)
			{
				item.Dispose();
			}
		}
	}
}
namespace CessilCellsCeaChells.Merges
{
	internal abstract class CessilMerge
	{
		internal readonly TypeReference TargetTypeRef;

		private static readonly Dictionary<string, Type> CessilMergeTypes = new Dictionary<string, Type>
		{
			{
				typeof(RequiresFieldAttribute).FullName,
				typeof(FieldMerge)
			},
			{
				typeof(RequiresPropertyAttribute).FullName,
				typeof(PropertyMerge)
			},
			{
				typeof(RequiresMethodAttribute).FullName,
				typeof(MethodMerge)
			},
			{
				typeof(RequiresMethodDefaultsAttribute).FullName,
				typeof(MethodMerge)
			},
			{
				typeof(RequiresEnumInsertionAttribute).FullName,
				typeof(EnumInsertionMerge)
			}
		};

		internal string TargetAssemblyName => ((AssemblyNameReference)((MemberReference)TargetTypeRef.Resolve()).Module.Assembly.Name).Name + ".dll";

		protected CessilMerge(TypeReference targetTypeRef)
		{
			TargetTypeRef = targetTypeRef;
			base..ctor();
		}

		internal static bool TryCreateMerges(AssemblyDefinition assembly, out CessilMerge[] merges)
		{
			merges = (from customAttribute in (IEnumerable<CustomAttribute>)assembly.CustomAttributes
				select new KeyValuePair<bool, CessilMerge>(TryConvertFrom(customAttribute, out CessilMerge merge), merge) into tuple
				where tuple.Key
				select tuple.Value).ToArray();
			return merges.Length != 0;
		}

		private static bool TryConvertFrom(CustomAttribute attribute, out CessilMerge? merge)
		{
			merge = null;
			if (!CessilMergeTypes.TryGetValue(((MemberReference)attribute.AttributeType).FullName, out Type value))
			{
				return false;
			}
			merge = (CessilMerge)Activator.CreateInstance(value, attribute);
			return merge != null;
		}

		internal static TypeReference GetOrImportTypeReference(ModuleDefinition into, Type type)
		{
			TypeReference result = default(TypeReference);
			if (!into.TryGetTypeReference(type.FullName, ref result))
			{
				return into.ImportReference(type);
			}
			return result;
		}

		internal static TypeReference GetOrImportTypeReference(ModuleDefinition into, TypeReference type)
		{
			TypeReference result = default(TypeReference);
			if (!into.TryGetTypeReference(((MemberReference)type).FullName, ref result))
			{
				return into.ImportReference(type);
			}
			return result;
		}

		internal abstract CustomAttribute ConvertToAttribute(AssemblyDefinition into);

		internal abstract bool TryMergeInto(TypeDefinition typeDefinition, out IMemberDefinition? memberDefinition);
	}
	internal class EnumInsertionMerge : CessilMerge
	{
		private readonly string EnumEntryName;

		public EnumInsertionMerge(CustomAttribute attribute)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			CustomAttributeArgument val = attribute.ConstructorArguments[1];
			EnumEntryName = (string)((CustomAttributeArgument)(ref val)).Value;
			val = attribute.ConstructorArguments[0];
			base..ctor((TypeReference)((CustomAttributeArgument)(ref val)).Value);
		}

		internal override CustomAttribute ConvertToAttribute(AssemblyDefinition into)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			TypeReference orImportTypeReference = CessilMerge.GetOrImportTypeReference(into.MainModule, typeof(Type));
			TypeReference orImportTypeReference2 = CessilMerge.GetOrImportTypeReference(into.MainModule, TargetTypeRef);
			CustomAttribute val = new CustomAttribute(into.MainModule.ImportReference((MethodBase)typeof(RequiresEnumInsertionAttribute).GetConstructors().First()));
			val.ConstructorArguments.Add(new CustomAttributeArgument(orImportTypeReference, (object)orImportTypeReference2));
			val.ConstructorArguments.Add(new CustomAttributeArgument(into.MainModule.TypeSystem.String, (object)EnumEntryName));
			return val;
		}

		internal override bool TryMergeInto(TypeDefinition typeDefinition, out IMemberDefinition? memberDefinition)
		{
			memberDefinition = null;
			FieldDefinition fieldDefinition;
			bool flag = CessilHelper.TryCreateField(typeDefinition, EnumEntryName, (TypeReference)(object)typeDefinition, out fieldDefinition, (FieldAttributes)32854);
			long num = -1L;
			foreach (FieldDefinition item in ((IEnumerable<FieldDefinition>)typeDefinition.Fields).Where((FieldDefinition field) => ((MemberReference)field).Name != "value__"))
			{
				if (Convert.ToInt64(item.Constant) > Convert.ToInt64(num))
				{
					num = Convert.ToInt64(item.Constant);
				}
			}
			if (flag)
			{
				fieldDefinition.Constant = Convert.ChangeType(num + 1, Type.GetType(((MemberReference)((FieldReference)((IEnumerable<FieldDefinition>)typeDefinition.Fields).First((FieldDefinition field) => ((MemberReference)field).Name == "value__")).FieldType).FullName) ?? throw new InvalidOperationException());
			}
			if (flag)
			{
				memberDefinition = (IMemberDefinition?)(object)fieldDefinition;
			}
			return flag;
		}
	}
	internal class FieldMerge : CessilMerge
	{
		private readonly string FieldName;

		private readonly TypeReference FieldType;

		private readonly bool IsPublic;

		public FieldMerge(CustomAttribute attribute)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			CustomAttributeArgument val = attribute.ConstructorArguments[1];
			FieldName = (string)((CustomAttributeArgument)(ref val)).Value;
			val = attribute.ConstructorArguments[2];
			FieldType = (TypeReference)((CustomAttributeArgument)(ref val)).Value;
			int isPublic;
			if (attribute.ConstructorArguments.Count > 3)
			{
				val = attribute.ConstructorArguments[3];
				isPublic = (((bool)((CustomAttributeArgument)(ref val)).Value) ? 1 : 0);
			}
			else
			{
				isPublic = 0;
			}
			IsPublic = (byte)isPublic != 0;
			val = attribute.ConstructorArguments[0];
			base..ctor((TypeReference)((CustomAttributeArgument)(ref val)).Value);
		}

		internal override CustomAttribute ConvertToAttribute(AssemblyDefinition into)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			TypeReference orImportTypeReference = CessilMerge.GetOrImportTypeReference(into.MainModule, typeof(Type));
			TypeReference orImportTypeReference2 = CessilMerge.GetOrImportTypeReference(into.MainModule, TargetTypeRef);
			TypeReference orImportTypeReference3 = CessilMerge.GetOrImportTypeReference(into.MainModule, FieldType);
			CustomAttribute val = new CustomAttribute(into.MainModule.ImportReference((MethodBase)typeof(RequiresFieldAttribute).GetConstructors().First()));
			val.ConstructorArguments.Add(new CustomAttributeArgument(orImportTypeReference, (object)orImportTypeReference2));
			val.ConstructorArguments.Add(new CustomAttributeArgument(into.MainModule.TypeSystem.String, (object)FieldName));
			val.ConstructorArguments.Add(new CustomAttributeArgument(orImportTypeReference, (object)orImportTypeReference3));
			val.ConstructorArguments.Add(new CustomAttributeArgument(into.MainModule.TypeSystem.Boolean, (object)IsPublic));
			return val;
		}

		internal override bool TryMergeInto(TypeDefinition typeDefinition, out IMemberDefinition? memberDefinition)
		{
			memberDefinition = null;
			FieldDefinition fieldDefinition;
			bool flag = CessilHelper.TryCreateField(typeDefinition, FieldName, CessilMerge.GetOrImportTypeReference(((MemberReference)typeDefinition).Module, FieldType), out fieldDefinition, (FieldAttributes)((!IsPublic) ? 1 : 6));
			if (flag)
			{
				memberDefinition = (IMemberDefinition?)(object)fieldDefinition;
			}
			return flag;
		}
	}
	internal class MethodMerge : CessilMerge
	{
		private readonly string MethodName;

		private readonly TypeReference MethodType;

		private readonly TypeReference[] MethodParameters;

		private readonly object[] MethodDefaults;

		public MethodMerge(CustomAttribute attribute)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			CustomAttributeArgument val = attribute.ConstructorArguments[1];
			MethodName = (string)((CustomAttributeArgument)(ref val)).Value;
			val = attribute.ConstructorArguments[2];
			MethodType = (TypeReference)((CustomAttributeArgument)(ref val)).Value;
			val = attribute.ConstructorArguments[3];
			MethodParameters = ((IEnumerable<CustomAttributeArgument>)(CustomAttributeArgument[])((CustomAttributeArgument)(ref val)).Value).Select((Func<CustomAttributeArgument, TypeReference>)((CustomAttributeArgument attr) => (TypeReference)((CustomAttributeArgument)(ref attr)).Value)).ToArray();
			object[] methodDefaults;
			if (attribute.ConstructorArguments.Count <= 4)
			{
				methodDefaults = new object[0];
			}
			else
			{
				val = attribute.ConstructorArguments[4];
				methodDefaults = ((CustomAttributeArgument[])((CustomAttributeArgument)(ref val)).Value).Select((CustomAttributeArgument attr) => ((CustomAttributeArgument)(ref attr)).Value).ToArray();
			}
			MethodDefaults = methodDefaults;
			val = attribute.ConstructorArguments[0];
			base..ctor((TypeReference)((CustomAttributeArgument)(ref val)).Value);
		}

		internal override CustomAttribute ConvertToAttribute(AssemblyDefinition into)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			AssemblyDefinition into2 = into;
			TypeReference typeTypeRef = CessilMerge.GetOrImportTypeReference(into2.MainModule, typeof(Type));
			TypeReference orImportTypeReference = CessilMerge.GetOrImportTypeReference(into2.MainModule, TargetTypeRef);
			TypeReference orImportTypeReference2 = CessilMerge.GetOrImportTypeReference(into2.MainModule, MethodType);
			Type type = ((MethodDefaults.Length != 0) ? typeof(RequiresMethodDefaultsAttribute) : typeof(RequiresMethodAttribute));
			CustomAttribute val = new CustomAttribute(into2.MainModule.ImportReference((MethodBase)type.GetConstructors().First()));
			val.ConstructorArguments.Add(new CustomAttributeArgument(typeTypeRef, (object)orImportTypeReference));
			val.ConstructorArguments.Add(new CustomAttributeArgument(into2.MainModule.TypeSystem.String, (object)MethodName));
			val.ConstructorArguments.Add(new CustomAttributeArgument(typeTypeRef, (object)orImportTypeReference2));
			val.ConstructorArguments.Add(new CustomAttributeArgument((TypeReference)(object)TypeReferenceRocks.MakeArrayType(typeTypeRef), (object)((IEnumerable<TypeReference>)MethodParameters).Select((Func<TypeReference, CustomAttributeArgument>)((TypeReference tRef) => new CustomAttributeArgument(typeTypeRef, (object)CessilMerge.GetOrImportTypeReference(into2.MainModule, tRef)))).ToArray()));
			CustomAttribute val2 = val;
			if (MethodDefaults.Length != 0)
			{
				val2.ConstructorArguments.Add(new CustomAttributeArgument((TypeReference)(object)TypeReferenceRocks.MakeArrayType(into2.MainModule.TypeSystem.Object), (object)((IEnumerable<object>)MethodDefaults).Select((Func<object, CustomAttributeArgument>)((object tObj) => new CustomAttributeArgument(into2.MainModule.TypeSystem.Object, tObj))).ToArray()));
			}
			return val2;
		}

		internal override bool TryMergeInto(TypeDefinition typeDefinition, out IMemberDefinition? memberDefinition)
		{
			TypeDefinition typeDefinition2 = typeDefinition;
			memberDefinition = null;
			TypeReference[] importedParamReferences = MethodParameters.Select((TypeReference param) => ((MemberReference)typeDefinition2).Module.ImportReference((TypeReference)(object)param.Resolve())).ToArray();
			MethodDefinition methodDefinition;
			bool flag = CessilHelper.TryCreateMethod(typeDefinition2, MethodName, CessilMerge.GetOrImportTypeReference(((MemberReference)typeDefinition2).Module, MethodType), importedParamReferences, ((IEnumerable<object>)MethodDefaults).Select((Func<object, CustomAttributeArgument>)((object obj) => (CustomAttributeArgument)obj)).ToArray(), out methodDefinition);
			if (flag)
			{
				memberDefinition = (IMemberDefinition?)(object)methodDefinition;
			}
			return flag;
		}
	}
	internal class PropertyMerge : CessilMerge
	{
		private readonly string PropertyName;

		private readonly TypeReference PropertyType;

		private readonly bool InitializeOnAccess;

		public PropertyMerge(CustomAttribute attribute)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			CustomAttributeArgument val = attribute.ConstructorArguments[1];
			PropertyName = (string)((CustomAttributeArgument)(ref val)).Value;
			val = attribute.ConstructorArguments[2];
			PropertyType = (TypeReference)((CustomAttributeArgument)(ref val)).Value;
			val = attribute.ConstructorArguments[3];
			InitializeOnAccess = (bool)((CustomAttributeArgument)(ref val)).Value;
			val = attribute.ConstructorArguments[0];
			base..ctor((TypeReference)((CustomAttributeArgument)(ref val)).Value);
		}

		internal override CustomAttribute ConvertToAttribute(AssemblyDefinition into)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			TypeReference orImportTypeReference = CessilMerge.GetOrImportTypeReference(into.MainModule, typeof(Type));
			TypeReference orImportTypeReference2 = CessilMerge.GetOrImportTypeReference(into.MainModule, TargetTypeRef);
			TypeReference orImportTypeReference3 = CessilMerge.GetOrImportTypeReference(into.MainModule, PropertyType);
			CustomAttribute val = new CustomAttribute(into.MainModule.ImportReference((MethodBase)typeof(RequiresPropertyAttribute).GetConstructors().First()));
			val.ConstructorArguments.Add(new CustomAttributeArgument(orImportTypeReference, (object)orImportTypeReference2));
			val.ConstructorArguments.Add(new CustomAttributeArgument(into.MainModule.TypeSystem.String, (object)PropertyName));
			val.ConstructorArguments.Add(new CustomAttributeArgument(orImportTypeReference, (object)orImportTypeReference3));
			val.ConstructorArguments.Add(new CustomAttributeArgument(into.MainModule.TypeSystem.Boolean, (object)InitializeOnAccess));
			return val;
		}

		internal override bool TryMergeInto(TypeDefinition typeDefinition, out IMemberDefinition? memberDefinition)
		{
			memberDefinition = null;
			TypeReference orImportTypeReference = CessilMerge.GetOrImportTypeReference(((MemberReference)typeDefinition).Module, PropertyType);
			if (!CessilHelper.TryCreateProperty(typeDefinition, PropertyName, orImportTypeReference, out FieldDefinition backingField, out PropertyDefinition propertyDefinition))
			{
				return false;
			}
			if (InitializeOnAccess)
			{
				AddSingletonCheckToProperty(backingField, PropertyType.Resolve(), propertyDefinition);
			}
			memberDefinition = (IMemberDefinition?)(object)propertyDefinition;
			return true;
		}

		private static void AddSingletonCheckToProperty(FieldDefinition backingField, TypeDefinition resolvedAndImported, PropertyDefinition singletonPropDef)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			MethodDefinition val = ((IEnumerable<MethodDefinition>)resolvedAndImported.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition method) => ((MemberReference)method).Name == ".ctor" && ((MethodReference)method).Parameters.Count == 0));
			if (val != null)
			{
				MethodReference val2 = ((MemberReference)backingField).Module.ImportReference((MethodReference)(object)val);
				MethodDefinition getMethod = singletonPropDef.GetMethod;
				getMethod.Body.Instructions.Clear();
				ILProcessor iLProcessor = getMethod.Body.GetILProcessor();
				iLProcessor.Emit(OpCodes.Ldarg_0);
				iLProcessor.Emit(OpCodes.Ldfld, (FieldReference)(object)backingField);
				iLProcessor.Emit(OpCodes.Ldnull);
				iLProcessor.Emit(OpCodes.Ceq);
				Instruction val3 = iLProcessor.Create(OpCodes.Nop);
				iLProcessor.Emit(OpCodes.Brfalse, val3);
				iLProcessor.Emit(OpCodes.Ldarg_0);
				iLProcessor.Emit(OpCodes.Newobj, val2);
				iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)singletonPropDef.SetMethod);
				iLProcessor.Append(val3);
				MethodBodyRocks.OptimizeMacros(getMethod.Body);
				iLProcessor.Emit(OpCodes.Ldarg_0);
				iLProcessor.Emit(OpCodes.Ldfld, (FieldReference)(object)backingField);
				iLProcessor.Emit(OpCodes.Ret);
			}
		}
	}
}
namespace CessilCellsCeaChells.Internal
{
	internal static class AssemblyCacheHandler
	{
		private const string AssemblyCacheDLLPrefix = "CessilCache.";

		internal static bool TryLoadCachedMerges(string assemblyPath, CessilMerger cessilMerger, out CessilMerge[] merges)
		{
			merges = new CessilMerge[0];
			if (!Directory.Exists(cessilMerger.CachePath))
			{
				Directory.CreateDirectory(cessilMerger.CachePath);
			}
			string text = Path.Combine(cessilMerger.CachePath, "CessilCache." + Path.GetFileName(assemblyPath));
			long num = File.GetLastWriteTimeUtc(assemblyPath).ToFileTimeUtc();
			bool flag = File.Exists(text) && File.GetLastWriteTimeUtc(text).ToFileTimeUtc() == num;
			AssemblyDefinition val = LoadAssembly(flag ? text : assemblyPath, cessilMerger);
			if (val == null)
			{
				return false;
			}
			if (flag)
			{
				CessilMerger.LogDebugSafe("Falling back to cached merges for '" + ((AssemblyNameReference)val.Name).Name + "'. Write Time hasn't changed.");
			}
			else
			{
				CessilMerger.LogDebugSafe("Loading and caching merges for '" + ((AssemblyNameReference)val.Name).Name + "'. " + (File.Exists(text) ? "Write Time has changed." : "Cache doesn't exist."));
			}
			if (!CessilMerge.TryCreateMerges(val, out merges))
			{
				CessilMerger.LogDebugSafe("Plugin '" + ((AssemblyNameReference)val.Name).Name + "' doesn't contain any merges.");
			}
			if (!flag)
			{
				CacheMerges(text, val, num, merges);
			}
			return merges.Length != 0;
		}

		internal static AssemblyDefinition? LoadAssembly(string assemblyPath, CessilMerger cessilMerger)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			AssemblyDefinition val = null;
			try
			{
				val = AssemblyDefinition.ReadAssembly(assemblyPath, new ReaderParameters
				{
					ReadWrite = true,
					AssemblyResolver = cessilMerger.TypeResolver
				});
			}
			catch
			{
			}
			if (val != null)
			{
				cessilMerger.AssembliesToDispose.Add(val);
			}
			return val;
		}

		private static void CacheMerges(string cachePath, AssemblyDefinition assemblyDefinition, long writeTime, CessilMerge[] merges)
		{
			if (File.Exists(cachePath))
			{
				File.Delete(cachePath);
			}
			AssemblyDefinition val = AssemblyDefinition.CreateAssembly(assemblyDefinition.Name, ((ModuleReference)assemblyDefinition.MainModule).Name, (ModuleKind)0);
			foreach (CessilMerge cessilMerge in merges)
			{
				val.CustomAttributes.Add(cessilMerge.ConvertToAttribute(val));
			}
			val.Write(cachePath);
			if (File.Exists(cachePath))
			{
				File.SetLastWriteTimeUtc(cachePath, DateTime.FromFileTimeUtc(writeTime));
			}
		}
	}
	internal static class CessilHelper
	{
		internal static bool TryCreateField(TypeDefinition typeDef, string name, TypeReference importedFieldType, out FieldDefinition? fieldDefinition, FieldAttributes customAttributes = 1)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_0048: Expected O, but got Unknown
			string name2 = name;
			fieldDefinition = null;
			if (((IEnumerable<FieldDefinition>)typeDef.Fields).Any((FieldDefinition field) => ((MemberReference)field).Name == name2))
			{
				return false;
			}
			Collection<FieldDefinition> fields = typeDef.Fields;
			FieldDefinition val = new FieldDefinition(name2, customAttributes, importedFieldType);
			FieldDefinition val2 = val;
			fieldDefinition = val;
			fields.Add(val2);
			return true;
		}

		internal static bool TryCreateProperty(TypeDefinition typeDef, string name, TypeReference importedPropType, out FieldDefinition? backingField, out PropertyDefinition? propertyDefinition, string fieldNameTemplate = "<{0}>k__BackingField", string methodNameTemplate = "{0}_{1}")
		{
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Expected O, but got Unknown
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Expected O, but got Unknown
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Expected O, but got Unknown
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Expected O, but got Unknown
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Expected O, but got Unknown
			//IL_0259: Expected O, but got Unknown
			string name2 = name;
			propertyDefinition = null;
			backingField = null;
			if (((IEnumerable<PropertyDefinition>)typeDef.Properties).Any((PropertyDefinition prop) => ((MemberReference)prop).Name == name2))
			{
				return false;
			}
			if (!TryCreateField(typeDef, string.Format(fieldNameTemplate, name2), importedPropType, out backingField, (FieldAttributes)1))
			{
				return false;
			}
			TypeReference val = default(TypeReference);
			if (!((MemberReference)typeDef).Module.TryGetTypeReference(typeof(CompilerGeneratedAttribute).FullName, ref val))
			{
				val = ((MemberReference)typeDef).Module.ImportReference(typeof(CompilerGeneratedAttribute));
			}
			MethodReference val2 = ((MemberReference)typeDef).Module.ImportReference((MethodReference)(object)((IEnumerable<MethodDefinition>)val.Resolve().Methods).First((MethodDefinition method) => ((MemberReference)method).Name == ".ctor"));
			backingField.CustomAttributes.Add(new CustomAttribute(val2));
			MethodDefinition val3 = new MethodDefinition(string.Format(methodNameTemplate, "get", name2), (MethodAttributes)2182, importedPropType);
			typeDef.Methods.Add(val3);
			val3.Body = new MethodBody(val3);
			val3.CustomAttributes.Add(new CustomAttribute(val2));
			ILProcessor iLProcessor = val3.Body.GetILProcessor();
			iLProcessor.Emit(OpCodes.Ldarg_0);
			iLProcessor.Emit(OpCodes.Ldfld, (FieldReference)(object)backingField);
			iLProcessor.Emit(OpCodes.Ret);
			MethodDefinition val4 = new MethodDefinition(string.Format(methodNameTemplate, "set", name2), (MethodAttributes)2182, ((MemberReference)typeDef).Module.Assembly.MainModule.TypeSystem.Void);
			typeDef.Methods.Add(val4);
			val4.Body = new MethodBody(val4);
			val4.CustomAttributes.Add(new CustomAttribute(val2));
			((MethodReference)val4).Parameters.Add(new ParameterDefinition("value", (ParameterAttributes)0, importedPropType));
			iLProcessor = val4.Body.GetILProcessor();
			iLProcessor.Emit(OpCodes.Ldarg_0);
			iLProcessor.Emit(OpCodes.Ldarg_1);
			iLProcessor.Emit(OpCodes.Stfld, (FieldReference)(object)backingField);
			iLProcessor.Emit(OpCodes.Ret);
			Collection<PropertyDefinition> properties = typeDef.Properties;
			PropertyDefinition val5 = new PropertyDefinition(name2, (PropertyAttributes)0, importedPropType)
			{
				GetMethod = val3,
				SetMethod = val4
			};
			PropertyDefinition val6 = val5;
			propertyDefinition = val5;
			properties.Add(val6);
			return true;
		}

		internal static bool TryCreateMethod(TypeDefinition typeDef, string name, TypeReference importedReturnType, TypeReference[] importedParamReferences, CustomAttributeArgument[] constants, out MethodDefinition? methodDefinition)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Expected O, but got Unknown
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			string name2 = name;
			TypeReference[] importedParamReferences2 = importedParamReferences;
			methodDefinition = null;
			if (((IEnumerable<MethodDefinition>)typeDef.Methods).Any((MethodDefinition method) => ((MemberReference)method).Name == name2 && ParameterTypesMatch(((IEnumerable<ParameterDefinition>)((MethodReference)method).Parameters).Select((ParameterDefinition param) => ((ParameterReference)param).ParameterType).ToArray(), importedParamReferences2)))
			{
				return false;
			}
			MethodDefinition val = new MethodDefinition(name2, (MethodAttributes)134, importedReturnType);
			val.Body.InitLocals = true;
			methodDefinition = val;
			methodDefinition.Body.GetILProcessor().Emit(OpCodes.Ret);
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
			TypeReference[] array = importedParamReferences2;
			foreach (TypeReference val2 in array)
			{
				string key = (val2.IsGenericInstance ? ((MemberReference)val2).Name.Substring(0, ((MemberReference)val2).Name.IndexOf('`')) : ((MemberReference)val2).Name);
				if (!dictionary2.ContainsKey(key))
				{
					dictionary2.Add(key, 0);
				}
				if (!dictionary.ContainsKey(key))
				{
					dictionary.Add(key, 0);
				}
				dictionary[key]++;
			}
			for (int j = 0; j < importedParamReferences2.Length; j++)
			{
				TypeReference val3 = importedParamReferences2[j];
				string text = (val3.IsGenericInstance ? ((MemberReference)val3).Name.Substring(0, ((MemberReference)val3).Name.IndexOf('`')) : ((MemberReference)val3).Name);
				int num = dictionary[text];
				int num2 = dictionary2[text]++;
				string text2 = "p" + text + ((num > 1) ? ("_" + num2) : "");
				int num3 = importedParamReferences2.Length - constants.Length;
				int num4 = j - num3;
				bool flag = constants.Length != 0 && j >= num3 && ((MemberReference)((CustomAttributeArgument)(ref constants[num4])).Type).FullName == ((MemberReference)val3).FullName;
				ParameterDefinition val4 = new ParameterDefinition(text2, (ParameterAttributes)(flag ? 16 : 0), val3);
				if (num4 >= 0 && constants.Length > num4 && ((MemberReference)((CustomAttributeArgument)(ref constants[num4])).Type).FullName != ((MemberReference)val3).FullName)
				{
					CessilMerger.LogWarnSafe($"Ignoring parameter constant @ {j + 1}, and all preceding parameters, for " + "'" + ((MemberReference)typeDef).FullName + "::" + ((MemberReference)methodDefinition).Name + "' because '" + ((MemberReference)((CustomAttributeArgument)(ref constants[num4])).Type).FullName + "' is not the correct type! It should be '" + ((MemberReference)val3).FullName + "'.");
				}
				if (flag)
				{
					val4.Constant = ((CustomAttributeArgument)(ref constants[num4])).Value;
				}
				else
				{
					Enumerator<ParameterDefinition> enumerator = ((MethodReference)methodDefinition).Parameters.GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							ParameterDefinition current = enumerator.Current;
							current.Constant = null;
							current.Attributes = (ParameterAttributes)0;
						}
					}
					finally
					{
						((IDisposable)enumerator).Dispose();
					}
				}
				((MethodReference)methodDefinition).Parameters.Add(val4);
			}
			typeDef.Methods.Add(methodDefinition);
			return true;
		}

		private static bool ParameterTypesMatch(TypeReference[] parametersFrom, TypeReference[] parametersTo)
		{
			return parametersFrom.Select((TypeReference type) => ((MemberReference)type).FullName).SequenceEqual(parametersTo.Select((TypeReference type) => ((MemberReference)type).FullName));
		}
	}
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	public abstract class RequiresAttribute : Attribute
	{
	}
}
namespace CessilCellsCeaChells.CeaChore
{
	public class RequiresFieldAttribute : RequiresAttribute
	{
		public RequiresFieldAttribute(Type targetType, string fieldName, Type fieldType, bool isPublic = false)
		{
		}
	}
	public class RequiresPropertyAttribute : RequiresAttribute
	{
		public RequiresPropertyAttribute(Type targetType, string propertyName, Type propertyType, bool singletonCreateOnAccess = false)
		{
		}
	}
	public class RequiresMethodAttribute : RequiresAttribute
	{
		public RequiresMethodAttribute(Type targetType, string methodName, Type returnType, params Type[] arguments)
		{
		}
	}
	public class RequiresMethodDefaultsAttribute : RequiresAttribute
	{
		public RequiresMethodDefaultsAttribute(Type targetType, string methodName, Type returnType, Type[] argumentTypes, object[] argumentDefaults)
		{
		}
	}
	public class RequiresEnumInsertionAttribute : RequiresAttribute
	{
		public RequiresEnumInsertionAttribute(Type targetType, string entryName)
		{
		}
	}
}

BepInEx/patchers/CessilCellsCeaChells/CessilCellsCeaChells.Preloader.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Mono.Cecil;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("CessilCellsCeaChells.Preloader")]
[assembly: AssemblyConfiguration("Mono10")]
[assembly: AssemblyFileVersion("0.3.6.0")]
[assembly: AssemblyInformationalVersion("0.3.6+7d89ac2f0f27f18bdede1a7a48d74cf17c6333f1")]
[assembly: AssemblyProduct("CessilCellsCeaChells.Preloader")]
[assembly: AssemblyTitle("CessilCellsCeaChells.Preloader")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.6.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CessilCellsCeaChells.Preloader
{
	internal static class CessilCellsCeaChellsDownByTheCeaChore
	{
		public static IEnumerable<string> TargetDLLs => Merger.TargetDLLFileNames;

		private static CessilMerger Merger { get; } = new CessilMerger();


		private static ManualLogSource Logger { get; } = Logger.CreateLogSource("CessilCellsCeaChellsDownByTheCeaChore");


		public static void Initialize()
		{
			CessilMerger.LogDebug += Logger.LogDebug;
			CessilMerger.LogWarn += Logger.LogWarning;
			Merger.CachePath = Path.Combine(Paths.CachePath, "CessilCellsCeaChellsDownByTheCeaChore");
			Merger.TypeResolver = (IAssemblyResolver)(object)TypeLoader.Resolver;
			LoadPlugins();
			Logger.LogInfo((object)"Initialized!");
		}

		private static void LoadPlugins()
		{
			string text = Paths.PluginPath ?? "";
			if (!Directory.Exists(text))
			{
				throw new ArgumentException("Invalid plugin directory!", text);
			}
			int num = default(int);
			foreach (string item in Directory.GetFiles(text, "*.dll", SearchOption.AllDirectories).OrderBy(delegate(string path)
			{
				using SHA256 sHA = SHA256.Create();
				string text2 = path.Replace(Paths.PluginPath, "");
				int num2 = sHA.ComputeHash(Encoding.UTF8.GetBytes(text2)).Aggregate(0, (int i, byte b) => i + b);
				Logger.LogDebug((object)$"Hashed '{text2}' to '{num2}'");
				return num2;
			}))
			{
				if (Merger.LoadMergesFrom(item, ref num))
				{
					Logger.LogInfo((object)string.Format("Successfully loaded {0} merge{1} from '{2}'", num, (num == 1) ? "" : "s", Path.GetFileName(item)));
				}
			}
		}

		public static void Patch(AssemblyDefinition assembly)
		{
			Logger.LogInfo((object)("Patching '" + ((AssemblyNameReference)assembly.Name).Name + "'.."));
			Merger.MergeInto(assembly);
			if (!Directory.Exists(Paths.CachePath))
			{
				Directory.CreateDirectory(Paths.CachePath);
			}
			string text = Path.Combine(Paths.CachePath, "Cessil." + ((AssemblyNameReference)assembly.Name).Name + ".dll");
			assembly.Write(text);
			Logger.LogInfo((object)("Patching '" + ((AssemblyNameReference)assembly.Name).Name + "' done! Cached to '" + text + "'"));
		}

		public static void Finish()
		{
			Merger.Dispose();
			Logger.LogInfo((object)"Finished!");
		}
	}
}