Decompiled source of TurretMeCorro v1.0.2

RivalSilver97.TurretMeCorro.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
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 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("RivalSilver97.TurretMeCorro")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RivalSilver97.TurretMeCorro")]
[assembly: AssemblyTitle("RivalSilver97.TurretMeCorro")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 CustomTurretSound
{
	[BepInPlugin("RivalSilver97.TurretMeCorro", "Turret - Me Corro", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static AudioClip CustomSeePlayerSFX;

		public static Plugin Instance;

		public static ManualLogSource Logger;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("RivalSilver97.TurretMeCorro");
			_harmony.PatchAll(typeof(TurretAudioPatch));
			((MonoBehaviour)this).StartCoroutine(LoadAudioFile());
		}

		private IEnumerator LoadAudioFile()
		{
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			string text = Path.Combine(directoryName, "TurretSeePlayer.wav");
			if (!File.Exists(text))
			{
				string[] files = Directory.GetFiles(directoryName, "*.wav");
				if (files.Length == 0)
				{
					Logger.LogError((object)("[TurretMeCorro] ¡NO SE ENCONTRÓ NINGÚN ARCHIVO .WAV en " + directoryName + "!"));
					yield break;
				}
				text = files[0];
			}
			Logger.LogInfo((object)("[TurretMeCorro] Cargando archivo de sonido desde: " + text));
			string absoluteUri = new Uri(text).AbsoluteUri;
			UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(absoluteUri, (AudioType)20);
			try
			{
				yield return www.SendWebRequest();
				if ((int)www.result == 1)
				{
					CustomSeePlayerSFX = DownloadHandlerAudioClip.GetContent(www);
					((Object)CustomSeePlayerSFX).name = "TurretSeePlayer";
					Logger.LogInfo((object)"[TurretMeCorro] ¡Sonido 'TurretSeePlayer.wav' cargado y listo en memoria!");
				}
				else
				{
					Logger.LogError((object)("[TurretMeCorro] Error al cargar el audio: " + www.error));
				}
			}
			finally
			{
				((IDisposable)www)?.Dispose();
			}
		}
	}
	[HarmonyPatch(typeof(Turret))]
	internal class TurretAudioPatch
	{
		private static bool hasShownTip;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void OverrideTurretDetectSound(Turret __instance)
		{
			if ((Object)(object)Plugin.CustomSeePlayerSFX != (Object)null)
			{
				__instance.detectPlayerSFX = Plugin.CustomSeePlayerSFX;
				Plugin.Logger.LogInfo((object)"[TurretMeCorro] Sonido personalizado asignado a la torreta con éxito.");
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void CheckTurretTarget(Turret __instance)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			if ((Object)(object)__instance.targetPlayerWithRotation != (Object)null)
			{
				if ((Object)(object)__instance.targetPlayerWithRotation == (Object)(object)GameNetworkManager.Instance.localPlayerController && !hasShownTip)
				{
					hasShownTip = true;
					if ((Object)(object)HUDManager.Instance != (Object)null)
					{
						HUDManager.Instance.DisplayTip("¡ME CORROOOOOOO!", "¡ME CORROOOOOOO!", true, false, "LC_Tip1");
					}
				}
			}
			else
			{
				hasShownTip = false;
			}
		}
	}
}