Decompiled source of CrushableHeads v1.1.2

CrushableHeads.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using CrushableHeads;
using HBMF.AudioImporter;
using HBMF.GameResources;
using HBMF.ModMenu;
using HarmonyLib;
using Il2Cpp;
using Il2CppInteractionSystem;
using MelonLoader;
using MelonLoader.Preferences;
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(Mod), "CrushableHeads", "1.1.2", "korbykob", null)]
[assembly: MelonGame("GexagonVR", "Hard Bullet")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CrushableHeads")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CrushableHeads")]
[assembly: AssemblyTitle("CrushableHeads")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CrushableHeads;

[HarmonyPatch]
public class Mod : MelonMod
{
	private AudioClip crush;

	private bool crushing = false;

	private float crushingTime;

	private static GameObject skull;

	private static MelonPreferences_Entry<bool> enabled;

	public override void OnInitializeMelon()
	{
		MemoryStream memoryStream = new MemoryStream();
		Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("CrushableHeads.Crush.wav");
		manifestResourceStream.CopyTo(memoryStream);
		manifestResourceStream.Close();
		crush = Audio.Import(memoryStream.ToArray());
		memoryStream.Close();
		enabled = MelonPreferences.CreateCategory("CrushableHeads").CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		Menu.CreateCategory("CRUSHABLE HEADS").CreateBool("ENABLE", enabled.Value, (Action<bool>)delegate(bool value)
		{
			enabled.Value = value;
		});
	}

	public override void OnUpdate()
	{
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Expected O, but got Unknown
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		if (enabled.Value && (Object)(object)GameResources.LeftGrabber != (Object)null && (Object)(object)GameResources.RightGrabber != (Object)null && ((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab != null && ((AbstractGrabber)GameResources.RightGrabber).CurrentGrab != null && (Object)(object)((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab.Grabbable == (Object)(object)((AbstractGrabber)GameResources.RightGrabber).CurrentGrab.Grabbable && ((Object)((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab.Grabbable).name == "head" && (Object)(object)((Component)((Component)((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab.Grabbable).transform.parent.parent.parent).GetComponent<EnemyRoot>() != (Object)null && skull.activeSelf && Vector3.Distance(GameResources.TrueLeftHand.position, GameResources.TrueRightHand.position) <= 0.125f)
		{
			if (!crushing)
			{
				crushingTime = Time.time;
				crushing = true;
			}
			else if (Time.time - crushingTime >= 0.5f)
			{
				AudioSource val = ((Component)((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab.Grabbable).gameObject.AddComponent<AudioSource>();
				val.clip = crush;
				val.Play(new PlaySettings
				{
					Attached = false
				});
				HealthContainer component = ((Component)((Component)((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab.Grabbable).transform.parent.parent.parent.Find("[SYSTEMS]/AI/Health")).GetComponent<HealthContainer>();
				if (!component.IgnoreDamage)
				{
					component.RemoveHealth(float.PositiveInfinity);
				}
				((Component)((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab.Grabbable).GetComponent<Attachable>().ForceDetachAll();
				((Component)((Component)((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab.Grabbable).transform.parent.parent.parent.Find("[SYSTEMS]/Violence/Dismemberment")).GetComponent<DismembermentDebug>().DetachLimbByLimbPart((LimbPart)0);
				((Component)((Component)((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab.Grabbable).transform.Find("Colliders[Head]")).GetComponent<ColliderContainer>().DeactivateAllColliders();
				skull.SetActive(false);
				((Component)((Component)((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab.Grabbable).transform.parent.parent.Find("AnimatorBones/root/pelvis/spine_01/spine_02/spine_03/neck_01/head/PhysicalJawTarget/CC_Base_JawRoot/JawModel")).gameObject.SetActive(false);
				MelonCoroutines.Start(Hide(((Component)((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab.Grabbable).transform.parent.parent.parent.Find("[DATA STORAGES]/MeshesStorage/Activated")));
				((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab.Grabbable.ForceUngrab();
			}
			else
			{
				GameResources.InputManager.LeftController.Vibrate(0.2f, 0.1f, 1f);
				GameResources.InputManager.RightController.Vibrate(0.2f, 0.1f, 1f);
			}
		}
		else
		{
			crushing = false;
		}
	}

	private static IEnumerator Hide(Transform meshes)
	{
		yield return (object)new WaitForEndOfFrame();
		foreach (Transform part in ((Component)meshes).GetComponentsInChildren<Transform>())
		{
			if (((Object)part).name.EndsWith("[Head][POSITIVE]"))
			{
				((Component)part).gameObject.SetActive(false);
			}
		}
	}

	[HarmonyPatch(typeof(Resurrector), "Resurrect")]
	[HarmonyPrefix]
	public static void RestoreHead(Resurrector __instance)
	{
		GameObject gameObject = ((Component)((Component)__instance).transform.parent.parent.parent.Find("[BODY]/AnimatorBones/root/pelvis/spine_01/spine_02/spine_03/neck_01/head/SkullModel")).gameObject;
		if (!gameObject.activeSelf)
		{
			((Component)((Component)__instance).transform.parent.parent.parent.Find("[BODY]/PhysicalBones/head/Colliders[Head]")).GetComponent<ColliderContainer>().ActivateAllColliders();
			gameObject.SetActive(true);
			((Component)((Component)__instance).transform.parent.parent.parent.Find("[BODY]/AnimatorBones/root/pelvis/spine_01/spine_02/spine_03/neck_01/head/PhysicalJawTarget/CC_Base_JawRoot/JawModel")).gameObject.SetActive(true);
		}
	}

	[HarmonyPatch(typeof(Grabbable), "AttemptGrab", new Type[]
	{
		typeof(AbstractGrabber),
		typeof(AbstractGrabPoint),
		typeof(GrabType),
		typeof(ConfigurableJoint)
	})]
	[HarmonyPostfix]
	public static void GrabPatch(Grabbable __instance)
	{
		if (((Object)__instance).name == "head" && (Object)(object)((Component)((Component)__instance).transform.parent.parent.parent).GetComponent<EnemyRoot>() != (Object)null)
		{
			skull = ((Component)((Component)__instance).transform.parent.parent.Find("AnimatorBones/root/pelvis/spine_01/spine_02/spine_03/neck_01/head/SkullModel")).gameObject;
		}
	}
}