Decompiled source of GlueFix v0.0.5

GlueFix.dll

Decompiled 8 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AIGraph;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using HarmonyLib;
using Il2CppSystem;
using LevelGeneration;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("GlueFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GlueFix")]
[assembly: AssemblyTitle("GlueFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace GlueFix
{
	[BepInPlugin("GlueFix", "GlueFix", "0.0.5")]
	public class Plugin : BasePlugin
	{
		public class GlueFix : MonoBehaviour
		{
			public static void Initialize()
			{
				foreach (InfectionSpitter item in Object.FindObjectsOfType<InfectionSpitter>())
				{
					CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(SpitterKiller(item)), (Action)null);
				}
				foreach (CellSoundEmitter item2 in Object.FindObjectsOfType<CellSoundEmitter>())
				{
					Behaviour component = ((Component)item2).GetComponent<Behaviour>();
					if ((Object)(object)component != (Object)null)
					{
						component.enabled = false;
					}
					((MonoBehaviour)item2).StopAllCoroutines();
					item2.StopSound();
					if (item2.m_sound != null)
					{
						item2.m_sound.Recycle();
					}
					Debug.Log(Object.op_Implicit("GlueFix - removed sound from " + ((Object)((Component)((Component)item2).transform.parent).gameObject).name));
				}
			}

			public static void GlueKiller(GlueGunProjectile blob)
			{
				CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(GlueFixer(blob)), (Action)null);
			}

			public static IEnumerator SpitterKiller(InfectionSpitter spit)
			{
				AIG_CourseNode node = spit.m_courseNode;
				int id = ((Object)spit).GetInstanceID();
				PlayerAgent plr = PlayerManager.GetLocalPlayerAgent();
				while (true)
				{
					if (plr.m_courseNode != node && spit.m_sound != null && spit.m_purrLoopPlaying)
					{
						spit.m_purrLoopPlaying = false;
						spit.CleanupSound();
						Debug.Log(Object.op_Implicit($"GlueFix - removed audio from spitter {id} in zone {spit.m_courseNode.m_zone.ID} area {spit.m_courseNode.m_area.UID}"));
					}
					yield return (object)new WaitForSeconds(1f);
				}
			}

			public static IEnumerator GlueFixer(GlueGunProjectile blob)
			{
				float alku = Clock.Time;
				yield return (object)new WaitForSeconds(6f);
				_ = blob.SyncID;
				if (!((Object)(object)blob != (Object)null))
				{
					yield break;
				}
				while ((Object)(object)blob != (Object)null)
				{
					float num = Clock.Time - alku;
					if ((int)blob.m_collisionLandingType == 5 && !((StickingProjectileBase)blob).CollisionCheck(false))
					{
						Debug.Log(Object.op_Implicit($"GlueFix: destroy hovering blob {blob.SyncID}"));
						if (blob.m_sound != null)
						{
							blob.m_sound.Recycle();
						}
						blob.m_sound = null;
						ProjectileManager.WantToDestroyGlue(blob.SyncID);
					}
					if ((int)blob.m_collisionLandingType == 4)
					{
						if ((Object)(object)((Component)((StickingProjectileBase)blob).m_projLastRayHitCollider).gameObject == (Object)null)
						{
							Debug.Log(Object.op_Implicit($"a true orphan is found and removed {blob.SyncID}"));
							if (blob.m_sound != null)
							{
								blob.m_sound.Recycle();
							}
							blob.m_sound = null;
							ProjectileManager.WantToDestroyGlue(blob.SyncID);
						}
						if ((Object)(object)((Component)((StickingProjectileBase)blob).m_projLastRayHitCollider).gameObject != (Object)null)
						{
							LG_WeakDoor componentInParent = ((Component)((StickingProjectileBase)blob).m_projLastRayHitCollider).gameObject.GetComponentInParent<LG_WeakDoor>();
							if ((Object)(object)componentInParent == (Object)null)
							{
								if (blob.m_sound != null)
								{
									blob.m_sound.Recycle();
								}
								blob.m_sound = null;
								ProjectileManager.WantToDestroyGlue(blob.SyncID);
							}
							if ((Object)(object)componentInParent != (Object)null && (int)componentInParent.LastStatus == 11)
							{
								if (blob.m_sound != null)
								{
									blob.m_sound.Recycle();
								}
								blob.m_sound = null;
								ProjectileManager.WantToDestroyGlue(blob.SyncID);
								Debug.Log(Object.op_Implicit($"GlueFix: destroy blob of destroyed door {blob.SyncID}"));
							}
						}
					}
					if (num > 257f && (int)blob.m_collisionLandingType != 4)
					{
						Debug.Log(Object.op_Implicit($"GlueFix: destroy ghost blob {blob.SyncID}"));
						if (blob.m_sound != null)
						{
							blob.m_sound.Recycle();
						}
						blob.m_sound = null;
						ProjectileManager.WantToDestroyGlue(blob.SyncID);
					}
					yield return (object)new WaitForSeconds(1f);
				}
			}
		}

		[HarmonyPatch(typeof(GlueGunProjectile), "Awake")]
		private class CfoamDebugPatches
		{
			[HarmonyPostfix]
			private static void Postfix(GlueGunProjectile __instance)
			{
				GlueFix.GlueKiller(__instance);
			}

			[HarmonyPatch(typeof(GlueGunProjectile), "SyncDestroy")]
			[HarmonyPrefix]
			private static bool Prefix(GlueGunProjectile __instance)
			{
				if (__instance.m_sound != null)
				{
					Debug.Log(Object.op_Implicit("GlueFix: blob destroyed, m_sound recycled"));
					__instance.m_sound.Recycle();
				}
				return true;
			}

			[HarmonyPatch(typeof(Item), "OnDespawn")]
			[HarmonyPrefix]
			private static void KillSound(Item __instance)
			{
				CellSoundPlayer component = ((Component)__instance).GetComponent<CellSoundPlayer>();
				if (component != null)
				{
					component.Recycle();
					Debug.Log(Object.op_Implicit("GlueFix - CellSoundPlayer of item " + ((Object)((Component)__instance).gameObject).name + " was recycled"));
				}
			}
		}

		public override void Load()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("GlueFix").PatchAll();
			((BasePlugin)this).AddComponent<GlueFix>();
			LG_Factory.OnFactoryBuildDone += Action.op_Implicit((Action)GlueFix.Initialize);
		}
	}
	[GeneratedCode("VersionInfoGenerator", "2.0.0+git50a4b1a-master")]
	[CompilerGenerated]
	internal static class VersionInfo
	{
		public const string RootNamespace = "GlueFix";

		public const string Version = "1.0.0";

		public const string VersionPrerelease = null;

		public const string VersionMetadata = null;

		public const string SemVer = "1.0.0";

		public const string GitRevShort = null;

		public const string GitRevLong = null;

		public const string GitBranch = null;

		public const string GitTag = null;

		public const bool GitIsDirty = false;
	}
}