Decompiled source of BONEuphoria v1.0.0

Mods/BONEuphoria.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BONEuphoria;
using BONEuphoria.Core;
using BONEuphoriaUtilities;
using HarmonyLib;
using MelonLoader;
using PuppetMasta;
using RootMotion.FinalIK;
using StressLevelZero.AI;
using StressLevelZero.Props.Weapons;
using UnhollowerBaseLib;
using UnhollowerRuntimeLib;
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(Base), "BONEuphoria", "1.0.0", "spark", null)]
[assembly: MelonGame("Stress Level Zero", "BONEWORKS")]
[assembly: AssemblyTitle("BONEuphoria")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BONEuphoria")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d283e45b-decf-4a39-9694-e2467dde09d7")]
[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")]
public enum Arm
{
	Left,
	Right
}
namespace BONEuphoriaUtilities
{
	public class OriginalPuppetProperties : MonoBehaviour
	{
		public float damper = 0f;

		public float weight = 0f;

		public OriginalPuppetProperties(IntPtr ptr)
			: base(ptr)
		{
		}
	}
}
namespace BONEuphoria
{
	public class Base : MelonMod
	{
		public List<AIBrain> brains = new List<AIBrain>();

		public bool load = false;

		public IEnumerator<WaitForSeconds> Update()
		{
			while (true)
			{
				Il2CppArrayBase<AIBrain> brains = Resources.FindObjectsOfTypeAll<AIBrain>();
				foreach (AIBrain brain in brains)
				{
					try
					{
						Transform ai = ((Component)brain).gameObject.transform;
						PuppetMaster puppet = ((Component)ai.Find("Physics")).GetComponent<PuppetMaster>();
						BehaviourPowerLegs legpower = ((Component)ai.Find("AiRig/BehaviourPowerLegs")).GetComponent<BehaviourPowerLegs>();
						if ((Object)(object)((Component)ai).GetComponent<BONEuphoriaWoundHandler>() == (Object)null)
						{
							((Component)ai).gameObject.AddComponent<BONEuphoriaWoundHandler>();
						}
						if ((Object)(object)puppet != (Object)null && (Object)(object)legpower != (Object)null)
						{
							((Component)puppet).gameObject.transform.Find("Root_M");
							legpower._dyingTime = 2f;
							Animator animator = puppet.targetAnimator;
							((Component)((Component)legpower).transform).GetComponent<SphereCollider>().radius = 6f;
							puppet.stateSettings = new StateSettings(3f, 0f, 0f, 0f, false, false);
							if ((Object)(object)((Component)ai).GetComponent<OriginalPuppetProperties>() != (Object)null && puppet.isAlive)
							{
								Util.RemoveAllIk(ai);
								OriginalPuppetProperties properties = ((Component)ai).GetComponent<OriginalPuppetProperties>();
								puppet.muscleDamper = properties.damper;
								puppet.muscleWeight = properties.weight;
								animator.speed = 1f;
								Object.Destroy((Object)(object)properties);
							}
						}
					}
					catch
					{
					}
				}
				yield return new WaitForSeconds(0.2f);
			}
		}

		public override void OnApplicationStart()
		{
			((Harmony)((MelonBase)this).harmonyInstance).PatchAll();
			ClassInjector.RegisterTypeInIl2Cpp<OriginalPuppetProperties>();
			ClassInjector.RegisterTypeInIl2Cpp<BONEuphoriaWoundHandler>();
		}

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			if (!load)
			{
				load = true;
				MelonCoroutines.Start((IEnumerator)Update());
			}
		}
	}
	[HarmonyPatch(typeof(PuppetMaster), "Kill", new Type[] { })]
	public class PuppetMasterPatch
	{
		[HarmonyPrefix]
		private static void Prefix(PuppetMaster __instance)
		{
			AIBrain componentInParent = ((Component)((Component)__instance).transform).GetComponentInParent<AIBrain>();
			Animator targetAnimator = __instance.targetAnimator;
			Util.RemoveAllIk(((Component)componentInParent).transform);
			if ((Object)(object)((Component)componentInParent).GetComponent<OriginalPuppetProperties>() == (Object)null)
			{
				OriginalPuppetProperties originalPuppetProperties = ((Component)componentInParent).gameObject.AddComponent<OriginalPuppetProperties>();
				originalPuppetProperties.damper = __instance.muscleDamper;
				originalPuppetProperties.weight = __instance.muscleWeight;
			}
			__instance.muscleDamper = 1000000f;
			__instance.muscleWeight = 10f;
			targetAnimator.speed = 0.5f;
		}
	}
	[HarmonyPatch(typeof(Gun), "OnFire", new Type[] { })]
	public class GunFirePatch
	{
		[HarmonyPostfix]
		private static void Postfix(Gun __instance)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Invalid comparison between Unknown and I4
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Ray val = default(Ray);
				((Ray)(ref val))..ctor(__instance.firePointTransform.position, __instance.firePointTransform.forward);
				RaycastHit val2 = default(RaycastHit);
				if (Physics.Raycast(val, ref val2, 800f) && (int)__instance.hammerState == 1 && (Object)(object)__instance.chamberedCartridge != (Object)null)
				{
					int num = Random.Range(1, 8);
					AIBrain componentInParent = ((Component)((Component)((RaycastHit)(ref val2)).collider).transform).GetComponentInParent<AIBrain>();
					PuppetMaster puppetMaster = componentInParent.puppetMaster;
					BONEuphoriaWoundHandler component = ((Component)((Component)componentInParent).transform).GetComponent<BONEuphoriaWoundHandler>();
					component.HoldWound(Arm.Left, ((Component)((RaycastHit)(ref val2)).collider).transform, ((RaycastHit)(ref val2)).point);
					if (num == 3 || num == 6)
					{
						component.HoldWound(Arm.Right, ((Component)((RaycastHit)(ref val2)).collider).transform, ((RaycastHit)(ref val2)).point);
					}
				}
			}
			catch
			{
			}
		}
	}
	public static class Util
	{
		public static Transform GetAi(Transform start)
		{
			Transform val = start;
			while ((Object)(object)val != (Object)null)
			{
				if ((Object)(object)((Component)val).GetComponent<AIBrain>() != (Object)null)
				{
					return val;
				}
				val = val.parent;
			}
			return null;
		}

		public static void RemoveAllIk(Transform root)
		{
			if (!((Object)(object)root == (Object)null))
			{
				BONEuphoriaWoundHandler[] array = Il2CppArrayBase<BONEuphoriaWoundHandler>.op_Implicit(((Component)root).GetComponents<BONEuphoriaWoundHandler>());
				BONEuphoriaWoundHandler[] array2 = array;
				foreach (BONEuphoriaWoundHandler bONEuphoriaWoundHandler in array2)
				{
					Object.DestroyImmediate((Object)(object)bONEuphoriaWoundHandler);
				}
			}
		}

		public static bool IsABehindB(Vector3 a, Transform b)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = a - b.position;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			Vector3 forward = b.forward;
			float num = Vector3.Dot(forward, normalized);
			return num < -0.5f;
		}
	}
}
namespace BONEuphoria.Core
{
	public class BONEuphoriaWoundHandler : MonoBehaviour
	{
		internal PuppetMaster puppet;

		internal AIBrain aibrain;

		internal BehaviourPowerLegs behaviour;

		internal Transform leftarmik;

		internal Transform rightarmik;

		public int woundholdtime = 2;

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

		internal void Start()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			puppet = ((Component)((Component)this).transform).GetComponentInChildren<PuppetMaster>();
			aibrain = ((Component)this).GetComponent<AIBrain>();
			behaviour = ((Component)((Component)aibrain).transform.Find("AiRig/BehaviourPowerLegs")).GetComponent<BehaviourPowerLegs>();
			leftarmik = new GameObject("LeftIK").transform;
			leftarmik.parent = ((Component)aibrain).transform;
			rightarmik = new GameObject("RightIK").transform;
			rightarmik.parent = ((Component)aibrain).transform;
		}

		public void HoldWound(Arm arm, Transform limb, Vector3 worldtarget)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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)
			if ((int)puppet.state != 1)
			{
				switch (arm)
				{
				case Arm.Left:
				{
					Vector3 localPosition2 = limb.InverseTransformPoint(worldtarget);
					leftarmik.parent = limb;
					leftarmik.localPosition = localPosition2;
					IK val2 = ((Il2CppArrayBase<IK>)(object)behaviour.ik.armIkSolvers)[0];
					((Behaviour)val2).enabled = true;
					((IKSolverTrigonometricSlz)((Il2CppObjectBase)val2.GetIKSolver()).TryCast<IKSolverLimbSlz>()).target = leftarmik;
					MelonCoroutines.Start(StartReleaseWound(Arm.Left));
					break;
				}
				case Arm.Right:
				{
					Vector3 localPosition = limb.InverseTransformPoint(worldtarget);
					rightarmik.parent = limb;
					rightarmik.localPosition = localPosition;
					IK val = ((Il2CppArrayBase<IK>)(object)behaviour.ik.armIkSolvers)[1];
					((Behaviour)val).enabled = true;
					((IKSolverTrigonometricSlz)((Il2CppObjectBase)val.GetIKSolver()).TryCast<IKSolverLimbSlz>()).target = rightarmik;
					MelonCoroutines.Start(StartReleaseWound(Arm.Right));
					break;
				}
				}
			}
		}

		internal IEnumerator StartReleaseWound(Arm arm)
		{
			yield return (object)new WaitForSeconds((float)woundholdtime);
			switch (arm)
			{
			case Arm.Left:
				((Behaviour)((Il2CppArrayBase<IK>)(object)behaviour.ik.armIkSolvers)[0]).enabled = false;
				((IKSolverTrigonometricSlz)((Il2CppObjectBase)((Il2CppArrayBase<IK>)(object)behaviour.ik.armIkSolvers)[0].GetIKSolver()).TryCast<IKSolverLimbSlz>()).target = null;
				break;
			case Arm.Right:
				((Behaviour)((Il2CppArrayBase<IK>)(object)behaviour.ik.armIkSolvers)[1]).enabled = false;
				((IKSolverTrigonometricSlz)((Il2CppObjectBase)((Il2CppArrayBase<IK>)(object)behaviour.ik.armIkSolvers)[1].GetIKSolver()).TryCast<IKSolverLimbSlz>()).target = null;
				break;
			}
		}
	}
}