Decompiled source of Holster Hider v1.1.0

Mods/HolsterHider.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib;
using BoneLib.BoneMenu;
using HolsterHider;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.VRMK;
using Il2CppSystem;
using Il2CppSystem.Collections;
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: AssemblyTitle("Holster Hider")]
[assembly: MelonInfo(typeof(HolsterHiderMod), "Holster Hider", "1.1.0", "Lakatrazz", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonOptionalDependencies(new string[] { "LabFusion" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
namespace HolsterHider;

public class BodyConfig
{
	private readonly HolsterConfig[] _holsterConfigs = null;

	public HolsterConfig[] HolsterConfigs => _holsterConfigs;

	public bool ScaleHolsters { get; set; } = true;


	public HolsterConfig HeadGroup => _holsterConfigs[0];

	public HolsterConfig RightShoulderGroup => _holsterConfigs[1];

	public HolsterConfig LeftShoulderGroup => _holsterConfigs[2];

	public HolsterConfig RightUnderarmGroup => _holsterConfigs[3];

	public HolsterConfig LeftUnderarmGroup => _holsterConfigs[4];

	public HolsterConfig BackGroup => _holsterConfigs[5];

	public HolsterConfig AmmoPouchGroup => _holsterConfigs[6];

	public HolsterConfig BodyLogGroup => _holsterConfigs[7];

	public BodyConfig()
	{
		_holsterConfigs = new HolsterConfig[8]
		{
			new HolsterConfig(),
			new HolsterConfig(),
			new HolsterConfig(),
			new HolsterConfig(),
			new HolsterConfig(),
			new HolsterConfig(),
			new HolsterConfig(),
			new HolsterConfig()
		};
	}
}
public class BodyPreference
{
	public HolsterPreference[] _holsterPreferences = null;

	public HolsterPreference[] HolsterPreferences => _holsterPreferences;

	public BoolPreference ScalePreference { get; set; }

	public HolsterPreference HeadPreference => _holsterPreferences[0];

	public HolsterPreference RightShoulderPreference => _holsterPreferences[1];

	public HolsterPreference LeftShoulderPreference => _holsterPreferences[2];

	public HolsterPreference RightUnderarmPreference => _holsterPreferences[3];

	public HolsterPreference LeftUnderarmPreference => _holsterPreferences[4];

	public HolsterPreference BackPreference => _holsterPreferences[5];

	public HolsterPreference AmmoPouchPreference => _holsterPreferences[6];

	public HolsterPreference BodyLogPreference => _holsterPreferences[7];

	public void LoadPreferences(MelonPreferences_Category category)
	{
		ScalePreference = new BoolPreference(category, "Resize Holsters");
		_holsterPreferences = new HolsterPreference[8]
		{
			new HolsterPreference(category, "Head"),
			new HolsterPreference(category, "Right Shoulder"),
			new HolsterPreference(category, "Left Shoulder"),
			new HolsterPreference(category, "Right Underarm"),
			new HolsterPreference(category, "Left Underarm"),
			new HolsterPreference(category, "Back"),
			new HolsterPreference(category, "Ammo Pouch"),
			new HolsterPreference(category, "Body Log")
		};
	}

	public void LoadConfig(BodyConfig config)
	{
		ScalePreference.OnSetValue = delegate(bool value)
		{
			config.ScaleHolsters = value;
		};
		ScalePreference.UpdatePreferences();
		for (int i = 0; i < HolsterPreferences.Length; i++)
		{
			HolsterPreferences[i].config = config.HolsterConfigs[i];
			HolsterPreferences[i].UpdatePreferences();
		}
	}

	public void UpdatePreferences()
	{
		ScalePreference.UpdatePreferences();
		HolsterPreference[] holsterPreferences = HolsterPreferences;
		foreach (HolsterPreference holsterPreference in holsterPreferences)
		{
			holsterPreference.UpdatePreferences();
		}
	}

	public void ResetPreferences()
	{
		ScalePreference.SetValue(value: true);
		HolsterPreference[] holsterPreferences = HolsterPreferences;
		foreach (HolsterPreference holsterPreference in holsterPreferences)
		{
			holsterPreference.SetVisibility(HolsterVisibility.DEFAULT);
		}
		HolsterHiderMod.UpdateHolsters();
	}
}
public class BodyReference
{
	private readonly HolsterReference[] _holsterReferences = null;

	private RigManager _rigManager = null;

	public HolsterReference[] HolsterReferences => _holsterReferences;

	public HolsterReference HeadGroup => _holsterReferences[0];

	public HolsterReference RightShoulderGroup => _holsterReferences[1];

	public HolsterReference LeftShoulderGroup => _holsterReferences[2];

	public HolsterReference RightUnderarmGroup => _holsterReferences[3];

	public HolsterReference LeftUnderarmGroup => _holsterReferences[4];

	public HolsterReference BackGroup => _holsterReferences[5];

	public HolsterReference AmmoPouchGroup => _holsterReferences[6];

	public HolsterReference BodyLogGroup => _holsterReferences[7];

	public BodyReference()
	{
		_holsterReferences = new HolsterReference[8]
		{
			new HolsterReference(),
			new HolsterReference(),
			new HolsterReference(),
			new HolsterReference(),
			new HolsterReference(),
			new HolsterReference(),
			new HolsterReference(),
			new HolsterReference()
		};
	}

	public void ApplyConfig(BodyConfig config)
	{
		if ((Object)(object)_rigManager == (Object)null)
		{
			return;
		}
		float scale = 1f;
		if (config.ScaleHolsters)
		{
			scale = _rigManager.avatar.height / 1.76f;
		}
		for (int i = 0; i < HolsterReferences.Length; i++)
		{
			HolsterReference holsterReference = HolsterReferences[i];
			if (holsterReference != AmmoPouchGroup && holsterReference != BodyLogGroup)
			{
				holsterReference.ScaleMeshes(scale);
				holsterReference.ScaleColliders(scale);
			}
			else
			{
				holsterReference.ScaleObject(scale);
			}
			holsterReference.SetVisibility(config.HolsterConfigs[i].visibility);
		}
	}

	public void CacheReferences(RigManager rigManager)
	{
		_rigManager = rigManager;
		Il2CppReferenceArray<SlotContainer> bodySlots = rigManager.inventory.bodySlots;
		CacheHolster((InventoryHandReceiver)(object)((Component)((Rig)rigManager.physicsRig).m_head).GetComponentInChildren<InventorySlotReceiver>(true), HeadGroup);
		CacheHolster((InventoryHandReceiver)(object)((Il2CppArrayBase<SlotContainer>)(object)bodySlots)[3].inventorySlotReceiver, RightShoulderGroup);
		CacheHolster((InventoryHandReceiver)(object)((Il2CppArrayBase<SlotContainer>)(object)bodySlots)[2].inventorySlotReceiver, LeftShoulderGroup);
		CacheHolster((InventoryHandReceiver)(object)((Il2CppArrayBase<SlotContainer>)(object)bodySlots)[5].inventorySlotReceiver, RightUnderarmGroup);
		CacheHolster((InventoryHandReceiver)(object)((Il2CppArrayBase<SlotContainer>)(object)bodySlots)[0].inventorySlotReceiver, LeftUnderarmGroup);
		CacheHolster((InventoryHandReceiver)(object)((Il2CppArrayBase<SlotContainer>)(object)bodySlots)[4].inventorySlotReceiver, BackGroup);
		CacheHolster((InventoryHandReceiver)(object)((Component)rigManager).GetComponentInChildren<InventoryAmmoReceiver>(true), AmmoPouchGroup);
		CachePullCord(((Component)((Il2CppArrayBase<SlotContainer>)(object)rigManager.inventory.specialItems)[0]).GetComponentInChildren<PullCordDevice>(true), BodyLogGroup);
	}

	private static void CacheHolster(InventoryHandReceiver receiver, HolsterReference holster)
	{
		Transform parent = ((Component)receiver).transform.parent;
		holster.CacheReferences(parent, Il2CppArrayBase<MeshRenderer>.op_Implicit(((Component)parent).GetComponentsInChildren<MeshRenderer>(true)), Il2CppArrayBase<Collider>.op_Implicit(((Component)parent).GetComponentsInChildren<Collider>(true)));
	}

	private static void CachePullCord(PullCordDevice pullCord, HolsterReference holster)
	{
		Transform transform = ((Component)pullCord).transform;
		holster.CacheReferences(transform, Il2CppArrayBase<MeshRenderer>.op_Implicit(((Component)transform.Find("BodyLog")).GetComponentsInChildren<MeshRenderer>(true)), Il2CppArrayBase<Collider>.op_Implicit(((Component)transform).GetComponentsInChildren<Collider>(true)));
	}
}
public class BoolPreference
{
	public MelonPreferences_Entry<bool> preference;

	public BoolElement element;

	public string identifier;

	public Action<bool> OnSetValue;

	public BoolPreference(MelonPreferences_Category category, string identifier)
	{
		preference = category.CreateEntry<bool>(identifier, true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		this.identifier = identifier;
	}

	public void OnBoneMenuChange(bool value)
	{
		SetValue(value);
		HolsterHiderMod.UpdateHolsters();
	}

	public void SetValue(bool value)
	{
		preference.Value = value;
		((MelonPreferences_Entry)preference).Category.SaveToFile(false);
		UpdatePreferences();
	}

	public void UpdatePreferences()
	{
		bool value = preference.Value;
		if (element != null)
		{
			element.Value = value;
		}
		OnSetValue?.Invoke(value);
	}
}
public class ColliderScaleHolder
{
	private Vector3 _initialSize = Vector3.one;

	private Vector3 _initialCenter = Vector3.zero;

	public ColliderScaleHolder(Collider collider)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		_initialSize = GetSize(collider);
		_initialCenter = GetCenter(collider);
	}

	public void SetScale(Collider collider, float scale)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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)
		SetSize(collider, _initialSize * scale);
		SetCenter(collider, _initialCenter * scale);
	}

	public Vector3 GetCenter(Collider collider)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		BoxCollider val = ((Il2CppObjectBase)collider).TryCast<BoxCollider>();
		if ((Object)(object)val != (Object)null)
		{
			return val.center;
		}
		CapsuleCollider val2 = ((Il2CppObjectBase)collider).TryCast<CapsuleCollider>();
		if ((Object)(object)val2 != (Object)null)
		{
			return val2.center;
		}
		SphereCollider val3 = ((Il2CppObjectBase)collider).TryCast<SphereCollider>();
		if ((Object)(object)val3 != (Object)null)
		{
			return val3.center;
		}
		return Vector3.zero;
	}

	public void SetCenter(Collider collider, Vector3 center)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		BoxCollider val = ((Il2CppObjectBase)collider).TryCast<BoxCollider>();
		if ((Object)(object)val != (Object)null)
		{
			val.center = center;
			return;
		}
		CapsuleCollider val2 = ((Il2CppObjectBase)collider).TryCast<CapsuleCollider>();
		if ((Object)(object)val2 != (Object)null)
		{
			val2.center = center;
			return;
		}
		SphereCollider val3 = ((Il2CppObjectBase)collider).TryCast<SphereCollider>();
		if ((Object)(object)val3 != (Object)null)
		{
			val3.center = center;
		}
	}

	public Vector3 GetSize(Collider collider)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: 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_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		BoxCollider val = ((Il2CppObjectBase)collider).TryCast<BoxCollider>();
		if ((Object)(object)val != (Object)null)
		{
			return val.size;
		}
		CapsuleCollider val2 = ((Il2CppObjectBase)collider).TryCast<CapsuleCollider>();
		if ((Object)(object)val2 != (Object)null)
		{
			return new Vector3(val2.radius, val2.height, val2.radius);
		}
		SphereCollider val3 = ((Il2CppObjectBase)collider).TryCast<SphereCollider>();
		if ((Object)(object)val3 != (Object)null)
		{
			return Vector3.one * val3.radius;
		}
		return Vector3.one;
	}

	public void SetSize(Collider collider, Vector3 size)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		BoxCollider val = ((Il2CppObjectBase)collider).TryCast<BoxCollider>();
		if ((Object)(object)val != (Object)null)
		{
			val.size = size;
			return;
		}
		CapsuleCollider val2 = ((Il2CppObjectBase)collider).TryCast<CapsuleCollider>();
		if ((Object)(object)val2 != (Object)null)
		{
			val2.radius = size.x;
			val2.height = size.y;
			return;
		}
		SphereCollider val3 = ((Il2CppObjectBase)collider).TryCast<SphereCollider>();
		if ((Object)(object)val3 != (Object)null)
		{
			val3.radius = size.x;
		}
	}
}
public enum HolsterVisibility
{
	DEFAULT,
	INVISIBLE,
	DISABLED
}
public class HolsterConfig
{
	public HolsterVisibility visibility;
}
public class HolsterPreference
{
	public MelonPreferences_Entry<HolsterVisibility> preference;

	public EnumElement element;

	public string identifier;

	public HolsterConfig config;

	public HolsterPreference(MelonPreferences_Category category, string identifier)
	{
		preference = category.CreateEntry<HolsterVisibility>(identifier, HolsterVisibility.DEFAULT, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		this.identifier = identifier;
	}

	public void OnBoneMenuChange(Enum value)
	{
		HolsterVisibility visibility = (HolsterVisibility)(object)value;
		SetVisibility(visibility);
		HolsterHiderMod.UpdateHolsters();
	}

	public void SetVisibility(HolsterVisibility visibility)
	{
		preference.Value = visibility;
		((MelonPreferences_Entry)preference).Category.SaveToFile(false);
		UpdatePreferences();
	}

	public void UpdatePreferences()
	{
		HolsterVisibility value = preference.Value;
		if (element != null)
		{
			element.Value = value;
		}
		if (config != null)
		{
			config.visibility = value;
		}
	}
}
public class HolsterReference
{
	private Transform _root;

	private Vector3 _rootLocalPosition;

	private Vector3 _rootLocalScale;

	private MeshRenderer[] _renderers;

	private Collider[] _colliders;

	private Vector3[] _rendererScales;

	private ColliderScaleHolder[] _colliderScales;

	public void CacheReferences(Transform root, MeshRenderer[] renderers, Collider[] colliders)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		_root = root;
		_rootLocalPosition = root.localPosition;
		_rootLocalScale = root.localScale;
		foreach (MeshRenderer val in renderers)
		{
			List<Transform> list = new List<Transform>();
			IEnumerator enumerator = ((Component)val).transform.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					Object current = enumerator.Current;
					list.Add(((Il2CppObjectBase)current).TryCast<Transform>());
				}
			}
			finally
			{
				if (enumerator is IDisposable disposable)
				{
					disposable.Dispose();
				}
			}
			foreach (Transform item in list)
			{
				((Component)item).transform.parent = ((Component)val).transform.parent;
			}
		}
		_renderers = renderers;
		_colliders = colliders;
		_rendererScales = (Vector3[])(object)new Vector3[renderers.Length];
		for (int j = 0; j < _rendererScales.Length; j++)
		{
			_rendererScales[j] = ((Component)renderers[j]).transform.localScale;
		}
		_colliderScales = new ColliderScaleHolder[colliders.Length];
		for (int k = 0; k < _colliderScales.Length; k++)
		{
			_colliderScales[k] = new ColliderScaleHolder(_colliders[k]);
		}
	}

	public void ScaleObject(float scale)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		_root.localScale = _rootLocalScale * scale;
	}

	public void ScaleMeshes(float scale)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		_root.localPosition = _rootLocalPosition * scale;
		for (int i = 0; i < _renderers.Length; i++)
		{
			((Component)_renderers[i]).transform.localScale = _rendererScales[i] * scale;
		}
	}

	public void ScaleColliders(float scale)
	{
		for (int i = 0; i < _colliders.Length; i++)
		{
			_colliderScales[i].SetScale(_colliders[i], scale);
		}
	}

	public void SetVisibility(HolsterVisibility visibility)
	{
		switch (visibility)
		{
		case HolsterVisibility.INVISIBLE:
		{
			((Component)_root).gameObject.SetActive(true);
			MeshRenderer[] renderers2 = _renderers;
			foreach (MeshRenderer val2 in renderers2)
			{
				((Renderer)val2).enabled = false;
			}
			break;
		}
		case HolsterVisibility.DISABLED:
			((Component)_root).gameObject.SetActive(false);
			break;
		default:
		{
			((Component)_root).gameObject.SetActive(true);
			MeshRenderer[] renderers = _renderers;
			foreach (MeshRenderer val in renderers)
			{
				((Renderer)val).enabled = true;
			}
			break;
		}
		}
	}
}
public class HolsterHiderMod : MelonMod
{
	public const string Version = "1.1.0";

	private static readonly BodyPreference _bodyPreferences = new BodyPreference();

	private static readonly BodyReference _bodyReferences = new BodyReference();

	private static readonly BodyConfig _bodyConfig = new BodyConfig();

	private bool _preferencesSetup = false;

	public MelonPreferences_Category MelonCategory { get; private set; }

	public Page MainPage { get; private set; }

	public override void OnLateInitializeMelon()
	{
		MelonCategory = MelonPreferences.CreateCategory("Holster Hider");
		_bodyPreferences.LoadPreferences(MelonCategory);
		_bodyPreferences.LoadConfig(_bodyConfig);
		SetupBoneMenu();
		_preferencesSetup = true;
		Hooking.OnLevelLoaded += OnLevelLoaded;
		Hooking.OnSwitchAvatarPostfix += OnSwitchAvatar;
	}

	private void OnSwitchAvatar(Avatar avatar)
	{
		if (!((Object)(object)avatar != (Object)(object)Player.RigManager.avatar))
		{
			UpdateHolsters();
		}
	}

	public void SetupBoneMenu()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		MainPage = Page.Root.CreatePage("Holster Hider", new Color(1f, 0.75f, 0.79f), 0, true);
		BoolPreference scalePreference = _bodyPreferences.ScalePreference;
		BoolElement element = MainPage.CreateBool("Resize Holsters", Color.cyan, scalePreference.preference.Value, (Action<bool>)scalePreference.OnBoneMenuChange);
		_bodyPreferences.ScalePreference.element = element;
		HolsterPreference[] holsterPreferences = _bodyPreferences.HolsterPreferences;
		foreach (HolsterPreference holsterPreference in holsterPreferences)
		{
			holsterPreference.element = MainPage.CreateEnum(holsterPreference.identifier, Color.green, (Enum)holsterPreference.preference.Value, (Action<Enum>)holsterPreference.OnBoneMenuChange);
		}
		MainPage.CreateFunction("Reset Settings", Color.green, (Action)ResetHolsters);
	}

	public override void OnPreferencesLoaded()
	{
		if (_preferencesSetup)
		{
			UpdatePreferences();
			UpdateHolsters();
		}
	}

	private void UpdatePreferences()
	{
		_bodyPreferences.UpdatePreferences();
	}

	public static void UpdateHolsters()
	{
		_bodyReferences.ApplyConfig(_bodyConfig);
	}

	private void ResetHolsters()
	{
		_bodyPreferences.ResetPreferences();
		UpdateHolsters();
	}

	public static void OnLevelLoaded(LevelInfo level)
	{
		RigManager rigManager = Player.RigManager;
		_bodyReferences.CacheReferences(rigManager);
		UpdateHolsters();
	}
}