Decompiled source of ResourceMod v1.0.0

ResourceMod.dll

Decompiled 19 hours 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 Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("ResourceMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Resource cheat mod for Goblin Buster")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e02dd8764628d1e8f9c17ba1e5b12acaeb5789cf")]
[assembly: AssemblyProduct("ResourceMod")]
[assembly: AssemblyTitle("ResourceMod")]
[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 ResourceMod
{
	[BepInPlugin("com.mod.goblinbuster.resourcemod", "Goblin Buster Resource Mod", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private bool _showMenu;

		private Rect _windowRect = new Rect(20f, 20f, 320f, 380f);

		private string _amountInput = "100";

		private int _selectedResource;

		private bool _showResourceDropdown;

		private bool _showAmountDropdown;

		private Vector2 _resourceScrollPos;

		private Vector2 _amountScrollPos;

		private Rect _resourceButtonRect;

		private Rect _amountButtonRect;

		private Rect _resourceDropdownRect;

		private Rect _amountDropdownRect;

		private readonly string[] _resourceNames = new string[8] { "Wood", "Iron", "Crystals (Amethysts)", "Mana", "Soul Shards", "Ectoplasm", "Raw Runes", "Gold (In-Level)" };

		private readonly string[] _quickAmounts = new string[9] { "100", "500", "1,000", "5,000", "10,000", "50,000", "100,000", "500,000", "1,000,000" };

		private readonly int[] _quickAmountValues = new int[9] { 100, 500, 1000, 5000, 10000, 50000, 100000, 500000, 1000000 };

		private const int MAX_RESOURCE_VALUE = 2000000000;

		private const float MIN_WIDTH = 280f;

		private const float MIN_HEIGHT = 320f;

		private bool _isResizing;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin com.mod.goblinbuster.resourcemod is loaded!");
		}

		private void Update()
		{
			if (Input.GetKeyDown((KeyCode)286))
			{
				_showMenu = !_showMenu;
				if (!_showMenu)
				{
					_showResourceDropdown = false;
					_showAmountDropdown = false;
				}
				Logger.LogInfo((object)$"Resource menu toggled: {_showMenu}");
			}
		}

		private void OnGUI()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (_showMenu)
			{
				GUI.backgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.95f);
				_windowRect = GUI.Window(12345, _windowRect, new WindowFunction(DrawWindow), "Resource Mod Menu");
				((Rect)(ref _windowRect)).width = Mathf.Max(((Rect)(ref _windowRect)).width, 280f);
				((Rect)(ref _windowRect)).height = Mathf.Max(((Rect)(ref _windowRect)).height, 320f);
			}
		}

		private void DrawWindow(int windowId)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Invalid comparison between Unknown and I4
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Invalid comparison between Unknown and I4
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			if (GUI.Button(new Rect(((Rect)(ref _windowRect)).width - 25f, 3f, 20f, 18f), "X"))
			{
				_showMenu = false;
				_showResourceDropdown = false;
				_showAmountDropdown = false;
			}
			GUILayout.Space(10f);
			GUILayout.Label("=== Give Resources ===", Array.Empty<GUILayoutOption>());
			GUILayout.Label("Select Resource:", Array.Empty<GUILayoutOption>());
			if (GUILayout.Button(_resourceNames[_selectedResource], (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(25f) }))
			{
				_showResourceDropdown = !_showResourceDropdown;
				_showAmountDropdown = false;
			}
			if ((int)Event.current.type == 7)
			{
				_resourceButtonRect = GUILayoutUtility.GetLastRect();
			}
			GUILayout.Space(10f);
			GUILayout.Label("Amount to Give:", Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			_amountInput = GUILayout.TextField(_amountInput, 12, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(((Rect)(ref _windowRect)).width - 80f) });
			if (GUILayout.Button("Presets", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(55f) }))
			{
				_showAmountDropdown = !_showAmountDropdown;
				_showResourceDropdown = false;
			}
			if ((int)Event.current.type == 7)
			{
				_amountButtonRect = GUILayoutUtility.GetLastRect();
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(10f);
			if (GUILayout.Button("Give Resources", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(35f) }))
			{
				GiveResources();
			}
			GUILayout.Space(10f);
			GUILayout.Label("--- Current Resources ---", Array.Empty<GUILayoutOption>());
			if ((Object)(object)AccountManager.Instance != (Object)null)
			{
				GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
				GUILayout.Label($"Wood: {AccountManager.Instance.Wood:N0}", Array.Empty<GUILayoutOption>());
				GUILayout.Label($"Iron: {AccountManager.Instance.Iron:N0}", Array.Empty<GUILayoutOption>());
				GUILayout.Label($"Crystals: {AccountManager.Instance.Crystals:N0}", Array.Empty<GUILayoutOption>());
				GUILayout.Label($"Mana: {AccountManager.Instance.Mana:N0}", Array.Empty<GUILayoutOption>());
				GUILayout.Label($"Soul Shards: {AccountManager.Instance.SoulShards:N0}", Array.Empty<GUILayoutOption>());
				GUILayout.Label($"Ectoplasm: {AccountManager.Instance.Ectoplasm:N0}", Array.Empty<GUILayoutOption>());
				GUILayout.Label($"Raw Runes: {AccountManager.Instance.RawRunes:N0}", Array.Empty<GUILayoutOption>());
				LevelManager val = Object.FindObjectOfType<LevelManager>();
				if ((Object)(object)val != (Object)null)
				{
					GUILayout.Label($"Gold (In-Level): {val.PlayerGold:N0}", Array.Empty<GUILayoutOption>());
				}
				GUILayout.EndVertical();
			}
			else
			{
				GUILayout.Label("AccountManager not found - not in game?", Array.Empty<GUILayoutOption>());
			}
			GUILayout.FlexibleSpace();
			GUILayout.Label("Drag edges to resize", GUI.skin.label, Array.Empty<GUILayoutOption>());
			GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref _windowRect)).width - 30f, 20f));
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(((Rect)(ref _windowRect)).width - 20f, ((Rect)(ref _windowRect)).height - 20f, 20f, 20f);
			GUI.Box(val2, "//");
			if ((int)Event.current.type == 0 && ((Rect)(ref val2)).Contains(Event.current.mousePosition))
			{
				_isResizing = true;
			}
			DrawDropdownOverlays();
		}

		private void DrawDropdownOverlays()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			if (_showResourceDropdown)
			{
				float num = 140f;
				_resourceDropdownRect = new Rect(((Rect)(ref _resourceButtonRect)).x, ((Rect)(ref _resourceButtonRect)).y + ((Rect)(ref _resourceButtonRect)).height, ((Rect)(ref _resourceButtonRect)).width, num);
				GUI.Box(_resourceDropdownRect, "");
				GUILayout.BeginArea(_resourceDropdownRect);
				_resourceScrollPos = GUILayout.BeginScrollView(_resourceScrollPos, Array.Empty<GUILayoutOption>());
				for (int i = 0; i < _resourceNames.Length; i++)
				{
					if (GUILayout.Button(_resourceNames[i], Array.Empty<GUILayoutOption>()))
					{
						_selectedResource = i;
						_showResourceDropdown = false;
					}
				}
				GUILayout.EndScrollView();
				GUILayout.EndArea();
				if ((int)Event.current.type == 0 && !((Rect)(ref _resourceDropdownRect)).Contains(Event.current.mousePosition) && !((Rect)(ref _resourceButtonRect)).Contains(Event.current.mousePosition))
				{
					_showResourceDropdown = false;
					Event.current.Use();
				}
			}
			if (!_showAmountDropdown)
			{
				return;
			}
			float num2 = 120f;
			_amountDropdownRect = new Rect(((Rect)(ref _amountButtonRect)).x, ((Rect)(ref _amountButtonRect)).y + ((Rect)(ref _amountButtonRect)).height, ((Rect)(ref _amountButtonRect)).width + 30f, num2);
			GUI.Box(_amountDropdownRect, "");
			GUILayout.BeginArea(_amountDropdownRect);
			_amountScrollPos = GUILayout.BeginScrollView(_amountScrollPos, Array.Empty<GUILayoutOption>());
			for (int j = 0; j < _quickAmounts.Length; j++)
			{
				if (GUILayout.Button(_quickAmounts[j], Array.Empty<GUILayoutOption>()))
				{
					_amountInput = _quickAmountValues[j].ToString();
					_showAmountDropdown = false;
				}
			}
			GUILayout.EndScrollView();
			GUILayout.EndArea();
			if ((int)Event.current.type == 0 && !((Rect)(ref _amountDropdownRect)).Contains(Event.current.mousePosition) && !((Rect)(ref _amountButtonRect)).Contains(Event.current.mousePosition))
			{
				_showAmountDropdown = false;
				Event.current.Use();
			}
		}

		private void LateUpdate()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			if (_isResizing)
			{
				if (Input.GetMouseButton(0))
				{
					Vector2 val = default(Vector2);
					((Vector2)(ref val))..ctor(Input.mousePosition.x, (float)Screen.height - Input.mousePosition.y);
					Vector2 val2 = default(Vector2);
					((Vector2)(ref val2))..ctor(((Rect)(ref _windowRect)).x, ((Rect)(ref _windowRect)).y);
					((Rect)(ref _windowRect)).width = Mathf.Max(280f, val.x - val2.x + 10f);
					((Rect)(ref _windowRect)).height = Mathf.Max(320f, val.y - val2.y + 10f);
				}
				else
				{
					_isResizing = false;
				}
			}
		}

		private void GiveResources()
		{
			_showResourceDropdown = false;
			_showAmountDropdown = false;
			if (!int.TryParse(_amountInput.Replace(",", ""), out var result))
			{
				Logger.LogWarning((object)"Invalid amount entered - must be a number");
				return;
			}
			if (result < 0)
			{
				Logger.LogWarning((object)"Amount cannot be negative");
				return;
			}
			if (result == 0)
			{
				Logger.LogWarning((object)"Amount must be greater than 0");
				return;
			}
			if ((Object)(object)AccountManager.Instance == (Object)null)
			{
				Logger.LogWarning((object)"AccountManager not available - are you in a game?");
				return;
			}
			switch (_selectedResource)
			{
			case 0:
				AccountManager.Instance.Wood = SafeAdd(AccountManager.Instance.Wood, result, "Wood");
				break;
			case 1:
				AccountManager.Instance.Iron = SafeAdd(AccountManager.Instance.Iron, result, "Iron");
				break;
			case 2:
				AccountManager.Instance.Crystals = SafeAdd(AccountManager.Instance.Crystals, result, "Crystals");
				break;
			case 3:
				AccountManager.Instance.Mana = SafeAdd(AccountManager.Instance.Mana, result, "Mana");
				break;
			case 4:
				AccountManager.Instance.SoulShards = SafeAdd(AccountManager.Instance.SoulShards, result, "Soul Shards");
				break;
			case 5:
				AccountManager.Instance.Ectoplasm = SafeAdd(AccountManager.Instance.Ectoplasm, result, "Ectoplasm");
				break;
			case 6:
				AccountManager.Instance.RawRunes = SafeAdd(AccountManager.Instance.RawRunes, result, "Raw Runes");
				break;
			case 7:
			{
				LevelManager val = Object.FindObjectOfType<LevelManager>();
				if ((Object)(object)val != (Object)null)
				{
					val.PlayerGold = SafeAdd(val.PlayerGold, result, "Gold");
				}
				else
				{
					Logger.LogWarning((object)"LevelManager not found - you need to be in a level to give gold");
				}
				break;
			}
			}
			AccountManager.Instance.SaveResources();
			if ((Object)(object)AccountManager.Instance.UpgradeManager != (Object)null && ((Behaviour)AccountManager.Instance.UpgradeManager).isActiveAndEnabled)
			{
				AccountManager.Instance.UpgradeManager.WoodAmount = AccountManager.Instance.Wood;
				AccountManager.Instance.UpgradeManager.IronAmount = AccountManager.Instance.Iron;
				AccountManager.Instance.UpgradeManager.CrystalsAmount = AccountManager.Instance.Crystals;
				AccountManager.Instance.UpgradeManager.ManaAmount = AccountManager.Instance.Mana;
				AccountManager.Instance.UpgradeManager.SoulShardsAmount = AccountManager.Instance.SoulShards;
				AccountManager.Instance.UpgradeManager.EctoplasmAmount = AccountManager.Instance.Ectoplasm;
				AccountManager.Instance.UpgradeManager.RawRunesAmount = AccountManager.Instance.RawRunes;
				AccountManager.Instance.UpgradeManager.UpdateResourcesViews();
			}
			Logger.LogInfo((object)$"Gave {result} {_resourceNames[_selectedResource]}");
		}

		private int SafeAdd(int current, int toAdd, string resourceName)
		{
			if (current > 2000000000 - toAdd)
			{
				Logger.LogWarning((object)$"Capping {resourceName} at {2000000000} to prevent overflow");
				return 2000000000;
			}
			if ((long)current + (long)toAdd > int.MaxValue)
			{
				Logger.LogWarning((object)$"Capping {resourceName} at {2000000000} to prevent overflow");
				return 2000000000;
			}
			return current + toAdd;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.mod.goblinbuster.resourcemod";

		public const string PLUGIN_NAME = "Goblin Buster Resource Mod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}