Decompiled source of Deez Nuts v0.1.1

plugins/DeezNuts/DeezNuts.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Blackforge.Hot;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 Blackforge.Hot
{
	public interface IHotModule
	{
		void Load(HotHost host);

		Dictionary<string, string> Unload();
	}
	public sealed class HotHost
	{
		private readonly string folder;

		public string Name => "deeznuts";

		public ManualLogSource Log { get; }

		public Harmony Harmony { get; }

		public bool Reloading => false;

		public Dictionary<string, string> Handover { get; } = new Dictionary<string, string>();

		public string Version { get; }

		public bool InSync { get; internal set; } = true;

		public bool IsDedicatedServer
		{
			get
			{
				if ((Object)(object)ZNet.instance != (Object)null)
				{
					return ZNet.instance.IsDedicated();
				}
				return false;
			}
		}

		internal HotHost(ManualLogSource log, Harmony harmony, string folder, string version)
		{
			Log = log;
			Harmony = harmony;
			this.folder = folder;
			Version = version;
		}

		public string AssetPath(string relative)
		{
			string text = ModFiles.Find(folder, relative);
			if (text != null)
			{
				return text;
			}
			throw new FileNotFoundException("Deez Nuts " + Version + " has no " + relative + " next to its dll, install the whole mod folder");
		}

		public byte[] ReadAsset(string relative)
		{
			return File.ReadAllBytes(AssetPath(relative));
		}

		public IEnumerable<string> Assets(string under)
		{
			string path = Path.Combine(folder, under.Replace('/', Path.DirectorySeparatorChar));
			if (!Directory.Exists(path))
			{
				return Enumerable.Empty<string>();
			}
			return from text in Directory.GetFiles(path, "*", SearchOption.AllDirectories)
				select text.Substring(folder.Length + 1).Replace(Path.DirectorySeparatorChar, '/') into result
				orderby result
				select result;
		}

		public void AddPrefabs(ZNetScene scene, IEnumerable<GameObject> prefabs)
		{
			bool flag = (Object)(object)ZNetScene.instance == (Object)(object)scene;
			foreach (GameObject prefab in prefabs)
			{
				scene.m_prefabs.RemoveAll((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name == ((Object)prefab).name);
				scene.m_prefabs.Add(prefab);
				if (flag)
				{
					scene.m_namedPrefabs[StringExtensionMethods.GetStableHashCode(((Object)prefab).name)] = prefab;
				}
			}
		}

		public void UnregisterRpc(IEnumerable<string> names)
		{
			if (ZRoutedRpc.instance == null)
			{
				return;
			}
			foreach (string name in names)
			{
				ZRoutedRpc.instance.m_functions.Remove(StringExtensionMethods.GetStableHashCode(name));
			}
		}
	}
	internal static class ModFiles
	{
		internal static string Find(string folder, string relative)
		{
			string text = Path.Combine(folder, relative.Replace('/', Path.DirectorySeparatorChar));
			if (File.Exists(text))
			{
				return text;
			}
			string text2 = Path.Combine(folder, Path.GetFileName(text));
			if (!File.Exists(text2))
			{
				return null;
			}
			return text2;
		}
	}
}
namespace Blackforge.DeezNuts
{
	[HarmonyPatch(typeof(Character), "Damage")]
	internal static class MeleeReach
	{
		private static void Prefix(Character __instance, HitData hit)
		{
			WeakSpot val = Sacks.Spot(__instance);
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val.m_collider == (Object)null) && !((Object)(object)hit.m_hitCollider == (Object)(object)val.m_collider))
			{
				Collider val2 = Sacks.Pick(__instance, hit);
				NutsPlugin.Log.LogInfo((object)("deez nuts: a hit on " + __instance.m_name + " took " + (((Object)(object)hit.m_hitCollider != (Object)null) ? ((Object)hit.m_hitCollider).name : "nothing") + ", it counts for " + (((Object)(object)val2 != (Object)null) ? ((Object)val2).name : "nothing")));
				hit.m_hitCollider = val2;
			}
		}
	}
	[HarmonyPatch(typeof(Character), "RPC_Damage")]
	internal static class SweetSpot
	{
		public static Character Current;

		public static bool Applied;

		private static void Prefix(Character __instance, HitData hit)
		{
			Current = null;
			Applied = false;
			WeakSpot weakSpot = __instance.GetWeakSpot(hit.m_weakSpot);
			if ((Object)(object)weakSpot != (Object)null && ((Object)weakSpot).name == "DeezNuts")
			{
				Current = __instance;
			}
		}

		private static void Postfix(Character __instance, HitData hit)
		{
			if ((Object)(object)Current == (Object)(object)__instance && Applied)
			{
				Net.Crit(__instance, hit);
			}
			Current = null;
			Applied = false;
		}
	}
	[HarmonyPatch(typeof(Character), "ApplyDamage")]
	internal static class SackDamage
	{
		private static void Prefix(Character __instance, HitData hit)
		{
			if (!((Object)(object)SweetSpot.Current != (Object)(object)__instance) && !__instance.IsDead())
			{
				float totalDamage = hit.GetTotalDamage();
				((DamageTypes)(ref hit.m_damage)).Modify(Settings.Damage);
				NutsPlugin.Log.LogInfo((object)$"deez nuts: a sack hit of {totalDamage:0} damage does {hit.GetTotalDamage():0}, {__instance.GetMaxHealth():0} health");
				SweetSpot.Applied = true;
			}
		}
	}
	public static class Models
	{
		private static readonly Dictionary<string, Mesh> cache = new Dictionary<string, Mesh>();

		public static Mesh Load(string name)
		{
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Expected O, but got Unknown
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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)
			if (cache.TryGetValue(name, out var value))
			{
				return value;
			}
			using Stream input = new MemoryStream(NutsPlugin.Host.ReadAsset("meshes/" + name + ".bfm"));
			using BinaryReader binaryReader = new BinaryReader(input);
			if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "BFM5")
			{
				throw new InvalidDataException(name + " is not a mesh file");
			}
			int num = binaryReader.ReadInt32();
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<int[]> list4 = new List<int[]>();
			for (int i = 0; i < num; i++)
			{
				binaryReader.ReadBytes(binaryReader.ReadInt32());
				int count = list.Count;
				int num2 = binaryReader.ReadInt32();
				for (int j = 0; j < num2; j++)
				{
					list.Add(new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle()));
					list2.Add(new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle()));
					list3.Add(new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle()));
				}
				int[] array = new int[binaryReader.ReadInt32()];
				for (int k = 0; k < array.Length; k++)
				{
					array[k] = count + binaryReader.ReadInt32();
				}
				list4.Add(array);
			}
			value = new Mesh
			{
				name = "deeznuts_" + name
			};
			value.SetVertices(list);
			value.SetNormals(list2);
			value.SetUVs(0, list3);
			value.SetColors(Enumerable.Repeat<Color>(Color.white, list.Count).ToList());
			value.subMeshCount = num;
			for (int l = 0; l < num; l++)
			{
				value.SetTriangles(list4[l], l);
			}
			value.RecalculateBounds();
			value.RecalculateTangents();
			cache[name] = value;
			return value;
		}

		public static void Clear()
		{
			cache.Clear();
		}
	}
	public static class Net
	{
		private const string Ask = "deeznuts_ask";

		private const string Values = "deeznuts_settings";

		private const string CritCall = "deeznuts_crit";

		private static readonly string[] RpcNames = new string[4] { "deeznuts_ask", "deeznuts_settings", "deeznuts_crit", "deeznuts_hitbox" };

		private static GameObject session;

		private static bool asked;

		private const float Huge = 4f;

		private const float SecondBurst = 0.15f;

		private const int Loud = 3;

		public static bool IsServer
		{
			get
			{
				if ((Object)(object)ZNet.instance != (Object)null)
				{
					return ZNet.instance.IsServer();
				}
				return false;
			}
		}

		public static void Start()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			Stop();
			ZRoutedRpc instance = ZRoutedRpc.instance;
			instance.Register("deeznuts_ask", (Action<long>)OnAsk);
			instance.Register<float, float, float, float>("deeznuts_settings", (Method<float, float, float, float>)OnValues);
			instance.Register<Vector3, Vector3, ZDOID>("deeznuts_crit", (Action<long, Vector3, Vector3, ZDOID>)OnCrit);
			session = new GameObject("DeezNuts");
			session.AddComponent<Session>();
		}

		public static void Stop()
		{
			NutsPlugin.Host.UnregisterRpc(RpcNames);
			if ((Object)(object)session != (Object)null)
			{
				Object.Destroy((Object)(object)session);
				session = null;
			}
			asked = false;
			Settings.Forget();
		}

		public static void Tick()
		{
			if (!asked && !IsServer && ZRoutedRpc.instance != null && !((Object)(object)Player.m_localPlayer == (Object)null))
			{
				asked = true;
				ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "deeznuts_ask", Array.Empty<object>());
			}
		}

		private static void OnAsk(long sender)
		{
			if (IsServer)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(sender, "deeznuts_settings", new object[4]
				{
					Settings.Size,
					Settings.Damage,
					Settings.Growth,
					Settings.Hairiness
				});
			}
		}

		private static void OnValues(long sender, float size, float damage, float growth, float hair)
		{
			if (!IsServer && sender == ZRoutedRpc.instance.GetServerPeerID())
			{
				Settings.FromServer(size, damage, growth, hair);
			}
		}

		public static void Crit(Character troll, HitData hit)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			ZRoutedRpc.instance.InvokeRoutedRPC(0L, "deeznuts_crit", new object[3]
			{
				hit.m_point,
				hit.m_dir,
				troll.GetZDOID()
			});
			NutsPlugin.Log.LogInfo((object)$"deez nuts: a hit on the sack of {troll.m_name}, {troll.GetHealth():0} health left");
		}

		private static void OnCrit(long sender, Vector3 point, Vector3 direction, ZDOID id)
		{
			//IL_0015: 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_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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.FindInstance(id) : null);
			Character val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Character>() : null);
			if (!((Object)(object)val2 == (Object)null))
			{
				EffectList crit = (val2.m_critHitEffects.HasEffects() ? val2.m_critHitEffects : val2.m_hitEffects);
				if ((Object)(object)session != (Object)null)
				{
					((MonoBehaviour)session.GetComponent<Session>()).StartCoroutine(Bursts(crit, point));
				}
				BaseAI component = ((Component)val2).GetComponent<BaseAI>();
				if ((Object)(object)component != (Object)null)
				{
					component.m_idleSound.Create(((Component)val2).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
				}
				Swing componentInChildren = val.GetComponentInChildren<Swing>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.Kick(((Vector3)(ref direction)).normalized * 4f);
				}
			}
		}

		private static IEnumerator Bursts(EffectList crit, Vector3 point)
		{
			//IL_000e: 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)
			Burst(crit, point);
			yield return (object)new WaitForSeconds(0.15f);
			Burst(crit, point);
		}

		private static void Burst(EffectList crit, Vector3 point)
		{
			//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_0010: 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_0033: 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_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)
			GameObject[] array = crit.Create(point, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
			GameObject[] array2 = array;
			foreach (GameObject val in array2)
			{
				Transform transform = val.transform;
				transform.localScale *= 4f;
				ParticleSystem[] componentsInChildren = val.GetComponentsInChildren<ParticleSystem>();
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					MainModule main = componentsInChildren[j].main;
					((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)0;
				}
				ZSFX[] componentsInChildren2 = val.GetComponentsInChildren<ZSFX>();
				foreach (ZSFX sound in componentsInChildren2)
				{
					for (int k = 1; k < 3; k++)
					{
						Echo(sound);
					}
				}
			}
			NutsPlugin.Log.LogInfo((object)("deez nuts: crit " + string.Join(", ", array.Select((GameObject effect) => $"{((Object)effect).name} with {effect.GetComponentsInChildren<ZSFX>().Count((ZSFX s) => s.m_audioClips != null && s.m_audioClips.Length != 0)} sounds"))));
		}

		private static void Echo(ZSFX sound)
		{
			//IL_0024: 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_0035: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			AudioSource component = ((Component)sound).GetComponent<AudioSource>();
			AudioClip[] audioClips = sound.m_audioClips;
			if (!((Object)(object)component == (Object)null) && audioClips != null && audioClips.Length != 0)
			{
				GameObject val = new GameObject("DeezNutsLoud");
				val.transform.position = ((Component)component).transform.position;
				AudioSource val2 = val.AddComponent<AudioSource>();
				val2.clip = audioClips[Random.Range(0, audioClips.Length)];
				val2.outputAudioMixerGroup = component.outputAudioMixerGroup;
				val2.volume = Mathf.Min(sound.m_maxVol, 1f);
				val2.pitch = Random.Range(sound.m_minPitch, sound.m_maxPitch);
				val2.spatialBlend = component.spatialBlend;
				val2.rolloffMode = component.rolloffMode;
				val2.minDistance = component.minDistance;
				val2.maxDistance = component.maxDistance;
				val2.dopplerLevel = component.dopplerLevel;
				val2.priority = component.priority;
				val2.Play();
				Object.Destroy((Object)val, val2.clip.length / Mathf.Max(Mathf.Abs(val2.pitch), 0.1f) + 0.1f);
			}
		}
	}
	public class Session : MonoBehaviour
	{
		private void Update()
		{
			Net.Tick();
		}
	}
	public static class NutsPlugin
	{
		public static ManualLogSource Log;

		public static HotHost Host;
	}
	public class NutsModule : IHotModule
	{
		public void Load(HotHost host)
		{
			NutsPlugin.Log = host.Log;
			NutsPlugin.Host = host;
			Settings.Load();
			host.Harmony.PatchAll(typeof(NutsModule).Assembly);
			Sacks.AddTo(ZNetScene.instance);
			if ((Object)(object)Game.instance != (Object)null && ZRoutedRpc.instance != null)
			{
				Net.Start();
			}
			host.Log.LogInfo((object)("deez nuts ready, version " + host.Version));
		}

		public Dictionary<string, string> Unload()
		{
			Net.Stop();
			Sacks.RemoveFrom(ZNetScene.instance);
			Models.Clear();
			Sacks.ClearMeshes();
			return new Dictionary<string, string>();
		}
	}
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	internal static class AddOnScene
	{
		private static void Postfix(ZNetScene __instance)
		{
			Sacks.AddTo(__instance);
		}
	}
	[HarmonyPatch(typeof(Game), "Start")]
	internal static class StartOnGame
	{
		private static void Postfix()
		{
			Net.Start();
		}
	}
	public static class Sacks
	{
		public const string Part = "DeezNuts";

		private const string MeshName = "sack";

		private static readonly string[] Bodies = new string[2] { "Troll", "Troll_sleeping" };

		private static readonly string[] Ragdolls = new string[1] { "Troll_ragdoll" };

		private static readonly Vector3 Place = new Vector3(0f, -0.72f, 0.43f);

		private static readonly Dictionary<int, Mesh> hairy = new Dictionary<int, Mesh>();

		public const string BodyBox = "DeezNutsBody";

		public const string LegBox = "DeezNutsLeg";

		public const string AttackCollider = "Attack collider";

		public const float OverSack = 0.1f;

		private const int TopLevel = 3;

		private const float LegRadius = 0.55f;

		public static void AddTo(ZNetScene scene)
		{
			if ((Object)(object)scene == (Object)null)
			{
				return;
			}
			int num = 0;
			foreach (string item in Bodies.Concat(Ragdolls))
			{
				GameObject prefab = scene.GetPrefab(item);
				if ((Object)(object)prefab == (Object)null)
				{
					NutsPlugin.Log.LogWarning((object)("deez nuts: the game has no prefab " + item));
				}
				else if (Add(prefab, Bodies.Contains(item)))
				{
					num++;
				}
			}
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				if (Bodies.Contains(Utils.GetPrefabName(((Component)allCharacter).gameObject)))
				{
					Add(((Component)allCharacter).gameObject, weak: true);
				}
			}
			NutsPlugin.Log.LogInfo((object)$"deez nuts on {num} prefabs");
		}

		public static void RemoveFrom(ZNetScene scene)
		{
			List<GameObject> list = (from c in Character.GetAllCharacters()
				select ((Component)c).gameObject).ToList();
			if ((Object)(object)scene != (Object)null)
			{
				list.AddRange(from p in Bodies.Concat(Ragdolls).Select((Func<string, GameObject>)scene.GetPrefab)
					where (Object)(object)p != (Object)null
					select p);
			}
			foreach (GameObject item in list)
			{
				Swing[] componentsInChildren = item.GetComponentsInChildren<Swing>(true);
				foreach (Swing swing in componentsInChildren)
				{
					Character component = item.GetComponent<Character>();
					WeakSpot spot = ((Component)swing).GetComponent<WeakSpot>();
					if ((Object)(object)component != (Object)null && (Object)(object)spot != (Object)null && component.m_weakSpots != null)
					{
						component.m_weakSpots = component.m_weakSpots.Where((WeakSpot s) => (Object)(object)s != (Object)(object)spot).ToArray();
					}
					Object.DestroyImmediate((Object)(object)((Component)swing).gameObject, true);
				}
				RemoveHitboxes(item);
			}
		}

		private static void RemoveHitboxes(GameObject body)
		{
			foreach (Transform item in (from t in body.GetComponentsInChildren<Transform>(true)
				where ((Object)t).name == "DeezNutsBody" || ((Object)t).name == "DeezNutsLeg"
				select t).ToList())
			{
				Object.DestroyImmediate((Object)(object)((Component)item).gameObject, true);
			}
		}

		public static Mesh MeshFor(float hairiness)
		{
			Mesh val = Models.Load("sack");
			if (val.subMeshCount < 2)
			{
				return val;
			}
			int[] triangles = val.GetTriangles(1);
			int num = Mathf.RoundToInt((float)(triangles.Length / 12) * hairiness);
			if (hairy.TryGetValue(num, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			value = Object.Instantiate<Mesh>(val);
			((Object)value).name = $"deeznuts_sack_{num}";
			value.SetTriangles(triangles.Take(num * 12).ToArray(), 1);
			hairy[num] = value;
			return value;
		}

		public static void ClearMeshes()
		{
			hairy.Clear();
		}

		private static void AddHitboxes(GameObject body, SphereCollider ball)
		{
			//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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			RemoveHitboxes(body);
			CapsuleCollider component = body.GetComponent<CapsuleCollider>();
			Transform val = Find(body.transform, "Spine0");
			if ((Object)(object)component != (Object)null && (Object)(object)val != (Object)null)
			{
				Vector3 val2 = body.transform.TransformPoint(component.center);
				float num = val2.y + component.height / 2f;
				Transform transform = ((Component)ball).transform;
				float num2 = Settings.SizeAt(3) / Settings.SizeAt(1);
				float num3 = transform.position.y + (ball.center.y + ball.radius) * transform.lossyScale.y * num2;
				float num4 = num3 + 0.1f;
				NutsPlugin.Log.LogInfo((object)$"deez nuts: {((Object)body).name} body box from {num4 - body.transform.position.y:0.00} m to {num - body.transform.position.y:0.00} m, the sack top at 2 stars {num3 - body.transform.position.y:0.00} m");
				Box("DeezNutsBody", val, new Vector3(val2.x, (num + num4) / 2f, val2.z), Vector3.up, num - num4, component.radius);
			}
			string[] array = new string[2] { "Left", "Right" };
			foreach (string text in array)
			{
				Transform val3 = Find(body.transform, text + "UpLeg");
				Transform val4 = Find(body.transform, text + "Foot");
				if ((Object)(object)val3 != (Object)null && (Object)(object)val4 != (Object)null)
				{
					Vector3 up = val4.position - val3.position;
					Box("DeezNutsLeg", val3, (val3.position + val4.position) / 2f, up, ((Vector3)(ref up)).magnitude + 1.1f, 0.55f);
				}
			}
		}

		private static void Box(string name, Transform bone, Vector3 middle, Vector3 up, float height, float radius)
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name)
			{
				layer = LayerMask.NameToLayer("character_noenv")
			};
			val.transform.position = middle;
			val.transform.rotation = Quaternion.FromToRotation(Vector3.up, ((Vector3)(ref up)).normalized);
			val.transform.SetParent(bone, true);
			CapsuleCollider val2 = val.AddComponent<CapsuleCollider>();
			float x = val.transform.lossyScale.x;
			val2.direction = 1;
			val2.height = height / x;
			val2.radius = radius / x;
		}

		public static Collider Pick(Character character, HitData hit)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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)
			List<Collider> list = (from c in ((Component)character).GetComponentsInChildren<Collider>()
				where ((Object)c).name == "DeezNuts" || ((Object)c).name == "DeezNutsBody" || ((Object)c).name == "DeezNutsLeg"
				select c).ToList();
			if (list.Count == 0)
			{
				return hit.m_hitCollider;
			}
			Character attacker = hit.GetAttacker();
			if ((Object)(object)attacker != (Object)null)
			{
				Ray val = default(Ray);
				((Ray)(ref val))..ctor(attacker.GetEyePoint(), attacker.GetLookDir());
				Collider val2 = null;
				float num = float.MaxValue;
				RaycastHit val3 = default(RaycastHit);
				foreach (Collider item in list)
				{
					if (item.Raycast(val, ref val3, 8f) && ((RaycastHit)(ref val3)).distance < num)
					{
						num = ((RaycastHit)(ref val3)).distance;
						val2 = item;
					}
				}
				if ((Object)(object)val2 != (Object)null)
				{
					return val2;
				}
			}
			return list.OrderBy((Collider box) => Vector3.Distance(box.ClosestPoint(hit.m_point), hit.m_point)).First();
		}

		public static WeakSpot Spot(Character character)
		{
			if (character.m_weakSpots == null)
			{
				return null;
			}
			WeakSpot[] weakSpots = character.m_weakSpots;
			foreach (WeakSpot val in weakSpots)
			{
				if ((Object)(object)val != (Object)null && ((Object)val).name == "DeezNuts")
				{
					return val;
				}
			}
			return null;
		}

		private static bool Add(GameObject body, bool weak)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: 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_0164: 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_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			Transform val = Find(body.transform, "Root");
			Transform val2 = Find(body.transform, "LeftUpLeg");
			Transform val3 = Find(body.transform, "RightUpLeg");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
			{
				NutsPlugin.Log.LogWarning((object)("deez nuts: " + ((Object)body).name + " has no bones Root, LeftUpLeg and RightUpLeg"));
				return false;
			}
			if ((Object)(object)val.Find("DeezNuts") != (Object)null)
			{
				return false;
			}
			GameObject val4 = new GameObject("DeezNuts")
			{
				layer = LayerMask.NameToLayer("character_noenv")
			};
			Transform transform = val4.transform;
			transform.SetParent(val, false);
			Transform transform2 = body.transform;
			transform.position = (val2.position + val3.position) * 0.5f + transform2.rotation * Place;
			transform.rotation = transform2.rotation;
			Swing swing = val4.AddComponent<Swing>();
			swing.unit = 1f / val.lossyScale.x;
			transform.localScale = Vector3.one * swing.unit * Settings.Size;
			Mesh val5 = MeshFor(Settings.Hairiness);
			GameObject val6 = new GameObject("model")
			{
				layer = val4.layer
			};
			val6.transform.SetParent(transform, false);
			swing.filter = val6.AddComponent<MeshFilter>();
			swing.filter.sharedMesh = val5;
			MeshRenderer val7 = val6.AddComponent<MeshRenderer>();
			SkinnedMeshRenderer[] componentsInChildren = body.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			SkinnedMeshRenderer val8 = ((IEnumerable<SkinnedMeshRenderer>)componentsInChildren).FirstOrDefault((Func<SkinnedMeshRenderer, bool>)((SkinnedMeshRenderer s) => ((Object)s).name == "Body")) ?? componentsInChildren.FirstOrDefault();
			if ((Object)(object)val8 != (Object)null)
			{
				((Renderer)val7).sharedMaterials = Swing.Materials(((Renderer)val8).sharedMaterial, val5.subMeshCount);
			}
			swing.model = val6.transform;
			swing.skin = val8;
			if (weak)
			{
				SphereCollider val9 = val4.AddComponent<SphereCollider>();
				Bounds bounds = val5.bounds;
				val9.center = ((Bounds)(ref bounds)).center;
				swing.ball = val9;
				bounds = val5.bounds;
				swing.middle = ((Bounds)(ref bounds)).center;
				bounds = val5.bounds;
				Vector3 extents = ((Bounds)(ref bounds)).extents;
				val9.radius = ((Vector3)(ref extents)).magnitude * 0.6f;
				AddHitboxes(body, val9);
				WeakSpot val10 = val4.AddComponent<WeakSpot>();
				val10.m_damageModifiers = default(DamageModifiers);
				Character component = body.GetComponent<Character>();
				component.m_weakSpots = ((IEnumerable<WeakSpot>)(((object)component.m_weakSpots) ?? ((object)new WeakSpot[0]))).Concat((IEnumerable<WeakSpot>)(object)new WeakSpot[1] { val10 }).ToArray();
			}
			return true;
		}

		private static Transform Find(Transform under, string name)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			if (((Object)under).name == name)
			{
				return under;
			}
			foreach (Transform item in under)
			{
				Transform val = Find(item, name);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}
	}
	public static class Settings
	{
		private const string FileName = "vladasz.deeznuts.cfg";

		private static ConfigEntry<float> size;

		private static ConfigEntry<float> damage;

		private static ConfigEntry<float> growth;

		private static ConfigEntry<float> hair;

		private static bool fromServer;

		private static float serverSize;

		private static float serverDamage;

		private static float serverGrowth;

		private static float serverHair;

		public static float Size => Mathf.Clamp(fromServer ? serverSize : size.Value, 0.25f, 4f);

		public static float Damage => Mathf.Clamp(fromServer ? serverDamage : damage.Value, 1f, 100f);

		public static float Growth => Mathf.Clamp(fromServer ? serverGrowth : growth.Value, 0f, 2f);

		public static float Hairiness => Mathf.Clamp01(fromServer ? serverHair : hair.Value);

		public static void Load()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "vladasz.deeznuts.cfg"), true);
			size = val.Bind<float>("Nuts", "Size", 1f, "How big the sack is. 1 is its normal size, from 0.25 to 4.");
			damage = val.Bind<float>("Nuts", "DamageMultiplier", 12f, "How many times the damage of the weapon a hit on the sack does, from 1 to 100. At 12 a bronze sword takes 70 percent of the health of a troll with no star.");
			growth = val.Bind<float>("Nuts", "GrowthPerStar", 0.25f, "How much bigger the sack of a troll with stars is, per star. 0.25 is a quarter bigger, from 0 to 2.");
			hair = val.Bind<float>("Nuts", "Hairiness", 0.5f, "How hairy the sack is, from 0 to 1. 0 is bare, 1 is 200 hairs.");
			fromServer = false;
		}

		public static float SizeAt(int level)
		{
			return Size * (1f + Growth * (float)Mathf.Max(0, level - 1));
		}

		public static void FromServer(float sizeThere, float damageThere, float growthThere, float hairThere)
		{
			fromServer = true;
			serverSize = sizeThere;
			serverDamage = damageThere;
			serverGrowth = growthThere;
			serverHair = hairThere;
			NutsPlugin.Log.LogInfo((object)$"deez nuts settings from the server: size {Size}, damage multiplier {Damage}, growth per star {Growth}, hairiness {Hairiness}");
		}

		public static void Forget()
		{
			fromServer = false;
		}
	}
	[BepInPlugin("vladasz.deeznuts", "Deez Nuts", "0.1.1")]
	public class DeezNutsPlugin : BaseUnityPlugin
	{
		public const string Id = "vladasz.deeznuts";

		public const string Number = "0.1.1";

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			string location = ((BaseUnityPlugin)this).Info.Location;
			HotHost host = new HotHost(((BaseUnityPlugin)this).Logger, new Harmony("vladasz.deeznuts"), Path.GetDirectoryName(location), "0.1.1-" + Fingerprint(location));
			new NutsModule().Load(host);
		}

		private static string Fingerprint(string dll)
		{
			try
			{
				using SHA256 sHA = SHA256.Create();
				return BitConverter.ToString(sHA.ComputeHash(File.ReadAllBytes(dll)), 0, 4).Replace("-", "").ToLowerInvariant();
			}
			catch (Exception)
			{
				return "unknown";
			}
		}
	}
	public class Swing : MonoBehaviour
	{
		private class Fit
		{
			public CapsuleCollider capsule;

			public Vector3 center;

			public float height;

			public float radius;
		}

		public Transform model;

		public MeshFilter filter;

		public SphereCollider ball;

		public Vector3 middle;

		public SkinnedMeshRenderer skin;

		public float unit = 1f;

		private const float Length = 0.6f;

		private const float Stiffness = 45f;

		private const float Damping = 5f;

		private const float MaxLean = 0.8f;

		private const float SquashStiffness = 120f;

		private const float SquashDamping = 7f;

		private const float SquashGain = 0.012f;

		private const float MaxSquash = 0.35f;

		private Character character;

		private ZNetView view;

		private MeshRenderer looks;

		private Vector3 last;

		private Vector3 lastVelocity;

		private Vector3 offset;

		private Vector3 speed;

		private float squash;

		private float squashSpeed;

		private readonly List<Fit> fits = new List<Fit>();

		private void Start()
		{
			//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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			character = ((Component)this).GetComponentInParent<Character>();
			view = ((Component)this).GetComponentInParent<ZNetView>();
			looks = (((Object)(object)model != (Object)null) ? ((Component)model).GetComponent<MeshRenderer>() : null);
			last = ((Component)this).transform.position;
			if (!((Object)(object)character != (Object)null))
			{
				return;
			}
			CapsuleCollider[] componentsInChildren = ((Component)character).GetComponentsInChildren<CapsuleCollider>(true);
			foreach (CapsuleCollider val in componentsInChildren)
			{
				if (((Object)val).name == "DeezNutsBody" || ((Object)val).name == "Attack collider")
				{
					fits.Add(new Fit
					{
						capsule = val,
						center = val.center,
						height = val.height,
						radius = val.radius
					});
				}
			}
		}

		private void OnDestroy()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			foreach (Fit fit in fits)
			{
				if ((Object)(object)fit.capsule != (Object)null)
				{
					fit.capsule.center = fit.center;
					fit.capsule.height = fit.height;
					fit.capsule.radius = fit.radius;
				}
			}
		}

		public void Kick(Vector3 push)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			speed += push;
			squashSpeed -= ((Vector3)(ref push)).magnitude * 4f;
		}

		private void LateUpdate()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: 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_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: 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_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: 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)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Min(Time.deltaTime, 0.05f);
			if ((Object)(object)model == (Object)null || num <= 0f)
			{
				return;
			}
			Resize();
			Paint();
			Mesh val = Sacks.MeshFor(Settings.Hairiness);
			if ((Object)(object)filter != (Object)null && (Object)(object)filter.sharedMesh != (Object)(object)val)
			{
				filter.sharedMesh = val;
			}
			Vector3 position = ((Component)this).transform.position;
			Vector3 val2 = (position - last) / num;
			last = position;
			Vector3 val3 = (val2 - lastVelocity) / num;
			lastVelocity = val2;
			float num2 = 0.6f * ((Component)this).transform.lossyScale.x;
			Vector3 val4 = default(Vector3);
			((Vector3)(ref val4))..ctor(val3.x, 0f, val3.z);
			speed += (-val4 - 45f * offset - 5f * speed) * num;
			offset = Vector3.ClampMagnitude(offset + speed * num, 0.8f * num2);
			squashSpeed += (-120f * squash - 7f * squashSpeed - val3.y * 0.012f) * num;
			squash = Mathf.Clamp(squash + squashSpeed * num, -0.35f, 0.35f);
			Quaternion val5;
			if (!((Object)(object)character != (Object)null))
			{
				Quaternion rotation = ((Component)this).transform.rotation;
				val5 = Quaternion.Euler(0f, ((Quaternion)(ref rotation)).eulerAngles.y, 0f);
			}
			else
			{
				val5 = ((Component)character).transform.rotation;
			}
			Quaternion val6 = val5;
			Vector3 val7 = Vector3.down * num2 + offset;
			Vector3 normalized = ((Vector3)(ref val7)).normalized;
			model.rotation = Quaternion.FromToRotation(Vector3.down, normalized) * val6;
			float num3 = 1f / Mathf.Sqrt(1f + squash);
			model.localScale = new Vector3(num3, 1f + squash, num3);
			if ((Object)(object)ball != (Object)null)
			{
				ball.center = ((Component)this).transform.InverseTransformPoint(model.TransformPoint(middle));
			}
			if (!((Object)(object)ball != (Object)null))
			{
				return;
			}
			float num4 = ((Component)this).transform.TransformPoint(ball.center).y + ball.radius * ((Component)this).transform.lossyScale.x;
			foreach (Fit fit in fits)
			{
				FitOver(fit, num4 + 0.1f);
			}
		}

		private static void FitOver(Fit fit, float floor)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			CapsuleCollider capsule = fit.capsule;
			if ((Object)(object)capsule == (Object)null)
			{
				return;
			}
			Transform transform = ((Component)capsule).transform;
			float x = transform.lossyScale.x;
			Vector3 up = transform.up;
			if (!(up.y < 0.01f))
			{
				float num = fit.radius * x;
				float num2 = Mathf.Max(fit.height * x - 2f * num, 0f);
				Vector3 val = transform.TransformPoint(fit.center) + up * (num2 / 2f + num);
				float num3 = Mathf.Clamp((val.y - floor - num) / up.y - num, 0f, num2);
				if (num3 <= 0f)
				{
					num = Mathf.Clamp((val.y - floor) / (1f + up.y), 0.05f, num);
				}
				float num4 = (num3 + 2f * num) / x;
				if (!(Mathf.Abs(capsule.height - num4) < 0.001f) || !(Mathf.Abs(capsule.radius - num / x) < 0.001f))
				{
					capsule.center = transform.InverseTransformPoint(val - up * (num4 * x / 2f));
					capsule.height = num4;
					capsule.radius = num / x;
				}
			}
		}

		private void Resize()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			int level = 1;
			if ((Object)(object)character != (Object)null)
			{
				level = character.GetLevel();
			}
			else if ((Object)(object)view != (Object)null && view.IsValid())
			{
				level = view.GetZDO().GetInt(ZDOVars.s_level, 1);
			}
			float num = unit * Settings.SizeAt(level);
			if (!Mathf.Approximately(((Component)this).transform.localScale.x, num))
			{
				((Component)this).transform.localScale = Vector3.one * num;
			}
		}

		private void Paint()
		{
			if ((Object)(object)looks != (Object)null && (Object)(object)skin != (Object)null && (Object)(object)((Renderer)looks).sharedMaterial != (Object)(object)((Renderer)skin).sharedMaterial)
			{
				((Renderer)looks).sharedMaterials = Materials(((Renderer)skin).sharedMaterial, ((Renderer)looks).sharedMaterials.Length);
			}
		}

		public static Material[] Materials(Material troll, int parts)
		{
			Material[] array = (Material[])(object)new Material[parts];
			for (int i = 0; i < parts; i++)
			{
				array[i] = troll;
			}
			return array;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}