Decompiled source of SpineHero v1.0.3

SpineHero.dll

Decompiled 3 months ago
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using OtherLoader;
using UnityEngine;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace MeatKit
{
	public class HideInNormalInspectorAttribute : PropertyAttribute
	{
	}
}
namespace Ax.SpineHero
{
	[BepInPlugin("Ax.SpineHero", "SpineHero", "1.0.3")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	public class SpineHeroPlugin : BaseUnityPlugin
	{
		private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		internal static ManualLogSource Logger;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			LoadAssets();
		}

		private void LoadAssets()
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "Ax.SpineHero");
			OtherLoader.RegisterDirectLoad(BasePath, "Ax.SpineHero", "", "ax.spinehero", "", "");
		}
	}
}

SpineHeroDLL.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using FistVR;
using On.FistVR;
using OtherLoader;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SpineHero")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SpineHeroDLL")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("B5F1C390-B573-400B-807F-3EEE54451116")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SpineHeroDLLnamespace;

public class ScalableQBSlot : FVRQuickBeltSlot
{
	public Vector3 HeldObjectLocalScale;

	public Vector3 HeldObjectSize;

	public FVRInteractiveObject LastHeldObject;

	public Vector3 LastScale = Vector3.zero;

	public Vector3 TargetSize = new Vector3(0.1f, 0.1f, 0.1f);

	public List<Transform> AllTrans;

	public List<GameObject> AllPO;

	public bool CheckAttachment = true;

	public bool HardnessObjHandled = false;

	private Bounds CalculateBounds(GameObject root)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: 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_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
		Bounds result = default(Bounds);
		bool flag = false;
		Collider[] componentsInChildren = root.GetComponentsInChildren<Collider>();
		Collider[] array = componentsInChildren;
		foreach (Collider val in array)
		{
			if ((Object)(object)val != (Object)null)
			{
				Bounds bounds = val.bounds;
				if (!flag)
				{
					result = bounds;
					flag = true;
				}
				else
				{
					((Bounds)(ref result)).Encapsulate(bounds);
				}
			}
		}
		if (!flag)
		{
			result = default(Bounds);
			((Bounds)(ref result)).center = Vector3.zero;
			((Bounds)(ref result)).size = new Vector3(0.1f, 0.1f, 0.1f);
		}
		return result;
	}

	private List<Transform> GetAllChildren(Transform parent)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		List<Transform> list = new List<Transform>();
		foreach (Transform item in parent)
		{
			Transform val = item;
			list.Add(val);
			list.AddRange(GetAllChildren(val));
		}
		return list;
	}

	private List<GameObject> FindObjectsWithComponent<T>(Transform parent) where T : Component
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected O, but got Unknown
		List<GameObject> list = new List<GameObject>();
		if ((Object)(object)((Component)parent).GetComponent<T>() != (Object)null)
		{
			list.Add(((Component)parent).gameObject);
		}
		foreach (Transform item in parent)
		{
			Transform parent2 = item;
			list.AddRange(FindObjectsWithComponent<T>(parent2));
		}
		return list;
	}

	private void Update()
	{
		//IL_0375: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0410: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0338: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		Type typeFromHandle = typeof(FVRQuickBeltSlot);
		typeFromHandle.GetMethod("Update", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(this, null);
		if (Object.op_Implicit((Object)(object)base.HeldObject))
		{
			if ((Object)(object)base.HeldObject == (Object)(object)LastHeldObject)
			{
				((Component)LastHeldObject).gameObject.transform.localScale = LastScale;
				if (CheckAttachment)
				{
					List<Transform> allChildren = GetAllChildren(((Component)base.HeldObject).gameObject.transform);
					if (allChildren.Count != AllTrans.Count)
					{
						List<GameObject> list = FindObjectsWithComponent<FVRPhysicalObject>(((Component)base.HeldObject).gameObject.transform);
						foreach (GameObject item in list)
						{
							if (!AllPO.Contains(item) && !HardnessObjHandled)
							{
								Transform transform = item.transform;
								transform.localScale *= LastScale.x;
							}
						}
						HardnessObjHandled = false;
						AllTrans = allChildren;
						AllPO = list;
					}
				}
			}
			else
			{
				if (Object.op_Implicit((Object)(object)LastHeldObject))
				{
					((Component)LastHeldObject).gameObject.transform.localScale = HeldObjectLocalScale;
				}
				LastHeldObject = null;
				if (Object.op_Implicit((Object)(object)base.HeldObject))
				{
					Bounds val = CalculateBounds(((Component)base.HeldObject).gameObject);
					HeldObjectSize = ((Bounds)(ref val)).size;
					HeldObjectLocalScale = ((Component)base.HeldObject).gameObject.transform.localScale;
					Vector3 heldObjectLocalScale = HeldObjectLocalScale;
					if (HeldObjectSize.x > TargetSize.x || HeldObjectSize.y > TargetSize.y || HeldObjectSize.z > TargetSize.z)
					{
						float val2 = HeldObjectLocalScale.x * TargetSize.x / HeldObjectSize.x;
						float val3 = HeldObjectLocalScale.y * TargetSize.y / HeldObjectSize.y;
						float val4 = HeldObjectLocalScale.z * TargetSize.z / HeldObjectSize.z;
						float num = Math.Min(Math.Min(val2, val3), val4);
						((Vector3)(ref heldObjectLocalScale))..ctor(num, num, num);
						LastScale = heldObjectLocalScale;
						AllTrans = GetAllChildren(((Component)base.HeldObject).gameObject.transform);
						AllPO = FindObjectsWithComponent<FVRPhysicalObject>(((Component)base.HeldObject).gameObject.transform);
					}
					((Component)base.HeldObject).gameObject.transform.localScale = heldObjectLocalScale;
					LastHeldObject = base.HeldObject;
				}
			}
		}
		else
		{
			if (Object.op_Implicit((Object)(object)LastHeldObject))
			{
				((Component)LastHeldObject).gameObject.transform.localScale = HeldObjectLocalScale;
			}
			LastHeldObject = null;
		}
		if (Object.op_Implicit((Object)(object)base.HeldObject) && ((FVRPhysicalObject)/*isinst with value type is only supported in some contexts*/).m_isHardnessed)
		{
			FVRInteractiveObject heldObject = base.HeldObject;
			if (Object.op_Implicit((Object)(object)((heldObject is FVRPhysicalObject) ? heldObject : null).m_hand))
			{
				((Component)LastHeldObject).gameObject.transform.localScale = HeldObjectLocalScale;
				CheckAttachment = false;
				HardnessObjHandled = true;
			}
			else
			{
				((Component)LastHeldObject).gameObject.transform.localScale = LastScale;
				CheckAttachment = true;
			}
		}
	}
}
[BepInPlugin("GUID.SpineHeroDLL", "SpineHeroDLL", "1.0.0")]
[BepInProcess("h3vr.exe")]
public class SpineHeroDLL : BaseUnityPlugin
{
	public GameObject SpineHeroObjectL = null;

	public GameObject SpineHeroObjectR = null;

	private float timer = 0f;

	private float UpdateRate = 0.05f;

	private bool LoadedPack = false;

	public bool newobj = false;

	public void CreateCustomQB(orig_ConfigureQuickbelt orig, FVRPlayerBody self, int index)
	{
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Expected O, but got Unknown
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_0289: Expected O, but got Unknown
		orig.Invoke(self, index);
		if (!LoadedPack)
		{
			return;
		}
		if (Object.op_Implicit((Object)(object)SpineHeroObjectL))
		{
			Object.DestroyImmediate((Object)(object)SpineHeroObjectR);
			Object.DestroyImmediate((Object)(object)SpineHeroObjectL);
			SpineHeroObjectR = null;
			SpineHeroObjectL = null;
		}
		if (Object.op_Implicit((Object)(object)SpineHeroObjectL))
		{
			return;
		}
		Console.Write("==============Initial new SpineHeroObject====================");
		if (!IM.OD.ContainsKey("SpineHeroObject"))
		{
			return;
		}
		AnvilCallback<GameObject> gameObjectAsync = ((AnvilAsset)IM.OD["SpineHeroObject"]).GetGameObjectAsync();
		Scene activeScene;
		if (Object.op_Implicit((Object)(object)gameObjectAsync.Result))
		{
			SpineHeroObjectL = Object.Instantiate<GameObject>(gameObjectAsync.Result);
			SpineHeroObjectL.transform.position = new Vector3(0f, 0f, 0f);
			SpineHeroObjectL.transform.rotation = Quaternion.identity;
			foreach (Transform item in SpineHeroObjectL.gameObject.transform)
			{
				Transform val = item;
				if (((Component)val).gameObject.tag == "QuickbeltSlot")
				{
					FVRQuickBeltSlot component = ((Component)val).GetComponent<FVRQuickBeltSlot>();
					GM.CurrentPlayerBody.QBSlots_Internal.Add(component);
				}
			}
			Console.Write("Initial new SpineHeroObject");
		}
		else
		{
			activeScene = SceneManager.GetActiveScene();
			Console.Write("Can't find spawned SpineHeroObject,please wait for the assets load or report a bug,current scene name : {0}", ((Scene)(ref activeScene)).name);
		}
		AnvilCallback<GameObject> gameObjectAsync2 = ((AnvilAsset)IM.OD["SpineHeroObject"]).GetGameObjectAsync();
		if (Object.op_Implicit((Object)(object)gameObjectAsync2.Result))
		{
			SpineHeroObjectR = Object.Instantiate<GameObject>(gameObjectAsync2.Result);
			SpineHeroObjectR.transform.position = new Vector3(0f, 0f, 0f);
			SpineHeroObjectR.transform.rotation = Quaternion.identity;
			SpineHeroObjectR.transform.localPosition = Vector3.zero;
			SpineHeroObjectR.transform.localRotation = Quaternion.Euler(0f, 0f, -180f);
			foreach (Transform item2 in SpineHeroObjectR.gameObject.transform)
			{
				Transform val2 = item2;
				if (((Component)val2).gameObject.tag == "QuickbeltSlot")
				{
					FVRQuickBeltSlot component2 = ((Component)val2).GetComponent<FVRQuickBeltSlot>();
					GM.CurrentPlayerBody.QBSlots_Internal.Add(component2);
				}
			}
			Console.Write("Initial new SpineHeroObject");
		}
		else
		{
			activeScene = SceneManager.GetActiveScene();
			Console.Write("Can't find spawned SpineHeroObject,please wait for the assets load or report a bug,current scene name : {0}", ((Scene)(ref activeScene)).name);
		}
		newobj = true;
	}

	public void Update()
	{
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Expected O, but got Unknown
		timer += Time.deltaTime;
		if (!(timer > UpdateRate))
		{
			return;
		}
		timer -= UpdateRate;
		if (!LoadedPack)
		{
			foreach (string value in OtherLoader.ManagedBundles.Values)
			{
				if (value.Contains("ax.spinehero"))
				{
					FVRPlayerBody.ConfigureQuickbelt += new hook_ConfigureQuickbelt(CreateCustomQB);
					LoadedPack = true;
				}
			}
			return;
		}
		if (newobj)
		{
			SpineHeroObjectL.transform.parent = ((Component)GM.CurrentPlayerBody.LeftHand).transform;
			SpineHeroObjectL.transform.localPosition = Vector3.zero;
			SpineHeroObjectL.transform.localRotation = Quaternion.identity;
			SpineHeroObjectR.transform.parent = ((Component)GM.CurrentPlayerBody.RightHand).transform;
			SpineHeroObjectR.transform.localPosition = Vector3.zero;
			SpineHeroObjectR.transform.localRotation = Quaternion.Euler(0f, 0f, -180f);
			newobj = false;
		}
	}
}