Decompiled source of ExtractionPointConfirmButton v1.0.0

com.github.zehsteam.ExtractionPointConfirmButton.dll

Decompiled 12 hours 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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
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: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+95e8e9c66d15a5200e4e6da19c3fd482401ce5de")]
[assembly: AssemblyProduct("ExtractionPointConfirmButton")]
[assembly: AssemblyTitle("com.github.zehsteam.ExtractionPointConfirmButton")]
[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 com.github.zehsteam.ExtractionPointConfirmButton
{
	internal static class Assets
	{
		public static GameObject ConfirmButtonObjectPrefab { get; private set; }

		public static void Load()
		{
			LoadAssetsFromAssetBundle();
		}

		private static void LoadAssetsFromAssetBundle()
		{
			AssetBundle val = LoadAssetBundle("extractionpointconfirmbutton_assets");
			if (!((Object)(object)val == (Object)null))
			{
				ConfirmButtonObjectPrefab = LoadAssetFromAssetBundle<GameObject>("ConfirmButtonObject", val);
				Plugin.Logger.LogInfo((object)"Successfully loaded assets from AssetBundle!");
			}
		}

		private static AssetBundle LoadAssetBundle(string fileName)
		{
			try
			{
				string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location);
				string text = Path.Combine(directoryName, fileName);
				return AssetBundle.LoadFromFile(text);
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Failed to load AssetBundle \"{fileName}\". {arg}");
			}
			return null;
		}

		private static T LoadAssetFromAssetBundle<T>(string name, AssetBundle assetBundle) where T : Object
		{
			if (string.IsNullOrWhiteSpace(name))
			{
				Plugin.Logger.LogError((object)("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)
			{
				Plugin.Logger.LogError((object)("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)
			{
				Plugin.Logger.LogError((object)("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;
		}
	}
	[BepInPlugin("com.github.zehsteam.ExtractionPointConfirmButton", "ExtractionPointConfirmButton", "1.0.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; }

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Logger = Logger.CreateLogSource("com.github.zehsteam.ExtractionPointConfirmButton");
			Logger.LogInfo((object)"ExtractionPointConfirmButton has awoken!");
			_harmony.PatchAll(typeof(RunManagerPatch));
			_harmony.PatchAll(typeof(ExtractionPointPatch));
			Assets.Load();
			NetworkPrefabs.RegisterNetworkPrefab(Assets.ConfirmButtonObjectPrefab);
		}
	}
	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.0.0";
	}
}
namespace com.github.zehsteam.ExtractionPointConfirmButton.Patches
{
	[HarmonyPatch(typeof(ExtractionPoint))]
	internal static class ExtractionPointPatch
	{
		private static readonly Dictionary<ExtractionPoint, float> _timeSinceConfirms = new Dictionary<ExtractionPoint, float>();

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


		public static void Reset()
		{
			ConfirmButtons.Clear();
			_timeSinceConfirms.Clear();
		}

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

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

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

		[HarmonyPatch("StateSetRPC")]
		[HarmonyPostfix]
		private static void StateSetRPCPatch(ref ExtractionPoint __instance, ref State state)
		{
			if (SemiFunc.IsMasterClientOrSingleplayer() && (int)state == 6 && ConfirmButtons.TryGetValue(__instance, out var value))
			{
				if (SemiFunc.IsMultiplayer())
				{
					PhotonNetwork.Destroy(((Component)value).gameObject);
				}
				else
				{
					Object.Destroy((Object)(object)((Component)value).gameObject);
				}
			}
		}

		private static void SpawnConfirmButtonObject(ExtractionPoint extractionPoint)
		{
			//IL_0042: 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)
			//IL_0049: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.IsMasterClientOrSingleplayer() || extractionPoint.isShop)
			{
				return;
			}
			Transform val = ((Component)extractionPoint).transform.Find("Scale");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to spawn confirm button object. Target transform is null.");
				return;
			}
			GameObject confirmButtonObjectPrefab = Assets.ConfirmButtonObjectPrefab;
			Vector3 position = val.position;
			Quaternion rotation = val.rotation;
			GameObject val2 = ((!SemiFunc.IsMultiplayer()) ? Object.Instantiate<GameObject>(confirmButtonObjectPrefab, position, rotation) : PhotonNetwork.InstantiateRoomObject(((Object)confirmButtonObjectPrefab).name, position, rotation, (byte)0, (object[])null));
			ConfirmButton component = val2.GetComponent<ConfirmButton>();
			if (SemiFunc.IsMultiplayer())
			{
				component.SetExtractionPointRPC(extractionPoint.photonView.ViewID);
			}
			else
			{
				component.SetExtractionPoint(extractionPoint);
			}
			ConfirmButtons.Add(extractionPoint, component);
		}

		private static void UpdateSuccessDelay(ExtractionPoint extractionPoint)
		{
			if (!extractionPoint.isShop && ConfirmButtons.ContainsKey(extractionPoint))
			{
				bool flag = true;
				if (_timeSinceConfirms.TryGetValue(extractionPoint, out var value) && Time.realtimeSinceStartup - value <= 2f)
				{
					flag = false;
				}
				if (flag)
				{
					extractionPoint.successDelay = 1.5f;
				}
				else
				{
					extractionPoint.successDelay = 0f;
				}
			}
		}
	}
	[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
	{
		public Transform ButtonVisualTransform;

		private bool _buttonAnimation;

		private float _buttonAnimationEval;

		private ExtractionPoint _extractionPoint;

		private void Update()
		{
			ButtonAnimation();
		}

		public void OnClick()
		{
			OnClickRPC();
		}

		[PunRPC]
		public void SetExtractionPointRPC(int viewID)
		{
			PhotonView photonView = PhotonNetwork.GetPhotonView(viewID);
			if ((Object)(object)photonView == (Object)null)
			{
				Plugin.Logger.LogError((object)"ConfirmButton: failed to set extraction point. PhotonView is null.");
				return;
			}
			ExtractionPoint extractionPoint = default(ExtractionPoint);
			if (!((Component)photonView).TryGetComponent<ExtractionPoint>(ref extractionPoint))
			{
				Plugin.Logger.LogError((object)"ConfirmButton: failed to set extraction point. ExtractionPoint is null.");
				return;
			}
			_extractionPoint = extractionPoint;
			Plugin.Logger.LogInfo((object)$"ConfirmButton: set extraction point. (ViewID: {viewID})");
		}

		public void SetExtractionPoint(ExtractionPoint extractionPoint)
		{
			_extractionPoint = extractionPoint;
			Plugin.Logger.LogInfo((object)"ConfirmButton: set extraction point.");
		}

		[PunRPC]
		private void OnClickRPC()
		{
			Plugin.Logger.LogInfo((object)"Confirm button clicked!");
			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 System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}