Decompiled source of InteractableTruckDoor v0.3.3

InteractableTruckDoor.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using InteractableTruckDoor.NonPatch;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using TMPro;
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("InteractableTruckDoor")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+27789c612bbcc4c52c259996b4e2534718c334e5")]
[assembly: AssemblyProduct("InteractableTruckDoor")]
[assembly: AssemblyTitle("InteractableTruckDoor")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace InteractableTruckDoor
{
	[RequireComponent(typeof(PhotonView))]
	internal class AnimationHandler : MonoBehaviour
	{
		internal AnimationCurve curve;

		internal float eval = 1f;

		internal float startYPosition;

		internal float doorOpenSpeed = 1f;

		internal float doorCloseSpeed = 1f;

		internal float doorTimer;

		internal float doorTimerText = 0.3f;

		internal float doorCloseTime = 20f;

		internal TruckDoor TruckDoor;

		internal PhotonView ThisPhotonView;

		internal static AnimationHandler Instance { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			TruckDoor = ((Component)this).GetComponent<TruckDoor>();
			((Component)this).GetComponent<PhotonView>().ViewID = 387548396;
		}

		private void Start()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			curve = new AnimationCurve();
			curve.CopyFrom(TruckDoor.doorCurve);
			startYPosition = 5.4405f;
		}

		private void Update()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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)
			if (eval < 1f)
			{
				float num = curve.Evaluate(eval);
				eval += doorCloseSpeed * Time.deltaTime;
				((Component)this).transform.position = new Vector3(((Component)this).transform.position.x, startYPosition - 2.5f * num, ((Component)this).transform.position.z);
			}
			if (NonPatches.isDoorClosed && (SemiFunc.RunIsLevel() | SemiFunc.RunIsShop()))
			{
				if (doorTimer > 0f)
				{
					doorTimer = Mathf.Clamp(doorTimer - Time.deltaTime / doorCloseTime, 0f, 1f);
					doorTimerText = Mathf.Clamp(doorTimerText - Time.deltaTime / (doorCloseTime * 1.4f), 0f, 0.3f);
				}
				else if (doorTimer >= 0f)
				{
					ButtonControler.Instance.OnTimerRanOut();
				}
			}
			else if (doorTimer != 1f && !NonPatches.isDoorClosed && (SemiFunc.RunIsLevel() | SemiFunc.RunIsShop()))
			{
				doorTimer = Mathf.Clamp(doorTimer + Time.deltaTime / (doorCloseTime * 0.22f), 0f, 1f);
				doorTimerText = Mathf.Clamp(doorTimerText + Time.deltaTime / doorCloseTime, 0f, 1f);
			}
		}

		[PunRPC]
		private void OpenDoorNetworked()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			TruckDoor.doorEval = 0f;
			TruckDoor.doorLoopEnd.Play(((Component)this).transform.position, 1f, 1f, 1f, 1f);
			TruckDoor.doorSound.Play(((Component)this).transform.position, 1f, 1f, 1f, 1f);
		}

		[PunRPC]
		private void CloseDoorNetworked()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			eval = 0f;
			TruckDoor.doorLoopEnd.Play(((Component)this).transform.position, 1f, 1f, 1f, 1f);
			TruckDoor.doorSound.Play(((Component)this).transform.position, 1f, 1f, 1f, 1f);
		}

		internal void OpenDoor()
		{
			if (PhotonNetwork.IsConnected)
			{
				PhotonView val = PhotonView.Get((Component)(object)Instance);
				val.RPC("OpenDoorNetworked", (RpcTarget)0, Array.Empty<object>());
			}
			else if (!PhotonNetwork.IsConnected)
			{
				OpenDoorNetworked();
			}
		}

		internal void CloseDoor()
		{
			if (PhotonNetwork.IsConnected)
			{
				PhotonView val = PhotonView.Get((Component)(object)Instance);
				val.RPC("CloseDoorNetworked", (RpcTarget)0, Array.Empty<object>());
			}
			else if (!PhotonNetwork.IsConnected)
			{
				CloseDoorNetworked();
			}
		}
	}
	internal class ButtonControler : MonoBehaviour
	{
		private static bool didThrow;

		private bool _buttonAnimation;

		internal float _buttonAnimationEval;

		public Transform ButtonVisualTransform;

		internal ExtractionPoint _extractionPoint = Object.FindAnyObjectByType<ExtractionPoint>();

		public TextMeshProUGUI doorPowerText;

		public TextMeshProUGUI ITDMDCC_Version;

		internal static ButtonControler Instance { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			((TMP_Text)ITDMDCC_Version).text = "0.3.3";
		}

		private void Start()
		{
			((Component)((Component)Instance).gameObject.transform.GetChild(1)).GetComponent<PhotonView>().ViewID = PhotonView.Get((Component)(object)Instance).ViewID + 1;
			if (PhotonNetwork.IsConnected)
			{
				PhotonView val = PhotonView.Get((Component)(object)Instance);
				val.RPC("ResetDoor", (RpcTarget)0, Array.Empty<object>());
			}
			else if (!PhotonNetwork.IsConnected)
			{
				ResetDoor();
			}
			NonPatches.Instance.CheckForCorrectZ();
		}

		private void Update()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			ButtonAnimation();
			((TMP_Text)doorPowerText).text = $"{Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f)}%";
			if (Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 90 || Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 89)
			{
				((Graphic)doorPowerText).color = new Color(0.5f, 1f, 0f, 1f);
			}
			else if (Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 88 || Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 79)
			{
				((Graphic)doorPowerText).color = new Color(0.6666666f, 1f, 0f, 1f);
			}
			else if (Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 78 || Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 69)
			{
				((Graphic)doorPowerText).color = new Color(5f / 6f, 1f, 0f, 1f);
			}
			else if (Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 68 || Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 59)
			{
				((Graphic)doorPowerText).color = new Color(1f, 1f, 0f, 1f);
			}
			else if (Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 58 || Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 49)
			{
				((Graphic)doorPowerText).color = new Color(1f, 0.8333334f, 0f, 1f);
			}
			else if (Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 48 || Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 39)
			{
				((Graphic)doorPowerText).color = new Color(1f, 2f / 3f, 0f, 1f);
			}
			else if (Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 38 || Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 29)
			{
				((Graphic)doorPowerText).color = new Color(1f, 0.5f, 0f, 1f);
			}
			else if (Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 28 || Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 19)
			{
				((Graphic)doorPowerText).color = new Color(1f, 0.3333333f, 0f, 1f);
			}
			else if (Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 18 || Mathf.RoundToInt(AnimationHandler.Instance.doorTimer * 100f) >= 9)
			{
				((Graphic)doorPowerText).color = new Color(1f, 0.1666667f, 0f, 1f);
			}
			else
			{
				((Graphic)doorPowerText).color = new Color(1f, 0f, 0f, 1f);
			}
		}

		public void OnClick()
		{
			if (PhotonNetwork.IsConnected)
			{
				PhotonView val = PhotonView.Get((Component)(object)Instance);
				val.RPC("OnClickRPC", (RpcTarget)0, Array.Empty<object>());
			}
			else if (!PhotonNetwork.IsConnected)
			{
				OnClickRPC();
			}
		}

		public void OnTimerRanOut()
		{
			if (PhotonNetwork.IsConnected)
			{
				PhotonView val = PhotonView.Get((Component)(object)Instance);
				val.RPC("OnTimerRanOutNetworked", (RpcTarget)0, Array.Empty<object>());
			}
			else if (!PhotonNetwork.IsConnected)
			{
				OnTimerRanOutNetworked();
			}
		}

		[PunRPC]
		private void OnTimerRanOutNetworked()
		{
			if (!NonPatches.isDoorMoving && NonPatches.isDoorClosed)
			{
				if ((Object)(object)Instance != (Object)null)
				{
					((MonoBehaviour)this).StartCoroutine((IEnumerator)OpenDoorInternal());
				}
				else if (!didThrow)
				{
					InteractableTruckDoor.logger.LogError((object)"Coroutine 'OpenDoorInternal' could NOT be started! ButtonControler object does NOT exist! If this error was thrown while loading to another level then its fine.");
					didThrow = true;
				}
			}
		}

		[PunRPC]
		private void OnClickRPC()
		{
			ButtonPushVisualsStart();
			if (!NonPatches.isDoorMoving && !NonPatches.isDoorClosed)
			{
				((MonoBehaviour)this).StartCoroutine((IEnumerator)CloseDoorInternal());
			}
			else if (!NonPatches.isDoorMoving && NonPatches.isDoorClosed)
			{
				((MonoBehaviour)this).StartCoroutine((IEnumerator)OpenDoorInternal());
			}
		}

		private IEnumerator<WaitUntil> CloseDoorInternal()
		{
			NonPatches.isDoorMoving = true;
			AnimationHandler.Instance.CloseDoor();
			yield return new WaitUntil((Func<bool>)(() => AnimationHandler.Instance.eval >= 1f));
			NonPatches.isDoorClosed = true;
			NonPatches.isDoorMoving = false;
		}

		private IEnumerator<WaitUntil> OpenDoorInternal()
		{
			NonPatches.isDoorMoving = true;
			AnimationHandler.Instance.OpenDoor();
			yield return new WaitUntil((Func<bool>)(() => AnimationHandler.Instance.TruckDoor.doorEval >= 1f));
			NonPatches.isDoorClosed = false;
			NonPatches.isDoorMoving = false;
		}

		[PunRPC]
		private void ResetDoor()
		{
			NonPatches.isDoorMoving = false;
			NonPatches.isDoorClosed = false;
			didThrow = false;
		}

		private void ButtonAnimation()
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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;
				}
			}
		}

		private void ButtonPushVisualsStart()
		{
			//IL_0037: 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)
			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;
			}
		}
	}
	internal class ConfigManager
	{
		public ExtendedConfigEntry<bool> EnableConfiguration;

		public ExtendedConfigEntry<float> DoorCloseSpeed;

		public ExtendedConfigEntry<float> DoorOpenSpeed;

		public ConfigManager()
		{
			BindConfigs();
			ClearUnusedEntries();
		}

		private void BindConfigs()
		{
			EnableConfiguration = new ExtendedConfigEntry<bool>("General Settings", "EnableConfiguration", defaultValue: false, "Enable if you want to use custom set config setting values. If disabled, the default config setting values will be used.");
			DoorCloseSpeed = new ExtendedConfigEntry<float>("General Settings", "DoorCloseSpeed", 1.5f, "How fast will the truck door close", useEnableConfiguration: true);
			DoorOpenSpeed = new ExtendedConfigEntry<float>("General Settings", "DoorOpenSpeed", 1.5f, "How fast will the truck door open", useEnableConfiguration: true);
		}

		private void ClearUnusedEntries()
		{
			ConfigFile config = ((BaseUnityPlugin)InteractableTruckDoor.Instance).Config;
			PropertyInfo property = ((object)config).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(config, null);
			dictionary.Clear();
			config.Save();
		}
	}
	internal class Content
	{
		public static GameObject[] AssetsList;

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

		private static void LoadAssetsFromAssetBundle()
		{
			try
			{
				string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)InteractableTruckDoor.Instance).Info.Location);
				string text = Path.Combine(directoryName, "interactabletruckdoorassets");
				AssetBundle val = AssetBundle.LoadFromFile(text);
				AssetsList = val.LoadAllAssets<GameObject>();
				InteractableTruckDoor.logger.LogInfo((object)"Successfully loaded assets from AssetBundle!");
			}
			catch (Exception arg)
			{
				InteractableTruckDoor.logger.LogError((object)$"Error: failed to load assets from AssetBundle.\n\n{arg}");
			}
		}
	}
	public class ExtendedConfigEntry<T>
	{
		public ConfigEntry<T> ConfigEntry;

		public Func<T> GetValue;

		public Action<T> SetValue;

		public bool UseEnableConfiguration = false;

		public T DefaultValue => (T)((ConfigEntryBase)ConfigEntry).DefaultValue;

		public T Value
		{
			get
			{
				return GetValue();
			}
			set
			{
				SetValue(value);
			}
		}

		public ExtendedConfigEntry(string section, string key, T defaultValue, string description, bool useEnableConfiguration = false)
		{
			ConfigEntry = ((BaseUnityPlugin)InteractableTruckDoor.Instance).Config.Bind<T>(section, key, defaultValue, description);
			UseEnableConfiguration = useEnableConfiguration;
			Initialize();
		}

		public ExtendedConfigEntry(string section, string key, T defaultValue, ConfigDescription configDescription = null, bool useEnableConfiguration = false)
		{
			ConfigEntry = ((BaseUnityPlugin)InteractableTruckDoor.Instance).Config.Bind<T>(section, key, defaultValue, configDescription);
			UseEnableConfiguration = useEnableConfiguration;
			Initialize();
		}

		private void Initialize()
		{
			if (GetValue == null)
			{
				GetValue = () => (UseEnableConfiguration && !InteractableTruckDoor.ConfigManager.EnableConfiguration.Value) ? DefaultValue : ConfigEntry.Value;
			}
			if (SetValue == null)
			{
				SetValue = delegate(T value)
				{
					ConfigEntry.Value = value;
				};
			}
		}

		public void ResetToDefault()
		{
			ConfigEntry.Value = (T)((ConfigEntryBase)ConfigEntry).DefaultValue;
		}
	}
	[BepInProcess("REPO.exe")]
	[BepInPlugin("InteractableTruckDoor-UnloadedHangar", "InteractableTruckDoor", "0.3.3")]
	public class InteractableTruckDoor : BaseUnityPlugin
	{
		public static class PluginInfo
		{
			public const string Guid = "InteractableTruckDoor-UnloadedHangar";

			public const string Name = "InteractableTruckDoor";

			public const string Ver = "0.3.3";
		}

		internal static ManualLogSource logger;

		internal static InteractableTruckDoor Instance;

		internal static ConfigManager ConfigManager;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = Logger.CreateLogSource("InteractableTruckDoor-UnloadedHangar");
			logger.LogInfo((object)"InteractableTruckDoor-UnloadedHangar loaded");
			ConfigManager = new ConfigManager();
			Content.Load();
			_harmony = new Harmony("InteractableTruckDoor-UnloadedHangar");
			_harmony.PatchAll();
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public struct SafeHSV
	{
		public static Color HSVToRGBSafe(float H, float S, float V, bool hdr = true)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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)
			if (H > 1f || S > 1f || V > 1f)
			{
				InteractableTruckDoor.logger.LogError((object)("Provided data inside method '" + MethodBase.GetCurrentMethod().Name + "' are out of range!"));
			}
			return Color.HSVToRGB(Mathf.Clamp(H, 0f, 1f), Mathf.Clamp(S, 0f, 1f), Mathf.Clamp(V, 0f, 1f), hdr);
		}
	}
}
namespace InteractableTruckDoor.Patch
{
	[HarmonyPatch]
	internal class Patches : MonoBehaviour
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(SemiFunc), "OnLevelGenDone")]
		private static void SpawnButton()
		{
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.RunIsLevel())
			{
				if (((Object)Object.FindObjectOfType<StartRoom>()).name == "Start Room - Manor - Small Room(Clone)")
				{
					GameObject val = Object.Instantiate<GameObject>(Content.AssetsList[0], new Vector3(3f, 0.655f, -13.5217f), Content.AssetsList[0].transform.rotation, ((Component)((Component)TruckScreenText.instance).gameObject.transform.parent).transform);
					PhotonView componentInChildren = val.gameObject.GetComponentInChildren<PhotonView>(true);
					componentInChildren.ViewID = 756454;
				}
				else if (((Object)Object.FindObjectOfType<StartRoom>()).name == "Module - Minecraft - Start(Clone)")
				{
					GameObject val2 = Object.Instantiate<GameObject>(Content.AssetsList[0], new Vector3(3f, 0.655f, -19.7219f), Content.AssetsList[0].transform.rotation, ((Component)((Component)TruckScreenText.instance).gameObject.transform.parent).transform);
					PhotonView componentInChildren2 = val2.gameObject.GetComponentInChildren<PhotonView>(true);
					componentInChildren2.ViewID = 756454;
				}
				else
				{
					GameObject val3 = Object.Instantiate<GameObject>(Content.AssetsList[0], new Vector3(3f, 0.655f, -15.8217f), Content.AssetsList[0].transform.rotation, ((Component)((Component)TruckScreenText.instance).gameObject.transform.parent).transform);
					PhotonView componentInChildren3 = val3.gameObject.GetComponentInChildren<PhotonView>(true);
					componentInChildren3.ViewID = 756454;
				}
			}
			else if (SemiFunc.RunIsShop())
			{
				GameObject val4 = Object.Instantiate<GameObject>(Content.AssetsList[0], new Vector3(3f, 0.655f, -5.8217f), Content.AssetsList[0].transform.rotation, ((Component)((Component)TruckScreenText.instance).gameObject.transform.parent).transform);
				PhotonView componentInChildren4 = val4.gameObject.GetComponentInChildren<PhotonView>(true);
				componentInChildren4.ViewID = 756454;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(TruckDoor), "Start")]
		private static void AssignComponent()
		{
			((Component)Object.FindObjectOfType<TruckDoor>()).gameObject.AddComponent<AnimationHandler>();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameDirector), "Start")]
		private static void ObjectSpawnPatch()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			GameObject val = new GameObject("InteractableTruckDoorHelper");
			val.AddComponent<NonPatches>();
			val.AddComponent<PhotonView>().ViewID = 780546346;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SemiFunc), "OnLevelGenDone")]
		private static void OnLevelGenDonePatch()
		{
			try
			{
				NonPatches.Instance.Sync();
			}
			catch (Exception ex)
			{
				InteractableTruckDoor.logger.LogError((object)ex);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(TruckDoor), "Update")]
		private static bool UpdatePatch(TruckDoor __instance)
		{
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.timeToCheck)
			{
				if (__instance.playerInTruckCheckTimer > 0f)
				{
					__instance.playerInTruckCheckTimer -= Time.deltaTime;
				}
				else
				{
					__instance.playerInTruckCheckTimer = 0.5f;
					if (!__instance.introActivationDone && !SemiFunc.PlayersAllInTruck())
					{
						__instance.introActivationDone = true;
						if (!TutorialDirector.instance.tutorialActive)
						{
							__instance.extractionPointNearest.ActivateTheFirstExtractionPointAutomaticallyWhenAPlayerLeaveTruck();
						}
					}
				}
			}
			if (__instance.doorDelay > 0f && SemiFunc.LevelGenDone())
			{
				__instance.doorDelay -= Time.deltaTime;
			}
			if (__instance.doorDelay <= 0f && __instance.doorEval < 1f)
			{
				if (!__instance.doorOpen)
				{
					__instance.doorOpen = true;
					if (SemiFunc.RunIsShop())
					{
						SemiFunc.UIFocusText("Buy stuff in the shop", Color.white, AssetManager.instance.colorYellow, 3f);
					}
					GameDirector.instance.CameraImpact.ShakeDistance(3f, 3f, 8f, ((Component)__instance).transform.position, 0.1f);
					__instance.doorLoopStart.Play(((Component)__instance).transform.position, 1f, 1f, 1f, 1f);
				}
				float num = __instance.doorCurve.Evaluate(__instance.doorEval);
				__instance.doorEval += AnimationHandler.Instance.doorOpenSpeed * Time.deltaTime;
				((Component)__instance).transform.position = new Vector3(((Component)__instance).transform.position.x, __instance.startYPosition + 2.5f * num, ((Component)__instance).transform.position.z);
			}
			if (__instance.doorEval >= 1f && !__instance.fullyOpen)
			{
				__instance.fullyOpen = true;
				GameDirector.instance.CameraImpact.ShakeDistance(5f, 3f, 8f, ((Component)__instance).transform.position, 0.1f);
				__instance.doorLoopEnd.Play(((Component)__instance).transform.position, 1f, 1f, 1f, 1f);
				__instance.doorSound.Play(((Component)__instance).transform.position, 1f, 1f, 1f, 1f);
			}
			return false;
		}
	}
}
namespace InteractableTruckDoor.NonPatch
{
	public class NonPatches : MonoBehaviour
	{
		internal static bool isDoorClosed;

		internal static bool isDoorMoving;

		private bool hasRan = false;

		public static NonPatches Instance { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
		}

		internal void Sync()
		{
			if (PhotonNetwork.IsConnected && PhotonNetwork.IsMasterClient && (SemiFunc.RunIsLevel() | SemiFunc.RunIsShop()))
			{
				PhotonView val = PhotonView.Get((Component)(object)Instance);
				val.RPC("SendDataToClients", (RpcTarget)0, new object[2]
				{
					InteractableTruckDoor.ConfigManager.DoorOpenSpeed.Value,
					InteractableTruckDoor.ConfigManager.DoorCloseSpeed.Value
				});
			}
			else if (!PhotonNetwork.IsConnected && (SemiFunc.RunIsLevel() | SemiFunc.RunIsShop()))
			{
				SendDataToClients(InteractableTruckDoor.ConfigManager.DoorOpenSpeed.Value, InteractableTruckDoor.ConfigManager.DoorCloseSpeed.Value);
			}
		}

		[PunRPC]
		private void SendDataToClients(float doorOpenSpeedInternal, float doorCloseSpeedInternal)
		{
			AnimationHandler.Instance.doorOpenSpeed = Mathf.Clamp(doorOpenSpeedInternal, 0.1f, 10f);
			AnimationHandler.Instance.doorCloseSpeed = Mathf.Clamp(doorCloseSpeedInternal, 0.1f, 10f);
			InteractableTruckDoor.logger.LogInfo((object)$"Received data from MasterClient! Data -> DoorOpenSpeed: {Mathf.Clamp(doorOpenSpeedInternal, 0.1f, 10f)}, DoorCloseSpeed: {Mathf.Clamp(doorCloseSpeedInternal, 0.1f, 10f)}");
		}

		internal void CheckForCorrectZ()
		{
			try
			{
				if (!SemiFunc.RunIsLevel() && SemiFunc.RunIsShop())
				{
					if (PerformCalculation() != 0.2863016f)
					{
						InteractableTruckDoor.logger.LogWarning((object)"Calculation error! Truck door console is at the wrong position!");
					}
					else
					{
						InteractableTruckDoor.logger.LogInfo((object)"Calculation successful! No action required.");
					}
				}
			}
			catch (Exception ex)
			{
				InteractableTruckDoor.logger.LogError((object)ex);
			}
			static float PerformCalculation()
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: 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_009d: Unknown result type (might be due to invalid IL or missing references)
				if (SemiFunc.RunIsLevel())
				{
					return ((Component)ButtonControler.Instance).gameObject.transform.position.z - ((Component)((Component)((Component)TruckScreenText.instance).gameObject.transform.parent).transform.GetChild(1)).transform.position.z;
				}
				if (SemiFunc.RunIsShop())
				{
					return ((Component)ButtonControler.Instance).gameObject.transform.position.z - ((Component)((Component)((Component)TruckScreenText.instance).gameObject.transform.parent).transform.GetChild(0)).transform.position.z;
				}
				return 0f;
			}
		}
	}
}