Decompiled source of SynergiesAPI v1.0.0

SynergiesAPI.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Atomicrops.Core.Upgrades;
using Atomicrops.Game.Data;
using Atomicrops.Game.Player;
using Atomicrops.Game.Upgrades;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SharedLib;
using UnityEngine;
using UnityEngine.UI;

[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: AssemblyCompany("SynergiesAPI")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3b667bb2714e0f74b141e5d323763526d97b13a2")]
[assembly: AssemblyProduct("SynergiesAPI")]
[assembly: AssemblyTitle("SynergiesAPI")]
[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 Template
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SynergiesAPI";

		public const string PLUGIN_NAME = "SynergiesAPI";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace SynergiesAPI
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "pauli.plugin.SynergiesAPI";

		public const string PLUGIN_NAME = "SynergiesAPI";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	public class ActionContainer
	{
		public Action Function { get; set; }

		public Action Cleanup { get; set; }

		public ActionContainer(Action actionMethod, Action cleanupMethod)
		{
			Function = actionMethod;
			Cleanup = cleanupMethod;
		}
	}
	[BepInPlugin("pauli.plugin.SynergiesAPI", "SynergiesAPI", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Log;

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			Instance = this;
			HookFloatTextPrefab();
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin pauli.plugin.SynergiesAPI is loaded!");
			Harmony val = new Harmony("pauli.plugin.SynergiesAPI");
			val.PatchAll();
		}

		private void HookFloatTextPrefab()
		{
			GameObject val = Resources.Load<GameObject>("InGameFloatTextNumberOnly");
			if ((Object)(object)val != (Object)null && (Object)(object)val.GetComponent<RainbowFloatText>() == (Object)null)
			{
				RainbowFloatText rainbowFloatText = val.AddComponent<RainbowFloatText>();
				((Behaviour)rainbowFloatText).enabled = false;
			}
		}
	}
	public class RainbowFloatText : MonoBehaviour
	{
		public float speed = 1.2f;

		public float saturation = 1f;

		public float brightness = 1f;

		private bool isRunning = false;

		private Text numberText;

		private void Awake()
		{
			numberText = ((Component)this).GetComponentInChildren<Text>(true);
		}

		public void Begin(float duration)
		{
			isRunning = true;
			((MonoBehaviour)this).Invoke("Stop", duration);
		}

		private void Stop()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			isRunning = false;
			if ((Object)(object)numberText != (Object)null)
			{
				((Graphic)numberText).color = Color.white;
			}
		}

		private void Update()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if (isRunning && !((Object)(object)numberText == (Object)null))
			{
				float num = default(float);
				float num2 = default(float);
				float num3 = default(float);
				Color.RGBToHSV(((Graphic)numberText).color, ref num, ref num2, ref num3);
				num = (num + Time.deltaTime * speed) % 1f;
				num2 = saturation;
				num3 = brightness;
				((Graphic)numberText).color = Color.HSVToRGB(num, num2, num3);
			}
		}
	}
	public class Synergy
	{
		[CompilerGenerated]
		private sealed class <ShowText>d__12 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Synergy <>4__this;

			private PlayerComp <player>5__1;

			private FieldInfo <goTmpField>5__2;

			private GameObject <go>5__3;

			private RainbowFloatText <rainbow>5__4;

			private string <items>5__5;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ShowText>d__12(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<player>5__1 = null;
				<goTmpField>5__2 = null;
				<go>5__3 = null;
				<rainbow>5__4 = null;
				<items>5__5 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0158: Unknown result type (might be due to invalid IL or missing references)
				//IL_015d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0174: Unknown result type (might be due to invalid IL or missing references)
				//IL_017e: Expected O, but got Unknown
				//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Expected O, but got Unknown
				//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0107: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<player>5__1 = SingletonSceneScope<PlayerComp>.I;
					if ((Object)(object)<player>5__1 == (Object)null)
					{
						return false;
					}
					InGameText.FloatUpNumberOnly("SYNERGY!", Vector2.op_Implicit(<player>5__1.Anchors.Head), false, 6f);
					<goTmpField>5__2 = AccessTools.Field(typeof(InGameText), "_goTmp");
					<go>5__3 = (GameObject)<goTmpField>5__2.GetValue(null);
					<rainbow>5__4 = <go>5__3.GetComponent<RainbowFloatText>();
					if ((Object)(object)<rainbow>5__4 == (Object)null)
					{
						<rainbow>5__4 = <go>5__3.AddComponent<RainbowFloatText>();
					}
					((Behaviour)<rainbow>5__4).enabled = true;
					<rainbow>5__4.Begin(10f);
					<>2__current = (object)new WaitForSeconds(1.5f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<items>5__5 = string.Join(" + ", <>4__this.requiredUpgrades);
					InGameText.FloatUpNumberOnly(<>4__this.name + ": " + <items>5__5, Vector2.op_Implicit(<player>5__1.Anchors.Head), false, 6f);
					<>2__current = (object)new WaitForSeconds(1.5f);
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					InGameText.FloatUpNumberOnly(<>4__this.description, Vector2.op_Implicit(<player>5__1.Anchors.Head), false, 6f);
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static List<Synergy> AllSynergies = new List<Synergy>();

		public static Dictionary<string, List<Synergy>> AllRequiredUpgrades = new Dictionary<string, List<Synergy>>();

		public static HashSet<string> CurrentUpgrades = new HashSet<string>();

		public bool isActive = false;

		public string name;

		public string description;

		public List<string> requiredUpgrades;

		public Action action;

		public Action cleanup;

		public bool hasDonePopup = false;

		public Synergy(string synergyName, string synergyDescription, Action functionalityMethod, Action cleanupMethod, List<string> upgrades)
		{
			name = synergyName;
			description = synergyDescription;
			action = functionalityMethod;
			cleanup = cleanupMethod;
			requiredUpgrades = new List<string>();
			foreach (string upgrade in upgrades)
			{
				string text = upgrade.Trim(' ', '#').ToLower();
				requiredUpgrades.Add(text);
				if (!AllRequiredUpgrades.TryGetValue(text, out var value))
				{
					value = new List<Synergy>();
					AllRequiredUpgrades[text] = value;
				}
				value.Add(this);
			}
			AllSynergies.Add(this);
		}

		public void Activate()
		{
			if (!hasDonePopup)
			{
				((MonoBehaviour)Plugin.Instance).StartCoroutine(ShowText());
				hasDonePopup = true;
			}
			action?.Invoke();
		}

		[IteratorStateMachine(typeof(<ShowText>d__12))]
		public IEnumerator ShowText()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ShowText>d__12(0)
			{
				<>4__this = this
			};
		}
	}
	[HarmonyPatch(typeof(UpgradeRunner), "ApplyUpgradeList")]
	[Harmony]
	internal class UpgradeRunner_ApplyUpgradeList_Patch
	{
		[HarmonyPriority(600)]
		private static void Prefix()
		{
			foreach (Synergy allSynergy in Synergy.AllSynergies)
			{
				if (allSynergy.isActive)
				{
					allSynergy.Activate();
				}
			}
		}
	}
	[HarmonyPatch(typeof(UpgradesCollection), "_addStack")]
	internal class UpgradesCollection_addStack_Patch
	{
		private static void Prefix(UpgradeDef def)
		{
			string text = def.LootProperties.DisplayName.Trim().ToLower();
			Synergy.CurrentUpgrades.Add(text);
			if (!Synergy.AllRequiredUpgrades.TryGetValue(text, out var value))
			{
				return;
			}
			foreach (Synergy item in value)
			{
				bool flag = true;
				foreach (string requiredUpgrade in item.requiredUpgrades)
				{
					if (!Synergy.CurrentUpgrades.Contains(requiredUpgrade))
					{
						flag = false;
						break;
					}
				}
				if (flag)
				{
					item.isActive = true;
				}
			}
		}
	}
	[HarmonyPatch(typeof(GameDataPresets), "NewGameData")]
	internal class GameDataPresets_NewGameData_Patch
	{
		private static void Prefix()
		{
			foreach (Synergy allSynergy in Synergy.AllSynergies)
			{
				if (allSynergy.isActive)
				{
					allSynergy.cleanup?.Invoke();
					allSynergy.isActive = false;
					allSynergy.hasDonePopup = false;
					Synergy.CurrentUpgrades = new HashSet<string>();
				}
			}
		}
	}
}