Decompiled source of BreakableBonesPatch6 v1.0.1

Mods/BreakableBonesPatch6.dll

Decompiled 2 months 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.Versioning;
using System.Security;
using System.Security.Permissions;
using AudioImportLib;
using BoneLib.BoneMenu;
using BreakableBonesPatch6;
using BreakableBonesPatch6.Resources;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow.PuppetMasta;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
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(Core), "BreakableBonesPatch6", "1.0.0", "MajedCT", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BreakableBonesPatch6")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+bdd5cd164ba9e5120ec89c202960af0a68306033")]
[assembly: AssemblyProduct("BreakableBonesPatch6")]
[assembly: AssemblyTitle("BreakableBonesPatch6")]
[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 BreakableBonesPatch6
{
	[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_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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if (!Core.toggled.Value)
			{
				return;
			}
			Muscle[] array = muscles;
			foreach (Muscle val in array)
			{
				if (val._maxForce == 0f)
				{
					break;
				}
				ConfigurableJoint component = ((Component)val.jointBreakBroadcaster).GetComponent<ConfigurableJoint>();
				Vector3 val2 = ((Joint)component).currentTorque;
				float magnitude = ((Vector3)(ref val2)).magnitude;
				val2 = ((Joint)component).currentForce;
				float magnitude2 = ((Vector3)(ref val2)).magnitude;
				if (magnitude > Core.breakTorque.Value || magnitude2 > Core.breakForce.Value)
				{
					component.angularXMotion = (ConfigurableJointMotion)((!Core.x) ? 1 : 2);
					component.angularYMotion = (ConfigurableJointMotion)((!Core.y) ? 1 : 2);
					component.angularZMotion = (ConfigurableJointMotion)((!Core.z) ? 1 : 2);
					string text = Path.Combine(MelonEnvironment.UserDataDirectory, "BoneBreaking");
					AudioClip val3 = API.LoadAudioClip(text + "/snapcracklepop.wav", true);
					AudioSource val4 = (Object.op_Implicit((Object)(object)((Component)((Joint)component).connectedBody).gameObject.GetComponent<AudioSource>()) ? ((Component)((Joint)component).connectedBody).gameObject.GetComponent<AudioSource>() : ((Component)((Joint)component).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 (Core.kill.Value)
					{
						pMaster.Kill();
					}
				}
			}
		}

		private void OnDestroy()
		{
			if (!Core.fixspawn)
			{
				return;
			}
			Muscle[] array = muscles;
			foreach (Muscle val in array)
			{
				if (val._maxForce != 0f)
				{
					return;
				}
				ConfigurableJoint component = ((Component)val.jointBreakBroadcaster).GetComponent<ConfigurableJoint>();
				component.angularXMotion = (ConfigurableJointMotion)1;
				component.angularYMotion = (ConfigurableJointMotion)1;
				component.angularZMotion = (ConfigurableJointMotion)1;
				val._maxForce = oldForce;
			}
			pMaster.FixMusclePositions();
			pMaster.Resurrect();
		}
	}
	public class Core : 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;
			}
		}

		private static readonly string BonelabPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Steam\\steamapps\\common\\BONELAB\\UserData\\BoneBreaking\\snapcracklepop.wav");

		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> kill;

		public static bool x = false;

		public static bool y = true;

		public static bool z = false;

		public static bool fixspawn = true;

		public static float increment = 100f;

		public static float max = 0f;

		private void checksnapcrackle()
		{
			try
			{
				string directoryName = Path.GetDirectoryName(BonelabPath);
				if (!Directory.Exists(directoryName))
				{
					Directory.CreateDirectory(directoryName);
				}
				if (File.Exists(BonelabPath))
				{
					return;
				}
				using (UnmanagedMemoryStream unmanagedMemoryStream = BreakableBonesPatch6.Resources.Resource1.snapcracklepop)
				{
					using FileStream destination = new FileStream(BonelabPath, FileMode.Create, FileAccess.Write);
					unmanagedMemoryStream.CopyTo(destination);
				}
				MelonLogger.Msg("extracted snapcracklepop");
			}
			catch (Exception value)
			{
				MelonLogger.Error($"couldn't extract snapcracklepop: {value}");
			}
		}

		public override void OnInitializeMelon()
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			checksnapcrackle();
			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);
			kill = categ.CreateEntry<bool>("KillOnBreak", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			Page val = Page.Root.CreatePage("Breakable Bones", Color.white, 0, true);
			val.CreateFloat("Break Torque", Color.red, breakTorque.Value, increment, 0f, float.MaxValue, (Action<float>)delegate(float value)
			{
				breakTorque.Value = value;
			});
			val.CreateFloat("Break Force", Color.red, breakForce.Value, increment, 0f, float.MaxValue, (Action<float>)delegate(float value)
			{
				breakForce.Value = value;
			});
			val.CreateBool("Mod Toggle", Color.red, toggled.Value, (Action<bool>)delegate(bool value)
			{
				toggled.Value = value;
			});
			val.CreateBool("Kill On Break", Color.red, kill.Value, (Action<bool>)delegate(bool value)
			{
				kill.Value = value;
			});
			Page val2 = val.CreatePage("Experimental Settings [!]", Color.yellow, 0, true);
			val2.CreateFloat("force/torque button increment", Color.yellow, increment, 25f, 0f, float.MaxValue, (Action<float>)delegate(float value)
			{
				increment = value;
			});
			val2.CreateFloat("brokenjoint maxforce", Color.yellow, max, 1f, 0f, float.MaxValue, (Action<float>)delegate(float value)
			{
				max = value;
			});
			val2.CreateBool("unlock_x", Color.yellow, x, (Action<bool>)delegate(bool value)
			{
				x = value;
			});
			val2.CreateBool("unlock_y", Color.yellow, y, (Action<bool>)delegate(bool value)
			{
				y = value;
			});
			val2.CreateBool("unlock_z", Color.yellow, z, (Action<bool>)delegate(bool value)
			{
				z = value;
			});
			val2.CreateBool("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)
				{
					resourceMan = new ResourceManager("BreakableBones.Resource1", typeof(Resource1).Assembly);
				}
				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()
		{
		}
	}
}
namespace BreakableBonesPatch6.Resources
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.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("BreakableBonesPatch6.Resources.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()
		{
		}
	}
}