Decompiled source of FreeChestsPlus v1.0.3

FreeChestsPlus.dll

Decompiled a day 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 Assets.Scripts.Actors.Player;
using Assets.Scripts.Inventory__Items__Pickups.Chests;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("FreeChestsPlus")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0cdf697b094bae0d59ca38ae12b26f897b942b1a")]
[assembly: AssemblyProduct("FreeChestsPlus")]
[assembly: AssemblyTitle("FreeChestsPlus")]
[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;
		}
	}
}
[BepInPlugin("com.megabonk.freechestsplus", "FreeChestsPlus", "1.0.2")]
public class FreeChestsPlugin : BasePlugin
{
	public override void Load()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		((BasePlugin)this).Log.LogInfo((object)"FreeChestsPlus mod loaded!");
		Harmony val = new Harmony("com.megabonk.freechestsplus");
		val.PatchAll();
	}
}
[HarmonyPatch(typeof(InteractableChest))]
internal static class InteractableChestPatches
{
	private static ManualLogSource Logger = Logger.CreateLogSource("FreeChestsPlus");

	private static MyPlayer cachedPlayer = null;

	private static MyPlayer GetPlayer()
	{
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Expected O, but got Unknown
		try
		{
			if ((Object)(object)cachedPlayer != (Object)null)
			{
				return cachedPlayer;
			}
			Type type = typeof(InteractableChest).Assembly.GetType("GameManager");
			if (type != null)
			{
				PropertyInfo property = type.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public);
				if (property != null)
				{
					object value = property.GetValue(null);
					if (value != null)
					{
						PropertyInfo property2 = type.GetProperty("player", BindingFlags.Instance | BindingFlags.Public);
						if (property2 != null)
						{
							object? value2 = property2.GetValue(value);
							MyPlayer val = (MyPlayer)((value2 is MyPlayer) ? value2 : null);
							if ((Object)(object)val != (Object)null)
							{
								cachedPlayer = val;
								return val;
							}
						}
					}
				}
			}
			Logger.LogWarning((object)"[GetPlayer] Could not find player!");
			return null;
		}
		catch (Exception ex)
		{
			ManualLogSource logger = Logger;
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(19, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[GetPlayer] Error: ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
			}
			logger.LogError(val2);
			return null;
		}
	}

	[HarmonyPatch("CanAfford")]
	[HarmonyPrefix]
	private static bool CanAfford_Prefix(ref bool __result)
	{
		__result = true;
		return false;
	}

	[HarmonyPatch("Interact")]
	[HarmonyPostfix]
	private static void Interact_Postfix()
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		MyPlayer player = GetPlayer();
		if (((player != null) ? player.inventory : null) == null)
		{
			return;
		}
		float gold = player.inventory.gold;
		if (gold < 0f)
		{
			ManualLogSource logger = Logger;
			bool flag = default(bool);
			BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(54, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Interact_Postfix] Gold went negative (");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(gold);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("), setting to 0");
			}
			logger.LogWarning(val);
			player.inventory.gold = 0f;
		}
	}
}