Decompiled source of Free Mine Upgrades v1.0.1

FreeMineUpgrades.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.Logging;
using Eremite.Buildings;
using Eremite.Buildings.UI;
using Eremite.Controller;
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(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("FreeMineUpgrades")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Makes mine upgrades free")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d6ada77561ccfe85ca4c2c807fd24c8c3fc0d51c")]
[assembly: AssemblyProduct("FreeMineUpgrades")]
[assembly: AssemblyTitle("FreeMineUpgrades")]
[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 FreeMineUpgrades
{
	[BepInPlugin("FreeMineUpgrades", "FreeMineUpgrades", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(GameController), "StartGame")]
		public class GameControllerStartGamePatch
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				Log.LogInfo((object)"Game started - FreeMineUpgrades is active");
			}
		}

		[HarmonyPatch(typeof(UpgradableBuilding), "AllGoodsAvailableFor")]
		public class UpgradableBuilding_AllGoodsAvailableFor_Patch
		{
			[HarmonyPrefix]
			private static bool Prefix(UpgradableBuilding __instance, ref bool __result)
			{
				if (__instance is Mine)
				{
					try
					{
						__result = true;
						return false;
					}
					catch (Exception arg)
					{
						Log.LogError((object)$"Error in AllGoodsAvailableFor Prefix Patch for Mine: {arg}");
						return true;
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(UpgradableBuilding), "RemoveGoods")]
		public class UpgradableBuilding_RemoveGoods_Patch
		{
			[HarmonyPrefix]
			private static bool Prefix(UpgradableBuilding __instance)
			{
				if (__instance is Mine)
				{
					try
					{
						return false;
					}
					catch (Exception arg)
					{
						Log.LogError((object)$"Error in RemoveGoods Prefix Patch for Mine: {arg}");
						return true;
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(BuildingUpgradesPanel), "SetUpGoods")]
		public class BuildingUpgradesPanel_SetUpGoods_Patch
		{
			[HarmonyPostfix]
			private static void Postfix(BuildingUpgradesPanel __instance)
			{
				try
				{
					FieldInfo fieldInfo = AccessTools.Field(typeof(BuildingUpgradesPanel), "building");
					if (fieldInfo == null)
					{
						Log.LogError((object)"Failed to find field 'building' in BuildingUpgradesPanel.");
						return;
					}
					object? value = fieldInfo.GetValue(__instance);
					UpgradableBuilding val = (UpgradableBuilding)((value is UpgradableBuilding) ? value : null);
					if ((Object)(object)val == (Object)null)
					{
						return;
					}
					bool flag = val is Mine;
					FieldInfo fieldInfo2 = AccessTools.Field(typeof(BuildingUpgradesPanel), "goodsLayout");
					FieldInfo fieldInfo3 = AccessTools.Field(typeof(BuildingUpgradesPanel), "noGoodsText");
					if (fieldInfo2 == null || fieldInfo3 == null)
					{
						Log.LogError((object)"Failed to find 'goodsLayout' or 'noGoodsText' field in BuildingUpgradesPanel.");
						return;
					}
					object? value2 = fieldInfo2.GetValue(__instance);
					Component val2 = (Component)((value2 is Component) ? value2 : null);
					object? value3 = fieldInfo3.GetValue(__instance);
					GameObject val3 = (GameObject)((value3 is GameObject) ? value3 : null);
					if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
					{
						Log.LogWarning((object)"Could not get Component/GameObject for 'goodsLayout' or 'noGoodsText'.");
					}
					else if (flag)
					{
						if (val2.gameObject.activeSelf)
						{
							Log.LogInfo((object)("Hiding upgrade costs UI for Mine ('" + ((Object)val).name + "')."));
						}
						val2.gameObject.SetActive(false);
						val3.SetActive(false);
					}
					else
					{
						if (!val2.gameObject.activeSelf)
						{
							Log.LogInfo((object)("Ensuring upgrade costs UI is visible for non-Mine ('" + ((object)val).GetType().Name + "')."));
						}
						val2.gameObject.SetActive(true);
					}
				}
				catch (Exception arg)
				{
					Log.LogError((object)$"Error in BuildingUpgradesPanel_SetUpGoods_Patch Postfix: {arg}");
				}
			}
		}

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("FreeMineUpgrades");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			Log.LogInfo((object)"Plugin FreeMineUpgrades is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "FreeMineUpgrades";

		public const string PLUGIN_NAME = "FreeMineUpgrades";

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