Decompiled source of PeakTrajectoryPreview v1.3.0

plugins\PeakTrajectoryPreview.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = "")]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace PeakTrajectoryPreview;

[BepInPlugin("moralpeak.trajectorypreview", "PEAK 投掷轨迹预览", "1.3.0")]
public sealed class PeakTrajectoryPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "moralpeak.trajectorypreview";

	public const string PluginName = "PEAK 投掷轨迹预览";

	public const string PluginVersion = "1.3.0";

	private static PeakTrajectoryPlugin _instance;

	private Harmony _harmony;

	private PeakGameAccess _game;

	private TrajectoryRenderer _renderer;

	private int _lastLocalRefreshFrame = -1;

	private ConfigEntry<bool> _enabled;

	private ConfigEntry<float> _lineWidth;

	private ConfigEntry<string> _trajectoryColor;

	private ConfigEntry<bool> _showLandingMarker;

	private ConfigEntry<float> _landingMarkerSize;

	private ConfigEntry<float> _heldItemOpacity;

	private void Awake()
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Expected O, but got Unknown
		_instance = this;
		BindConfig();
		_game = new PeakGameAccess(((BaseUnityPlugin)this).Logger);
		_renderer = new TrajectoryRenderer();
		_harmony = new Harmony("moralpeak.trajectorypreview");
		if (!_game.TryGetCharacterItemsUpdate(out var update))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"未找到 CharacterItems.Update,当前 PEAK 版本暂不受支持。");
			return;
		}
		MethodInfo methodInfo = AccessTools.Method(typeof(PeakTrajectoryPlugin), "CharacterItemsUpdatePostfix", (Type[])null, (Type[])null);
		_harmony.Patch((MethodBase)update, (HarmonyMethod)null, new HarmonyMethod(methodInfo), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"投掷轨迹预览已加载。");
	}

	private void Update()
	{
		if (_renderer != null && Time.frameCount > _lastLocalRefreshFrame + 2)
		{
			_renderer.Hide();
		}
	}

	private void OnDestroy()
	{
		if (_harmony != null)
		{
			_harmony.UnpatchSelf();
		}
		if (_renderer != null)
		{
			_renderer.Dispose();
		}
		if ((Object)(object)_instance == (Object)(object)this)
		{
			_instance = null;
		}
	}

	private static void CharacterItemsUpdatePostfix(object __instance)
	{
		if ((Object)(object)_instance != (Object)null)
		{
			_instance.RefreshPreview(__instance);
		}
	}

	private void RefreshPreview(object characterItems)
	{
		if (_game.IsLocalCharacterItems(characterItems))
		{
			_lastLocalRefreshFrame = Time.frameCount;
			if (!_enabled.Value || !_game.TryGetThrowSnapshot(characterItems, 0.02f, out var snapshot))
			{
				_renderer.Hide();
			}
			else
			{
				_renderer.Render(snapshot, GetSettings());
			}
		}
	}

	private TrajectorySettings GetSettings()
	{
		//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_0068: Unknown result type (might be due to invalid IL or missing references)
		return new TrajectorySettings(128, 0.025f, 3.5f, 80f, 0.08f, -1, Mathf.Clamp(_lineWidth.Value, 0.002f, 0.5f), ParseColor(_trajectoryColor.Value, new Color(0.33f, 0.9f, 0.6f, 1f)), _showLandingMarker.Value, Color.red, Mathf.Clamp(_landingMarkerSize.Value, 0.05f, 4f), Mathf.Clamp01(_heldItemOpacity.Value));
	}

	private void BindConfig()
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Expected O, but got Unknown
		_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("常用设置", "启用预览", true, "本地玩家蓄力投掷时显示轨迹预览。");
		_lineWidth = ((BaseUnityPlugin)this).Config.Bind<float>("常用设置", "轨迹线宽", 0.085f, new ConfigDescription("轨迹线在世界空间中的宽度。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 0.3f), new object[0]));
		_trajectoryColor = ((BaseUnityPlugin)this).Config.Bind<string>("常用设置", "轨迹颜色", "#54E59A", "轨迹线使用的 HTML 颜色,例如 #54E59A。");
		_showLandingMarker = ((BaseUnityPlugin)this).Config.Bind<bool>("常用设置", "显示落点", true, "在第一个预测碰撞点显示标记。");
		_landingMarkerSize = ((BaseUnityPlugin)this).Config.Bind<float>("常用设置", "落点大小", 0.6f, "落点标记在世界空间中的大小。");
		_heldItemOpacity = ((BaseUnityPlugin)this).Config.Bind<float>("常用设置", "手持物品可见度", 0f, new ConfigDescription("轨迹预览显示时手持物品的可见程度。默认 0 为隐藏,可确保轨迹和落点不会被遮挡。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
	}

	private static Color ParseColor(string value, Color fallback)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		Color result = default(Color);
		if (!ColorUtility.TryParseHtmlString(value, ref result))
		{
			return fallback;
		}
		return result;
	}
}
internal sealed class PeakGameAccess
{
	private const BindingFlags InstanceFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

	private const BindingFlags StaticFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

	private readonly ManualLogSource _log;

	private readonly Type _characterItemsType;

	private readonly Type _characterType;

	private readonly Type _helperFunctionsType;

	private readonly FieldInfo _characterItemsCharacter;

	private readonly FieldInfo _throwChargeLevel;

	private readonly FieldInfo _minThrowForce;

	private readonly FieldInfo _maxThrowForce;

	private readonly FieldInfo _localCharacter;

	private readonly FieldInfo _characterData;

	private readonly MemberInfo _currentItem;

	private readonly FieldInfo _lookValues;

	private readonly FieldInfo _lookDirection;

	private readonly MethodInfo _lookToDirection;

	private bool _reportedReadFailure;

	public PeakGameAccess(ManualLogSource log)
	{
		_log = log;
		_characterItemsType = AccessTools.TypeByName("CharacterItems");
		_characterType = AccessTools.TypeByName("Character");
		_helperFunctionsType = AccessTools.TypeByName("HelperFunctions");
		_characterItemsCharacter = FindField(_characterItemsType, "character");
		_throwChargeLevel = FindField(_characterItemsType, "throwChargeLevel");
		_minThrowForce = FindField(_characterItemsType, "minThrowForce");
		_maxThrowForce = FindField(_characterItemsType, "maxThrowForce");
		_localCharacter = FindField(_characterType, "localCharacter", isStatic: true);
		_characterData = FindField(_characterType, "data");
		Type type = ((_characterData == null) ? null : _characterData.FieldType);
		_currentItem = FindMember(type, "currentItem", "_currentitem");
		_lookValues = FindField(type, "lookValues");
		_lookDirection = FindField(type, "lookDirection");
		_lookToDirection = ((_helperFunctionsType == null) ? null : AccessTools.Method(_helperFunctionsType, "LookToDirection", new Type[2]
		{
			typeof(Vector3),
			typeof(Vector3)
		}, (Type[])null));
	}

	public bool TryGetCharacterItemsUpdate(out MethodInfo update)
	{
		update = ((_characterItemsType == null) ? null : AccessTools.Method(_characterItemsType, "Update", (Type[])null, (Type[])null));
		return update != null;
	}

	public bool IsLocalCharacterItems(object characterItems)
	{
		if (characterItems == null || _characterItemsCharacter == null || _localCharacter == null)
		{
			return false;
		}
		object value = _characterItemsCharacter.GetValue(characterItems);
		object value2 = _localCharacter.GetValue(null);
		if (value != null)
		{
			return object.ReferenceEquals(value, value2);
		}
		return false;
	}

	public bool TryGetThrowSnapshot(object characterItems, float minimumCharge, out ThrowSnapshot snapshot)
	{
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: 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_0181: 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)
		snapshot = default(ThrowSnapshot);
		try
		{
			if (!IsLocalCharacterItems(characterItems) || _throwChargeLevel == null || _minThrowForce == null || _maxThrowForce == null)
			{
				return false;
			}
			float num = ReadFloat(_throwChargeLevel.GetValue(characterItems));
			if (num < minimumCharge)
			{
				return false;
			}
			object value = _characterItemsCharacter.GetValue(characterItems);
			object obj = ((_characterData == null) ? null : _characterData.GetValue(value));
			Component val = (Component)((_currentItem == null) ? null : /*isinst with value type is only supported in some contexts*/);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Rigidbody itemBody = GetItemBody(val);
			if ((Object)(object)itemBody == (Object)null)
			{
				return false;
			}
			float num2 = ReadFloat(_minThrowForce.GetValue(characterItems));
			float num3 = ReadFloat(_maxThrowForce.GetValue(characterItems));
			Vector3 aimDirection = GetAimDirection(obj);
			if (((Vector3)(ref aimDirection)).sqrMagnitude < 0.0001f)
			{
				return false;
			}
			float num4 = num2 + (num3 - num2) * Mathf.Clamp01(num);
			float itemThrowMultiplier = GetItemThrowMultiplier(val);
			Vector3 val2 = val.transform.position;
			Vector3 val3 = GetLinearVelocity(itemBody);
			if (((object)val).GetType().Name == "Backpack")
			{
				val2 += Vector3.up * 0.25f;
				val3 = Vector3.zero;
			}
			Vector3 initialVelocity = val3 + ((Vector3)(ref aimDirection)).normalized * (num4 * 0.5f * itemThrowMultiplier);
			snapshot = new ThrowSnapshot(val2, initialVelocity, GetGravityMultiplier(val), GetLinearDamping(itemBody), itemBody, val.transform, ((Object)((value is Component) ? value : null) == (Object)null) ? null : ((Component)value).transform, IsRopeSpool(val));
			return true;
		}
		catch (Exception ex)
		{
			if (!_reportedReadFailure)
			{
				_reportedReadFailure = true;
				_log.LogWarning((object)("Could not read the PEAK throw state: " + ex.Message));
			}
			return false;
		}
	}

	private Vector3 GetAimDirection(object data)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: 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_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
		if (_lookDirection != null && _lookDirection.GetValue(data) is Vector3)
		{
			return (Vector3)_lookDirection.GetValue(data);
		}
		if (_lookValues != null && _lookToDirection != null && _lookValues.GetValue(data) is Vector2 val)
		{
			object obj = _lookToDirection.Invoke(null, new object[2]
			{
				Vector3.forward,
				(object)new Vector3(val.x, val.y, 0f)
			});
			if (obj is Vector3)
			{
				return (Vector3)obj;
			}
		}
		Camera main = Camera.main;
		if (!((Object)(object)main == (Object)null))
		{
			return ((Component)main).transform.forward;
		}
		return Vector3.zero;
	}

	private static Rigidbody GetItemBody(Component item)
	{
		FieldInfo fieldInfo = FindField(((object)item).GetType(), "rig");
		Rigidbody val = (Rigidbody)((fieldInfo == null) ? null : /*isinst with value type is only supported in some contexts*/);
		return val ?? item.GetComponent<Rigidbody>();
	}

	private static float GetItemThrowMultiplier(Component item)
	{
		FieldInfo fieldInfo = FindField(((object)item).GetType(), "throwForceMultiplier");
		if (!(fieldInfo == null))
		{
			return ReadFloat(fieldInfo.GetValue(item));
		}
		return 1f;
	}

	private static float GetGravityMultiplier(Component item)
	{
		Component val = item.GetComponent("Antigrav");
		if ((Object)(object)val == (Object)null)
		{
			FieldInfo fieldInfo = FindField(((object)item).GetType(), "_antiGrav");
			val = (Component)((fieldInfo == null) ? null : /*isinst with value type is only supported in some contexts*/);
		}
		if ((Object)(object)val == (Object)null)
		{
			return 1f;
		}
		FieldInfo fieldInfo2 = FindField(((object)val).GetType(), "intensity");
		if (!(fieldInfo2 == null))
		{
			return 1f - ReadFloat(fieldInfo2.GetValue(val));
		}
		return 1f;
	}

	private static bool IsRopeSpool(Component item)
	{
		if ((Object)(object)item.GetComponent("RopeSpool") != (Object)null || (Object)(object)item.GetComponent("RopeAnchorProjectile") != (Object)null || (Object)(object)item.GetComponent("RopeAnchorWithRope") != (Object)null)
		{
			return true;
		}
		string name = ((object)item).GetType().Name;
		if (name.IndexOf("Rope", StringComparison.OrdinalIgnoreCase) < 0)
		{
			return name.IndexOf("Tether", StringComparison.OrdinalIgnoreCase) >= 0;
		}
		return true;
	}

	private static Vector3 GetLinearVelocity(Rigidbody body)
	{
		//IL_003e: 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)
		PropertyInfo property = typeof(Rigidbody).GetProperty("linearVelocity", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (property != null && property.GetValue(body, null) is Vector3)
		{
			return (Vector3)property.GetValue(body, null);
		}
		return body.velocity;
	}

	private static float GetLinearDamping(Rigidbody body)
	{
		PropertyInfo property = typeof(Rigidbody).GetProperty("linearDamping", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (property != null)
		{
			return ReadFloat(property.GetValue(body, null));
		}
		return body.drag;
	}

	private static FieldInfo FindField(Type type, string name, bool isStatic = false)
	{
		if (!(type == null))
		{
			return type.GetField(name, isStatic ? (BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) : (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic));
		}
		return null;
	}

	private static MemberInfo FindMember(Type type, string propertyName, string fieldName)
	{
		if (type == null)
		{
			return null;
		}
		PropertyInfo property = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		return (MemberInfo)(((object)property) ?? ((object)FindField(type, fieldName)));
	}

	private static object GetMemberValue(MemberInfo member, object instance)
	{
		PropertyInfo propertyInfo = member as PropertyInfo;
		if (!(propertyInfo != null))
		{
			return ((FieldInfo)member).GetValue(instance);
		}
		return propertyInfo.GetValue(instance, null);
	}

	private static float ReadFloat(object value)
	{
		if (value != null)
		{
			return Convert.ToSingle(value);
		}
		return 0f;
	}
}
internal struct ThrowSnapshot
{
	public readonly Vector3 Origin;

	public readonly Vector3 InitialVelocity;

	public readonly float GravityMultiplier;

	public readonly float LinearDamping;

	public readonly Rigidbody ItemBody;

	public readonly Transform ItemRoot;

	public readonly Transform CharacterRoot;

	public readonly bool IsRopeSpool;

	public ThrowSnapshot(Vector3 origin, Vector3 initialVelocity, float gravityMultiplier, float linearDamping, Rigidbody itemBody, Transform itemRoot, Transform characterRoot, bool isRopeSpool)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		Origin = origin;
		InitialVelocity = initialVelocity;
		GravityMultiplier = gravityMultiplier;
		LinearDamping = linearDamping;
		ItemBody = itemBody;
		ItemRoot = itemRoot;
		CharacterRoot = characterRoot;
		IsRopeSpool = isRopeSpool;
	}
}
internal sealed class TrajectoryRenderer : IDisposable
{
	private sealed class FadedRenderer
	{
		public readonly Renderer Renderer;

		public readonly Material[] OriginalMaterials;

		public readonly Material[] TransparentMaterials;

		public readonly bool OriginalForceRenderingOff;

		public FadedRenderer(Renderer renderer, Material[] originalMaterials, Material[] transparentMaterials, bool originalForceRenderingOff)
		{
			Renderer = renderer;
			OriginalMaterials = originalMaterials;
			TransparentMaterials = transparentMaterials;
			OriginalForceRenderingOff = originalForceRenderingOff;
		}
	}

	private const float MarkerSurfaceOffset = 0.015f;

	private readonly RaycastHit[] _hits = (RaycastHit[])(object)new RaycastHit[32];

	private Vector3[] _points = (Vector3[])(object)new Vector3[64];

	private GameObject _root;

	private LineRenderer _trajectory;

	private LineRenderer _markerFirst;

	private LineRenderer _markerSecond;

	private readonly List<FadedRenderer> _fadedRenderers = new List<FadedRenderer>();

	private Transform _fadedItem;

	private float _fadedOpacity = -1f;

	public void Render(ThrowSnapshot snapshot, TrajectorySettings settings)
	{
		//IL_002f: 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_005f: 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_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_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: 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_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: 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_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: 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_014f: 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_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		EnsureVisuals();
		EnsurePointCapacity(settings.PointCount);
		SetHeldItemOpacity(snapshot.ItemRoot, settings.HeldItemOpacity);
		_trajectory.startColor = settings.TrajectoryColor;
		_trajectory.endColor = settings.TrajectoryColor;
		_trajectory.widthMultiplier = settings.LineWidth;
		Vector3 val = snapshot.Origin;
		Vector3 val2 = snapshot.InitialVelocity;
		_points[0] = val;
		int num = 1;
		bool flag = false;
		RaycastHit impact = default(RaycastHit);
		int num2 = Mathf.Min(settings.PointCount - 1, Mathf.CeilToInt(settings.MaximumFlightTime / settings.SimulationStep));
		for (int i = 0; i < num2; i++)
		{
			val2 += Physics.gravity * (settings.SimulationStep * snapshot.GravityMultiplier);
			val2 *= 1f / (1f + Mathf.Max(0f, snapshot.LinearDamping) * settings.SimulationStep);
			Vector3 val3 = val + val2 * settings.SimulationStep;
			if (TryFindImpact(val, val3, settings, snapshot, out impact))
			{
				ref Vector3 reference = ref _points[num++];
				reference = ((RaycastHit)(ref impact)).point + ((RaycastHit)(ref impact)).normal * 0.015f;
				flag = true;
				break;
			}
			_points[num++] = val3;
			val = val3;
			if (Vector3.Distance(snapshot.Origin, val) >= settings.MaximumDistance)
			{
				break;
			}
		}
		_trajectory.positionCount = num;
		for (int j = 0; j < num; j++)
		{
			_trajectory.SetPosition(j, _points[j]);
		}
		if (flag && settings.ShowLandingMarker)
		{
			ShowMarker(((RaycastHit)(ref impact)).point + ((RaycastHit)(ref impact)).normal * 0.015f, ((RaycastHit)(ref impact)).normal, settings);
		}
		else
		{
			HideMarker();
		}
	}

	public void Hide()
	{
		if ((Object)(object)_trajectory != (Object)null)
		{
			_trajectory.positionCount = 0;
		}
		HideMarker();
		RestoreHeldItemOpacity();
	}

	public void Dispose()
	{
		RestoreHeldItemOpacity();
		if ((Object)(object)_root != (Object)null)
		{
			Object.Destroy((Object)(object)_root);
		}
	}

	private bool TryFindImpact(Vector3 start, Vector3 end, TrajectorySettings settings, ThrowSnapshot snapshot, out RaycastHit impact)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: 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_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_0050: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: 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)
		Vector3 val = end - start;
		float magnitude = ((Vector3)(ref val)).magnitude;
		impact = default(RaycastHit);
		if (magnitude <= 0.0001f)
		{
			return false;
		}
		Vector3 val2 = val / magnitude;
		int num = ((settings.CollisionRadius > 0f) ? Physics.SphereCastNonAlloc(start, settings.CollisionRadius, val2, _hits, magnitude, settings.CollisionLayerMask, (QueryTriggerInteraction)1) : Physics.RaycastNonAlloc(start, val2, _hits, magnitude, settings.CollisionLayerMask, (QueryTriggerInteraction)1));
		float num2 = float.MaxValue;
		for (int i = 0; i < num; i++)
		{
			RaycastHit val3 = _hits[i];
			if (!ShouldIgnore(((RaycastHit)(ref val3)).collider, snapshot) && ((RaycastHit)(ref val3)).distance < num2)
			{
				num2 = ((RaycastHit)(ref val3)).distance;
				impact = val3;
			}
		}
		return num2 < float.MaxValue;
	}

	private static bool ShouldIgnore(Collider collider, ThrowSnapshot snapshot)
	{
		if ((Object)(object)collider == (Object)null)
		{
			return true;
		}
		Transform transform = ((Component)collider).transform;
		if (!IsWithin(transform, snapshot.ItemRoot) && !IsWithin(transform, snapshot.CharacterRoot) && !((Object)(object)collider.attachedRigidbody == (Object)(object)snapshot.ItemBody))
		{
			if (snapshot.IsRopeSpool)
			{
				return IsRopeGeometry(collider);
			}
			return false;
		}
		return true;
	}

	private static bool IsRopeGeometry(Collider collider)
	{
		Transform val = ((Component)collider).transform;
		while ((Object)(object)val != (Object)null)
		{
			if ((Object)(object)((Component)val).GetComponent("RopeSegment") != (Object)null || (Object)(object)((Component)val).GetComponent("RopeAnchorProjectile") != (Object)null || (Object)(object)((Component)val).GetComponent("RopeAnchorWithRope") != (Object)null)
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	private static bool IsWithin(Transform transform, Transform root)
	{
		if ((Object)(object)root != (Object)null)
		{
			if (!((Object)(object)transform == (Object)(object)root))
			{
				return transform.IsChildOf(root);
			}
			return true;
		}
		return false;
	}

	private void ShowMarker(Vector3 position, Vector3 normal, TrajectorySettings settings)
	{
		//IL_0000: 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_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: 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_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//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_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = Vector3.Cross(normal, (Mathf.Abs(normal.y) > 0.9f) ? Vector3.forward : Vector3.up);
		Vector3 normalized = ((Vector3)(ref val)).normalized;
		Vector3 val2 = Vector3.Cross(normal, normalized);
		Vector3 normalized2 = ((Vector3)(ref val2)).normalized;
		float num = settings.LandingMarkerSize * 0.5f;
		SetMarkerLine(_markerFirst, position - normalized * num, position + normalized * num, settings);
		SetMarkerLine(_markerSecond, position - normalized2 * num, position + normalized2 * num, settings);
	}

	private static void SetMarkerLine(LineRenderer line, Vector3 start, Vector3 end, TrajectorySettings settings)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: 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)
		line.startColor = settings.LandingMarkerColor;
		line.endColor = settings.LandingMarkerColor;
		line.widthMultiplier = Mathf.Max(settings.LineWidth * 1.25f, 0.01f);
		line.positionCount = 2;
		line.SetPosition(0, start);
		line.SetPosition(1, end);
	}

	private void HideMarker()
	{
		if ((Object)(object)_markerFirst != (Object)null)
		{
			_markerFirst.positionCount = 0;
			_markerSecond.positionCount = 0;
		}
	}

	private void EnsureVisuals()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		if (!((Object)(object)_root != (Object)null))
		{
			_root = new GameObject("PeakTrajectoryPreview.Visuals");
			Object.DontDestroyOnLoad((Object)(object)_root);
			_trajectory = CreateLine("Trajectory", 0);
			_markerFirst = CreateLine("LandingMarkerA", 1);
			_markerSecond = CreateLine("LandingMarkerB", 1);
		}
	}

	private LineRenderer CreateLine(string name, int sortingOrder)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		GameObject val = new GameObject(name);
		val.transform.SetParent(_root.transform, false);
		LineRenderer val2 = val.AddComponent<LineRenderer>();
		((Renderer)val2).material = CreateMaterial();
		((Renderer)val2).material.renderQueue = 3010;
		val2.useWorldSpace = true;
		val2.alignment = (LineAlignment)0;
		val2.numCapVertices = 4;
		val2.numCornerVertices = 4;
		((Renderer)val2).sortingOrder = sortingOrder;
		return val2;
	}

	private static Material CreateMaterial()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		Shader val = Shader.Find("Sprites/Default");
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("Unlit/Color");
		}
		return new Material(val);
	}

	private void EnsurePointCapacity(int minimumSize)
	{
		if (_points.Length < minimumSize)
		{
			_points = (Vector3[])(object)new Vector3[minimumSize];
		}
	}

	private void SetHeldItemOpacity(Transform itemRoot, float opacity)
	{
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Expected O, but got Unknown
		if ((Object)(object)itemRoot == (Object)null || opacity >= 0.99f)
		{
			RestoreHeldItemOpacity();
		}
		else
		{
			if ((Object)(object)_fadedItem == (Object)(object)itemRoot && Mathf.Approximately(_fadedOpacity, opacity))
			{
				return;
			}
			RestoreHeldItemOpacity();
			_fadedItem = itemRoot;
			_fadedOpacity = opacity;
			Renderer[] componentsInChildren = ((Component)itemRoot).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				Material[] sharedMaterials = val.sharedMaterials;
				if (sharedMaterials == null || sharedMaterials.Length == 0)
				{
					continue;
				}
				if (opacity <= 0.01f)
				{
					_fadedRenderers.Add(new FadedRenderer(val, sharedMaterials, null, val.forceRenderingOff));
					val.forceRenderingOff = true;
					continue;
				}
				Material[] array = (Material[])(object)new Material[sharedMaterials.Length];
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if (!((Object)(object)sharedMaterials[j] == (Object)null))
					{
						array[j] = new Material(sharedMaterials[j]);
						ConfigureTransparentMaterial(array[j], opacity);
					}
				}
				val.materials = array;
				_fadedRenderers.Add(new FadedRenderer(val, sharedMaterials, array, val.forceRenderingOff));
			}
		}
	}

	private void RestoreHeldItemOpacity()
	{
		for (int i = 0; i < _fadedRenderers.Count; i++)
		{
			FadedRenderer fadedRenderer = _fadedRenderers[i];
			if ((Object)(object)fadedRenderer.Renderer != (Object)null)
			{
				fadedRenderer.Renderer.sharedMaterials = fadedRenderer.OriginalMaterials;
				fadedRenderer.Renderer.forceRenderingOff = fadedRenderer.OriginalForceRenderingOff;
			}
			if (fadedRenderer.TransparentMaterials == null)
			{
				continue;
			}
			for (int j = 0; j < fadedRenderer.TransparentMaterials.Length; j++)
			{
				if ((Object)(object)fadedRenderer.TransparentMaterials[j] != (Object)null)
				{
					Object.Destroy((Object)(object)fadedRenderer.TransparentMaterials[j]);
				}
			}
		}
		_fadedRenderers.Clear();
		_fadedItem = null;
		_fadedOpacity = -1f;
	}

	private static void ConfigureTransparentMaterial(Material material, float opacity)
	{
		SetMaterialAlpha(material, "_BaseColor", opacity);
		SetMaterialAlpha(material, "_Color", opacity);
		material.SetOverrideTag("RenderType", "Transparent");
		if (material.HasProperty("_Surface"))
		{
			material.SetFloat("_Surface", 1f);
		}
		if (material.HasProperty("_Blend"))
		{
			material.SetFloat("_Blend", 0f);
		}
		if (material.HasProperty("_SrcBlend"))
		{
			material.SetInt("_SrcBlend", 5);
		}
		if (material.HasProperty("_DstBlend"))
		{
			material.SetInt("_DstBlend", 10);
		}
		if (material.HasProperty("_ZWrite"))
		{
			material.SetInt("_ZWrite", 0);
		}
		material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
		material.DisableKeyword("_ALPHATEST_ON");
		material.EnableKeyword("_ALPHABLEND_ON");
		material.renderQueue = 3000;
	}

	private static void SetMaterialAlpha(Material material, string property, float opacity)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		if (material.HasProperty(property))
		{
			Color color = material.GetColor(property);
			color.a *= opacity;
			material.SetColor(property, color);
		}
	}
}
internal struct TrajectorySettings
{
	public readonly int PointCount;

	public readonly float SimulationStep;

	public readonly float MaximumFlightTime;

	public readonly float MaximumDistance;

	public readonly float CollisionRadius;

	public readonly int CollisionLayerMask;

	public readonly float LineWidth;

	public readonly Color TrajectoryColor;

	public readonly bool ShowLandingMarker;

	public readonly Color LandingMarkerColor;

	public readonly float LandingMarkerSize;

	public readonly float HeldItemOpacity;

	public TrajectorySettings(int pointCount, float simulationStep, float maximumFlightTime, float maximumDistance, float collisionRadius, int collisionLayerMask, float lineWidth, Color trajectoryColor, bool showLandingMarker, Color landingMarkerColor, float landingMarkerSize, float heldItemOpacity)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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)
		PointCount = pointCount;
		SimulationStep = simulationStep;
		MaximumFlightTime = maximumFlightTime;
		MaximumDistance = maximumDistance;
		CollisionRadius = collisionRadius;
		CollisionLayerMask = collisionLayerMask;
		LineWidth = lineWidth;
		TrajectoryColor = trajectoryColor;
		ShowLandingMarker = showLandingMarker;
		LandingMarkerColor = landingMarkerColor;
		LandingMarkerSize = landingMarkerSize;
		HeldItemOpacity = heldItemOpacity;
	}
}