Decompiled source of GtaVDeathSound v1.0.0

GtaVDeathSound.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("GtaVDeathSound")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GtaVDeathSound")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("36720953-f415-4bc9-b728-8bdea912bada")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GtaVDeathSoundMod
{
	[BepInPlugin("com.yourname.gtavdeathsound", "GTA V Death Sound Mod", "1.0.0")]
	public class GtaVDeathSound : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <LoadClip>d__3 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public string path;

			public GtaVDeathSound <>4__this;

			private string <uri>5__1;

			private AudioType <type>5__2;

			private UnityWebRequest <www>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <LoadClip>d__3(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<uri>5__1 = null;
				<www>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00af: Invalid comparison between Unknown and I4
				bool result;
				try
				{
					switch (<>1__state)
					{
					default:
						result = false;
						break;
					case 0:
						<>1__state = -1;
						<uri>5__1 = "file://" + path;
						<type>5__2 = (AudioType)(path.EndsWith(".wav") ? 20 : 14);
						<www>5__3 = UnityWebRequestMultimedia.GetAudioClip(<uri>5__1, <type>5__2);
						<>1__state = -3;
						<>2__current = <www>5__3.SendWebRequest();
						<>1__state = 1;
						result = true;
						break;
					case 1:
						<>1__state = -3;
						if ((int)<www>5__3.result != 1)
						{
							((BaseUnityPlugin)<>4__this).Logger.LogError((object)("GtaVDeathSound: Error loading clip – " + <www>5__3.error));
							result = false;
							<>m__Finally1();
						}
						else
						{
							deathClip = DownloadHandlerAudioClip.GetContent(<www>5__3);
							((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"GtaVDeathSound: Successfully loaded death sound.");
							<>m__Finally1();
							<www>5__3 = null;
							result = false;
						}
						break;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<www>5__3 != null)
				{
					((IDisposable)<www>5__3).Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		internal static AudioClip deathClip;

		private static string fileName = "gtavdeath.ogg";

		private void Awake()
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			((BaseUnityPlugin)this).Logger.LogInfo((object)"GtaVDeathSound: Loading external death sound...");
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), fileName);
			if (!File.Exists(text))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("GtaVDeathSound: File not found: " + text));
				return;
			}
			((MonoBehaviour)this).StartCoroutine(LoadClip(text));
			new Harmony("com.yourname.gtavdeathsound").PatchAll();
		}

		[IteratorStateMachine(typeof(<LoadClip>d__3))]
		private IEnumerator LoadClip(string path)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadClip>d__3(0)
			{
				<>4__this = this,
				path = path
			};
		}
	}
}
namespace GtaVDeathSoundMod.Patches
{
	[HarmonyPatch(typeof(PlayerDeathEffects))]
	[HarmonyPatch("Start")]
	public class PlayerDeathEffectsPatch
	{
		[HarmonyPostfix]
		public static void Postfix(PlayerDeathEffects __instance)
		{
			if (__instance?.deathSound != null && (Object)(object)GtaVDeathSound.deathClip != (Object)null)
			{
				__instance.deathSound.Sounds = (AudioClip[])(object)new AudioClip[1] { GtaVDeathSound.deathClip };
				Debug.Log((object)"GtaVDeathSound: Replaced death sound with external clip.");
			}
			else
			{
				Debug.LogWarning((object)"GtaVDeathSound: Could not replace sound — deathSound or clip is null.");
			}
		}
	}
}