Decompiled source of GlowScream v1.0.0

BepInEx/plugins/glowscream.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Dissonance;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;

[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("glowscream")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("glowscream")]
[assembly: AssemblyTitle("glowscream")]
[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;
		}
	}
}
namespace glowscream
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "glowscream";

		public const string PLUGIN_NAME = "glowscream";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace glowscreamfix
{
	[BepInPlugin("glowscream", "glowscream", "1.0.0")]
	public class glowscreamfix : BaseUnityPlugin
	{
		public static bool found;

		public static PlayerControllerB knownplayer;

		public static Transform currentlight;

		public static float lightIntensity;

		public static bool madelamp;

		public static glowscreamfix 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)"glowscream 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("glowscream");
			}
			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 class makelamp
	{
		public static void lampspawn()
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			Item[] array = Resources.FindObjectsOfTypeAll<Item>();
			foreach (Item val in array)
			{
				if (((Object)val).name.ToLower() == "fancy lamp" || ((Object)val).name.ToLower() == "fancylamp")
				{
					Transform currentlight = Object.Instantiate<Transform>(val.spawnPrefab.transform.Find("light"), ((Component)glowscreamfix.knownplayer).transform.position + ((Component)glowscreamfix.knownplayer).transform.up * 1.28f, ((Component)glowscreamfix.knownplayer).transform.rotation, ((Component)glowscreamfix.knownplayer.thisController).transform);
					glowscreamfix.currentlight = currentlight;
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	public class PlayerConnection
	{
		[HarmonyPatch("ConnectClientToPlayerObject")]
		[HarmonyPostfix]
		public static void findplayer(PlayerControllerB __instance)
		{
			if (!glowscreamfix.found)
			{
				glowscreamfix.knownplayer = __instance;
				glowscreamfix.found = true;
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class PlayerDisconnection
	{
		[HarmonyPatch("OnLocalDisconnect")]
		[HarmonyPostfix]
		public static void removeplayer()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			if (glowscreamfix.found)
			{
				glowscreamfix.currentlight = new Transform();
				glowscreamfix.knownplayer = new PlayerControllerB();
				glowscreamfix.found = false;
				glowscreamfix.madelamp = false;
			}
		}
	}
}
namespace glowscreamfix.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class lightUpdatePatch
	{
		internal Dictionary<string, GameObject> ObjectCache = new Dictionary<string, GameObject>();

		private static bool volumeLeniency;

		private static float Speed;

		private static float RangeSpeed;

		private static float timer;

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void Update(PlayerControllerB __instance)
		{
			if ((!IngamePlayerSettings.Instance.settings.micEnabled || IngamePlayerSettings.Instance.settings.pushToTalk || StartOfRound.Instance.voiceChatModule == null) | ((Object)(object)__instance != (Object)(object)glowscreamfix.knownplayer))
			{
				return;
			}
			if (!glowscreamfix.madelamp)
			{
				makelamp.lampspawn();
				glowscreamfix.madelamp = true;
			}
			VoicePlayerState val = StartOfRound.Instance.voiceChatModule.FindPlayer(StartOfRound.Instance.voiceChatModule.LocalPlayerName);
			float num = Mathf.Clamp(val.Amplitude * 35f, 0f, 2f);
			if (num >= 0.9f)
			{
				timer = 0f;
				volumeLeniency = true;
				float num2 = (num * 20f - Speed) * 225f;
				float num3 = (num * 20f - Speed) * 50f;
				Speed += num2 / 60f * Time.deltaTime;
				RangeSpeed += num3 / 30f * Time.deltaTime;
				((Component)glowscreamfix.currentlight).GetComponent<HDAdditionalLightData>().intensity = Speed * 50f;
				((Component)glowscreamfix.currentlight).GetComponent<HDAdditionalLightData>().range = RangeSpeed;
				((Component)glowscreamfix.currentlight).GetComponent<HDAdditionalLightData>().shadowNearPlane = 2f;
				return;
			}
			if (volumeLeniency && num >= 0.75f)
			{
				timer = 0f;
				float num4 = (num * 20f - Speed) * 225f;
				float num5 = (num * 20f - Speed) * 50f;
				Speed += num4 / 60f * Time.deltaTime;
				RangeSpeed += num5 / 30f * Time.deltaTime;
				((Component)glowscreamfix.currentlight).GetComponent<HDAdditionalLightData>().intensity = Speed * 50f;
				((Component)glowscreamfix.currentlight).GetComponent<HDAdditionalLightData>().range = RangeSpeed;
				((Component)glowscreamfix.currentlight).GetComponent<HDAdditionalLightData>().shadowNearPlane = 2f;
				return;
			}
			timer += Time.deltaTime;
			if (!(timer <= 0.075f))
			{
				volumeLeniency = false;
				float num6 = (0f - Speed) * 225f;
				float num7 = (0f - Speed) * 50f;
				Speed += num6 / 60f * Time.deltaTime;
				RangeSpeed += num7 / 30f * Time.deltaTime;
				glowscreamfix.lightIntensity = Mathf.MoveTowards(glowscreamfix.lightIntensity, Speed, 300f * Time.deltaTime);
				((Component)glowscreamfix.currentlight).GetComponent<HDAdditionalLightData>().intensity = Speed * 50f;
				((Component)glowscreamfix.currentlight).GetComponent<HDAdditionalLightData>().range = RangeSpeed;
				((Component)glowscreamfix.currentlight).GetComponent<HDAdditionalLightData>().shadowNearPlane = 2f;
			}
		}
	}
}
namespace glowscreamfix.Util
{
	public static class UtilExtensions
	{
		public static float MoveTowards(this float source, float target, float delta)
		{
			if (target > source)
			{
				return Mathf.Min(target, source + delta);
			}
			if (target < source)
			{
				return Mathf.Max(target, source - delta);
			}
			return source;
		}

		public static Transform FindComponentInChildren(this Transform transform, string name)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			foreach (Transform item in transform)
			{
				Transform val = item;
				if (((Object)val).name == name)
				{
					return val;
				}
				Transform val2 = val.FindComponentInChildren(name);
				if (val2 != null)
				{
					return val2;
				}
			}
			return null;
		}
	}
}