Decompiled source of GatsPrizeWheel v0.1.2

BepInEx/plugins/GatsWheel.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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Movement;
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.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("GatsWheel")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-alpha.0.4+260bdf5ddb220042e04ac867d08cfc14a531b76d")]
[assembly: AssemblyProduct("Spin the Prize Wheel with your hard earned Gats")]
[assembly: AssemblyTitle("GatsWheel")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 GatsWheel
{
	[MycoMod(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("hed14.gatswheel", "GatsWheel", "0.1.2")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGUID = "hed14.gatswheel";

		public const string PluginName = "GatsWheel";

		public const string PluginVersion = "0.1.2";

		public const int GatsFallbackCost = 499;

		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin hed14.gatswheel is loaded!");
			Harmony val = new Harmony("hed14.gatswheel");
			val.PatchAll();
			Logger.LogInfo((object)"Harmony patches applied.");
		}
	}
	[HarmonyPatch(typeof(RewardSpinner), "HasRequiredResources")]
	internal class HasRequiredResourcesPatch
	{
		private static void Postfix(RewardSpinner __instance, ref bool __result, ref PlayerResource firstAvailable)
		{
			if (__result)
			{
				return;
			}
			if (!(AccessTools.Field(typeof(RewardSpinner), "cost").GetValue(__instance) is ResourceCost[] array))
			{
				__result = false;
				return;
			}
			for (int i = 0; i < array.Length; i++)
			{
				if ((Object)(object)firstAvailable == (Object)null)
				{
					firstAvailable = array[i].resource;
				}
				if (PlayerData.Instance.GetResource(array[i].resource) >= array[i].count)
				{
					firstAvailable = array[i].resource;
					__result = true;
					return;
				}
				PlayerResource resource = PlayerResource.GetResource("scrip");
				if ((Object)(object)resource != (Object)null && PlayerData.Instance.GetResource(resource) >= 499)
				{
					firstAvailable = resource;
					__result = true;
					return;
				}
			}
			__result = false;
		}
	}
	[HarmonyPatch(typeof(RewardSpinner), "OnImmediateInteract")]
	internal class OnImmediateInteractPatch
	{
		private static bool Prefix(RewardSpinner __instance, Player player)
		{
			if ((bool)AccessTools.Field(typeof(RewardSpinner), "isSpinning").GetValue(__instance))
			{
				return false;
			}
			if (!(AccessTools.Field(typeof(RewardSpinner), "cost").GetValue(__instance) is ResourceCost[] array))
			{
				return true;
			}
			bool flag = false;
			for (int i = 0; i < array.Length; i++)
			{
				PlayerResource resource = array[i].resource;
				int count = array[i].count;
				if (PlayerData.Instance.TryRemoveResource(resource, count))
				{
					flag = true;
					Plugin.Logger.LogInfo((object)("RewardSpinner used " + resource.Name + " for spin."));
					break;
				}
				PlayerResource resource2 = PlayerResource.GetResource("scrip");
				if ((Object)(object)resource2 != (Object)null && PlayerData.Instance.TryRemoveResource(resource2, 499))
				{
					flag = true;
					Plugin.Logger.LogInfo((object)$"RewardSpinner used Gats fallback ({499}) for spin.");
					break;
				}
			}
			if (!flag)
			{
				object value = AccessTools.Field(typeof(Global), "AbilityErrorSound").GetValue(Global.Instance);
				AccessTools.Method(value.GetType(), "Post", (Type[])null, (Type[])null).Invoke(value, new object[1] { ((Component)PlayerLook.Instance).gameObject });
				return false;
			}
			object value2 = AccessTools.Field(typeof(RewardSpinner), "rewards").GetValue(__instance);
			LevelUnlock[] array2 = AccessTools.Property(value2.GetType(), "Properties").GetValue(value2) as LevelUnlock[];
			MethodInfo methodInfo = AccessTools.Method(typeof(RewardSpinner), "StartSpin", (Type[])null, (Type[])null);
			methodInfo.Invoke(__instance, new object[2]
			{
				Random.Range(0, array2.Length),
				true
			});
			return false;
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class InteractTextPatch
	{
		private static void Postfix(RewardSpinner __instance, ref string __result)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			if (AccessTools.Field(typeof(RewardSpinner), "cost").GetValue(__instance) is ResourceCost[])
			{
				object[] array2 = new object[1];
				bool flag = (bool)AccessTools.Method(typeof(RewardSpinner), "HasRequiredResources", (Type[])null, (Type[])null).Invoke(__instance, array2);
				PlayerResource val = (PlayerResource)array2[0];
				if ((Object)(object)val != (Object)null && val.ID == "scrip")
				{
					int num = 499;
					__result = $"Use {num} Gats";
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "GatsWheel";

		public const string PLUGIN_NAME = "Spin the Prize Wheel with your hard earned Gats";

		public const string PLUGIN_VERSION = "0.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}