Decompiled source of MountUpRestored v3.4.1

MountUpRestored.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using AllTameable;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using LocalizationManager;
using Microsoft.CodeAnalysis;
using MountUp;
using MountUp.ModCompat;
using RRRCore;
using UnityEngine;
using UnityEngine.UI;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.BufferedDeserialization;
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
using YamlDotNet.Serialization.Callbacks;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;

[assembly: AssemblyCompany("Microsoft")]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MountUp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2021")]
[assembly: AssemblyProduct("MountUp")]
[assembly: ComVisible(false)]
[assembly: Guid("9e1c6dc2-1a11-4768-96f1-0f71c70e1dbe")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyTrademark("")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("meldurson.MountUpRestored", "Mount Up Restored", "3.4.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Setup : BaseUnityPlugin
{
	private const string ModGUID = "meldurson.MountUpRestored";

	public static ManualLogSource logger;

	public static GameObject boarSaddlePrefab;

	public static ItemDrop boarSaddleItem;

	public static ItemDrop wolfSaddleItem;

	public static ItemDrop loxSaddleItem;

	public static GameObject wolfSaddlePrefab;

	public static GameObject genericSaddlePrefab;

	public static GameObject[] tieredSaddlePrefabs = (GameObject[])(object)new GameObject[9];

	public static ItemDrop[] tieredSaddleItems = (ItemDrop[])(object)new ItemDrop[9];

	public static bool lateLoad = false;

	public static Vector3 boarMountPos = new Vector3(-0.509f, -0.2195f, 0.0495f);

	public static Vector3 wolfMountPos = new Vector3(-0.327f, -0.127f, 0.023f);

	public static Vector3 boarSaddlePos = new Vector3(0.0189f, -0.283f, 0f);

	public static Vector3 wolfSaddlePos = new Vector3(0.00398f, -0.177f, 0f);

	public static Vector3 boarLocalScale = new Vector3(0.9f, 1f, 1f);

	public static Vector3 wolfLocalScale = new Vector3(0.9f, 1.27f, 1.05f);

	public static Vector3 rotationAdjust = new Vector3(0f, -90f, 180f);

	public static Vector3 posDefault = new Vector3(0f, 0.01f, 0f);

	public static ConfigEntry<bool> canMountPlayer;

	public static ConfigEntry<float> BoarStamina;

	public static ConfigEntry<float> WolfStamina;

	public static ConfigEntry<float> LoxStamina;

	public static ConfigEntry<float> AsksvinStamina;

	public static ConfigEntry<float> FedStaminaMultiplier;

	public static ConfigEntry<bool> adjustCustom;

	public static ConfigEntry<KeyboardShortcut> adjustCustomModeSwitch;

	public static KeyboardShortcut saveMountKeys = new KeyboardShortcut((KeyCode)115, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 });

	public static ButtonConfig adjustCustomModeSwitchButton;

	public static ConfigEntry<bool> teleportMounts;

	public static ConfigEntry<int> customMountCount;

	public static Dictionary<string, int> mountNameDict;

	public static List<ConfigEntry<string>> customMountNames;

	public static List<ConfigEntry<int>> customMountSaddleTiers;

	public static List<ConfigEntry<Vector3>> customMountPoints;

	public static List<ConfigEntry<Vector3>> customSaddlePos;

	public static List<ConfigEntry<Vector3>> customSaddleScale;

	public static List<ConfigEntry<Vector3>> customSaddleRot;

	public static List<ConfigEntry<float>> customMountFlyStamina;

	public static List<ConfigEntry<float>> customStamina;

	public static List<ConfigEntry<string>> customTightMountPaths;

	public static ConfigEntry<Vector3> MountPointAdjustment;

	private static ConfigEntry<KeyboardShortcut> mountModifierKey;

	public static ConfigEntry<bool> useBlockforSecondary;

	public static ConfigEntry<string> saddleNames;

	public static ConfigEntry<bool> canAttackMounted;

	public static ConfigEntry<bool> mountsCanDrown;

	public static GameObject SalObj;

	public static Dictionary<string, Mount> customMounts = new Dictionary<string, Mount>();

	public static Dictionary<string, Mount> removeMounts = new Dictionary<string, Mount>();

	public static List<string> LateLoadMounts = new List<string>();

	public static List<string> AddFullMountToYaml = new List<string>();

	public static List<string> AddJustPathToYaml = new List<string>();

	public static string[] TieredSaddleNames = new string[9];

	public static Dictionary<string, Mount> legacyMounts = new Dictionary<string, Mount>();

	public static Vector3 legacyOffset = new Vector3(0.048f, 0.035f, -0.205f);

	public static Vector3 legacyScale = new Vector3(1.7f, 0.77f, 1f);

	public static bool isWritingYML = false;

	public static bool RecipesMade = false;

	private static string AssetPath = "Assets/Saddles/";

	public static CustomRPC jot_MountlistRPC;

	public static bool MountUpdate = false;

	public GameObject Root;

	internal readonly Harmony _harmony = new Harmony("meldurson.MountUpRestored");

	public static Setup instance = null;

	private void Awake()
	{
		//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_0034: Expected O, but got Unknown
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		//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_0070: Expected O, but got Unknown
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Expected O, but got Unknown
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Expected O, but got Unknown
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Expected O, but got Unknown
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Expected O, but got Unknown
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Expected O, but got Unknown
		//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_0130: Expected O, but got Unknown
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Expected O, but got Unknown
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Expected O, but got Unknown
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Expected O, but got Unknown
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Expected O, but got Unknown
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Expected O, but got Unknown
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Expected O, but got Unknown
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Expected O, but got Unknown
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Expected O, but got Unknown
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Expected O, but got Unknown
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: Expected O, but got Unknown
		//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: Expected O, but got Unknown
		//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e7: Expected O, but got Unknown
		//IL_030f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0314: Unknown result type (might be due to invalid IL or missing references)
		//IL_031d: Expected O, but got Unknown
		//IL_031d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0327: Expected O, but got Unknown
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_04be: Expected O, but got Unknown
		instance = this;
		canMountPlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Can Mount Player", false, new ConfigDescription("Experimental: Can Players be mounted", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		teleportMounts = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Teleport Mounts", true, new ConfigDescription("Allow Mounts to Teleport with their rider", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		BoarStamina = ((BaseUnityPlugin)this).Config.Bind<float>("Stamina", "Boar Stamina", 60f, new ConfigDescription("Mounted Boar Stamina", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		WolfStamina = ((BaseUnityPlugin)this).Config.Bind<float>("Stamina", "Wolf Stamina", 120f, new ConfigDescription("Mounted Wolf Stamina", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		LoxStamina = ((BaseUnityPlugin)this).Config.Bind<float>("Stamina", "Lox Stamina Override", -1f, new ConfigDescription("Override Lox Stamina, set -1 to not modify", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		AsksvinStamina = ((BaseUnityPlugin)this).Config.Bind<float>("Stamina", "Asksvin Stamina Override", -1f, new ConfigDescription("Override Asksvin Stamina, set -1 to not modify", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		FedStaminaMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Stamina", "Stamina Regen Multiplier", 1f, new ConfigDescription("Multiply stamina regen rate when mount is fed", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		MountPointAdjustment = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Micromanagement", "Mount Point Adjustment", Vector3.zero, (ConfigDescription)null);
		mountModifierKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "Player Mount Modifier Key", new KeyboardShortcut((KeyCode)304, Array.Empty<KeyCode>()), "This key plus your interact key will attempt to mount another player");
		adjustCustom = ((BaseUnityPlugin)this).Config.Bind<bool>("Custom Mounts", "Enable Adjust Custom Mounts", false, new ConfigDescription("Enable Controls to adjust custom mount's mount points and saddle position", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		canAttackMounted = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Can Attack Mounted", true, new ConfigDescription("Allow mount to attack using attack keys while mounted", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		mountsCanDrown = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Land Mounts can Drown", true, new ConfigDescription("Do land mounts start to take damage if you run out of stamina when swimming", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		useBlockforSecondary = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Use Block Key to Perform Secondary", true, new ConfigDescription("Determines if while mounted the block key also performs secondary attack", (AcceptableValueBase)null, Array.Empty<object>()));
		saddleNames = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Saddle Names", "Meadows Saddle,Forest Saddle,Swamp Saddle,Mountain Saddle,Plains Saddle,Mistlands Saddle,Ashlands Saddle,Deep North Saddle,", new ConfigDescription("Set the names of the different tiers of Saddle", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		adjustCustomModeSwitch = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Custom Mounts", "Adjust Custom Mount Mode Switch", new KeyboardShortcut((KeyCode)96, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), (ConfigDescription)null);
		logger = ((BaseUnityPlugin)this).Logger;
		UseFileOpenReadTextWithSystemTextYaml();
		Localizer.Load();
		if (Directory.GetFiles(Path.GetDirectoryName(Paths.BepInExConfigPath), "MountUpRestored_CustomMounts*.yml").Count() == 0)
		{
			create_YML();
		}
		WriteMounts();
		logger.LogMessage((object)"Finished loading in custom mounts");
		LoadBuiltInMounts();
		string text = "List of Mounts: ";
		foreach (KeyValuePair<string, Mount> customMount in customMounts)
		{
			text = text + customMount.Key + ", ";
			LateLoadMounts.Add(customMount.Key);
		}
		logger.LogMessage((object)text.TrimEnd(',', ' '));
		Root = ((Component)this).gameObject;
		PrefabManager.OnVanillaPrefabsAvailable += LoadAssets;
		PrefabManager.OnVanillaPrefabsAvailable += CreateSaddles;
		PieceManager.OnPiecesRegistered += SetupMountable;
		lateLoad = true;
		SynchronizationManager.OnConfigurationSynchronized += delegate
		{
			MountUpdate = true;
		};
		jot_MountlistRPC = NetworkManager.Instance.AddRPC("jot_MountlistRPC", (CoroutineHandler)null, new CoroutineHandler(jot_RPCClientReceive));
		SynchronizationManager.Instance.AddInitialSynchronization(jot_MountlistRPC, (Func<ZPackage>)SendInitialConfig);
	}

	public void Start()
	{
		Patches.setup = this;
		Patches.Apply();
	}

	private void LoadAssets()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Expected O, but got Unknown
		AssetBundle val = AssetUtils.LoadAssetBundleFromResources("mountupassets", typeof(Setup).Assembly);
		genericSaddlePrefab = (GameObject)val.LoadAsset("Assets/MeldursonAssets/SaddleBase.prefab", typeof(GameObject));
		for (int i = 0; i < 9; i++)
		{
			tieredSaddlePrefabs[i] = (GameObject)val.LoadAsset(AssetPath + "SaddleT" + i + ".prefab", typeof(GameObject));
			PrefabExtension.FixReferences(tieredSaddlePrefabs[i], true);
		}
		PrefabManager.OnVanillaPrefabsAvailable -= LoadAssets;
	}

	private ZPackage SendInitialConfig()
	{
		logger.LogWarning((object)"Sent Client MountList RPC");
		CfgPackage cfgPackage = new CfgPackage();
		return cfgPackage.PackMountlist();
	}

	private static void LoadBuiltInMounts()
	{
		//IL_003a: 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_006b: 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_00e8: 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_0119: 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)
		if (!customMounts.ContainsKey("Wolf"))
		{
			Mount mount = new Mount();
			mount.PrefabName = "Wolf";
			mount.mountPath = "WolfSmooth/CG/Pelvis/Spine/Spine1";
			mount.mountPoint = wolfMountPos;
			mount.saddlePos = wolfSaddlePos;
			mount.saddleTier = 4;
			mount.stamina = WolfStamina.Value;
			mount.saddleScale = wolfLocalScale;
			mount.saddleRotation = Vector3.zero;
			customMounts.Add("Wolf", mount);
			logger.LogMessage((object)("added from default=" + mount.PrefabName));
		}
		if (!customMounts.ContainsKey("Boar"))
		{
			Mount mount2 = new Mount();
			mount2.PrefabName = "Boar";
			mount2.mountPath = "CG/Pelvis/Spine/Spine1";
			mount2.mountPoint = boarMountPos;
			mount2.saddlePos = boarSaddlePos;
			mount2.saddleTier = 1;
			mount2.stamina = BoarStamina.Value;
			mount2.saddleScale = boarLocalScale;
			mount2.saddleRotation = Vector3.zero;
			customMounts.Add("Boar", mount2);
			logger.LogMessage((object)("added from default=" + mount2.PrefabName));
		}
	}

	private IEnumerator jot_RPCClientReceive(long sender, ZPackage package)
	{
		logger.LogWarning((object)"Client received MountList RPC");
		removeMounts = customMounts;
		yield return null;
		CfgPackage.Unpack(package);
		LateLoadMounts.Clear();
		foreach (KeyValuePair<string, Mount> key in customMounts)
		{
			LateLoadMounts.Add(key.Key);
		}
		SetupMountable(fromServer: true);
	}

	public static void writeYML()
	{
		logger.LogWarning((object)"Writing to YML");
		if (!ZNet.instance.IsServer())
		{
			logger.LogWarning((object)"not Server, cancelling WriteYML");
		}
		else
		{
			if (isWritingYML)
			{
				return;
			}
			try
			{
				isWritingYML = true;
				if (AddFullMountToYaml.Count <= 0)
				{
					isWritingYML = false;
					return;
				}
				WriteMounts();
				isWritingYML = false;
			}
			catch
			{
				logger.LogWarning((object)"Error in Writing YML");
				isWritingYML = false;
			}
			isWritingYML = false;
		}
	}

	public static List<Mount> ParseMounts(string ymlContents)
	{
		<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser <c2834ef7-3f97-4650-bd1b-0135027032a2>Parser = new <c2834ef7-3f97-4650-bd1b-0135027032a2>Parser(new StringReader(ymlContents));
		<80f48f06-95fc-42a7-99c4-ac69626e7678>IDeserializer <80f48f06-95fc-42a7-99c4-ac69626e7678>IDeserializer = new <d918db1b-b1f5-4af0-8b7d-2de074ba9b19>DeserializerBuilder().WithNamingConvention(<2632c038-f242-4ed1-a275-f5227c6c8ce2>CamelCaseNamingConvention.Instance).Build();
		<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.Consume<<cc337c1a-39df-4a3b-897f-c8dee2ff4043>StreamStart>();
		if (!<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.TryConsume<<4d518326-d58e-4e22-aa12-1e1a9fb667f8>DocumentStart>(out var _))
		{
			return new List<Mount>();
		}
		<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.Consume<<64399ab7-b4c9-4cb1-8d96-58c59e027f1d>MappingStart>();
		List<Mount> list = new List<Mount>();
		<f71aea5e-b8d4-4da7-add5-47cedbf1d89b>Scalar event2;
		while (<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.TryConsume<<f71aea5e-b8d4-4da7-add5-47cedbf1d89b>Scalar>(out event2))
		{
			try
			{
				Mount mount;
				if (<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.Current.GetType() != typeof(<64399ab7-b4c9-4cb1-8d96-58c59e027f1d>MappingStart))
				{
					if ((event2.Value ?? "") == "")
					{
						continue;
					}
					mount = new Mount();
					goto IL_00c5;
				}
				mount = new Mount(<80f48f06-95fc-42a7-99c4-ac69626e7678>IDeserializer.Deserialize<MountSerialized>(<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser));
				goto IL_00c5;
				IL_00c5:
				if ((mount.PrefabName ?? "") == "")
				{
					mount.PrefabName = event2.Value;
				}
				list.Add(mount);
			}
			catch
			{
				logger.LogWarning((object)("Failed to parse " + event2.Value + " from yaml, check to make sure this prefab is formated correctly"));
			}
		}
		return list;
	}

	public static string formatMountYML(string mountYML, string prefabName)
	{
		mountYML = mountYML.Replace("\n", "\n  ").Replace("'", "");
		if (mountYML.StartsWith("prefabName:"))
		{
			mountYML = mountYML.Remove(0, mountYML.IndexOf("\n") + 1);
		}
		return prefabName + ":\n" + mountYML + "\n";
	}

	public static bool create_YML()
	{
		string[] files = Directory.GetFiles(Path.GetDirectoryName(Paths.BepInExConfigPath), "MountUpRestored_CustomMounts*.yml");
		if (files.Count() > 0)
		{
			logger.LogError((object)"There are already MountUpRestored_CustomMounts in your config folder, check to make sure they are formatted correctly");
			logger.LogError((object)"The files are:");
			string[] array = files;
			foreach (string text in array)
			{
				logger.LogError((object)text);
			}
			return false;
		}
		string path = Path.Combine(Path.GetDirectoryName(Paths.BepInExConfigPath), Path.GetFileName("MountUpRestored_CustomMounts.yml"));
		File.Create(path).Dispose();
		string contents = "#   To start setup for mounting a creature, add the creature prefab name on its own line followed by a colon : such as\nPrefabName:\n#   Once loading into the game and coming across this creature it will attempt to snap the saddle to the correct bone and complete the rest of the config in this file\n#   By default the required saddle is a Tier 3 saddle (Advanced Saddle) that you will need to use on the creature to mount it.\n#   To adjust the mounting location you will need to set Enable Adjust Custom Mounts = true in meldurson.MountUpRestored.cfg\n#   You can also find a bunch of premade configurations https://thunderstore.io/c/valheim/p/Meldurson/MountUpRestored/wiki/1368-premade-configs/ that you can copy/paste parts into this file, or paste the entire config into your config folder\n\n";
		File.AppendAllText(path, contents);
		return true;
	}

	public static void WriteMounts()
	{
		if (AddFullMountToYaml.Count <= 0)
		{
			return;
		}
		string[] files = Directory.GetFiles(Path.GetDirectoryName(Paths.BepInExConfigPath), "MountUpRestored_CustomMounts*.yml");
		if (files.Count() > 0)
		{
			<1ad88279-f719-4f9c-ab38-283574c6ddec>ISerializer <1ad88279-f719-4f9c-ab38-283574c6ddec>ISerializer = new <04618b05-873d-4731-b63e-9e7c4dd10374>SerializerBuilder().WithNamingConvention(<2632c038-f242-4ed1-a275-f5227c6c8ce2>CamelCaseNamingConvention.Instance).Build();
			string[] array = files;
			foreach (string path in array)
			{
				string text = File.ReadAllText(path);
				if ((text.Trim(' ', '\n', '\t') ?? "") == "")
				{
					continue;
				}
				<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser <c2834ef7-3f97-4650-bd1b-0135027032a2>Parser = new <c2834ef7-3f97-4650-bd1b-0135027032a2>Parser(new StringReader(text));
				<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.Consume<<cc337c1a-39df-4a3b-897f-c8dee2ff4043>StreamStart>();
				if (!<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.TryConsume<<4d518326-d58e-4e22-aa12-1e1a9fb667f8>DocumentStart>(out var _))
				{
					continue;
				}
				<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.Consume<<64399ab7-b4c9-4cb1-8d96-58c59e027f1d>MappingStart>();
				int num = 0;
				bool flag = false;
				bool flag2 = false;
				<f71aea5e-b8d4-4da7-add5-47cedbf1d89b>Scalar event2;
				while (<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.TryConsume<<f71aea5e-b8d4-4da7-add5-47cedbf1d89b>Scalar>(out event2))
				{
					if (flag)
					{
						for (int j = 0; j < num; j++)
						{
							<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.SkipThisAndNestedEvents();
							if (!<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.TryConsume<<f71aea5e-b8d4-4da7-add5-47cedbf1d89b>Scalar>(out var event3))
							{
								flag2 = true;
							}
							else
							{
								event2 = event3;
							}
						}
					}
					if (flag2)
					{
						break;
					}
					flag = false;
					num++;
					try
					{
						if (!AddFullMountToYaml.Contains(event2.Value))
						{
							<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.SkipThisAndNestedEvents();
							continue;
						}
						if (!customMounts.TryGetValue(event2.Value, out var value))
						{
							logger.LogWarning((object)("Could not find" + event2.Value + "in MountsToOverwrite, skipping write"));
							<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.SkipThisAndNestedEvents();
							continue;
						}
						MountToYaml graph = new MountToYaml(value);
						string value2 = formatMountYML(<1ad88279-f719-4f9c-ab38-283574c6ddec>ISerializer.Serialize(graph), event2.Value);
						<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.SkipThisAndNestedEvents();
						string text2 = text.Remove(event2.Start.Index, <c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.Current.Start.Index - 1 - event2.Start.Index).Insert(event2.Start.Index, value2);
						text = text2;
						AddFullMountToYaml.Remove(event2.Value);
						<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser = new <c2834ef7-3f97-4650-bd1b-0135027032a2>Parser(new StringReader(text));
						flag = true;
						<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.Consume<<cc337c1a-39df-4a3b-897f-c8dee2ff4043>StreamStart>();
						<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.Consume<<4d518326-d58e-4e22-aa12-1e1a9fb667f8>DocumentStart>();
						<c2834ef7-3f97-4650-bd1b-0135027032a2>Parser.Consume<<64399ab7-b4c9-4cb1-8d96-58c59e027f1d>MappingStart>();
					}
					catch
					{
						logger.LogWarning((object)("Failed to parse " + event2.Value + " from yaml, check to make sure this prefab is formated correctly"));
					}
				}
				File.WriteAllText(path, text);
				logger.LogMessage((object)"Overwrote existing creatures to yaml");
			}
			if (AddFullMountToYaml.Count <= 0)
			{
				return;
			}
			string text3 = "\n";
			foreach (string item in AddFullMountToYaml)
			{
				if (!customMounts.TryGetValue(item, out var value3))
				{
					logger.LogWarning((object)("Could not find" + item + "in MountsToOverwrite, skipping write"));
					continue;
				}
				logger.LogWarning((object)("writing " + item + " to " + files[0]));
				string text4 = formatMountYML(<1ad88279-f719-4f9c-ab38-283574c6ddec>ISerializer.Serialize(new MountToYaml(value3)), item);
				text3 += text4;
			}
			File.AppendAllText(files[0], text3);
			logger.LogWarning((object)"Saved creatures to YML");
		}
		else
		{
			logger.LogWarning((object)"no MountList files, creating one");
			if (create_YML())
			{
				WriteMounts();
			}
		}
	}

	public static List<Mount> UseFileOpenReadTextWithSystemTextYaml()
	{
		string[] files = Directory.GetFiles(Path.GetDirectoryName(Paths.BepInExConfigPath), "MountUpRestored_CustomMounts*.yml");
		List<Mount> list = new List<Mount>();
		if (files.Count() > 0)
		{
			string[] array = files;
			foreach (string path in array)
			{
				string ymlContents = File.ReadAllText(path);
				List<Mount> list2 = ParseMounts(ymlContents);
				if (list2[0].PrefabName == "PrefabName")
				{
					list2.RemoveAt(0);
				}
				foreach (Mount mount in list2)
				{
					if (!list.Exists((Mount x) => x.PrefabName == mount.PrefabName) && !((mount.PrefabName ?? "") == ""))
					{
						list.Add(mount);
						if (!customMounts.ContainsKey(mount.PrefabName))
						{
							customMounts.Add(mount.PrefabName, mount);
						}
					}
				}
			}
		}
		else
		{
			logger.LogWarning((object)"no config files");
		}
		return list;
	}

	public static string StringVec(Vector3 vec)
	{
		//IL_0006: 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_001c: Unknown result type (might be due to invalid IL or missing references)
		return $"{{\"x\":{vec.x:F2},\"y\":{vec.y:F2},\"z\":{vec.z:F2}" + "}";
	}

	public static void MakeMountable(Tameable tame, bool legacy = false)
	{
		string name = ((Object)tame).name;
		bool flag = false;
		if (name == "Lox")
		{
			return;
		}
		Mount value2;
		if (customMounts.TryGetValue(name, out var value))
		{
			logger.LogMessage((object)("Making " + ((Object)tame).name + " Mountable" + (legacy ? "(legacy)" : "")));
			if (int.TryParse(value.customSaddle, out var result) && result <= 8 && result >= 0)
			{
				tame.m_saddleItem = tieredSaddleItems[result];
			}
			else
			{
				bool flag2 = false;
				if ((value.customSaddle ?? "") != "")
				{
					GameObject prefab = PrefabManager.Instance.GetPrefab(value.customSaddle);
					if (Object.op_Implicit((Object)(object)prefab))
					{
						ItemDrop saddleItem = default(ItemDrop);
						if (prefab.TryGetComponent<ItemDrop>(ref saddleItem))
						{
							tame.m_saddleItem = saddleItem;
							flag2 = true;
							logger.LogInfo((object)("Set custom Saddle: " + value.customSaddle + " for " + name));
						}
						else
						{
							logger.LogWarning((object)("Unable to find itemDrop in object :" + value.customSaddle + " to use as a custom saddle item for " + name + ". Please make sure to use the an items prefab name"));
						}
					}
					else if (value.customSaddle.StartsWith("attach_"))
					{
						logger.LogWarning((object)("Will attempt to use custom mounting animation (" + value.customSaddle + ") for " + name));
					}
					else
					{
						logger.LogWarning((object)("Unable to find GameObject :" + value.customSaddle + " to use as a custom saddle item for " + name + ". Please make sure to use the prefab name"));
					}
				}
				if (!flag2)
				{
					result = ((value.saddleTier == 0) ? 5 : value.saddleTier);
					tame.m_saddleItem = tieredSaddleItems[result];
				}
			}
			flag = true;
			LateLoadMounts.Remove(name);
		}
		else if (removeMounts.TryGetValue(name, out value2))
		{
			tame.m_saddleItem = null;
			Mountable mountable = default(Mountable);
			if (((Component)tame).gameObject.TryGetComponent<Mountable>(ref mountable))
			{
				logger.LogWarning((object)("removed " + name + " from mountable"));
				Object.DestroyImmediate((Object)(object)mountable);
			}
			return;
		}
		if ((Object)(object)((Component)tame).gameObject.GetComponent<Mountable>() == (Object)null && flag)
		{
			((Component)tame).gameObject.AddComponent<Mountable>().Type = name;
		}
	}

	private static void SetupMountable()
	{
		SetupMountable(fromServer: false);
	}

	private static void SetupMountable(bool fromServer = false)
	{
		if (!fromServer && !ZNet.instance.IsServer())
		{
			logger.LogMessage((object)"Not Server, will wait for RPC");
			return;
		}
		if (LateLoadMounts.Count > 0)
		{
			for (int num = LateLoadMounts.Count - 1; num >= 0; num--)
			{
				bool flag = true;
				logger.LogMessage((object)("Late mount load for " + LateLoadMounts[num]));
				GameObject prefab = PrefabManager.Instance.GetPrefab(LateLoadMounts[num]);
				if ((Object)(object)prefab == (Object)null)
				{
					logger.LogWarning((object)("Go is null for " + LateLoadMounts[num]));
				}
				else
				{
					Tameable val = prefab.GetComponent<Tameable>();
					if (lateLoad && (Object)(object)val == (Object)null && ((Object)prefab).name.StartsWith("RRR"))
					{
						logger.LogMessage((object)("RRRCompat Mounting for " + LateLoadMounts[num]));
						RRRCompat.tryAddTameable(prefab);
						val = prefab.GetComponent<Tameable>();
					}
					if ((Object)(object)val == (Object)null)
					{
						if ((Object)(object)prefab.GetComponent<MonsterAI>() == (Object)null)
						{
							logger.LogWarning((object)(LateLoadMounts[num] + " cannot be mounted as does not have a MonsterAI"));
							flag = false;
						}
						else
						{
							logger.LogWarning((object)("Manually added Tameable for " + LateLoadMounts[num]));
							val = prefab.AddComponent<Tameable>();
						}
					}
					if (flag)
					{
						MakeMountable(val);
					}
				}
			}
		}
		if (LoxStamina.Value != -1f)
		{
			SetMountStamina(PrefabManager.Instance.GetPrefab("Lox"), LoxStamina.Value);
		}
		if (AsksvinStamina.Value != -1f)
		{
			SetMountStamina(PrefabManager.Instance.GetPrefab("Asksvin"), AsksvinStamina.Value);
		}
		UpdateSaddleDesc();
		PieceManager.OnPiecesRegistered -= SetupMountable;
	}

	public static void SetMountStamina(GameObject go, float newStam)
	{
		Tameable val = default(Tameable);
		if (!((Object)(object)go == (Object)null) && go.TryGetComponent<Tameable>(ref val) && !((Object)(object)val.m_saddle == (Object)null))
		{
			logger.LogWarning((object)("Set Stamina of " + ((Object)go).name + " to " + newStam));
			val.m_saddle.m_maxStamina = newStam;
		}
	}

	private static void RemoveMounts()
	{
		Tameable[] array = (from m in Resources.FindObjectsOfTypeAll<Tameable>()
			where !((Object)m).name.Contains("(Clone)")
			select m).ToArray();
		Mountable mountable = default(Mountable);
		for (int i = 0; i < array.Length; i++)
		{
			if (((Component)array[i]).gameObject.TryGetComponent<Mountable>(ref mountable))
			{
				Debug.Log((object)("Clearing mountable from " + ((Object)array[i]).name));
				Object.DestroyImmediate((Object)(object)mountable);
				array[i].m_saddleItem = null;
			}
		}
		PieceManager.OnPiecesRegistered += SetupMountable;
	}

	public static void ResetAllMounts()
	{
		RemoveMounts();
		customMounts.Clear();
		removeMounts.Clear();
		UseFileOpenReadTextWithSystemTextYaml();
		LoadBuiltInMounts();
		LateLoadMounts.Clear();
		foreach (KeyValuePair<string, Mount> customMount in customMounts)
		{
			LateLoadMounts.Add(customMount.Key);
		}
	}

	public static void CreateSaddles()
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Expected O, but got Unknown
		for (int i = 0; i < tieredSaddlePrefabs.Length; i++)
		{
			string description = "No current creatures can be mounted with this saddle (an error might have occurred)";
			CustomItem item = ItemManager.Instance.GetItem("SaddleT" + i);
			if (item != null)
			{
				item.ItemDrop.m_itemData.m_shared.m_description = description;
				continue;
			}
			CustomItem val = new CustomItem(((Component)tieredSaddlePrefabs[i].transform.GetChild(1)).gameObject, true, CreateRecipes(i));
			ItemManager.Instance.AddItem(val);
			tieredSaddleItems[i] = val.ItemDrop;
			val.ItemDrop.m_itemData.m_shared.m_name = "Tier " + i + " Saddle";
			val.ItemDrop.m_itemData.m_dropPrefab = tieredSaddlePrefabs[i];
			val.ItemDrop.m_itemData.m_shared.m_weight = 5f + (float)i;
			val.ItemDrop.m_itemData.m_shared.m_description = description;
		}
		PrefabManager.OnVanillaPrefabsAvailable -= CreateSaddles;
		if (!RecipesMade)
		{
			RecipesMade = true;
		}
	}

	public static void UpdateSaddleDesc()
	{
		//IL_0361: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Expected O, but got Unknown
		List<string>[] array = new List<string>[9];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = new List<string>();
		}
		Character val = default(Character);
		foreach (KeyValuePair<string, Mount> customMount in customMounts)
		{
			int result = -1;
			GameObject prefab = PrefabManager.Instance.GetPrefab(customMount.Key);
			string text = customMount.Key;
			if ((Object)(object)prefab == (Object)null)
			{
				Debug.LogWarning((object)("go null for " + text + " skipping"));
				continue;
			}
			if (prefab.TryGetComponent<Character>(ref val))
			{
				text = val.m_name;
			}
			string text2 = customMount.Value.customSaddle ?? "";
			if (int.TryParse(text2, out result) || result > 8 || result < 0)
			{
				array[result].Add(text);
			}
			else if (text2.Length > 1)
			{
				if (text2.Contains("SaddleT"))
				{
					string text3 = text2.Substring(7, text2.Length - 7);
					Debug.Log((object)(customMount.Key + " has custom saddle with tier " + text3));
					if (int.TryParse(text3, out var result2) && result2 <= 8 && result2 >= 0)
					{
						customMount.Value.customSaddle = text3;
						array[result2].Add(text);
					}
				}
			}
			else
			{
				result = ((customMount.Value.saddleTier == 0) ? 5 : customMount.Value.saddleTier);
				array[result].Add(text);
			}
		}
		TieredSaddleNames = saddleNames.Value.Split(new char[1] { ',' });
		for (int j = 0; j < array.Length; j++)
		{
			string text4 = "$custsaddle_desc";
			if (j > 4)
			{
				text4 = "$custsaddle2_desc";
			}
			else if (j > 2)
			{
				text4 = "$custsaddle3_desc";
			}
			if (array[j].Count > 0)
			{
				text4 += " $custsaddle_has_multi ";
			}
			text4 += string.Join(", ", array[j]);
			text4 = text4.TrimEnd(',', ' ');
			CustomItem item = ItemManager.Instance.GetItem("SaddleT" + j);
			if (item != null)
			{
				Debug.Log((object)("Updating Saddle item for Tier " + j));
				item.ItemDrop.m_itemData.m_shared.m_description = text4;
				if (j > 0)
				{
					item.Recipe.Recipe.m_enabled = array[j].Count > 0;
					if (j <= TieredSaddleNames.Length)
					{
						item.ItemDrop.m_itemData.m_shared.m_name = TieredSaddleNames[j - 1];
					}
				}
				continue;
			}
			item = new CustomItem(((Component)tieredSaddlePrefabs[j].transform.GetChild(1)).gameObject, true, CreateRecipes(j));
			text4 = Localization.instance.Localize(text4);
			ItemManager.Instance.AddItem(item);
			tieredSaddleItems[j] = item.ItemDrop;
			if (j < array.Length)
			{
				item.ItemDrop.m_itemData.m_shared.m_name = TieredSaddleNames[j - 1];
			}
			else
			{
				item.ItemDrop.m_itemData.m_shared.m_name = "Tier " + j + " Saddle";
			}
			item.ItemDrop.m_itemData.m_dropPrefab = tieredSaddlePrefabs[j];
			item.ItemDrop.m_itemData.m_shared.m_weight = 5f + (float)j;
			item.ItemDrop.m_itemData.m_shared.m_description = text4;
		}
		if (!RecipesMade)
		{
			RecipesMade = true;
		}
	}

	private static ItemConfig CreateRecipes(int recipeNum)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Expected O, but got Unknown
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Expected O, but got Unknown
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Expected O, but got Unknown
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Expected O, but got Unknown
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Expected O, but got Unknown
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Expected O, but got Unknown
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Expected O, but got Unknown
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Expected O, but got Unknown
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Expected O, but got Unknown
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Expected O, but got Unknown
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Expected O, but got Unknown
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Expected O, but got Unknown
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Expected O, but got Unknown
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Expected O, but got Unknown
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Expected O, but got Unknown
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Expected O, but got Unknown
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Expected O, but got Unknown
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Expected O, but got Unknown
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Expected O, but got Unknown
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Expected O, but got Unknown
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Expected O, but got Unknown
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Expected O, but got Unknown
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Expected O, but got Unknown
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Expected O, but got Unknown
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Expected O, but got Unknown
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: Expected O, but got Unknown
		//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d7: Expected O, but got Unknown
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0305: Expected O, but got Unknown
		//IL_030f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Expected O, but got Unknown
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_032d: Expected O, but got Unknown
		//IL_0337: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Expected O, but got Unknown
		//IL_0362: Unknown result type (might be due to invalid IL or missing references)
		//IL_036c: Expected O, but got Unknown
		//IL_0377: Unknown result type (might be due to invalid IL or missing references)
		//IL_0381: Expected O, but got Unknown
		//IL_038b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0395: Expected O, but got Unknown
		//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03aa: Expected O, but got Unknown
		ItemConfig val = new ItemConfig();
		switch (recipeNum)
		{
		case 1:
			val.AddRequirement(new RequirementConfig("LeatherScraps", 6, 0, false));
			val.AddRequirement(new RequirementConfig("DeerHide", 4, 0, false));
			val.AddRequirement(new RequirementConfig("HardAntler", 2, 0, false));
			val.AddRequirement(new RequirementConfig("Dandelion", 10, 0, false));
			val.CraftingStation = CraftingStations.Workbench;
			val.MinStationLevel = 1;
			break;
		case 2:
			val.AddRequirement(new RequirementConfig("TrollHide", 6, 0, false));
			val.AddRequirement(new RequirementConfig("DeerHide", 4, 0, false));
			val.AddRequirement(new RequirementConfig("Bronze", 4, 0, false));
			val.AddRequirement(new RequirementConfig("AncientSeed", 3, 0, false));
			val.CraftingStation = CraftingStations.Forge;
			val.MinStationLevel = 1;
			break;
		case 3:
			val.AddRequirement(new RequirementConfig("DeerHide", 15, 0, false));
			val.AddRequirement(new RequirementConfig("ElderBark", 10, 0, false));
			val.AddRequirement(new RequirementConfig("Iron", 6, 0, false));
			val.AddRequirement(new RequirementConfig("Guck", 10, 0, false));
			val.CraftingStation = CraftingStations.Forge;
			val.MinStationLevel = 2;
			break;
		case 4:
			val.AddRequirement(new RequirementConfig("WolfPelt", 6, 0, false));
			val.AddRequirement(new RequirementConfig("DeerHide", 4, 0, false));
			val.AddRequirement(new RequirementConfig("Obsidian", 2, 0, false));
			val.AddRequirement(new RequirementConfig("Silver", 5, 0, false));
			val.AddRequirement(new RequirementConfig("FreezeGland", 10, 0, false));
			val.CraftingStation = CraftingStations.Workbench;
			val.MinStationLevel = 4;
			break;
		case 5:
			val.AddRequirement(new RequirementConfig("LoxPelt", 6, 0, false));
			val.AddRequirement(new RequirementConfig("DeerHide", 4, 0, false));
			val.AddRequirement(new RequirementConfig("BlackMetal", 4, 0, false));
			val.AddRequirement(new RequirementConfig("TrophyLox", 1, 0, false));
			val.AddRequirement(new RequirementConfig("Tar", 5, 0, false));
			val.CraftingStation = CraftingStations.Forge;
			val.MinStationLevel = 3;
			break;
		case 6:
			val.AddRequirement(new RequirementConfig("ScaleHide", 15, 0, false));
			val.AddRequirement(new RequirementConfig("Obsidian", 6, 0, false));
			val.AddRequirement(new RequirementConfig("YggdrasilWood", 6, 0, false));
			val.AddRequirement(new RequirementConfig("Sap", 10, 0, false));
			val.AddRequirement(new RequirementConfig("Eitr", 3, 0, false));
			val.CraftingStation = CraftingStations.Workbench;
			val.MinStationLevel = 5;
			break;
		case 7:
			val.AddRequirement(new RequirementConfig("LoxPelt", 10, 0, false));
			val.AddRequirement(new RequirementConfig("MorgenHeart", 2, 0, false));
			val.AddRequirement(new RequirementConfig("FlametalNew", 6, 0, false));
			val.AddRequirement(new RequirementConfig("Tar", 5, 0, false));
			val.CraftingStation = CraftingStations.Forge;
			val.MinStationLevel = 4;
			break;
		case 8:
			val.AddRequirement(new RequirementConfig("WolfPelt", 20, 0, false));
			val.AddRequirement(new RequirementConfig("ScaleHide", 10, 0, false));
			val.AddRequirement(new RequirementConfig("GemstoneBlue", 1, 0, false));
			val.AddRequirement(new RequirementConfig("FreezeGland", 50, 0, false));
			val.CraftingStation = CraftingStations.ArtisanTable;
			val.MinStationLevel = 2;
			break;
		}
		return val;
	}
}
namespace MountUp
{
	internal class AdjustmentPatches
	{
		[HarmonyPatch(typeof(Character), "GetHoverText")]
		[HarmonyPostfix]
		private static void Char_GetHoverText(Character __instance, ref string __result)
		{
			//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_00ea: 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)
			Mountable mountable = default(Mountable);
			if (!__instance.m_tamed || !((Component)__instance).gameObject.TryGetComponent<Mountable>(ref mountable) || !Setup.adjustCustom.Value || !ZNet.instance.IsServer() || (Object)(object)mountable.getSaddle() == (Object)null || !mountable.getSaddle().activeSelf)
			{
				return;
			}
			KeyboardShortcut val = new KeyboardShortcut((KeyCode)101, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 });
			if (((KeyboardShortcut)(ref val)).IsDown())
			{
				Player localPlayer = Player.m_localPlayer;
				Sadle component = mountable.getSaddle().GetComponent<Sadle>();
				if ((Object)(object)component != (Object)null && (Object)(object)localPlayer != (Object)null)
				{
					Debug.LogWarning((object)"Attempt Force Mount");
					ZNetView nview = component.m_nview;
					object[] array = new object[1];
					ZDOID zDOID = ((Character)localPlayer).GetZDOID();
					array[0] = ((ZDOID)(ref zDOID)).UserID;
					nview.InvokeRPC("RequestControl", array);
				}
			}
			string text = Localization.instance.Localize("$hud_rename");
			string text2 = Localization.instance.Localize("$sitinsaddle");
			__result = __result.Replace(text, text + "\n[<color=orange><b>Alt+E</b></color>] " + text2);
		}
	}
	[Serializable]
	public class CfgPackage
	{
		public MountSerialized[] mounts;

		public static ZPackage zpack;

		public ZPackage PackMountlist()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			if (zpack == null)
			{
				Pack();
				Setup.logger.LogWarning((object)"Packed List");
			}
			else
			{
				Setup.logger.LogWarning((object)"Already Packed List");
			}
			ZPackage val = new ZPackage();
			return zpack;
		}

		public ZPackage Pack()
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			mounts = new MountSerialized[Setup.customMounts.Count];
			int num = 0;
			foreach (KeyValuePair<string, Mount> customMount in Setup.customMounts)
			{
				mounts[num] = new MountSerialized(customMount.Value);
				num++;
			}
			MountSerialized[] array = mounts;
			foreach (MountSerialized mountSerialized in array)
			{
				Setup.logger.LogWarning((object)("mount in list=" + mountSerialized.PrefabName));
			}
			ZPackage val = new ZPackage();
			using MemoryStream memoryStream = new MemoryStream();
			using (GZipStream serializationStream = new GZipStream(memoryStream, CompressionLevel.Optimal))
			{
				new BinaryFormatter().Serialize(serializationStream, this);
			}
			byte[] buffer = memoryStream.GetBuffer();
			val.Write(buffer);
			zpack = val;
			return val;
		}

		public static void Unpack(ZPackage package, bool setValue = true)
		{
			byte[] buffer = package.ReadByteArray();
			using MemoryStream stream = new MemoryStream(buffer);
			using GZipStream serializationStream = new GZipStream(stream, CompressionMode.Decompress, leaveOpen: true);
			if (new BinaryFormatter().Deserialize(serializationStream) is CfgPackage cfgPackage)
			{
				Setup.logger.LogMessage((object)"Unpackaging MountUp Configs.");
				MountSerialized[] array = cfgPackage.mounts;
				Setup.removeMounts = new Dictionary<string, Mount>(Setup.customMounts);
				Setup.customMounts.Clear();
				MountSerialized[] array2 = array;
				foreach (MountSerialized mountSerialized in array2)
				{
					Setup.logger.LogMessage((object)("mount=" + mountSerialized.PrefabName));
					Setup.customMounts.Add(mountSerialized.PrefabName, new Mount(mountSerialized));
				}
				Setup.logger.LogMessage((object)"Successfully unpacked configs.");
			}
			else
			{
				Setup.logger.LogWarning((object)"Received bad config package. Unable to load.");
			}
		}
	}
	public class Mountable : MonoBehaviour
	{
		public GameObject mountPoint;

		private Transform mountPointBase;

		private GameObject saddle;

		private float flyStaminaDrain = 10f;

		public bool canfly = false;

		private Animator anim;

		public string Type;

		public static ManualLogSource logger;

		public Vector3 basePos;

		private static Vector3 rotationAdjust = Setup.rotationAdjust;

		private static Vector3 posDefault = Setup.posDefault;

		public int[] attackorder = new int[4];

		private bool initAttacks = false;

		private bool setCustomAttacks = false;

		private float lastSaddleScale = 0f;

		private float updateTime = 0.7f;

		public ZNetView m_nview;

		public void Awake()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_0093: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: 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)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0759: Unknown result type (might be due to invalid IL or missing references)
			//IL_076c: Unknown result type (might be due to invalid IL or missing references)
			//IL_064e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0653: Unknown result type (might be due to invalid IL or missing references)
			//IL_0675: Unknown result type (might be due to invalid IL or missing references)
			//IL_068d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0692: Unknown result type (might be due to invalid IL or missing references)
			//IL_0697: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_091e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0924: Unknown result type (might be due to invalid IL or missing references)
			//IL_0929: Unknown result type (might be due to invalid IL or missing references)
			//IL_092e: Unknown result type (might be due to invalid IL or missing references)
			//IL_093a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0915: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_09fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a0e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a1e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a33: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a44: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a49: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a4e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a53: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a65: Unknown result type (might be due to invalid IL or missing references)
			if (logger == null)
			{
				logger = Setup.logger;
			}
			Tameable component = ((Component)this).GetComponent<Tameable>();
			Type = ((Object)component).name.Replace("(Clone)", "");
			Humanoid component2 = ((Component)this).gameObject.GetComponent<Humanoid>();
			Transform val = ((Component)component2).gameObject.transform.Find("Visual");
			mountPoint = new GameObject("MountPoint");
			mountPoint.transform.parent = val;
			mountPoint.transform.rotation = ((Component)this).transform.rotation;
			Vector3 val2 = posDefault;
			Vector3 val3 = posDefault;
			Vector3 one = Vector3.one;
			Vector3 val4 = rotationAdjust;
			m_nview = ((Component)this).gameObject.GetComponent<ZNetView>();
			m_nview.Register("RPC_SetMountPoint", (Action<long>)RPC_SetMountPoint);
			if (!Setup.customMounts.TryGetValue(Type, out var value))
			{
				logger.LogWarning((object)(Type + " is not in custom mounts list, removing mountable"));
				Object.Destroy((Object)(object)this);
				return;
			}
			string text = value.mountPath ?? "";
			if (text.Contains("\\"))
			{
				logger.LogWarning((object)(Type + " Mount Path should use '/' rather than '\\', trying to replace"));
				text.Replace('\\', '/');
				value.mountPath = text;
			}
			if (text != "")
			{
				mountPointBase = val.Find(text);
			}
			val2 = (basePos = value.mountPoint);
			val3 = value.saddlePos;
			one = value.saddleScale;
			val4 = value.saddleRotation + rotationAdjust;
			if ((Object)(object)mountPointBase == (Object)null)
			{
				string[] array;
				if (!(text == ""))
				{
					mountPoint.transform.parent = val;
					string text2 = "";
					array = text.Split(new char[1] { '/' });
					string[] array2 = array;
					foreach (string text3 in array2)
					{
						if (!text2.Equals(""))
						{
							text2 += "/";
						}
						if ((Object)(object)val.Find(text2 + text3) == (Object)null)
						{
							string text4 = Type + " Mount Path '" + text + "' is not correct. ";
							if (text2 != "")
							{
								text4 = text4 + "'" + text2 + "' appears to work. ";
							}
							text4 = text4 + text3 + " cannot be found in " + Type + " body. " + Type + " will not be rideable.";
							((Component)component2).GetComponent<Tameable>().m_saddleItem = null;
							logger.LogError((object)text4);
							return;
						}
						text2 += text3;
					}
					logger.LogError((object)("Unknown error in setting up saddle and riding for " + Type + ", it will not be rideable"));
					((Component)component2).GetComponent<Tameable>().m_saddleItem = null;
					return;
				}
				Transform[] componentsInChildren = ((Component)val).GetComponentsInChildren<Transform>();
				string[] array3 = new string[7] { "spine2", "spine1", "tail2", "spine", "neck", "head", "armature" };
				List<string> list = new List<string>();
				array = array3;
				string[] array4 = array;
				foreach (string text5 in array4)
				{
					Transform[] array5 = componentsInChildren;
					Transform[] array6 = array5;
					foreach (Transform val5 in array6)
					{
						if (((Object)val5).name.ToLowerInvariant() == text5)
						{
							Transform val6 = val5;
							if (text5 == "neck")
							{
								val6 = val6.parent;
							}
							if ((Object)(object)mountPointBase == (Object)null)
							{
								mountPointBase = val6;
								text = GetPath(val6);
							}
							else if (text5 != "armature")
							{
								list.Add(GetPath(val6));
							}
							break;
						}
					}
				}
				if ((Object)(object)mountPointBase == (Object)null)
				{
					array = array3;
					string[] array7 = array;
					foreach (string value2 in array7)
					{
						Transform[] array8 = componentsInChildren;
						Transform[] array9 = array8;
						foreach (Transform val7 in array9)
						{
							string text6 = ((Object)val7).name.ToLowerInvariant();
							if (text6.StartsWith(value2) || text6.EndsWith(value2))
							{
								if ((Object)(object)mountPointBase == (Object)null)
								{
									mountPointBase = val7;
									text = GetPath(val7);
								}
								else
								{
									list.Add(GetPath(val7));
								}
								break;
							}
						}
					}
				}
				if (!((Object)(object)mountPointBase != (Object)null))
				{
					logger.LogError((object)("Could not find potential Mount Path for " + Type + ". " + Type + " will not be rideable"));
					((Component)component2).GetComponent<Tameable>().m_saddleItem = null;
					return;
				}
				string text7 = "";
				if (list.Count > 0)
				{
					text7 = "\nPossible Alternatives:";
					foreach (string item in list)
					{
						text7 = text7 + "\n" + item;
					}
				}
				value.mountPath = text;
				if (value.saddleRotation == Vector3.zero)
				{
					mountPoint.transform.rotation = mountPointBase.rotation;
					value.saddleRotation = mountPoint.transform.localEulerAngles - Setup.rotationAdjust;
					val4 = value.saddleRotation + Setup.rotationAdjust;
				}
				logger.LogMessage((object)("Found potential Mount Path for " + Type + ": " + text + text7));
				Setup.AddFullMountToYaml.Add(value.PrefabName);
				((MonoBehaviour)this).Invoke("UpdateConfig", 5f);
			}
			mountPoint.transform.parent = val;
			saddle = Object.Instantiate<GameObject>(((Component)Setup.tieredSaddlePrefabs[value.saddleTier].transform.GetChild(0)).gameObject, val);
			mountPoint.transform.localEulerAngles = val4;
			saddle.transform.localEulerAngles = val4;
			saddle.GetComponent<Sadle>().m_maxStamina = value.stamina;
			flyStaminaDrain = value.flyingStamina;
			BaseAI baseAI = ((Character)component2).GetBaseAI();
			MonsterAI val8 = (MonsterAI)(object)((baseAI is MonsterAI) ? baseAI : null);
			if ((Object)(object)val8 != (Object)null && val8.m_avoidLand)
			{
				saddle.GetComponent<Sadle>().m_swimStaminaDrain = 0f;
			}
			if (((Character)component2).IsFlying())
			{
				if (flyStaminaDrain < 0f)
				{
					flyStaminaDrain = 1f;
				}
				canfly = true;
			}
			else if (flyStaminaDrain > 0f)
			{
				canfly = true;
			}
			Sadle component3 = saddle.GetComponent<Sadle>();
			component3.m_hoverText = ((Character)component2).m_name + " $mu_saddle";
			component3.m_attachPoint = mountPoint.transform;
			if ((value.customSaddle ?? "") != "" && value.customSaddle.StartsWith("attach_"))
			{
				component3.m_attachAnimation = value.customSaddle;
			}
			saddle.SetActive(false);
			component.m_saddle = component3;
			((Component)component3).transform.localPosition = val3;
			((Component)component3).transform.localScale = one;
			if (Setup.adjustCustom.Value)
			{
				anim = ((Component)component2).gameObject.GetComponentInChildren<Animator>();
			}
			if (val4 != rotationAdjust)
			{
				((Component)component3).GetComponentInChildren<Transform>().localEulerAngles = val4;
			}
			val2 += Setup.MountPointAdjustment.Value;
			mountPoint.transform.localPosition = val2;
			if ((Object)(object)component.m_saddle != (Object)null)
			{
				component.m_nview.Register("AddSaddle", (Action<long>)component.RPC_AddSaddle);
				component.m_nview.Register<bool>("SetSaddle", (Action<long, bool>)component.RPC_SetSaddle);
				component.SetSaddle(component.HaveSaddle());
			}
			mountPoint.transform.parent = mountPointBase;
			saddle.transform.parent = mountPointBase;
			mountPoint.transform.localEulerAngles = val4;
			saddle.transform.localEulerAngles = val4;
			mountPoint.transform.localPosition = val2;
			Transform transform = mountPoint.transform;
			transform.position -= mountPoint.transform.rotation * (MountUp.lossyfactor * (saddle.transform.lossyScale.z - 1f) * Vector3.forward);
			((Component)component3).transform.localPosition = val3;
			SphereCollider component4 = saddle.GetComponent<SphereCollider>();
			if (!((value.customAttackOrder ?? "") != ""))
			{
				return;
			}
			string[] array10 = value.customAttackOrder.Split(new char[1] { ',' });
			int num = Math.Min(4, array10.Length);
			for (int n = 0; n < num; n++)
			{
				if (int.TryParse(array10[n], out var result))
				{
					attackorder[n] = result;
				}
				else
				{
					logger.LogWarning((object)("Failed to set custom attack order for " + array10[n]));
				}
			}
			setCustomAttacks = true;
		}

		public void setattacks(Humanoid humanoid)
		{
			if (humanoid.m_inventory != null)
			{
				List<ItemData> inventory = humanoid.m_inventory.m_inventory;
				bool[] array = new bool[4];
				bool flag = true;
				if (setCustomAttacks)
				{
					for (int i = 0; i < attackorder.Length; i++)
					{
						if (attackorder[i] >= inventory.Count)
						{
							logger.LogWarning((object)(attackorder[i] + " is higher than the total array of attacks (" + (inventory.Count - 1) + "), please reduce the number"));
							flag = false;
						}
					}
					if (flag)
					{
						initAttacks = true;
						return;
					}
				}
				for (int j = 0; j < inventory.Count; j++)
				{
					float totalDamage = ((DamageTypes)(ref inventory[j].m_shared.m_damages)).GetTotalDamage();
					if (totalDamage <= 0f)
					{
						continue;
					}
					if (inventory[j].m_shared.m_aiWhenFlying)
					{
						if (!array[2])
						{
							attackorder[2] = j;
							array[2] = true;
							continue;
						}
						if (array[3])
						{
							if (((DamageTypes)(ref inventory[attackorder[3]].m_shared.m_damages)).GetTotalDamage() < totalDamage)
							{
								attackorder[3] = j;
							}
							continue;
						}
						if (((DamageTypes)(ref inventory[attackorder[2]].m_shared.m_damages)).GetTotalDamage() > totalDamage)
						{
							attackorder[3] = attackorder[2];
							attackorder[2] = j;
						}
						else
						{
							attackorder[3] = j;
						}
						array[3] = true;
					}
					else if (!array[0])
					{
						attackorder[0] = j;
						array[0] = true;
					}
					else if (array[1])
					{
						if (((DamageTypes)(ref inventory[attackorder[1]].m_shared.m_damages)).GetTotalDamage() < totalDamage)
						{
							attackorder[1] = j;
						}
					}
					else
					{
						if (((DamageTypes)(ref inventory[attackorder[0]].m_shared.m_damages)).GetTotalDamage() > totalDamage)
						{
							attackorder[1] = attackorder[0];
							attackorder[0] = j;
						}
						else
						{
							attackorder[1] = j;
						}
						array[1] = true;
					}
				}
				if (!array[3])
				{
					attackorder[3] = attackorder[2];
				}
				if (!array[0] & array[2])
				{
					attackorder[0] = attackorder[2];
					if (array[3])
					{
						attackorder[1] = attackorder[3];
						array[1] = true;
					}
				}
				if (!array[1])
				{
					attackorder[1] = attackorder[0];
				}
				initAttacks = true;
			}
			else
			{
				Debug.LogWarning((object)"Creature does not have attacks");
			}
		}

		public void Delayed_ResetMountPoint()
		{
			ResetMountPoint();
			if (!Setup.adjustCustom.Value)
			{
				((MonoBehaviour)this).Invoke("Delayed_ResetMountPoint", updateTime);
				updateTime += 1f;
			}
		}

		public void ResetMountPoint()
		{
			//IL_000f: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = mountPoint.transform;
			transform.localPosition = basePos;
			transform.position -= ((Component)transform).transform.rotation * (MountUp.lossyfactor * (saddle.transform.lossyScale.z - 1f) * Vector3.forward);
		}

		public void RPC_SetMountPoint(long sender)
		{
			ResetMountPoint();
		}

		public bool hasInitAttacks()
		{
			return initAttacks;
		}

		public void setAnimation(bool isAnimating)
		{
			if ((Object)(object)anim != (Object)null)
			{
				((Behaviour)anim).enabled = isAnimating;
			}
		}

		public float getFlyStaminaDrain()
		{
			return flyStaminaDrain;
		}

		public GameObject getSaddle()
		{
			return saddle;
		}

		public void reduceflyingStamina(float dt)
		{
			Character component = ((Component)this).gameObject.GetComponent<Character>();
			if (Object.op_Implicit((Object)(object)component) && component.m_flying)
			{
				float stamina = saddle.GetComponent<Sadle>().GetStamina();
				saddle.GetComponent<Sadle>().SetStamina(stamina - dt * flyStaminaDrain);
			}
		}

		private string GetPath(Transform child)
		{
			string text = ((Object)child).name;
			Transform parent = child.parent;
			while (((Object)parent).name != "Visual")
			{
				text = ((Object)parent).name + "/" + text;
				parent = parent.parent;
			}
			return text;
		}

		private void UpdateConfig()
		{
			Setup.writeYML();
		}
	}
	public class MountUp
	{
		public enum AdjustMode
		{
			None,
			Saddle,
			Mount,
			Rotation
		}

		[HarmonyPatch(typeof(Tameable), "SetSaddle")]
		public static class InterceptSetSaddle
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				bool skipped = false;
				foreach (CodeInstruction instruction in instructions)
				{
					if (instruction.opcode == OpCodes.Ldarg_0)
					{
						skipped = true;
					}
					if (skipped)
					{
						yield return instruction;
					}
				}
			}
		}

		public static GameObject keyDisplayPanel;

		public static Text EditModeTitle;

		public static Text commandDisplay;

		public static Text keyDisplay;

		public static string CommandStringPos = "";

		public static string CommandStringRot = "";

		public static string keyString = "";

		public static float dampingPercent = 0.9f;

		public static float AdjustSpeed = 0.9f;

		public static Vector3 sumOffset = Vector3.zero;

		public static int countOffset = 0;

		public static Vector3 avgOffset = Vector3.zero;

		public static Vector3 lastPos = Vector3.zero;

		public static Vector3 speedMulti = Vector3.one;

		public static float max_dist = 2f;

		public static float lossyfactor = 0.25f;

		public static bool useSmooth = true;

		public static AdjustMode adjustMode;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(LevelEffects), "Start")]
		private static void LevelEffectsStart_Patch(LevelEffects __instance)
		{
			if (Object.op_Implicit((Object)(object)__instance.m_baseEnableObject))
			{
				Mountable component = __instance.m_baseEnableObject.GetComponent<Mountable>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.ResetMountPoint();
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Sadle), "Interact")]
		private static void Sadle_Interact_Patch(Sadle __instance)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			Mountable mountable = default(Mountable);
			if (((Component)__instance.m_character).TryGetComponent<Mountable>(ref mountable) && !Setup.adjustCustom.Value)
			{
				mountable.m_nview.InvokeRPC("RPC_SetMountPoint", Array.Empty<object>());
			}
			__instance.m_character.m_maxAirAltitude = ((Component)__instance).transform.position.y;
			__instance.m_character.m_groundContact = false;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Sadle), "Awake")]
		private static void Sadle_Awake_Patch(Sadle __instance)
		{
			Mountable mountable = default(Mountable);
			if (((Component)__instance.m_character).TryGetComponent<Mountable>(ref mountable))
			{
				((MonoBehaviour)mountable).Invoke("Delayed_ResetMountPoint", 1.3f);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Player), "Update")]
		private static void Player_Update_Patch(Player __instance)
		{
			//IL_0018: 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)
			if (((Character)__instance).IsRiding())
			{
				((Component)__instance).transform.position = __instance.m_attachPoint.position;
				((Component)__instance).transform.rotation = __instance.m_attachPoint.rotation;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ZNetScene), "Shutdown")]
		private static void Postfix()
		{
			Debug.Log((object)"Reseting Mounts");
			Setup.ResetAllMounts();
		}

		[HarmonyPatch(typeof(LevelEffects), "SetupLevelVisualization")]
		[HarmonyPostfix]
		private static void LevelEffectsSetupLevelVisualization_Patch(LevelEffects __instance)
		{
			Mountable mountable = default(Mountable);
			if (Object.op_Implicit((Object)(object)__instance.m_character) && ((Component)__instance.m_character).gameObject.TryGetComponent<Mountable>(ref mountable))
			{
				mountable.ResetMountPoint();
			}
		}

		private static void displayKeybinds(bool active)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: 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_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: 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)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)keyDisplayPanel))
			{
				if (GUIManager.Instance == null)
				{
					Debug.LogError((object)"GUIManager instance is null");
					return;
				}
				if (!Object.op_Implicit((Object)(object)GUIManager.CustomGUIFront))
				{
					Debug.LogError((object)"GUIManager CustomGUI is null");
					return;
				}
				SetCommandsStrings();
				keyDisplayPanel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -300f), 400f, 500f, false);
				((Behaviour)keyDisplayPanel.GetComponent<Image>()).enabled = false;
				GameObject val = GUIManager.Instance.CreateText(keyString.Substring(0, keyString.IndexOf('\n')), keyDisplayPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(187f, -265f), GUIManager.Instance.AveriaSerifBold, 20, GUIManager.Instance.ValheimOrange, true, Color.black, 300f, 500f, false);
				keyDisplay = val.GetComponent<Text>();
				GameObject val2 = GUIManager.Instance.CreateText(CommandStringPos.Substring(0, CommandStringPos.IndexOf('\n')), keyDisplayPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(-45f, -265f), GUIManager.Instance.AveriaSerifBold, 20, Color.white, true, Color.black, 300f, 500f, false);
				commandDisplay = val2.GetComponent<Text>();
				commandDisplay.alignment = (TextAnchor)2;
				GameObject val3 = GUIManager.Instance.CreateText("Not Editing", keyDisplayPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(50f, 5f), GUIManager.Instance.AveriaSerifBold, 27, Color.red, true, Color.black, 400f, 40f, false);
				EditModeTitle = val3.GetComponent<Text>();
				EditModeTitle.alignment = (TextAnchor)7;
			}
			keyDisplayPanel.SetActive(active);
		}

		public static string getKeybingsString()
		{
			//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_0035: 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_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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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)
			//IL_0104: 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_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: 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_01d1: Unknown result type (might be due to invalid IL or missing references)
			string text = "";
			string text2 = text;
			KeyboardShortcut value = Setup.adjustCustomModeSwitch.Value;
			text = text2 + string.Join("+", ((KeyboardShortcut)(ref value)).Modifiers);
			string text3 = text;
			value = Setup.adjustCustomModeSwitch.Value;
			KeyCode val = ((KeyboardShortcut)(ref value)).MainKey;
			text = text3 + "+" + ((object)(KeyCode)(ref val)).ToString() + "\n";
			string[] obj = new string[5] { text, null, null, null, null };
			val = (KeyCode)276;
			obj[1] = ((object)(KeyCode)(ref val)).ToString();
			obj[2] = "/";
			val = (KeyCode)275;
			obj[3] = ((object)(KeyCode)(ref val)).ToString();
			obj[4] = "\n";
			text = string.Concat(obj);
			string[] obj2 = new string[5] { text, null, null, null, null };
			val = (KeyCode)273;
			obj2[1] = ((object)(KeyCode)(ref val)).ToString();
			obj2[2] = "/";
			val = (KeyCode)274;
			obj2[3] = ((object)(KeyCode)(ref val)).ToString();
			obj2[4] = "\n";
			text = string.Concat(obj2);
			string[] obj3 = new string[5] { text, null, null, null, null };
			val = (KeyCode)280;
			obj3[1] = ((object)(KeyCode)(ref val)).ToString();
			obj3[2] = "/";
			val = (KeyCode)281;
			obj3[3] = ((object)(KeyCode)(ref val)).ToString();
			obj3[4] = "\n";
			text = string.Concat(obj3);
			string[] obj4 = new string[5] { text, null, null, null, null };
			val = (KeyCode)306;
			obj4[1] = ((object)(KeyCode)(ref val)).ToString();
			obj4[2] = "+";
			val = (KeyCode)115;
			obj4[3] = ((object)(KeyCode)(ref val)).ToString();
			obj4[4] = "\n";
			text = string.Concat(obj4);
			string text4 = text;
			val = (KeyCode)305;
			text = text4 + "\n" + ((object)(KeyCode)(ref val)).ToString() + "\n";
			string text5 = text;
			val = (KeyCode)303;
			text = text5 + ((object)(KeyCode)(ref val)).ToString() + "\n";
			string text6 = text;
			val = (KeyCode)307;
			text = text6 + ((object)(KeyCode)(ref val)).ToString() + "\n";
			return SimplifyKeys(text);
		}

		public static string SimplifyKeys(string keyString)
		{
			return keyString.Replace("Left", "L-").Replace("Right", "R-").Replace("Control", "Ctrl")
				.Replace("BackQuote", "` (BackQuote)");
		}

		public static void SetCommandsStrings()
		{
			CommandStringPos = "";
			CommandStringRot = "";
			CommandStringPos += "Cycle Edit Mode                 \n";
			CommandStringRot = CommandStringPos;
			CommandStringRot += "Tilt Left/Right                 \nRotate Forward/Back                 \nSpin Left/Right                 \n";
			CommandStringPos += "Move Left/Right                 \nMove Forward/Back                 \nMove Up/Down                 \n";
			string text = "Save to YML                 \n Finer Adjustment:\n0.5x (hold)                 \n0.1x (hold)                 \n0.05x (hold)                 \n";
			CommandStringPos += text;
			CommandStringRot += text;
			keyString = getKeybingsString();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "Update")]
		private static void PlayerUpdate_Patch(Player __instance)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0549: Unknown result type (might be due to invalid IL or missing references)
			//IL_0550: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0579: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0678: Unknown result type (might be due to invalid IL or missing references)
			//IL_067d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0482: Unknown result type (might be due to invalid IL or missing references)
			//IL_0487: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06da: Unknown result type (might be due to invalid IL or missing references)
			//IL_06df: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0639: Unknown result type (might be due to invalid IL or missing references)
			//IL_063e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0640: Unknown result type (might be due to invalid IL or missing references)
			//IL_060b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0501: Unknown result type (might be due to invalid IL or missing references)
			//IL_0660: Unknown result type (might be due to invalid IL or missing references)
			//IL_0665: Unknown result type (might be due to invalid IL or missing references)
			//IL_0667: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer())
			{
				displayKeybinds(active: false);
				return;
			}
			if (!Setup.adjustCustom.Value)
			{
				displayKeybinds(active: false);
				return;
			}
			bool flag = false;
			bool flag2 = false;
			bool num = ZInput.instance != null;
			KeyboardShortcut value = Setup.adjustCustomModeSwitch.Value;
			if (num & ((KeyboardShortcut)(ref value)).IsDown())
			{
				adjustMode = (AdjustMode)((int)(adjustMode + 1) % Enum.GetValues(typeof(AdjustMode)).Length);
				string text = "";
				if (CommandStringPos == "")
				{
					SetCommandsStrings();
				}
				switch (adjustMode)
				{
				case AdjustMode.None:
					text = "Adjust Mode: None";
					EditModeTitle.text = "Not Editing";
					commandDisplay.text = CommandStringPos.Substring(0, CommandStringPos.IndexOf('\n'));
					keyDisplay.text = keyString.Substring(0, keyString.IndexOf('\n'));
					break;
				case AdjustMode.Saddle:
					text = "Adjust Mode: Saddle Position";
					EditModeTitle.text = "Adjust Mode: Saddle Position";
					commandDisplay.text = CommandStringPos;
					keyDisplay.text = keyString;
					flag = true;
					break;
				case AdjustMode.Mount:
					text = "Adjust Mode: Player Mount Position";
					EditModeTitle.text = "Adjust Mode: Player Mount Position";
					commandDisplay.text = CommandStringPos;
					keyDisplay.text = keyString;
					flag = true;
					break;
				case AdjustMode.Rotation:
					text = "Adjust Mode: Saddle Rotation";
					EditModeTitle.text = "Adjust Mode: Rotation";
					commandDisplay.text = CommandStringRot;
					keyDisplay.text = keyString;
					flag2 = true;
					break;
				default:
					text = "Adjust Mode: Unknown (error)";
					EditModeTitle.text = "Error: Not Editing";
					break;
				}
				((Character)__instance).Message((MessageType)1, text, 0, (Sprite)null);
			}
			IDoodadController doodadController = __instance.GetDoodadController();
			Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null);
			if ((Object)(object)val == (Object)null)
			{
				displayKeybinds(active: false);
				return;
			}
			Mountable component = ((Component)val.GetCharacter()).gameObject.GetComponent<Mountable>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				displayKeybinds(active: false);
				return;
			}
			displayKeybinds(active: true);
			Transform val2 = null;
			Transform val3 = null;
			switch (adjustMode)
			{
			case AdjustMode.None:
				val2 = null;
				component.setAnimation(isAnimating: true);
				break;
			case AdjustMode.Saddle:
				val2 = ((Component)val).transform;
				val3 = val.m_attachPoint;
				component.setAnimation(isAnimating: false);
				break;
			case AdjustMode.Rotation:
				val2 = ((Component)val).transform;
				val3 = val.m_attachPoint;
				component.setAnimation(isAnimating: false);
				break;
			case AdjustMode.Mount:
				val2 = val.m_attachPoint;
				val3 = ((Component)val).transform;
				component.setAnimation(isAnimating: false);
				break;
			default:
				component.setAnimation(isAnimating: false);
				break;
			}
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			float num2 = 1f;
			if (Input.GetKey((KeyCode)305))
			{
				num2 *= 0.5f;
			}
			if (Input.GetKey((KeyCode)303))
			{
				num2 *= 0.1f;
			}
			if (Input.GetKey((KeyCode)307))
			{
				num2 *= 0.05f;
			}
			Vector3 localPosition = val2.localPosition;
			Vector3 localEulerAngles = val2.localEulerAngles;
			if (adjustMode != AdjustMode.Rotation)
			{
				if (Input.GetKeyDown((KeyCode)275))
				{
					Transform obj = val2;
					obj.position += val2.rotation * (num2 * Vector3.right);
				}
				if (Input.GetKeyDown((KeyCode)276))
				{
					Transform obj2 = val2;
					obj2.position -= val2.rotation * (num2 * Vector3.right);
				}
				if (Input.GetKeyDown((KeyCode)273))
				{
					Transform obj3 = val2;
					obj3.position += val2.rotation * (num2 * Vector3.forward);
				}
				if (Input.GetKeyDown((KeyCode)274))
				{
					Transform obj4 = val2;
					obj4.position -= val2.rotation * (num2 * Vector3.forward);
				}
				if (Input.GetKeyDown((KeyCode)280))
				{
					Transform obj5 = val2;
					obj5.position += val2.rotation * (num2 * Vector3.up);
				}
				if (Input.GetKeyDown((KeyCode)281))
				{
					Transform obj6 = val2;
					obj6.position -= val2.rotation * (num2 * Vector3.up);
				}
			}
			else
			{
				num2 *= 20f;
				if (rotateTransform(val2, num2) && (Object)(object)val3 != (Object)null)
				{
					rotateTransform(val3, num2);
				}
			}
			if (Vector3.Distance(val2.position, val3.position) > 2.5f)
			{
				((Character)__instance).Message((MessageType)2, "Saddle and Mount Point Must Stay closer,\n or player will dismount", 0, (Sprite)null);
				val2.localPosition = localPosition;
			}
			string text2 = ((Object)val.GetCharacter()).name.Replace("(Clone)", "");
			if (val2.localPosition != localPosition || flag)
			{
				Vector3 val4 = val2.localPosition - localPosition;
				if (Setup.customMounts.TryGetValue(text2, out var value2))
				{
					string text3 = text2 + " Saddle Position = ";
					if (adjustMode == AdjustMode.Mount)
					{
						text3 = text2 + " Mount Point = ";
					}
					string text4 = Setup.StringVec(val2.localPosition);
					Debug.Log((object)(text3 + text4));
				}
				if (adjustMode == AdjustMode.Mount)
				{
					Mount mount = value2;
					mount.mountPoint += val4;
				}
				else if (adjustMode == AdjustMode.Saddle)
				{
					Mount mount2 = value2;
					mount2.saddlePos += val4;
				}
			}
			else if (val2.localEulerAngles != localEulerAngles || flag2)
			{
				if (Setup.customMounts.TryGetValue(text2, out var value3))
				{
					string text5 = "Saddle Rotation = ";
					string text6 = Setup.StringVec(val2.localEulerAngles - Setup.rotationAdjust);
					Debug.Log((object)(text5 + text6));
				}
				value3.saddleRotation = val2.localEulerAngles - Setup.rotationAdjust;
			}
			if (((KeyboardShortcut)(ref Setup.saveMountKeys)).IsDown())
			{
				((Character)__instance).Message((MessageType)2, "Saving " + text2 + " to MountUp YML", 0, (Sprite)null);
				if (!Setup.AddFullMountToYaml.Contains(text2))
				{
					Setup.AddFullMountToYaml.Add(text2);
				}
				Setup.writeYML();
			}
		}

		private static bool rotateTransform(Transform transform, float num)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_005d: 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_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_00aa: 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_00d1: 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)
			bool result = false;
			if (Input.GetKeyDown((KeyCode)275))
			{
				transform.Rotate((0f - num) * Vector3.forward);
				result = true;
			}
			if (Input.GetKeyDown((KeyCode)276))
			{
				transform.Rotate(num * Vector3.forward);
				result = true;
			}
			if (Input.GetKeyDown((KeyCode)273))
			{
				transform.Rotate(num * Vector3.right);
				result = true;
			}
			if (Input.GetKeyDown((KeyCode)274))
			{
				transform.Rotate((0f - num) * Vector3.right);
				result = true;
			}
			if (Input.GetKeyDown((KeyCode)280))
			{
				transform.Rotate(num * Vector3.up);
				result = true;
			}
			if (Input.GetKeyDown((KeyCode)281))
			{
				transform.Rotate((0f - num) * Vector3.up);
				result = true;
			}
			return result;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TeleportWorldTrigger), "OnTriggerEnter")]
		private static void TeleportWorldTriggerOnTriggerEnter_Patch(TeleportWorldTrigger __instance, Collider colliderIn)
		{
			if (!Setup.teleportMounts.Value)
			{
				return;
			}
			Tameable component = ((Component)colliderIn).GetComponent<Tameable>();
			if (!((Object)(object)component != (Object)null) || !component.m_character.IsTamed() || !component.HaveRider())
			{
				return;
			}
			long user = component.m_saddle.GetUser();
			if (!component.m_saddle.HaveValidUser())
			{
				return;
			}
			ZDO val = null;
			foreach (ZDO allCharacterZDO in ZNet.instance.GetAllCharacterZDOS())
			{
				if (((ZDOID)(ref allCharacterZDO.m_uid)).UserID == user)
				{
					val = allCharacterZDO;
				}
			}
			if (val == null)
			{
				return;
			}
			GameObject gameObject = ((Component)ZNetScene.instance.FindInstance(val)).gameObject;
			if (!((Object)(object)gameObject == (Object)null))
			{
				Player component2 = gameObject.GetComponent<Player>();
				if (!((Object)(object)component2 == (Object)null) && !((Object)(object)Player.m_localPlayer != (Object)(object)component2))
				{
					__instance.m_teleportWorld.Teleport(component2);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TeleportWorld), "Teleport")]
		private static void TeleportWorldTeleport_Patch(Player player)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (Setup.teleportMounts.Value)
			{
				IDoodadController doodadController = player.GetDoodadController();
				Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null);
				if ((Object)(object)val != (Object)null)
				{
					val.m_speed = (Speed)0;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "UpdateTeleport")]
		[HarmonyPostfix]
		private static void PlayerUpdateTeleport_Patch(ref bool ___m_teleporting, ref float ___m_teleportTimer, ref Vector3 ___m_teleportTargetPos, ref Quaternion ___m_teleportTargetRot, Player __instance)
		{
			//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_004b: 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)
			//IL_0076: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			if ((Setup.teleportMounts.Value & ___m_teleporting) && (double)___m_teleportTimer > 2.0)
			{
				IDoodadController doodadController = __instance.m_doodadController;
				Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null);
				if ((Object)(object)val != (Object)null)
				{
					_ = __instance.m_teleportTargetRot * Vector3.forward;
					((Component)val.GetCharacter()).transform.position = __instance.m_teleportTargetPos;
					((Component)val.GetCharacter()).transform.rotation = __instance.m_teleportTargetRot;
					val.GetCharacter().m_body.velocity = Vector3.zero;
					val.m_speed = (Speed)0;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "Interact", new Type[]
		{
			typeof(GameObject),
			typeof(bool),
			typeof(bool)
		})]
		[HarmonyPostfix]
		private static void PlayerInteract_Patch(GameObject go, bool hold, bool alt, ref float ___m_lastHoverInteractTime, Player __instance)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//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_00e0: 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_0125: Unknown result type (might be due to invalid IL or missing references)
			Player componentInParent = go.GetComponentInParent<Player>();
			if ((Object)(object)componentInParent != (Object)null && Setup.canMountPlayer.Value && alt)
			{
				___m_lastHoverInteractTime = Time.time;
				GameObject visual = ((Character)componentInParent).GetVisual();
				if (((Object)((Component)visual.transform.GetChild(visual.transform.childCount - 1)).gameObject).name.Equals("MountPoint"))
				{
					Transform child = visual.transform.GetChild(visual.transform.childCount - 1);
					child.parent = null;
					Object.Destroy((Object)(object)((Component)child).gameObject);
				}
				GameObject val = new GameObject("MountPoint");
				val.transform.parent = visual.transform;
				Vector3 localPosition = default(Vector3);
				((Vector3)(ref localPosition))..ctor(0f, 0.6997871f, -0.2250879f);
				Quaternion rotation = visual.transform.rotation;
				val.transform.rotation = rotation;
				val.transform.localPosition = localPosition;
				Transform transform = val.transform;
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(0f, 0f, 0f);
				string text = "attach_chair";
				((Character)__instance).AttachStart(transform, visual, false, false, false, text, val2, (Transform)null);
			}
		}

		public static bool HasSwimDrain(float swimDrain)
		{
			return swimDrain > 0f;
		}

		[HarmonyPatch(typeof(Sadle), "UpdateDrown")]
		[HarmonyPrefix]
		private static bool SadleUpdateDrown_Patch(Sadle __instance)
		{
			if (__instance.m_swimStaminaDrain > 0f && Setup.mountsCanDrown.Value)
			{
				return true;
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Sadle), "UpdateStamina")]
		private static void SadleUpdateStamina_Patch(Sadle __instance, float dt)
		{
			Character character = __instance.m_character;
			if (!Object.op_Implicit((Object)(object)character))
			{
				return;
			}
			Mountable component = ((Component)character).GetComponent<Mountable>();
			float stamina = __instance.GetStamina();
			if (Object.op_Implicit((Object)(object)component) && __instance.HaveValidUser() && character.m_flying)
			{
				float num = stamina - dt * component.getFlyStaminaDrain();
				if (num < 0f)
				{
					character.Land();
					num = 0f;
				}
				__instance.SetStamina(num);
			}
			if (__instance.m_staminaRegenTimer > 0f || character.InAttack() || (character.IsSwimming() && __instance.m_swimStaminaDrain > 0f))
			{
				return;
			}
			float maxStamina = __instance.GetMaxStamina();
			if (stamina < maxStamina || stamina > maxStamina)