Decompiled source of BreakableBones v1.6.0

BreakableBones.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BreakableBones;
using HBMF.AudioImporter;
using HBMF.GameResources;
using HBMF.ModMenu;
using HBMF.Utilities;
using HarmonyLib;
using Il2Cpp;
using Il2CppInteractionSystem;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
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), "BreakableBones", "1.6.0", "korbykob", null)]
[assembly: MelonGame("GexagonVR", "Hard Bullet")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BreakableBones")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BreakableBones")]
[assembly: AssemblyTitle("BreakableBones")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BreakableBones;

[HarmonyPatch]
public class Mod : MelonMod
{
	internal static MelonPreferences_Entry<bool> enabled;

	internal static MelonPreferences_Entry<float> force;

	public override void OnInitializeMelon()
	{
		BreakableBonesManager.snap = Audio.Import(Utils.GetResource(Assembly.GetExecutingAssembly(), "BreakableBones.Snap.wav"));
		MelonPreferences_Category val = MelonPreferences.CreateCategory("BreakableBones");
		enabled = val.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		force = val.CreateEntry<float>("BreakForce", 30000f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		Menu.CreateCategory("BREAKABLE BONES").CreateBool("ENABLE", enabled.Value, (Action<bool>)delegate(bool value)
		{
			enabled.Value = value;
		}).CreateSlider("BREAK FORCE", force.Value, 0f, 60000f, 1000, "", (Action<float>)delegate(float value)
		{
			force.Value = value;
		});
	}

	[HarmonyPatch(typeof(EnemyRoot), "Awake")]
	[HarmonyPostfix]
	public static void SpawnPatch(EnemyRoot __instance)
	{
		if ((Object)(object)((Component)__instance).transform.parent == (Object)(object)GameResources.Enemies)
		{
			Transform val = ((Component)__instance).transform.Find("[BODY]/PhysicalBones");
			if ((Object)(object)((Component)val).GetComponent<BreakableBonesManager>() == (Object)null)
			{
				((Component)val).gameObject.AddComponent<BreakableBonesManager>();
			}
		}
	}
}
[RegisterTypeInIl2Cpp]
public class BreakableBonesManager : MonoBehaviour
{
	internal static AudioClip snap;

	private ConfigurableJoint[] joints;

	public BreakableBonesManager(IntPtr ptr)
		: base(ptr)
	{
	}

	internal void Start()
	{
		joints = Il2CppArrayBase<ConfigurableJoint>.op_Implicit(((Component)this).GetComponentsInChildren<ConfigurableJoint>());
		ConfigurableJoint[] array = joints;
		foreach (ConfigurableJoint val in array)
		{
			((Component)val).gameObject.AddComponent<AudioSource>().clip = snap;
		}
	}

	internal void Update()
	{
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Invalid comparison between Unknown and I4
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		ConfigurableJoint[] array = joints;
		foreach (ConfigurableJoint val in array)
		{
			if (!Mod.enabled.Value || !(((Object)val).name != "spine_02") || ((!((Object)(object)GameResources.RightGrabber != (Object)null) || ((AbstractGrabber)GameResources.RightGrabber).CurrentGrab == null || (!((Object)(object)((AbstractGrabber)GameResources.RightGrabber).CurrentGrab.Grabbable == (Object)(object)((Component)val).GetComponent<Grabbable>()) && !((Object)(object)((Component)((AbstractGrabber)GameResources.RightGrabber).CurrentGrab.Grabbable).GetComponent<Rigidbody>() == (Object)(object)((Joint)val).connectedBody))) && (!((Object)(object)GameResources.LeftGrabber != (Object)null) || ((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab == null || (!((Object)(object)((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab.Grabbable == (Object)(object)((Component)val).GetComponent<Grabbable>()) && !((Object)(object)((Component)((AbstractGrabber)GameResources.LeftGrabber).CurrentGrab.Grabbable).GetComponent<Rigidbody>() == (Object)(object)((Joint)val).connectedBody)))) || (int)val.angularXMotion == 2)
			{
				continue;
			}
			Vector3 currentTorque = ((Joint)val).currentTorque;
			if (((Vector3)(ref currentTorque)).magnitude >= Mod.force.Value * Time.unscaledDeltaTime)
			{
				val.angularXMotion = (ConfigurableJointMotion)2;
				val.angularYMotion = (ConfigurableJointMotion)2;
				val.angularZMotion = (ConfigurableJointMotion)2;
				HealthContainer component = ((Component)((Component)this).transform.parent.parent.Find("[SYSTEMS]/AI/Health")).GetComponent<HealthContainer>();
				if (!component.IgnoreDamage)
				{
					component.RemoveHealth(float.PositiveInfinity);
				}
				((Component)val).GetComponent<AudioSource>().Play((PlaySettings)null);
			}
		}
	}
}