Decompiled source of HyperionStation v0.2.0

HyperionStation.dll

Decompiled a week 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 LethalLevelLoader;
using Microsoft.CodeAnalysis;
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: AssemblyCompany("HyperionStation")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HyperionStation")]
[assembly: AssemblyTitle("HyperionStation")]
[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 HyperionStation
{
	public static class Common
	{
		public static bool CollideWithPlayer(Collider collider_obj)
		{
			if (((Component)collider_obj).tag == "Player")
			{
				return true;
			}
			GameObject gameObject = ((Component)collider_obj).gameObject;
			while ((Object)(object)gameObject != (Object)null)
			{
				if (gameObject.tag == "Player")
				{
					return true;
				}
				if ((Object)(object)gameObject.transform.parent == (Object)null)
				{
					return false;
				}
				gameObject = ((Component)gameObject.transform.parent).gameObject;
			}
			return false;
		}

		public static bool CollideWithEnemy(Collider collider_obj)
		{
			if (((Component)collider_obj).tag == "Enemy")
			{
				return true;
			}
			GameObject gameObject = ((Component)collider_obj).gameObject;
			while ((Object)(object)gameObject != (Object)null)
			{
				if (gameObject.tag == "Enemy")
				{
					return true;
				}
				if ((Object)(object)gameObject.transform.parent == (Object)null)
				{
					return false;
				}
				gameObject = ((Component)gameObject.transform.parent).gameObject;
			}
			return false;
		}
	}
	[Serializable]
	public class dotATSequence
	{
		public int totalFrames = 0;

		public int firstFrame = 0;

		public int startingFrame = 0;

		public bool randomly = false;
	}
	[ExecuteInEditMode]
	public class DotAnimatedTexture : MonoBehaviour
	{
		public int materialTotalFrames;

		public int activeSequence = 0;

		public List<dotATSequence> sequences;

		public float FPS = 10f;

		public bool showWarnings = false;

		private Renderer _renderer = null;

		private int materialTileRows = 0;

		private int materialTileCols = 0;

		private int prevIndex = -1;

		private void Start()
		{
			Init();
		}

		private void Init()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_renderer == (Object)null)
			{
				_renderer = ((Component)this).GetComponent<Renderer>();
			}
			Material val = (((Object)(object)_renderer == (Object)null) ? null : _renderer.sharedMaterial);
			if ((Object)(object)val == (Object)null)
			{
				materialTileRows = (materialTileCols = 0);
				return;
			}
			Vector2 mainTextureScale = val.mainTextureScale;
			materialTileRows = ((!(mainTextureScale.y > 0f)) ? 1 : Mathf.RoundToInt(1f / mainTextureScale.y));
			materialTileCols = ((!(mainTextureScale.x > 0f)) ? 1 : Mathf.RoundToInt(1f / mainTextureScale.x));
		}

		private void Update()
		{
			ForceUpdate(force: false);
		}

		public void ForceUpdate(bool force = true)
		{
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			bool isPlaying = Application.isPlaying;
			if (!isPlaying)
			{
				Init();
			}
			materialTotalFrames = materialTileRows * materialTileCols;
			if (materialTotalFrames == 0 || sequences == null || activeSequence + 1 > sequences.Count)
			{
				return;
			}
			int totalFrames = sequences[activeSequence].totalFrames;
			int startingFrame = sequences[activeSequence].startingFrame;
			int firstFrame = sequences[activeSequence].firstFrame;
			bool randomly = sequences[activeSequence].randomly;
			if (totalFrames == 0 || totalFrames + firstFrame > materialTileCols * materialTileRows || (Object)(object)_renderer == (Object)null)
			{
				return;
			}
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(1f / (float)materialTileCols, 1f / (float)materialTileRows);
			int num;
			if (isPlaying)
			{
				num = ((int)(Time.time * FPS) + startingFrame) % totalFrames;
			}
			else
			{
				num = startingFrame % totalFrames;
				Vector2 mainTextureScale = _renderer.sharedMaterial.mainTextureScale;
				int num2 = 0;
				if (mainTextureScale.x * mainTextureScale.y != 0f)
				{
					num2 = Mathf.RoundToInt(1f / (mainTextureScale.x * mainTextureScale.y));
				}
				materialTotalFrames = num2;
			}
			if (firstFrame + num != prevIndex)
			{
				prevIndex = firstFrame + num;
				if (randomly && isPlaying)
				{
					num = Mathf.RoundToInt(Random.value * (float)(totalFrames - 1));
				}
				num += firstFrame;
				Vector2 mainTextureOffset = default(Vector2);
				((Vector2)(ref mainTextureOffset))..ctor((float)(num % materialTileCols) * val.x, 1f - val.y - (float)(num / materialTileCols) * val.y);
				if (isPlaying)
				{
					_renderer.material.mainTextureOffset = mainTextureOffset;
				}
			}
		}
	}
	public enum dotHskDoorStats
	{
		none = 0,
		closed = 1,
		broken = 2,
		off = 4,
		blocked = 8
	}
	public enum dotHskDoorMode
	{
		active = 1,
		activeOpen = 0,
		blocked = 9,
		brokenOpen = 6,
		brokenClosed = 7,
		inactiveOpen = 4,
		inactiveClosed = 5
	}
	[ExecuteInEditMode]
	public class DotHskDoor : MonoBehaviour
	{
		public dotHskDoorMode mode = dotHskDoorMode.active;

		public DotHskDoorSlider doorScript;

		private dotHskDoorMode prevMode = dotHskDoorMode.active;

		private bool first = true;

		private void Update()
		{
			if ((Object)(object)doorScript != (Object)null && (prevMode != mode || first))
			{
				if (doorScript.setMode(mode, first))
				{
					prevMode = mode;
				}
				else
				{
					mode = prevMode;
				}
				first = false;
			}
		}
	}
	public class DotHskDoorBase : DotHskDoorsEventsClass
	{
		[Header("Sounds")]
		public AudioSource audioSource;

		public AudioClip openSound;

		public AudioClip closeSound;

		public AudioClip blockedSound;

		[Header("Lights")]
		public Color blockedColor = new Color(1f, 0f, 0f);

		public Color activeColor = new Color(0f, 1f, 4f / 85f);

		public Light[] lights;

		[Header("Glass")]
		public Renderer doorGlass = null;

		public Material glassOn = null;

		public Material glassBlocked = null;

		public Material glassOff = null;

		private float[] soundLen = new float[3];

		public void Start()
		{
			if ((Object)(object)closeSound != (Object)null)
			{
				soundLen[0] = closeSound.length;
			}
			if ((Object)(object)openSound != (Object)null)
			{
				soundLen[2] = openSound.length;
			}
		}

		public override void OnStartMotion(float fromPos, int dir)
		{
			if ((Object)(object)audioSource != (Object)null && soundLen[dir + 1] > 0f)
			{
				audioSource.clip = ((dir == 1) ? openSound : closeSound);
				audioSource.time = ((fromPos == 0f) ? 0f : ((dir == 1) ? fromPos : (1f - fromPos)));
				audioSource.Play();
			}
		}

		public override void OnBlock()
		{
			if ((Object)(object)audioSource != (Object)null && (Object)(object)blockedSound != (Object)null)
			{
				audioSource.clip = blockedSound;
				audioSource.time = 0f;
				audioSource.Play();
			}
		}

		public override void OnChangeMode(bool isOff, bool isBlocked)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)doorGlass != (Object)null)
			{
				if (isOff)
				{
					doorGlass.sharedMaterial = glassOff;
				}
				else if (isBlocked)
				{
					doorGlass.sharedMaterial = glassBlocked;
				}
				else
				{
					doorGlass.sharedMaterial = glassOn;
				}
			}
			if (lights.Length != 0)
			{
				for (int i = 0; i < lights.Length; i++)
				{
					lights[i].color = (Color)(isOff ? new Color(0f, 0f, 0f) : (isBlocked ? blockedColor : activeColor));
					((Behaviour)lights[i]).enabled = !isOff;
				}
			}
		}

		public override void OnInit()
		{
		}

		public override void OnStop()
		{
		}
	}
	public class DotHskDoorBeep : MonoBehaviour
	{
		public AudioSource audioSource;

		public AudioClip beepSound;

		private void OnTriggerEnter(Collider other)
		{
			if (Common.CollideWithPlayer(other) && (Object)(object)audioSource != (Object)null && (Object)(object)beepSound != (Object)null)
			{
				audioSource.clip = beepSound;
				audioSource.time = 0f;
				audioSource.Play();
			}
			if (Common.CollideWithEnemy(other) && (Object)(object)audioSource != (Object)null && (Object)(object)beepSound != (Object)null)
			{
				audioSource.clip = beepSound;
				audioSource.time = 0f;
				audioSource.Play();
			}
		}
	}
	[Serializable]
	public class dotHskDoorFlap
	{
		public Vector3 openPos = default(Vector3);

		public Vector3 closedPos = default(Vector3);

		public Vector3 almostOpenPos = default(Vector3);

		public Vector3 almostClosedPos = default(Vector3);

		public Transform flap;
	}
	public abstract class DotHskDoorsEventsClass : MonoBehaviour
	{
		[HideInInspector]
		public DotHskDoorSlider door;

		public abstract void OnInit();

		public abstract void OnStartMotion(float fromPos, int dir);

		public abstract void OnChangeMode(bool isOff, bool isBlocked);

		public abstract void OnBlock();

		public abstract void OnStop();
	}
	[ExecuteInEditMode]
	public class DotHskDoorSlider : MonoBehaviour
	{
		public List<dotHskDoorFlap> doorFlaps;

		public float motionTime = 1f;

		[HideInInspector]
		public DotHskDoorsEventsClass doorEvents;

		private int dir = 0;

		public float curPos = 0f;

		private float targetPos = 0f;

		private bool isOff = false;

		private bool isBlocked = false;

		public bool getIsFullyOpen()
		{
			return curPos == 1f;
		}

		public bool getIsFullyClosed()
		{
			return curPos == 0f;
		}

		public bool getIsStopped()
		{
			return dir == 0;
		}

		private void Start()
		{
			Init();
		}

		private void Update()
		{
			if (Application.isPlaying)
			{
				if (dir != 0)
				{
					float num = curPos + (float)dir * ((motionTime == 0f) ? 1f : (1f / motionTime)) * Time.deltaTime;
					if ((float)dir * (targetPos - num) < 0.01f)
					{
						num = targetPos;
						dir = 0;
					}
					moveTo(num);
					if ((Object)(object)doorEvents != (Object)null && dir == 0)
					{
						doorEvents.OnStop();
					}
				}
			}
			else
			{
				Init();
			}
		}

		private void Init()
		{
			if ((Object)(object)doorEvents == (Object)null)
			{
				doorEvents = ((Component)this).GetComponent<DotHskDoorsEventsClass>();
				if ((Object)(object)doorEvents != (Object)null)
				{
					doorEvents.door = this;
					doorEvents.OnInit();
				}
			}
		}

		private void moveTo(float newPos)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (newPos != curPos)
			{
				for (int i = 0; i < doorFlaps.Count; i++)
				{
					doorFlaps[i].flap.localPosition = Vector3.Lerp(doorFlaps[i].closedPos, doorFlaps[i].openPos, newPos);
				}
				curPos = newPos;
			}
		}

		public bool setMode(dotHskDoorMode mode, bool isInit)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			bool flag = (mode & dotHskDoorMode.active) != 0;
			isOff = (mode & dotHskDoorMode.inactiveOpen) != 0;
			isBlocked = (mode & (dotHskDoorMode)8) != 0;
			if ((Object)(object)doorEvents != (Object)null)
			{
				doorEvents.OnChangeMode(isOff, isBlocked);
			}
			if ((mode & (dotHskDoorMode)2) != 0)
			{
				for (int i = 0; i < doorFlaps.Count; i++)
				{
					Vector3 val2 = (doorFlaps[i].flap.localPosition = (flag ? doorFlaps[i].almostClosedPos : doorFlaps[i].almostOpenPos));
					Vector3 val3 = val2;
					float magnitude = ((Vector3)(ref doorFlaps[i].openPos)).magnitude;
					curPos = ((magnitude == 0f) ? 0f : (((Vector3)(ref val3)).magnitude / magnitude));
				}
				dir = 0;
			}
			else
			{
				float num = (targetPos = (flag ? 0f : 1f));
				if (Application.isPlaying && num != curPos && !isInit)
				{
					dir = ((num > curPos) ? 1 : (-1));
					if ((Object)(object)doorEvents != (Object)null)
					{
						doorEvents.OnStartMotion(curPos, dir);
					}
				}
				else
				{
					dir = 0;
					moveTo(num);
				}
			}
			return true;
		}

		public void operate(bool open)
		{
			if (isOff)
			{
				return;
			}
			if (isBlocked)
			{
				if ((Object)(object)doorEvents != (Object)null && open)
				{
					doorEvents.OnBlock();
				}
				return;
			}
			float num = (open ? 1f : 0f);
			if (targetPos != num)
			{
				dir = ((curPos < (targetPos = num)) ? 1 : (-1));
				if ((Object)(object)doorEvents != (Object)null)
				{
					doorEvents.OnStartMotion(curPos, dir);
				}
			}
		}

		private void OnTriggerEnter(Collider other)
		{
			if (Common.CollideWithPlayer(other))
			{
				operate(open: true);
			}
			if (Common.CollideWithEnemy(other))
			{
				operate(open: true);
			}
		}

		private void OnTriggerExit(Collider other)
		{
			if (Common.CollideWithPlayer(other))
			{
				operate(open: false);
			}
			if (Common.CollideWithEnemy(other))
			{
				operate(open: false);
			}
		}
	}
	[BepInPlugin("Tolian.HyperionStation", "Hyperion Station", "0.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "Tolian.HyperionStation";

		public const string NAME = "Hyperion Station";

		public const string VERSION = "0.0.1";

		private void Awake()
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(directoryName, "hyperionstation"));
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load Interior Dungeon assets.");
				return;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Interior Assets loaded successfully");
			ExtendedDungeonFlow val2 = val.LoadAsset<ExtendedDungeonFlow>("Assets/LethalCompany/Mods/HyperStation/LLL/HyperionStationFlow.asset");
			PatchedContent.RegisterExtendedDungeonFlow(val2);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Extended DungeonFlow");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "HyperionStation";

		public const string PLUGIN_NAME = "HyperionStation";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}