Decompiled source of SnoringWarning v1.1.1

BepInEx/plugins/SnoringWarning/zarin.contentwarning.snoringwarning.dll

Decompiled 7 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using ContentSettings.API.Attributes;
using ContentSettings.API.Settings;
using Microsoft.CodeAnalysis;
using On;
using SnoringWarning.Behaviours;
using SnoringWarning.Hooks;
using UnityEngine;
using Zorro.Settings;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("30ca8cff-69e0-4138-93b6-c2ea6c9c3865")]
[assembly: IgnoresAccessChecksTo("Ashley.MeshSplitter")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("com.rlabrecque.steamworks.net")]
[assembly: IgnoresAccessChecksTo("Discord")]
[assembly: IgnoresAccessChecksTo("HBAO.Demo.Universal.Runtime")]
[assembly: IgnoresAccessChecksTo("HBAO.Runtime")]
[assembly: IgnoresAccessChecksTo("HBAO.Universal.Runtime")]
[assembly: IgnoresAccessChecksTo("MeshSplit")]
[assembly: IgnoresAccessChecksTo("Photon3Unity3D")]
[assembly: IgnoresAccessChecksTo("PhotonChat")]
[assembly: IgnoresAccessChecksTo("PhotonRealtime")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking.Utilities")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.API")]
[assembly: IgnoresAccessChecksTo("PhotonVoice")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.PUN")]
[assembly: IgnoresAccessChecksTo("pworld")]
[assembly: IgnoresAccessChecksTo("sc.posteffects.runtime")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Attributes")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Modules.Unity.Addressables")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Modules.UnityLocalization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization.Config")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Utilities")]
[assembly: IgnoresAccessChecksTo("Tayx.Graphy")]
[assembly: IgnoresAccessChecksTo("Unity.Addressables")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InternalAPIEngineBridge.013")]
[assembly: IgnoresAccessChecksTo("Unity.Localization")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.PlayableGraphVisualizer")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipeline.Universal.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Universal.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Universal.Shaders")]
[assembly: IgnoresAccessChecksTo("Unity.ResourceManager")]
[assembly: IgnoresAccessChecksTo("Unity.ScriptableBuildPipeline")]
[assembly: IgnoresAccessChecksTo("Unity.Splines")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Antlr3.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Core")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Flow")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.State")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("Zorro.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Zorro.PhotonUtility")]
[assembly: IgnoresAccessChecksTo("Zorro.Recorder")]
[assembly: IgnoresAccessChecksTo("Zorro.Settings.Runtime")]
[assembly: IgnoresAccessChecksTo("Zorro.UI.Runtime")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("zarin.contentwarning.snoringwarning")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+a234374bda9ad4a4b21b38028fa1f2218e8e0b08")]
[assembly: AssemblyProduct("SnoringWarning")]
[assembly: AssemblyTitle("zarin.contentwarning.snoringwarning")]
[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace SnoringWarning
{
	[ContentWarningPlugin("zarin.contentwarning.snoringwarning", "SnoringWarning", true)]
	[BepInPlugin("zarin.contentwarning.snoringwarning", "SnoringWarning", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class SnoringWarning : BaseUnityPlugin
	{
		private static string snoreBundleName = Assembly.GetExecutingAssembly().GetManifestResourceNames().FirstOrDefault((string n) => n.EndsWith("snoringwarning"));

		private static AssetBundle _snoreBundle = AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(snoreBundleName));

		public static SnoringWarning Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			new BedHook().Init();
			LogInfo("SnoringWarning (zarin.contentwarning.snoringwarning) has loaded!");
		}

		public void LogInfo(object message)
		{
			Logger.LogInfo(message);
		}

		public void LogDebug(object message)
		{
			Logger.LogDebug(message);
		}

		internal T GetBundleAsset<T>(string name) where T : Object
		{
			return _snoreBundle.LoadAsset<T>(name);
		}
	}
	internal class SnoringWarningSettings
	{
		internal enum SnoreType
		{
			Silent,
			Loud
		}

		internal static float Volume;

		internal static SnoreType Snore { get; private set; }

		internal static void SetSnoreType(int snoreType)
		{
			Dictionary<int, SnoreType> dictionary = new Dictionary<int, SnoreType>
			{
				[0] = SnoreType.Silent,
				[1] = SnoreType.Loud
			};
			Snore = dictionary[snoreType];
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "zarin.contentwarning.snoringwarning";

		public const string PLUGIN_NAME = "SnoringWarning";

		public const string PLUGIN_VERSION = "1.1.1";
	}
}
namespace SnoringWarning.Settings
{
	[SettingRegister("CYCLOZARIN MODS", "SnoringWarning settings")]
	internal class SnoreType : EnumSetting, ICustomSetting, IExposedSetting
	{
		private List<string> _choices => new List<string>(2) { "Silent", "Loud" };

		public override void ApplyValue()
		{
			SnoringWarningSettings.SetSnoreType(((IntSetting)this).Value);
			SnoringWarning.Instance.LogDebug($"Key name: Snore type; Type: {SnoringWarningSettings.Snore}");
		}

		public override List<string> GetChoices()
		{
			return _choices;
		}

		public string GetDisplayName()
		{
			return "Snore type";
		}

		public override int GetDefaultValue()
		{
			return 0;
		}
	}
	[SettingRegister("CYCLOZARIN MODS", "SnoringWarning settings")]
	internal class SnoreVolume : IntSetting, ICustomSetting, IExposedSetting
	{
		public override void ApplyValue()
		{
			SnoringWarningSettings.Volume = (float)((IntSetting)this).Value / 100f;
			SnoringWarning.Instance.LogDebug($"Key name: Snore volume; Volume: {((IntSetting)this).Value}% ({SnoringWarningSettings.Volume})");
		}

		protected override int GetDefaultValue()
		{
			return 50;
		}

		public string GetDisplayName()
		{
			return "Snore volume";
		}

		protected override (int, int) GetMinMaxValue()
		{
			return (0, 100);
		}
	}
}
namespace SnoringWarning.Hooks
{
	public class BedHook
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_RPCA_AcceptSleep <0>__MM_Postfix_BedSnoringOn;

			public static hook_RPCA_LeaveBed <1>__MM_Prefix_BedSnoringOff;
		}

		internal void Init()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			object obj = <>O.<0>__MM_Postfix_BedSnoringOn;
			if (obj == null)
			{
				hook_RPCA_AcceptSleep val = MM_Postfix_BedSnoringOn;
				<>O.<0>__MM_Postfix_BedSnoringOn = val;
				obj = (object)val;
			}
			Bed.RPCA_AcceptSleep += (hook_RPCA_AcceptSleep)obj;
			object obj2 = <>O.<1>__MM_Prefix_BedSnoringOff;
			if (obj2 == null)
			{
				hook_RPCA_LeaveBed val2 = MM_Prefix_BedSnoringOff;
				<>O.<1>__MM_Prefix_BedSnoringOff = val2;
				obj2 = (object)val2;
			}
			Bed.RPCA_LeaveBed += (hook_RPCA_LeaveBed)obj2;
			Player.Start += new hook_Start(MM_Postfix_CreateSnoreSourceAtPlayer);
			SnoringWarning.Instance.LogDebug("Hooked bed and player");
		}

		private static bool IsPlayerHaveSnoreSource(Player player)
		{
			return (Object)(object)((Component)player.refs.headPos).GetComponentInChildren<SnoreSource>() != (Object)null;
		}

		private IEnumerator MM_Postfix_CreateSnoreSourceAtPlayer(orig_Start orig, Player self)
		{
			yield return orig.Invoke(self);
			if (!IsPlayerHaveSnoreSource(self))
			{
				GameObject val = Object.Instantiate<GameObject>(new GameObject("SnoreSource"), self.HeadPosition(), Quaternion.identity, ((Component)self.refs.headPos).transform);
				SnoreSource snoreSource = val.AddComponent<SnoreSource>();
				snoreSource.UpdateSourceSettings();
				((Object)snoreSource).hideFlags = (HideFlags)61;
				Object.DontDestroyOnLoad((Object)(object)val);
				SnoringWarning.Instance.LogDebug("Snore source instantiated");
			}
		}

		private static void MM_Postfix_BedSnoringOn(orig_RPCA_AcceptSleep orig, Bed self, int playerID)
		{
			orig.Invoke(self, playerID);
			((Component)self.playerInBed.refs.headPos).GetComponentInChildren<SnoreSource>().PlaySnore();
			SnoringWarning.Instance.LogDebug("Playing snore");
		}

		private static void MM_Prefix_BedSnoringOff(orig_RPCA_LeaveBed orig, Bed self)
		{
			((Component)self.playerInBed.refs.headPos).GetComponentInChildren<SnoreSource>().StopSnore();
			SnoringWarning.Instance.LogDebug("Stopping snore");
			orig.Invoke(self);
		}
	}
}
namespace SnoringWarning.Behaviours
{
	[RequireComponent(typeof(AudioSource))]
	internal class SnoreSource : MonoBehaviour
	{
		private AudioSource _source;

		public void Start()
		{
			_source = ((Component)this).GetComponent<AudioSource>();
			_source.loop = true;
		}

		internal void UpdateSourceSettings()
		{
			_source.clip = ((SnoringWarningSettings.Snore == SnoringWarningSettings.SnoreType.Silent) ? SnoringWarning.Instance.GetBundleAsset<AudioClip>("snore_mimimi") : SnoringWarning.Instance.GetBundleAsset<AudioClip>("snore_augh"));
			_source.volume = SnoringWarningSettings.Volume;
			SnoringWarning.Instance.LogDebug($"Clip name: {((Object)_source.clip).name}; Volume: {_source.volume}");
		}

		internal void PlaySnore()
		{
			UpdateSourceSettings();
			_source.Play();
		}

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