Decompiled source of LimitlessPerks v1.1.1

plugins/LimitlessPerks/LimitlessPerks.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using LimitlessPerks.Core;
using Microsoft.CodeAnalysis;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("LimitlessPerks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1")]
[assembly: AssemblyProduct("LimitlessPerks")]
[assembly: AssemblyTitle("LimitlessPerks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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 LimitlessPerks
{
	public static class ConfigManager
	{
		public static bool EnabledLimitlessPerk;
	}
	[BepInPlugin("com.prideunique.limitlessperks", "LimitlessPerks", "1.1.1")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "com.prideunique.limitlessperks";

		public const string PLUGIN_NAME = "LimitlessPerks";

		public const string PLUGIN_VERSION = "1.1.1";

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)4;
			Harmony val = new Harmony("com.prideunique.limitlessperks");
			Type[] types = typeof(Plugin).Assembly.GetTypes();
			foreach (Type type in types)
			{
				if (type.GetCustomAttribute<PatchOnEntryAttribute>() != null)
				{
					val.PatchAll(type);
				}
			}
		}
	}
}
namespace LimitlessPerks.Patches
{
	[PatchOnEntry]
	[HarmonyPatch]
	public class ENT_PlayerPatch
	{
		[HarmonyPatch(typeof(ENT_Player), "CreateCommands")]
		[HarmonyPostfix]
		private static void ENT_PlayerCreateCommands(ENT_Player __instance)
		{
			ENT_Player __instance2 = __instance;
			CommandConsole.AddCommand("addperks", (Action<string[]>)delegate(string[] args)
			{
				//IL_011d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0122: Unknown result type (might be due to invalid IL or missing references)
				//IL_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0131: Unknown result type (might be due to invalid IL or missing references)
				//IL_0136: Unknown result type (might be due to invalid IL or missing references)
				//IL_013f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0144: Unknown result type (might be due to invalid IL or missing references)
				//IL_0149: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)__instance2 == (Object)null) && args != null && args.Length > 1 && int.TryParse(args[1], out var result2) && result2 > 0)
				{
					Perk perkAsset = CL_AssetManager.GetPerkAsset(args[0], "");
					if (!((Object)(object)perkAsset == (Object)null))
					{
						Perk val4 = Object.Instantiate<Perk>(perkAsset);
						bool flag4 = false;
						bool flag5 = false;
						PerkModule_ItemAdder val5 = null;
						for (int num3 = val4.modules.Count - 1; num3 >= 0; num3--)
						{
							PerkModule val6 = val4.modules[num3];
							if (val6 != null)
							{
								Type type2 = ((object)val6).GetType();
								if (type2 == typeof(PerkModule_ItemAdder))
								{
									flag4 = true;
									val5 = (PerkModule_ItemAdder)(object)((val6 is PerkModule_ItemAdder) ? val6 : null);
								}
								else if (type2 == typeof(PerkModule_InfectionDisplay))
								{
									flag5 = true;
								}
							}
						}
						if (flag4 && result2 > 1)
						{
							for (int j = 1; j < result2; j++)
							{
								List<Item> list2 = new List<Item>();
								foreach (Item_Object item in val5.itemsToAdd)
								{
									if (!((Object)(object)item == (Object)null))
									{
										Item clone2 = item.itemData.GetClone();
										clone2.bagPosition = new Vector3(0f, 0f, 1f) + Random.insideUnitSphere * 0.01f;
										clone2.bagRotation = Quaternion.LookRotation(clone2.upDirection);
										list2.Add(clone2);
									}
								}
								Inventory.instance.LoadItemsIntoBag(list2);
							}
						}
						if (flag5)
						{
							try
							{
								__instance2.AddPerk(val4, result2);
								return;
							}
							catch
							{
								return;
							}
						}
						__instance2.AddPerk(val4, result2);
					}
				}
			}, true);
			CommandConsole.AddCommand("addallperks", (Action<string[]>)delegate(string[] args)
			{
				//IL_0140: Unknown result type (might be due to invalid IL or missing references)
				//IL_0145: Unknown result type (might be due to invalid IL or missing references)
				//IL_014f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0154: Unknown result type (might be due to invalid IL or missing references)
				//IL_0159: Unknown result type (might be due to invalid IL or missing references)
				//IL_0162: Unknown result type (might be due to invalid IL or missing references)
				//IL_0167: Unknown result type (might be due to invalid IL or missing references)
				//IL_016c: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)__instance2 == (Object)null))
				{
					if (args == null || args.Length < 1)
					{
						foreach (WKDatabaseHolder database in CL_AssetManager.databases)
						{
							foreach (Perk perkAsset2 in database.database.perkAssets)
							{
								if (!((Object)(object)perkAsset2 == (Object)null))
								{
									bool flag = false;
									for (int num = perkAsset2.modules.Count - 1; num >= 0; num--)
									{
										PerkModule val = perkAsset2.modules[num];
										if (val != null && ((object)val).GetType() == typeof(PerkModule_InfectionDisplay))
										{
											flag = true;
											break;
										}
									}
									if (flag)
									{
										try
										{
											__instance2.AddPerk(perkAsset2, 1);
										}
										catch
										{
										}
									}
									else
									{
										__instance2.AddPerk(perkAsset2, 1);
									}
								}
							}
						}
						return;
					}
					if (int.TryParse(args[0], out var result) && result > 0)
					{
						foreach (WKDatabaseHolder database2 in CL_AssetManager.databases)
						{
							foreach (Perk perkAsset3 in database2.database.perkAssets)
							{
								if (!((Object)(object)perkAsset3 == (Object)null))
								{
									bool flag2 = false;
									bool flag3 = false;
									PerkModule_ItemAdder val2 = null;
									for (int num2 = perkAsset3.modules.Count - 1; num2 >= 0; num2--)
									{
										PerkModule val3 = perkAsset3.modules[num2];
										if (val3 != null)
										{
											Type type = ((object)val3).GetType();
											if (type == typeof(PerkModule_ItemAdder))
											{
												flag2 = true;
												val2 = (PerkModule_ItemAdder)(object)((val3 is PerkModule_ItemAdder) ? val3 : null);
											}
											else if (type == typeof(PerkModule_InfectionDisplay))
											{
												flag3 = true;
											}
										}
									}
									if (flag2)
									{
										for (int i = 1; i < result; i++)
										{
											List<Item> list = new List<Item>();
											foreach (Item_Object item2 in val2.itemsToAdd)
											{
												if (!((Object)(object)item2 == (Object)null))
												{
													Item clone = item2.itemData.GetClone();
													clone.bagPosition = new Vector3(0f, 0f, 1f) + Random.insideUnitSphere * 0.01f;
													clone.bagRotation = Quaternion.LookRotation(clone.upDirection);
													list.Add(clone);
												}
											}
											Inventory.instance.LoadItemsIntoBag(list);
										}
									}
									if (flag3)
									{
										try
										{
											__instance2.AddPerk(perkAsset3, result);
										}
										catch
										{
										}
									}
									else
									{
										__instance2.AddPerk(perkAsset3, result);
									}
								}
							}
						}
					}
				}
			}, true);
			CommandConsole.AddCommand("enablelimitlessperks", (Action<string[]>)delegate
			{
				ConfigManager.EnabledLimitlessPerk = true;
			}, true);
			CommandConsole.AddCommand("disablelimitlessperks", (Action<string[]>)delegate
			{
				ConfigManager.EnabledLimitlessPerk = false;
			}, true);
		}

		public static float MaxGravityReplacement(float a, float b)
		{
			if (!ConfigManager.EnabledLimitlessPerk || !CommandConsole.cheatsEnabled)
			{
				return Mathf.Max(a, b);
			}
			return a;
		}

		[HarmonyPatch(typeof(ENT_Player), "Movement")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> ENT_PlayerMovement(IEnumerable<CodeInstruction> instructions)
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			MethodInfo methodInfo = AccessTools.Method(typeof(Mathf), "Max", new Type[2]
			{
				typeof(float),
				typeof(float)
			}, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(ENT_PlayerPatch), "MaxGravityReplacement", new Type[2]
			{
				typeof(float),
				typeof(float)
			}, (Type[])null);
			if (methodInfo == null || methodInfo2 == null)
			{
				return list.AsEnumerable();
			}
			return new CodeMatcher((IEnumerable<CodeInstruction>)list, (ILGenerator)null).Start().MatchForward(true, (CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)0.2f, (string)null),
				new CodeMatch((OpCode?)OpCodes.Call, (object)methodInfo, (string)null)
			}).ThrowIfInvalid("Failed to match first `Mathf.Max` in ENT_Player.Movement")
				.SetOperandAndAdvance((object)methodInfo2)
				.InstructionEnumeration();
		}

		public static float DamageResistClampReplacement(float value, float min, float max)
		{
			if (!ConfigManager.EnabledLimitlessPerk || !CommandConsole.cheatsEnabled)
			{
				return Mathf.Clamp(value, min, max);
			}
			if (value < min)
			{
				return min;
			}
			return value;
		}

		[HarmonyPatch(typeof(ENT_Player), "Damage")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> ENT_PlayerDamage(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Expected O, but got Unknown
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Expected O, but got Unknown
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			MethodInfo methodInfo = AccessTools.Method(typeof(Mathf), "Clamp", new Type[3]
			{
				typeof(float),
				typeof(float),
				typeof(float)
			}, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(ENT_PlayerPatch), "DamageResistClampReplacement", new Type[3]
			{
				typeof(float),
				typeof(float),
				typeof(float)
			}, (Type[])null);
			if (methodInfo == null || methodInfo2 == null)
			{
				return list.AsEnumerable();
			}
			return new CodeMatcher((IEnumerable<CodeInstruction>)list, (ILGenerator)null).Start().MatchForward(true, (CodeMatch[])(object)new CodeMatch[5]
			{
				new CodeMatch((OpCode?)OpCodes.Ldstr, (object)"damageResist", (string)null),
				new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Call, (object)methodInfo, (string)null)
			}).ThrowIfInvalid("Failed to match first `Mathf.Clamp` in ENT_Player.Damage")
				.SetOperandAndAdvance((object)methodInfo2)
				.InstructionEnumeration();
		}
	}
	[PatchOnEntry]
	[HarmonyPatch]
	public static class PerkPatch
	{
		public class PerkOriginalData
		{
			public int stackMax;

			public bool canStack;

			public List<string> buffIds;

			public List<string> baseBuffIds;
		}

		private static Dictionary<Perk, PerkOriginalData> _originalPerkData = new Dictionary<Perk, PerkOriginalData>();

		[HarmonyPatch(typeof(Perk), "Update")]
		[HarmonyPrefix]
		private static void PerkUpdate(ref Perk __instance)
		{
			PerkOriginalData value;
			bool flag = _originalPerkData.TryGetValue(__instance, out value);
			if (!flag)
			{
				PerkOriginalData perkOriginalData = new PerkOriginalData();
				perkOriginalData.stackMax = __instance.stackMax;
				perkOriginalData.canStack = __instance.canStack;
				List<string> list = new List<string>();
				for (int i = 0; i < __instance.buff.buffs.Count; i++)
				{
					Buff val = __instance.buff.buffs[i];
					if (val != null)
					{
						list.Add(val.id);
					}
				}
				perkOriginalData.buffIds = list;
				List<string> list2 = new List<string>();
				for (int j = 0; j < __instance.baseBuff.buffs.Count; j++)
				{
					Buff val2 = __instance.buff.buffs[j];
					if (val2 != null)
					{
						list2.Add(val2.id);
					}
				}
				perkOriginalData.baseBuffIds = list2;
				_originalPerkData.Add(__instance, perkOriginalData);
			}
			if (!ConfigManager.EnabledLimitlessPerk || !CommandConsole.cheatsEnabled)
			{
				if (!flag)
				{
					return;
				}
				__instance.stackMax = value.stackMax;
				__instance.canStack = value.canStack;
				if (value.baseBuffIds == null || value.baseBuffIds.Count <= 0)
				{
					return;
				}
				for (int num = __instance.buff.buffs.Count - 1; num >= 0; num--)
				{
					Buff val3 = __instance.buff.buffs[num];
					if (val3 != null)
					{
						bool num2 = value.baseBuffIds.Contains(val3.id);
						bool flag2 = value.buffIds != null && value.buffIds.Contains(val3.id);
						if (num2 && !flag2)
						{
							__instance.baseBuff.buffs.Add(val3);
							__instance.buff.buffs.RemoveAt(num);
						}
					}
				}
				return;
			}
			for (int num3 = __instance.baseBuff.buffs.Count - 1; num3 >= 0; num3--)
			{
				Buff val4 = __instance.baseBuff.buffs[num3];
				if (val4 != null)
				{
					__instance.buff.buffs.Add(val4);
					__instance.baseBuff.buffs.Remove(val4);
				}
			}
			__instance.stackMax = int.MaxValue;
			__instance.canStack = true;
		}
	}
}
namespace LimitlessPerks.Core
{
	[PublicAPI]
	[AttributeUsage(AttributeTargets.Class, Inherited = false)]
	internal sealed class PatchOnEntryAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}