Decompiled source of BagetUnlockAll v1.0.0

BagetUnlockAll.dll

Decompiled 5 days ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace BagetUnlockAll;

[BepInPlugin("baget.unlockall", "BagetUnlockAll", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private static readonly string[][] Targets = new string[7][]
	{
		new string[2] { "RoR2.Run", "IsUnlockableUnlocked" },
		new string[2] { "RoR2.Run", "DoesEveryoneHaveThisUnlockableUnlocked" },
		new string[2] { "RoR2.PreGameController", "AnyUserHasUnlockable" },
		new string[2] { "RoR2.UserProfile", "HasUnlockable" },
		new string[2] { "RoR2.UserProfile", "HasSurvivorUnlocked" },
		new string[2] { "RoR2.UserProfile", "HasDiscoveredPickup" },
		new string[2] { "RoR2.Stats.StatSheet", "HasUnlockable" }
	};

	private void Awake()
	{
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Expected O, but got Unknown
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Expected O, but got Unknown
		Assembly assembly = null;
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly2 in assemblies)
		{
			if (assembly2.GetName().Name == "RoR2")
			{
				assembly = assembly2;
				break;
			}
		}
		if (assembly == null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"RoR2.dll не найден, мод ничего не сделал");
			return;
		}
		Type[] types;
		try
		{
			types = assembly.GetTypes();
		}
		catch (ReflectionTypeLoadException ex)
		{
			types = ex.Types;
		}
		Harmony val = new Harmony("baget.unlockall");
		HarmonyMethod val2 = new HarmonyMethod(typeof(Plugin).GetMethod("ReturnTrue", BindingFlags.Static | BindingFlags.NonPublic));
		int num = 0;
		int num2 = 0;
		string[][] targets = Targets;
		foreach (string[] array in targets)
		{
			Type type = assembly.GetType(array[0]);
			if (type == null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Нет типа " + array[0]));
				num2++;
				continue;
			}
			int num3 = 0;
			Type[] array2 = types;
			foreach (Type type2 in array2)
			{
				if (type2 == null || !type.IsAssignableFrom(type2))
				{
					continue;
				}
				MethodInfo[] methods = type2.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (!(methodInfo.Name != array[1]) && !(methodInfo.ReturnType != typeof(bool)) && !methodInfo.IsAbstract && !methodInfo.IsGenericMethodDefinition)
					{
						try
						{
							val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
							num3++;
						}
						catch (Exception ex2)
						{
							num2++;
							((BaseUnityPlugin)this).Logger.LogError((object)("Не удалось пропатчить " + type2.FullName + "." + methodInfo.Name + ": " + ex2.Message));
						}
					}
				}
			}
			if (num3 == 0)
			{
				num2++;
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Не найден метод " + array[0] + "." + array[1]));
			}
			num += num3;
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)("BagetUnlockAll: пропатчено методов " + num + ", проблем " + num2));
	}

	private static void ReturnTrue(ref bool __result)
	{
		__result = true;
	}
}