Decompiled source of RipAndTear v1.2.0

Mods/RipAndTear.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2Cpp;
using Il2CppDinoFracture;
using Il2CppHurricaneVR.Framework.Core;
using Il2CppHurricaneVR.Framework.Core.Grabbers;
using Il2CppSystem;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using RipAndTear;
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(Core), "RipAndTear", "1.2.0", "MajedCT", null)]
[assembly: MelonGame("Kubunautilus", "BrutalistickVR")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RipAndTear")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RipAndTear")]
[assembly: AssemblyTitle("RipAndTear")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RipAndTear
{
	public class Core : MelonMod
	{
		[HarmonyPatch(typeof(HVRGrabbable), "InternalOnGrabbed")]
		public static class PatchGrab
		{
			private static void Postfix(HVRGrabbable __instance)
			{
				if ((((Object)__instance).name == "Neck" && !removeNeckGib.Value) || ((Object)__instance).name == "Head" || ((Object)__instance).name == "Jaw" || ((Object)__instance).name == "UpperChest" || ((Object)__instance).name == "MiddleChest" || ((Object)__instance).name == "Knee_L" || ((Object)__instance).name == "Pelvis" || ((Object)__instance).name == "Shoulder_R" || ((Object)__instance).name == "Elbow_R" || ((Object)__instance).name == "Elbow_L" || ((Object)__instance).name == "Hip_R" || ((Object)__instance).name == "Shoulder_L" || ((Object)__instance).name == "Knee_R" || ((Object)__instance).name == "Hip_L" || ((Object)__instance).name == "Foot_R" || ((Object)__instance).name == "Foot_L")
				{
					SliceOnInputCustom component = ((Component)__instance).GetComponent<SliceOnInputCustom>();
					HVRGrabbable component2 = ((Component)__instance).GetComponent<HVRGrabbable>();
					SliceManager(component, component2, ((Object)__instance).GetInstanceID());
				}
			}
		}

		[HarmonyPatch(typeof(HVRGrabbable), "InternalOnReleased")]
		public static class PatchUnGrab
		{
			private static void Postfix(HVRGrabbable __instance)
			{
				if ((((Object)__instance).name == "Neck" && !removeNeckGib.Value) || ((Object)__instance).name == "Head" || ((Object)__instance).name == "Jaw" || ((Object)__instance).name == "UpperChest" || ((Object)__instance).name == "MiddleChest" || ((Object)__instance).name == "Knee_L" || ((Object)__instance).name == "Pelvis" || ((Object)__instance).name == "Shoulder_R" || ((Object)__instance).name == "Elbow_R" || ((Object)__instance).name == "Elbow_L" || ((Object)__instance).name == "Hip_R" || ((Object)__instance).name == "Shoulder_L" || ((Object)__instance).name == "Knee_R" || ((Object)__instance).name == "Hip_L" || ((Object)__instance).name == "Foot_R" || ((Object)__instance).name == "Foot_L")
				{
					SliceOnInputCustom component = ((Component)__instance).GetComponent<SliceOnInputCustom>();
					HVRGrabbable component2 = ((Component)__instance).GetComponent<HVRGrabbable>();
					SliceManagerNullifier(component, component2, ((Object)__instance).GetInstanceID());
				}
			}
		}

		[CompilerGenerated]
		private sealed class <GrabAfterFracture>d__17 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public SliceOnInputCustom original;

			public HVRHandGrabber hand;

			public Core <>4__this;

			private Transform <root>5__1;

			private Transform <chunks>5__2;

			private Transform <fracRoot>5__3;

			private HVRGrabbable <best>5__4;

			private float <bestVol>5__5;

			private int <i>5__6;

			private Transform <c>5__7;

			private IEnumerator<HVRGrabbable> <>s__8;

			private HVRGrabbable <g>5__9;

			private Renderer <r>5__10;

			private Vector3 <e>5__11;

			private float <vol>5__12;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <GrabAfterFracture>d__17(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<root>5__1 = null;
				<chunks>5__2 = null;
				<fracRoot>5__3 = null;
				<best>5__4 = null;
				<c>5__7 = null;
				<>s__8 = null;
				<g>5__9 = null;
				<r>5__10 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 3;
					return true;
				case 3:
					<>1__state = -1;
					<root>5__1 = ((Component)original).transform.parent.parent;
					<chunks>5__2 = <root>5__1.Find("Chunks");
					<fracRoot>5__3 = null;
					<i>5__6 = 0;
					while (<i>5__6 < <chunks>5__2.childCount)
					{
						<c>5__7 = <chunks>5__2.GetChild(<i>5__6);
						if (((Object)<c>5__7).name.Contains(((Object)((Component)original).gameObject).name))
						{
							<fracRoot>5__3 = <c>5__7;
							break;
						}
						<i>5__6++;
					}
					<best>5__4 = null;
					<bestVol>5__5 = 0f;
					<>s__8 = ((Component)<fracRoot>5__3).gameObject.GetComponentsInChildren<HVRGrabbable>(true).GetEnumerator();
					try
					{
						while (<>s__8.MoveNext())
						{
							<g>5__9 = <>s__8.Current;
							<r>5__10 = ((Component)<g>5__9).GetComponentInChildren<Renderer>();
							if (!((Object)(object)<r>5__10 == (Object)null))
							{
								Bounds bounds = <r>5__10.bounds;
								<e>5__11 = ((Bounds)(ref bounds)).extents;
								<vol>5__12 = <e>5__11.x * <e>5__11.y * <e>5__11.z;
								if (<vol>5__12 > <bestVol>5__5)
								{
									<bestVol>5__5 = <vol>5__12;
									<best>5__4 = <g>5__9;
								}
								<r>5__10 = null;
								<g>5__9 = null;
							}
						}
					}
					finally
					{
						if (<>s__8 != null)
						{
							<>s__8.Dispose();
						}
					}
					<>s__8 = null;
					if ((Object)(object)<best>5__4 != (Object)null)
					{
						Debug.Log(Object.op_Implicit("Grabbing chunk: " + ((Object)<best>5__4).name));
						((HVRGrabberBase)hand).ForceRelease();
						((HVRGrabberBase)hand).TryGrab(<best>5__4, false);
					}
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static HVRHexaBodyInputs playerInputs;

		public static HVRHandGrabber leftHand;

		public static HVRHandGrabber rightHand;

		public static SliceOnInputCustom slice1;

		public static SliceOnInputCustom slice2;

		public static int id1;

		public static int id2;

		public static HVRGrabbable grab1;

		public static HVRGrabbable grab2;

		public static MelonPreferences_Category category;

		public static MelonPreferences_Entry<bool> removeNeckGib;

		public override void OnInitializeMelon()
		{
			((MelonBase)this).LoggerInstance.Msg("Initialized.");
			category = MelonPreferences.CreateCategory("RipAndTear");
			removeNeckGib = category.CreateEntry<bool>("Don't gib neck", false, "Don't gib neck", "Disable neck gibbing to work with Choke Mod", false, false, (ValueValidator)null, (string)null);
			category.SaveToFile(true);
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (sceneName != "MainMenuScene")
			{
				playerInputs = GameObject.Find("Hexa4Rig26.10.23").GetComponentInChildren<HVRHexaBodyInputs>();
				leftHand = GameObject.Find("Hexa4Rig26.10.23").GetComponentInChildren<HVRHandGrabber>();
				GameObject val = GameObject.Find("Hexa4Rig26.10.23");
				leftHand = ((Component)val.transform.Find("Physics LeftHand")).GetComponent<HVRHandGrabber>();
				rightHand = ((Component)val.transform.Find("Physics RightHand")).GetComponent<HVRHandGrabber>();
			}
		}

		public static void SliceManager(SliceOnInputCustom slicer, HVRGrabbable grab, int id)
		{
			if ((Object)(object)grab1 == (Object)null && (Object)(object)slice1 == (Object)null && id1 == 0)
			{
				grab1 = grab;
				slice1 = slicer;
				id1 = id;
			}
			else if ((Object)(object)grab1 != (Object)null && (((Object)(object)slice1 != (Object)null) & (id1 != 0)) && (Object)(object)grab2 == (Object)null && (Object)(object)slice2 == (Object)null && id2 == 0)
			{
				grab2 = grab;
				slice2 = slicer;
				id2 = id;
			}
		}

		public static void SliceManagerNullifier(SliceOnInputCustom slicer, HVRGrabbable grab, int id)
		{
			if (id == id1)
			{
				grab1 = null;
				slice1 = null;
				id1 = 0;
			}
			else if (id == id2)
			{
				grab2 = null;
				slice2 = null;
				id2 = 0;
			}
		}

		[IteratorStateMachine(typeof(<GrabAfterFracture>d__17))]
		private IEnumerator GrabAfterFracture(SliceOnInputCustom original, HVRHandGrabber hand)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GrabAfterFracture>d__17(0)
			{
				<>4__this = this,
				original = original,
				hand = hand
			};
		}

		public override void OnUpdate()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)playerInputs == (Object)null)
			{
				return;
			}
			if (playerInputs.LeftController.TriggerButtonState.Active)
			{
				if ((Object)(object)grab1 != (Object)null && ((Object)grab1.Grabbers[0]).name == "Physics LeftHand")
				{
					string name = ((Object)((Component)slice1).gameObject).name;
					if (name != "Head" && name != "Pelvis")
					{
						TransferJointsOnFractureCustom componentInParent = ((Component)slice1).GetComponentInParent<TransferJointsOnFractureCustom>();
						componentInParent.DistanceTolerance = 0f;
					}
					if (removeNeckGib.Value && name == "Neck")
					{
						return;
					}
					slice1.ForceFracture();
					if (name.Contains("Elbow") || name.Contains("Shoulder") || name.Contains("Knee") || name.Contains("Hip") || name.Contains("Foot") || name.Contains("Jaw"))
					{
						MelonCoroutines.Start(GrabAfterFracture(slice1, leftHand));
					}
					else
					{
						((HVRGrabberBase)leftHand).ForceRelease();
					}
					SliceManagerNullifier(slice1, grab1, id1);
				}
				else if ((Object)(object)grab2 != (Object)null && ((Object)grab2.Grabbers[0]).name == "Physics LeftHand")
				{
					string name2 = ((Object)((Component)slice2).gameObject).name;
					if (name2 != "Head" && name2 != "Pelvis")
					{
						TransferJointsOnFractureCustom componentInParent2 = ((Component)slice2).GetComponentInParent<TransferJointsOnFractureCustom>();
						componentInParent2.DistanceTolerance = 0f;
					}
					if (removeNeckGib.Value && name2 == "Neck")
					{
						return;
					}
					slice2.ForceFracture();
					if (name2.Contains("Elbow") || name2.Contains("Shoulder") || name2.Contains("Knee") || name2.Contains("Hip") || name2.Contains("Foot") || name2.Contains("Jaw"))
					{
						MelonCoroutines.Start(GrabAfterFracture(slice2, leftHand));
					}
					else
					{
						((HVRGrabberBase)leftHand).ForceRelease();
					}
					SliceManagerNullifier(slice2, grab2, id2);
				}
			}
			if (!playerInputs.RightController.TriggerButtonState.Active)
			{
				return;
			}
			if ((Object)(object)grab1 != (Object)null && ((Object)grab1.Grabbers[0]).name == "Physics RightHand")
			{
				string name3 = ((Object)((Component)slice1).gameObject).name;
				if (name3 != "Head" && name3 != "Pelvis")
				{
					TransferJointsOnFractureCustom componentInParent3 = ((Component)slice1).GetComponentInParent<TransferJointsOnFractureCustom>();
					componentInParent3.DistanceTolerance = 0f;
				}
				if (!removeNeckGib.Value || !(name3 == "Neck"))
				{
					slice1.ForceFracture();
					if (name3.Contains("Elbow") || name3.Contains("Shoulder") || name3.Contains("Knee") || name3.Contains("Hip") || name3.Contains("Foot") || name3.Contains("Jaw"))
					{
						MelonCoroutines.Start(GrabAfterFracture(slice1, rightHand));
					}
					else
					{
						((HVRGrabberBase)rightHand).ForceRelease();
					}
					SliceManagerNullifier(slice1, grab1, id1);
				}
			}
			else
			{
				if (!((Object)(object)grab2 != (Object)null) || !(((Object)grab2.Grabbers[0]).name == "Physics RightHand"))
				{
					return;
				}
				string name4 = ((Object)((Component)slice2).gameObject).name;
				if (name4 != "Head" && name4 != "Pelvis")
				{
					TransferJointsOnFractureCustom componentInParent4 = ((Component)slice2).GetComponentInParent<TransferJointsOnFractureCustom>();
					componentInParent4.DistanceTolerance = 0f;
				}
				if (!removeNeckGib.Value || !(name4 == "Neck"))
				{
					slice2.ForceFracture();
					if (name4.Contains("Elbow") || name4.Contains("Shoulder") || name4.Contains("Knee") || name4.Contains("Hip") || name4.Contains("Foot") || name4.Contains("Jaw"))
					{
						MelonCoroutines.Start(GrabAfterFracture(slice2, rightHand));
					}
					else
					{
						((HVRGrabberBase)rightHand).ForceRelease();
					}
					SliceManagerNullifier(slice2, grab2, id2);
				}
			}
		}
	}
}