Gore.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using CementGB.Mod.Modules.PoolingModule;
using CementGB.Mod.Utilities;
using HarmonyLib;
using Il2CppFemur;
using MelonLoader;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Gore), "Gore", "0.0.2", "dotpy", null)]
[assembly: MelonGame("Boneloaf", "Gang Beasts")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Gore")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Gore")]
[assembly: AssemblyTitle("Gore")]
[assembly: AssemblyVersion("1.0.0.0")]
public class Gore : MelonMod
{
	[HarmonyPatch(typeof(CollisionHandeler), "OnCollisionEnter")]
	private static class CollisionHandlerPatch
	{
		public static void Prefix(CollisionHandeler __instance, Collision collision)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				CollisionHandeler componentInParent = collision.gameObject.GetComponentInParent<CollisionHandeler>();
				if ((Object)(object)componentInParent != (Object)null && (Object)(object)__instance.actor != (Object)(object)componentInParent.actor)
				{
					Vector3 relativeVelocity = collision.relativeVelocity;
					float magnitude = ((Vector3)(ref relativeVelocity)).magnitude;
					if (!(magnitude < cachedVelocityThreshold))
					{
						ContactPoint contact = collision.GetContact(0);
						GameObject gameObject = Pool.Instantiate(bloodParticlePrefab, ((ContactPoint)(ref contact)).point, Quaternion.FromToRotation(Vector3.up, ((ContactPoint)(ref contact)).normal));
						AddBloodToPool(gameObject);
					}
				}
			}
			catch (Exception ex)
			{
				Melon<Gore>.Logger.Error((object)ex);
			}
		}
	}

	public static float cachedVelocityThreshold;

	private static GameObject bloodParticlePrefab;

	private static float particleDuration;

	private static Dictionary<GameObject, float> bloodToPool = new Dictionary<GameObject, float>();

	public override void OnLateInitializeMelon()
	{
		AssetBundle val = EmbeddedUtilities.LoadEmbeddedAssetBundle(Assembly.GetExecutingAssembly(), "Gore.gore");
		bloodParticlePrefab = AssetUtilities.LoadPersistentAsset<GameObject>(val, "Blood Particles");
		val.Unload(false);
		particleDuration = bloodParticlePrefab.GetComponent<ParticleSystem>().main.duration;
		Pool.RegisterPrefab(bloodParticlePrefab, (Action<GameObject>)ResetBlood);
		CacheVelocityThreshold();
	}

	public static void AddBloodToPool(GameObject gameObject)
	{
		bloodToPool[gameObject] = particleDuration + 0.5f;
	}

	private void CacheVelocityThreshold()
	{
		cachedVelocityThreshold = 14f;
	}

	public void ResetBlood(GameObject bloodParticles)
	{
		ParticleSystem component = bloodParticles.GetComponent<ParticleSystem>();
		component.Clear();
		component.Play();
	}

	public override void OnUpdate()
	{
		foreach (GameObject key in bloodToPool.Keys)
		{
			if (bloodToPool[key] < 0f)
			{
				Pool.PoolObject(key);
				bloodToPool.Remove(key);
			}
			else
			{
				bloodToPool[key] -= Time.deltaTime;
			}
		}
	}
}