Decompiled source of WhimsicalWeather v1.0.0

BepInEx/plugins/WhimsicalWeather.dll

Decompiled 10 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DigitalRuby.ThunderAndLightning;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.UI;
using WhimsicalWeather.Behaviours;
using WhimsicalWeather.Controllers;
using WhimsicalWeather.Models;
using WhimsicalWeather.Patches;
using WhimsicalWeather.Visuals;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("WhimsicalWeather")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("WhimsicalWeather")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WhimsicalWeather")]
[assembly: AssemblyTitle("WhimsicalWeather")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace WhimsicalWeather
{
	public class Config
	{
		public static Config Instance;

		public ConfigEntry<bool> RainbowUI { get; set; }

		public ConfigEntry<float> RainbowUIHueShiftSpeed { get; set; }

		public ConfigEntry<bool> ChangePlayerPitch { get; set; }

		public ConfigEntry<float> PlayerPitchMultiplier { get; set; }

		public ConfigEntry<bool> RemovePlayerBlood { get; set; }

		public ConfigEntry<bool> FearLaughing { get; set; }

		public ConfigEntry<bool> ChangeShipHornPitch { get; set; }

		public ConfigEntry<float> ShipHornPitch { get; set; }

		public ConfigEntry<float> ShipHornStartPitch { get; set; }

		public ConfigEntry<bool> LollypopMeleeWeapons { get; set; }

		public ConfigEntry<bool> RainbowZapGun { get; set; }

		public ConfigEntry<bool> RainbowApparatus { get; set; }

		public ConfigEntry<bool> ClearMagnifyingGlass { get; set; }

		public ConfigEntry<bool> GooglyEyeDogs { get; set; }

		public ConfigEntry<bool> JesterHat { get; set; }

		public ConfigEntry<bool> RainbowBlob { get; set; }

		public ConfigEntry<bool> RainbowItemDropship { get; set; }

		public ConfigEntry<bool> DeveloperToggle { get; set; }

		public Config(ConfigFile cfg)
		{
			RainbowUI = cfg.Bind<bool>("Modifications", "RainbowUI", true, "Make the UI cycle through rainbow colors when using whimsical vision");
			RainbowUIHueShiftSpeed = cfg.Bind<float>("Modifications", "RainbowUISpeed", 1f, "How fast to cycle the UI's colors when using whimsical vision. Does nothing if Rainbow UI is disabled");
			ChangePlayerPitch = cfg.Bind<bool>("Modifications.Player", "ChangePlayerPitch", true, "Pitch up the voice chat of other players when using whimsical vision");
			PlayerPitchMultiplier = cfg.Bind<float>("Modifications.Player", "PlayerPitchMultiplier", 1.3f, "The amount player voice chat pitch is multiplied when using whimsical vision. Does nothing if Change Player Pitch is disabled");
			RemovePlayerBlood = cfg.Bind<bool>("Modifications.Player", "RemovePlayerBlood", true, "Remove all player blood when using whimsical vision");
			FearLaughing = cfg.Bind<bool>("Modifications.Player", "FearLaughing", true, "Have the player laugh to themselves when fear is high using whimsical vision");
			ChangeShipHornPitch = cfg.Bind<bool>("Modifications.Ship", "ChangeShipHornPitch", true, "Pitch up the ship's loud horn when using whimsical vision");
			ShipHornPitch = cfg.Bind<float>("Modifications.Ship", "ShipHornMaximumPitch", 1.3f, "The maximum pitch of the ship's loud horn when using whimsical vision. Does nothing if Change Ship Horn Pitch is disabled");
			ShipHornStartPitch = cfg.Bind<float>("Modifications.Ship", "ShipHornMinimumPitch", 1.25f, "The minimum/starting pitch of the ship's loud horn when using whimsical vision. Does nothing if Change Ship Horn Pitch is disabled");
			LollypopMeleeWeapons = cfg.Bind<bool>("Modifications.Items", "LollypopMeleeWeapons", true, "Replace melee weapons (Shovel, Stop Sign, Yield Sign) with lollypops when using whimsical vision");
			RainbowZapGun = cfg.Bind<bool>("Modifications.Items", "RainbowZapGun", true, "Make the zap gun's color rainbow over time when using whimsical vision");
			RainbowApparatus = cfg.Bind<bool>("Modifications.Items", "RainbowApparatus", true, "Make the apparatus's color rainbow over time when using whimsical vision");
			ClearMagnifyingGlass = cfg.Bind<bool>("Modifications.Items", "MagnifyingGlassShowsReality", true, "Make the magnifying glass show a clear picture of reality when using whimsical vision");
			GooglyEyeDogs = cfg.Bind<bool>("Modifications.Enemies", "GooglyEyeDogs", true, "Adds googly eyes to eyeless dogs when using whimsical vision");
			JesterHat = cfg.Bind<bool>("Modifications.Enemies", "JesterHat", true, "Adds a jester hat to the jester's final form when using whimsical vision");
			RainbowBlob = cfg.Bind<bool>("Modifications.Enemies", "RainbowBlob", true, "Make the Hygrodere's color rainbow over time when using whimsical vision");
			RainbowItemDropship = cfg.Bind<bool>("Modifications.World", "RainbowItemDropship", true, "Adds rainbow christmas lights to the item dropship when using whimsical vision");
			DeveloperToggle = cfg.Bind<bool>("Other.Development", "ManualWhimsicalVisionToggle", false, "Allows you to press F10 to manually enable/disable whimsical vision. Do NOT enable this unless you know what you're doing");
			Instance = this;
		}
	}
	[BepInPlugin("WhimsicalWeather", "WhimsicalWeather", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Logger;

		public static Material PassMaterial;

		public static Shader RainbowTextShader;

		public static Shader RainbowUIShader;

		public static Shader RainbowLerpShader;

		public static Shader RainbowParticleShader;

		public static Shader RainbowDropshipLightsShader;

		public static GameObject SparkParticles;

		public static GameObject Rainbow;

		public static GameObject GooglyEyes;

		public static GameObject JesterHat;

		public static GameObject RedLollypop;

		public static GameObject GrayLollypop;

		public static GameObject YellowLollypop;

		public static GameObject VisualsObject;

		public static GameObjectActivityBehaviour WeatherEvents;

		private static Shader? _litShader;

		private WhimsicalVisuals _visuals;

		private void Awake()
		{
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin WhimsicalWeather is loaded!");
			new Config(((BaseUnityPlugin)this).Config);
			_litShader = Shader.Find("HDRP/Lit");
			VisualsObject = GetVisuals();
			PassMaterial = GetPrefabMaterialFromName("PassShader");
			RainbowTextShader = GetPrefabMaterialFromName("TextShader").shader;
			RainbowUIShader = GetPrefabMaterialFromName("UIShader").shader;
			RainbowLerpShader = GetPrefabMaterialFromName("SmoothShader").shader;
			RainbowParticleShader = GetPrefabMaterialFromName("ParticleShader").shader;
			RainbowDropshipLightsShader = GetPrefabMaterialFromName("DropshipLightsShader").shader;
			SparkParticles = GetModelPrefabFromName("Sparticles");
			Rainbow = GetModelPrefabFromName("rainbow");
			GooglyEyes = GetModelPrefabFromName("GooglyEyeHolder");
			JesterHat = GetModelPrefabFromName("JesterHat");
			RedLollypop = GetModelPrefabFromName("Lollypop");
			GrayLollypop = GetModelPrefabFromName("GrayLollypop");
			YellowLollypop = GetModelPrefabFromName("YellowLollypop");
			ReplaceShadersWithLit(GooglyEyes);
			ReplaceShadersWithLit(JesterHat);
			ReplaceShadersWithLit(RedLollypop);
			ReplaceShadersWithLit(GrayLollypop);
			ReplaceShadersWithLit(YellowLollypop);
			InitializeTransparentMaterial(RedLollypop, "LollypopTransparent");
			InitializeTransparentMaterial(GrayLollypop, "GrayLollypopTransparent");
			InitializeTransparentMaterial(YellowLollypop, "YellowLollypopTransparent");
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			GameObject val = new GameObject("WhimsicalVisuals");
			((Object)val).hideFlags = (HideFlags)61;
			_visuals = val.AddComponent<WhimsicalVisuals>();
			_visuals.SetAudio(((Component)VisualsObject.transform.Find("SparkleAudio")).GetComponent<AudioSource>().clip);
			RegisterWeather(val);
		}

		private void RegisterWeather(GameObject visualsObject)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0043: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			GameObject val = new GameObject("WhimsicalVisualsVisualsDummy");
			((Object)val).hideFlags = (HideFlags)61;
			GameObject val2 = new GameObject("WhimsicalVisualsPermanentObject");
			((Object)val2).hideFlags = (HideFlags)61;
			WeatherEvents = val2.AddComponent<GameObjectActivityBehaviour>();
			val2.SetActive(false);
			WeatherEvents.EventsEnabled = true;
			WeatherEffect val3 = new WeatherEffect
			{
				name = "<color=#FF00FF>Whimsical</color>",
				effectObject = val,
				effectPermanentObject = val2,
				lerpPosition = false,
				sunAnimatorBool = "",
				transitioning = false
			};
			Weathers.RegisterWeather("<color=#FF00FF>Whimsical</color>", val3, (LevelTypes)(-1), 0, 0);
		}

		private GameObject GetVisuals()
		{
			return AssetBundle.LoadFromFile(Path.Join((ReadOnlySpan<char>)Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), (ReadOnlySpan<char>)"visualsobject")).LoadAsset<GameObject>("assets/visualsobject.prefab");
		}

		private Material GetPrefabMaterialFromName(string name)
		{
			return ((Renderer)((Component)VisualsObject.transform.Find(name)).GetComponent<MeshRenderer>()).sharedMaterial;
		}

		private GameObject GetModelPrefabFromName(string name)
		{
			return ((Component)VisualsObject.transform.Find("Models/" + name)).gameObject;
		}

		public static void ReplaceShadersWithLit(GameObject gameObject)
		{
			if ((Object)(object)_litShader == (Object)null)
			{
				Logger.LogWarning((object)"Cannot find HDRP/Lit");
				return;
			}
			foreach (Material item in gameObject.GetComponentsInChildren<Renderer>(true).SelectMany((Renderer x) => x.sharedMaterials).ToList())
			{
				item.shader = _litShader;
			}
		}

		public static void InitializeTransparentMaterial(GameObject gameObject, string materialName)
		{
			foreach (Material item in gameObject.GetComponentsInChildren<Renderer>(true).SelectMany((Renderer x) => x.sharedMaterials).ToList())
			{
				if (!(((Object)item).name != materialName))
				{
					item.renderQueue = 3000;
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "WhimsicalWeather";

		public const string PLUGIN_NAME = "WhimsicalWeather";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace WhimsicalWeather.Visuals
{
	public class WhimsicalVisuals : MonoBehaviour
	{
		private const float _animationLength = 4f;

		public static bool WhimsicalVisualsEnabled;

		private bool _enabled;

		private GameObject? _sparkles;

		private GameObject? _rainbow;

		private AudioClip _sparkleAudio;

		private bool _animating;

		private bool _reversedAnimation;

		private float _animationProgress;

		private CustomPassVolume? _customPassVolume;

		private ReplacementController _replacementController = new ReplacementController();

		public static event Action OnVisualsEnabled;

		public static event Action OnVisualsDisabled;

		private void Awake()
		{
			List<TextureReplacementBehaviour> textureReplacements = Plugin.VisualsObject.GetComponentsInChildren<TextureReplacementBehaviour>(true).ToList();
			List<SoundReplacementBehaviour> soundReplacements = Plugin.VisualsObject.GetComponentsInChildren<SoundReplacementBehaviour>(true).ToList();
			_replacementController.CreateTextureReplacements(textureReplacements);
			_replacementController.CreateSoundReplacements(soundReplacements);
			_replacementController.CreateImageShaderReplacements();
			AudioPatches.SetReplacementController(_replacementController);
			OnVisualsEnabled += Enable;
			OnVisualsDisabled += Disable;
		}

		private void OnDestroy()
		{
			OnVisualsEnabled -= Enable;
			OnVisualsDisabled -= Disable;
		}

		private void Update()
		{
			if (Config.Instance.DeveloperToggle.Value && UnityInput.Current.GetKeyDown((KeyCode)291))
			{
				ToggleVisualsEvent(!_enabled);
			}
			if (_animating)
			{
				SetEffectPercentage(Mathf.Clamp01(_reversedAnimation ? (1f - _animationProgress / 4f) : (_animationProgress / 4f)));
				if (_animationProgress >= 4f)
				{
					_animating = false;
					if ((Object)(object)_sparkles != (Object)null)
					{
						_sparkles.GetComponent<ParticleSystem>().Stop();
					}
					if (!_reversedAnimation)
					{
						ReplaceVisuals();
					}
					else
					{
						DisableAfterAnimation();
					}
				}
				_animationProgress += Time.deltaTime;
			}
			_ = (Object)(object)SoundManager.Instance == (Object)null;
		}

		public static void ToggleVisualsEvent(bool enabled)
		{
			if (enabled)
			{
				WhimsicalVisuals.OnVisualsEnabled?.Invoke();
			}
			else
			{
				WhimsicalVisuals.OnVisualsDisabled?.Invoke();
			}
		}

		private void ReplaceVisuals()
		{
			_replacementController.ReplaceAll();
			WalkieTalkiePatches.SetWalkieLightIntensity(0.1f);
			ShovelPatches.ReplaceAllShovels();
		}

		private void UnreplaceVisuals()
		{
			if ((Object)(object)_rainbow != (Object)null)
			{
				_rainbow.SetActive(false);
			}
			_replacementController.UnreplaceAll();
			WalkieTalkiePatches.SetWalkieLightIntensity(0.4843846f);
			ShovelPatches.RestoreAllShovels();
		}

		public void SetAudio(AudioClip sparkleAudio)
		{
			_sparkleAudio = sparkleAudio;
		}

		public void Enable()
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Logger.LogInfo((object)"Enabling WhimsicalVisuals.");
			_enabled = true;
			WhimsicalVisualsEnabled = true;
			PlayerControllerB val = StartOfRound.Instance?.localPlayerController;
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			FullScreenCustomPass customPass = GetCustomPass(val.gameplayCamera);
			if (customPass != null)
			{
				if ((Object)(object)_sparkles == (Object)null)
				{
					_sparkles = Object.Instantiate<GameObject>(Plugin.SparkParticles);
					_sparkles.transform.SetParent(((Component)val.gameplayCamera).transform, false);
					_sparkles.transform.localPosition = new Vector3(0f, 0f, 0.5f);
					_sparkles.transform.localRotation = Quaternion.identity;
					_sparkles.transform.localScale = Vector3.one;
				}
				if ((Object)(object)_rainbow == (Object)null)
				{
					_rainbow = Object.Instantiate<GameObject>(Plugin.Rainbow);
					_rainbow.transform.localPosition = new Vector3(0f, 0f, 0f);
					_rainbow.transform.localRotation = Quaternion.identity;
					_rainbow.transform.localScale = new Vector3(300f, 300f, 300f);
				}
				if ((Object)(object)HUDManager.Instance != (Object)null)
				{
					HUDManager.Instance.DisplayTip("Photosensitivity alert!", "<size=16px>You've landed in <color=#FF00FF>Whimsical</color> weather.\nThis mod features flashing lights that may potentially trigger seizures for people with epilepsy.", true, true, "LC_PhotosensitiveTip");
				}
				_sparkles.SetActive(true);
				_rainbow.SetActive(true);
				PlaySparkleAudio();
				SetEffectPercentage(0f);
				_animating = true;
				_reversedAnimation = false;
				_animationProgress = 0f;
				((CustomPass)customPass).enabled = true;
			}
		}

		public void Disable()
		{
			Plugin.Logger.LogInfo((object)"Disabling WhimsicalVisuals.");
			_enabled = false;
			WhimsicalVisualsEnabled = false;
			if ((Object)(object)_sparkles != (Object)null)
			{
				PlaySparkleAudio();
				_sparkles.GetComponent<ParticleSystem>().Play();
				SetEffectPercentage(1f);
			}
			_animating = true;
			_reversedAnimation = true;
			_animationProgress = 0f;
			UnreplaceVisuals();
		}

		private void SetEffectPercentage(float progress)
		{
			//IL_004c: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			Plugin.PassMaterial.SetFloat("_UVPercent", progress);
			if ((Object)(object)_sparkles != (Object)null)
			{
				float num = 0.33f;
				float num2 = (1f - progress) * (num * 2f) - num;
				_sparkles.transform.localPosition = new Vector3(_sparkles.transform.localPosition.x, num2, _sparkles.transform.localPosition.z);
			}
			VoicePitchPatches.SetVoicePitchOverridePercent(progress);
		}

		private void PlaySparkleAudio()
		{
			PlayerControllerB val = StartOfRound.Instance?.localPlayerController;
			if (!((Object)(object)val == (Object)null))
			{
				val.itemAudio.PlayOneShot(_sparkleAudio);
			}
		}

		public void DisableAfterAnimation()
		{
			PlayerControllerB val = StartOfRound.Instance?.localPlayerController;
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			FullScreenCustomPass customPass = GetCustomPass(val.gameplayCamera);
			if (customPass != null)
			{
				if ((Object)(object)_sparkles != (Object)null)
				{
					_sparkles.SetActive(false);
				}
				((CustomPass)customPass).enabled = false;
			}
		}

		private FullScreenCustomPass? GetCustomPass(Camera camera)
		{
			if ((Object)(object)_customPassVolume != (Object)null)
			{
				CustomPass? obj = _customPassVolume.customPasses.Where((CustomPass x) => x is FullScreenCustomPass).FirstOrDefault();
				return (FullScreenCustomPass?)(object)((obj is FullScreenCustomPass) ? obj : null);
			}
			_customPassVolume = Object.FindObjectOfType<CustomPassVolume>();
			if ((Object)(object)_customPassVolume == (Object)null)
			{
				return null;
			}
			CustomPass obj2 = _customPassVolume.AddPassOfType<FullScreenCustomPass>();
			CustomPass obj3 = ((obj2 is FullScreenCustomPass) ? obj2 : null);
			((FullScreenCustomPass)obj3).fullscreenPassMaterial = Plugin.PassMaterial;
			obj3.enabled = false;
			return (FullScreenCustomPass?)(object)obj3;
		}
	}
}
namespace WhimsicalWeather.Patches
{
	[HarmonyPatch(typeof(AudioSource))]
	internal class AudioPatches
	{
		private static ReplacementController? _replacementController;

		public static void SetReplacementController(ReplacementController replacementController)
		{
			_replacementController = replacementController;
		}

		[HarmonyPatch("PlayOneShot", new Type[] { typeof(AudioClip) })]
		[HarmonyPatch("PlayOneShotHelper")]
		[HarmonyPrefix]
		private static void PlayOneShotPrefix(ref AudioClip clip)
		{
			if (WhimsicalVisuals.WhimsicalVisualsEnabled && _replacementController != null && !((Object)(object)clip == (Object)null) && ((Object)clip).name != null && ((!(((Object)clip).name == "ShovelHitDefault") && !(((Object)clip).name == "ShovelHitDefault2")) || Config.Instance.LollypopMeleeWeapons.Value))
			{
				_replacementController.ReplaceSoundIfNeeded(ref clip);
			}
		}
	}
	[HarmonyPatch(typeof(BlobAI))]
	internal class BlobPatches
	{
		private static int _gradientColorProperty;

		private static Color _defaultBlobColor;

		private static readonly float _hue;

		private static readonly float _saturation;

		private static readonly float _value;

		static BlobPatches()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			_gradientColorProperty = Shader.PropertyToID("_Gradient_Color");
			_defaultBlobColor = new Color(0.04313725f, 1f, 0.3046348f);
			float hue = default(float);
			float saturation = default(float);
			float value = default(float);
			Color.RGBToHSV(_defaultBlobColor, ref hue, ref saturation, ref value);
			_hue = hue;
			_saturation = saturation;
			_value = value;
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void StartPrefix(BlobAI __instance)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (WhimsicalVisuals.WhimsicalVisualsEnabled && Config.Instance.RainbowBlob.Value)
			{
				float num = (_hue + Time.unscaledTime / 5f) % 1f;
				__instance.thisSlimeMaterial.SetColor(_gradientColorProperty, Color.HSVToRGB(num, _saturation, _value));
			}
		}
	}
	[HarmonyPatch]
	internal class BloodPatches
	{
		[HarmonyPatch(typeof(PlayerControllerB), "DropBlood")]
		[HarmonyPatch(typeof(PlayerControllerB), "AddBloodToBody")]
		[HarmonyPrefix]
		private static bool DropBloodPrefix()
		{
			if (!Config.Instance.RemovePlayerBlood.Value)
			{
				return true;
			}
			return !WhimsicalVisuals.WhimsicalVisualsEnabled;
		}

		[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayerFromOtherClientClientRpc")]
		[HarmonyPostfix]
		private static void DamagePlayerFromOtherClientPostfix(PlayerControllerB __instance)
		{
			if (Config.Instance.RemovePlayerBlood.Value && __instance.health < 6 && (Object)(object)__instance.bodyBloodDecals[0] != (Object)null && __instance.bodyBloodDecals[0].activeSelf)
			{
				__instance.bodyBloodDecals[0].SetActive(false);
			}
		}

		[HarmonyPatch(typeof(DeadBodyInfo), "MakeCorpseBloody")]
		[HarmonyPrefix]
		private static bool MakeCorpseBloodyPrefix()
		{
			if (!Config.Instance.RemovePlayerBlood.Value)
			{
				return true;
			}
			return !WhimsicalVisuals.WhimsicalVisualsEnabled;
		}
	}
	[HarmonyPatch(typeof(MouthDogAI))]
	internal class DogPatches
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPrefix(MouthDogAI __instance)
		{
			//IL_0055: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			if (WhimsicalVisuals.WhimsicalVisualsEnabled && !((Object)(object)Plugin.GooglyEyes == (Object)null) && Config.Instance.GooglyEyeDogs.Value)
			{
				Transform val = ((Component)__instance).transform.Find("MouthDogModel/AnimContainer/Armature/Neck1Container/Neck1/Neck2/JawUpper");
				if (!((Object)(object)val == (Object)null))
				{
					GameObject obj = Object.Instantiate<GameObject>(Plugin.GooglyEyes, val, false);
					obj.transform.localPosition = Vector3.zero;
					obj.transform.localRotation = Quaternion.identity;
					obj.transform.localScale = Vector3.one;
				}
			}
		}
	}
	[HarmonyPatch(typeof(ShipAlarmCord))]
	internal class HornPatches
	{
		private static MethodInfo _modifiedHornPitchMethod = AccessTools.Method(typeof(HornPatches), "ModifiedHornPitch", (Type[])null, (Type[])null);

		private static MethodInfo _modifiedHornLowPitchMethod = AccessTools.Method(typeof(HornPatches), "ModifiedHornLowPitch", (Type[])null, (Type[])null);

		[HarmonyPatch(typeof(ShipAlarmCord), "Update")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> ShipHornUpdateTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_R4)
				{
					object operand = list[i].operand;
					if (operand is float && (float)operand == 0.97f)
					{
						list[i].opcode = OpCodes.Call;
						list[i].operand = _modifiedHornPitchMethod;
						continue;
					}
				}
				if (list[i].opcode == OpCodes.Ldc_R4)
				{
					object operand = list[i].operand;
					if (operand is float && (float)operand == 0.88f)
					{
						list[i].opcode = OpCodes.Call;
						list[i].operand = _modifiedHornLowPitchMethod;
					}
				}
			}
			return list.Where((CodeInstruction x) => x.opcode != OpCodes.Nop).AsEnumerable();
		}

		public static float ModifiedHornPitch()
		{
			if (!WhimsicalVisuals.WhimsicalVisualsEnabled || !Config.Instance.ChangeShipHornPitch.Value)
			{
				return 0.97f;
			}
			return Config.Instance.ShipHornPitch.Value;
		}

		public static float ModifiedHornLowPitch()
		{
			if (!WhimsicalVisuals.WhimsicalVisualsEnabled || !Config.Instance.ChangeShipHornPitch.Value)
			{
				return 0.88f;
			}
			return Config.Instance.ShipHornStartPitch.Value;
		}
	}
	[HarmonyPatch(typeof(JesterAI))]
	internal class JesterPatches
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPrefix(JesterAI __instance)
		{
			//IL_0055: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			if (WhimsicalVisuals.WhimsicalVisualsEnabled && !((Object)(object)Plugin.JesterHat == (Object)null) && Config.Instance.JesterHat.Value)
			{
				Transform val = ((Component)__instance).transform.Find("MeshContainer/AnimContainer/metarig/BoxContainer/spine.004/spine.005/spine.006/UpperJaw");
				if (!((Object)(object)val == (Object)null))
				{
					GameObject obj = Object.Instantiate<GameObject>(Plugin.JesterHat, val, false);
					obj.transform.localPosition = Vector3.zero;
					obj.transform.localRotation = Quaternion.identity;
					obj.transform.localScale = Vector3.one;
				}
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal class NetworkPatches
	{
		[HarmonyPatch("Disconnect")]
		[HarmonyPrefix]
		private static void OnDisconnect(GameNetworkManager __instance)
		{
			if (!__instance.isDisconnecting && !((Object)(object)StartOfRound.Instance == (Object)null) && WhimsicalVisuals.WhimsicalVisualsEnabled)
			{
				if (WhimsicalVisuals.WhimsicalVisualsEnabled)
				{
					WhimsicalVisuals.ToggleVisualsEvent(enabled: false);
				}
				Plugin.WeatherEvents.EventsEnabled = false;
				((Component)Plugin.WeatherEvents).gameObject.SetActive(false);
				Plugin.WeatherEvents.EventsEnabled = true;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerPatches
	{
		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void StartPrefix(PlayerControllerB __instance)
		{
			Object[] array = Resources.FindObjectsOfTypeAll(typeof(HDAdditionalCameraData));
			foreach (Object obj in array)
			{
				Object obj2 = ((obj is HDAdditionalCameraData) ? obj : null);
				((HDAdditionalCameraData)obj2).customRenderingSettings = true;
				ToggleCustomPass((HDAdditionalCameraData)(object)obj2, enable: true);
			}
			HDAdditionalCameraData component = ((Component)__instance.gameplayCamera).GetComponent<HDAdditionalCameraData>();
			if ((Object)(object)component != (Object)null)
			{
				component.customRenderingSettings = true;
				ToggleCustomPass(component, enable: true);
			}
		}

		public static void ToggleCustomPass(HDAdditionalCameraData cameraData, bool enable)
		{
			((BitArray128)(ref cameraData.renderingPathCustomFrameSettingsOverrideMask.mask))[6u] = true;
			((FrameSettings)(ref cameraData.renderingPathCustomFrameSettings)).SetEnabled((FrameSettingsField)6, enable);
		}
	}
	[HarmonyPatch]
	internal class ShovelPatches
	{
		private static List<Shovel> _trackedShovels = new List<Shovel>();

		public static bool _tracking = false;

		[HarmonyPatch(typeof(GrabbableObject))]
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPostfix(GrabbableObject __instance)
		{
			Shovel val = (Shovel)(object)((__instance is Shovel) ? __instance : null);
			if (val != null)
			{
				CreateShovelVisuals(val);
				_trackedShovels.Add(val);
				if (_tracking && Config.Instance.LollypopMeleeWeapons.Value)
				{
					SetShovelVisuals(val, enabled: true);
				}
			}
		}

		[HarmonyPatch(typeof(GrabbableObject))]
		[HarmonyPatch("EnableItemMeshes")]
		[HarmonyPostfix]
		private static void EnableItemMeshesPostfix(GrabbableObject __instance, ref bool enable)
		{
			if (enable)
			{
				Shovel val = (Shovel)(object)((__instance is Shovel) ? __instance : null);
				MeshRenderer val2 = default(MeshRenderer);
				if (val != null && WhimsicalVisuals.WhimsicalVisualsEnabled && Config.Instance.LollypopMeleeWeapons.Value && ((Component)val).gameObject.TryGetComponent<MeshRenderer>(ref val2))
				{
					((Renderer)val2).enabled = false;
				}
			}
		}

		[HarmonyPatch(typeof(GrabbableObject))]
		[HarmonyPatch("GrabItemOnClient")]
		[HarmonyPatch("GrabItemFromEnemy")]
		[HarmonyPostfix]
		private static void EnableItemMeshesPostfix(GrabbableObject __instance)
		{
			Shovel val = (Shovel)(object)((__instance is Shovel) ? __instance : null);
			MeshRenderer val2 = default(MeshRenderer);
			if (val != null && WhimsicalVisuals.WhimsicalVisualsEnabled && Config.Instance.LollypopMeleeWeapons.Value && ((Component)val).gameObject.TryGetComponent<MeshRenderer>(ref val2))
			{
				((Renderer)val2).enabled = false;
			}
		}

		public static void ReplaceAllShovels()
		{
			if (!Config.Instance.LollypopMeleeWeapons.Value)
			{
				return;
			}
			foreach (Shovel trackedShovel in _trackedShovels)
			{
				if (!((Object)(object)trackedShovel == (Object)null))
				{
					SetShovelVisuals(trackedShovel, enabled: true);
				}
			}
			_tracking = true;
		}

		public static void RestoreAllShovels()
		{
			foreach (Shovel trackedShovel in _trackedShovels)
			{
				if (!((Object)(object)trackedShovel == (Object)null))
				{
					SetShovelVisuals(trackedShovel, enabled: false);
				}
			}
			_tracking = false;
		}

		private static void CreateShovelVisuals(Shovel shovel)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)shovel).transform.Find("CustomVisuals");
			if ((Object)(object)val == (Object)null)
			{
				val = new GameObject("CustomVisuals").transform;
				val.SetParent(((Component)shovel).transform);
				((Component)val).transform.localPosition = Vector3.zero;
				((Component)val).transform.localRotation = Quaternion.identity;
				((Component)val).transform.localScale = Vector3.one;
			}
			foreach (Transform item in val)
			{
				((Component)item).gameObject.SetActive(false);
			}
			GameObject shovelVisuals = GetShovelVisuals(shovel);
			if (!((Object)(object)shovelVisuals == (Object)null))
			{
				GameObject obj = Object.Instantiate<GameObject>(shovelVisuals, ((Component)val).transform, false);
				obj.transform.localPosition = Vector3.zero;
				obj.transform.localRotation = Quaternion.identity;
				obj.transform.localScale = Vector3.one;
				((Component)val).gameObject.SetActive(false);
			}
		}

		private static void SetShovelVisuals(Shovel shovel, bool enabled)
		{
			Transform val = ((Component)shovel).transform.Find("CustomVisuals");
			if (!((Object)(object)val == (Object)null))
			{
				((Component)val).gameObject.SetActive(enabled);
				Transform val2 = ((Component)shovel).transform.Find("mesh");
				if ((Object)(object)val2 != (Object)null)
				{
					((Component)val2).gameObject.SetActive(!enabled);
				}
				MeshRenderer val3 = default(MeshRenderer);
				if (((Component)shovel).gameObject.TryGetComponent<MeshRenderer>(ref val3))
				{
					((Renderer)val3).enabled = !enabled;
				}
			}
		}

		private static GameObject? GetShovelVisuals(Shovel shovel)
		{
			if (((Object)((Component)shovel).gameObject).name.StartsWith("ShovelItem"))
			{
				return Plugin.GrayLollypop;
			}
			if (((Object)((Component)shovel).gameObject).name.StartsWith("YieldSign"))
			{
				return Plugin.YellowLollypop;
			}
			((Object)((Component)shovel).gameObject).name.StartsWith("StopSign");
			return Plugin.RedLollypop;
		}
	}
	[HarmonyPatch]
	internal class VoicePitchPatches
	{
		private static MethodInfo _modifiedVoiceTargetsMethod = AccessTools.Method(typeof(VoicePitchPatches), "ModifiedPlayerVoicePitches", (Type[])null, (Type[])null);

		private static float _voicePitchAddAmount = 0f;

		[HarmonyPatch(typeof(SoundManager), "SetPlayerVoiceFilters")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> SetPlayerVoiceFiltersTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldfld && list[i].operand is FieldInfo fieldInfo && fieldInfo.Name == "playerVoicePitchTargets")
				{
					list[i].opcode = OpCodes.Call;
					list[i].operand = _modifiedVoiceTargetsMethod;
				}
			}
			return list.Where((CodeInstruction x) => x.opcode != OpCodes.Nop).AsEnumerable();
		}

		public static float[] ModifiedPlayerVoicePitches(SoundManager soundManager)
		{
			if (WhimsicalVisuals.WhimsicalVisualsEnabled && Config.Instance.ChangePlayerPitch.Value)
			{
				return soundManager.playerVoicePitchTargets.Select((float x) => x + _voicePitchAddAmount).ToArray();
			}
			return soundManager.playerVoicePitchTargets;
		}

		public static void SetVoicePitchOverridePercent(float percent)
		{
			_voicePitchAddAmount = percent * (Config.Instance.PlayerPitchMultiplier.Value - 1f);
		}
	}
	[HarmonyPatch(typeof(WalkieTalkie))]
	internal class WalkieTalkiePatches
	{
		public const float WalkieTalkieLightIntensityOverride = 0.1f;

		public const float WalkieTalkieLightIntensityDefault = 0.4843846f;

		[HarmonyPatch("OnEnable")]
		[HarmonyPostfix]
		private static void StartPrefix(PlayerControllerB __instance)
		{
			if (WhimsicalVisuals.WhimsicalVisualsEnabled)
			{
				SetWalkieLightIntensity(0.1f);
			}
		}

		public static void SetWalkieLightIntensity(float intensity)
		{
			foreach (WalkieTalkie allWalkieTalky in WalkieTalkie.allWalkieTalkies)
			{
				if (!((Object)(object)allWalkieTalky == (Object)null) && !((Object)(object)allWalkieTalky.walkieTalkieLight == (Object)null))
				{
					allWalkieTalky.walkieTalkieLight.intensity = intensity;
				}
			}
		}
	}
	[HarmonyPatch]
	internal class ZapGunPatches
	{
		private static int _tintColorProperty = Shader.PropertyToID("_TintColor");

		[HarmonyPatch(typeof(LightningBoltScript))]
		[HarmonyPatch("UpdateShaderParameters")]
		[HarmonyPostfix]
		private static void CreateDependencies(LightningBoltScript __instance)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			if (WhimsicalVisuals.WhimsicalVisualsEnabled && Config.Instance.RainbowZapGun.Value)
			{
				float num2 = default(float);
				float num3 = default(float);
				float num = default(float);
				Color.RGBToHSV(new Color(1f, 0f, 0f), ref num, ref num2, ref num3);
				num = (num + Time.unscaledTime / 5f) % 1f;
				__instance.lightningMaterialMeshInternal.SetColor(_tintColorProperty, Color.HSVToRGB(num, num2, num3));
				__instance.lightningMaterialMeshNoGlowInternal.SetColor(_tintColorProperty, Color.HSVToRGB(num, num2, num3));
			}
		}
	}
}
namespace WhimsicalWeather.Models
{
	internal class ColorReplacement : MaterialReplacement
	{
		private Dictionary<Material, Color> _originalColorsByMaterial = new Dictionary<Material, Color>();

		private Color _replacement;

		private string _materialName;

		private string _colorName;

		public ColorReplacement(Color replacement, string materialName, string colorName)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			_replacement = replacement;
			_materialName = materialName;
			_colorName = colorName;
		}

		public override bool MaterialIsMatch(Material material)
		{
			if ((Object)(object)material == (Object)null || (Object)(object)material.shader == (Object)null)
			{
				return false;
			}
			if (!((Object)material).name.StartsWith(_materialName))
			{
				return false;
			}
			if (!material.HasColor(_colorName))
			{
				return false;
			}
			return true;
		}

		public override void ReplaceOnMaterial(Material material)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if (!material.HasColor(_colorName))
			{
				Plugin.Logger.LogWarning((object)("Attempted to replace color on " + ((Object)material).name + " but color " + _colorName + " does not exist!"));
			}
			else if (!_replacedMaterials.Contains(material))
			{
				_replacedMaterials.Add(material);
				_originalColorsByMaterial.Add(material, material.GetColor(_colorName));
				material.SetColor(_colorName, _replacement);
			}
		}

		public override void RestoreMaterials()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			foreach (Material replacedMaterial in _replacedMaterials)
			{
				if (!((Object)(object)replacedMaterial == (Object)null))
				{
					replacedMaterial.SetColor(_colorName, _originalColorsByMaterial[replacedMaterial]);
				}
			}
			_replacedMaterials.Clear();
			_originalColorsByMaterial.Clear();
		}

		public override string ToString()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return $"MaterialReplacement (Color): {_replacement} (replacing {_colorName} on {_materialName})";
		}
	}
	internal class FloatReplacement : MaterialReplacement
	{
		private Dictionary<Material, float> _originalFloatsByMaterial = new Dictionary<Material, float>();

		private float _replacement;

		private string _materialName;

		private string _floatName;

		public FloatReplacement(float replacement, string materialName, string floatName)
		{
			_replacement = replacement;
			_materialName = materialName;
			_floatName = floatName;
		}

		public override bool MaterialIsMatch(Material material)
		{
			if ((Object)(object)material == (Object)null || (Object)(object)material.shader == (Object)null)
			{
				return false;
			}
			if (!((Object)material).name.StartsWith(_materialName))
			{
				return false;
			}
			if (!material.HasFloat(_floatName))
			{
				return false;
			}
			return true;
		}

		public override void ReplaceOnMaterial(Material material)
		{
			if (!material.HasFloat(_floatName))
			{
				Plugin.Logger.LogWarning((object)("Attempted to replace float on " + ((Object)material).name + " but float " + _floatName + " does not exist!"));
			}
			else if (!_replacedMaterials.Contains(material))
			{
				_replacedMaterials.Add(material);
				_originalFloatsByMaterial.Add(material, material.GetFloat(_floatName));
				material.SetFloat(_floatName, _replacement);
			}
		}

		public override void RestoreMaterials()
		{
			foreach (Material replacedMaterial in _replacedMaterials)
			{
				if (!((Object)(object)replacedMaterial == (Object)null))
				{
					replacedMaterial.SetFloat(_floatName, _originalFloatsByMaterial[replacedMaterial]);
				}
			}
			_replacedMaterials.Clear();
			_originalFloatsByMaterial.Clear();
		}

		public override string ToString()
		{
			return $"MaterialReplacement (Float): {_replacement} (replacing {_floatName} on {_materialName})";
		}
	}
	internal class ImageGameObjectNameShaderReplacement : ImageShaderReplacement
	{
		private Shader _replacement;

		private string _gameObjectName;

		private string? _parentName;

		public ImageGameObjectNameShaderReplacement(Shader replacement, string gameObjectName, string? parentName = null)
		{
			_gameObjectName = gameObjectName;
			_parentName = parentName;
			_replacement = replacement;
		}

		public override bool ImageShaderIsMatch(Image image)
		{
			if ((Object)(object)image == (Object)null || (Object)(object)((Component)image).gameObject == (Object)null)
			{
				return false;
			}
			if (_parentName != null && (Object)(object)((Component)image).transform.parent == (Object)null)
			{
				return false;
			}
			if (_parentName != null && ((Object)((Component)image).transform.parent).name != _parentName)
			{
				return false;
			}
			if (((Object)((Component)image).gameObject).name != _gameObjectName)
			{
				return false;
			}
			return true;
		}

		public override void ReplaceImageShader(Image image)
		{
			if (!_originalMaterialsByImage.ContainsKey(image))
			{
				_originalMaterialsByImage.Add(image, ((Graphic)image).material);
				((Graphic)image).material = Object.Instantiate<Material>(((Graphic)image).material);
				((Graphic)image).material.shader = _replacement;
				if (Config.Instance.RainbowUIHueShiftSpeed.Value != 1f && (!((Object)(object)((Graphic)image).material.shader != (Object)(object)Plugin.RainbowUIShader) || !((Object)(object)((Graphic)image).material.shader != (Object)(object)Plugin.RainbowTextShader)))
				{
					((Graphic)image).material.SetFloat("_HueShiftSpeed", Config.Instance.RainbowUIHueShiftSpeed.Value);
				}
			}
		}

		public override void RestoreImageShaders()
		{
			foreach (var (val3, material) in _originalMaterialsByImage)
			{
				if (!((Object)(object)val3 == (Object)null))
				{
					((Graphic)val3).material = material;
				}
			}
			_originalMaterialsByImage.Clear();
		}

		public override string ToString()
		{
			string text = ((_parentName == null) ? string.Empty : (_parentName + "/"));
			return "ImageShaderReplacement (GameObject Name): " + ((Object)_replacement).name + " (replacing GameObject: " + text + _gameObjectName + ")";
		}
	}
	internal class ImageNameShaderReplacement : ImageShaderReplacement
	{
		private Shader _replacement;

		private string _spriteName;

		public ImageNameShaderReplacement(Shader replacement, string spriteName)
		{
			_spriteName = spriteName;
			_replacement = replacement;
		}

		public override bool ImageShaderIsMatch(Image image)
		{
			if ((Object)(object)image != (Object)null && (Object)(object)image.sprite != (Object)null)
			{
				return ((Object)image.sprite).name == _spriteName;
			}
			return false;
		}

		public override void ReplaceImageShader(Image image)
		{
			if (!_originalMaterialsByImage.ContainsKey(image))
			{
				_originalMaterialsByImage.Add(image, ((Graphic)image).material);
				((Graphic)image).material = Object.Instantiate<Material>(((Graphic)image).material);
				((Graphic)image).material.shader = _replacement;
				if (Config.Instance.RainbowUIHueShiftSpeed.Value != 1f && (!((Object)(object)((Graphic)image).material.shader != (Object)(object)Plugin.RainbowUIShader) || !((Object)(object)((Graphic)image).material.shader != (Object)(object)Plugin.RainbowTextShader)))
				{
					((Graphic)image).material.SetFloat("_HueShiftSpeed", Config.Instance.RainbowUIHueShiftSpeed.Value);
				}
			}
		}

		public override void RestoreImageShaders()
		{
			foreach (var (val3, material) in _originalMaterialsByImage)
			{
				if (!((Object)(object)val3 == (Object)null))
				{
					((Graphic)val3).material = material;
				}
			}
			_originalMaterialsByImage.Clear();
		}

		public override string ToString()
		{
			return "ImageShaderReplacement (Name): " + ((Object)_replacement).name + " (replacing sprite: " + _spriteName + ")";
		}
	}
	internal abstract class ImageShaderReplacement
	{
		protected Dictionary<Image, Material?> _originalMaterialsByImage = new Dictionary<Image, Material>();

		public bool ImageShadersReplaced => _originalMaterialsByImage.Count > 0;

		public void ReplaceImageShaderIfMatch(Image image)
		{
			if (ImageShaderIsMatch(image))
			{
				ReplaceImageShader(image);
			}
		}

		public abstract bool ImageShaderIsMatch(Image image);

		public abstract void ReplaceImageShader(Image image);

		public abstract void RestoreImageShaders();
	}
	internal class MaterialNameShaderReplacement : MaterialReplacement
	{
		private Dictionary<Material, Shader?> _originalShadersByMaterial = new Dictionary<Material, Shader>();

		private Shader _replacement;

		private string _materialName;

		private bool _isParticle;

		public MaterialNameShaderReplacement(Shader replacement, string materialName, bool isParticle)
		{
			_materialName = materialName;
			_replacement = replacement;
			_isParticle = isParticle;
		}

		public override bool MaterialIsMatch(Material material)
		{
			if ((Object)(object)material == (Object)null || (Object)(object)material.shader == (Object)null)
			{
				return false;
			}
			return ((Object)material).name == _materialName;
		}

		public override void ReplaceOnMaterial(Material material)
		{
			if (_replacedMaterials.Contains(material))
			{
				return;
			}
			_replacedMaterials.Add(material);
			_originalShadersByMaterial.Add(material, material.shader);
			if (_isParticle)
			{
				if (((Object)material.shader).name == "HDRP/Unlit")
				{
					Texture texture = material.GetTexture("_UnlitColorMap");
					material.shader = _replacement;
					material.SetTexture("_BaseColorMap", texture);
				}
				else
				{
					material.shader = _replacement;
				}
			}
			else
			{
				material.shader = _replacement;
			}
		}

		public override void RestoreMaterials()
		{
			foreach (Material replacedMaterial in _replacedMaterials)
			{
				if (!((Object)(object)replacedMaterial == (Object)null))
				{
					replacedMaterial.shader = _originalShadersByMaterial[replacedMaterial];
				}
			}
			_replacedMaterials.Clear();
			_originalShadersByMaterial.Clear();
		}

		public override string ToString()
		{
			return "MaterialReplacement (Material Name): " + ((Object)_replacement).name + " (replacing " + _materialName + ")";
		}
	}
	internal abstract class MaterialReplacement
	{
		protected List<Material> _replacedMaterials = new List<Material>();

		public bool MaterialsReplaced => _replacedMaterials.Count > 0;

		public void ReplaceMaterialIfMatch(Material material)
		{
			if (MaterialIsMatch(material))
			{
				ReplaceOnMaterial(material);
			}
		}

		public abstract bool MaterialIsMatch(Material material);

		public abstract void ReplaceOnMaterial(Material material);

		public abstract void RestoreMaterials();
	}
	internal class MaterialShaderReplacement : MaterialReplacement
	{
		private Dictionary<Material, Shader?> _originalShadersByMaterial = new Dictionary<Material, Shader>();

		private Shader _replacement;

		private string _shaderName;

		public MaterialShaderReplacement(Shader replacement, string shaderName)
		{
			_shaderName = shaderName;
			_replacement = replacement;
		}

		public override bool MaterialIsMatch(Material material)
		{
			if ((Object)(object)material == (Object)null || (Object)(object)material.shader == (Object)null)
			{
				return false;
			}
			return ((Object)material.shader).name == _shaderName;
		}

		public override void ReplaceOnMaterial(Material material)
		{
			if (!_replacedMaterials.Contains(material))
			{
				_replacedMaterials.Add(material);
				_originalShadersByMaterial.Add(material, material.shader);
				material.shader = _replacement;
				if (Config.Instance.RainbowUIHueShiftSpeed.Value != 1f && (!((Object)(object)material.shader != (Object)(object)Plugin.RainbowUIShader) || !((Object)(object)material.shader != (Object)(object)Plugin.RainbowTextShader)))
				{
					material.SetFloat("_HueShiftSpeed", Config.Instance.RainbowUIHueShiftSpeed.Value);
				}
			}
		}

		public override void RestoreMaterials()
		{
			foreach (Material replacedMaterial in _replacedMaterials)
			{
				if (!((Object)(object)replacedMaterial == (Object)null))
				{
					replacedMaterial.shader = _originalShadersByMaterial[replacedMaterial];
				}
			}
			_replacedMaterials.Clear();
			_originalShadersByMaterial.Clear();
		}

		public override string ToString()
		{
			return "MaterialReplacement (Shader): " + ((Object)_replacement).name + " (replacing " + _shaderName + ")";
		}
	}
	public enum SoundReplacementType
	{
		OneShotAudio,
		SoundManagerHighAction1
	}
	internal class TextureReplacement : MaterialReplacement
	{
		private Dictionary<Material, Texture?> _originalTexturesByMaterial = new Dictionary<Material, Texture>();

		private Texture _replacement;

		private string _materialName;

		private string _propertyName;

		private bool _forceTransparentLayer;

		public TextureReplacement(TextureReplacementBehaviour textureReplacement)
		{
			_replacement = textureReplacement.Texture;
			_materialName = textureReplacement.MaterialName;
			_propertyName = textureReplacement.PropertyName;
			_forceTransparentLayer = textureReplacement.ForceTransparentLayer;
		}

		public override bool MaterialIsMatch(Material material)
		{
			if ((Object)(object)material == (Object)null || (Object)(object)material.shader == (Object)null)
			{
				return false;
			}
			if (!((Object)material).name.StartsWith(_materialName))
			{
				return false;
			}
			if (!material.HasProperty(_propertyName))
			{
				return false;
			}
			return true;
		}

		public override void ReplaceOnMaterial(Material material)
		{
			if (!material.HasProperty(_propertyName))
			{
				Plugin.Logger.LogWarning((object)("Attempted to replace texture on " + ((Object)material).name + " but property " + _propertyName + " does not exist!"));
			}
			else if (!_replacedMaterials.Contains(material))
			{
				_replacedMaterials.Add(material);
				_originalTexturesByMaterial.Add(material, material.GetTexture(_propertyName));
				material.SetTexture(_propertyName, _replacement);
				if (_forceTransparentLayer)
				{
					material.renderQueue = 3000;
				}
			}
		}

		public override void RestoreMaterials()
		{
			foreach (Material replacedMaterial in _replacedMaterials)
			{
				if (!((Object)(object)replacedMaterial == (Object)null))
				{
					replacedMaterial.SetTexture(_propertyName, _originalTexturesByMaterial[replacedMaterial]);
					if (_forceTransparentLayer)
					{
						replacedMaterial.renderQueue = replacedMaterial.rawRenderQueue;
					}
				}
			}
			_replacedMaterials.Clear();
			_originalTexturesByMaterial.Clear();
		}

		public override string ToString()
		{
			return "MaterialReplacement (Texture): " + ((Object)_replacement).name + " (replacing " + _propertyName + " on " + _materialName + ")";
		}
	}
}
namespace WhimsicalWeather.Controllers
{
	internal class ReplacementController
	{
		private static List<string> _imageSpriteNames = new List<string>
		{
			"DialogueBox1Frame 1", "DialogueBox1Frame 2", "DialogueBox1Frame 3", "DialogueBox1Frame 4", "DialogueBox1Frame 5", "DialogueBox1Frame 6", "SprintMeter", "scanCircle1", "scanCircle2", "ScanUI1",
			"DialogueBoxSimple", "BatteryIcon", "BatteryMeter", "BatteryMeterFrame", "timeIcon1", "timeIcon2", "timeIcon3", "timeIcon3b", "SpeakingSymbol", "CircleMeterOutline",
			"CircleMeterFill", "endgameStatsBG", "endgameStatsBoxes", "endgameAllPlayersDead", "shipClockIcon"
		};

		private static List<string> _imageGameObjectNames = new List<string>
		{
			"HeaderTextBox", "SubTextBox", "Panel (2)", "Panel (1)", "PleaseConfirmChangesPanel/Panel", "Symbol", "DividingLine", "Container2/Image", "LevelUp/Image", "LevelUp/Image (2)",
			"LevelUp/LevelUpMeter", "Penalty/Image"
		};

		private static List<string> _particleMaterialNames = new List<string> { "SparkParticle", "BeamUpZap", "BeamUpZap 1" };

		private List<MaterialReplacement> _materialReplacements = new List<MaterialReplacement>();

		private List<ImageShaderReplacement> _imageShaderReplacements = new List<ImageShaderReplacement>();

		private List<SoundReplacementBehaviour> _soundReplacements = new List<SoundReplacementBehaviour>();

		private List<SoundReplacementBehaviour> _oneShotSoundReplacements = new List<SoundReplacementBehaviour>();

		private AudioClip? _highAction1Clip;

		public void CreateSoundReplacements(List<SoundReplacementBehaviour> soundReplacements)
		{
			_soundReplacements = soundReplacements;
			_oneShotSoundReplacements = _soundReplacements.Where((SoundReplacementBehaviour x) => x.SoundReplacementType == SoundReplacementType.OneShotAudio).ToList();
		}

		public void CreateTextureReplacements(List<TextureReplacementBehaviour> textureReplacements)
		{
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			foreach (TextureReplacementBehaviour textureReplacement in textureReplacements)
			{
				_materialReplacements.Add(new TextureReplacement(textureReplacement));
			}
			foreach (string particleMaterialName in _particleMaterialNames)
			{
				if (!(particleMaterialName == "SparkParticle") || Config.Instance.RainbowZapGun.Value)
				{
					_materialReplacements.Add(new MaterialNameShaderReplacement(Plugin.RainbowParticleShader, particleMaterialName, isParticle: true));
				}
			}
			if (Config.Instance.RainbowItemDropship.Value)
			{
				_materialReplacements.Add(new MaterialNameShaderReplacement(Plugin.RainbowDropshipLightsShader, "LEDLightYellow", isParticle: false));
				_materialReplacements.Add(new ColorReplacement(new Color(0.9f, 0f, 0f, 1f), "LEDLightYellow", "_Color"));
			}
			if (Config.Instance.ClearMagnifyingGlass.Value)
			{
				_materialReplacements.Add(new ColorReplacement(new Color(0f, 0f, 0.2f, 0.3f), "GlassTex", "_BaseColor"));
				_materialReplacements.Add(new FloatReplacement(0.85f, "GlassTex", "_Smoothness"));
			}
			if (Config.Instance.RainbowApparatus.Value)
			{
				_materialReplacements.Add(new MaterialNameShaderReplacement(Plugin.RainbowUIShader, "TankLight", isParticle: false));
				_materialReplacements.Add(new ColorReplacement(new Color(0.8f, 0f, 0f, 1f), "TankLight", "_Color"));
				_materialReplacements.Add(new FloatReplacement(5f, "TankLight", "_HueShiftSpeed"));
			}
		}

		public void CreateImageShaderReplacements()
		{
			if (!Config.Instance.RainbowUI.Value)
			{
				return;
			}
			foreach (string imageSpriteName in _imageSpriteNames)
			{
				ImageNameShaderReplacement item = new ImageNameShaderReplacement(Plugin.RainbowUIShader, imageSpriteName);
				_imageShaderReplacements.Add(item);
			}
			foreach (string imageGameObjectName in _imageGameObjectNames)
			{
				string[] array = imageGameObjectName.Split('/');
				ImageGameObjectNameShaderReplacement item2 = ((array.Length <= 1) ? new ImageGameObjectNameShaderReplacement(Plugin.RainbowUIShader, imageGameObjectName) : new ImageGameObjectNameShaderReplacement(Plugin.RainbowUIShader, array[1], array[0]));
				_imageShaderReplacements.Add(item2);
			}
			_materialReplacements.Add(new MaterialShaderReplacement(Plugin.RainbowTextShader, "TextMeshPro/Distance Field"));
		}

		public void ReplaceAll()
		{
			Material[] array = Resources.FindObjectsOfTypeAll(typeof(Material)) as Material[];
			foreach (Material material in array)
			{
				foreach (MaterialReplacement materialReplacement in _materialReplacements)
				{
					materialReplacement.ReplaceMaterialIfMatch(material);
				}
			}
			Image[] array2 = Resources.FindObjectsOfTypeAll(typeof(Image)) as Image[];
			foreach (Image image in array2)
			{
				foreach (ImageShaderReplacement imageShaderReplacement in _imageShaderReplacements)
				{
					imageShaderReplacement.ReplaceImageShaderIfMatch(image);
				}
			}
			foreach (SoundReplacementBehaviour soundReplacement in _soundReplacements)
			{
				if (soundReplacement.SoundReplacementType == SoundReplacementType.SoundManagerHighAction1 && (Object)(object)SoundManager.Instance != (Object)null)
				{
					_highAction1Clip = SoundManager.Instance.highAction1.clip;
					SoundManager.Instance.highAction1.clip = soundReplacement.ReplacementClip;
					if (!GameNetworkManager.Instance.localPlayerController.isPlayerDead)
					{
						SoundManager.Instance.highAction1.Stop();
						SoundManager.Instance.highAction1.Play();
					}
				}
			}
		}

		public void UnreplaceAll()
		{
			foreach (MaterialReplacement materialReplacement in _materialReplacements)
			{
				materialReplacement.RestoreMaterials();
			}
			foreach (ImageShaderReplacement imageShaderReplacement in _imageShaderReplacements)
			{
				imageShaderReplacement.RestoreImageShaders();
			}
			foreach (SoundReplacementBehaviour soundReplacement in _soundReplacements)
			{
				if (soundReplacement.SoundReplacementType == SoundReplacementType.SoundManagerHighAction1 && (Object)(object)SoundManager.Instance != (Object)null)
				{
					SoundManager.Instance.highAction1.clip = _highAction1Clip;
					_highAction1Clip = null;
					if (!GameNetworkManager.Instance.localPlayerController.isPlayerDead)
					{
						SoundManager.Instance.highAction1.Stop();
						SoundManager.Instance.highAction1.Play();
					}
				}
			}
		}

		private void ReplaceCustomSounds(bool enabled)
		{
			foreach (SoundReplacementBehaviour soundReplacement in _soundReplacements)
			{
				if (soundReplacement.SoundReplacementType == SoundReplacementType.SoundManagerHighAction1 && Config.Instance.FearLaughing.Value && (Object)(object)SoundManager.Instance != (Object)null)
				{
					if (enabled)
					{
						_highAction1Clip = SoundManager.Instance.highAction1.clip;
						SoundManager.Instance.highAction1.clip = soundReplacement.ReplacementClip;
					}
					else
					{
						SoundManager.Instance.highAction1.clip = _highAction1Clip;
						_highAction1Clip = null;
					}
					if (!GameNetworkManager.Instance.localPlayerController.isPlayerDead)
					{
						SoundManager.Instance.highAction1.Stop();
						SoundManager.Instance.highAction1.Play();
					}
				}
			}
		}

		public void ReplaceSoundIfNeeded(ref AudioClip clip)
		{
			if (!((Object)(object)clip == (Object)null))
			{
				string clipName = ((Object)clip).name;
				SoundReplacementBehaviour soundReplacementBehaviour = _oneShotSoundReplacements.FirstOrDefault((SoundReplacementBehaviour x) => x.SoundName == clipName);
				if (!((Object)(object)soundReplacementBehaviour == (Object)null))
				{
					clip = soundReplacementBehaviour.ReplacementClip;
				}
			}
		}
	}
}
namespace WhimsicalWeather.Behaviours
{
	public class GameObjectActivityBehaviour : MonoBehaviour
	{
		public bool EventsEnabled;

		private void OnEnable()
		{
			if (EventsEnabled)
			{
				WhimsicalVisuals.ToggleVisualsEvent(enabled: true);
			}
		}

		private void OnDisable()
		{
			if (EventsEnabled)
			{
				WhimsicalVisuals.ToggleVisualsEvent(enabled: false);
			}
		}
	}
	[Serializable]
	public class SoundReplacementBehaviour : MonoBehaviour
	{
		public AudioClip ReplacementClip;

		public string SoundName;

		public SoundReplacementType SoundReplacementType;
	}
	[Serializable]
	public class TextureReplacementBehaviour : MonoBehaviour
	{
		public Texture Texture;

		public string MaterialName;

		public string PropertyName;

		public bool ForceTransparentLayer;
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}