Decompiled source of KCCDownpatcher v1.1.1

plugins/KCCDownplugin.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dolso;
using HG.Reflection;
using KinematicCharacterController;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace Dolso
{
	internal static class log
	{
		private static readonly ManualLogSource logger = Logger.CreateLogSource(Assembly.GetExecutingAssembly().GetName().Name);

		internal static void info(object data)
		{
			logger.LogInfo(data);
		}

		internal static void message(object data)
		{
			logger.LogMessage(data);
		}

		internal static void warning(object data)
		{
			logger.LogWarning(data);
		}

		internal static void error(object data)
		{
			logger.LogError(data);
		}

		internal static void fatal(object data)
		{
			logger.LogFatal(data);
		}

		internal static void LogError(this ILCursor c, object data)
		{
			logger.LogError((object)$"ILCursor failure, skipping: {data}\n{c}");
		}

		internal static void LogErrorCaller(this ILCursor c, object data)
		{
			logger.LogError((object)$"ILCursor failed in {new StackFrame(1).GetMethod().Name}, skipping: {data}\n{c}");
		}
	}
	internal static class HookManager
	{
		internal delegate bool ConfigEnabled<T>(T configValue);

		private class HookedConfig<T>
		{
			private readonly ConfigEnabled<T> enabled;

			private readonly IDetour detour;

			internal HookedConfig(ConfigEntry<T> configEntry, ConfigEnabled<T> enabled, IDetour detour)
			{
				this.enabled = enabled;
				this.detour = detour;
				configEntry.SettingChanged += ConfigChanged;
				ConfigChanged(configEntry, null);
			}

			private void ConfigChanged(object sender, EventArgs args)
			{
				if (enabled(((ConfigEntry<T>)sender).Value))
				{
					if (!detour.IsApplied)
					{
						detour.Apply();
					}
				}
				else if (detour.IsApplied)
				{
					detour.Undo();
				}
			}
		}

		internal const BindingFlags allFlags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly ConfigEnabled<bool> boolConfigEnabled = BoolEnabled;

		private static ILHookConfig ilHookConfig = new ILHookConfig
		{
			ManualApply = true
		};

		private static HookConfig onHookConfig = new HookConfig
		{
			ManualApply = true
		};

		internal static void Hook(Type typeFrom, string fromMethod, Manipulator ilHook)
		{
			Hook(GetMethod(typeFrom, fromMethod), ilHook);
		}

		internal static void Hook(Delegate fromMethod, Manipulator ilHook)
		{
			Hook(fromMethod.Method, ilHook);
		}

		internal static void Hook(MethodBase fromMethod, Manipulator ilHook)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				new ILHook(fromMethod, ilHook, ref ilHookConfig).Apply();
			}
			catch (Exception e)
			{
				e.LogHookError(fromMethod, ((Delegate)(object)ilHook).Method);
			}
		}

		internal static void Hook(Type typeFrom, string fromMethod, Delegate onHook)
		{
			Hook(GetMethod(typeFrom, fromMethod), onHook.Method, onHook.Target);
		}

		internal static void Hook(Delegate fromMethod, Delegate onHook)
		{
			Hook(fromMethod.Method, onHook.Method, onHook.Target);
		}

		internal static void Hook(MethodBase fromMethod, Delegate onHook)
		{
			Hook(fromMethod, onHook.Method, onHook.Target);
		}

		internal static void Hook(MethodBase fromMethod, MethodInfo onHook, object target = null)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				new Hook(fromMethod, onHook, target, ref onHookConfig).Apply();
			}
			catch (Exception e)
			{
				e.LogHookError(fromMethod, onHook);
			}
		}

		internal static void HookConfig(this ConfigEntry<bool> configEntry, Type typeFrom, string fromMethod, Delegate hook)
		{
			configEntry.HookConfig(boolConfigEnabled, GetMethod(typeFrom, fromMethod), hook.Method, hook.Target);
		}

		internal static void HookConfig(this ConfigEntry<bool> configEntry, MethodBase fromMethod, Delegate hook)
		{
			configEntry.HookConfig(boolConfigEnabled, fromMethod, hook.Method, hook.Target);
		}

		internal static void HookConfig(this ConfigEntry<bool> configEntry, MethodBase fromMethod, MethodInfo hook)
		{
			configEntry.HookConfig(boolConfigEnabled, fromMethod, hook);
		}

		internal static void HookConfig<T>(this ConfigEntry<T> configEntry, ConfigEnabled<T> enabled, Type typeFrom, string fromMethod, Delegate hook)
		{
			configEntry.HookConfig(enabled, GetMethod(typeFrom, fromMethod), hook.Method, hook.Target);
		}

		internal static void HookConfig<T>(this ConfigEntry<T> configEntry, ConfigEnabled<T> enabled, MethodBase fromMethod, Delegate hook)
		{
			configEntry.HookConfig(enabled, fromMethod, hook.Method, hook.Target);
		}

		internal static void HookConfig<T>(this ConfigEntry<T> configEntry, ConfigEnabled<T> enabled, MethodBase fromMethod, MethodInfo hook, object target = null)
		{
			try
			{
				new HookedConfig<T>(configEntry, enabled, ManualDetour(fromMethod, hook, target));
			}
			catch (Exception e)
			{
				e.LogHookError(fromMethod, hook);
			}
		}

		internal static IDetour ManualDetour(Type typeFrom, string fromMethod, Delegate hook)
		{
			return ManualDetour(GetMethod(typeFrom, fromMethod), hook.Method, hook.Target);
		}

		internal static IDetour ManualDetour(MethodBase fromMethod, Delegate hook)
		{
			return ManualDetour(fromMethod, hook.Method, hook.Target);
		}

		internal static IDetour ManualDetour(MethodBase fromMethod, MethodInfo hook, object target = null)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			try
			{
				ParameterInfo[] parameters = hook.GetParameters();
				if (parameters.Length == 1 && parameters[0].ParameterType == typeof(ILContext))
				{
					return (IDetour)new ILHook(fromMethod, (Manipulator)hook.CreateDelegate(typeof(Manipulator)), ref ilHookConfig);
				}
				return (IDetour)new Hook(fromMethod, hook, target, ref onHookConfig);
			}
			catch (Exception e)
			{
				e.LogHookError(fromMethod, hook);
				return null;
			}
		}

		internal static MethodInfo GetMethod(Type typeFrom, string methodName)
		{
			if (typeFrom == null || methodName == null)
			{
				log.error($"Null argument in GetMethod: type={typeFrom}, name={methodName}");
				return null;
			}
			MethodInfo[] array = (from a in typeFrom.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
				where a.Name == methodName
				select a).ToArray();
			switch (array.Length)
			{
			case 1:
				return array[0];
			case 0:
				log.error($"Failed to find method: {typeFrom}::{methodName}");
				return null;
			default:
			{
				string text = $"{array.Length} ambiguous matches found for: {typeFrom}::{methodName}, may be incorrect";
				MethodInfo[] array2 = array;
				for (int i = 0; i < array2.Length; i++)
				{
					text = text + "\n" + array2[i];
				}
				log.warning(text);
				return array[0];
			}
			}
		}

		internal static MethodInfo GetMethod(Type typeFrom, string methodName, params Type[] parameters)
		{
			if (typeFrom == null || methodName == null)
			{
				log.error($"Null argument in GetMethod: type={typeFrom}, name={methodName}");
				return null;
			}
			MethodInfo? method = typeFrom.GetMethod(methodName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, parameters, null);
			if (method == null)
			{
				log.error($"Failed to find method: {typeFrom}::{methodName}_{parameters.Length}");
			}
			return method;
		}

		internal static void SetPriority(string[] beforeIL = null, string[] beforeOn = null, string[] afterIL = null, string[] afterOn = null)
		{
			ilHookConfig.Before = beforeIL;
			onHookConfig.Before = beforeOn;
			ilHookConfig.After = afterIL;
			onHookConfig.After = afterOn;
		}

		internal static void LogHookError(this Exception e, MethodBase fromMethod, MethodInfo hook)
		{
			log.error((fromMethod == null) ? $"null from-method for hook: {hook.Name}\n{e}" : $"Failed to hook: {fromMethod.DeclaringType}::{fromMethod.Name} - {hook.Name}\n{e}");
		}

		private static bool BoolEnabled(bool configValue)
		{
			return configValue;
		}
	}
	internal static class RiskofOptions
	{
		internal const string RooGuid = "com.rune580.riskofoptions";

		internal static bool enabled => Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");

		internal static void SetSprite(Sprite sprite)
		{
			ModSettingsManager.SetModIcon(sprite);
		}

		internal static void SetSpriteDefaultIcon()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string fullName = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)).FullName;
				Texture2D val = new Texture2D(256, 256);
				if (ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(fullName, "icon.png"))))
				{
					ModSettingsManager.SetModIcon(Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)));
				}
				else
				{
					log.error("Failed to load icon.png");
				}
			}
			catch (Exception ex)
			{
				log.error("Failed to load icon.png\n" + ex);
			}
		}

		internal static void AddOption(ConfigEntryBase entry)
		{
			AddOption(entry, string.Empty, string.Empty);
		}

		internal static void AddOption(ConfigEntryBase entry, string categoryName = "", string name = "", bool restartRequired = false)
		{
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Expected O, but got Unknown
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Expected O, but got Unknown
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			//IL_014a: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Expected O, but got Unknown
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			Type settingType = entry.SettingType;
			object obj;
			if (!(settingType == typeof(float)))
			{
				obj = ((!(settingType == typeof(string))) ? ((!(settingType == typeof(bool))) ? ((!(settingType == typeof(int))) ? ((!(settingType == typeof(Color))) ? ((!(settingType == typeof(KeyboardShortcut))) ? ((object)((!settingType.IsEnum) ? ((ChoiceOption)null) : new ChoiceOption(entry, new ChoiceConfig()))) : ((object)new KeyBindOption((ConfigEntry<KeyboardShortcut>)(object)entry, new KeyBindConfig()))) : ((object)new ColorOption((ConfigEntry<Color>)(object)entry, new ColorOptionConfig()))) : ((object)new IntFieldOption((ConfigEntry<int>)(object)entry, new IntFieldConfig()))) : ((object)new CheckBoxOption((ConfigEntry<bool>)(object)entry, new CheckBoxConfig()))) : ((object)new StringInputFieldOption((ConfigEntry<string>)(object)entry, new InputFieldConfig
				{
					submitOn = (SubmitEnum)6,
					lineType = (LineType)0
				})));
			}
			else if (entry.Description.AcceptableValues is AcceptableValueRange<float>)
			{
				obj = (object)new SliderOption((ConfigEntry<float>)(object)entry, new SliderConfig
				{
					min = ((AcceptableValueRange<float>)(object)entry.Description.AcceptableValues).MinValue,
					max = ((AcceptableValueRange<float>)(object)entry.Description.AcceptableValues).MaxValue,
					FormatString = "{0:f2}",
					description = entry.DescWithDefault("{0:f2}")
				});
			}
			else
			{
				ConfigEntry<float> obj2 = (ConfigEntry<float>)(object)entry;
				FloatFieldConfig val = new FloatFieldConfig();
				((NumericFieldConfig<float>)val).FormatString = "{0:f2}";
				((BaseOptionConfig)val).description = entry.DescWithDefault("{0:f2}");
				obj = (object)new FloatFieldOption(obj2, val);
			}
			BaseOption val2 = (BaseOption)obj;
			if (val2 == null)
			{
				return;
			}
			BaseOptionConfig config = val2.GetConfig();
			config.category = categoryName;
			config.name = name;
			config.restartRequired = restartRequired;
			if (config.description == "")
			{
				config.description = entry.DescWithDefault();
			}
			try
			{
				ModSettingsManager.AddOption(val2);
			}
			catch (Exception arg)
			{
				log.error($"AddOption {entry.Definition} failed\n{arg}");
			}
		}

		internal static void AddOption(ConfigEntry<float> entry, float min, float max, string format = "{0:f2}", string categoryName = "")
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new SliderOption(entry, new SliderConfig
			{
				min = min,
				max = max,
				FormatString = format,
				category = categoryName,
				description = ((ConfigEntryBase)(object)entry).DescWithDefault(format)
			}));
		}

		internal static void AddIntSlider(ConfigEntry<int> entry, int min, int max, string categoryName = "")
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(entry, new IntSliderConfig
			{
				min = min,
				max = max,
				category = categoryName,
				description = ((ConfigEntryBase)(object)entry).DescWithDefault()
			}));
		}

		private static string DescWithDefault(this ConfigEntryBase entry, string format = "{0}")
		{
			return string.Format("{1}\n[Default: " + format + "]", entry.DefaultValue, entry.Description.Description);
		}
	}
}
namespace KCCDownplugin
{
	internal class Config
	{
		private static ConfigFile configFile;

		internal static ConfigEntry<string> oldKccBlacklistConfig;

		internal static ConfigEntry<bool> enableOldPotRolling;

		internal static void DoConfig(ConfigFile bepConfigFile)
		{
			configFile = bepConfigFile;
			oldKccBlacklistConfig = bepConfigFile.Bind<string>("Kinematic Settings", "Old KCC blacklist", "", "Prevent using old KCC on players for the listed bodies\nSeperated by ', ' or ',', and names must match exactly, use debugtoolkit's list_body command to view them.\nIf an entry is 'all' then will be disabled for all bodies.\n");
			enableOldPotRolling = bepConfigFile.Bind<bool>("Kinematic Settings", "Old Pot Rolling", true, "Changes pot physics material to how it was pre-sots, as the old kcc is not compatible with the new pot physics");
			if (RiskofOptions.enabled)
			{
				DoRiskOfOptions();
			}
		}

		internal static void DoRiskOfOptions()
		{
			RiskofOptions.SetSpriteDefaultIcon();
			RiskofOptions.AddOption((ConfigEntryBase)(object)oldKccBlacklistConfig);
			RiskofOptions.AddOption((ConfigEntryBase)(object)enableOldPotRolling);
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CcReloadConfig(ConCommandArgs args)
		{
			configFile.Reload();
			Debug.Log((object)"KCCDownpatcher config reloaded");
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("dolso.KCCDownplugin", "KCCDownplugin", "1.1.1")]
	public class KCCDownplugin : BaseUnityPlugin
	{
		private static BodyIndex[] oldKccBlacklist;

		private void Awake()
		{
			Config.DoConfig(((BaseUnityPlugin)this).Config);
			Config.oldKccBlacklistConfig.SettingChanged += delegate
			{
				RefreshOldKCCBlacklist();
			};
			Config.enableOldPotRolling.SettingChanged += delegate
			{
				ChangePotPhysics();
			};
			if (Config.enableOldPotRolling.Value)
			{
				ChangePotPhysics();
			}
			HookManager.Hook(typeof(CharacterMotor), "BeforeCharacterUpdate", (Delegate)new Action<Action<CharacterMotor, float>, CharacterMotor, float>(AddSafeMovementCheck_On_BeforeCharacterUpdate_CharacterMotor));
			HookManager.Hook(typeof(PlayerCharacterMasterController), "Awake", (Delegate)new Action<Action<PlayerCharacterMasterController>, PlayerCharacterMasterController>(SubscribePlayerBodyStart_On_Awake_PlayerCharacterMasterController));
			HookManager.Hook(typeof(KinematicCharacterSystem), "RegisterCharacterMotor", (Delegate)new Action<Action<KinematicCharacterMotor>, KinematicCharacterMotor>(CheckIfUsingOld_On_Register_KinematicCharacterSystem));
			HookManager.Hook(typeof(KinematicCharacterSystem), "UnregisterCharacterMotor", (Delegate)new Action<Action<KinematicCharacterMotor>, KinematicCharacterMotor>(CheckIfUsingOld_On_Unregister_KinematicCharacterSystem));
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(ApplyConfig));
		}

		private static async void ChangePotPhysics()
		{
			AsyncOperationHandle<GameObject> pot = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/ExplosivePotDestructible/ExplosivePotDestructibleBody.prefab");
			AsyncOperationHandle<PhysicMaterial> physmat = Addressables.LoadAssetAsync<PhysicMaterial>((object)("RoR2/Base/Common/" + (Config.enableOldPotRolling.Value ? "physmatDestructibles" : "physmatBouncy") + ".physicMaterial"));
			await Task.WhenAll(pot.Task, physmat.Task);
			((Collider)pot.Result.GetComponent<MeshCollider>()).material = physmat.Result;
			pot.Release();
			physmat.Release();
		}

		private static void ApplyConfig()
		{
			try
			{
				RefreshOldKCCBlacklist();
			}
			catch (Exception data)
			{
				log.error(data);
				oldKccBlacklist = (BodyIndex[])(object)new BodyIndex[0];
			}
		}

		private static void RefreshOldKCCBlacklist()
		{
			List<KinematicCharacterMotor> list = FindBodies(Config.oldKccBlacklistConfig, gatherAll: false);
			if (list == null)
			{
				oldKccBlacklist = (BodyIndex[])(object)new BodyIndex[1] { (BodyIndex)(-1) };
			}
			else
			{
				oldKccBlacklist = list.Select((KinematicCharacterMotor a) => BodyCatalog.FindBodyIndex(((Component)a).gameObject)).ToArray();
			}
		}

		private static List<KinematicCharacterMotor> FindBodies(ConfigEntry<string> configEntry, bool gatherAll)
		{
			List<KinematicCharacterMotor> list = new List<KinematicCharacterMotor>();
			string[] array = configEntry.Value.Split(new string[2] { ", ", "," }, StringSplitOptions.RemoveEmptyEntries);
			KinematicCharacterMotor item = default(KinematicCharacterMotor);
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text == "all")
				{
					log.info("found all for " + ((ConfigEntryBase)configEntry).Definition.Key);
					if (gatherAll)
					{
						GameObject[] bodyPrefabs = BodyCatalog.bodyPrefabs;
						foreach (GameObject val in bodyPrefabs)
						{
							if (Object.op_Implicit((Object)(object)val) && val.TryGetComponent<KinematicCharacterMotor>(ref item))
							{
								list.Add(item);
							}
						}
						return list;
					}
					return null;
				}
				GameObject val2 = BodyCatalog.FindBodyPrefab(text);
				if (!Object.op_Implicit((Object)(object)val2))
				{
					log.warning("failed to find body '" + text + "'");
					continue;
				}
				KinematicCharacterMotor component = val2.GetComponent<KinematicCharacterMotor>();
				if (!Object.op_Implicit((Object)(object)component))
				{
					log.warning(text + " does not have a KinematicCharacterMotor");
				}
				else
				{
					list.Add(component);
				}
			}
			return list;
		}

		private static void AddSafeMovementCheck_On_BeforeCharacterUpdate_CharacterMotor(Action<CharacterMotor, float> orig, CharacterMotor self, float deltaTime)
		{
			if (!((BaseCharacterController)self).Motor.usingOldKCC)
			{
				orig(self, deltaTime);
				return;
			}
			float sqrMagnitude = ((Vector3)(ref self.rootMotion)).sqrMagnitude;
			if (sqrMagnitude > 0f)
			{
				((BaseCharacterController)self).Motor.SafeMovement = sqrMagnitude >= 1.1736112f;
			}
			orig(self, deltaTime);
			((BaseCharacterController)self).Motor.SafeMovement = ((Vector3)(ref self.velocity)).sqrMagnitude * Time.fixedDeltaTime * Time.fixedDeltaTime >= 1.1736112f;
		}

		private static void SubscribePlayerBodyStart_On_Awake_PlayerCharacterMasterController(Action<PlayerCharacterMasterController> orig, PlayerCharacterMasterController self)
		{
			orig(self);
			self.master.onBodyStart += OnPlayerBodyStart;
		}

		private static void OnPlayerBodyStart(CharacterBody body)
		{
			//IL_0027: 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)
			CharacterMotor characterMotor = body.characterMotor;
			if (!Object.op_Implicit((Object)(object)characterMotor) || (oldKccBlacklist.Length != 0 && ((int)oldKccBlacklist[0] == -1 || oldKccBlacklist.Contains(body.bodyIndex))))
			{
				return;
			}
			if (!Object.op_Implicit((Object)(object)((BaseCharacterController)characterMotor).Motor))
			{
				((BaseCharacterController)characterMotor).SetupCharacterMotor(((Component)characterMotor).GetComponent<KinematicCharacterMotor>());
			}
			if (((BaseCharacterController)characterMotor).Motor.usingOldKCC)
			{
				return;
			}
			if (((Behaviour)((BaseCharacterController)characterMotor).Motor).enabled)
			{
				KinematicCharacterSystem.UnregisterCharacterMotor(((BaseCharacterController)characterMotor).Motor);
				((BaseCharacterController)characterMotor).Motor.usingOldKCC = true;
				OldKinematicCharacterSystem.RegisterCharacterMotor(((BaseCharacterController)characterMotor).Motor);
			}
			else
			{
				((BaseCharacterController)characterMotor).Motor.usingOldKCC = true;
			}
			GameObject bodyPrefab = BodyCatalog.GetBodyPrefab(body.bodyIndex);
			if (Object.op_Implicit((Object)(object)bodyPrefab))
			{
				KinematicCharacterMotor component = bodyPrefab.GetComponent<KinematicCharacterMotor>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.usingOldKCC = true;
				}
			}
		}

		private static void CheckIfUsingOld_On_Register_KinematicCharacterSystem(Action<KinematicCharacterMotor> orig, KinematicCharacterMotor motor)
		{
			if (motor.usingOldKCC)
			{
				OldKinematicCharacterSystem.RegisterCharacterMotor(motor);
			}
			else
			{
				orig(motor);
			}
		}

		private static void CheckIfUsingOld_On_Unregister_KinematicCharacterSystem(Action<KinematicCharacterMotor> orig, KinematicCharacterMotor motor)
		{
			if (motor.usingOldKCC)
			{
				OldKinematicCharacterSystem.UnregisterCharacterMotor(motor);
			}
			else
			{
				orig(motor);
			}
		}
	}
	public static class OldKinematicCharacterMotor
	{
		public static KinematicCharacterMotor kcm;

		public const bool PreventSnappingOnLedges = false;

		public const int MaxHitsBudget = 16;

		public const int MaxCollisionBudget = 16;

		public const int MaxGroundingSweepIterations = 2;

		public const int MaxMovementSweepIterations = 6;

		public const int MaxSteppingSweepIterations = 3;

		public const int MaxRigidbodyOverlapsCount = 16;

		public const int MaxDiscreteCollisionIterations = 3;

		public const float CollisionOffset = 0.001f;

		public const float GroundProbeReboundDistance = 0.02f;

		public const float MinimumGroundProbingDistance = 0.005f;

		public const float GroundProbingBackstepDistance = 0.1f;

		public const float SweepProbingBackstepDistance = 0.002f;

		public const float SecondaryProbesVertical = 0.02f;

		public const float SecondaryProbesHorizontal = 0.001f;

		public const float MinVelocityMagnitude = 0.01f;

		public const float SteppingForwardDistance = 0.03f;

		public const float MinDistanceForLedge = 0.05f;

		public const float CorrelationForVerticalObstruction = 0.01f;

		public const float ExtraSteppingForwardDistance = 0.01f;

		public const float ExtraStepHeightPadding = 0.01f;

		public static void UpdatePhase1(float deltaTime)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: 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_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: 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_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: 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_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ee: 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_067a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: 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_0695: Unknown result type (might be due to invalid IL or missing references)
			//IL_0696: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06db: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_063c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0646: Unknown result type (might be due to invalid IL or missing references)
			//IL_064b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0650: Unknown result type (might be due to invalid IL or missing references)
			//IL_065b: 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_0661: Unknown result type (might be due to invalid IL or missing references)
			//IL_0666: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: 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_0838: Unknown result type (might be due to invalid IL or missing references)
			//IL_0842: Unknown result type (might be due to invalid IL or missing references)
			//IL_0848: Unknown result type (might be due to invalid IL or missing references)
			//IL_084d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0852: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0826: Unknown result type (might be due to invalid IL or missing references)
			//IL_082b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0800: Unknown result type (might be due to invalid IL or missing references)
			//IL_080f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0815: Unknown result type (might be due to invalid IL or missing references)
			//IL_081a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0774: Unknown result type (might be due to invalid IL or missing references)
			//IL_077e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0788: Unknown result type (might be due to invalid IL or missing references)
			//IL_078d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0792: Unknown result type (might be due to invalid IL or missing references)
			//IL_0797: Unknown result type (might be due to invalid IL or missing references)
			if (float.IsNaN(kcm.BaseVelocity.x) || float.IsNaN(kcm.BaseVelocity.y) || float.IsNaN(kcm.BaseVelocity.z))
			{
				kcm.BaseVelocity = Vector3.zero;
			}
			if (float.IsNaN(kcm._attachedRigidbodyVelocity.x) || float.IsNaN(kcm._attachedRigidbodyVelocity.y) || float.IsNaN(kcm._attachedRigidbodyVelocity.z))
			{
				kcm._attachedRigidbodyVelocity = Vector3.zero;
			}
			if (kcm._mustUngroundTimeCounter > 0f)
			{
				kcm._mustUngroundTimeCounter = 0f;
			}
			kcm.CharacterController.BeforeCharacterUpdate(deltaTime);
			kcm._transientPosition = kcm._transform.position;
			kcm.TransientRotation = kcm._transform.rotation;
			kcm._initialSimulationPosition = kcm._transientPosition;
			kcm._initialSimulationRotation = kcm.TransientRotation;
			kcm._rigidbodyProjectionHitCount = 0;
			kcm._overlapsCount = 0;
			kcm._lastSolvedOverlapNormalDirty = false;
			if (kcm._movePositionDirty)
			{
				if (kcm._solveMovementCollisions)
				{
					if (InternalCharacterMove(kcm._movePositionTarget - kcm._transientPosition, deltaTime, out kcm._internalResultingMovementMagnitude, out kcm._internalResultingMovementDirection) && kcm.InteractiveRigidbodyHandling)
					{
						Vector3 zero = Vector3.zero;
						kcm.ProcessVelocityForRigidbodyHits(ref zero, deltaTime);
					}
				}
				else
				{
					kcm._transientPosition = kcm._movePositionTarget;
				}
				kcm._movePositionDirty = false;
			}
			((CharacterTransientGroundingReport)(ref kcm.LastGroundingStatus)).CopyFrom(kcm.GroundingStatus);
			kcm.GroundingStatus = default(CharacterGroundingReport);
			kcm.GroundingStatus.GroundNormal = kcm._characterUp;
			if (kcm._solveMovementCollisions)
			{
				Vector3 val = kcm._cachedWorldUp;
				float num = 0f;
				int i = 0;
				bool flag = false;
				for (; i < 3; i++)
				{
					if (flag)
					{
						break;
					}
					int num2 = kcm.CharacterCollisionsOverlap(kcm._transientPosition, kcm.TransientRotation, kcm._internalProbedColliders, 0f, false);
					if (num2 > 0)
					{
						for (int j = 0; j < num2; j++)
						{
							Rigidbody attachedRigidbody = kcm._internalProbedColliders[j].attachedRigidbody;
							if (Object.op_Implicit((Object)(object)attachedRigidbody) && (!attachedRigidbody.isKinematic || Object.op_Implicit((Object)(object)((Component)attachedRigidbody).GetComponent<PhysicsMover>())))
							{
								continue;
							}
							Transform component = ((Component)kcm._internalProbedColliders[j]).GetComponent<Transform>();
							if (Physics.ComputePenetration((Collider)(object)kcm.Capsule, kcm._transientPosition, kcm.TransientRotation, kcm._internalProbedColliders[j], component.position, component.rotation, ref val, ref num))
							{
								HitStabilityReport val2 = default(HitStabilityReport);
								val2.IsStable = kcm.IsStableOnNormal(val);
								val = kcm.GetObstructionNormal(val, val2.IsStable);
								Vector3 val3 = val * (num + 0.001f);
								KinematicCharacterMotor obj = kcm;
								obj._transientPosition += val3;
								if (kcm._overlapsCount < kcm._overlaps.Length)
								{
									kcm._overlaps[kcm._overlapsCount] = new OverlapResult(val, kcm._internalProbedColliders[j]);
									KinematicCharacterMotor obj2 = kcm;
									obj2._overlapsCount++;
								}
								break;
							}
						}
					}
					else
					{
						flag = true;
					}
				}
			}
			if (kcm._solveGrounding)
			{
				if (kcm._mustUnground)
				{
					KinematicCharacterMotor obj3 = kcm;
					obj3._transientPosition += kcm._characterUp * 0.0075f;
				}
				else
				{
					float probingDistance = 0.005f;
					if (!kcm.LastGroundingStatus.SnappingPrevented && (kcm.LastGroundingStatus.IsStableOnGround || kcm.LastMovementIterationFoundAnyGround))
					{
						probingDistance = (((int)kcm.StepHandling == 0) ? kcm.CapsuleRadius : Mathf.Max(kcm.CapsuleRadius, kcm.MaxStepHeight));
						probingDistance += kcm.GroundDetectionExtraDistance;
					}
					ProbeGround(ref kcm._transientPosition, kcm.TransientRotation, probingDistance, ref kcm.GroundingStatus);
				}
			}
			kcm.LastMovementIterationFoundAnyGround = false;
			kcm._mustUnground = false;
			if (kcm._solveGrounding)
			{
				kcm.CharacterController.PostGroundingUpdate(deltaTime);
			}
			if (!kcm.InteractiveRigidbodyHandling)
			{
				return;
			}
			kcm._lastAttachedRigidbody = kcm._attachedRigidbody;
			if (Object.op_Implicit((Object)(object)kcm.AttachedRigidbodyOverride))
			{
				kcm._attachedRigidbody = kcm.AttachedRigidbodyOverride;
			}
			else if (kcm.GroundingStatus.IsStableOnGround && Object.op_Implicit((Object)(object)kcm.GroundingStatus.GroundCollider.attachedRigidbody))
			{
				Rigidbody interactiveRigidbody = kcm.GetInteractiveRigidbody(kcm.GroundingStatus.GroundCollider);
				if (Object.op_Implicit((Object)(object)interactiveRigidbody))
				{
					kcm._attachedRigidbody = interactiveRigidbody;
				}
			}
			else
			{
				kcm._attachedRigidbody = null;
			}
			Vector3 zero2 = Vector3.zero;
			Vector3 zero3 = Vector3.zero;
			if (Object.op_Implicit((Object)(object)kcm._attachedRigidbody))
			{
				kcm.GetVelocityFromRigidbodyMovement(kcm._attachedRigidbody, kcm._transientPosition, deltaTime, ref zero2, ref zero3);
			}
			if (kcm.PreserveAttachedRigidbodyMomentum && (Object)(object)kcm._lastAttachedRigidbody != (Object)null && (Object)(object)kcm._attachedRigidbody != (Object)(object)kcm._lastAttachedRigidbody)
			{
				KinematicCharacterMotor obj4 = kcm;
				obj4.BaseVelocity += kcm._attachedRigidbodyVelocity;
				KinematicCharacterMotor obj5 = kcm;
				obj5.BaseVelocity -= zero2;
			}
			kcm._attachedRigidbodyVelocity = kcm._cachedZeroVector;
			if (Object.op_Implicit((Object)(object)kcm._attachedRigidbody))
			{
				kcm._attachedRigidbodyVelocity = zero2;
				Vector3 val4 = Vector3.ProjectOnPlane(Quaternion.Euler(57.29578f * deltaTime * zero3) * kcm._characterForward, kcm._characterUp);
				Vector3 normalized = ((Vector3)(ref val4)).normalized;
				kcm.TransientRotation = Quaternion.LookRotation(normalized, kcm._characterUp);
			}
			if (Object.op_Implicit((Object)(object)kcm.GroundingStatus.GroundCollider) && Object.op_Implicit((Object)(object)kcm.GroundingStatus.GroundCollider.attachedRigidbody) && (Object)(object)kcm.GroundingStatus.GroundCollider.attachedRigidbody == (Object)(object)kcm._attachedRigidbody && (Object)(object)kcm._attachedRigidbody != (Object)null && (Object)(object)kcm._lastAttachedRigidbody == (Object)null)
			{
				KinematicCharacterMotor obj6 = kcm;
				obj6.BaseVelocity -= Vector3.ProjectOnPlane(kcm._attachedRigidbodyVelocity, kcm._characterUp);
			}
			if (!(((Vector3)(ref kcm._attachedRigidbodyVelocity)).sqrMagnitude > 0f))
			{
				return;
			}
			kcm._isMovingFromAttachedRigidbody = true;
			if (kcm._solveMovementCollisions)
			{
				if (InternalCharacterMove(kcm._attachedRigidbodyVelocity * deltaTime, deltaTime, out kcm._internalResultingMovementMagnitude, out kcm._internalResultingMovementDirection))
				{
					kcm._attachedRigidbodyVelocity = kcm._internalResultingMovementDirection * kcm._internalResultingMovementMagnitude / deltaTime;
				}
				else
				{
					kcm._attachedRigidbodyVelocity = Vector3.zero;
				}
			}
			else
			{
				KinematicCharacterMotor obj7 = kcm;
				obj7._transientPosition += kcm._attachedRigidbodyVelocity * deltaTime;
			}
			kcm._isMovingFromAttachedRigidbody = false;
		}

		public static void UpdatePhase2(float deltaTime)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_045e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0463: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0505: Unknown result type (might be due to invalid IL or missing references)
			//IL_050b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0510: Unknown result type (might be due to invalid IL or missing references)
			//IL_0515: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_0498: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0551: Unknown result type (might be due to invalid IL or missing references)
			//IL_055b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0565: Unknown result type (might be due to invalid IL or missing references)
			//IL_056a: 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_057e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0583: Unknown result type (might be due to invalid IL or missing references)
			//IL_0588: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: 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_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			kcm.CharacterController.UpdateRotation(ref kcm._transientRotation, deltaTime);
			kcm.TransientRotation = kcm._transientRotation;
			if (kcm._moveRotationDirty)
			{
				kcm.TransientRotation = kcm._moveRotationTarget;
				kcm._moveRotationDirty = false;
			}
			if (kcm._solveMovementCollisions && kcm.InteractiveRigidbodyHandling)
			{
				if (kcm.InteractiveRigidbodyHandling && Object.op_Implicit((Object)(object)kcm._attachedRigidbody))
				{
					float radius = kcm.Capsule.radius;
					RaycastHit val = default(RaycastHit);
					if (kcm.CharacterGroundSweep(kcm._transientPosition + kcm._characterUp * radius, kcm.TransientRotation, -kcm._characterUp, radius, ref val) && (Object)(object)((RaycastHit)(ref val)).collider.attachedRigidbody == (Object)(object)kcm._attachedRigidbody && kcm.IsStableOnNormal(((RaycastHit)(ref val)).normal))
					{
						float num = radius - ((RaycastHit)(ref val)).distance;
						kcm._transientPosition = kcm._transientPosition + kcm._characterUp * num + kcm._characterUp * 0.001f;
					}
				}
				if (kcm.SafeMovement || kcm.InteractiveRigidbodyHandling)
				{
					Vector3 val2 = kcm._cachedWorldUp;
					float num2 = 0f;
					int i = 0;
					bool flag = false;
					for (; i < 3; i++)
					{
						if (flag)
						{
							break;
						}
						int num3 = kcm.CharacterCollisionsOverlap(kcm._transientPosition, kcm.TransientRotation, kcm._internalProbedColliders, 0f, false);
						if (num3 > 0)
						{
							for (int j = 0; j < num3; j++)
							{
								Transform component = ((Component)kcm._internalProbedColliders[j]).GetComponent<Transform>();
								if (!Physics.ComputePenetration((Collider)(object)kcm.Capsule, kcm._transientPosition, kcm.TransientRotation, kcm._internalProbedColliders[j], component.position, component.rotation, ref val2, ref num2))
								{
									continue;
								}
								HitStabilityReport val3 = default(HitStabilityReport);
								val3.IsStable = kcm.IsStableOnNormal(val2);
								val2 = kcm.GetObstructionNormal(val2, val3.IsStable);
								Vector3 val4 = val2 * (num2 + 0.001f);
								KinematicCharacterMotor obj = kcm;
								obj._transientPosition += val4;
								if (kcm.InteractiveRigidbodyHandling)
								{
									Rigidbody attachedRigidbody = kcm._internalProbedColliders[j].attachedRigidbody;
									if (Object.op_Implicit((Object)(object)attachedRigidbody))
									{
										PhysicsMover component2 = ((Component)attachedRigidbody).GetComponent<PhysicsMover>();
										if (Object.op_Implicit((Object)(object)component2) && Object.op_Implicit((Object)(object)attachedRigidbody) && (!attachedRigidbody.isKinematic || Object.op_Implicit((Object)(object)component2)))
										{
											HitStabilityReport val5 = default(HitStabilityReport);
											val5.IsStable = kcm.IsStableOnNormal(val2);
											if (val5.IsStable)
											{
												kcm.LastMovementIterationFoundAnyGround = val5.IsStable;
											}
											if (Object.op_Implicit((Object)(object)component2.Rigidbody) && (Object)(object)component2.Rigidbody != (Object)(object)kcm._attachedRigidbody)
											{
												_ = kcm._transientPosition + kcm.TransientRotation * kcm._characterTransformToCapsuleCenter;
												Vector3 transientPosition = kcm._transientPosition;
												kcm.StoreRigidbodyHit(component2.Rigidbody, kcm.Velocity, transientPosition, val2, val5);
											}
										}
									}
								}
								if (kcm._overlapsCount < kcm._overlaps.Length)
								{
									kcm._overlaps[kcm._overlapsCount] = new OverlapResult(val2, kcm._internalProbedColliders[j]);
									KinematicCharacterMotor obj2 = kcm;
									obj2._overlapsCount++;
								}
								break;
							}
						}
						else
						{
							flag = true;
						}
					}
				}
			}
			kcm.CharacterController.UpdateVelocity(ref kcm.BaseVelocity, deltaTime);
			if (((Vector3)(ref kcm.BaseVelocity)).magnitude < 0.01f)
			{
				kcm.BaseVelocity = Vector3.zero;
			}
			if (((Vector3)(ref kcm.BaseVelocity)).sqrMagnitude > 0f)
			{
				if (kcm._solveMovementCollisions)
				{
					if (InternalCharacterMove(kcm.BaseVelocity * deltaTime, deltaTime, out kcm._internalResultingMovementMagnitude, out kcm._internalResultingMovementDirection))
					{
						kcm.BaseVelocity = kcm._internalResultingMovementDirection * kcm._internalResultingMovementMagnitude / deltaTime;
					}
					else
					{
						kcm.BaseVelocity = Vector3.zero;
					}
				}
				else
				{
					KinematicCharacterMotor obj3 = kcm;
					obj3._transientPosition += kcm.BaseVelocity * deltaTime;
				}
			}
			if (kcm.InteractiveRigidbodyHandling)
			{
				kcm.ProcessVelocityForRigidbodyHits(ref kcm.BaseVelocity, deltaTime);
			}
			if (kcm.HasPlanarConstraint)
			{
				kcm._transientPosition = kcm._initialSimulationPosition + Vector3.ProjectOnPlane(kcm._transientPosition - kcm._initialSimulationPosition, ((Vector3)(ref kcm.PlanarConstraintAxis)).normalized);
			}
			if (kcm.DiscreteCollisionEvents)
			{
				int num4 = kcm.CharacterCollisionsOverlap(kcm._transientPosition, kcm.TransientRotation, kcm._internalProbedColliders, 0.002f, false);
				for (int k = 0; k < num4; k++)
				{
					kcm.CharacterController.OnDiscreteCollisionDetected(kcm._internalProbedColliders[k]);
				}
			}
			kcm.CharacterController.AfterCharacterUpdate(deltaTime);
		}

		private static void ProbeGround(ref Vector3 probingPosition, Quaternion atRotation, float probingDistance, ref CharacterGroundingReport groundingReport)
		{
			//IL_0013: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: 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_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: 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_01b2: 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)
			if (probingDistance < 0.005f)
			{
				probingDistance = 0.005f;
			}
			int num = 0;
			RaycastHit val = default(RaycastHit);
			bool flag = false;
			Vector3 val2 = probingPosition;
			Vector3 val3 = atRotation * -kcm._cachedWorldUp;
			float num2 = probingDistance;
			while (num2 > 0f && num <= 2 && !flag)
			{
				if (kcm.CharacterGroundSweep(val2, atRotation, val3, num2, ref val))
				{
					Vector3 val4 = val2 + val3 * ((RaycastHit)(ref val)).distance;
					HitStabilityReport val5 = default(HitStabilityReport);
					kcm.EvaluateHitStability(((RaycastHit)(ref val)).collider, ((RaycastHit)(ref val)).normal, ((RaycastHit)(ref val)).point, val4, kcm.TransientRotation, kcm.BaseVelocity, ref val5);
					if (val5.LedgeDetected && val5.IsOnEmptySideOfLedge && val5.DistanceFromLedge > kcm.MaxStableDistanceFromLedge)
					{
						val5.IsStable = false;
					}
					groundingReport.FoundAnyGround = true;
					groundingReport.GroundNormal = ((RaycastHit)(ref val)).normal;
					groundingReport.InnerGroundNormal = val5.InnerNormal;
					groundingReport.OuterGroundNormal = val5.OuterNormal;
					groundingReport.GroundCollider = ((RaycastHit)(ref val)).collider;
					groundingReport.GroundPoint = ((RaycastHit)(ref val)).point;
					groundingReport.SnappingPrevented = false;
					if (val5.IsStable)
					{
						if (kcm.LedgeAndDenivelationHandling && kcm.LastGroundingStatus.FoundAnyGround && ((Vector3)(ref val5.InnerNormal)).sqrMagnitude != 0f && ((Vector3)(ref val5.OuterNormal)).sqrMagnitude != 0f)
						{
							if (Vector3.Angle(val5.InnerNormal, val5.OuterNormal) > kcm.MaxStableDenivelationAngle)
							{
								groundingReport.SnappingPrevented = true;
							}
							else if (Vector3.Angle(kcm.LastGroundingStatus.InnerGroundNormal, val5.OuterNormal) > kcm.MaxStableDenivelationAngle)
							{
								groundingReport.SnappingPrevented = true;
							}
						}
						groundingReport.IsStableOnGround = true;
						if (!groundingReport.SnappingPrevented)
						{
							val4 += -val3 * 0.001f;
							InternalMoveCharacterPosition(ref probingPosition, val4, atRotation);
						}
						kcm.CharacterController.OnGroundHit(((RaycastHit)(ref val)).collider, ((RaycastHit)(ref val)).normal, ((RaycastHit)(ref val)).point, ref val5);
						flag = true;
					}
					else
					{
						Vector3 val6 = val3 * ((RaycastHit)(ref val)).distance + atRotation * Vector3.up * Mathf.Clamp(0.001f, 0f, ((RaycastHit)(ref val)).distance);
						val2 += val6;
						num2 = Mathf.Min(0.02f, Mathf.Clamp(num2 - ((Vector3)(ref val6)).magnitude, 0f, float.PositiveInfinity));
						Vector3 val7 = Vector3.ProjectOnPlane(val3, ((RaycastHit)(ref val)).normal);
						val3 = ((Vector3)(ref val7)).normalized;
					}
				}
				else
				{
					flag = true;
				}
				num++;
			}
		}

		private static bool InternalCharacterMove(Vector3 movement, float deltaTime, out float resultingMovementMagnitude, out Vector3 resultingMovementDirection)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: 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_044f: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_046e: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: 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_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: 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_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c5: 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_03d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			kcm._rigidbodiesPushedCount = 0;
			bool result = true;
			Vector3 remainingMovementDirection = ((Vector3)(ref movement)).normalized;
			float remainingMovementMagnitude = ((Vector3)(ref movement)).magnitude;
			resultingMovementDirection = remainingMovementDirection;
			resultingMovementMagnitude = remainingMovementMagnitude;
			int num = 0;
			bool flag = true;
			Vector3 val = kcm._transientPosition;
			Vector3 transientPosition = kcm._transientPosition;
			Vector3 normalized = ((Vector3)(ref movement)).normalized;
			Vector3 previousObstructionNormal = kcm._cachedZeroVector;
			MovementSweepState sweepState = (MovementSweepState)0;
			for (int i = 0; i < kcm._overlapsCount; i++)
			{
				if (Vector3.Dot(remainingMovementDirection, kcm._overlaps[i].Normal) < 0f)
				{
					InternalHandleMovementProjection(kcm.IsStableOnNormal(kcm._overlaps[i].Normal) && !kcm._mustUnground, kcm._overlaps[i].Normal, kcm._overlaps[i].Normal, normalized, ref sweepState, ref previousObstructionNormal, ref resultingMovementMagnitude, ref remainingMovementDirection, ref remainingMovementMagnitude);
				}
			}
			RaycastHit val2 = default(RaycastHit);
			RaycastHit val6 = default(RaycastHit);
			while (remainingMovementMagnitude > 0f && num <= 6 && flag)
			{
				if (kcm.CharacterCollisionsSweep(val, kcm.TransientRotation, remainingMovementDirection, remainingMovementMagnitude + 0.001f, ref val2, kcm._internalCharacterHits, 0f, false) > 0)
				{
					transientPosition = val + remainingMovementDirection * ((RaycastHit)(ref val2)).distance + ((RaycastHit)(ref val2)).normal * 0.001f;
					Vector3 val3 = transientPosition - val;
					HitStabilityReport stabilityReport = default(HitStabilityReport);
					EvaluateHitStability(((RaycastHit)(ref val2)).collider, ((RaycastHit)(ref val2)).normal, ((RaycastHit)(ref val2)).point, transientPosition, kcm.TransientRotation, ref stabilityReport);
					bool flag2 = false;
					if (kcm._solveGrounding && (int)kcm.StepHandling != 0 && stabilityReport.ValidStepDetected && Mathf.Abs(Vector3.Dot(((RaycastHit)(ref val2)).normal, kcm._characterUp)) <= 0.01f)
					{
						Vector3 val4 = Vector3.ProjectOnPlane(-((RaycastHit)(ref val2)).normal, kcm._characterUp);
						Vector3 normalized2 = ((Vector3)(ref val4)).normalized;
						Vector3 val5 = transientPosition + normalized2 * 0.03f + kcm._characterUp * kcm.MaxStepHeight;
						int num2 = kcm.CharacterCollisionsSweep(val5, kcm.TransientRotation, -kcm._characterUp, kcm.MaxStepHeight, ref val6, kcm._internalCharacterHits, 0f, false);
						for (int j = 0; j < num2; j++)
						{
							if ((Object)(object)((RaycastHit)(ref kcm._internalCharacterHits[j])).collider == (Object)(object)stabilityReport.SteppedCollider)
							{
								val = val5 + -kcm._characterUp * (((RaycastHit)(ref kcm._internalCharacterHits[j])).distance - 0.001f);
								flag2 = true;
								remainingMovementMagnitude = Mathf.Clamp(remainingMovementMagnitude - ((Vector3)(ref val3)).magnitude, 0f, float.PositiveInfinity);
								break;
							}
						}
					}
					if (!flag2)
					{
						val = transientPosition;
						remainingMovementMagnitude = Mathf.Clamp(remainingMovementMagnitude - ((Vector3)(ref val3)).magnitude, 0f, float.PositiveInfinity);
						kcm.CharacterController.OnMovementHit(((RaycastHit)(ref val2)).collider, ((RaycastHit)(ref val2)).normal, ((RaycastHit)(ref val2)).point, ref stabilityReport);
						Vector3 obstructionNormal = kcm.GetObstructionNormal(((RaycastHit)(ref val2)).normal, stabilityReport.IsStable);
						if (kcm.InteractiveRigidbodyHandling && Object.op_Implicit((Object)(object)((RaycastHit)(ref val2)).collider.attachedRigidbody))
						{
							kcm.StoreRigidbodyHit(((RaycastHit)(ref val2)).collider.attachedRigidbody, remainingMovementDirection * resultingMovementMagnitude / deltaTime, ((RaycastHit)(ref val2)).point, obstructionNormal, stabilityReport);
						}
						InternalHandleMovementProjection(stabilityReport.IsStable && !kcm._mustUnground, ((RaycastHit)(ref val2)).normal, obstructionNormal, normalized, ref sweepState, ref previousObstructionNormal, ref resultingMovementMagnitude, ref remainingMovementDirection, ref remainingMovementMagnitude);
					}
				}
				else
				{
					flag = false;
				}
				num++;
				if (num > 6)
				{
					remainingMovementMagnitude = 0f;
					result = false;
				}
			}
			Vector3 targetPosition = val + remainingMovementDirection * remainingMovementMagnitude;
			InternalMoveCharacterPosition(ref kcm._transientPosition, targetPosition, kcm.TransientRotation);
			resultingMovementDirection = remainingMovementDirection;
			return result;
		}

		private static void InternalHandleMovementProjection(bool stableOnHit, Vector3 hitNormal, Vector3 obstructionNormal, Vector3 originalMoveDirection, ref MovementSweepState sweepState, ref Vector3 previousObstructionNormal, ref float resultingMovementMagnitude, ref Vector3 remainingMovementDirection, ref float remainingMovementMagnitude)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			if (remainingMovementMagnitude <= 0f)
			{
				return;
			}
			Vector3 movement = originalMoveDirection * remainingMovementMagnitude;
			float num = remainingMovementMagnitude;
			if (stableOnHit)
			{
				kcm.LastMovementIterationFoundAnyGround = true;
			}
			if ((int)sweepState == 2)
			{
				remainingMovementMagnitude = 0f;
				resultingMovementMagnitude = 0f;
				sweepState = (MovementSweepState)3;
			}
			else
			{
				HandleMovementProjection(ref movement, obstructionNormal, stableOnHit);
				remainingMovementDirection = ((Vector3)(ref movement)).normalized;
				remainingMovementMagnitude = ((Vector3)(ref movement)).magnitude;
				resultingMovementMagnitude = remainingMovementMagnitude / num * resultingMovementMagnitude;
				if ((int)sweepState == 0)
				{
					sweepState = (MovementSweepState)1;
				}
				else if ((int)sweepState == 1 && Vector3.Dot(previousObstructionNormal, remainingMovementDirection) < 0f)
				{
					Vector3 val = Vector3.Cross(previousObstructionNormal, obstructionNormal);
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					movement = Vector3.Project(movement, normalized);
					remainingMovementDirection = ((Vector3)(ref movement)).normalized;
					remainingMovementMagnitude = ((Vector3)(ref movement)).magnitude;
					resultingMovementMagnitude = remainingMovementMagnitude / num * resultingMovementMagnitude;
					sweepState = (MovementSweepState)2;
				}
			}
			previousObstructionNormal = obstructionNormal;
		}

		private static bool InternalMoveCharacterPosition(ref Vector3 movedPosition, Vector3 targetPosition, Quaternion atRotation)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			bool flag = true;
			if (kcm.SafeMovement && kcm.CharacterCollisionsOverlap(targetPosition, atRotation, kcm._internalProbedColliders, 0f, false) > 0)
			{
				flag = false;
			}
			if (flag)
			{
				movedPosition = targetPosition;
				return true;
			}
			return false;
		}

		private static void EvaluateHitStability(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint, Vector3 atCharacterPosition, Quaternion atCharacterRotation, ref HitStabilityReport stabilityReport)
		{
			//IL_0015: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			if (!kcm._solveGrounding)
			{
				stabilityReport.IsStable = false;
				return;
			}
			Vector3 val = atCharacterRotation * Vector3.up;
			Vector3 val2 = Vector3.ProjectOnPlane(hitNormal, val);
			Vector3 normalized = ((Vector3)(ref val2)).normalized;
			bool flag = kcm.IsStableOnNormal(hitNormal);
			stabilityReport.InnerNormal = hitNormal;
			stabilityReport.OuterNormal = hitNormal;
			if ((int)kcm.StepHandling != 0 && !flag)
			{
				Rigidbody attachedRigidbody = hitCollider.attachedRigidbody;
				if (!Object.op_Implicit((Object)(object)attachedRigidbody) || attachedRigidbody.isKinematic)
				{
					kcm.DetectSteps(atCharacterPosition, atCharacterRotation, hitPoint, normalized, ref stabilityReport);
				}
			}
			if (kcm.LedgeAndDenivelationHandling)
			{
				float num = 0.05f;
				if ((int)kcm.StepHandling != 0)
				{
					num = kcm.MaxStepHeight;
				}
				bool flag2 = false;
				bool flag3 = false;
				RaycastHit val3 = default(RaycastHit);
				if (kcm.CharacterCollisionsRaycast(hitPoint + val * 0.02f + normalized * 0.001f, -val, num + 0.02f, ref val3, kcm._internalCharacterHits, false) > 0)
				{
					stabilityReport.InnerNormal = ((RaycastHit)(ref val3)).normal;
					flag2 = kcm.IsStableOnNormal(((RaycastHit)(ref val3)).normal);
				}
				RaycastHit val4 = default(RaycastHit);
				if (kcm.CharacterCollisionsRaycast(hitPoint + val * 0.02f + -normalized * 0.001f, -val, num + 0.02f, ref val4, kcm._internalCharacterHits, false) > 0)
				{
					stabilityReport.OuterNormal = ((RaycastHit)(ref val4)).normal;
					flag3 = kcm.IsStableOnNormal(((RaycastHit)(ref val4)).normal);
				}
				stabilityReport.LedgeDetected = flag2 != flag3;
				if (stabilityReport.LedgeDetected)
				{
					stabilityReport.IsOnEmptySideOfLedge = flag3 && !flag2;
					stabilityReport.LedgeGroundNormal = (flag3 ? ((RaycastHit)(ref val4)).normal : ((RaycastHit)(ref val3)).normal);
					val2 = Vector3.Cross(hitNormal, ((RaycastHit)(ref val4)).normal);
					stabilityReport.LedgeRightDirection = ((Vector3)(ref val2)).normalized;
					val2 = Vector3.Cross(stabilityReport.LedgeGroundNormal, stabilityReport.LedgeRightDirection);
					stabilityReport.LedgeFacingDirection = ((Vector3)(ref val2)).normalized;
					val2 = Vector3.ProjectOnPlane(hitPoint - (atCharacterPosition + atCharacterRotation * kcm._characterTransformToCapsuleBottom), val);
					stabilityReport.DistanceFromLedge = ((Vector3)(ref val2)).magnitude;
				}
			}
			if (flag || stabilityReport.ValidStepDetected)
			{
				stabilityReport.IsStable = true;
			}
			kcm.CharacterController.ProcessHitStabilityReport(hitCollider, hitNormal, hitPoint, atCharacterPosition, atCharacterRotation, ref stabilityReport);
		}

		private static void HandleMovementProjection(ref Vector3 movement, Vector3 obstructionNormal, bool stableOnHit)
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (kcm.GroundingStatus.IsStableOnGround && !kcm._mustUnground)
			{
				if (stableOnHit)
				{
					movement = kcm.GetDirectionTangentToSurface(movement, obstructionNormal) * ((Vector3)(ref movement)).magnitude;
					return;
				}
				Vector3 val = Vector3.Cross(obstructionNormal, kcm.GroundingStatus.GroundNormal);
				val = Vector3.Cross(((Vector3)(ref val)).normalized, obstructionNormal);
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				movement = kcm.GetDirectionTangentToSurface(movement, normalized) * ((Vector3)(ref movement)).magnitude;
				movement = Vector3.ProjectOnPlane(movement, obstructionNormal);
			}
			else if (stableOnHit)
			{
				movement = Vector3.ProjectOnPlane(movement, kcm._characterUp);
				movement = kcm.GetDirectionTangentToSurface(movement, obstructionNormal) * ((Vector3)(ref movement)).magnitude;
			}
			else
			{
				movement = Vector3.ProjectOnPlane(movement, obstructionNormal);
			}
		}
	}
	[DefaultExecutionOrder(-99)]
	public class OldKinematicCharacterSystem : MonoBehaviour
	{
		public static List<KinematicCharacterMotor> PlayerMotors = new List<KinematicCharacterMotor>();

		private static OldKinematicCharacterSystem _instance;

		public static bool AutoSimulation = true;

		private static float _lastCustomInterpolationStartTime = -1f;

		private static float _lastCustomInterpolationDeltaTime = -1f;

		public static void EnsureCreation()
		{
			//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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			if ((Object)(object)_instance == (Object)null)
			{
				GameObject val = new GameObject("OldKinematicCharacterSystem");
				_instance = val.AddComponent<OldKinematicCharacterSystem>();
				((Object)val).hideFlags = (HideFlags)8;
				((Object)_instance).hideFlags = (HideFlags)8;
				Object.DontDestroyOnLoad((Object)val);
			}
		}

		public static OldKinematicCharacterSystem GetInstance()
		{
			return _instance;
		}

		public static void RegisterCharacterMotor(KinematicCharacterMotor motor)
		{
			EnsureCreation();
			PlayerMotors.Add(motor);
			motor.Rigidbody = ((Component)motor).GetComponent<Rigidbody>();
			motor.Rigidbody.interpolation = (RigidbodyInterpolation)0;
		}

		public static void UnregisterCharacterMotor(KinematicCharacterMotor motor)
		{
			PlayerMotors.Remove(motor);
		}

		private void OnDisable()
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}

		private void Awake()
		{
			_instance = this;
		}

		private void FixedUpdate()
		{
			if (AutoSimulation && PlayerMotors.Count > 0)
			{
				float deltaTime = Time.deltaTime;
				if (deltaTime != 0f)
				{
					PreSimulationUpdate(deltaTime);
					Simulate(deltaTime);
					PostSimulationUpdate(deltaTime);
				}
			}
		}

		private void Update()
		{
			CustomInterpolationUpdate();
		}

		public static void Simulate(float deltaTime)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < PlayerMotors.Count; i++)
			{
				OldKinematicCharacterMotor.kcm = PlayerMotors[i];
				OldKinematicCharacterMotor.UpdatePhase1(deltaTime);
			}
			for (int j = 0; j < PlayerMotors.Count; j++)
			{
				OldKinematicCharacterMotor.kcm = PlayerMotors[j];
				OldKinematicCharacterMotor.UpdatePhase2(deltaTime);
				PlayerMotors[j].Transform.SetPositionAndRotation(PlayerMotors[j].TransientPosition, PlayerMotors[j].TransientRotation);
			}
		}

		public static void PreSimulationUpdate(float deltaTime)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			MoveActorsToDestination();
			for (int i = 0; i < PlayerMotors.Count; i++)
			{
				PlayerMotors[i].InitialTickPosition = PlayerMotors[i].Transform.position;
				PlayerMotors[i].InitialTickRotation = PlayerMotors[i].Transform.rotation;
			}
		}

		public static void PostSimulationUpdate(float deltaTime)
		{
			//IL_0037: 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)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			Physics.SyncTransforms();
			_lastCustomInterpolationStartTime = Time.time;
			_lastCustomInterpolationDeltaTime = deltaTime;
			for (int i = 0; i < PlayerMotors.Count; i++)
			{
				PlayerMotors[i].Rigidbody.position = PlayerMotors[i].InitialTickPosition;
				PlayerMotors[i].Rigidbody.rotation = PlayerMotors[i].InitialTickRotation;
				PlayerMotors[i].Rigidbody.MovePosition(PlayerMotors[i].TransientPosition);
				PlayerMotors[i].Rigidbody.MoveRotation(PlayerMotors[i].TransientRotation);
			}
		}

		private static void MoveActorsToDestination()
		{
			//IL_001f: 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)
			for (int i = 0; i < PlayerMotors.Count; i++)
			{
				PlayerMotors[i].Transform.SetPositionAndRotation(PlayerMotors[i].TransientPosition, PlayerMotors[i].TransientRotation);
			}
		}

		private static void CustomInterpolationUpdate()
		{
			//IL_0036: 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_004c: 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)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01((Time.time - _lastCustomInterpolationStartTime) / _lastCustomInterpolationDeltaTime);
			for (int i = 0; i < PlayerMotors.Count; i++)
			{
				PlayerMotors[i].Transform.SetPositionAndRotation(Vector3.Lerp(PlayerMotors[i].InitialTickPosition, PlayerMotors[i].TransientPosition, num), Quaternion.Slerp(PlayerMotors[i].InitialTickRotation, PlayerMotors[i].TransientRotation, num));
			}
		}
	}
}

patchers/KCCDownpatcher.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using Mono.Cecil;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("KCCDownpatcher")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0.0+b308ded7e289cd4e5145d2f62c5cc4db9dba7d59")]
[assembly: AssemblyProduct("KCCDownpatcher")]
[assembly: AssemblyTitle("KCCDownpatcher")]
[assembly: AssemblyVersion("1.1.0.0")]
public static class KCCDownpatcher
{
	private static readonly ManualLogSource Log = Logger.CreateLogSource("KCCDownpatcher");

	public static IEnumerable<string> TargetDLLs { get; } = new string[1] { "KinematicCharacterController.dll" };


	public static void Patch(AssemblyDefinition assembly)
	{
		ModuleDefinition mainModule = assembly.MainModule;
		TypeDefinition type = mainModule.GetType("KinematicCharacterController.KinematicCharacterMotor");
		ModuleDefinition mainModule2 = AssemblyDefinition.ReadAssembly(Path.Combine(Paths.ManagedPath, "UnityEngine.PhysicsModule.dll")).MainModule;
		TypeReference fieldType = mainModule.ImportReference((TypeReference)(object)mainModule2.GetType("UnityEngine.Rigidbody"));
		ModuleDefinition mainModule3 = AssemblyDefinition.ReadAssembly(Path.Combine(Paths.ManagedPath, "UnityEngine.CoreModule.dll")).MainModule;
		TypeReference fieldType2 = mainModule.ImportReference((TypeReference)(object)mainModule3.GetType("UnityEngine.Vector3"));
		AddField(type, fieldType, "Rigidbody");
		AddField(type, mainModule.TypeSystem.Boolean, "usingOldKCC");
		AddField(type, mainModule.TypeSystem.Boolean, "SafeMovement");
		AddField(type, mainModule.TypeSystem.Int32, "_rigidbodiesPushedCount");
		AddField(type, mainModule.TypeSystem.Single, "_internalResultingMovementMagnitude");
		AddField(type, fieldType2, "_internalResultingMovementDirection");
	}

	private static void AddField(TypeDefinition target, TypeReference fieldType, string fieldName)
	{
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Expected O, but got Unknown
		if (target == null || fieldType == null)
		{
			Log.LogError((object)("Null types in AddField: " + fieldName));
			return;
		}
		if (((IEnumerable<FieldDefinition>)target.Fields).FirstOrDefault((Func<FieldDefinition, bool>)((FieldDefinition a) => ((MemberReference)a).Name == fieldName)) != null)
		{
			Log.LogWarning((object)(((MemberReference)target).Name + "." + fieldName + " already exists"));
			return;
		}
		FieldDefinition val = new FieldDefinition(fieldName, (FieldAttributes)6, fieldType);
		target.Fields.Add(val);
	}
}