Decompiled source of LogBookPatcher v1.0.1

LogBookPatcher.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using IL.RoR2.UI.LogBook;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2.UI.LogBook;
using RoR2;
using RoR2.ExpansionManagement;
using RoR2.UI.LogBook;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LogBookPatcher")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+06078b5003906533ec6ef5bd66bb155694a47862")]
[assembly: AssemblyProduct("LogBookPatcher")]
[assembly: AssemblyTitle("LogBookPatcher")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LogBookPatcher
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	public static class Extension
	{
		public static bool MatchAny(this Instruction instruction, out Instruction param)
		{
			param = instruction;
			return true;
		}
	}
	[BepInPlugin("Dnarok.LogBookPatcher", "LogBookPatcher", "1.0.1")]
	public class LogBookPatcher : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<Instruction, bool> <>9__4_2;

			public static Func<Instruction, bool> <>9__4_3;

			public static Func<Instruction, bool> <>9__4_6;

			public static Func<LogBookPage, bool> <>9__4_7;

			public static Manipulator <>9__4_0;

			public static hook_BuildPickupEntries <>9__4_1;

			internal void <Awake>b__4_0(ILContext il)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Expected O, but got Unknown
				//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0106: Unknown result type (might be due to invalid IL or missing references)
				<>c__DisplayClass4_0 CS$<>8__locals0 = new <>c__DisplayClass4_0();
				ILCursor val = new ILCursor(il);
				CS$<>8__locals0.after_if = null;
				CS$<>8__locals0.inside_if = null;
				if (!val.TryGotoNext(new Func<Instruction, bool>[2]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
					(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(LogBookPage), "modelPanel")
				}) || !val.TryGotoNext(new Func<Instruction, bool>[2]
				{
					(Instruction x) => ILPatternMatchingExt.MatchBeq(x, ref CS$<>8__locals0.after_if),
					(Instruction x) => x.MatchAny(out CS$<>8__locals0.inside_if)
				}))
				{
					Log.Error("Failed to hook LogBookPage.SetEntry, cannot apply fix.");
					return;
				}
				val.GotoPrev(new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0)
				});
				val.Emit(OpCodes.Ldarg_0);
				val.EmitDelegate<Func<LogBookPage, bool>>((Func<LogBookPage, bool>)((LogBookPage self) => self.modelPanel.modelPrefabAddress == null));
				val.Emit(OpCodes.Brtrue, CS$<>8__locals0.inside_if);
			}

			internal bool <Awake>b__4_2(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdarg(x, 0);
			}

			internal bool <Awake>b__4_3(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdfld(x, typeof(LogBookPage), "modelPanel");
			}

			internal bool <Awake>b__4_6(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdarg(x, 0);
			}

			internal bool <Awake>b__4_7(LogBookPage self)
			{
				return self.modelPanel.modelPrefabAddress == null;
			}

			internal Entry[] <Awake>b__4_1(orig_BuildPickupEntries orig, Dictionary<ExpansionDef, bool> availability)
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Invalid comparison between Unknown and I4
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				Entry[] array = orig.Invoke(availability);
				Entry[] array2 = array;
				foreach (Entry val in array2)
				{
					if (!(val.extraData is PickupIndex))
					{
						continue;
					}
					PickupIndex val2 = (PickupIndex)val.extraData;
					PickupDef pickupDef = ((PickupIndex)(ref val2)).pickupDef;
					if ((int)pickupDef.equipmentIndex != -1)
					{
						EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(pickupDef.equipmentIndex);
						if (Object.op_Implicit((Object)(object)equipmentDef))
						{
							val.modelPrefabAddress = equipmentDef.pickupModelReference;
						}
					}
				}
				return array;
			}
		}

		[CompilerGenerated]
		private sealed class <>c__DisplayClass4_0
		{
			public ILLabel after_if;

			public Instruction inside_if;

			internal bool <Awake>b__4(Instruction x)
			{
				return ILPatternMatchingExt.MatchBeq(x, ref after_if);
			}

			internal bool <Awake>b__5(Instruction x)
			{
				return x.MatchAny(out inside_if);
			}
		}

		public const string PluginGUID = "Dnarok.LogBookPatcher";

		public const string PluginAuthor = "Dnarok";

		public const string PluginName = "LogBookPatcher";

		public const string PluginVersion = "1.0.1";

		public void Awake()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			object obj = <>c.<>9__4_0;
			if (obj == null)
			{
				Manipulator val = delegate(ILContext il)
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000d: Expected O, but got Unknown
					//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
					//IL_0106: Unknown result type (might be due to invalid IL or missing references)
					ILCursor val5 = new ILCursor(il);
					ILLabel after_if = null;
					Instruction inside_if = null;
					if (!val5.TryGotoNext(new Func<Instruction, bool>[2]
					{
						(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
						(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(LogBookPage), "modelPanel")
					}) || !val5.TryGotoNext(new Func<Instruction, bool>[2]
					{
						(Instruction x) => ILPatternMatchingExt.MatchBeq(x, ref after_if),
						(Instruction x) => x.MatchAny(out inside_if)
					}))
					{
						Log.Error("Failed to hook LogBookPage.SetEntry, cannot apply fix.");
					}
					else
					{
						val5.GotoPrev(new Func<Instruction, bool>[1]
						{
							(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0)
						});
						val5.Emit(OpCodes.Ldarg_0);
						val5.EmitDelegate<Func<LogBookPage, bool>>((Func<LogBookPage, bool>)((LogBookPage self) => self.modelPanel.modelPrefabAddress == null));
						val5.Emit(OpCodes.Brtrue, inside_if);
					}
				};
				<>c.<>9__4_0 = val;
				obj = (object)val;
			}
			LogBookPage.SetEntry += (Manipulator)obj;
			object obj2 = <>c.<>9__4_1;
			if (obj2 == null)
			{
				hook_BuildPickupEntries val2 = delegate(orig_BuildPickupEntries orig, Dictionary<ExpansionDef, bool> availability)
				{
					//IL_0025: Unknown result type (might be due to invalid IL or missing references)
					//IL_002a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0037: Unknown result type (might be due to invalid IL or missing references)
					//IL_003d: Invalid comparison between Unknown and I4
					//IL_0041: Unknown result type (might be due to invalid IL or missing references)
					Entry[] array = orig.Invoke(availability);
					Entry[] array2 = array;
					foreach (Entry val3 in array2)
					{
						if (val3.extraData is PickupIndex)
						{
							PickupIndex val4 = (PickupIndex)val3.extraData;
							PickupDef pickupDef = ((PickupIndex)(ref val4)).pickupDef;
							if ((int)pickupDef.equipmentIndex != -1)
							{
								EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(pickupDef.equipmentIndex);
								if (Object.op_Implicit((Object)(object)equipmentDef))
								{
									val3.modelPrefabAddress = equipmentDef.pickupModelReference;
								}
							}
						}
					}
					return array;
				};
				<>c.<>9__4_1 = val2;
				obj2 = (object)val2;
			}
			LogBookController.BuildPickupEntries += (hook_BuildPickupEntries)obj2;
		}
	}
}