Decompiled source of stenchofdeath v1.0.1

lol.rek.StenchofDeath.dll

Decompiled 2 months ago
using System;
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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("lol.rek.StenchofDeath")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+9f68655f8ce35a1706bd22b97a5505b8c526fa01")]
[assembly: AssemblyProduct("StenchofDeath")]
[assembly: AssemblyTitle("lol.rek.StenchofDeath")]
[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 StenchofDeath
{
	public static class Assets
	{
		public static GameObject? FlyPrefab { get; set; }
	}
	[BepInPlugin("lol.rek.StenchofDeath", "StenchofDeath", "1.0.1")]
	public class StenchofDeath : BaseUnityPlugin
	{
		public static StenchofDeath Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			Logger.LogInfo((object)"lol.rek.StenchofDeath v1.0.1 making bodies extra stinky");
			Logger.LogInfo((object)"Loading Fly Asset...");
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "symbiosis"));
			Assets.FlyPrefab = val.LoadAsset<GameObject>("assets/symbiosis/prefabs/stenchofdeath.prefab");
			Logger.LogInfo((object)"Finished Loading!");
		}

		internal static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("lol.rek.StenchofDeath");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "lol.rek.StenchofDeath";

		public const string PLUGIN_NAME = "StenchofDeath";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}
namespace StenchofDeath.Patches
{
	[HarmonyPatch]
	public class StenchOfDeathPatch
	{
		private class StenchData
		{
			public DeadBodyInfo? Body;

			public GameObject? Flies;

			public Transform? FliesTransform;

			public ParticleSystem? ParticleSystem;

			public EmissionModule EmissionModule;

			public AudioSource? AudioSource;

			public float TimeSinceDeath;

			public float TimeSinceRotten;

			public bool BodyRotten;

			public void Reset()
			{
				Body = null;
				Flies = null;
				FliesTransform = null;
				ParticleSystem = null;
				AudioSource = null;
				TimeSinceDeath = 0f;
				TimeSinceRotten = 0f;
				BodyRotten = false;
			}
		}

		private const float TIME_TO_ROT = 60f;

		private const float STENCH_DURATION = 30f;

		private const float EMISSION_MULTIPLIER = 10f;

		private const float AUDIO_MULTIPLIER = 0.1f;

		private const int POOL_MAX_SIZE = 32;

		private static readonly List<StenchData> _activeData = new List<StenchData>(32);

		private static readonly Stack<StenchData> _dataPool = new Stack<StenchData>(32);

		private static StenchData GetPooledData()
		{
			if (_dataPool.Count > 0)
			{
				StenchData stenchData = _dataPool.Pop();
				stenchData.Reset();
				return stenchData;
			}
			return new StenchData();
		}

		private static void ReturnToPool(StenchData data)
		{
			if (_dataPool.Count < 32)
			{
				data.Reset();
				_dataPool.Push(data);
			}
		}

		[HarmonyPatch(typeof(DeadBodyInfo), "Start")]
		[HarmonyPostfix]
		private static void StartPostfix(DeadBodyInfo __instance)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			StenchData pooledData = GetPooledData();
			pooledData.Body = __instance;
			_activeData.Add(pooledData);
			pooledData.Flies = Object.Instantiate<GameObject>(Assets.FlyPrefab, ((Component)__instance).transform, true);
			pooledData.FliesTransform = pooledData.Flies.transform;
			pooledData.FliesTransform.localPosition = Vector3.zero;
			pooledData.FliesTransform.localScale = Vector3.one;
			pooledData.ParticleSystem = pooledData.Flies.GetComponent<ParticleSystem>();
			pooledData.EmissionModule = pooledData.ParticleSystem.emission;
			((EmissionModule)(ref pooledData.EmissionModule)).rateOverTime = MinMaxCurve.op_Implicit(0f);
			pooledData.ParticleSystem.Play();
			pooledData.AudioSource = pooledData.Flies.GetComponent<AudioSource>();
			pooledData.AudioSource.volume = 0f;
			pooledData.AudioSource.Play();
		}

		[HarmonyPatch(typeof(DeadBodyInfo), "Update")]
		[HarmonyPostfix]
		private static void UpdatePostfix(DeadBodyInfo __instance)
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			StenchData stenchData = null;
			for (int i = 0; i < _activeData.Count; i++)
			{
				if (!((Object)(object)_activeData[i].Body != (Object)(object)__instance))
				{
					stenchData = _activeData[i];
					break;
				}
			}
			if (stenchData == null)
			{
				return;
			}
			stenchData.TimeSinceDeath += Time.deltaTime;
			if (!stenchData.BodyRotten)
			{
				if (stenchData.TimeSinceDeath >= 60f)
				{
					stenchData.BodyRotten = true;
					stenchData.TimeSinceRotten = stenchData.TimeSinceDeath;
				}
				return;
			}
			float num = stenchData.TimeSinceDeath - stenchData.TimeSinceRotten;
			if (!(num > 30f))
			{
				float num2 = num / 30f;
				((EmissionModule)(ref stenchData.EmissionModule)).rateOverTime = MinMaxCurve.op_Implicit(num2 * 10f);
				stenchData.AudioSource.volume = num2 * 0.1f;
			}
		}

		[HarmonyPatch(typeof(DeadBodyInfo), "OnDestroy")]
		[HarmonyPostfix]
		private static void OnDestroyPostfix(DeadBodyInfo __instance)
		{
			for (int num = _activeData.Count - 1; num >= 0; num--)
			{
				if (!((Object)(object)_activeData[num].Body != (Object)(object)__instance))
				{
					StenchData stenchData = _activeData[num];
					if ((Object)(object)stenchData.Flies != (Object)null)
					{
						Object.Destroy((Object)(object)stenchData.Flies);
					}
					_activeData.RemoveAt(num);
					ReturnToPool(stenchData);
					break;
				}
			}
		}
	}
}