Decompiled source of CustomDiscoverStateLib v1.0.1

Kistras-CustomDiscoverStateLib.dll

Decompiled a month ago
using System;
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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Kistras-CustomDiscoverStateLib")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+ecb0ea156d319532af57b3a5509092d13c08d37c")]
[assembly: AssemblyProduct("CustomDiscoverStateLib")]
[assembly: AssemblyTitle("Kistras-CustomDiscoverStateLib")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 CustomDiscoverStateLib
{
	[BepInPlugin("Kistras-CustomDiscoverStateLib", "CustomDiscoverStateLib", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private readonly Harmony harmony = new Harmony("Kistras-CustomDiscoverStateLib");

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			harmony.PatchAll(typeof(Patches));
			Logger.LogInfo((object)"Plugin Kistras-CustomDiscoverStateLib is loaded!");
		}
	}
	public static class CustomDiscoverState
	{
		public delegate bool DynamicStateDelegate(ValuableDiscover valuableDiscover, PhysGrabObject physGrabObject, out Color? middle, out Color? corner);

		public delegate bool ConditionalStateDelegate(ValuableDiscover valuableDiscover, PhysGrabObject physGrabObject);

		public class CustomDiscoverGraphic
		{
			public Color ColorMiddle;

			public Color ColorCorner;
		}

		private static int lastAddedIndex = 260;

		internal static Dictionary<State, ConditionalStateDelegate> conditionalStates = new Dictionary<State, ConditionalStateDelegate>();

		internal static Dictionary<State, CustomDiscoverGraphic> customStates = new Dictionary<State, CustomDiscoverGraphic>();

		internal static Dictionary<State, DynamicStateDelegate> dynamicStates = new Dictionary<State, DynamicStateDelegate>();

		public static State AddNewDiscoverGraphic(Color middle, Color corner)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			State val = (State)lastAddedIndex;
			lastAddedIndex++;
			customStates[val] = new CustomDiscoverGraphic
			{
				ColorMiddle = middle,
				ColorCorner = corner
			};
			return val;
		}

		public static State AddNewConditionalDiscoverGraphic(ConditionalStateDelegate condition, Color middle, Color corner)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			State val = AddNewDiscoverGraphic(middle, corner);
			conditionalStates[val] = condition;
			return val;
		}

		public static State AddNewDynamicDiscoverGraphic(DynamicStateDelegate @delegate)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			State val = AddNewDiscoverGraphic(new Color(0f, 0f, 0f, 0f), Color.white);
			dynamicStates[val] = @delegate;
			return val;
		}
	}
	[HarmonyPatch]
	internal class Patches
	{
		[HarmonyPatch(typeof(ValuableDiscover), "New")]
		[HarmonyPrefix]
		public static bool ValuableDiscoverPatch(ValuableDiscover __instance, PhysGrabObject _target, State _state)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			Color? middle = null;
			Color? corner = null;
			if (!CustomDiscoverState.customStates.TryGetValue(_state, out var value))
			{
				bool flag = false;
				foreach (KeyValuePair<State, CustomDiscoverState.ConditionalStateDelegate> conditionalState in CustomDiscoverState.conditionalStates)
				{
					if (conditionalState.Value(__instance, _target))
					{
						value = CustomDiscoverState.customStates[conditionalState.Key];
						flag = true;
						middle = value.ColorMiddle;
						corner = value.ColorCorner;
						break;
					}
				}
				if (!flag || value == null)
				{
					foreach (KeyValuePair<State, CustomDiscoverState.DynamicStateDelegate> dynamicState in CustomDiscoverState.dynamicStates)
					{
						if (dynamicState.Value(__instance, _target, out middle, out corner))
						{
							_state = dynamicState.Key;
							flag = true;
							break;
						}
					}
					if (!flag)
					{
						return true;
					}
				}
			}
			else
			{
				middle = value.ColorMiddle;
				corner = value.ColorCorner;
			}
			if (!middle.HasValue || !corner.HasValue)
			{
				return true;
			}
			ValuableDiscoverGraphic component = Object.Instantiate<GameObject>(__instance.graphicPrefab, ((Component)__instance).transform).GetComponent<ValuableDiscoverGraphic>();
			component.target = _target;
			component.state = _state;
			((Graphic)((Component)component.middle).GetComponent<Image>()).color = middle.Value;
			((Graphic)((Component)component.topLeft).GetComponent<Image>()).color = corner.Value;
			((Graphic)((Component)component.topRight).GetComponent<Image>()).color = corner.Value;
			((Graphic)((Component)component.botLeft).GetComponent<Image>()).color = corner.Value;
			((Graphic)((Component)component.botRight).GetComponent<Image>()).color = corner.Value;
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Kistras-CustomDiscoverStateLib";

		public const string PLUGIN_NAME = "CustomDiscoverStateLib";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}