Mods/Gore.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Gore;
using HarmonyLib;
using Il2CppFemur;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using Microsoft.CodeAnalysis;
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(global::Gore.Gore), "Gore", "0.0.1", "dotpy", "https://github.com/HueSamai/CementMods/releases")]
[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+ce455c8de0b60fb4a68825a50b9911a612ebfe5d")]
[assembly: AssemblyProduct("Gore")]
[assembly: AssemblyTitle("Gore")]
[assembly: NeutralResourcesLanguage("en-US")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Gore
{
	public class Gore : MelonMod
	{
		[HarmonyPatch(typeof(CollisionHandeler), "OnCollisionEnter")]
		private static class CollisionHandlerPatch
		{
			public static void Prefix(CollisionHandeler __instance, Collision collision)
			{
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: 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))
					{
						return;
					}
					Vector3 relativeVelocity = collision.relativeVelocity;
					float magnitude = ((Vector3)(ref relativeVelocity)).magnitude;
					if (!(magnitude < cachedVelocityThreshold))
					{
						ContactPoint contact = collision.GetContact(0);
						GameObject item = Object.Instantiate<GameObject>(bloodParticlePrefab, ((ContactPoint)(ref contact)).point, Quaternion.FromToRotation(Vector3.up, ((ContactPoint)(ref contact)).normal));
						Bloods.Add(item);
						Times.Add((int)(particleDuration + 3f) * 50);
						if (Bloods.Count > 19)
						{
							Object.Destroy((Object)(object)Bloods[0]);
							Bloods.RemoveAt(0);
							Times.RemoveAt(0);
						}
					}
				}
				catch (Exception ex)
				{
					Melon<Gore>.Logger.Error((object)ex);
				}
			}
		}

		[HarmonyPatch(typeof(StatusHandeler), "KillBeast")]
		public class CleanUpPatch
		{
			[HarmonyPostfix]
			public static void Postfix(StatusHandeler __instance)
			{
				if ((Object)(object)((Component)__instance).gameObject != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)__instance).gameObject);
				}
			}
		}

		public static float cachedVelocityThreshold;

		private static GameObject bloodParticlePrefab;

		private static float particleDuration;

		private static List<GameObject> Bloods = new List<GameObject>();

		private static List<int> Times = new List<int>();

		private static int currentFrame = 0;

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

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			Times.Clear();
			Bloods.Clear();
		}

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

		public override void OnFixedUpdate()
		{
			currentFrame++;
			for (int i = 0; i < Bloods.Count; i++)
			{
				if (Times[i] >= currentFrame)
				{
					Times.RemoveAt(i);
					Object.Destroy((Object)(object)Bloods[i]);
					Bloods.RemoveAt(i);
				}
			}
		}
	}
	public static class UnityObjectUtilities
	{
		public static void MakePersistent(this Object objec, bool dontDestroyOnLoad = false)
		{
			objec.hideFlags = (HideFlags)61;
			if (dontDestroyOnLoad)
			{
				Object.DontDestroyOnLoad(objec);
			}
		}
	}
	public static class Utilities
	{
		public static T? LoadPersistentAsset<T>(this AssetBundle bundle, string name) where T : Object
		{
			T val = bundle.LoadAsset<T>(name);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return default(T);
			}
			MakePersistent((Object)(object)val);
			return val;
		}

		public static AssetBundle LoadEmbeddedAssetBundle(Assembly assembly, string name)
		{
			if (((ReadOnlySpan<string>)assembly.GetManifestResourceNames()).Contains(name))
			{
				using (Stream stream = assembly.GetManifestResourceStream(name) ?? throw new Exception("Resource stream returned null. This could mean an inaccessible resource caller-side or an invalid argument was passed."))
				{
					using MemoryStream memoryStream = new MemoryStream();
					stream.CopyTo(memoryStream);
					byte[] array = memoryStream.ToArray();
					return AssetBundle.LoadFromMemory(Il2CppStructArray<byte>.op_Implicit(array));
				}
			}
			throw new Exception($"No resources matching the name '{name}' were found in the assembly '{assembly.FullName}'. Please ensure you passed the correct name.");
		}

		public static void MakePersistent(this Object objec, bool dontDestroyOnLoad = false)
		{
			objec.hideFlags = (HideFlags)61;
			if (dontDestroyOnLoad)
			{
				Object.DontDestroyOnLoad(objec);
			}
		}
	}
}