Decompiled source of BreakableBones v1.0.1

Mods/BreakableBones.dll

Decompiled a month ago
using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using AudioImportLib;
using BoneLib.BoneMenu;
using BoneLib.BoneMenu.Elements;
using BreakableBones;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using PuppetMasta;
using UnhollowerBaseLib;
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(Main), "BreakableBones", "1.0.0", "joe swan#2228", null)]
[assembly: AssemblyTitle("BreakableBones")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BreakableBones")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("23e24170-9f60-473b-8784-ab3fdaa9cece")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BreakableBones;

[RegisterTypeInIl2Cpp]
internal class JointHandler : MonoBehaviour
{
	public PuppetMaster pMaster;

	public Muscle[] muscles;

	private float oldForce;

	public JointHandler(IntPtr poptart)
		: base(poptart)
	{
	}

	private void Start()
	{
		muscles = Il2CppArrayBase<Muscle>.op_Implicit((Il2CppArrayBase<Muscle>)(object)pMaster.muscles);
	}

	private void Update()
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		Muscle[] array = muscles;
		foreach (Muscle val in array)
		{
			if (val._maxForce == 0f)
			{
				break;
			}
			ConfigurableJoint joint = val.joint;
			Vector3 val2 = ((Joint)joint).currentTorque;
			float magnitude = ((Vector3)(ref val2)).magnitude;
			val2 = ((Joint)joint).currentForce;
			float magnitude2 = ((Vector3)(ref val2)).magnitude;
			if (magnitude > Main.breakTorque.Value || magnitude2 > Main.breakForce.Value)
			{
				joint.angularXMotion = (ConfigurableJointMotion)((!Main.x) ? 1 : 2);
				joint.angularYMotion = (ConfigurableJointMotion)((!Main.y) ? 1 : 2);
				joint.angularZMotion = (ConfigurableJointMotion)((!Main.z) ? 1 : 2);
				string text = Path.Combine(MelonUtils.UserDataDirectory, "BoneBreaking");
				AudioClip val3 = API.LoadAudioClip(text + "/snapcracklepop.wav", true);
				AudioSource val4 = (Object.op_Implicit((Object)(object)((Component)((Joint)joint).connectedBody).gameObject.GetComponent<AudioSource>()) ? ((Component)((Joint)joint).connectedBody).gameObject.GetComponent<AudioSource>() : ((Component)((Joint)joint).connectedBody).gameObject.AddComponent<AudioSource>());
				val4.pitch = Random.Range(0.75f, 1.15f);
				val4.PlayOneShot(val3, Random.Range(0.8f, 1.3f));
				oldForce = val._maxForce;
				val._maxForce = 0f;
				if (Main.takedamage.Value)
				{
					SubBehaviourHealth health = ((Component)((Component)pMaster).transform.root).GetComponentInChildren<BehaviourBaseNav>().health;
					health.cur_hp -= 25f;
				}
			}
		}
	}

	private void OnDestroy()
	{
		if (!Main.fixspawn)
		{
			return;
		}
		Muscle[] array = muscles;
		foreach (Muscle val in array)
		{
			if (val._maxForce != 0f)
			{
				return;
			}
			ConfigurableJoint joint = val.joint;
			joint.angularXMotion = (ConfigurableJointMotion)1;
			joint.angularYMotion = (ConfigurableJointMotion)1;
			joint.angularZMotion = (ConfigurableJointMotion)1;
			val._maxForce = oldForce;
		}
		pMaster.muscles = pMaster.defaultMuscles;
		pMaster.FixMusclePositions();
		pMaster.FixTargetTransforms();
		pMaster.Resurrect();
	}
}
public class Main : MelonMod
{
	[HarmonyPatch(typeof(PuppetMaster), "Awake")]
	public class onAwake
	{
		[HarmonyPostfix]
		public static void Postfix(PuppetMaster __instance)
		{
			GameObject gameObject = ((Component)__instance).gameObject;
			gameObject.AddComponent<JointHandler>().pMaster = __instance;
		}
	}

	public MelonPreferences_Category categ;

	public static MelonPreferences_Entry<float> breakTorque;

	public static MelonPreferences_Entry<float> breakForce;

	public static MelonPreferences_Entry<bool> toggled;

	public static MelonPreferences_Entry<bool> takedamage;

	public static bool x = false;

	public static bool y = true;

	public static bool z = false;

	public static bool fixspawn = true;

	public static float increment = 50f;

	public static float max = 0f;

	public override void OnUpdate()
	{
	}

	public override void OnInitializeMelon()
	{
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
		categ = MelonPreferences.CreateCategory("BoneBreaking");
		breakTorque = categ.CreateEntry<float>("BoneBreakTorque", 7000f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		breakForce = categ.CreateEntry<float>("BoneBreakForce", 7000f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		toggled = categ.CreateEntry<bool>("Toggled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		takedamage = categ.CreateEntry<bool>("NPCDamage", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MenuCategory val = MenuManager.CreateCategory("BoneBreaking", Color.white);
		SubPanelElement val2 = val.CreateSubPanel("Bone Settings", Color.red);
		val2.CreateFloatElement("Break Torque", Color.red, breakTorque.Value, increment, 0f, float.MaxValue, (Action<float>)delegate(float value)
		{
			breakTorque.Value = value;
		});
		val2.CreateFloatElement("Break Force", Color.red, breakForce.Value, increment, 0f, float.MaxValue, (Action<float>)delegate(float value)
		{
			breakForce.Value = value;
		});
		val2.CreateBoolElement("Toggled", Color.red, toggled.Value, (Action<bool>)delegate(bool value)
		{
			toggled.Value = value;
		});
		val2.CreateBoolElement("Damage On Break", Color.red, takedamage.Value, (Action<bool>)delegate(bool value)
		{
			takedamage.Value = value;
		});
		SubPanelElement val3 = val.CreateSubPanel("Experimental Settings [!]", Color.yellow);
		val3.CreateFloatElement("force/torque button increment", Color.yellow, increment, 25f, 0f, float.MaxValue, (Action<float>)delegate(float value)
		{
			increment = value;
		});
		val3.CreateFloatElement("brokenjoint maxforce", Color.yellow, max, 1f, 0f, float.MaxValue, (Action<float>)delegate(float value)
		{
			max = value;
		});
		val3.CreateBoolElement("unlock_x", Color.yellow, x, (Action<bool>)delegate(bool value)
		{
			x = value;
		});
		val3.CreateBoolElement("unlock_y", Color.yellow, y, (Action<bool>)delegate(bool value)
		{
			y = value;
		});
		val3.CreateBoolElement("unlock_z", Color.yellow, z, (Action<bool>)delegate(bool value)
		{
			z = value;
		});
		val3.CreateBoolElement("fix_destroy-respawn", Color.yellow, fixspawn, (Action<bool>)delegate(bool value)
		{
			fixspawn = value;
		});
	}

	public override void OnDeinitializeMelon()
	{
		MelonPreferences.Save();
	}
}
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resource1
{
	private static ResourceManager resourceMan;

	private static CultureInfo resourceCulture;

	[EditorBrowsable(EditorBrowsableState.Advanced)]
	internal static ResourceManager ResourceManager
	{
		get
		{
			if (resourceMan == null)
			{
				ResourceManager resourceManager = new ResourceManager("BreakableBones.Resource1", typeof(Resource1).Assembly);
				resourceMan = resourceManager;
			}
			return resourceMan;
		}
	}

	[EditorBrowsable(EditorBrowsableState.Advanced)]
	internal static CultureInfo Culture
	{
		get
		{
			return resourceCulture;
		}
		set
		{
			resourceCulture = value;
		}
	}

	internal static UnmanagedMemoryStream snapcracklepop => ResourceManager.GetStream("snapcracklepop", resourceCulture);

	internal Resource1()
	{
	}
}