Decompiled source of FatEnemies v2.0.1

FatEnemies.dll

Decompiled 13 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("FatEnemies")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FatEnemies")]
[assembly: AssemblyTitle("FatEnemies")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 FatEnemies
{
	internal class Profile
	{
		public float Belly = 2.2f;

		public float Arms = 1.8f;

		public float Legs = 1.8f;

		public float Head = 1f;

		public float Width = 1.4f;

		public float Height = 0.9f;

		public float Speed = 0.6f;

		public float Anim = 0.6f;

		public Profile Clone()
		{
			return (Profile)MemberwiseClone();
		}

		private static string F(float v)
		{
			return v.ToString("R", CultureInfo.InvariantCulture);
		}

		public string Serialize()
		{
			return string.Join("|", F(Belly), F(Arms), F(Legs), F(Head), F(Width), F(Height), F(Speed), F(Anim));
		}

		public static Profile Parse(string[] f, int start)
		{
			Profile profile = new Profile();
			profile.Belly = G(start, profile.Belly);
			profile.Arms = G(start + 1, profile.Arms);
			profile.Legs = G(start + 2, profile.Legs);
			profile.Head = G(start + 3, profile.Head);
			profile.Width = G(start + 4, profile.Width);
			profile.Height = G(start + 5, profile.Height);
			profile.Speed = G(start + 6, profile.Speed);
			profile.Anim = G(start + 7, profile.Anim);
			return profile;
			float G(int i, float d)
			{
				if (i >= f.Length || !float.TryParse(f[i], NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
				{
					return d;
				}
				return result;
			}
		}
	}
	[BepInPlugin("com.example.fatenemies", "Fat Enemies", "2.0.1")]
	public class FatEnemiesPlugin : BaseUnityPlugin
	{
		public const string Guid = "com.example.fatenemies";

		private const string AllKey = "* All enemies (default)";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> AffectTamed;

		internal static ConfigEntry<bool> AffectBosses;

		private static ConfigEntry<float> _belly;

		private static ConfigEntry<float> _arms;

		private static ConfigEntry<float> _legs;

		private static ConfigEntry<float> _head;

		private static ConfigEntry<float> _width;

		private static ConfigEntry<float> _height;

		private static ConfigEntry<float> _speed;

		private static ConfigEntry<float> _anim;

		internal static Profile Default = new Profile();

		internal static readonly Dictionary<string, Profile> Overrides = new Dictionary<string, Profile>();

		internal static readonly HashSet<string> Seen = new HashSet<string>();

		private static string _overridesPath;

		private bool _open;

		private bool _dirty;

		private bool _menuApiBroken;

		private Rect _window = new Rect(20f, 80f, 640f, 620f);

		private Vector2 _listScroll;

		private Vector2 _sliderScroll;

		private string _selected = "* All enemies (default)";

		private string _filter = "";

		private List<string> _names;

		private bool _prefabWarned;

		internal static Profile GetProfile(string name)
		{
			if (!Overrides.TryGetValue(name, out var value))
			{
				return Default;
			}
			return value;
		}

		private void Awake()
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Expected O, but got Unknown
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Expected O, but got Unknown
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Expected O, but got Unknown
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Expected O, but got Unknown
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Expected O, but got Unknown
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Turn the mod on or off.");
			AffectTamed = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AffectTamed", false, "Also change tamed creatures.");
			AffectBosses = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AffectBosses", true, "Also change bosses.");
			Profile profile = new Profile();
			_belly = ((BaseUnityPlugin)this).Config.Bind<float>("Default", "BellySize", profile.Belly, new ConfigDescription("Torso inflation. 1 = normal.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 4f), Array.Empty<object>()));
			_arms = ((BaseUnityPlugin)this).Config.Bind<float>("Default", "ArmSize", profile.Arms, new ConfigDescription("Arm thickness (across the arm, not its length). 1 = normal.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 4f), Array.Empty<object>()));
			_legs = ((BaseUnityPlugin)this).Config.Bind<float>("Default", "LegSize", profile.Legs, new ConfigDescription("Leg thickness (across the leg, not its length). 1 = normal.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 4f), Array.Empty<object>()));
			_head = ((BaseUnityPlugin)this).Config.Bind<float>("Default", "HeadSize", profile.Head, new ConfigDescription("Head size. 1 = normal.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.3f, 3f), Array.Empty<object>()));
			_width = ((BaseUnityPlugin)this).Config.Bind<float>("Default", "BodyWidth", profile.Width, new ConfigDescription("Whole-body sideways and front-to-back stretch. 1 = none.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 3f), Array.Empty<object>()));
			_height = ((BaseUnityPlugin)this).Config.Bind<float>("Default", "BodyHeight", profile.Height, new ConfigDescription("Whole-body height multiplier.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 2f), Array.Empty<object>()));
			_speed = ((BaseUnityPlugin)this).Config.Bind<float>("Default", "SpeedMultiplier", profile.Speed, new ConfigDescription("Movement speed multiplier. 1 = vanilla.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 2f), Array.Empty<object>()));
			_anim = ((BaseUnityPlugin)this).Config.Bind<float>("Default", "AnimationSpeedMultiplier", profile.Anim, new ConfigDescription("Animation speed multiplier (also slows attack wind-ups). 1 = vanilla.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 2f), Array.Empty<object>()));
			Default = new Profile
			{
				Belly = _belly.Value,
				Arms = _arms.Value,
				Legs = _legs.Value,
				Head = _head.Value,
				Width = _width.Value,
				Height = _height.Value,
				Speed = _speed.Value,
				Anim = _anim.Value
			};
			_overridesPath = Path.Combine(Paths.ConfigPath, "com.example.fatenemies.creatures.txt");
			LoadOverrides();
			new Harmony("com.example.fatenemies").PatchAll();
		}

		private static void LoadOverrides()
		{
			try
			{
				if (!File.Exists(_overridesPath))
				{
					return;
				}
				string[] array = File.ReadAllLines(_overridesPath);
				foreach (string text in array)
				{
					if (!text.StartsWith("#"))
					{
						string[] array2 = text.Split(new char[1] { '|' });
						if (array2.Length >= 2)
						{
							Overrides[array2[0]] = Profile.Parse(array2, 1);
						}
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Could not read creature overrides: " + ex.Message));
			}
		}

		private void SaveAll()
		{
			try
			{
				_belly.Value = Default.Belly;
				_arms.Value = Default.Arms;
				_legs.Value = Default.Legs;
				_head.Value = Default.Head;
				_width.Value = Default.Width;
				_height.Value = Default.Height;
				_speed.Value = Default.Speed;
				_anim.Value = Default.Anim;
				((BaseUnityPlugin)this).Config.Save();
				List<string> list = new List<string> { "# name|belly|arms|legs|head|width|height|speed|anim (written by the in-game panel)" };
				foreach (KeyValuePair<string, Profile> @override in Overrides)
				{
					list.Add(@override.Key + "|" + @override.Value.Serialize());
				}
				File.WriteAllLines(_overridesPath, list.ToArray());
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Could not save settings: " + ex.Message));
			}
			_dirty = false;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static bool PauseMenuVisible()
		{
			return Menu.IsVisible();
		}

		private bool InPauseMenu()
		{
			if (_menuApiBroken)
			{
				return false;
			}
			try
			{
				return PauseMenuVisible();
			}
			catch (Exception ex)
			{
				_menuApiBroken = true;
				Log.LogWarning((object)("Menu.IsVisible unavailable (" + ex.GetType().Name + "); press F8 to open the panel instead."));
				return false;
			}
		}

		private void Update()
		{
			try
			{
				if (_menuApiBroken && Input.GetKeyDown((KeyCode)289))
				{
					_open = !_open;
				}
			}
			catch
			{
			}
		}

		private void RefreshNames()
		{
			HashSet<string> hashSet = new HashSet<string>(Seen);
			try
			{
				CollectPrefabNames(hashSet);
			}
			catch (Exception ex)
			{
				if (!_prefabWarned)
				{
					_prefabWarned = true;
					Log.LogWarning((object)("Could not list spawnable creatures (" + ex.GetType().Name + "); showing creatures seen so far."));
				}
			}
			_names = new List<string>(hashSet);
			_names.Sort(StringComparer.OrdinalIgnoreCase);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void CollectPrefabNames(HashSet<string> set)
		{
			Type type = AccessTools.TypeByName("ZNetScene");
			if (type == null)
			{
				return;
			}
			object obj = AccessTools.Property(type, "instance")?.GetValue(null, null) ?? AccessTools.Field(type, "instance")?.GetValue(null);
			if (obj == null || !((AccessTools.Field(type, "m_prefabs")?.GetValue(obj) ?? AccessTools.Property(type, "m_prefabs")?.GetValue(obj, null)) is IEnumerable enumerable))
			{
				return;
			}
			foreach (object item in enumerable)
			{
				GameObject val = (GameObject)((item is GameObject) ? item : null);
				if ((Object)(object)val != (Object)null && ((Object)val).name != "Player" && (Object)(object)val.GetComponent<Character>() != (Object)null)
				{
					set.Add(((Object)val).name);
				}
			}
		}

		private void OnGUI()
		{
			//IL_004f: 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)
			//IL_0060: 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_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Invalid comparison between Unknown and I4
			//IL_012e: 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_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			bool flag = InPauseMenu();
			if (!flag && (!_menuApiBroken || !_open))
			{
				if (_open)
				{
					_open = false;
					if (_dirty)
					{
						SaveAll();
					}
				}
				return;
			}
			float num = Mathf.Max(1f, (float)Screen.height / 1080f);
			Matrix4x4 matrix = GUI.matrix;
			GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
			float num2 = (float)Screen.height / num;
			if (_menuApiBroken)
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
			if (flag && GUI.Button(new Rect(20f, num2 - 60f, 190f, 40f), _open ? "Close Fat Enemies" : "Fat Enemies"))
			{
				_open = !_open;
				if (_open && _names == null)
				{
					RefreshNames();
				}
				if (!_open && _dirty)
				{
					SaveAll();
				}
			}
			if (_open)
			{
				if (_names == null)
				{
					RefreshNames();
				}
				((Rect)(ref _window)).height = Mathf.Min(620f, num2 - 120f);
				GUI.Box(_window, GUIContent.none);
				GUI.Box(_window, GUIContent.none);
				_window = GUI.Window(4007, _window, new WindowFunction(DrawWindow), "Fat Enemies");
			}
			if ((int)Event.current.type == 1 && _dirty)
			{
				SaveAll();
			}
			GUI.matrix = matrix;
		}

		private void DrawWindow(int id)
		{
			//IL_0049: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: 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_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(220f) });
			GUILayout.Label("Search", Array.Empty<GUILayoutOption>());
			_filter = GUILayout.TextField(_filter, Array.Empty<GUILayoutOption>());
			_listScroll = GUILayout.BeginScrollView(_listScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(((Rect)(ref _window)).height - 120f) });
			if (GUILayout.Toggle(_selected == "* All enemies (default)", "* All enemies (default)", GUIStyle.op_Implicit("Button"), Array.Empty<GUILayoutOption>()))
			{
				_selected = "* All enemies (default)";
			}
			foreach (string name in _names)
			{
				if (_filter.Length <= 0 || name.IndexOf(_filter, StringComparison.OrdinalIgnoreCase) >= 0)
				{
					string text = (Overrides.ContainsKey(name) ? "★ " : "") + name;
					if (GUILayout.Toggle(_selected == name, text, GUIStyle.op_Implicit("Button"), Array.Empty<GUILayoutOption>()))
					{
						_selected = name;
					}
				}
			}
			GUILayout.EndScrollView();
			if (GUILayout.Button("Refresh list", Array.Empty<GUILayoutOption>()))
			{
				RefreshNames();
			}
			GUILayout.EndVertical();
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			bool flag = _selected == "* All enemies (default)";
			bool flag2 = !flag && Overrides.ContainsKey(_selected);
			GUILayout.Label(flag ? "Editing: all enemies without their own settings" : ("Editing: " + _selected + (flag2 ? "  (custom)" : "  (default until you move a slider)")), Array.Empty<GUILayoutOption>());
			Profile profile = (flag ? Default : (flag2 ? Overrides[_selected] : Default.Clone()));
			string text2 = profile.Serialize();
			bool flag3 = GUILayout.Toggle(Enabled.Value, " Mod enabled", Array.Empty<GUILayoutOption>());
			if (flag3 != Enabled.Value)
			{
				Enabled.Value = flag3;
				_dirty = true;
			}
			_sliderScroll = GUILayout.BeginScrollView(_sliderScroll, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Body parts", Array.Empty<GUILayoutOption>());
			profile.Belly = Slider("Belly", profile.Belly, 1f, 4f);
			profile.Arms = Slider("Arms", profile.Arms, 0.5f, 4f);
			profile.Legs = Slider("Legs", profile.Legs, 0.5f, 4f);
			profile.Head = Slider("Head", profile.Head, 0.3f, 3f);
			GUILayout.Space(6f);
			GUILayout.Label("Whole body", Array.Empty<GUILayoutOption>());
			profile.Width = Slider("Width", profile.Width, 0.5f, 3f);
			profile.Height = Slider("Height", profile.Height, 0.5f, 2f);
			GUILayout.Space(6f);
			GUILayout.Label("Movement", Array.Empty<GUILayoutOption>());
			profile.Speed = Slider("Move speed", profile.Speed, 0.1f, 2f);
			profile.Anim = Slider("Animation speed", profile.Anim, 0.1f, 2f);
			GUILayout.EndScrollView();
			if (profile.Serialize() != text2)
			{
				if (!flag)
				{
					Overrides[_selected] = profile;
				}
				_dirty = true;
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button(flag ? "Reset defaults" : "Reset to default", Array.Empty<GUILayoutOption>()))
			{
				if (flag)
				{
					Default = new Profile();
				}
				else
				{
					Overrides.Remove(_selected);
				}
				_dirty = true;
			}
			if (GUILayout.Button("Save", Array.Empty<GUILayoutOption>()))
			{
				SaveAll();
			}
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 22f));
		}

		private static float Slider(string label, float value, float min, float max)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
			value = GUILayout.HorizontalSlider(value, min, max, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
			GUILayout.Label(value.ToString("0.00"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(44f) });
			GUILayout.EndHorizontal();
			return Mathf.Round(value * 100f) / 100f;
		}

		private void OnDestroy()
		{
			if (_dirty)
			{
				SaveAll();
			}
		}
	}
	internal class FatMarker : MonoBehaviour
	{
		private class Part
		{
			public Transform Bone;

			public Vector3 Base;

			public int Axis = -1;

			public bool Counter;

			public bool IsHead;

			public bool IsArm;

			public bool IsLeg;
		}

		private static readonly HashSet<string> Reported = new HashSet<string>();

		private string _label;

		private Character _char;

		private Animator _animator;

		private float _lastAnimSet = -1f;

		private float _lastAnimFactor = 1f;

		private float _speedApplied = 1f;

		private Vector3 _rootBase;

		private Vector3 _rootSet;

		private bool _rigSearched;

		private Transform _belly;

		private Vector3 _bellyBase;

		private readonly List<Part> _parts = new List<Part>();

		private static bool _speedBroken;

		private void Awake()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			_label = ((Object)((Component)this).gameObject).name.Replace("(Clone)", "");
			FatEnemiesPlugin.Seen.Add(_label);
			_char = ((Component)this).GetComponent<Character>();
			_animator = ((Component)this).GetComponentInChildren<Animator>();
			_rootBase = (_rootSet = ((Component)this).transform.localScale);
		}

		private void LateUpdate()
		{
			Profile p = (FatEnemiesPlugin.Enabled.Value ? FatEnemiesPlugin.GetProfile(_label) : null);
			UpdateRoot(p);
			if (!_speedBroken)
			{
				try
				{
					UpdateSpeed(p);
				}
				catch (Exception ex)
				{
					_speedBroken = true;
					FatEnemiesPlugin.Log.LogWarning((object)("Speed control disabled (" + ex.GetType().Name + "): " + ex.Message));
				}
			}
			UpdateAnimation(p);
			UpdateBones(p);
		}

		private void UpdateRoot(Profile p)
		{
			//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_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_0045: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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)
			//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_0064: Unknown result type (might be due to invalid IL or missing references)
			if (((Component)this).transform.localScale != _rootSet)
			{
				_rootBase = ((Component)this).transform.localScale;
			}
			Vector3 val = (Vector3)((p == null) ? Vector3.one : new Vector3(p.Width, p.Height, p.Width));
			_rootSet = Vector3.Scale(_rootBase, val);
			((Component)this).transform.localScale = _rootSet;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void UpdateSpeed(Profile p)
		{
			if (!((Object)(object)_char == (Object)null))
			{
				float num = p?.Speed ?? 1f;
				if (!Mathf.Approximately(num, _speedApplied))
				{
					float num2 = num / _speedApplied;
					Character obj = _char;
					obj.m_walkSpeed *= num2;
					Character obj2 = _char;
					obj2.m_runSpeed *= num2;
					Character obj3 = _char;
					obj3.m_swimSpeed *= num2;
					Character obj4 = _char;
					obj4.m_flySlowSpeed *= num2;
					Character obj5 = _char;
					obj5.m_flyFastSpeed *= num2;
					_speedApplied = num;
				}
			}
		}

		private void UpdateAnimation(Profile p)
		{
			if (!((Object)(object)_animator == (Object)null))
			{
				float num = p?.Anim ?? 1f;
				float speed = _animator.speed;
				float num2 = (Mathf.Approximately(speed, _lastAnimSet) ? (speed / Mathf.Max(_lastAnimFactor, 0.0001f)) : speed);
				_lastAnimFactor = num;
				_lastAnimSet = num2 * num;
				_animator.speed = _lastAnimSet;
			}
		}

		private void UpdateBones(Profile p)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_00d0: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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_00ff: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			if (!_rigSearched)
			{
				FindRig();
			}
			if ((Object)(object)_belly == (Object)null)
			{
				return;
			}
			float num = p?.Belly ?? 1f;
			_belly.localScale = _bellyBase * num;
			Vector3 val2 = default(Vector3);
			foreach (Part part in _parts)
			{
				if ((Object)(object)part.Bone == (Object)null)
				{
					continue;
				}
				Vector3 val = part.Base;
				if (part.IsArm || part.IsLeg)
				{
					float num2 = ((p == null) ? 1f : (part.IsArm ? p.Arms : p.Legs));
					((Vector3)(ref val2))..ctor(num2, num2, num2);
					if (part.Axis >= 0)
					{
						((Vector3)(ref val2))[part.Axis] = 1f;
					}
					val = Vector3.Scale(val, val2);
				}
				if (part.IsHead && p != null)
				{
					val *= p.Head;
				}
				part.Bone.localScale = (part.Counter ? (val / num) : val);
			}
		}

		private static bool NameHas(Transform t, string s)
		{
			return ((Object)t).name.IndexOf(s, StringComparison.OrdinalIgnoreCase) >= 0;
		}

		private static int Depth(Transform t)
		{
			int num = 0;
			while ((Object)(object)t.parent != (Object)null)
			{
				t = t.parent;
				num++;
			}
			return num;
		}

		private Transform Shallowest(Transform[] all, params string[] names)
		{
			Transform result = null;
			int num = int.MaxValue;
			foreach (Transform val in all)
			{
				if ((Object)(object)val == (Object)(object)((Component)this).transform)
				{
					continue;
				}
				foreach (string s in names)
				{
					if (NameHas(val, s))
					{
						int num2 = Depth(val);
						if (num2 < num)
						{
							result = val;
							num = num2;
						}
						break;
					}
				}
			}
			return result;
		}

		private static bool IsLimbName(Transform t)
		{
			if (NameHas(t, "armature") || NameHas(t, "armor") || NameHas(t, "harm"))
			{
				return false;
			}
			if (!NameHas(t, "arm") && !NameHas(t, "leg"))
			{
				return NameHas(t, "thigh");
			}
			return true;
		}

		private static bool HasLimbAncestor(Transform t)
		{
			Transform parent = t.parent;
			while ((Object)(object)parent != (Object)null)
			{
				if (IsLimbName(parent))
				{
					return true;
				}
				parent = parent.parent;
			}
			return false;
		}

		private static int LongAxis(Transform bone)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			Transform val = null;
			float num = 0f;
			foreach (Transform item in bone)
			{
				Transform val2 = item;
				Vector3 localPosition = val2.localPosition;
				float sqrMagnitude = ((Vector3)(ref localPosition)).sqrMagnitude;
				if (sqrMagnitude > num)
				{
					num = sqrMagnitude;
					val = val2;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return -1;
			}
			Vector3 localPosition2 = val.localPosition;
			float num2 = Mathf.Abs(localPosition2.x);
			float num3 = Mathf.Abs(localPosition2.y);
			float num4 = Mathf.Abs(localPosition2.z);
			if (!(num2 >= num3) || !(num2 >= num4))
			{
				if (!(num3 >= num4))
				{
					return 2;
				}
				return 1;
			}
			return 0;
		}

		private static void Collect(Transform t, HashSet<Transform> chain)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			chain.Add(t);
			foreach (Transform item in t)
			{
				Transform t2 = item;
				if (NameHas(t2, "spine"))
				{
					Collect(t2, chain);
				}
			}
		}

		private void FindRig()
		{
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			_rigSearched = true;
			Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
			Transform val = Shallowest(componentsInChildren, "spine") ?? Shallowest(componentsInChildren, "hips", "pelvis");
			if ((Object)(object)val == (Object)null)
			{
				if (Reported.Add(_label))
				{
					FatEnemiesPlugin.Log.LogWarning((object)(_label + ": no spine/hips bone found, body effects skipped"));
				}
				return;
			}
			HashSet<Transform> hashSet = new HashSet<Transform>();
			Collect(val, hashSet);
			Dictionary<Transform, Part> dictionary = new Dictionary<Transform, Part>();
			foreach (Transform item2 in hashSet)
			{
				foreach (Transform item3 in item2)
				{
					Transform val2 = item3;
					if (!hashSet.Contains(val2))
					{
						Part item = (dictionary[val2] = new Part
						{
							Bone = val2,
							Base = val2.localScale,
							Counter = true,
							IsHead = (NameHas(val2, "neck") || NameHas(val2, "head"))
						});
						_parts.Add(item);
					}
				}
			}
			Transform[] array = componentsInChildren;
			foreach (Transform val3 in array)
			{
				if (!((Object)(object)val3 == (Object)(object)((Component)this).transform) && IsLimbName(val3) && !HasLimbAncestor(val3))
				{
					if (!dictionary.TryGetValue(val3, out var value))
					{
						value = new Part
						{
							Bone = val3,
							Base = val3.localScale
						};
						_parts.Add(value);
					}
					value.Axis = LongAxis(val3);
					bool flag = (value.IsLeg = NameHas(val3, "leg") || NameHas(val3, "thigh"));
					value.IsArm = !flag;
				}
			}
			_belly = val;
			_bellyBase = val.localScale;
			if (!Reported.Add(_label))
			{
				return;
			}
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			foreach (Part part2 in _parts)
			{
				if (part2.IsArm)
				{
					num++;
				}
				if (part2.IsLeg)
				{
					num2++;
				}
				if (part2.IsHead)
				{
					num3++;
				}
			}
			FatEnemiesPlugin.Log.LogInfo((object)(_label + ": belly bone '" + ((Object)val).name + "', " + num + " arm(s), " + num2 + " leg(s), " + num3 + " head/neck"));
		}
	}
	internal static class Fatten
	{
		public static void Attach(Character c)
		{
			if (!((Object)(object)c == (Object)null) && !c.IsPlayer() && (FatEnemiesPlugin.AffectTamed.Value || !c.IsTamed()) && (FatEnemiesPlugin.AffectBosses.Value || !c.IsBoss()) && (Object)(object)((Component)c).GetComponent<FatMarker>() == (Object)null)
			{
				((Component)c).gameObject.AddComponent<FatMarker>();
			}
		}
	}
	[HarmonyPatch(typeof(Character), "Awake")]
	internal static class CharacterAwakePatch
	{
		private static void Postfix(Character __instance)
		{
			Fatten.Attach(__instance);
		}
	}
}