Decompiled source of SillyItems v1.3.2

SillyGlasses.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using On.RoR2;
using RoR2;
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("SillyGlasses")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SillyGlasses")]
[assembly: AssemblyCopyright("Copyright ©  2019")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("29a2bb13-7659-4aac-b40e-529c72d5a209")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.1", FrameworkDisplayName = ".NET Framework 4.6.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: UnverifiableCode]
namespace SillyGlasses;

public class BootlegLimbMatcher : MonoBehaviour
{
	[Serializable]
	public struct LimbPair
	{
		public Transform originalTransform;

		public string targetChildLimb;

		public float originalLimbLength;

		[NonSerialized]
		public Transform targetTransform;
	}

	public bool scaleLimbs = true;

	private bool valid;

	public LimbPair[] limbPairs;

	private float distance;

	public void Init(LimbMatcher limbMatcher_, ChildLocator childLocator_, float distance_)
	{
		limbPairs = limbMatcher_.limbPairs;
		scaleLimbs = limbMatcher_.scaleLimbs;
		distance = distance_;
		SetChildLocator(childLocator_);
	}

	public void SetChildLocator(ChildLocator childLocator)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: 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)
		valid = true;
		for (int i = 0; i < limbPairs.Length; i++)
		{
			LimbPair val = limbPairs[i];
			Transform val2 = childLocator.FindChild(val.targetChildLimb);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				valid = false;
				break;
			}
			limbPairs[i].targetTransform = val2;
		}
	}

	private void LateUpdate()
	{
		UpdateLimbs();
	}

	private void UpdateLimbs()
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: 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)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: 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_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: 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)
		//IL_00c8: 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)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
		if (!valid)
		{
			return;
		}
		for (int i = 0; i < limbPairs.Length; i++)
		{
			LimbPair val = limbPairs[i];
			Transform targetTransform = val.targetTransform;
			if (!Object.op_Implicit((Object)(object)targetTransform) || !Object.op_Implicit((Object)(object)val.originalTransform))
			{
				continue;
			}
			val.originalTransform.position = targetTransform.position + targetTransform.forward * distance;
			val.originalTransform.rotation = targetTransform.rotation;
			if (i < limbPairs.Length - 1)
			{
				float num = Vector3.Magnitude(limbPairs[i + 1].targetTransform.position - targetTransform.position);
				float originalLimbLength = val.originalLimbLength;
				if (scaleLimbs)
				{
					Vector3 localScale = val.originalTransform.localScale;
					localScale.y = num / originalLimbLength;
					val.originalTransform.localScale = localScale;
				}
			}
		}
	}
}
public class CharacterSwooceHandler : MonoBehaviour
{
	private bool _subscribedToEvents;

	private Dictionary<ItemIndex, int> _instantiatedSillyAmounts = new Dictionary<ItemIndex, int>();

	private Dictionary<ItemIndex, Transform> _instantiatedSillyParents = new Dictionary<ItemIndex, Transform>();

	private Dictionary<ItemIndex, List<Transform>> _extraParentsLists = new Dictionary<ItemIndex, List<Transform>>();

	private Dictionary<ItemIndex, List<ParentedPrefabDisplay>> _sillyParentedPrefabDisplays = new Dictionary<ItemIndex, List<ParentedPrefabDisplay>>();

	private CharacterModel _swoocedCharacterModel;

	private Inventory _swoocedCurrentInventory;

	private ChildLocator _swoocedChildLocator;

	private float _specialItemDistance;

	private MaterialPropertyBlock propertyStorage;

	public CharacterModel swoocedCharacterModel => _swoocedCharacterModel;

	private int _cfgMaxItems => Utils.Cfg_ItemStackMax;

	private float _cfgDistanceMultiplier => Utils.Cfg_ItemDistanceMultiplier;

	public void Init(float distance_)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		propertyStorage = new MaterialPropertyBlock();
		_specialItemDistance = distance_;
		_swoocedCharacterModel = ((Component)this).GetComponent<CharacterModel>();
		_swoocedCurrentInventory = _swoocedCharacterModel.body.inventory;
		SubscribeToEvents(subscribing: true);
	}

	private void Update()
	{
		//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_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		Color val = Color.black;
		if (Object.op_Implicit((Object)(object)_swoocedCharacterModel.body) && Object.op_Implicit((Object)(object)_swoocedCharacterModel.body.healthComponent))
		{
			float num = Mathf.Clamp01(1f - _swoocedCharacterModel.body.healthComponent.timeSinceLastHit / CharacterModel.hitFlashDuration);
			float num2 = Mathf.Pow(Mathf.Clamp01(1f - _swoocedCharacterModel.body.healthComponent.timeSinceLastHeal / CharacterModel.healFlashDuration), 0.5f);
			val = ((!(num2 > num)) ? (((_swoocedCharacterModel.body.healthComponent.shield > 0f) ? CharacterModel.hitFlashShieldColor : CharacterModel.hitFlashBaseColor) * num) : (CharacterModel.healFlashColor * num2));
		}
		foreach (List<ParentedPrefabDisplay> value in _sillyParentedPrefabDisplays.Values)
		{
			for (int i = 0; i < value.Count; i++)
			{
				ParentedPrefabDisplay val2 = value[i];
				ItemDisplay itemDisplay = ((ParentedPrefabDisplay)(ref val2)).itemDisplay;
				if (!((Object)(object)itemDisplay == (Object)null))
				{
					itemDisplay.SetVisibilityLevel(_swoocedCharacterModel.visibility);
					for (int j = 0; j < itemDisplay.rendererInfos.Length; j++)
					{
						Renderer renderer = itemDisplay.rendererInfos[j].renderer;
						renderer.GetPropertyBlock(propertyStorage);
						propertyStorage.SetColor(CommonShaderProperties._FlashColor, val);
						propertyStorage.SetFloat(CommonShaderProperties._Fade, _swoocedCharacterModel.fade);
						renderer.SetPropertyBlock(propertyStorage);
					}
				}
			}
		}
	}

	private void OnDestroy()
	{
		SubscribeToEvents(subscribing: false);
	}

	private void SubscribeToEvents(bool subscribing)
	{
		if (subscribing != _subscribedToEvents)
		{
			_subscribedToEvents = subscribing;
			if (subscribing)
			{
				SillyGlassesPlugin instance = SillyGlassesPlugin.instance;
				instance.enableDisableDisplayEvent = (SillyGlassesPlugin.EnableDisableDisplayEvent)Delegate.Combine(instance.enableDisableDisplayEvent, new SillyGlassesPlugin.EnableDisableDisplayEvent(onHookedEnableDisableDisplay));
			}
			else
			{
				SillyGlassesPlugin instance2 = SillyGlassesPlugin.instance;
				instance2.enableDisableDisplayEvent = (SillyGlassesPlugin.EnableDisableDisplayEvent)Delegate.Remove(instance2.enableDisableDisplayEvent, new SillyGlassesPlugin.EnableDisableDisplayEvent(onHookedEnableDisableDisplay));
			}
		}
	}

	public void onHookedEnableDisableDisplay(CharacterModel characterModel_, ItemIndex itemIndex_)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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_0044: 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)
		if (!((Object)(object)characterModel_ == (Object)null) && !((Object)(object)((Component)characterModel_).gameObject != (Object)(object)((Component)this).gameObject) && Object.op_Implicit((Object)(object)characterModel_.itemDisplayRuleSet))
		{
			DisplayRuleGroup itemDisplayRuleGroup = characterModel_.itemDisplayRuleSet.GetItemDisplayRuleGroup(itemIndex_);
			PseudoInstantiateDisplayRuleGroup(characterModel_, itemDisplayRuleGroup, itemIndex_);
		}
	}

	private void PseudoInstantiateDisplayRuleGroup(CharacterModel characterModel_, DisplayRuleGroup displayRuleGroup_, ItemIndex itemIndex_)
	{
		//IL_002f: 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_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Invalid comparison between Unknown and I4
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: 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_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0233: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Invalid comparison between Unknown and I4
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Unknown result type (might be due to invalid IL or missing references)
		//IL_0315: Unknown result type (might be due to invalid IL or missing references)
		//IL_0336: Unknown result type (might be due to invalid IL or missing references)
		//IL_035f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0367: Unknown result type (might be due to invalid IL or missing references)
		//IL_0388: Unknown result type (might be due to invalid IL or missing references)
		//IL_0389: Unknown result type (might be due to invalid IL or missing references)
		//IL_038e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0397: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_swoocedCurrentInventory == (Object)null || (Object)(object)characterModel_ != (Object)(object)_swoocedCharacterModel || displayRuleGroup_.rules == null || displayRuleGroup_.rules.Length == 0 || (int)itemIndex_ == -1)
		{
			return;
		}
		if (!_instantiatedSillyAmounts.ContainsKey(itemIndex_))
		{
			_instantiatedSillyAmounts.Add(itemIndex_, 0);
		}
		int itemCount = _swoocedCurrentInventory.GetItemCount(itemIndex_);
		int num = _instantiatedSillyAmounts[itemIndex_];
		int num2 = num + ((itemCount > 0) ? 1 : 0);
		int num3 = itemCount - num2;
		if (itemCount == 1 && num3 >= 0)
		{
			return;
		}
		ParentedPrefabDisplay item;
		if (num3 < 0)
		{
			if (!_instantiatedSillyParents.ContainsKey(itemIndex_) || !((Object)(object)_instantiatedSillyParents[itemIndex_] != (Object)null))
			{
				return;
			}
			Object.Destroy((Object)(object)((Component)_instantiatedSillyParents[itemIndex_]).gameObject);
			_instantiatedSillyParents[itemIndex_] = null;
			_instantiatedSillyAmounts[itemIndex_] = 0;
			if (_extraParentsLists.ContainsKey(itemIndex_) && _extraParentsLists[itemIndex_] != null)
			{
				List<Transform> list = _extraParentsLists[itemIndex_];
				for (int num4 = list.Count - 1; num4 >= 0; num4--)
				{
					if (Object.op_Implicit((Object)(object)list[num4]))
					{
						Object.Destroy((Object)(object)((Component)list[num4]).gameObject);
					}
					list.RemoveAt(num4);
				}
			}
			if (_sillyParentedPrefabDisplays.ContainsKey(itemIndex_))
			{
				for (int num5 = _sillyParentedPrefabDisplays[itemIndex_].Count - 1; num5 >= 0; num5--)
				{
					item = _sillyParentedPrefabDisplays[itemIndex_][num5];
					((ParentedPrefabDisplay)(ref item)).Undo();
				}
				_sillyParentedPrefabDisplays[itemIndex_].Clear();
			}
			PseudoInstantiateDisplayRuleGroup(characterModel_, displayRuleGroup_, itemIndex_);
			return;
		}
		if ((Object)(object)_swoocedChildLocator == (Object)null)
		{
			_swoocedChildLocator = ((Component)characterModel_).GetComponent<ChildLocator>();
		}
		for (int i = 0; i < num3; i++)
		{
			int num6 = num2 + i;
			if (_cfgMaxItems != -1 && num6 + 1 >= _cfgMaxItems)
			{
				break;
			}
			_instantiatedSillyAmounts[itemIndex_]++;
			for (int j = 0; j < displayRuleGroup_.rules.Length; j++)
			{
				ItemDisplayRule val = displayRuleGroup_.rules[j];
				if ((int)val.ruleType > 0)
				{
					continue;
				}
				Transform val2 = _swoocedChildLocator.FindChild(val.childName);
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				GameObject val3 = InstantiateSillyItem(val, _swoocedChildLocator, val2, num6, itemIndex_);
				if (!((Object)(object)val3 == (Object)null))
				{
					if (!_sillyParentedPrefabDisplays.ContainsKey(itemIndex_))
					{
						_sillyParentedPrefabDisplays[itemIndex_] = new List<ParentedPrefabDisplay>();
					}
					List<ParentedPrefabDisplay> list2 = _sillyParentedPrefabDisplays[itemIndex_];
					item = default(ParentedPrefabDisplay);
					((ParentedPrefabDisplay)(ref item)).instance = val3;
					((ParentedPrefabDisplay)(ref item)).itemDisplay = val3.GetComponent<ItemDisplay>();
					item.itemIndex = itemIndex_;
					list2.Add(item);
					Transform sillyParent = GetSillyParent(itemIndex_, val2);
					val3.transform.parent = sillyParent;
					if ((Object)(object)sillyParent == (Object)null)
					{
						Utils.Log("sillyParent is null \nwait how \nI should be pretty much covering all the bases there");
					}
				}
			}
		}
	}

	private GameObject InstantiateSillyItem(ItemDisplayRule displayRule_, ChildLocator childLocator_, Transform bodyDisplayParent_, int instanceMult_, ItemIndex itemIndex_)
	{
		//IL_0001: 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)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: 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_0030: 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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: 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_0098: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: 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_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: 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_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		GameObject followerPrefab = displayRule_.followerPrefab;
		if ((Object)(object)followerPrefab == (Object)null)
		{
			return null;
		}
		Vector3 localPos = displayRule_.localPos;
		Quaternion localRotation = Quaternion.Euler(displayRule_.localAngles);
		Vector3 localScale = displayRule_.localScale;
		GameObject val = Object.Instantiate<GameObject>(followerPrefab.gameObject, bodyDisplayParent_);
		val.transform.localPosition = localPos;
		val.transform.localRotation = localRotation;
		val.transform.localScale = localScale;
		float num = (float)instanceMult_ * _cfgDistanceMultiplier * _specialItemDistance;
		Vector3 val2;
		Vector3 val3;
		if (!Utils.Cfg_OutwardStackType)
		{
			val2 = val.transform.forward * num;
		}
		else if (displayRule_.childName != "Head")
		{
			val3 = val.transform.position - bodyDisplayParent_.position;
			Vector3 normalized = ((Vector3)(ref val3)).normalized;
			val3 = Vector3.Cross(((Component)bodyDisplayParent_).transform.up, normalized);
			Vector3 normalized2 = ((Vector3)(ref val3)).normalized;
			val3 = Vector3.Cross(((Component)bodyDisplayParent_).transform.up, normalized2);
			normalized2 = ((Vector3)(ref val3)).normalized;
			val3 = (normalized - normalized2) * 0.5f;
			Vector3 normalized3 = ((Vector3)(ref val3)).normalized;
			val2 = normalized3 * num;
		}
		else
		{
			val3 = val.transform.position - bodyDisplayParent_.position;
			val2 = ((Vector3)(ref val3)).normalized * num;
		}
		Transform transform = val.transform;
		transform.position += val2;
		if (Utils.Cfg_UseLogs)
		{
			((Object)val).name = $"{((Object)val).name} {instanceMult_}";
		}
		LimbMatcher component = val.GetComponent<LimbMatcher>();
		if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)childLocator_))
		{
			val.AddComponent<BootlegLimbMatcher>().Init(component, childLocator_, num);
		}
		return val;
	}

	private Transform GetSillyParent(ItemIndex itemIndex_, Transform bodyDisplayParent_)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: 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_0168: Unknown result type (might be due to invalid IL or missing references)
		Transform val = (_instantiatedSillyParents.ContainsKey(itemIndex_) ? _instantiatedSillyParents[itemIndex_] : null);
		if ((Object)(object)val == (Object)null)
		{
			Transform val2 = CreateNewParentedTransform("SillyItem_" + ((object)(ItemIndex)(ref itemIndex_)).ToString() + "_Parent", bodyDisplayParent_);
			_instantiatedSillyParents[itemIndex_] = val2;
			return val2;
		}
		if ((Object)(object)val != (Object)null && (Object)(object)val.parent == (Object)(object)bodyDisplayParent_)
		{
			return _instantiatedSillyParents[itemIndex_];
		}
		if ((Object)(object)val != (Object)null && (Object)(object)val.parent != (Object)(object)bodyDisplayParent_)
		{
			List<Transform> list = null;
			if (!_extraParentsLists.ContainsKey(itemIndex_))
			{
				_extraParentsLists[itemIndex_] = new List<Transform>();
			}
			list = _extraParentsLists[itemIndex_];
			Transform val3 = list.Find((Transform extra) => (Object)(object)bodyDisplayParent_ == (Object)(object)extra.parent);
			if ((Object)(object)val3 == (Object)null)
			{
				val3 = CreateNewParentedTransform("SillyItem_" + ((object)(ItemIndex)(ref itemIndex_)).ToString() + "_ExtraParent", bodyDisplayParent_);
				_extraParentsLists[itemIndex_].Add(val3);
			}
			return val3;
		}
		return null;
	}

	private Transform CreateNewParentedTransform(string name, Transform parent)
	{
		//IL_0002: 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_0022: 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)
		Transform transform = new GameObject(name).transform;
		transform.parent = parent;
		transform.localPosition = Vector3.one;
		transform.localRotation = Quaternion.identity;
		transform.localScale = Vector3.one;
		return transform;
	}

	private void ShowFunnyCube(Transform parent_, Vector3 displayRuleLocalPos_, Quaternion displayRuleLocalRotation_, float forwardDistance_)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Expected O, but got Unknown
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
		Type[] array = new Type[2]
		{
			typeof(MeshRenderer),
			typeof(MeshFilter)
		};
		GameObject val2 = new GameObject("bruh", array);
		val2.GetComponent<MeshFilter>().mesh = val.GetComponent<MeshFilter>().mesh;
		((Renderer)val2.GetComponent<MeshRenderer>()).material = new Material(((Renderer)val.GetComponent<MeshRenderer>()).material);
		val2.transform.parent = parent_;
		val2.transform.localPosition = displayRuleLocalPos_;
		val2.transform.localRotation = displayRuleLocalRotation_;
		val2.transform.localScale = new Vector3(0.169f, 0.01f, 0.1f);
		Transform transform = val2.transform;
		transform.position += val2.transform.forward * forwardDistance_;
		Object.Destroy((Object)(object)val);
	}

	private static void RunCheats()
	{
		if (!Utils.Cfg_PlantsForHire)
		{
		}
	}

	private void TestAddGlasses()
	{
		if ((Object)(object)_swoocedCurrentInventory != (Object)null)
		{
			_swoocedCurrentInventory.GiveItem((ItemIndex)Utils.Cfg_CheatItemBoring, 1);
		}
	}

	private void TestRemoveGlasses()
	{
		if ((Object)(object)_swoocedCurrentInventory != (Object)null)
		{
			_swoocedCurrentInventory.RemoveItem((ItemIndex)Utils.Cfg_CheatItemBoring, 1);
		}
	}
}
public class Utils
{
	public static int Cfg_ItemStackMax = -1;

	public static bool Cfg_OutwardStackType;

	public static float Cfg_ItemDistanceMultiplier = 0.042f;

	public static float Cfg_EngiTurretItemDistanceMultiplier = 1.5f;

	public static float Cfg_ScavengerItemDistanceMultiplier = 6f;

	public static float Cfg_BrotherItemDistanceMultiplier = 2f;

	public static bool Cfg_UseLogs = false;

	public static bool Cfg_PlantsForHire = false;

	public static int Cfg_CheatItem = 7;

	public static int Cfg_CheatItemBoring = 58;

	public static void Log(string logString, bool chat = false)
	{
		if (Cfg_UseLogs)
		{
			Debug.LogWarning((object)("[SillyLog] " + logString));
			if (chat)
			{
				Chat.AddMessage(logString);
			}
		}
	}
}
[BepInPlugin("com.TheTimeSweeper.SillyItem", "Silly Items", "1.3.2")]
public class SillyGlassesPlugin : BaseUnityPlugin
{
	public delegate void UpdateItemDisplayEvent(CharacterModel self, Inventory inventory);

	public delegate void EnableDisableDisplayEvent(CharacterModel self, ItemIndex itemIndex);

	public delegate void UpdateMaterialsEvent(CharacterModel self);

	public delegate void UpdateCameraEvent(CharacterModel self, CameraRigController cameraRig);

	public EnableDisableDisplayEvent enableDisableDisplayEvent;

	private string[] _turretGuyNames = new string[4] { "EngiBeamTurretBody", "EngiTurretBody", "EngiWalkerTurretBody", "TeslaTowerBody" };

	private string[] _scavGuyNames = new string[5] { "ScavBody", "ScavLunar1Body", "ScavLunar2Body", "ScavLunar3Body", "ScavLunar4Body" };

	private string[] _moonGuyNames = new string[5] { "BrotherBody", "BrotherGlassBody", "BrotherHauntBody", "BrotherHurtBody", "MithrixBody" };

	private int _currentRandomIndex;

	private int _spawnedRandomItems;

	private int _currentRedIndex;

	private int _spawnedRedItems;

	public static SillyGlassesPlugin instance;

	public void Awake()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		instance = this;
		InitConfig();
		CharacterBody.OnInventoryChanged += new hook_OnInventoryChanged(InvChangedHook);
		CharacterModel.EnableItemDisplay += new hook_EnableItemDisplay(EnableItemDisplayHook);
		CharacterModel.DisableItemDisplay += new hook_DisableItemDisplay(DisableItemDisplayHook);
	}

	private void CharacterBody_Awake(orig_Awake orig, CharacterBody self)
	{
		orig.Invoke(self);
		float specialItemDistance = getSpecialItemDistance(self);
		ModelLocator modelLocator = self.modelLocator;
		if (!((Object)(object)((modelLocator != null) ? modelLocator.modelTransform : null) == (Object)null))
		{
			CharacterSwooceHandler characterSwooceHandler = ((Component)self.modelLocator.modelTransform).gameObject.AddComponent<CharacterSwooceHandler>();
			characterSwooceHandler.Init(specialItemDistance);
		}
	}

	private void InitConfig()
	{
		string text = "hope youre having a lovely day";
		Utils.Cfg_ItemStackMax = ((BaseUnityPlugin)this).Config.Bind<int>(text, "ItemStacksMax", -1, "Maximum item displays that can be spawned (-1 for infinite).").Value;
		Utils.Cfg_OutwardStackType = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "Outward Stacking", false, "Makes item stacks outward from the bone it's attached to, rather than their object's forward facing direction.").Value;
		Utils.Cfg_ItemDistanceMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>(text, "ItemDistanceMultiplier", 0.048f, "The distance between extra displays that spawns.").Value;
		Utils.Cfg_EngiTurretItemDistanceMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>(text, "EngiTurretItemDistanceMultiplier", 1.5f, "Items are a little bigger on Engis Turrets. Spread them out a bit more.").Value;
		Utils.Cfg_ScavengerItemDistanceMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>(text, "ScavItemDistanceMultiplier", 6f, "Items are a also bigger on Scavengers I think").Value;
		Utils.Cfg_BrotherItemDistanceMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>(text, "BrotherItemDistanceMultiplier", 2f, "Big Spikes.").Value;
		Utils.Cfg_UseLogs = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "Output Logs", false, "because I keep forgetting to remove logs from my builds haha woops.").Value;
		string text2 = "liar liar plants for hire";
		Utils.Cfg_PlantsForHire = ((BaseUnityPlugin)this).Config.Bind<bool>(text2, "Cheats", false, "Press f2 f3 f6 and f9 to rain items from the sky.").Value;
		Utils.Cfg_CheatItem = ((BaseUnityPlugin)this).Config.Bind<int>(text2, "Cheat Item", 7, "Press f7 to spawn this item (glasses are 7)").Value;
		Utils.Cfg_CheatItemBoring = ((BaseUnityPlugin)this).Config.Bind<int>(text2, "Cheat Item2", 58, "Press f11 and f10 to add/remove this item boringly (58 for magazines)").Value;
	}

	private void CharacterBody_Start(orig_Start orig, CharacterBody self)
	{
		orig.Invoke(self);
		float specialItemDistance = getSpecialItemDistance(self);
		ModelLocator modelLocator = self.modelLocator;
		if (!((Object)(object)((modelLocator != null) ? modelLocator.modelTransform : null) == (Object)null))
		{
			CharacterSwooceHandler characterSwooceHandler = ((Component)self.modelLocator.modelTransform).gameObject.AddComponent<CharacterSwooceHandler>();
			characterSwooceHandler.Init(specialItemDistance);
		}
	}

	private void InvChangedHook(orig_OnInventoryChanged orig, CharacterBody self)
	{
		float specialItemDistance = getSpecialItemDistance(self);
		if (!((Object)(object)self.modelLocator.modelTransform == (Object)null))
		{
			if ((Object)(object)((Component)self.modelLocator.modelTransform).gameObject.GetComponent<CharacterSwooceHandler>() == (Object)null)
			{
				CharacterSwooceHandler characterSwooceHandler = ((Component)self.modelLocator.modelTransform).gameObject.AddComponent<CharacterSwooceHandler>();
				characterSwooceHandler.Init(specialItemDistance);
			}
			orig.Invoke(self);
		}
	}

	private float getSpecialItemDistance(CharacterBody self)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: 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_0021: 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)
		BodyIndex bodyIndex = self.bodyIndex;
		if (CheckNames(bodyIndex, _turretGuyNames))
		{
			return Utils.Cfg_EngiTurretItemDistanceMultiplier;
		}
		if (CheckNames(bodyIndex, _scavGuyNames))
		{
			return Utils.Cfg_ScavengerItemDistanceMultiplier;
		}
		if (CheckNames(bodyIndex, _moonGuyNames))
		{
			return Utils.Cfg_BrotherItemDistanceMultiplier;
		}
		return 1f;
	}

	private static bool CheckNames(BodyIndex index, string[] names)
	{
		//IL_0006: 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)
		for (int i = 0; i < names.Length; i++)
		{
			if (index == BodyCatalog.FindBodyIndex(names[i]))
			{
				return true;
			}
		}
		return false;
	}

	private void DisableItemDisplayHook(orig_DisableItemDisplay orig, CharacterModel self, ItemIndex itemIndex)
	{
		//IL_0003: 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)
		orig.Invoke(self, itemIndex);
		enableDisableDisplayEvent?.Invoke(self, itemIndex);
	}

	private void EnableItemDisplayHook(orig_EnableItemDisplay orig, CharacterModel self, ItemIndex itemIndex)
	{
		//IL_0003: 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)
		orig.Invoke(self, itemIndex);
		enableDisableDisplayEvent?.Invoke(self, itemIndex);
	}

	public void Update()
	{
	}

	private void TestSpawnItem(int item = -1)
	{
		List<PickupIndex> availableTier1DropList = Run.instance.availableTier1DropList;
		TestSpawnItem(availableTier1DropList, item);
	}

	private void TestSpawnItemRed()
	{
		List<PickupIndex> availableTier3DropList = Run.instance.availableTier3DropList;
		TestSpawnItem(availableTier3DropList, -1, random: false);
	}

	private void TestSpawnItem(List<PickupIndex> dropList, int item = -1, bool random = true)
	{
		//IL_0100: 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_0108: 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_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: 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_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = PlayerCharacterMasterController.instances[0].master.GetBodyObject().transform;
		PickupIndex val = default(PickupIndex);
		if (item > -1)
		{
			((PickupIndex)(ref val))..ctor((ItemIndex)item);
		}
		else
		{
			if (dropList.Count < 0)
			{
				return;
			}
			if (random)
			{
				if (_spawnedRandomItems >= 3)
				{
					Utils.Log("treasureRNG broken", chat: true);
					_spawnedRandomItems = 1;
				}
				else
				{
					_spawnedRandomItems++;
				}
				val = dropList[_currentRandomIndex];
			}
			else
			{
				_spawnedRedItems++;
				if (_spawnedRedItems >= 3)
				{
					_currentRedIndex++;
					_spawnedRedItems = 0;
				}
				if (_currentRedIndex >= dropList.Count)
				{
					_currentRedIndex = 1;
				}
				val = dropList[_currentRedIndex];
			}
		}
		Vector3 insideUnitSphere = Random.insideUnitSphere;
		insideUnitSphere.y = Mathf.Abs(insideUnitSphere.y * 3f);
		insideUnitSphere /= 3f;
		PickupDropletController.CreatePickupDroplet(val, transform.position + Vector3.up * 69f, insideUnitSphere * 20f);
	}
}
public class SillyItemDisplayRules : List<SillyItemDisplayRule>
{
}
public enum SillyItemDisplayBehavior
{
	DEFAULT,
	DEFAULT_BOTH_WAYS,
	OUTWARD,
	SCATTER
}
public class SillyItemDisplayRule
{
	public string character;

	public ItemIndex item;

	public Vector3 defaultStackDirection = Vector3.forward;

	public float distanceMult = 1f;

	public SillyItemDisplayBehavior stackBehavior;
}