Decompiled source of 17 Ignaris v1.0.0

IgnarisScripts.dll

Decompiled a day 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 BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using IgnarisScripts.NetcodePatcher;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[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: AssemblyVersion("0.0.0.0")]
[module: NetcodePatchedAssembly]
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 IgnarisScripts
{
	public class OxygenManager : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <AddOxygenAfterDelay>d__12 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public OxygenManager <>4__this;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>4__this.OxygenCoolDown = true;
					<>2__current = (object)new WaitForSeconds(0.5f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.Oxygen++;
					<>4__this.OxygenCoolDown = false;
					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();
			}
		}

		[CompilerGenerated]
		private sealed class <DamagePlayerAfterDelay>d__13 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public OxygenManager <>4__this;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Expected O, but got Unknown
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>4__this.DamageCoolDown = true;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					StartOfRound.Instance.localPlayerController.DamagePlayer(20, true, true, (CauseOfDeath)9, 0, false, default(Vector3));
					<>4__this.DamageCoolDown = false;
					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();
			}
		}

		[CompilerGenerated]
		private sealed class <RemoveOxygenAfterDelay>d__11 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public OxygenManager <>4__this;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Expected O, but got Unknown
				//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fa: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>4__this.OxygenCoolDown = true;
					<>2__current = (object)new WaitForSeconds(0.5f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.Oxygen--;
					<>4__this.OxygenCoolDown = false;
					if (!<>4__this.IsBreathing)
					{
						<>4__this.IsBreathing = true;
						HUDManager.Instance.UIAudio.PlayOneShot(<>4__this.BreathingSound);
						if (<>4__this.Oxygen == 10)
						{
							HUDManager.Instance.UIAudio.PlayOneShot(StartOfRound.Instance.HUDSystemAlertSFX);
						}
						<>2__current = (object)new WaitForSeconds(5f);
						<>1__state = 2;
						return true;
					}
					break;
				case 2:
					<>1__state = -1;
					<>4__this.IsBreathing = false;
					break;
				}
				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 GameObject OxygenHud;

		public AudioClip BreathingSound;

		private bool IsBreathing = false;

		private bool DamageCoolDown = false;

		private bool OxygenCoolDown = false;

		public static OxygenManager Instance;

		private int Oxygen = 100;

		private bool IsOxygen = false;

		public void Awake()
		{
			Instance = this;
			Plugin.Instance.InstantiatedOxygenHud = Object.Instantiate<GameObject>(OxygenHud, HUDManager.Instance.HUDContainer.transform);
		}

		public void SetOxygen(bool set)
		{
			if (set)
			{
				((Component)Plugin.Instance.InstantiatedOxygenHud.transform.Find("Container")).gameObject.SetActive(true);
				Debug.Log((object)$"Disabled Clock {HUDManager.Instance.Clock.canvasGroup.alpha} + Enabled oxygen ui");
				IsOxygen = true;
			}
			else if (!set)
			{
				((Component)Plugin.Instance.InstantiatedOxygenHud.transform.Find("Container")).gameObject.SetActive(false);
				Debug.Log((object)$"Enabled Clock {HUDManager.Instance.Clock.canvasGroup.alpha} + Disabled oxygen ui");
				IsOxygen = false;
			}
		}

		private void Update()
		{
			if (IsOxygen && !StartOfRound.Instance.localPlayerController.isPlayerDead)
			{
				((TMP_Text)((Component)Plugin.Instance.InstantiatedOxygenHud.transform.Find("Container/OxygenNumber")).gameObject.GetComponent<TextMeshProUGUI>()).text = $"{Oxygen}%";
				HUDManager.Instance.Clock.canvasGroup.alpha = 0f;
				if (!OxygenCoolDown && Oxygen > 0)
				{
					((MonoBehaviour)this).StartCoroutine(RemoveOxygenAfterDelay());
				}
				if (Oxygen <= 0 && !DamageCoolDown)
				{
					((MonoBehaviour)this).StartCoroutine(DamagePlayerAfterDelay());
				}
			}
			else if (!IsOxygen && !StartOfRound.Instance.localPlayerController.isPlayerDead)
			{
				((TMP_Text)((Component)Plugin.Instance.InstantiatedOxygenHud.transform.Find("Container/OxygenNumber")).gameObject.GetComponent<TextMeshProUGUI>()).text = $"{Oxygen}%";
				if (!OxygenCoolDown && Oxygen < 100)
				{
					((MonoBehaviour)this).StartCoroutine(AddOxygenAfterDelay());
				}
				if (Oxygen <= 0 && !DamageCoolDown)
				{
					((MonoBehaviour)this).StartCoroutine(DamagePlayerAfterDelay());
				}
			}
			else if (StartOfRound.Instance.localPlayerController.isPlayerDead)
			{
				SetOxygen(set: false);
				Debug.Log((object)"Player Died");
			}
		}

		[IteratorStateMachine(typeof(<RemoveOxygenAfterDelay>d__11))]
		public IEnumerator RemoveOxygenAfterDelay()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <RemoveOxygenAfterDelay>d__11(0)
			{
				<>4__this = this
			};
		}

		[IteratorStateMachine(typeof(<AddOxygenAfterDelay>d__12))]
		public IEnumerator AddOxygenAfterDelay()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <AddOxygenAfterDelay>d__12(0)
			{
				<>4__this = this
			};
		}

		[IteratorStateMachine(typeof(<DamagePlayerAfterDelay>d__13))]
		public IEnumerator DamagePlayerAfterDelay()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DamagePlayerAfterDelay>d__13(0)
			{
				<>4__this = this
			};
		}

		private void OnDestroy()
		{
			Debug.Log((object)"Destroyed OxygenManager");
			Object.Destroy((Object)(object)Plugin.Instance.InstantiatedOxygenHud);
			Plugin.Instance.InstantiatedOxygenHud = null;
		}
	}
	public class OxygenTrigger : MonoBehaviour
	{
		private Collider trigger;

		private bool isInside;

		private void Awake()
		{
			trigger = ((Component)this).GetComponent<Collider>();
			trigger.isTrigger = true;
		}

		private void FixedUpdate()
		{
			bool flag = IsLocalPlayerBodyInside();
			if (flag != isInside)
			{
				isInside = flag;
				OxygenManager.Instance.SetOxygen(isInside);
			}
		}

		private bool IsLocalPlayerBodyInside()
		{
			//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_0053: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
			if (localPlayerController.isPlayerDead || (Object)(object)localPlayerController == (Object)null)
			{
				return false;
			}
			Collider component = ((Component)localPlayerController.thisPlayerBody).GetComponent<Collider>();
			if ((Object)(object)component == (Object)null)
			{
				return false;
			}
			Bounds bounds = trigger.bounds;
			return ((Bounds)(ref bounds)).Intersects(component.bounds);
		}

		private void OnDisable()
		{
			if (isInside)
			{
				isInside = false;
				OxygenManager.Instance.SetOxygen(set: false);
			}
		}
	}
	[BepInPlugin("WaterGun.IgnarisScripts", "IgnarisScripts", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string GUID = "WaterGun.IgnarisScripts";

		private const string NAME = "IgnarisScripts";

		private const string VER = "1.0.0";

		public static Plugin Instance;

		public GameObject InstantiatedOxygenHud;

		private void Awake()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			Instance = this;
			Harmony val = new Harmony("WaterGun.IgnarisScripts");
			val.PatchAll();
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace IgnarisScripts.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}