Decompiled source of GitGudDeath v1.0.0

GitGudDeath.dll

Decompiled a month 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.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GitGudDeath")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("GitGudDeath")]
[assembly: AssemblyTitle("GitGudDeath")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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 GitGudDeath
{
	[BepInPlugin("io.github.gitguddeath", "GitGudDeath", "0.1.0")]
	public class GitGudDeathPlugin : BaseUnityPlugin
	{
		[HarmonyPatch]
		public class GameManagerPatch
		{
			[CompilerGenerated]
			private sealed class <MyWrapper>d__2 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public IEnumerator result;

				public float waitTime;

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

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

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

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						gitgud = true;
						GameManagerPatch.waitTime = waitTime;
						break;
					case 1:
						<>1__state = -1;
						break;
					}
					if (result.MoveNext())
					{
						<>2__current = result.Current;
						<>1__state = 1;
						return true;
					}
					gitgud = false;
					return false;
				}

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

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

			private static bool gitgud;

			private static float waitTime;

			[IteratorStateMachine(typeof(<MyWrapper>d__2))]
			[HarmonyPostfix]
			[HarmonyPatch(typeof(GameManager), "PlayerDead")]
			private static IEnumerator MyWrapper(IEnumerator result, float waitTime)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <MyWrapper>d__2(0)
				{
					result = result,
					waitTime = waitTime
				};
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(GameManager), "SaveGame", new Type[]
			{
				typeof(int),
				typeof(Action<bool>),
				typeof(bool),
				typeof(AutoSaveName)
			})]
			private static void SaveGamePrefix(GameManager __instance)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				if ((int)__instance.playerData.permadeathMode == 0 && gitgud)
				{
					((MonoBehaviour)__instance).StartCoroutine(PlayGitGudAfter(waitTime - 1.5f));
				}
				gitgud = false;
			}
		}

		[CompilerGenerated]
		private sealed class <LoadOggAudio>d__6 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public GitGudDeathPlugin <>4__this;

			private UnityWebRequest <request>5__1;

			private AudioClip <audioClip>5__2;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<request>5__1 = null;
				<audioClip>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<request>5__1 = UnityWebRequestMultimedia.GetAudioClip(path, (AudioType)14);
					<>2__current = <request>5__1.SendWebRequest();
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<audioClip>5__2 = DownloadHandlerAudioClip.GetContent(<request>5__1);
					if ((Object)(object)<audioClip>5__2 != (Object)null)
					{
						GitGud = <audioClip>5__2;
						AudioSource.resource = (AudioResource)(object)GitGud;
					}
					return false;
				}
			}

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

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

		[CompilerGenerated]
		private sealed class <PlayGitGudAfter>d__7 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public float time;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(time);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					AudioSource.Play();
					return false;
				}
			}

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

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

		private static AudioClip GitGud;

		private static AudioSource AudioSource;

		private static string path;

		private Harmony harmony;

		public const string Id = "io.github.gitguddeath";

		public static string Name => "GitGudDeath";

		public static string Version => "0.1.0";

		private void Awake()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + Name + " (io.github.gitguddeath) has loaded!"));
			path = Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "gitgud.ogg");
			GameObject val = new GameObject("GitGud");
			AudioSource val2 = val.AddComponent<AudioSource>();
			val2.spatialBlend = 0f;
			Object.DontDestroyOnLoad((Object)(object)val);
			AudioSource = val2;
			((MonoBehaviour)this).StartCoroutine(LoadOggAudio());
			harmony = new Harmony("io.github.gitguddeath");
			harmony.PatchAll();
			SceneManager.sceneLoaded += SceneManager_sceneLoaded;
		}

		private void SceneManager_sceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (((Scene)(ref scene)).name == "PermaDeath")
			{
				((MonoBehaviour)this).StartCoroutine(PlayGitGudAfter(1.5f));
			}
		}

		[IteratorStateMachine(typeof(<LoadOggAudio>d__6))]
		private IEnumerator LoadOggAudio()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadOggAudio>d__6(0)
			{
				<>4__this = this
			};
		}

		[IteratorStateMachine(typeof(<PlayGitGudAfter>d__7))]
		private static IEnumerator PlayGitGudAfter(float time)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <PlayGitGudAfter>d__7(0)
			{
				time = time
			};
		}
	}
}