Decompiled source of WrinklerPatcher v0.1.3

patchers/WrinkePatch.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Collections.Generic;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("WrinkePatch")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Dell Inc.")]
[assembly: AssemblyProduct("WrinkePatch")]
[assembly: AssemblyCopyright("Copyright © Dell Inc. 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c93c9c5d-9a72-418c-a5c6-9541e1373860")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace WrinkePatch
{
	public class WrinklePatch
	{
		internal const string ModName = "WrinklePatch";

		internal const string ModVersion = "1.0.0";

		internal const string Author = "arubius";

		private const string ModGUID = "arubius.WrinklePatch";

		public static readonly ManualLogSource WrinklePatchLogger = Logger.CreateLogSource("WrinklePatch");

		public static List<string> targetDllNames = new List<string>
		{
			"Mining.dll", "Ranching.dll", "Lumberjacking.dll", "Building.dll", "PackHorse.dll", "Sailing.dll", "Vitality.dll", "Evasion.dll", "Tenacity.dll", "Farming.dll",
			"SmoothSave.dll", "Exploration.dll", "Foraging.dll", "Cooking.dll", "Blacksmithing.dll", "Backpacks.dll", "GracefulTeleportation.dll", "Afterdeath.dll", "Jewelcrafting.dll", "CreatureLevelControl.dll"
		};

		public static IEnumerable<string> TargetDLLs { get; } = Array.Empty<string>();


		public static void Patch(AssemblyDefinition assembly)
		{
		}

		public static void RemoveAttributeFromAssembly(string assemblyPath, string attributeName)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			using MemoryStream memoryStream = new MemoryStream();
			using (FileStream fileStream = File.OpenRead(assemblyPath))
			{
				fileStream.CopyTo(memoryStream);
			}
			memoryStream.Position = 0L;
			AssemblyDefinition val = AssemblyDefinition.ReadAssembly((Stream)memoryStream);
			Enumerator<TypeDefinition> enumerator = val.MainModule.Types.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					TypeDefinition current = enumerator.Current;
					RemoveAttribute(current.CustomAttributes, attributeName, ((MemberReference)current).Name);
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			using FileStream fileStream2 = File.Open(assemblyPath, FileMode.Create, FileAccess.Write, FileShare.None);
			val.Write((Stream)fileStream2);
		}

		private static void RemoveAttribute(Collection<CustomAttribute> attributes, string attributeName, string baseClassName)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			CustomAttribute val = null;
			Enumerator<CustomAttribute> enumerator = attributes.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					CustomAttribute current = enumerator.Current;
					if (!(((MemberReference)current.AttributeType).Name == attributeName))
					{
						continue;
					}
					Enumerator<CustomAttributeArgument> enumerator2 = current.ConstructorArguments.GetEnumerator();
					try
					{
						while (enumerator2.MoveNext())
						{
							CustomAttributeArgument current2 = enumerator2.Current;
							if (((MemberReference)((CustomAttributeArgument)(ref current2)).Type).FullName == typeof(string).FullName && (string)((CustomAttributeArgument)(ref current2)).Value == "org.bepinex.plugins.valheim_plus")
							{
								val = current;
								break;
							}
						}
					}
					finally
					{
						((IDisposable)enumerator2).Dispose();
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			if (val != null)
			{
				attributes.Remove(val);
				WrinklePatchLogger.LogInfo((object)("Attribute " + attributeName + " removed from classes derived from " + baseClassName + "."));
			}
		}

		public static void Initialize()
		{
			foreach (string item in Directory.EnumerateFiles(Paths.PluginPath, "*.dll", SearchOption.AllDirectories))
			{
				string fileName = Path.GetFileName(item);
				if (targetDllNames.Contains(fileName))
				{
					WrinklePatchLogger.LogDebug((object)(fileName + " found, attempting to patch."));
					try
					{
						RemoveAttributeFromAssembly(item, "BepInIncompatibility");
					}
					catch (Exception arg)
					{
						WrinklePatchLogger.LogError((object)(fileName + $" found, but the attempt to delete the file failed with the following error: {Environment.NewLine}{arg}"));
					}
				}
			}
		}

		public static void Finish()
		{
		}
	}
}