Decompiled source of DapMeUp v1.0.1

plugins/com.dharsi.dapmeup.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.dharsi.dapmeup")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("com.dharsi.dapmeup")]
[assembly: AssemblyTitle("DapMeUp")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 DapMeUp
{
	[BepInPlugin("com.dharsi.dapmeup", "DapMeUp", "1.0.1")]
	public class DapMeUpPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Character), "Awake")]
		private static class CharacterAwake
		{
			private static void Postfix(Character __instance)
			{
				if (customAudio.Length != 0)
				{
					soundPlayer = ((Component)__instance).gameObject.AddComponent<SoundPlayer>();
					Log.LogInfo((object)"SoundPlayer added!");
				}
			}
		}

		[HarmonyPatch(typeof(GUIManager), "Grasp")]
		private static class PlayDapSFXPatch
		{
			private static void Postfix(GUIManager __instance)
			{
				if (customAudio.Length != 0)
				{
					Log.LogInfo((object)"Calling SoundPlayer");
					soundPlayer.Dap(((MonoBehaviourPun)((Component)soundPlayer).gameObject.GetComponent<Character>()).photonView.ViewID);
				}
			}
		}

		private static string folderPath;

		internal static AudioClip[] customAudio;

		internal static SoundPlayer soundPlayer;

		public const string Id = "com.dharsi.dapmeup";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "DapMeUp";

		public static string Version => "1.0.1";

		private void Awake()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " is loading!"));
			List<string> list = Directory.GetDirectories(Paths.PluginPath, "assets", SearchOption.AllDirectories).ToList();
			if (!list.Any())
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Couldn't find assets folder");
				return;
			}
			folderPath = list[0];
			((BaseUnityPlugin)this).Logger.LogInfo((object)(folderPath + " is the sound path."));
			Harmony val = new Harmony("com.dharsi.dapmeup");
			val.PatchAll();
			LoadAudio();
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}

		private void LoadAudio()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Invalid comparison between Unknown and I4
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Invalid comparison between Unknown and I4
			Log.LogInfo((object)("Looking for oggs in: " + folderPath));
			string[] files = Directory.GetFiles(folderPath, "*.ogg");
			if (files.Length == 0)
			{
				Log.LogWarning((object)"No ogg file found.");
				return;
			}
			customAudio = (AudioClip[])(object)new AudioClip[files.Length];
			for (int i = 0; i < files.Length; i++)
			{
				string text = "file://" + files[i];
				UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(text, (AudioType)14);
				try
				{
					audioClip.SendWebRequest();
					try
					{
						while (!audioClip.isDone)
						{
						}
						if ((int)audioClip.result == 2 || (int)audioClip.result == 3)
						{
							Log.LogInfo((object)("Failed to load ogg file: " + audioClip.error));
							break;
						}
						AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
						customAudio[i] = content;
						Log.LogInfo((object)("Loaded ogg file: " + files[i]));
					}
					catch (Exception ex)
					{
						((BaseUnityPlugin)this).Logger.LogError((object)(ex.Message + ", " + ex.StackTrace));
					}
				}
				finally
				{
					((IDisposable)audioClip)?.Dispose();
				}
			}
		}
	}
	public class SoundPlayer : MonoBehaviour
	{
		private SFX_Instance dapSFX;

		internal float timeSinceDap;

		internal bool currentlyDapping;

		private void Awake()
		{
			//IL_007b: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			dapSFX = ScriptableObject.CreateInstance<SFX_Instance>();
			if (DapMeUpPlugin.customAudio.Length == 0)
			{
				DapMeUpPlugin.Log.LogError((object)"customAudio length is 0");
				return;
			}
			dapSFX.clips = (AudioClip[])(object)new AudioClip[DapMeUpPlugin.customAudio.Length];
			for (int i = 0; i < dapSFX.clips.Length; i++)
			{
				DapMeUpPlugin.Log.LogInfo((object)"appending audio clip");
				dapSFX.clips[i] = DapMeUpPlugin.customAudio[i];
			}
			dapSFX.settings = new SFX_Settings
			{
				volume = 0.5f,
				volume_Variation = 0.2f,
				pitch = 1f,
				pitch_Variation = 0.1f,
				spatialBlend = 1f,
				dopplerLevel = 1f,
				range = 150f,
				cooldown = 0.02f,
				maxInstances_NOT_IMPLEMENTED = 5
			};
		}

		private void Update()
		{
			if (currentlyDapping)
			{
				timeSinceDap += Time.deltaTime;
				if (timeSinceDap > 1f)
				{
					currentlyDapping = false;
				}
			}
		}

		public void Dap(int photonID)
		{
			PlaySoundGlobal(photonID);
			currentlyDapping = true;
			timeSinceDap = 0f;
		}

		public void PlaySoundGlobal(int photonID)
		{
			DapMeUpPlugin.Log.LogInfo((object)("SoundPlayer called with ID " + photonID));
			if (currentlyDapping)
			{
				DapMeUpPlugin.Log.LogInfo((object)"Already dapping!");
				return;
			}
			Character val = null;
			if (Character.GetCharacterWithPhotonID(photonID, ref val))
			{
				SoundPlayer component = ((Component)val).GetComponent<SoundPlayer>();
				component.PlaySound(val);
			}
			else
			{
				DapMeUpPlugin.Log.LogError((object)("Couldn't find Character from photon ID " + photonID));
			}
		}

		public void PlaySound(Character __instance)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			DapMeUpPlugin.Log.LogInfo((object)"Playing sound!");
			SFX_Instance val = dapSFX;
			if ((Object)val != (Object)null)
			{
				val.Play(__instance.Center);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}