Decompiled source of Beanie Lib v1.0.2

LethalGravityControl.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 LethalLevelLoader;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;

[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("LethalGravityControl")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Project1")]
[assembly: AssemblyTitle("LethalGravityControl")]
[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.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;
		}
	}
	[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;
		}
	}
}
public class BreakerBoxCustom : NetworkBehaviour
{
	[Header("Breaker Settings")]
	public int leversSwitchedOff = 2;

	public bool isPowerOn = false;

	[Header("References")]
	public Animator[] breakerSwitches;

	public AudioSource thisAudioSource;

	public AudioSource breakerBoxHum;

	public AudioClip switchPowerSFX;

	[Header("Events")]
	public UnityEvent onBreakerActivated;

	public UnityEvent onBreakerDeactivated;

	private void Start()
	{
		isPowerOn = false;
		SetSwitchesOff();
		if ((Object)(object)breakerBoxHum != (Object)null && breakerBoxHum.isPlaying)
		{
			breakerBoxHum.Stop();
		}
	}

	public void SetSwitchesOff()
	{
		int num = Mathf.Clamp(leversSwitchedOff, 0, breakerSwitches.Length);
		leversSwitchedOff = 0;
		Random random = new Random(StartOfRound.Instance.randomMapSeed);
		HashSet<int> hashSet = new HashSet<int>();
		while (hashSet.Count < num && hashSet.Count < breakerSwitches.Length)
		{
			int num2 = random.Next(0, breakerSwitches.Length);
			if (!hashSet.Contains(num2))
			{
				hashSet.Add(num2);
				AnimatedObjectTrigger component = ((Component)breakerSwitches[num2]).GetComponent<AnimatedObjectTrigger>();
				if (component.boolValue)
				{
					breakerSwitches[num2].SetBool("turnedLeft", false);
					component.boolValue = false;
					component.setInitialState = false;
					leversSwitchedOff++;
				}
			}
		}
	}

	public void SwitchBreaker(bool on)
	{
		if (on)
		{
			leversSwitchedOff--;
		}
		else
		{
			leversSwitchedOff++;
		}
		if (((NetworkBehaviour)this).IsServer)
		{
			if (leversSwitchedOff <= 0 && !isPowerOn)
			{
				isPowerOn = true;
				UnityEvent obj = onBreakerActivated;
				if (obj != null)
				{
					obj.Invoke();
				}
				if ((Object)(object)thisAudioSource != (Object)null && (Object)(object)switchPowerSFX != (Object)null)
				{
					thisAudioSource.PlayOneShot(switchPowerSFX);
				}
			}
			else if (leversSwitchedOff > 0 && isPowerOn)
			{
				isPowerOn = false;
				UnityEvent obj2 = onBreakerDeactivated;
				if (obj2 != null)
				{
					obj2.Invoke();
				}
				if ((Object)(object)thisAudioSource != (Object)null && (Object)(object)switchPowerSFX != (Object)null)
				{
					thisAudioSource.PlayOneShot(switchPowerSFX);
				}
			}
		}
		if (leversSwitchedOff <= 0)
		{
			if (!breakerBoxHum.isPlaying)
			{
				breakerBoxHum.Play();
			}
		}
		else if (leversSwitchedOff == 1)
		{
			breakerBoxHum.Stop();
		}
	}
}
[Serializable]
public class ThresholdEvent
{
	public int threshold = 1;

	public UnityEvent OnThresholdReached = new UnityEvent();

	[HideInInspector]
	public bool triggered = false;
}
public class TriggerCounter : MonoBehaviour
{
	public ThresholdEvent[] thresholds;

	public UnityEvent OnResetCounter = new UnityEvent();

	public UnityEvent OnTurnOffCounter = new UnityEvent();

	private int currentCount = 0;

	private bool isActive = true;

	public void IncreaseCount()
	{
		if (!isActive)
		{
			return;
		}
		currentCount++;
		ThresholdEvent[] array = thresholds;
		foreach (ThresholdEvent thresholdEvent in array)
		{
			if (!thresholdEvent.triggered && currentCount >= thresholdEvent.threshold)
			{
				thresholdEvent.triggered = true;
				thresholdEvent.OnThresholdReached.Invoke();
			}
		}
	}

	public void ResetCounter()
	{
		currentCount = 0;
		ThresholdEvent[] array = thresholds;
		foreach (ThresholdEvent thresholdEvent in array)
		{
			thresholdEvent.triggered = false;
		}
		isActive = true;
	}

	public void TurnOffCounter()
	{
		isActive = false;
	}

	private void Awake()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		OnResetCounter.AddListener(new UnityAction(ResetCounter));
		OnTurnOffCounter.AddListener(new UnityAction(TurnOffCounter));
	}
}
namespace Project1
{
	[BepInPlugin("LethalGravityControl", "Project1", "1.0.0")]
	public class Project1 : BaseUnityPlugin
	{
		public static Project1 Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			Logger.LogInfo((object)"LethalGravityControl v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("LethalGravityControl");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LethalGravityControl";

		public const string PLUGIN_NAME = "Project1";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace Project1.Patches
{
	public class XTextureReplaceBasedOnTags : MonoBehaviour
	{
		public MaterialsWithNames[] materialsWithNames = Array.Empty<MaterialsWithNames>();

		public Renderer renderer => ((Component)this).GetComponent<Renderer>();

		public void Start()
		{
			foreach (ContentTag contentTag in ((ExtendedContent)LevelManager.CurrentExtendedLevel).ContentTags)
			{
				ReplaceTextureBasedOnTagName(contentTag.contentTagName);
			}
		}

		public void ReplaceTextureBasedOnTagName(string contentTagName)
		{
			MaterialsWithNames[] array = this.materialsWithNames;
			foreach (MaterialsWithNames materialsWithNames in array)
			{
				if (materialsWithNames.contentTagNames.Contains(contentTagName))
				{
					renderer.SetMaterials(materialsWithNames.materials);
					break;
				}
			}
		}
	}
	[Serializable]
	public class MaterialsWithNames
	{
		public List<Material> materials = new List<Material>();

		public string[] contentTagNames = Array.Empty<string>();
	}
}
namespace MyProject.Signals
{
	public static class SignalHub
	{
		private static Dictionary<string, List<SignalReceiverHub>> receiversByWordID = new Dictionary<string, List<SignalReceiverHub>>();

		public static void Register(string wordID, SignalReceiverHub receiver)
		{
			if (!((Object)(object)receiver == (Object)null))
			{
				if (!receiversByWordID.TryGetValue(wordID, out List<SignalReceiverHub> value))
				{
					value = new List<SignalReceiverHub>();
					receiversByWordID[wordID] = value;
				}
				if (!value.Contains(receiver))
				{
					value.Add(receiver);
				}
			}
		}

		public static void Unregister(string wordID, SignalReceiverHub receiver)
		{
			if (!((Object)(object)receiver == (Object)null) && receiversByWordID.TryGetValue(wordID, out List<SignalReceiverHub> value))
			{
				value.Remove(receiver);
				if (value.Count == 0)
				{
					receiversByWordID.Remove(wordID);
				}
			}
		}

		public static void Send(string wordID)
		{
			if (!receiversByWordID.TryGetValue(wordID, out List<SignalReceiverHub> value))
			{
				return;
			}
			List<SignalReceiverHub> list = new List<SignalReceiverHub>(value);
			foreach (SignalReceiverHub item in list)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.ReceiveSignal();
				}
				else
				{
					value.Remove(item);
				}
			}
			if (value.Count == 0)
			{
				receiversByWordID.Remove(wordID);
			}
		}
	}
	public class SignalSenderHub : MonoBehaviour
	{
		public string wordID;

		public UnityEvent onSend;

		public void SendSignal()
		{
			SignalHub.Send(wordID);
			UnityEvent obj = onSend;
			if (obj != null)
			{
				obj.Invoke();
			}
		}
	}
	public class SignalReceiverHub : MonoBehaviour
	{
		public string wordID;

		public UnityEvent onReceive;

		private void OnEnable()
		{
			SignalHub.Register(wordID, this);
		}

		private void OnDisable()
		{
			SignalHub.Unregister(wordID, this);
		}

		public void ReceiveSignal()
		{
			UnityEvent obj = onReceive;
			if (obj != null)
			{
				obj.Invoke();
			}
		}
	}
}