Decompiled source of LongstandingSolitudeFix v1.0.3

plugins/LongstandingSolitudeFix/LongstandingSolitudeFix.dll

Decompiled a week ago
using System;
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.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LongstandingSolitudeFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b7d737084ac3bc867487363fd6ab7bbbbf326503")]
[assembly: AssemblyProduct("LongstandingSolitudeFix")]
[assembly: AssemblyTitle("LongstandingSolitudeFix")]
[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 LongstandingSolitudeFix
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.Tutorials.ConfigurationTutorial", "ConfigurationTutorial", "1.0.0")]
	public class Configs : BaseUnityPlugin
	{
		private static ConfigFile CustomConfigFile { get; set; }

		public static ConfigEntry<bool> BreakIntoPearl { get; set; }

		internal static void Init()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			CustomConfigFile = new ConfigFile(Paths.ConfigPath + "\\LongstandingSolitudeFix.cfg", true);
			BreakIntoPearl = CustomConfigFile.Bind<bool>("LongstandingSolitudeFix", "BreakIntoPearlAtMaxLevel", true, "Whether or not to break Longstanding Solitude into a pearl at max level");
		}
	}
	public class Hooks
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Action<CharacterBody> <0>__GlobalEventManager_onCharacterLevelUp;

			public static hook_OnInteractionBegin <1>__PurchaseInteraction_OnInteractionBegin;

			public static hook_GiveItem_ItemIndex_int <2>__Inventory_GiveItem_ItemIndex_int;
		}

		internal static void Init()
		{
			//IL_0032: 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: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			GlobalEventManager.onCharacterLevelUp += GlobalEventManager_onCharacterLevelUp;
			object obj = <>O.<1>__PurchaseInteraction_OnInteractionBegin;
			if (obj == null)
			{
				hook_OnInteractionBegin val = PurchaseInteraction_OnInteractionBegin;
				<>O.<1>__PurchaseInteraction_OnInteractionBegin = val;
				obj = (object)val;
			}
			PurchaseInteraction.OnInteractionBegin += (hook_OnInteractionBegin)obj;
			object obj2 = <>O.<2>__Inventory_GiveItem_ItemIndex_int;
			if (obj2 == null)
			{
				hook_GiveItem_ItemIndex_int val2 = Inventory_GiveItem_ItemIndex_int;
				<>O.<2>__Inventory_GiveItem_ItemIndex_int = val2;
				obj2 = (object)val2;
			}
			Inventory.GiveItem_ItemIndex_int += (hook_GiveItem_ItemIndex_int)obj2;
		}

		private static void Inventory_GiveItem_ItemIndex_int(orig_GiveItem_ItemIndex_int orig, Inventory self, ItemIndex itemIndex, int count)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			if (itemIndex != Items.OnLevelUpFreeUnlock.itemIndex)
			{
				orig.Invoke(self, itemIndex, count);
				return;
			}
			if (!Configs.BreakIntoPearl.Value)
			{
				orig.Invoke(self, itemIndex, count);
				return;
			}
			CharacterMaster component = ((Component)self).gameObject.GetComponent<CharacterMaster>();
			if ((Object)(object)component == (Object)null)
			{
				orig.Invoke(self, itemIndex, count);
				return;
			}
			CharacterBody body = component.GetBody();
			if ((Object)(object)body == (Object)null)
			{
				orig.Invoke(self, itemIndex, count);
				return;
			}
			if (body.level < (float)TeamManager.naturalLevelCap)
			{
				orig.Invoke(self, itemIndex, count);
				return;
			}
			orig.Invoke(self, Items.Pearl.itemIndex, count);
			CharacterMasterNotificationQueue.SendTransformNotification(body.master, Items.OnLevelUpFreeUnlock.itemIndex, Items.Pearl.itemIndex, (TransformationType)0);
		}

		private static void PurchaseInteraction_OnInteractionBegin(orig_OnInteractionBegin orig, PurchaseInteraction self, Interactor activator)
		{
			int num = 0;
			CharacterBody component = ((Component)activator).GetComponent<CharacterBody>();
			if ((Object)(object)component != (Object)null)
			{
				num = component.GetBuffCount(Buffs.FreeUnlocks);
			}
			orig.Invoke(self, activator);
			if (num == 0 || (Object)(object)component == (Object)null || self.cost > 0)
			{
				return;
			}
			int buffCount = component.GetBuffCount(Buffs.FreeUnlocks);
			if (num - buffCount > 0)
			{
				for (int i = 0; i < num - buffCount; i++)
				{
					component.AddBuff(Buffs.FreeUnlocks);
				}
			}
		}

		private static void ReplaceLSWithPearl(CharacterBody body, Inventory inventory)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			if (Configs.BreakIntoPearl.Value && !(body.level < (float)TeamManager.naturalLevelCap))
			{
				int itemCount = inventory.GetItemCount(Items.OnLevelUpFreeUnlock);
				if (itemCount >= 1)
				{
					inventory.RemoveItem(Items.OnLevelUpFreeUnlock, itemCount);
					inventory.GiveItem(Items.Pearl, itemCount);
					CharacterMasterNotificationQueue.SendTransformNotification(body.master, Items.OnLevelUpFreeUnlock.itemIndex, Items.Pearl.itemIndex, (TransformationType)0);
				}
			}
		}

		private static void GlobalEventManager_onCharacterLevelUp(CharacterBody body)
		{
			ReplaceLSWithPearl(body, body.inventory);
		}
	}
	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);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("royal.LongstandingSolitudeFix", "LongstandingSolitudeFix", "1.0.0")]
	public class Main : BaseUnityPlugin
	{
		public const string PluginGUID = "royal.LongstandingSolitudeFix";

		public const string PluginAuthor = "royal";

		public const string PluginName = "LongstandingSolitudeFix";

		public const string PluginVersion = "1.0.0";

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			Configs.Init();
			Hooks.Init();
		}
	}
}