Decompiled source of TocoronCompat1030 v1.0.0

patchers/TocoronCompat1030.dll

Decompiled 10 hours ago
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx.Logging;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
public static class TocoronCompat1030
{
	public static IEnumerable<string> TargetDLLs => new string[1] { "SoftReferenceableAssets.dll" };

	public static void Patch(AssemblyDefinition assembly)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Expected O, but got Unknown
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Expected O, but got Unknown
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Expected O, but got Unknown
		//IL_018f: 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_01a9: Unknown result type (might be due to invalid IL or missing references)
		ManualLogSource val = Logger.CreateLogSource("TocoronCompat1030");
		TypeDefinition val2 = null;
		Enumerator<TypeDefinition> enumerator = assembly.MainModule.Types.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				TypeDefinition current = enumerator.Current;
				if (((MemberReference)current).FullName == "SoftReferenceableAssets.SoftReference`1")
				{
					val2 = current;
				}
			}
		}
		finally
		{
			((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
		}
		if (val2 == null)
		{
			val.LogWarning((object)"No se encontro SoftReference`1");
			return;
		}
		MethodDefinition val3 = null;
		Enumerator<MethodDefinition> enumerator2 = val2.Methods.GetEnumerator();
		try
		{
			while (enumerator2.MoveNext())
			{
				MethodDefinition current2 = enumerator2.Current;
				if (((MemberReference)current2).Name == "get_Name" && ((MethodReference)current2).Parameters.Count == 0)
				{
					val.LogInfo((object)"get_Name ya existe, no hace falta");
					return;
				}
				if (((MemberReference)current2).Name == "get_name" && ((MethodReference)current2).Parameters.Count == 0)
				{
					val3 = current2;
				}
			}
		}
		finally
		{
			((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose();
		}
		if (val3 == null)
		{
			val.LogWarning((object)"No se encontro get_name");
			return;
		}
		GenericInstanceType val4 = new GenericInstanceType((TypeReference)(object)val2);
		Enumerator<GenericParameter> enumerator3 = ((TypeReference)val2).GenericParameters.GetEnumerator();
		try
		{
			while (enumerator3.MoveNext())
			{
				GenericParameter current3 = enumerator3.Current;
				val4.GenericArguments.Add((TypeReference)(object)current3);
			}
		}
		finally
		{
			((IDisposable)enumerator3/*cast due to .constrained prefix*/).Dispose();
		}
		MethodReference val5 = new MethodReference("get_name", ((MethodReference)val3).ReturnType, (TypeReference)(object)val4);
		val5.HasThis = true;
		MethodReference val6 = val5;
		MethodDefinition val7 = new MethodDefinition("get_Name", (MethodAttributes)2182, ((MethodReference)val3).ReturnType);
		((MethodReference)val7).HasThis = true;
		ILProcessor iLProcessor = val7.Body.GetILProcessor();
		iLProcessor.Emit(OpCodes.Ldarg_0);
		iLProcessor.Emit(OpCodes.Call, val6);
		iLProcessor.Emit(OpCodes.Ret);
		val2.Methods.Add(val7);
		val.LogInfo((object)"Anadido SoftReference<T>.get_Name -> get_name (compatibilidad Valheim 1.0.30)");
	}
}