Decompiled source of MwSkinAdditions v1.3.0

MwSkinAdditions.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Missions.BrotherEncounter;
using HG;
using IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour.HookGen;
using MwSkinAdditions.Networking;
using On.EntityStates;
using On.EntityStates.Missions.BrotherEncounter;
using On.RoR2;
using On.RoR2.UI;
using R2API.Networking;
using R2API.Networking.Interfaces;
using R2API.Utils;
using RoR2;
using RoR2.Audio;
using RoR2.ContentManagement;
using RoR2.Networking;
using RoR2.UI;
using RoR2BepInExPack.Utilities;
using UnityEngine;
using UnityEngine.Networking;
using dteeicons;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MwSkinAdditions")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5801f88961db0b793e052a1beecc22059a75c845")]
[assembly: AssemblyProduct("MwSkinAdditions")]
[assembly: AssemblyTitle("MwSkinAdditions")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MwSkinAdditions
{
	public class BlendShapeAnimation
	{
		public string meshName;

		public string blendShapeName;

		public int feature;

		public int priority;

		public float fadeInDuration;

		public float holdDuration;

		public float fadeOutDuration;

		public bool blockBlinking;

		public BlendShapeAnimation(string meshName, string blendShapeName, int feature, int priority, float fadeInDuration, float holdDuration, float fadeOutDuration, bool blockBlinking = false)
		{
			this.meshName = meshName;
			this.blendShapeName = blendShapeName;
			this.feature = feature;
			this.priority = priority;
			this.fadeInDuration = fadeInDuration;
			this.holdDuration = holdDuration;
			this.fadeOutDuration = fadeOutDuration;
			this.blockBlinking = blockBlinking;
		}
	}
	public class BlinkBlendShapeAnimation : BlendShapeAnimation
	{
		public BlinkBlendShapeAnimation(string meshName, string blendShapeName, int feature = -1, int priority = 0, float fadeInDuration = 0.1f, float holdDuration = 0f, float fadeOutDuration = 0.1f, bool blockBlinking = false)
			: base(meshName, blendShapeName, feature, priority, fadeInDuration, holdDuration, fadeOutDuration, blockBlinking)
		{
		}
	}
	public class ExpressionController : MwBaseComponent
	{
		private class ExpressionState
		{
			public Coroutine coroutine;

			public BlendShapeAnimation animation;

			public SkinnedMeshRenderer skinnedMeshRenderer;

			public bool finished;
		}

		private EventSubOptions options;

		private CharacterBody cachedCharacterBody;

		private Dictionary<string, SkinnedMeshRenderer> cachedRenderers = new Dictionary<string, SkinnedMeshRenderer>();

		private Dictionary<string, int> cachedBlendShapes = new Dictionary<string, int>();

		private Dictionary<int, ExpressionState> featureStates = new Dictionary<int, ExpressionState>();

		private Dictionary<int, bool> featureActive = new Dictionary<int, bool>();

		public bool inDeathState;

		private float blinkInterval;

		private float blinkStopwatch;

		private bool doubleBlink;

		private int blinkStoppers;

		public CharacterBody characterBody
		{
			get
			{
				if ((Object)(object)cachedCharacterBody != (Object)null)
				{
					return cachedCharacterBody;
				}
				cachedCharacterBody = ((Component)this).GetComponent<CharacterBody>();
				return cachedCharacterBody;
			}
		}

		private ExpressionController()
		{
			blinkInterval = Random.Range(0f, 5f);
		}

		public override void Init(EventSub eventSub)
		{
			options = eventSub?.options;
			eventSub.Death = (Action<GameObject>)Delegate.Combine(eventSub.Death, (Action<GameObject>)delegate
			{
				inDeathState = true;
			});
		}

		public void TryPlayAnimation(BlendShapeAnimation animation)
		{
			SkinnedMeshRenderer skinnedMeshRenderer = GetSkinnedMeshRenderer(animation.meshName);
			if (Object.op_Implicit((Object)(object)skinnedMeshRenderer))
			{
				TrySetExpressionRoutine(animation, skinnedMeshRenderer);
			}
		}

		private SkinnedMeshRenderer GetSkinnedMeshRenderer(string meshName)
		{
			if (cachedRenderers.ContainsKey(meshName))
			{
				SkinnedMeshRenderer val = cachedRenderers[meshName];
				if (val != null)
				{
					return val;
				}
			}
			SkinnedMeshRenderer val2 = null;
			GameObject modelFromEventBody = SkinEvents.GetModelFromEventBody(((Component)this).gameObject);
			if (Object.op_Implicit((Object)(object)modelFromEventBody))
			{
				Transform val3 = modelFromEventBody.transform.Find(meshName);
				if (Object.op_Implicit((Object)(object)val3))
				{
					val2 = ((Component)val3).GetComponent<SkinnedMeshRenderer>();
				}
			}
			cachedRenderers[meshName] = val2;
			return val2;
		}

		private void TrySetExpressionRoutine(BlendShapeAnimation animation, SkinnedMeshRenderer renderer)
		{
			ExpressionState featureState = GetFeatureState(animation.feature);
			if (featureState != null && animation.priority > featureState.animation.priority)
			{
				CancelExpressionSmooth(featureState);
			}
			if (!GetFeatureActive(animation.feature))
			{
				ExpressionState expressionState = new ExpressionState
				{
					animation = animation,
					skinnedMeshRenderer = renderer
				};
				expressionState.coroutine = ((MonoBehaviour)this).StartCoroutine(ExpressionRoutine(animation, renderer, expressionState));
				featureStates[animation.feature] = expressionState;
				if (animation.blockBlinking)
				{
					blinkStoppers++;
				}
			}
		}

		private IEnumerator ExpressionRoutine(BlendShapeAnimation animation, SkinnedMeshRenderer renderer, ExpressionState expressionState)
		{
			float stopwatch = 0f;
			featureActive[animation.feature] = true;
			int index = GetBlendShapeIndex(animation, renderer);
			while (stopwatch < animation.fadeInDuration)
			{
				stopwatch += Time.deltaTime;
				renderer.SafeSetBlendShapeWeight(index, Mathf.Lerp(0f, 100f, stopwatch / animation.fadeInDuration));
				yield return null;
			}
			renderer.SafeSetBlendShapeWeight(index, 100f);
			yield return (object)new WaitForSeconds(animation.holdDuration);
			stopwatch = 0f;
			while (stopwatch < animation.fadeOutDuration)
			{
				stopwatch += Time.deltaTime;
				renderer.SafeSetBlendShapeWeight(index, Mathf.Lerp(100f, 0f, stopwatch / animation.fadeOutDuration));
				yield return null;
			}
			renderer.SafeSetBlendShapeWeight(index, 0f);
			featureActive[animation.feature] = false;
			if (animation.blockBlinking)
			{
				blinkStoppers--;
			}
			expressionState.finished = true;
		}

		public void CancelCurrentExpressionsSmooth()
		{
			foreach (ExpressionState value in featureStates.Values)
			{
				if (value != null)
				{
					CancelExpressionSmooth(value);
				}
			}
		}

		public void CancelCurrentExpressions()
		{
			foreach (ExpressionState value in featureStates.Values)
			{
				if (value != null)
				{
					CancelExpression(value);
				}
			}
		}

		private void CancelExpressionSmooth(ExpressionState expressionState)
		{
			CancelExpression(expressionState);
			((MonoBehaviour)this).StartCoroutine(BlendToZero(expressionState));
		}

		private void CancelExpression(ExpressionState expressionState)
		{
			((MonoBehaviour)this).StopCoroutine(expressionState.coroutine);
			featureActive[expressionState.animation.feature] = false;
			if (!expressionState.finished && expressionState.animation.blockBlinking)
			{
				blinkStoppers--;
				expressionState.finished = true;
			}
		}

		private IEnumerator BlendToZero(ExpressionState expressionState)
		{
			int index = GetBlendShapeIndex(expressionState.animation, expressionState.skinnedMeshRenderer);
			float startWeight = expressionState.skinnedMeshRenderer.GetBlendShapeWeight(index);
			float stopwatch = 0f;
			while (stopwatch < expressionState.animation.fadeOutDuration)
			{
				stopwatch += Time.deltaTime;
				expressionState.skinnedMeshRenderer.SafeSetBlendShapeWeight(index, Mathf.Lerp(startWeight, 0f, stopwatch / expressionState.animation.fadeOutDuration));
				yield return null;
			}
		}

		private ExpressionState GetFeatureState(int feature)
		{
			if (featureStates.ContainsKey(feature))
			{
				return featureStates[feature];
			}
			return null;
		}

		private bool GetFeatureActive(int feature)
		{
			if (featureActive.ContainsKey(feature))
			{
				return featureActive[feature];
			}
			return false;
		}

		private int GetBlendShapeIndex(BlendShapeAnimation animation, SkinnedMeshRenderer skinnedMeshRenderer)
		{
			if (cachedBlendShapes.ContainsKey(animation.blendShapeName))
			{
				return cachedBlendShapes[animation.blendShapeName];
			}
			int blendShapeIndex = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(animation.blendShapeName);
			cachedBlendShapes[animation.blendShapeName] = blendShapeIndex;
			return blendShapeIndex;
		}

		private void Update()
		{
			if (options.blinkAnimations != null && blinkStoppers <= 0)
			{
				BlinkUpdate();
			}
			if (options.conditionalIdleAnimations != null)
			{
				IdleUpdate();
			}
		}

		private void BlinkUpdate()
		{
			blinkStopwatch += Time.deltaTime;
			if (!(blinkStopwatch >= blinkInterval))
			{
				return;
			}
			if (!inDeathState)
			{
				BlendShapeAnimation[] blinkAnimations = options.blinkAnimations;
				foreach (BlendShapeAnimation animation in blinkAnimations)
				{
					TryPlayAnimation(animation);
				}
				if (doubleBlink)
				{
					doubleBlink = false;
				}
				else if (Random.value <= 0.1f)
				{
					doubleBlink = true;
				}
			}
			else
			{
				doubleBlink = false;
			}
			blinkStopwatch = 0f;
			if (doubleBlink)
			{
				blinkInterval = 0.3f;
			}
			else
			{
				blinkInterval = Random.Range(3f, 8f);
			}
		}

		private void IdleUpdate()
		{
			IdleAnimation[] conditionalIdleAnimations = options.conditionalIdleAnimations;
			foreach (IdleAnimation idleAnimation in conditionalIdleAnimations)
			{
				if (idleAnimation == null || idleAnimation.condition == null)
				{
					continue;
				}
				if (idleAnimation.condition(this))
				{
					BlendShapeAnimation[] animations = idleAnimation.animations;
					foreach (BlendShapeAnimation animation in animations)
					{
						TryPlayAnimation(animation);
					}
				}
				else
				{
					if (!idleAnimation.cancelOnConditionFalse)
					{
						continue;
					}
					BlendShapeAnimation[] animations2 = idleAnimation.animations;
					foreach (BlendShapeAnimation blendShapeAnimation in animations2)
					{
						ExpressionState featureState = GetFeatureState(blendShapeAnimation.feature);
						if (GetFeatureActive(blendShapeAnimation.feature) && featureState?.animation == blendShapeAnimation)
						{
							CancelExpressionSmooth(featureState);
						}
					}
				}
			}
		}

		public override void MarkForDeletion()
		{
			CancelCurrentExpressions();
			base.MarkForDeletion();
		}
	}
	public class IdleAnimation
	{
		public BlendShapeAnimation[] animations;

		public Func<ExpressionController, bool> condition;

		public bool cancelOnConditionFalse;

		public IdleAnimation(BlendShapeAnimation[] animations, Func<ExpressionController, bool> condition, bool cancelOnConditionFalse = true)
		{
			this.animations = animations;
			this.condition = condition;
			this.cancelOnConditionFalse = cancelOnConditionFalse;
		}
	}
	public class BoneTransformation
	{
		public string targetBonePath;

		public Vector3 localScale = Vector3.one;

		public Vector3 position = Vector3.zero;

		public string relativeBonePath;

		public TransformContexts contexts = TransformContexts.All;

		public Action<TransformationInstance> OnUpdate;

		public BoneTransformation()
		{
		}//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)


		public BoneTransformation(string targetBonePath, Vector3 localScale, Vector3 position, string relativeBonePath = null)
		{
			//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_002d: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			this.targetBonePath = targetBonePath;
			this.localScale = localScale;
			this.position = position;
			this.relativeBonePath = relativeBonePath;
		}

		public BoneTransformation(string armaturePath, Vector3 localScale, Vector3 position, TransformContexts contexts, string relativeBonePath = null)
			: this(armaturePath, localScale, position, relativeBonePath)
		{
			//IL_0002: 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)
			this.contexts = contexts;
		}

		[Obsolete("Use the overload with TransformContexts instead.")]
		public BoneTransformation(string armaturePath, Vector3 localScale, Vector3 position, bool applyInLobby, string relativeBonePath = null)
			: this(armaturePath, localScale, position, relativeBonePath)
		{
			//IL_0002: 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)
			contexts |= TransformContexts.CSS;
		}
	}
	public class TransformationInstance
	{
		public GameObject model;

		public Transform boneTransform;

		public Transform relativeBone;

		public Transform relativeBoneOverride;

		public Vector3? positionOverride = null;

		public Vector3? localScaleOverride = null;

		public bool shouldApply = true;

		public Animator animator;

		public BoneTransformation source;

		public bool resolved;

		public Vector3 prevLocalPosition = new Vector3(float.NaN, float.NaN, float.NaN);

		public Vector3 prevPositionOffset;

		public TransformationInstance(GameObject model, Animator animator, BoneTransformation source)
		{
			//IL_002f: 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)
			this.model = model;
			this.animator = animator;
			this.source = source;
			if (Object.op_Implicit((Object)(object)model))
			{
				boneTransform = model.transform.Find(source.targetBonePath);
				shouldApply = (Object.op_Implicit((Object)(object)Run.instance) && (source.contexts & TransformContexts.Run) == TransformContexts.Run) || (!Object.op_Implicit((Object)(object)Run.instance) && (source.contexts & TransformContexts.CSS) == TransformContexts.CSS);
				SetRelativeBoneByPath(source.relativeBonePath);
				if (Object.op_Implicit((Object)(object)boneTransform))
				{
					resolved = true;
				}
			}
		}

		public void SetRelativeBoneByPath(string path)
		{
			if (path != null)
			{
				relativeBone = model.transform.Find(path);
				if (!Object.op_Implicit((Object)(object)relativeBone))
				{
					Log.Error("Received invalid relative bone path: " + path);
					relativeBone = boneTransform;
				}
			}
			else
			{
				relativeBone = boneTransform;
			}
		}

		public void SetRelativeBoneOverrideByPath(string path)
		{
			if (path != null)
			{
				relativeBoneOverride = model.transform.Find(path);
				if (!Object.op_Implicit((Object)(object)relativeBoneOverride))
				{
					Log.Error("Received invalid relative bone override path: " + path);
					relativeBoneOverride = null;
				}
			}
			else
			{
				relativeBoneOverride = null;
			}
		}

		public void RemoveAllOverrides()
		{
			relativeBoneOverride = null;
			positionOverride = null;
			localScaleOverride = null;
		}
	}
	public class TransformationReversion
	{
		public Transform boneTransform;

		public Vector3 initialLocalScale = Vector3.one;

		public Vector3 initialLocalPosition = Vector3.zero;

		public TransformationReversion(Transform boneTransform)
		{
			//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_0027: 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_0033: 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)
			this.boneTransform = boneTransform;
			initialLocalScale = boneTransform.localScale;
			initialLocalPosition = boneTransform.localPosition;
		}

		public void Apply()
		{
			//IL_0018: 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)
			if (Object.op_Implicit((Object)(object)boneTransform))
			{
				boneTransform.localScale = initialLocalScale;
				boneTransform.localPosition = initialLocalPosition;
			}
		}
	}
	[Flags]
	public enum TransformContexts : uint
	{
		CSS = 1u,
		Run = 2u,
		All = uint.MaxValue
	}
	public class TransformController : MwBaseComponent
	{
		private List<TransformationInstance> transformInstances;

		public Dictionary<Transform, TransformationReversion> transformReversions;

		private CharacterBody characterBody;

		private Animator animator;

		private GameObject model;

		public BoneTransformation[] boneTransformations;

		public BoneTransformation rtiBoneTransformation;

		private int _rtiIndex = 0;

		private bool forcePositionUpdate;

		private bool reverted;

		private Vector3 _rtiPositionVector;

		private Vector3 _rtiLocalScaleVector;

		public int rtiIndex
		{
			get
			{
				return _rtiIndex;
			}
			set
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: 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)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				_rtiIndex = value;
				rtiBoneTransformation = boneTransformations[_rtiIndex];
				_rtiPositionVector = rtiBoneTransformation.position;
				_rtiLocalScaleVector = rtiBoneTransformation.localScale;
			}
		}

		public Vector3 rtiPositionVector
		{
			get
			{
				//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_000a: Unknown result type (might be due to invalid IL or missing references)
				return _rtiPositionVector;
			}
			set
			{
				//IL_0002: 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_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				_rtiPositionVector = value;
				rtiBoneTransformation.position = _rtiPositionVector;
				forcePositionUpdate = true;
			}
		}

		public Vector3 rtiLocalScaleVector
		{
			get
			{
				//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_000a: Unknown result type (might be due to invalid IL or missing references)
				return _rtiLocalScaleVector;
			}
			set
			{
				//IL_0002: 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_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				_rtiLocalScaleVector = value;
				rtiBoneTransformation.localScale = _rtiLocalScaleVector;
			}
		}

		public override void Init(EventSub eventSub)
		{
			//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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			boneTransformations = eventSub.options.boneTransformations;
			rtiBoneTransformation = boneTransformations[rtiIndex];
			_rtiPositionVector = rtiBoneTransformation.position;
			_rtiLocalScaleVector = rtiBoneTransformation.localScale;
			model = SkinEvents.GetModelFromEventBody(((Component)this).gameObject);
			GameObject obj = UnityObjectExtensions.AsValidOrNull<GameObject>(model);
			animator = ((obj != null) ? obj.GetComponent<Animator>() : null);
			AssignTransformations();
		}

		private void Start()
		{
			characterBody = ((Component)this).GetComponent<CharacterBody>();
		}

		private void AssignTransformations()
		{
			transformInstances = new List<TransformationInstance>();
			if (transformReversions == null)
			{
				transformReversions = new Dictionary<Transform, TransformationReversion>();
			}
			for (int i = 0; i < boneTransformations.Length; i++)
			{
				TransformationInstance transformationInstance = new TransformationInstance(model, animator, boneTransformations[i]);
				if (transformationInstance.resolved)
				{
					transformInstances.Add(transformationInstance);
					if (!transformReversions.ContainsKey(transformationInstance.boneTransform))
					{
						transformReversions.Add(transformationInstance.boneTransform, new TransformationReversion(transformationInstance.boneTransform));
					}
				}
				else
				{
					Log.Error("Failed to resolve TransformationInstance with target bone path \"" + transformationInstance.source.targetBonePath + "\"");
				}
			}
			ApplyPostionAndScale();
		}

		private void LateUpdate()
		{
			if (!Object.op_Implicit((Object)(object)characterBody) || Object.op_Implicit((Object)(object)characterBody.modelLocator.modelTransform))
			{
				ApplyPostionAndScale();
			}
		}

		private void ApplyPostionAndScale()
		{
			//IL_0190: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: 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)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			foreach (TransformationInstance transformInstance in transformInstances)
			{
				if (transformInstance == null || !transformInstance.shouldApply)
				{
					continue;
				}
				Transform boneTransform = transformInstance.boneTransform;
				BoneTransformation source = transformInstance.source;
				if ((!Object.op_Implicit((Object)(object)characterBody) || (Object.op_Implicit((Object)(object)characterBody) && !Object.op_Implicit((Object)(object)characterBody.currentVehicle))) && Object.op_Implicit((Object)(object)animator) && ((Behaviour)animator).enabled)
				{
					Transform val = (Object.op_Implicit((Object)(object)transformInstance.relativeBoneOverride) ? transformInstance.relativeBoneOverride : transformInstance.relativeBone);
					bool flag = transformInstance.prevLocalPosition != boneTransform.localPosition;
					if (Object.op_Implicit((Object)(object)boneTransform) && Object.op_Implicit((Object)(object)val) && (flag || forcePositionUpdate))
					{
						Vector3 val2 = (transformInstance.positionOverride.HasValue ? transformInstance.positionOverride.Value : source.position);
						if (!flag)
						{
							boneTransform.position = val.TransformPoint(val2 - transformInstance.prevPositionOffset);
						}
						else
						{
							boneTransform.position = val.TransformPoint(val2);
						}
						transformInstance.prevLocalPosition = boneTransform.localPosition;
						transformInstance.prevPositionOffset = val2;
					}
				}
				if (Object.op_Implicit((Object)(object)transformInstance.boneTransform))
				{
					boneTransform.localScale = (transformInstance.localScaleOverride.HasValue ? transformInstance.localScaleOverride.Value : source.localScale);
				}
				source.OnUpdate?.Invoke(transformInstance);
			}
			forcePositionUpdate = false;
		}

		private void OnDestroy()
		{
			if (!reverted)
			{
				RevertPositionAndScale();
			}
		}

		public void RevertPositionAndScale()
		{
			foreach (TransformationReversion value in transformReversions.Values)
			{
				value.Apply();
			}
			reverted = true;
		}

		public override void OnSwapWith<T>(T component)
		{
			if (component is TransformController)
			{
				TransformController transformController = component as TransformController;
				transformReversions = transformController.transformReversions;
				transformController.RevertPositionAndScale();
			}
		}
	}
	public class Compat
	{
		private static bool? _iconsModEnabled;

		public static bool shouldOverrideIconsMod;

		public static bool iconsModEnabled
		{
			get
			{
				if (!_iconsModEnabled.HasValue)
				{
					_iconsModEnabled = Chainloader.PluginInfos.ContainsKey("DTEE.Icons");
				}
				return _iconsModEnabled.Value;
			}
		}

		public static void EnableIconsModHooks()
		{
			try
			{
				MethodInfo method = typeof(dteeicons).GetMethod("ApplyDynamicIcon", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if (method != null)
				{
					HookEndpointManager.Add((MethodBase)method, (Delegate)new Action<Action<dteeicons, BodyIndex, int, Action<Texture2D>, string>, dteeicons, BodyIndex, int, Action<Texture2D>, string>(OnIconsModApplyLobbyIcons));
				}
			}
			catch (Exception arg)
			{
				Log.Error($"Error with Icons compat: {arg}");
			}
		}

		private static void OnIconsModApplyLobbyIcons(Action<dteeicons, BodyIndex, int, Action<Texture2D>, string> orig, dteeicons self, BodyIndex bodyIndex, int skinIndex, Action<Texture2D> applyAction, string logPrefix)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if (shouldOverrideIconsMod)
			{
				skinIndex = -1;
				shouldOverrideIconsMod = false;
			}
			orig(self, bodyIndex, skinIndex, applyAction, logPrefix);
		}
	}
	internal class ContentPacks : IContentPackProvider
	{
		internal ContentPack contentPack = new ContentPack();

		public static List<NetworkSoundEventDef> networkSoundEventDefs = new List<NetworkSoundEventDef>();

		public string identifier => "mwmw.MwSkinAdditions";

		internal static NetworkSoundEventDef CreateAndAddNetworkSoundEventDef(string eventName)
		{
			NetworkSoundEventDef val = ScriptableObject.CreateInstance<NetworkSoundEventDef>();
			val.akId = AkSoundEngine.GetIDFromString(eventName);
			val.eventName = eventName;
			networkSoundEventDefs.Add(val);
			return val;
		}

		public void Initialize()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			ContentManager.collectContentPackProviders += new CollectContentPackProvidersDelegate(ContentManager_collectContentPackProviders);
		}

		private void ContentManager_collectContentPackProviders(AddContentPackProviderDelegate addContentPackProvider)
		{
			addContentPackProvider.Invoke((IContentPackProvider)(object)this);
		}

		public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
		{
			contentPack.identifier = identifier;
			contentPack.networkSoundEventDefs.Add(networkSoundEventDefs.ToArray());
			args.ReportProgress(1f);
			yield break;
		}

		public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args)
		{
			ContentPack.Copy(contentPack, args.output);
			args.ReportProgress(1f);
			yield break;
		}

		public IEnumerator FinalizeAsync(FinalizeAsyncArgs args)
		{
			args.ReportProgress(1f);
			yield break;
		}
	}
	public enum AngleDirection
	{
		Clockwise = -1,
		AntiClockwise = 1
	}
	public class CorrectionController : MwBaseComponent
	{
		public CorrectiveBlendShape[] correctiveBlendShapes;

		private List<CorrectionInstance> correctionInstances;

		public override void Init(EventSub eventSub)
		{
			correctiveBlendShapes = eventSub.options.correctiveBlendShapes;
			AssignCorrections();
		}

		private void AssignCorrections()
		{
			correctionInstances = new List<CorrectionInstance>();
			for (int i = 0; i < correctiveBlendShapes.Length; i++)
			{
				CorrectionInstance correctionInstance = new CorrectionInstance(((Component)this).gameObject, correctiveBlendShapes[i]);
				if (correctionInstance.resolved)
				{
					correctionInstances.Add(correctionInstance);
				}
				else
				{
					Log.Error("Failed to resolve CorrectionInstance with BlendShape name \"" + correctionInstance.source.blendShapeName + "\"");
				}
			}
			ApplyCorrections();
		}

		private void Update()
		{
			ApplyCorrections();
		}

		private void ApplyCorrections()
		{
			foreach (CorrectionInstance correctionInstance in correctionInstances)
			{
				if (Object.op_Implicit((Object)(object)correctionInstance.renderer))
				{
					correctionInstance.source.correctionMethod.EvaluateAndApply(correctionInstance);
				}
			}
		}
	}
	public class CorrectionInstance
	{
		public GameObject body;

		public Transform boneTransform;

		public int blendShapeIndex;

		public SkinnedMeshRenderer renderer;

		public CorrectiveBlendShape source;

		public bool resolved;

		public CorrectionInstance(GameObject body, CorrectiveBlendShape source)
		{
			this.body = body;
			this.source = source;
			GameObject val = UnityObjectExtensions.AsValidOrNull<GameObject>(SkinEvents.GetModelFromEventBody(body));
			object obj;
			if (val == null)
			{
				obj = null;
			}
			else
			{
				Transform obj2 = UnityObjectExtensions.AsValidOrNull<Transform>(val.transform.Find(source.meshName));
				obj = ((obj2 != null) ? ((Component)obj2).GetComponent<SkinnedMeshRenderer>() : null);
			}
			renderer = (SkinnedMeshRenderer)obj;
			if (Object.op_Implicit((Object)(object)renderer) && Object.op_Implicit((Object)(object)renderer.sharedMesh))
			{
				if (source.targetBonePath != null)
				{
					boneTransform = val.transform.Find(source.targetBonePath);
				}
				blendShapeIndex = renderer.sharedMesh.GetBlendShapeIndex(source.blendShapeName);
				if ((source.targetBonePath == null || (source.targetBonePath != null && Object.op_Implicit((Object)(object)boneTransform))) && blendShapeIndex != -1)
				{
					resolved = true;
					source.correctionMethod.Init(this);
				}
			}
		}
	}
	public class AxisCorrection : BaseCorrectionMethod
	{
		public float minAngle;

		public float maxAngle;

		public TargetAxis targetAxis;

		public AngleDirection direction;

		public float inverseLerpLowerThreshold;

		public float inverseLerpUpperThreshold;

		public AxisCorrection(float minAngle, float maxAngle, TargetAxis targetAxis, AngleDirection direction = AngleDirection.AntiClockwise, float anglePadding = -1f)
		{
			this.minAngle = MwUtils.Mod(minAngle, 360f);
			this.maxAngle = MwUtils.Mod(maxAngle, 360f);
			this.targetAxis = targetAxis;
			this.direction = direction;
			float num = (360f - MwUtils.AngleDelta(minAngle, maxAngle, direction)) * 0.5f - 0.01f;
			if (anglePadding > num || anglePadding < 0f)
			{
				anglePadding = num;
			}
			if (direction == AngleDirection.AntiClockwise)
			{
				inverseLerpLowerThreshold = MwUtils.InverseLerpAngle(minAngle, maxAngle, MwUtils.Mod(minAngle - anglePadding, 360f), direction);
				inverseLerpUpperThreshold = MwUtils.InverseLerpAngle(minAngle, maxAngle, MwUtils.Mod(maxAngle + anglePadding, 360f), direction);
			}
			else
			{
				inverseLerpLowerThreshold = MwUtils.InverseLerpAngle(minAngle, maxAngle, MwUtils.Mod(minAngle + anglePadding, 360f), direction);
				inverseLerpUpperThreshold = MwUtils.InverseLerpAngle(minAngle, maxAngle, MwUtils.Mod(maxAngle - anglePadding, 360f), direction);
			}
		}

		public override float Evaluate(CorrectionInstance instance)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)instance.boneTransform))
			{
				return -1f;
			}
			Vector3 localEulerAngles = instance.boneTransform.localEulerAngles;
			float value = ((Vector3)(ref localEulerAngles))[(int)targetAxis];
			float num = MwUtils.InverseLerpAngle(minAngle, maxAngle, value, direction);
			float result = -1f;
			if (num > inverseLerpLowerThreshold && num < inverseLerpUpperThreshold)
			{
				result = ((num < 0f) ? 0f : ((!(num <= 1f)) ? 100f : (Mathf.Clamp01(MwUtils.InverseLerpAngle(minAngle, maxAngle, value, direction)) * 100f)));
			}
			return result;
		}
	}
	public abstract class BaseCorrectionMethod
	{
		public bool debug;

		public abstract float Evaluate(CorrectionInstance instance);

		public virtual void Init(CorrectionInstance instance)
		{
			if (debug)
			{
				StartDebug(instance);
			}
		}

		public virtual void StartDebug(CorrectionInstance instance)
		{
		}

		public virtual void EvaluateAndApply(CorrectionInstance instance)
		{
			float num = Evaluate(instance);
			if (num >= 0f)
			{
				instance.renderer.SetBlendShapeWeight(instance.blendShapeIndex, num);
			}
		}
	}
	public class LineCorrectionDebugController : MonoBehaviour
	{
		public LineCorrection correction;

		public Transform boneTransform;

		public LineRenderer axis1Preview;

		public LineRenderer axis2Preview;

		public LineRenderer forwardPreview;

		public const float width = 0.05f;

		public void Init(CorrectionInstance instance)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_0084: 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)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_0118: 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_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected O, but got Unknown
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			if (instance.source.correctionMethod is LineCorrection)
			{
				Material material = new Material(Shader.Find("Sprites/Default"));
				boneTransform = instance.boneTransform;
				correction = instance.source.correctionMethod as LineCorrection;
				GameObject val = new GameObject("Axis1Preview");
				val.transform.parent = boneTransform;
				axis1Preview = val.AddComponent<LineRenderer>();
				axis1Preview.startColor = Color.green;
				axis1Preview.endColor = Color.green;
				axis1Preview.useWorldSpace = true;
				axis1Preview.startWidth = 0.05f;
				axis1Preview.endWidth = 0.05f;
				axis1Preview.positionCount = 2;
				((Renderer)axis1Preview).material = material;
				GameObject val2 = new GameObject("Axis2Preview");
				val2.transform.parent = boneTransform;
				axis2Preview = val2.AddComponent<LineRenderer>();
				axis2Preview.startColor = Color.cyan;
				axis2Preview.endColor = Color.cyan;
				axis2Preview.useWorldSpace = true;
				axis2Preview.startWidth = 0.05f;
				axis2Preview.endWidth = 0.05f;
				axis2Preview.positionCount = 2;
				((Renderer)axis2Preview).material = material;
				GameObject val3 = new GameObject("ForwardPreview");
				val3.transform.parent = boneTransform;
				forwardPreview = val3.AddComponent<LineRenderer>();
				forwardPreview.startColor = Color.white;
				forwardPreview.endColor = Color.white;
				forwardPreview.useWorldSpace = true;
				forwardPreview.startWidth = 0.05f;
				forwardPreview.endWidth = 0.05f;
				forwardPreview.positionCount = 2;
				((Renderer)forwardPreview).material = material;
			}
		}

		public void Update()
		{
			//IL_000e: 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_0036: 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_0046: 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_0055: 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_0085: 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)
			//IL_00a0: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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_00fa: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			axis1Preview.SetPosition(0, boneTransform.position);
			axis1Preview.SetPosition(1, boneTransform.position + boneTransform.parent.rotation * correction.point1 * 1.5f);
			axis2Preview.SetPosition(0, boneTransform.position);
			axis2Preview.SetPosition(1, boneTransform.position + boneTransform.parent.rotation * correction.point2 * 1.5f);
			forwardPreview.SetPosition(0, boneTransform.position);
			forwardPreview.SetPosition(1, boneTransform.position + boneTransform.rotation * correction.forward * 1.5f);
		}
	}
	public class SegmentCorrectionDebugController : MonoBehaviour
	{
		public SegmentCorrection correction;

		public Transform boneTransform;

		public LineRenderer planePreview;

		public LineRenderer normalPreview;

		public LineRenderer forwardPreview;

		public const float width = 0.05f;

		public void Init(CorrectionInstance instance)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_00cd: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_0161: 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_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected O, but got Unknown
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			if (instance.source.correctionMethod is SegmentCorrection)
			{
				Material material = new Material(Shader.Find("Sprites/Default"));
				boneTransform = instance.boneTransform;
				correction = instance.source.correctionMethod as SegmentCorrection;
				GameObject val = new GameObject("PlanePreview");
				val.transform.parent = boneTransform;
				planePreview = val.AddComponent<LineRenderer>();
				planePreview.useWorldSpace = true;
				planePreview.startWidth = 0.05f;
				planePreview.endWidth = 0.05f;
				planePreview.positionCount = 5;
				((Renderer)planePreview).material = material;
				planePreview.startColor = Color.green;
				planePreview.endColor = Color.green;
				GameObject val2 = new GameObject("NormalPreview");
				val2.transform.parent = boneTransform;
				normalPreview = val2.AddComponent<LineRenderer>();
				normalPreview.useWorldSpace = true;
				normalPreview.startWidth = 0.05f;
				normalPreview.endWidth = 0.05f;
				normalPreview.positionCount = 2;
				((Renderer)normalPreview).material = material;
				normalPreview.startColor = Color.blue;
				normalPreview.endColor = Color.blue;
				GameObject val3 = new GameObject("ForwardPreview");
				val3.transform.parent = boneTransform;
				forwardPreview = val3.AddComponent<LineRenderer>();
				forwardPreview.useWorldSpace = true;
				forwardPreview.startWidth = 0.05f;
				forwardPreview.endWidth = 0.05f;
				forwardPreview.positionCount = 2;
				((Renderer)forwardPreview).material = material;
				forwardPreview.startColor = Color.white;
				forwardPreview.endColor = Color.white;
			}
		}

		public void Update()
		{
			//IL_000e: 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_0036: 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_0046: 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_0055: 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_007d: 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_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_009d: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_013b: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			planePreview.SetPosition(0, boneTransform.position);
			planePreview.SetPosition(1, boneTransform.position + boneTransform.parent.rotation * correction.axis1 * 1.5f);
			planePreview.SetPosition(2, boneTransform.position + boneTransform.parent.rotation * (correction.axis1 + correction.axis2) * 1.5f);
			planePreview.SetPosition(3, boneTransform.position + boneTransform.parent.rotation * correction.axis2 * 1.5f);
			planePreview.SetPosition(4, boneTransform.position);
			normalPreview.SetPosition(0, boneTransform.position);
			normalPreview.SetPosition(1, boneTransform.position + boneTransform.parent.rotation * correction.normal * 1.5f);
			forwardPreview.SetPosition(0, boneTransform.position);
			forwardPreview.SetPosition(1, boneTransform.position + boneTransform.rotation * correction.forward * 1.5f);
		}
	}
	public class DuoCorrection : BaseCorrectionMethod
	{
		public CorrectiveBlendShape correction1;

		public CorrectiveBlendShape correction2;

		public static FixedConditionalWeakTable<CorrectionInstance, CorrectionInstance[]> duoInstances = new FixedConditionalWeakTable<CorrectionInstance, CorrectionInstance[]>();

		public DuoCorrection(CorrectiveBlendShape correction1, CorrectiveBlendShape correction2)
		{
			this.correction1 = correction1;
			this.correction2 = correction2;
		}

		public override void Init(CorrectionInstance instance)
		{
			base.Init(instance);
			duoInstances[instance] = new CorrectionInstance[2]
			{
				new CorrectionInstance(instance.body, correction1),
				new CorrectionInstance(instance.body, correction2)
			};
		}

		public override float Evaluate(CorrectionInstance instance)
		{
			if (duoInstances.ContainsKey(instance))
			{
				CorrectionInstance[] array = duoInstances[instance];
				float num = array[0].source.correctionMethod.Evaluate(array[0]);
				float num2 = array[1].source.correctionMethod.Evaluate(array[1]);
				if (num <= num2 && num > 0f)
				{
					array[0].renderer.SetBlendShapeWeight(array[0].blendShapeIndex, 0f);
					array[1].renderer.SetBlendShapeWeight(array[1].blendShapeIndex, num2 - num);
					return num;
				}
				if (num2 < num && num2 > 0f)
				{
					array[0].renderer.SetBlendShapeWeight(array[0].blendShapeIndex, num - num2);
					array[1].renderer.SetBlendShapeWeight(array[1].blendShapeIndex, 0f);
					return num2;
				}
				array[0].renderer.SetBlendShapeWeight(array[0].blendShapeIndex, num);
				array[1].renderer.SetBlendShapeWeight(array[1].blendShapeIndex, num2);
				return 0f;
			}
			return -1f;
		}
	}
	public class LineCorrection : BaseCorrectionMethod
	{
		public Vector3 point1;

		public Vector3 point2;

		public Vector3 forward;

		public Vector3 normal;

		public bool equalPoints;

		public float startAngle;

		public LineCorrection(float startAngle, Vector3 point1, Vector3 point2, Vector3 forward)
		{
			//IL_0012: 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_001f: 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_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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			this.startAngle = startAngle;
			this.point1 = ((Vector3)(ref point1)).normalized;
			this.point2 = ((Vector3)(ref point2)).normalized;
			this.forward = ((Vector3)(ref forward)).normalized;
			if (this.point1 == -this.point2)
			{
				Log.Warning($"LineCorrection instance has point vectors that are directly opposite ({point1}, {point2}). " + "Cannot determine the intended path between the points, as there are infinite equidistant possibilities. Changing point2 to a compatible unit vector.");
				float num = float.PositiveInfinity;
				int num2 = 0;
				for (int i = 0; i < 2; i++)
				{
					float num3 = Mathf.Abs(((Vector3)(ref this.point2))[i]);
					if (num3 < num)
					{
						num = num3;
						num2 = i;
					}
				}
				this.point2 = Vector3.zero;
				((Vector3)(ref point2))[num2] = 1f;
			}
			equalPoints = this.point1 == this.point2;
			if (!equalPoints)
			{
				Vector3 val = Vector3.Cross(this.point1, this.point2);
				normal = ((Vector3)(ref val)).normalized;
			}
		}

		public override float Evaluate(CorrectionInstance instance)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0035: 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_005f: 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_0045: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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)
			if (!Object.op_Implicit((Object)(object)instance.boneTransform))
			{
				return -1f;
			}
			Vector3 val = instance.boneTransform.localRotation * forward;
			float num = (equalPoints ? Mathf.Acos(Vector3.Dot(val, point1)) : ((!OccursBefore(point1, val) || !OccursBefore(val, point2)) ? Mathf.Acos(Mathf.Max(Vector3.Dot(val, point1), Vector3.Dot(val, point2))) : Mathf.Asin(Mathf.Abs(Vector3.Dot(val, normal)))));
			return Mathf.InverseLerp(startAngle, 0f, num * 57.29578f) * 100f;
		}

		public override void StartDebug(CorrectionInstance instance)
		{
			((Component)instance.boneTransform).gameObject.AddComponent<LineCorrectionDebugController>().Init(instance);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public bool OccursBefore(Vector3 v1, Vector3 v2)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_0009: Unknown result type (might be due to invalid IL or missing references)
			return Vector3.Dot(Vector3.Cross(v1, v2), normal) >= 0f;
		}
	}
	public class SegmentCorrection : BaseCorrectionMethod
	{
		public Vector3 axis1;

		public Vector3 axis2;

		public Vector3 normal;

		public Vector3 forward;

		public float minSignedAngle;

		public float maxSignedAngle;

		public SegmentCorrection(float minSignedAngle, float maxSignedAngle, Vector3 axis1, Vector3 axis2, Vector3 forward)
		{
			//IL_0019: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0047: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			this.minSignedAngle = minSignedAngle;
			this.maxSignedAngle = maxSignedAngle;
			this.axis1 = ((Vector3)(ref axis1)).normalized;
			this.axis2 = ((Vector3)(ref axis2)).normalized;
			Vector3 val = Vector3.Cross(((Vector3)(ref axis1)).normalized, ((Vector3)(ref axis2)).normalized);
			normal = ((Vector3)(ref val)).normalized;
			this.forward = ((Vector3)(ref forward)).normalized;
		}

		public override float Evaluate(CorrectionInstance instance)
		{
			//IL_0023: 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_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)
			//IL_0034: 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)
			if (!Object.op_Implicit((Object)(object)instance.boneTransform))
			{
				return -1f;
			}
			Vector3 val = instance.boneTransform.localRotation * forward;
			float num = Mathf.Asin(Vector3.Dot(val, normal)) * 57.29578f;
			float result = 0f;
			if (num > maxSignedAngle)
			{
				result = 100f;
			}
			else if (num > minSignedAngle)
			{
				result = Mathf.InverseLerp(minSignedAngle, maxSignedAngle, num) * 100f;
			}
			return result;
		}

		public override void StartDebug(CorrectionInstance instance)
		{
			((Component)instance.boneTransform).gameObject.AddComponent<SegmentCorrectionDebugController>().Init(instance);
		}
	}
	public class CorrectiveBlendShape
	{
		public string meshName;

		public string targetBonePath;

		public string blendShapeName;

		public BaseCorrectionMethod correctionMethod;

		public CorrectiveBlendShape(string meshName, string blendShapeName, BaseCorrectionMethod correctionMethod)
		{
			this.meshName = meshName;
			this.blendShapeName = blendShapeName;
			this.correctionMethod = correctionMethod;
		}

		public CorrectiveBlendShape(string meshName, string targetBonePath, string blendShapeName, BaseCorrectionMethod correctionMethod)
		{
			this.meshName = meshName;
			this.targetBonePath = targetBonePath;
			this.blendShapeName = blendShapeName;
			this.correctionMethod = correctionMethod;
		}
	}
	public enum TargetAxis
	{
		X,
		Y,
		Z
	}
	public class EventSub
	{
		public SkinDef[] skinDefs;

		public EventSubOptions options;

		public static Action<GameObject> DifferentSkinAppliedGlobal;

		private Action<GameObject> SkinAppliedLobbyEarly;

		public Action<GameObject> SkinAppliedLobby;

		public Action<GameObject> SkinAppliedRun;

		public Action<GameObject, DamageReport> TakeDamage;

		public Action<GameObject> Death;

		public Action<GameObject> DefeatBossGroup;

		public Action<GameObject> LeavePod;

		public Action<GameObject> UsePrimary;

		public Action<GameObject> UseSecondary;

		public Action<GameObject> UseUtility;

		public Action<GameObject> UseSpecial;

		public Action<GameObject> ShrineSuccess;

		public Action<GameObject> ShrineFailure;

		public Action<GameObject> TeleporterStart;

		public Action<GameObject> TeleporterEnd;

		public Action<GameObject> BearDamageBlock;

		public Action<GameObject> LevelUp;

		public Action<GameObject> MithrixDefeat;

		public Action<GameObject> UseEquipment;

		public Action<GameObject, float> Heal;

		public Action<GameObject> Jump;

		public Action<GameObject> LeaveStage;

		public Action<GameObject> Idle;

		public Action<GameObject, ItemIndex> GetItem;

		public Action<GameObject> HoldoutZoneCharged;

		public Action<GameObject> LeaveSpawnTeleporterState;

		public SkinDef skinDef
		{
			get
			{
				if (skinDefs != null)
				{
					return skinDefs[0];
				}
				return null;
			}
			set
			{
				if (skinDefs != null && skinDefs.Length >= 1)
				{
					skinDefs[0] = value;
					return;
				}
				skinDefs = (SkinDef[])(object)new SkinDef[1] { value };
			}
		}

		public EventSub()
		{
			if (options == null)
			{
				options = new EventSubOptions();
			}
			SkinAppliedLobby = (Action<GameObject>)Delegate.Combine(SkinAppliedLobby, (Action<GameObject>)delegate(GameObject body)
			{
				SkinAppliedLobbyEarly?.Invoke(body);
			});
		}

		[Obsolete("Provide an EventSubOptions object instead.")]
		public EventSub(SkinDef skinDef, BoneTransformation[] boneTransformations = null, ExtraObject[] extraObjects = null, bool useAnimations = false, BlendShapeAnimation[] blinkAnimations = null, IdleAnimation[] conditionalIdleAnimations = null, VoiceGroup[] voiceGroups = null)
			: this()
		{
			this.skinDef = skinDef;
			options.boneTransformations = boneTransformations;
			options.extraObjects = extraObjects;
			options.blinkAnimations = blinkAnimations;
			options.conditionalIdleAnimations = conditionalIdleAnimations;
			options.voiceGroups = voiceGroups;
		}

		public EventSub(SkinDef skinDef, EventSubOptions eventSubOptions)
			: this()
		{
			if (eventSubOptions != null)
			{
				options = eventSubOptions;
			}
			this.skinDef = skinDef;
		}

		public EventSub(SkinDef[] skinDefs, EventSubOptions eventSubOptions)
			: this()
		{
			if (eventSubOptions != null)
			{
				options = eventSubOptions;
			}
			this.skinDefs = skinDefs;
		}

		public void Init()
		{
			SkinEvents.Register(this);
			if (options?.boneTransformations != null && (Object.op_Implicit((Object)(object)Stage.instance) || options.transformInCSS))
			{
				SubscribeAddMwComponent<TransformController>();
			}
			if (options?.extraObjects != null)
			{
				SubscribeAddMwComponent<ExtraObjectController>();
			}
			EventSubOptions eventSubOptions = options;
			if (eventSubOptions != null && eventSubOptions.isAnimated)
			{
				SubscribeAddMwComponent<ExpressionController>();
			}
			if (options?.voiceGroups != null)
			{
				SubscribeAddMwComponent<VoiceController>();
			}
			if (options?.correctiveBlendShapes != null)
			{
				SubscribeAddMwComponent<CorrectionController>();
			}
			if (options?.customIcons != null)
			{
				SkinAppliedRun = (Action<GameObject>)Delegate.Combine(SkinAppliedRun, new Action<GameObject>(SwapBodyIconRun));
			}
		}

		private void SubscribeAddMwComponent<T>() where T : MwBaseComponent
		{
			SkinAppliedRun = (Action<GameObject>)Delegate.Combine(SkinAppliedRun, new Action<GameObject>(AddMwComponent<T>));
			SkinAppliedLobbyEarly = (Action<GameObject>)Delegate.Combine(SkinAppliedLobbyEarly, new Action<GameObject>(AddMwComponent<T>));
		}

		private void AddMwComponent<T>(GameObject body) where T : MwBaseComponent
		{
			T val = default(T);
			if (!body.TryGetComponent<T>(ref val) || val.beingDeleted)
			{
				val = body.AddComponent<T>().SwapWith(val);
			}
			val.Init(this);
		}

		private static void SwapBodyIconRun(GameObject body)
		{
			CharacterBody val = default(CharacterBody);
			ModelSkinController val2 = default(ModelSkinController);
			if (body.TryGetComponent<CharacterBody>(ref val) && Object.op_Implicit((Object)(object)val.modelLocator) && Object.op_Implicit((Object)(object)val.modelLocator.modelTransform) && ((Component)val.modelLocator.modelTransform).TryGetComponent<ModelSkinController>(ref val2) && ArrayUtils.GetSafe<SkinDef>(val2.skins, val2.currentSkinIndex).TryGetCustomIcon(out var icon))
			{
				val.portraitIcon = icon;
			}
		}
	}
	public class EventSubOptions
	{
		public BoneTransformation[] boneTransformations = null;

		public CorrectiveBlendShape[] correctiveBlendShapes = null;

		public BlendShapeAnimation[] blinkAnimations = null;

		public IdleAnimation[] conditionalIdleAnimations = null;

		public VoiceGroup[] voiceGroups = null;

		[Tooltip("SkinDefs associated with this EventSub will take on the icon that shares its index - out of bounds or null will leave it as default")]
		public Texture[] customIcons = null;

		[Tooltip("Set to false to disable all bone transformations in the CSS/lobby. Use the 'contexts' flags field in TransformationOptions for more customisability.")]
		public bool transformInCSS = true;

		[Obsolete("Use in-built functionality via GameObject Activations instead.")]
		public ExtraObject[] extraObjects = null;

		[Tooltip("Set to true if you are not using blink or idle animations but wish to ensure the skin has an ExpressionController for custom animation events.")]
		public bool useAnimations = false;

		public Texture customIcon
		{
			get
			{
				return (customIcons == null || customIcons.Length == 0) ? null : customIcons[0];
			}
			set
			{
				if (customIcons == null)
				{
					customIcons = (Texture[])(object)new Texture[1] { value };
				}
			}
		}

		public bool isAnimated => useAnimations || forceAnimations;

		private bool forceAnimations
		{
			get
			{
				BlendShapeAnimation[] array = blinkAnimations;
				int result;
				if (array == null || array.Length == 0)
				{
					IdleAnimation[] array2 = conditionalIdleAnimations;
					result = ((array2 != null && array2.Length != 0) ? 1 : 0);
				}
				else
				{
					result = 1;
				}
				return (byte)result != 0;
			}
		}
	}
	public class ExtraObject
	{
		public GameObject prefab;

		public string armatureParentPath;

		public Vector3 localScale;

		public Vector3 localPosition;

		public Vector3 localEulerAngles;

		public ExtraObject(GameObject prefab, string armatureParentPath, Vector3 localScale, Vector3 localPosition, Vector3 localEulerAngles)
		{
			//IL_0017: 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)
			//IL_0020: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			this.prefab = prefab;
			this.armatureParentPath = armatureParentPath;
			this.localScale = localScale;
			this.localPosition = localPosition;
			this.localEulerAngles = localEulerAngles;
		}
	}
	public class ExtraObjectController : MwBaseComponent
	{
		public List<GameObject> extraObjs = new List<GameObject>();

		public override void Init(EventSub eventSub)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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)
			Transform transform = SkinEvents.GetModelFromEventBody(((Component)this).gameObject).transform;
			ExtraObject[] extraObjects = eventSub.options.extraObjects;
			foreach (ExtraObject extraObject in extraObjects)
			{
				GameObject val = Object.Instantiate<GameObject>(extraObject.prefab);
				val.transform.parent = transform.Find(extraObject.armatureParentPath);
				val.transform.localPosition = extraObject.localPosition;
				val.transform.localEulerAngles = extraObject.localEulerAngles;
				val.transform.localScale = extraObject.localScale;
				extraObjs.Add(val);
			}
		}

		public override void MarkForDeletion()
		{
			foreach (GameObject extraObj in extraObjs)
			{
				Object.Destroy((Object)(object)extraObj);
			}
			base.MarkForDeletion();
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	public abstract class MwBaseComponent : MonoBehaviour
	{
		public bool beingDeleted { get; private set; }

		public virtual void OnSwapWith<T>(T oldComponent) where T : MwBaseComponent
		{
		}

		public abstract void Init(EventSub eventSub);

		public virtual void MarkForDeletion()
		{
			beingDeleted = true;
			Object.Destroy((Object)(object)this);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("mwmw.MwSkinAdditions", "MwSkinAdditions", "1.3.0")]
	public class MwSkinAdditions : BaseUnityPlugin
	{
		public const string PluginGUID = "mwmw.MwSkinAdditions";

		public const string PluginAuthor = "mwmw";

		public const string PluginName = "MwSkinAdditions";

		public const string PluginVersion = "1.3.0";

		public static PluginInfo pluginInfo;

		public static MwSkinAdditions instance;

		public void Awake()
		{
			instance = this;
			pluginInfo = ((BaseUnityPlugin)this).Info;
			Log.Init(((BaseUnityPlugin)this).Logger);
			NetworkMessages.Init();
			SkinEvents.Init();
			RoR2Application.onStart = (Action)Delegate.Combine(RoR2Application.onStart, (Action)delegate
			{
				new ContentPacks().Initialize();
			});
		}
	}
	public static class MwUtils
	{
		public static Random rand = new Random();

		public static object RandomChoices(IEnumerable<object> choices, IEnumerable<float> weights)
		{
			List<float> list = new List<float>();
			float num = 0f;
			foreach (float weight in weights)
			{
				num += weight;
				list.Add(num);
			}
			float num2 = (float)rand.NextDouble() * num;
			int num3 = 0;
			foreach (object choice in choices)
			{
				if (num2 <= list[num3])
				{
					return choice;
				}
				num3++;
			}
			Log.Warning("RandomChoices: Couldn't make a choice - returning null!");
			return null;
		}

		public static object RandomChoice(IEnumerable<object> choices)
		{
			IList<object> list = (choices as IList<object>) ?? choices.ToList();
			if (list.Count > 0)
			{
				return list[rand.Next(list.Count)];
			}
			Log.Warning("RandomChoice: Got passed an empty enumerable - returning null!");
			return null;
		}

		public static object RandomChoice(object[] choices)
		{
			if (choices.Length != 0)
			{
				return choices[rand.Next(choices.Length)];
			}
			Log.Warning("RandomChoice: Got passed an empty enumerable - returning null!");
			return null;
		}

		public static void SafeSetBlendShapeWeight(this SkinnedMeshRenderer renderer, int index, float value)
		{
			if (Object.op_Implicit((Object)(object)renderer))
			{
				renderer.SetBlendShapeWeight(index, value);
			}
		}

		public static T SwapWith<T>(this T newComponent, T oldComponent) where T : MwBaseComponent
		{
			newComponent.OnSwapWith(oldComponent);
			return newComponent;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float Mod(float a, float b)
		{
			float num = a % b;
			if (num < 0f)
			{
				num += b;
			}
			return num;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float AngleDelta(float a, float b, AngleDirection direction)
		{
			if (direction == AngleDirection.AntiClockwise)
			{
				return Mod(b - a, 360f);
			}
			return Mod(a - b, 360f);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static float InverseLerpAngle(float a, float b, float value, AngleDirection direction)
		{
			float num = AngleDelta(a, b, direction);
			float num2 = AngleDelta(a, value, direction);
			float result = 0f;
			if (!Mathf.Approximately(num, 0f))
			{
				result = ((!(num2 > 180f + 0.5f * num)) ? (num2 / num) : ((num2 - 360f) / num));
			}
			return result;
		}
	}
	public static class SkinEvents
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Action <0>__SubscribeEventSkins;

			public static hook_ApplySkinAsync <1>__OnSkinAppliedBody;

			public static hook_OnInteractionBegin <2>__OnTeleporterStart;

			public static hook_OnDeathStart <3>__OnDeath;

			public static hook_EjectPassenger_GameObject <4>__OnLeavePod;

			public static hook_OnSkillActivated <5>__OnSkillActivated;

			public static hook_AddShrineStack <6>__OnChanceShrineInteract;

			public static Manipulator <7>__OnPickupAttemptGrant;

			public static Manipulator <8>__OnBearDamageBlock;

			public static Action<BossGroup> <9>__OnDefeatBossGroup;

			public static Action<TeleporterInteraction> <10>__OnTeleporterEnd;

			public static Action<DamageReport> <11>__OnTakeDamage;

			public static Action<CharacterBody> <12>__OnLevelUp;

			public static hook_OnEnter <13>__OnMithrixDefeat;

			public static Action<EquipmentSlot, EquipmentIndex> <14>__OnUseEquipment;

			public static Action<HealthComponent, float, ProcChainMask> <15>__OnHeal;

			public static hook_ApplyJumpVelocity <16>__OnJump;

			public static hook_Begin <17>__OnLeaveStage;

			public static hook_Update <18>__OnBodyUpdate;

			public static hook_OnExit <19>__OnLeaveSpawnTeleporterState;

			public static hook_Rebuild <20>__OnIconsRebuilt;

			public static hook_RebuildLocal <21>__OnLocalCSSLoadoutChanged;

			public static Action<GameObject> <22>__RemoveMwComponents;
		}

		private static List<EventSub> registeredEventSubs = new List<EventSub>();

		private static Dictionary<SkinDef, EventSub> skinDefToEventSub = new Dictionary<SkinDef, EventSub>();

		private static Dictionary<SkinIndex, EventSub> skinIndexToEventSub = new Dictionary<SkinIndex, EventSub>();

		private static Dictionary<SkinDef, Texture> skinDefToCustomIcon = new Dictionary<SkinDef, Texture>();

		private static Dictionary<SkinIndex, Texture> skinIndexToCustomIcon = new Dictionary<SkinIndex, Texture>();

		public static HashSet<CharacterBody> holdOffIdleInvocation = new HashSet<CharacterBody>();

		private static SurvivorIconController cssSelectedSurvivorIcon;

		private static bool loaded;

		public static void Init()
		{
			SubscribeGlobalEvents();
			SubscribeGameEvents();
			((ResourceAvailability)(ref SkinCatalog.availability)).CallWhenAvailable((Action)SubscribeEventSkins);
		}

		public static void Register(EventSub eventSub)
		{
			if (loaded)
			{
				Log.Warning("Failed to register an EventSub because initialisation has already completed!");
			}
			else
			{
				registeredEventSubs.Add(eventSub);
			}
		}

		public static bool TryGetCustomIcon(this SkinDef skinDef, out Texture icon)
		{
			icon = GetCustomIconFromSkinDef(skinDef);
			if (Object.op_Implicit((Object)(object)icon))
			{
				return true;
			}
			return false;
		}

		private static void SubscribeEventSkins()
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Invalid comparison between Unknown and I4
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			foreach (EventSub registeredEventSub in registeredEventSubs)
			{
				if (registeredEventSub == null)
				{
					Log.Error("Received a null EventSub! Ignoring...");
					continue;
				}
				for (int i = 0; i < registeredEventSub.skinDefs.Length; i++)
				{
					SkinDef val = registeredEventSub.skinDefs[i];
					if ((Object)(object)val == (Object)null)
					{
						Log.Error("Received a null SkinDef! Ignoring...");
						continue;
					}
					skinDefToEventSub.Add(val, registeredEventSub);
					bool flag = (int)val.skinIndex != -1;
					if (flag)
					{
						skinIndexToEventSub.Add(val.skinIndex, registeredEventSub);
					}
					if (registeredEventSub.options?.customIcons != null && i < registeredEventSub.options.customIcons.Length && (Object)(object)registeredEventSub.options.customIcons[i] != (Object)null)
					{
						Texture value = registeredEventSub.options.customIcons[i];
						skinDefToCustomIcon.Add(val, value);
						if (flag)
						{
							skinIndexToCustomIcon.Add(val.skinIndex, value);
						}
					}
				}
			}
			loaded = true;
		}

		private static void SubscribeGameEvents()
		{
			//IL_0011: 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_001c: Expected O, but got Unknown
			//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_003d: Expected O, but got Unknown
			//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)
			//IL_005e: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_0095: 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_00a0: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//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_0103: Expected O, but got Unknown
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Expected O, but got Unknown
			//IL_0200: 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_020b: Expected O, but got Unknown
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Expected O, but got Unknown
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Expected O, but got Unknown
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Expected O, but got Unknown
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Expected O, but got Unknown
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Expected O, but got Unknown
			object obj = <>O.<1>__OnSkinAppliedBody;
			if (obj == null)
			{
				hook_ApplySkinAsync val = OnSkinAppliedBody;
				<>O.<1>__OnSkinAppliedBody = val;
				obj = (object)val;
			}
			ModelSkinController.ApplySkinAsync += (hook_ApplySkinAsync)obj;
			object obj2 = <>O.<2>__OnTeleporterStart;
			if (obj2 == null)
			{
				hook_OnInteractionBegin val2 = OnTeleporterStart;
				<>O.<2>__OnTeleporterStart = val2;
				obj2 = (object)val2;
			}
			TeleporterInteraction.OnInteractionBegin += (hook_OnInteractionBegin)obj2;
			object obj3 = <>O.<3>__OnDeath;
			if (obj3 == null)
			{
				hook_OnDeathStart val3 = OnDeath;
				<>O.<3>__OnDeath = val3;
				obj3 = (object)val3;
			}
			CharacterBody.OnDeathStart += (hook_OnDeathStart)obj3;
			object obj4 = <>O.<4>__OnLeavePod;
			if (obj4 == null)
			{
				hook_EjectPassenger_GameObject val4 = OnLeavePod;
				<>O.<4>__OnLeavePod = val4;
				obj4 = (object)val4;
			}
			VehicleSeat.EjectPassenger_GameObject += (hook_EjectPassenger_GameObject)obj4;
			object obj5 = <>O.<5>__OnSkillActivated;
			if (obj5 == null)
			{
				hook_OnSkillActivated val5 = OnSkillActivated;
				<>O.<5>__OnSkillActivated = val5;
				obj5 = (object)val5;
			}
			CharacterBody.OnSkillActivated += (hook_OnSkillActivated)obj5;
			object obj6 = <>O.<6>__OnChanceShrineInteract;
			if (obj6 == null)
			{
				hook_AddShrineStack val6 = OnChanceShrineInteract;
				<>O.<6>__OnChanceShrineInteract = val6;
				obj6 = (object)val6;
			}
			ShrineChanceBehavior.AddShrineStack += (hook_AddShrineStack)obj6;
			object obj7 = <>O.<7>__OnPickupAttemptGrant;
			if (obj7 == null)
			{
				Manipulator val7 = OnPickupAttemptGrant;
				<>O.<7>__OnPickupAttemptGrant = val7;
				obj7 = (object)val7;
			}
			GenericPickupController.AttemptGrant += (Manipulator)obj7;
			object obj8 = <>O.<8>__OnBearDamageBlock;
			if (obj8 == null)
			{
				Manipulator val8 = OnBearDamageBlock;
				<>O.<8>__OnBearDamageBlock = val8;
				obj8 = (object)val8;
			}
			HealthComponent.TakeDamageProcess += (Manipulator)obj8;
			BossGroup.onBossGroupDefeatedServer += OnDefeatBossGroup;
			TeleporterInteraction.onTeleporterChargedGlobal += OnTeleporterEnd;
			GlobalEventManager.onServerDamageDealt += OnTakeDamage;
			GlobalEventManager.onCharacterLevelUp += OnLevelUp;
			object obj9 = <>O.<13>__OnMithrixDefeat;
			if (obj9 == null)
			{
				hook_OnEnter val9 = OnMithrixDefeat;
				<>O.<13>__OnMithrixDefeat = val9;
				obj9 = (object)val9;
			}
			EncounterFinished.OnEnter += (hook_OnEnter)obj9;
			EquipmentSlot.onServerEquipmentActivated += OnUseEquipment;
			HealthComponent.onCharacterHealServer += OnHeal;
			object obj10 = <>O.<16>__OnJump;
			if (obj10 == null)
			{
				hook_ApplyJumpVelocity val10 = OnJump;
				<>O.<16>__OnJump = val10;
				obj10 = (object)val10;
			}
			GenericCharacterMain.ApplyJumpVelocity += (hook_ApplyJumpVelocity)obj10;
			object obj11 = <>O.<17>__OnLeaveStage;
			if (obj11 == null)
			{
				hook_Begin val11 = OnLeaveStage;
				<>O.<17>__OnLeaveStage = val11;
				obj11 = (object)val11;
			}
			SceneExitController.Begin += (hook_Begin)obj11;
			object obj12 = <>O.<18>__OnBodyUpdate;
			if (obj12 == null)
			{
				hook_Update val12 = OnBodyUpdate;
				<>O.<18>__OnBodyUpdate = val12;
				obj12 = (object)val12;
			}
			CharacterBody.Update += (hook_Update)obj12;
			object obj13 = <>O.<19>__OnLeaveSpawnTeleporterState;
			if (obj13 == null)
			{
				hook_OnExit val13 = OnLeaveSpawnTeleporterState;
				<>O.<19>__OnLeaveSpawnTeleporterState = val13;
				obj13 = (object)val13;
			}
			SpawnTeleporterState.OnExit += (hook_OnExit)obj13;
			object obj14 = <>O.<20>__OnIconsRebuilt;
			if (obj14 == null)
			{
				hook_Rebuild val14 = OnIconsRebuilt;
				<>O.<20>__OnIconsRebuilt = val14;
				obj14 = (object)val14;
			}
			SurvivorIconController.Rebuild += (hook_Rebuild)obj14;
			object obj15 = <>O.<21>__OnLocalCSSLoadoutChanged;
			if (obj15 == null)
			{
				hook_RebuildLocal val15 = OnLocalCSSLoadoutChanged;
				<>O.<21>__OnLocalCSSLoadoutChanged = val15;
				obj15 = (object)val15;
			}
			CharacterSelectController.RebuildLocal += (hook_RebuildLocal)obj15;
			if (Compat.iconsModEnabled)
			{
				Compat.EnableIconsModHooks();
			}
		}

		private static void OnLocalCSSLoadoutChanged(orig_RebuildLocal orig, CharacterSelectController self, bool deselectButtons)
		{
			orig.Invoke(self, deselectButtons);
			if (Object.op_Implicit((Object)(object)self.characterSelectBarController) && (Object)(object)cssSelectedSurvivorIcon == (Object)(object)self.characterSelectBarController.pickedIcon)
			{
				self.characterSelectBarController.pickedIcon.shouldRebuild = true;
			}
			cssSelectedSurvivorIcon = self.characterSelectBarController.pickedIcon;
		}

		private static void OnIconsRebuilt(orig_Rebuild orig, SurvivorIconController self)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (!Object.op_Implicit((Object)(object)self.survivorIcon))
			{
				return;
			}
			LocalUser localUser = self.GetLocalUser();
			uint? obj;
			if (localUser == null)
			{
				obj = null;
			}
			else
			{
				NetworkUser obj2 = UnityObjectExtensions.AsValidOrNull<NetworkUser>(localUser.currentNetworkUser);
				if (obj2 == null)
				{
					obj = null;
				}
				else
				{
					NetworkLoadout obj3 = UnityObjectExtensions.AsValidOrNull<NetworkLoadout>(obj2.networkLoadout);
					if (obj3 == null)
					{
						obj = null;
					}
					else
					{
						Loadout loadout = obj3.loadout;
						if (loadout == null)
						{
							obj = null;
						}
						else
						{
							BodyLoadoutManager bodyLoadoutManager = loadout.bodyLoadoutManager;
							obj = ((bodyLoadoutManager != null) ? new uint?(bodyLoadoutManager.GetSkinIndex(self.survivorBodyIndex)) : ((uint?)null));
						}
					}
				}
			}
			uint? num = obj;
			if (num.HasValue)
			{
				SurvivorDef survivorDef = self.survivorDef;
				object obj4;
				if (survivorDef == null)
				{
					obj4 = null;
				}
				else
				{
					GameObject obj5 = UnityObjectExtensions.AsValidOrNull<GameObject>(survivorDef.displayPrefab);
					obj4 = ((obj5 != null) ? obj5.GetComponentInChildren<ModelSkinController>() : null);
				}
				ModelSkinController val = (ModelSkinController)obj4;
				if (Object.op_Implicit((Object)(object)val) && ArrayUtils.GetSafe<SkinDef>(val.skins, (int)num.Value).TryGetCustomIcon(out var icon))
				{
					self.survivorIcon.texture = icon;
					Compat.shouldOverrideIconsMod = true;
				}
			}
		}

		public static void SubscribeGlobalEvents()
		{
			EventSub.DifferentSkinAppliedGlobal = (Action<GameObject>)Delegate.Combine(EventSub.DifferentSkinAppliedGlobal, new Action<GameObject>(RemoveMwComponents));
		}

		public static EventSub GetEventSubFromBody(GameObject body)
		{
			if (!Object.op_Implicit((Object)(object)body))
			{
				return null;
			}
			SkinDef val = SkinCatalog.FindCurrentSkinDefForBodyInstance(body);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			return GetEventSubFromSkinDef(val);
		}

		public static EventSub GetEventSubFromSkinDef(SkinDef skinDef)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)skinDef != (Object)null && skinDefToEventSub.ContainsKey(skinDef))
			{
				return skinDefToEventSub[skinDef];
			}
			if ((Object)(object)skinDef != (Object)null && (int)skinDef.skinIndex != -1 && skinIndexToEventSub.ContainsKey(skinDef.skinIndex))
			{
				return skinIndexToEventSub[skinDef.skinIndex];
			}
			return null;
		}

		public static Texture GetCustomIconFromSkinDef(SkinDef skinDef)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Invalid comparison between Unknown and I4
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)skinDef != (Object)null)
			{
				if (skinDefToCustomIcon.ContainsKey(skinDef))
				{
					return skinDefToCustomIcon[skinDef];
				}
				if ((int)skinDef.skinIndex != -1 && skinIndexToCustomIcon.ContainsKey(skinDef.skinIndex))
				{
					return skinIndexToCustomIcon[skinDef.skinIndex];
				}
			}
			return null;
		}

		private static void ForEachBodySafe(Action<GameObject> action)
		{
			foreach (CharacterMaster readOnlyInstances in CharacterMaster.readOnlyInstancesList)
			{
				if (Object.op_Implicit((Object)(object)readOnlyInstances))
				{
					GameObject bodyObject = readOnlyInstances.GetBodyObject();
					if (Object.op_Implicit((Object)(object)bodyObject))
					{
						action(bodyObject);
					}
				}
			}
		}

		private static IEnumerator OnSkinAppliedBody(orig_ApplySkinAsync orig, ModelSkinController self, int skinIndex, AsyncReferenceHandleUnloadType unloadType)
		{
			//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)
			IEnumerator origSelf = orig.Invoke(self, skinIndex, unloadType);
			while (origSelf.MoveNext())
			{
				yield return origSelf.Current;
			}
			GameObject bodyObject = null;
			EventSub bodyEventSub = null;
			if (Object.op_Implicit((Object)(object)self) && (Object.op_Implicit((Object)(object)self.characterModel) & Object.op_Implicit((Object)(object)self.characterModel.body)))
			{
				bodyObject = ((Component)self.characterModel.body).gameObject;
			}
			if (Object.op_Implicit((Object)(object)bodyObject))
			{
				bodyEventSub = GetEventSubFromBody(bodyObject);
				EventSub.DifferentSkinAppliedGlobal?.Invoke(bodyObject);
			}
			else
			{
				EventSub.DifferentSkinAppliedGlobal?.Invoke(((Component)self).gameObject);
			}
			if (Object.op_Implicit((Object)(object)bodyObject) && bodyEventSub != null)
			{
				bodyEventSub.SkinAppliedRun?.Invoke(bodyObject);
				yield break;
			}
			EventSub cssBodyEventSub = default(EventSub);
			int num;
			if (!Object.op_Implicit((Object)(object)bodyObject))
			{
				SkinDef skinDef = ArrayUtils.GetSafe<SkinDef>(self.skins, self.currentSkinIndex);
				if (skinDef != null)
				{
					cssBodyEventSub = GetEventSubFromSkinDef(skinDef);
					num = ((cssBodyEventSub != null) ? 1 : 0);
					goto IL_01cb;
				}
			}
			num = 0;
			goto IL_01cb;
			IL_01cb:
			if (num != 0)
			{
				cssBodyEventSub?.SkinAppliedLobby?.Invoke(((Component)self).gameObject);
			}
		}

		private static void OnTeleporterStart(orig_OnInteractionBegin orig, TeleporterInteraction self, Interactor activator)
		{
			orig.Invoke(self, activator);
			if (Object.op_Implicit((Object)(object)TeleporterInteraction.instance) && !TeleporterInteraction.instance.isCharged)
			{
				GetEventSubFromBody(((Component)activator).gameObject)?.TeleporterStart?.Invoke(((Component)activator).gameObject);
			}
		}

		private static void OnDeath(orig_OnDeathStart orig, CharacterBody self)
		{
			orig.Invoke(self);
			GetEventSubFromBody(((Component)self).gameObject)?.Death?.Invoke(((Component)self).gameObject);
		}

		private static void OnLeavePod(orig_EjectPassenger_GameObject orig, VehicleSeat self, GameObject body)
		{
			orig.Invoke(self, body);
			if (self.isSurvivorPod)
			{
				GetEventSubFromBody(body)?.LeavePod?.Invoke(body);
			}
		}

		private static void OnSkillActivated(orig_OnSkillActivated orig, CharacterBody self, GenericSkill skill)
		{
			orig.Invoke(self, skill);
			EventSub eventSubFromBody = GetEventSubFromBody(((Component)self).gameObject);
			if (eventSubFromBody != null)
			{
				if ((Object)(object)skill == (Object)(object)self.skillLocator.primary)
				{
					eventSubFromBody.UsePrimary?.Invoke(((Component)self).gameObject);
				}
				else if ((Object)(object)skill == (Object)(object)self.skillLocator.secondary)
				{
					eventSubFromBody.UseSecondary?.Invoke(((Component)self).gameObject);
				}
				else if ((Object)(object)skill == (Object)(object)self.skillLocator.utility)
				{
					eventSubFromBody.UseUtility?.Invoke(((Component)self).gameObject);
				}
				else if ((Object)(object)skill == (Object)(object)self.skillLocator.special)
				{
					eventSubFromBody.UseSpecial?.Invoke(((Component)self).gameObject);
				}
			}
		}

		private static void OnChanceShrineInteract(orig_AddShrineStack orig, ShrineChanceBehavior self, Interactor activator)
		{
			int successfulPurchaseCount = self.successfulPurchaseCount;
			orig.Invoke(self, activator);
			EventSub eventSubFromBody = GetEventSubFromBody(((Component)activator).gameObject);
			if (eventSubFromBody != null)
			{
				if (successfulPurchaseCount < self.successfulPurchaseCount)
				{
					eventSubFromBody.ShrineSuccess?.Invoke(((Component)activator).gameObject);
				}
				else
				{
					eventSubFromBody.ShrineFailure?.Invoke(((Component)activator).gameObject);
				}
			}
		}

		private static void OnBearDamageBlock(ILContext il)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			Action<HealthComponent> action = delegate(HealthComponent healthComponent)
			{
				GetEventSubFromBody(((Component)healthComponent.body).gameObject)?.BearDamageBlock?.Invoke(((Component)healthComponent.body).gameObject);
			};
			ILCursor val = new ILCursor(il);
			int num = default(int);
			if (val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, "RoR2.HealthComponent+AssetReferences", "bearEffectPrefab")
			}) && val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num)
			}) && val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, ref num)
			}) && val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, "RoR2.EffectManager", "SpawnEffect")
			}))
			{
				val.Emit(OpCodes.Ldarg_0);
				val.EmitDelegate<Action<HealthComponent>>(action);
				if (val.TryGotoNext(new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, "RoR2.HealthComponent+AssetReferences", "bearVoidEffectPrefab")
				}) && val.TryGotoNext(new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num)
				}) && val.TryGotoNext(new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, ref num)
				}) && val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, "RoR2.EffectManager", "SpawnEffect")
				}))
				{
					val.Emit(OpCodes.Ldarg_0);
					val.EmitDelegate<Action<HealthComponent>>(action);
				}
			}
			else
			{
				Log.Error("OnBearDamageBlock ILHook failed. Tougher Times/Safer Spaces block events will not occur");
			}
		}

		private static void OnLevelUp(CharacterBody characterBody)
		{
			if (Object.op_Implicit((Object)(object)characterBody))
			{
				GetEventSubFromBody(((Component)characterBody).gameObject)?.LevelUp?.Invoke(((Component)characterBody).gameObject);
			}
		}

		private static void OnPickupAttemptGrant(ILContext il)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			Action<CharacterBody, PickupDef> action = delegate(CharacterBody body, PickupDef pickupDef)
			{
				//IL_001c: 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_002c: Expected I4, but got Unknown
				EventSub eventSubFromBody = GetEventSubFromBody(((Component)body).gameObject);
				if (eventSubFromBody != null)
				{
					NetMessageExtensions.Send((INetMessage)(object)new SyncGetItem(body.master.bodyInstanceId, (int)pickupDef.itemIndex), (NetworkDestination)1);
				}
			};
			ILCursor c = new ILCursor(il);
			int pickupLoc = 2;
			if (c.TryGotoNext(new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)typeof(PickupCatalog).GetMethod("GetPickupDef")),
				(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref pickupLoc)
			}) && c.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<GrantContext>(x, "shouldDestroy") && c.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
				{
					(Instruction val) => ILPatternMatchingExt.MatchStfld<GenericPickupController>(val, "consumed")
				})
			}))
			{
				c.Emit(OpCodes.Ldarg_1);
				c.Emit(OpCodes.Ldloc, pickupLoc);
				c.EmitDelegate<Action<CharacterBody, PickupDef>>(action);
			}
			else
			{
				Log.Error("OnPickupAttemptGrant ILHook failed. Pickup interaction related events will not occur");
			}
		}

		private static void OnDefeatBossGroup(BossGroup bossGroup)
		{
			if (((Object)((Component)bossGroup).gameObject).name != "BrotherEncounter, Phase 4")
			{
				ForEachBodySafe(delegate(GameObject bodyObject)
				{
					GetEventSubFromBody(bodyObject)?.DefeatBossGroup?.Invoke(bodyObject);
				});
			}
		}

		private static void OnTeleporterEnd(TeleporterInteraction teleporterInteraction)
		{
			ForEachBodySafe(delegate(GameObject bodyObject)
			{
				GetEventSubFromBody(bodyObject)?.TeleporterEnd?.Invoke(bodyObject);
			});
		}

		private static void OnTakeDamage(DamageReport damageReport)
		{
			if (Object.op_Implicit((Object)(object)damageReport.victimBody) && Object.op_Implicit((Object)(object)damageReport.victimBody.healthComponent) && damageReport.victimBody.healthComponent.health > 0f)
			{
				GetEventSubFromBody(((Component)damageReport.victimBody).gameObject)?.TakeDamage?.Invoke(((Component)damageReport.victimBody).gameObject, damageReport);
			}
		}

		private static void OnMithrixDefeat(orig_OnEnter orig, EncounterFinished self)
		{
			orig.Invoke(self);
			ForEachBodySafe(delegate(GameObject bodyObject)
			{
				GetEventSubFromBody(bodyObject)?.MithrixDefeat?.Invoke(bodyObject);
			});
		}

		private static void OnUseEquipment(EquipmentSlot self, EquipmentIndex index)
		{
			GetEventSubFromBody(((Component)self.characterBody).gameObject)?.UseEquipment?.Invoke(((Component)self.characterBody).gameObject);
		}

		private static void OnHeal(HealthComponent self, float amount, ProcChainMask procChainMask)
		{
			if (Object.op_Implicit((Object)(object)self) && Object.op_Implicit((Object)(object)self.body))
			{
				GetEventSubFromBody(((Component)self.body).gameObject)?.Heal?.Invoke(((Component)self.body).gameObject, amount);
			}
		}

		private static void OnJump(orig_ApplyJumpVelocity orig, CharacterMotor characterMotor, CharacterBody characterBody, float horizontalBonus, float verticalBonus, bool vault)
		{
			orig.Invoke(characterMotor, characterBody, horizontalBonus, verticalBonus, vault);
			GetEventSubFromBody(((Component)characterBody).gameObject)?.Jump?.Invoke(((Component)characterBody).gameObject);
		}

		private static void OnLeaveStage(orig_Begin orig, SceneExitController self)
		{
			orig.Invoke(self);
			ForEachBodySafe(delegate(GameObject bodyObject)
			{
				GetEventSubFromBody(bodyObject)?.LeaveStage?.Invoke(bodyObject);
			});
		}

		private static void OnLeaveSpawnTeleporterState(orig_OnExit orig, SpawnTeleporterState self)
		{
			orig.Invoke(self);
			if (Object.op_Implicit((Object)(object)Run.instance) && Run.instance.stageClearCount > 0 && Object.op_Implicit((Object)(object)((EntityState)self).gameObject))
			{
				GetEventSubFromBody(((EntityState)self).gameObject)?.LeaveSpawnTeleporterState?.Invoke(((EntityState)self).gameObject);
			}
		}

		public static GameObject GetModelFromEventBody(GameObject body)
		{
			ModelLocator val = default(ModelLocator);
			if (Object.op_Implicit((Object)(object)Stage.instance) && Object.op_Implicit((Object)(object)body) && body.TryGetComponent<ModelLocator>(ref val) && Object.op_Implicit((Object)(object)val.modelTransform))
			{
				return ((Component)val.modelTransform).gameObject;
			}
			return body;
		}

		public static ExpressionController GetExpressionController(GameObject body)
		{
			GameObject modelFromEventBody = GetModelFromEventBody(body);
			if (Object.op_Implicit((Object)(object)modelFromEventBody))
			{
				return modelFromEventBody.GetComponent<ExpressionController>();
			}
			return null;
		}

		public static void RemoveMwComponents(GameObject body)
		{
			if (Object.op_Implicit((Object)(object)body))
			{
				MwBaseComponent[] components = body.GetComponents<MwBaseComponent>();
				MwBaseComponent[] array = components;
				foreach (MwBaseComponent mwBaseComponent in array)
				{
					mwBaseComponent.MarkForDeletion();
				}
			}
		}

		private static void OnBodyUpdate(orig_Update orig, CharacterBody self)
		{
			orig.Invoke(self);
			if (Object.op_Implicit((Object)(object)self) && self.notMovingStopwatch > 10f)
			{
				EventSub eventSubFromBody = GetEventSubFromBody(((Component)self).gameObject);
				if (eventSubFromBody != null && self.notMovingStopwatch % 10f < 0.1f && !holdOffIdleInvocation.Contains(self))
				{
					eventSubFromBody.Idle?.Invoke(((Component)self).gameObject);
					((MonoBehaviour)RoR2Application.instance).StartCoroutine(HoldBodyFromIdleUpdate(self));
				}
			}
		}

		private static IEnumerator HoldBodyFromIdleUpdate(CharacterBody body)
		{
			holdOffIdleInvocation?.Add(body);
			yield return (object)new WaitForSeconds(1f);
			holdOffIdleInvocation?.Remove(body);
		}

		public static void InvokeGetItem(GameObject body, int itemIndex)
		{
			EventSub eventSubFromBody = GetEventSubFromBody(body.gameObject);
			eventSubFromBody.GetItem?.Invoke(body.gameObject, (ItemIndex)itemI