Decompiled source of ExtractionPointConfirmButton v1.1.0

com.github.zehsteam.ExtractionPointConfirmButton.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using REPOLib;
using REPOLib.Modules;
using UnityEngine;
using com.github.zehsteam.ExtractionPointConfirmButton.MonoBehaviours;
using com.github.zehsteam.ExtractionPointConfirmButton.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Zehs")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2025 Zehs")]
[assembly: AssemblyDescription("Adds a confirm button to extraction points.")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+4e79a0b5f97bea0d28b3a655637fcb08838a55c6")]
[assembly: AssemblyProduct("ExtractionPointConfirmButton")]
[assembly: AssemblyTitle("com.github.zehsteam.ExtractionPointConfirmButton")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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 com.github.zehsteam.ExtractionPointConfirmButton
{
	internal static class Assets
	{
		public static GameObject ConfirmButtonPrefab { get; private set; }

		public static void Initialize()
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string text = "extractionpointconfirmbutton_assets";
			string text2 = Path.Combine(directoryName, text);
			if (!File.Exists(text2))
			{
				Logger.LogFatal("Failed to load assets. AssetBundle file could not be found at path \"" + text2 + "\". Make sure the \"" + text + "\" file is in the same folder as the mod's DLL file.");
			}
			else
			{
				BundleLoader.LoadBundle(text2, (Action<AssetBundle>)OnAssetBundleLoaded, false);
			}
		}

		private static void OnAssetBundleLoaded(AssetBundle assetBundle)
		{
			ConfirmButtonPrefab = LoadAsset<GameObject>("ConfirmButton", assetBundle);
			NetworkPrefabs.RegisterNetworkPrefab(ConfirmButtonPrefab);
		}

		private static T LoadAsset<T>(string name, AssetBundle assetBundle) where T : Object
		{
			if (string.IsNullOrWhiteSpace(name))
			{
				Logger.LogError("Failed to load asset of type \"" + typeof(T).Name + "\" from AssetBundle. Name is null or whitespace.");
				return default(T);
			}
			if ((Object)(object)assetBundle == (Object)null)
			{
				Logger.LogError("Failed to load asset of type \"" + typeof(T).Name + "\" with name \"" + name + "\" from AssetBundle. AssetBundle is null.");
				return default(T);
			}
			T val = assetBundle.LoadAsset<T>(name);
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError("Failed to load asset of type \"" + typeof(T).Name + "\" with name \"" + name + "\" from AssetBundle. No asset found with that type and name.");
				return default(T);
			}
			return val;
		}

		private static bool TryLoadAsset<T>(string name, AssetBundle assetBundle, out T asset) where T : Object
		{
			asset = LoadAsset<T>(name, assetBundle);
			return (Object)(object)asset != (Object)null;
		}
	}
	internal static class ConfigManager
	{
		public static ConfigFile ConfigFile { get; private set; }

		public static ConfigEntry<bool> ExtendedLogging { get; private set; }

		public static void Initialize(ConfigFile configFile)
		{
			ConfigFile = configFile;
			BindConfigs();
		}

		private static void BindConfigs()
		{
			ExtendedLogging = ConfigFile.Bind<bool>("General", "ExtendedLogging", false, "Enable extended logging.");
		}
	}
	internal static class Logger
	{
		public static ManualLogSource ManualLogSource { get; private set; }

		public static void Initialize(ManualLogSource manualLogSource)
		{
			ManualLogSource = manualLogSource;
		}

		public static void LogDebug(object data, bool extended = true)
		{
			Log((LogLevel)32, data, extended);
		}

		public static void LogInfo(object data, bool extended = false)
		{
			Log((LogLevel)16, data, extended);
		}

		public static void LogWarning(object data, bool extended = false)
		{
			Log((LogLevel)4, data, extended);
		}

		public static void LogError(object data, bool extended = false)
		{
			Log((LogLevel)2, data, extended);
		}

		public static void LogFatal(object data, bool extended = false)
		{
			Log((LogLevel)1, data, extended);
		}

		public static void Log(LogLevel logLevel, object data, bool extended = false)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (!extended || IsExtendedLoggingEnabled())
			{
				ManualLogSource manualLogSource = ManualLogSource;
				if (manualLogSource != null)
				{
					manualLogSource.Log(logLevel, data);
				}
			}
		}

		public static bool IsExtendedLoggingEnabled()
		{
			if (ConfigManager.ExtendedLogging == null)
			{
				return false;
			}
			return ConfigManager.ExtendedLogging.Value;
		}
	}
	[BepInPlugin("com.github.zehsteam.ExtractionPointConfirmButton", "ExtractionPointConfirmButton", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("com.github.zehsteam.ExtractionPointConfirmButton");

		internal static Plugin Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger.Initialize(Logger.CreateLogSource("com.github.zehsteam.ExtractionPointConfirmButton"));
			Logger.LogInfo("ExtractionPointConfirmButton has awoken!");
			_harmony.PatchAll(typeof(RunManagerPatch));
			_harmony.PatchAll(typeof(ExtractionPointPatch));
			ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
			Assets.Initialize();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.github.zehsteam.ExtractionPointConfirmButton";

		public const string PLUGIN_NAME = "ExtractionPointConfirmButton";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}
namespace com.github.zehsteam.ExtractionPointConfirmButton.Patches
{
	[HarmonyPatch(typeof(ExtractionPoint))]
	internal static class ExtractionPointPatch
	{
		private static readonly Dictionary<ExtractionPoint, float> _timeConfirms = new Dictionary<ExtractionPoint, float>();

		public static Dictionary<ExtractionPoint, ConfirmButton> ConfirmButtons { get; private set; } = new Dictionary<ExtractionPoint, ConfirmButton>();


		public static void Reset()
		{
			ConfirmButtons.Clear();
			_timeConfirms.Clear();
			Logger.LogInfo("ExtractionPointPatch: Reset();", extended: true);
		}

		public static void ConfirmExtractionPoint(ExtractionPoint extractionPoint)
		{
			if ((Object)(object)extractionPoint == (Object)null || extractionPoint.isShop)
			{
				return;
			}
			if (extractionPoint.haulGoal - extractionPoint.haulCurrent > 0)
			{
				if (extractionPoint.StateIs((State)2))
				{
					extractionPoint.StateSet((State)5);
				}
			}
			else
			{
				_timeConfirms[extractionPoint] = Time.realtimeSinceStartup;
			}
		}

		public static void AddConfirmButtonPair(ExtractionPoint extractionPoint, ConfirmButton confirmButton)
		{
			if (!((Object)(object)extractionPoint == (Object)null) && !((Object)(object)confirmButton == (Object)null))
			{
				ConfirmButtons[extractionPoint] = confirmButton;
			}
		}

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch(ref ExtractionPoint __instance)
		{
			SpawnConfirmButtonObject(__instance);
			UpdateConfirmButtonVisibility(__instance);
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePatch(ref ExtractionPoint __instance)
		{
			UpdateSuccessDelay(__instance);
		}

		[HarmonyPatch("StateSetRPC")]
		[HarmonyPostfix]
		private static void StateSetRPCPatch(ref ExtractionPoint __instance)
		{
			UpdateConfirmButtonVisibility(__instance);
		}

		private static void SpawnConfirmButtonObject(ExtractionPoint extractionPoint)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)extractionPoint == (Object)null || extractionPoint.isShop || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			Transform val = ((Component)extractionPoint).transform.Find("Scale");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogFatal("ExtractionPointPatch: Failed to spawn confirm button object. Target transform is null.");
				return;
			}
			GameObject confirmButtonPrefab = Assets.ConfirmButtonPrefab;
			Vector3 position = val.position;
			Quaternion rotation = val.rotation;
			if ((Object)(object)confirmButtonPrefab == (Object)null)
			{
				Logger.LogFatal("ExtractionPointPatch: Failed to spawn confirm button. Prefab is null.");
				return;
			}
			GameObject val2 = NetworkPrefabs.SpawnNetworkPrefab(((Object)confirmButtonPrefab).name, position, rotation, (byte)0, (object[])null);
			ConfirmButton confirmButton = default(ConfirmButton);
			if ((Object)(object)val2 == (Object)null)
			{
				Logger.LogFatal("ExtractionPointPatch: Failed to spawn confirm button. GameObject is null.");
			}
			else if (!val2.TryGetComponent<ConfirmButton>(ref confirmButton))
			{
				Logger.LogFatal("ExtractionPointPatch: Failed to spawn confirm button. ConfirmButton is null.");
			}
			else
			{
				confirmButton.SetExtractionPoint(extractionPoint);
			}
		}

		private static void UpdateSuccessDelay(ExtractionPoint extractionPoint)
		{
			if (!((Object)(object)extractionPoint == (Object)null) && !extractionPoint.isShop && HasConfirmButton(extractionPoint))
			{
				bool flag = true;
				if (_timeConfirms.TryGetValue(extractionPoint, out var value) && Time.realtimeSinceStartup - value <= 2f)
				{
					flag = false;
				}
				if (flag)
				{
					extractionPoint.successDelay = 1.5f;
				}
				else
				{
					extractionPoint.successDelay = 0f;
				}
			}
		}

		private static bool HasConfirmButton(ExtractionPoint extractionPoint)
		{
			if ((Object)(object)extractionPoint == (Object)null || extractionPoint.isShop)
			{
				return false;
			}
			if (ConfirmButtons.TryGetValue(extractionPoint, out var value))
			{
				if ((Object)(object)value == (Object)null)
				{
					return false;
				}
				return ((Component)value).gameObject.activeSelf;
			}
			return false;
		}

		private static void UpdateConfirmButtonVisibility(ExtractionPoint extractionPoint)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)extractionPoint == (Object)null) && !extractionPoint.isShop && ConfirmButtons.TryGetValue(extractionPoint, out var value) && !((Object)(object)value == (Object)null))
			{
				value.SetVisible(ShowConfirmButton(extractionPoint.stateSetTo));
			}
		}

		private static bool ShowConfirmButton(State state)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			if ((int)state == 1)
			{
				return false;
			}
			if ((int)state == 6)
			{
				return false;
			}
			if ((int)state == 9)
			{
				return false;
			}
			if ((int)state == 7)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(RunManager))]
	internal static class RunManagerPatch
	{
		[HarmonyPatch("UpdateLevel")]
		[HarmonyPostfix]
		private static void UpdateLevelPatch()
		{
			ExtractionPointPatch.Reset();
		}
	}
}
namespace com.github.zehsteam.ExtractionPointConfirmButton.MonoBehaviours
{
	public class ConfirmButton : MonoBehaviour
	{
		[SerializeField]
		private GameObject _objectObject;

		[SerializeField]
		private Transform _buttonVisualTransform;

		private bool _buttonAnimation;

		private float _buttonAnimationEval;

		private ExtractionPoint _extractionPoint;

		private PhotonView _photonView;

		private void Start()
		{
			_photonView = ((Component)this).GetComponent<PhotonView>();
			SyncExtractionPoint();
		}

		private void Update()
		{
			ButtonAnimation();
		}

		public void OnClick()
		{
			if (SemiFunc.IsMultiplayer())
			{
				_photonView.RPC("OnClickRPC", (RpcTarget)0, Array.Empty<object>());
			}
			else
			{
				OnClickRPC();
			}
		}

		public void SetExtractionPoint(ExtractionPoint extractionPoint)
		{
			_extractionPoint = extractionPoint;
			ExtractionPointPatch.AddConfirmButtonPair(extractionPoint, this);
			Logger.LogInfo("ConfirmButton: Set extraction point.");
		}

		public void SetVisible(bool value)
		{
			if (!((Object)(object)_objectObject == (Object)null))
			{
				_objectObject.SetActive(value);
			}
		}

		private void SyncExtractionPoint()
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				if ((Object)(object)_extractionPoint == (Object)null)
				{
					Logger.LogError("ConfirmButton: Failed to sync extraction point. ExtractionPoint is null.");
				}
				else if (SemiFunc.IsMultiplayer())
				{
					int viewID = _extractionPoint.photonView.ViewID;
					_photonView.RPC("SyncExtractionPointRPC", (RpcTarget)0, new object[1] { viewID });
				}
			}
		}

		[PunRPC]
		private void SyncExtractionPointRPC(int extractionPointViewID)
		{
			PhotonView photonView = PhotonNetwork.GetPhotonView(extractionPointViewID);
			if ((Object)(object)photonView == (Object)null)
			{
				Logger.LogError("ConfirmButton: Failed to set extraction point. PhotonView is null.");
				return;
			}
			ExtractionPoint extractionPoint = default(ExtractionPoint);
			if (!((Component)photonView).TryGetComponent<ExtractionPoint>(ref extractionPoint))
			{
				Logger.LogError("ConfirmButton: Failed to set extraction point. ExtractionPoint is null.");
				return;
			}
			_extractionPoint = extractionPoint;
			ExtractionPointPatch.AddConfirmButtonPair(extractionPoint, this);
			Logger.LogInfo($"ConfirmButton: Set extraction point. (ViewID: {extractionPointViewID})");
		}

		[PunRPC]
		private void OnClickRPC()
		{
			ButtonPushVisualsStart();
			ExtractionPointPatch.ConfirmExtractionPoint(_extractionPoint);
		}

		private void ButtonPushVisualsStart()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_extractionPoint == (Object)null) && !_buttonAnimation)
			{
				_buttonVisualTransform.localScale = new Vector3(1f, 0.1f, 1f);
				_extractionPoint.soundButton.Play(_buttonVisualTransform.position, 1f, 1f, 1f, 1f);
				_buttonAnimationEval = 0f;
				_buttonAnimation = true;
			}
		}

		private void ButtonAnimation()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_extractionPoint == (Object)null) && _buttonAnimation)
			{
				_buttonAnimationEval += Time.deltaTime * 2f;
				_buttonAnimationEval = Mathf.Clamp01(_buttonAnimationEval);
				float num = _extractionPoint.buttonPressAnimationCurve.Evaluate(_buttonAnimationEval);
				Color val = default(Color);
				((Color)(ref val))..ctor(1f, 0.5f, 0f, 1f);
				((Renderer)((Component)_buttonVisualTransform).GetComponent<MeshRenderer>()).material.SetColor("_EmissionColor", Color.Lerp(val, Color.white, num));
				num = Mathf.Clamp(num, 0.5f, 1f);
				_buttonVisualTransform.localScale = new Vector3(1f, num, 1f);
				if (_buttonAnimationEval >= 1f)
				{
					_buttonAnimation = false;
					_buttonAnimationEval = 0f;
				}
			}
		}
	}
}
namespace com.github.zehsteam.ExtractionPointConfirmButton.Extensions
{
	internal static class ConfigFileExtensions
	{
		public static ConfigEntry<T> Bind<T>(this ConfigFile configFile, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			return configFile.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, Array.Empty<object>()));
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}