Decompiled source of MotorMod v0.8.0

plugins/MotorMod/MotorMod.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using MotorMod.Harness;
using MotorMod.Soundtrack;
using TMPro;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MotorMod
{
	public class BikeCondition : MonoBehaviour
	{
		public enum State
		{
			Fresh,
			Worn,
			Wrecked
		}

		private static readonly int s_color = Shader.PropertyToID("_Color");

		private static readonly int s_gloss = Shader.PropertyToID("_Glossiness");

		private static readonly int s_glossMap = Shader.PropertyToID("_GlossMapScale");

		private static readonly MaterialPropertyBlock s_clear = new MaterialPropertyBlock();

		private const float WornTint = 0.72f;

		private const float WornGloss = 0.6f;

		private const float WreckedTint = 0.45f;

		private const float WreckedGloss = 0.35f;

		private const float SmokeRate = 4f;

		private const float SmokeScale = 0.5f;

		private ZNetView m_nview;

		private MotorcycleController m_bike;

		private WearNTear m_wear;

		private BikeHealth m_health;

		private readonly List<Renderer> m_renderers = new List<Renderer>();

		private ParticleSystem m_smoke;

		private State m_state;

		private bool m_applied;

		private float m_nextPoll;

		public State Current => m_state;

		public bool Smoking
		{
			get
			{
				if ((Object)(object)m_smoke != (Object)null)
				{
					return m_smoke.isEmitting;
				}
				return false;
			}
		}

		public int SmokeParticles
		{
			get
			{
				if (!((Object)(object)m_smoke != (Object)null))
				{
					return 0;
				}
				return m_smoke.particleCount;
			}
		}

		public static bool Enabled
		{
			get
			{
				if (MotorModPlugin.DamageLook != null)
				{
					return MotorModPlugin.DamageLook.Value;
				}
				return true;
			}
		}

		public Vector3 EnginePoint
		{
			get
			{
				//IL_007e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: 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_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: 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_005e: 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_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)m_bike != (Object)null && (Object)(object)m_bike.m_wheelFront != (Object)null && (Object)(object)m_bike.m_wheelRear != (Object)null)
				{
					return (m_bike.m_wheelFront.position + m_bike.m_wheelRear.position) * 0.5f + Vector3.up * 0.45f;
				}
				return ((Component)this).transform.position + Vector3.up * 0.6f;
			}
		}

		public static State StateFor(float fraction)
		{
			if (!(fraction > 0.75f))
			{
				if (!(fraction > 0.25f))
				{
					return State.Wrecked;
				}
				return State.Worn;
			}
			return State.Fresh;
		}

		private void Awake()
		{
			m_nview = ((Component)this).GetComponent<ZNetView>();
			m_bike = ((Component)this).GetComponent<MotorcycleController>();
			m_wear = ((Component)this).GetComponent<WearNTear>();
			m_health = ((Component)this).GetComponent<BikeHealth>();
		}

		private void Start()
		{
			Transform val = (((Object)(object)m_bike != (Object)null && (Object)(object)m_bike.m_visual != (Object)null) ? m_bike.m_visual : ((Component)this).transform);
			MeshRenderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val2 in componentsInChildren)
			{
				bool flag = false;
				Transform val3 = ((Component)val2).transform;
				while ((Object)(object)val3 != (Object)null && (Object)(object)val3 != (Object)(object)val)
				{
					if (((Object)val3).name == "Saddlebags" || ((Object)val3).name == "Headlight")
					{
						flag = true;
						break;
					}
					val3 = val3.parent;
				}
				if (!flag)
				{
					m_renderers.Add((Renderer)(object)val2);
				}
			}
			Apply(StateFor(((Object)(object)m_health != (Object)null) ? m_health.Fraction : 1f), silent: true);
		}

		private void Update()
		{
			if (!((Object)(object)m_nview == (Object)null) && m_nview.IsValid() && !((Object)(object)m_health == (Object)null) && Time.time >= m_nextPoll)
			{
				m_nextPoll = Time.time + 0.2f;
				State state = StateFor(m_health.Fraction);
				if (state != m_state || !m_applied)
				{
					Apply(state, !m_applied);
				}
			}
		}

		private void Apply(State s, bool silent)
		{
			//IL_0071: 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_008a: 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)
			bool flag = s > m_state;
			m_state = s;
			m_applied = true;
			Tint(Enabled ? s : State.Fresh);
			SetSmoke(Enabled && s == State.Wrecked);
			if (!silent && flag && (Object)(object)m_wear != (Object)null && m_nview.IsOwner())
			{
				m_wear.m_switchEffect.Create(((Component)this).transform.position, ((Component)this).transform.rotation, (Transform)null, 1f, -1, default(ZDOID));
			}
		}

		private void Tint(State s)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_00b7: 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)
			float num = s switch
			{
				State.Worn => 0.72f, 
				State.Fresh => 1f, 
				_ => 0.45f, 
			};
			float num2 = s switch
			{
				State.Worn => 0.6f, 
				State.Fresh => 1f, 
				_ => 0.35f, 
			};
			foreach (Renderer renderer in m_renderers)
			{
				if ((Object)(object)renderer == (Object)null)
				{
					continue;
				}
				Material[] sharedMaterials = renderer.sharedMaterials;
				for (int i = 0; i < sharedMaterials.Length; i++)
				{
					Material val = sharedMaterials[i];
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					if (s == State.Fresh)
					{
						renderer.SetPropertyBlock(s_clear, i);
						continue;
					}
					MaterialPropertyBlock val2 = new MaterialPropertyBlock();
					if (val.HasProperty(s_color))
					{
						val2.SetColor(s_color, val.GetColor(s_color) * new Color(num, num, num, 1f));
					}
					if (val.HasProperty(s_gloss))
					{
						val2.SetFloat(s_gloss, val.GetFloat(s_gloss) * num2);
					}
					if (val.HasProperty(s_glossMap))
					{
						val2.SetFloat(s_glossMap, val.GetFloat(s_glossMap) * num2);
					}
					renderer.SetPropertyBlock(val2, i);
				}
			}
		}

		private void SetSmoke(bool on)
		{
			if (on && (Object)(object)m_smoke == (Object)null)
			{
				m_smoke = MakeSmoke();
			}
			if (!((Object)(object)m_smoke == (Object)null))
			{
				if (on && !m_smoke.isEmitting)
				{
					m_smoke.Play(true);
				}
				else if (!on && m_smoke.isEmitting)
				{
					m_smoke.Stop(true, (ParticleSystemStopBehavior)1);
				}
			}
		}

		private ParticleSystem MakeSmoke()
		{
			//IL_0101: 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_0121: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: 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_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("vfx_Damaged_Karve") : null);
			ParticleSystem val2 = (((Object)(object)val != (Object)null) ? val.GetComponentInChildren<ParticleSystem>(true) : null);
			if ((Object)(object)val2 == (Object)null)
			{
				MotorModPlugin.Log.LogWarning((object)(((Object)((Component)this).gameObject).name + ": no damage smoke to copy"));
				return null;
			}
			GameObject val3 = BikeTrail.LocalCopy(((Component)val2).gameObject);
			Component[] componentsInChildren = val3.GetComponentsInChildren<Component>(true);
			foreach (Component val4 in componentsInChildren)
			{
				if (!(val4 is Transform) && !(val4 is ParticleSystem) && !(val4 is ParticleSystemRenderer))
				{
					Object.Destroy((Object)(object)val4);
				}
			}
			((Object)val3).name = "EngineSmoke";
			val3.transform.SetParent(((Object)(object)m_bike != (Object)null && (Object)(object)m_bike.m_visual != (Object)null) ? m_bike.m_visual : ((Component)this).transform, false);
			val3.transform.position = EnginePoint;
			val3.transform.rotation = Quaternion.identity;
			val3.transform.localScale = Vector3.one * 0.5f;
			ParticleSystem component = val3.GetComponent<ParticleSystem>();
			MainModule main = component.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).playOnAwake = false;
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)0;
			EmissionModule emission = component.emission;
			((EmissionModule)(ref emission)).enabled = true;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(4f);
			((EmissionModule)(ref emission)).rateOverDistance = MinMaxCurve.op_Implicit(0f);
			((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[0]);
			component.Stop(true, (ParticleSystemStopBehavior)0);
			return component;
		}
	}
	public class BikeDefinition
	{
		public string Key;

		public string PrefabName;

		public string DisplayName;

		public string Description;

		public string BaseKey;

		public Color IconTint;

		public string CraftingStation = CraftingStations.Forge;

		public RequirementConfig[] Requirements;

		public string Pose = "attach_lox";

		public string Trail = "fire";

		public GameObject Prefab;

		public string FuelItem;

		public float FuelMetres;

		public float DefaultBagForward;

		public float DefaultBagUp;

		public float DefaultBagScale = 0.85f;

		public float WheelieEase = 1f;

		public float TopSpeed = 16f;

		public float Acceleration = 5f;

		public float BrakeForce = 9f;

		public float TurnRateSlow = 60f;

		public float TurnRateFast = 28f;

		public float LeanAngle = 22f;

		public float BoostMultiplier = 2f;

		public float Terrain = 0.5f;

		public float DefaultSeatForward;

		public float DefaultSeatUp;

		public float DefaultGripUp;

		public float DefaultGripSide;

		public float DefaultGripForward;

		public float Lean = 12f;

		public float LeanMax = 30f;

		public float DefaultFootForward = 0.55f;

		public float DefaultFootUp = 0.38f;

		public float DefaultFootSide = 0.32f;

		public ConfigEntry<float> CfgTopSpeed;

		public ConfigEntry<float> CfgAcceleration;

		public ConfigEntry<float> CfgBrakeForce;

		public ConfigEntry<float> CfgTurnRateSlow;

		public ConfigEntry<float> CfgTurnRateFast;

		public ConfigEntry<float> CfgLeanAngle;

		public ConfigEntry<float> CfgBoostMultiplier;

		public ConfigEntry<float> CfgTerrain;

		public ConfigEntry<float> SeatOffsetUp;

		public ConfigEntry<float> SeatOffsetForward;

		public ConfigEntry<float> SeatOffsetSide;

		public ConfigEntry<float> Scale;

		public ConfigEntry<float> GripOffsetUp;

		public ConfigEntry<float> GripOffsetSide;

		public ConfigEntry<float> GripOffsetForward;

		public ConfigEntry<string> CfgPose;

		public ConfigEntry<float> CfgWheelieEase;

		public ConfigEntry<float> CfgLean;

		public ConfigEntry<float> CfgLeanMax;

		public ConfigEntry<float> FootForward_;

		public ConfigEntry<float> FootUp_;

		public ConfigEntry<float> FootSide_;

		public ConfigEntry<float> BagForward;

		public ConfigEntry<float> BagUp;

		public ConfigEntry<float> BagScale;

		public static readonly List<BikeDefinition> All = Roster();

		public string BundleKey => BaseKey ?? Key;

		public string BundlePrefab
		{
			get
			{
				if (BaseKey != null)
				{
					return All.Find((BikeDefinition d) => d.Key == BaseKey).PrefabName;
				}
				return PrefabName;
			}
		}

		public string IconAsset => BundleKey + "_icon";

		public ConfigEntry<float> FootForward => FootForward_;

		public ConfigEntry<float> FootUp => FootUp_;

		public ConfigEntry<float> FootSide => FootSide_;

		private static RequirementConfig R(string item, int n)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			return new RequirementConfig(item, n, 0, true);
		}

		private static List<BikeDefinition> Roster()
		{
			//IL_0166: 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)
			BikeDefinition bikeDefinition = new BikeDefinition();
			bikeDefinition.Key = "hel";
			bikeDefinition.PrefabName = "HelCycle";
			bikeDefinition.DisplayName = "Hel Cycle";
			bikeDefinition.Description = "Silver, bone and a skull that remembers being alive.";
			bikeDefinition.WheelieEase = 0.85f;
			bikeDefinition.TopSpeed = 18f;
			bikeDefinition.Acceleration = 6f;
			bikeDefinition.TurnRateSlow = 60f;
			bikeDefinition.TurnRateFast = 28f;
			bikeDefinition.Terrain = 0.3f;
			bikeDefinition.Lean = 0f;
			bikeDefinition.DefaultSeatForward = -0.1f;
			bikeDefinition.DefaultFootForward = 0.6f;
			bikeDefinition.DefaultFootUp = 0.45f;
			bikeDefinition.DefaultFootSide = 0.34f;
			bikeDefinition.FuelItem = "SurtlingCore";
			bikeDefinition.FuelMetres = 1334f;
			bikeDefinition.Requirements = (RequirementConfig[])(object)new RequirementConfig[6]
			{
				R("Silver", 40),
				R("Iron", 10),
				R("BoneFragments", 50),
				R("SurtlingCore", 8),
				R("TrophySkeleton", 1),
				R("Chain", 4)
			};
			BikeDefinition bikeDefinition2 = bikeDefinition;
			return new List<BikeDefinition>
			{
				bikeDefinition2,
				Variant(bikeDefinition2, "wraith", "WraithCycle", "Wraith Cycle", "The Hel Cycle's cold twin. Its flames burn blue, like the lights the wraiths carry through the swamp at night.", "fire_blue", "TrophyWraith", new Color(0.55f, 0.75f, 1f, 1f)),
				Variant(bikeDefinition2, "draugr", "DraugrCycle", "Draugr Cycle", "The Hel Cycle risen from the swamp. Its flames burn green as rot.", "fire_green", "TrophyDraugr", new Color(0.55f, 1f, 0.55f, 1f))
			};
		}

		private static BikeDefinition Variant(BikeDefinition b, string key, string prefab, string name, string description, string trail, string trophy, Color tint)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			BikeDefinition obj = (BikeDefinition)b.MemberwiseClone();
			obj.Key = key;
			obj.PrefabName = prefab;
			obj.DisplayName = name;
			obj.Description = description;
			obj.Trail = trail;
			obj.BaseKey = b.Key;
			obj.IconTint = tint;
			obj.Requirements = Array.ConvertAll(b.Requirements, (RequirementConfig r) => (!(r.Item == "TrophySkeleton")) ? R(r.Item, r.Amount) : R(trophy, r.Amount));
			return obj;
		}

		public static BikeDefinition Find(string nameOrKey)
		{
			if (string.IsNullOrEmpty(nameOrKey))
			{
				return null;
			}
			string n = nameOrKey.ToLowerInvariant();
			return All.Find((BikeDefinition d) => d.Key == n) ?? All.Find((BikeDefinition d) => d.Key.StartsWith(n) || d.PrefabName.ToLowerInvariant().StartsWith(n) || d.DisplayName.ToLowerInvariant().StartsWith(n));
		}

		public static BikeDefinition ForObject(string gameObjectName)
		{
			return All.Find((BikeDefinition d) => gameObjectName.StartsWith(d.PrefabName));
		}

		public void BindConfig(ConfigFile config)
		{
			CfgTopSpeed = config.Bind<float>(Key, "TopSpeed", TopSpeed, "Top speed, metres per second.");
			CfgAcceleration = config.Bind<float>(Key, "Acceleration", Acceleration, "Throttle acceleration, m/s^2.");
			CfgBrakeForce = config.Bind<float>(Key, "BrakeForce", BrakeForce, "Braking deceleration, m/s^2.");
			CfgTurnRateSlow = config.Bind<float>(Key, "TurnRateSlow", TurnRateSlow, "Turn rate at walking pace, degrees per second.");
			CfgTurnRateFast = config.Bind<float>(Key, "TurnRateFast", TurnRateFast, "Turn rate at top speed, degrees per second.");
			CfgLeanAngle = config.Bind<float>(Key, "LeanAngle", LeanAngle, "Visual lean into turns at speed, degrees.");
			CfgBoostMultiplier = config.Bind<float>(Key, "BoostMultiplier", BoostMultiplier, "Top speed multiplier while holding Run.");
			CfgTerrain = config.Bind<float>(Key, "Terrain", Terrain, "0 to 1: how well the bike keeps speed and composure over bumps and slopes.");
			CfgWheelieEase = config.Bind<float>(Key, "WheelieEase", WheelieEase, "Wheelie difficulty: above 1 slower and easier, below 1 quicker and harder.");
			CfgPose = config.Bind<string>(Key, "Pose", Pose, "Rider animation while riding (attach_lox reaches forward, attach_chair sits upright).");
			CfgLean = config.Bind<float>(Key, "RiderLean", Lean, "Torso lean toward the bars, degrees; more is added automatically when the grips are out of reach.");
			CfgLeanMax = config.Bind<float>(Key, "RiderLeanMax", LeanMax, "Most extra lean the rider adds to reach the grips, degrees. Beyond that the arms stretch and the shoulders roll forward instead.");
			FootForward_ = config.Bind<float>(Key, "FootForward", DefaultFootForward, "Footpegs ahead of the seat, metres.");
			FootUp_ = config.Bind<float>(Key, "FootUp", DefaultFootUp, "Footpeg height above the ground, metres.");
			FootSide_ = config.Bind<float>(Key, "FootSide", DefaultFootSide, "Footpegs out from the centre line, metres.");
			SeatOffsetUp = config.Bind<float>(Key, "SeatOffsetUp", DefaultSeatUp, "Raise (+) or lower (-) the rider on the seat, metres. Re-mount after \"motor reload\".");
			SeatOffsetForward = config.Bind<float>(Key, "SeatOffsetForward", DefaultSeatForward, "Move the rider forward (+) or back (-) on the seat, metres.");
			SeatOffsetSide = config.Bind<float>(Key, "SeatOffsetSide", 0f, "Move the rider to the right (+) or left (-), metres.");
			Scale = config.Bind<float>(Key, "Scale", 1f, "Extra size multiplier applied to the whole bike (1 = as modelled).");
			GripOffsetUp = config.Bind<float>(Key, "GripOffsetUp", DefaultGripUp, "Move this bike's grips up (+) or down (-), metres. Hands follow.");
			GripOffsetSide = config.Bind<float>(Key, "GripOffsetSide", DefaultGripSide, "Move this bike's grips outward (+) or inward (-), metres.");
			GripOffsetForward = config.Bind<float>(Key, "GripOffsetForward", DefaultGripForward, "Move this bike's grips forward (+) or back (-), metres.");
			BagForward = config.Bind<float>(Key, "SaddlebagForward", DefaultBagForward, "Move the saddlebags forward (+) or back (-) from the rear axle, metres. They sit just outside the bike at that spot.");
			BagUp = config.Bind<float>(Key, "SaddlebagUp", DefaultBagUp, "Raise (+) or lower (-) the saddlebags, metres.");
			BagScale = config.Bind<float>(Key, "SaddlebagScale", DefaultBagScale, "Size of the saddlebags (1 = 38 cm wide).");
		}
	}
	public class BikeFuel : MonoBehaviour
	{
		private static readonly int s_fuelHash = StringExtensionMethods.GetStableHashCode("mm_fuel");

		private ZNetView m_nview;

		private MotorcycleController m_bike;

		public static bool Enabled
		{
			get
			{
				if (MotorModPlugin.FuelEnabled != null)
				{
					return MotorModPlugin.FuelEnabled.Value;
				}
				return true;
			}
		}

		public static float Capacity => Mathf.Max(100f, MotorModPlugin.TankKm.Value * 1000f);

		public float Metres
		{
			get
			{
				if (!((Object)(object)m_nview != (Object)null) || !m_nview.IsValid())
				{
					return 0f;
				}
				return m_nview.GetZDO().GetFloat(s_fuelHash, 0f);
			}
		}

		public float Fraction
		{
			get
			{
				if (!Enabled)
				{
					return 1f;
				}
				return Mathf.Clamp01(Metres / Capacity);
			}
		}

		public bool Empty
		{
			get
			{
				if (Enabled)
				{
					return Metres <= 0.01f;
				}
				return false;
			}
		}

		public string Percent => $"{Mathf.CeilToInt(Fraction * 100f)}%";

		private BikeDefinition D
		{
			get
			{
				if (!((Object)(object)m_bike != (Object)null))
				{
					return null;
				}
				return m_bike.m_definition;
			}
		}

		public string FuelItem
		{
			get
			{
				if (D == null)
				{
					return null;
				}
				return D.FuelItem;
			}
		}

		public string FuelName
		{
			get
			{
				GameObject val = ((FuelItem != null && (Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(FuelItem) : null);
				ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null);
				if (!((Object)(object)val2 != (Object)null))
				{
					return "fuel";
				}
				return Localization.instance.Localize(val2.m_itemData.m_shared.m_name);
			}
		}

		public string FillHint => "\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] Fill tank (" + FuelName + ")";

		public string HotbarHint => "\n[<color=yellow><b>1-8</b></color>] Add " + FuelName;

		private void Awake()
		{
			m_nview = ((Component)this).GetComponent<ZNetView>();
			m_bike = ((Component)this).GetComponent<MotorcycleController>();
		}

		public float MetresPer(string prefabName)
		{
			if (D == null || !(prefabName == D.FuelItem))
			{
				return 0f;
			}
			return D.FuelMetres;
		}

		public void Burn(float metres)
		{
			if (Enabled && !(metres <= 0f) && m_nview.IsOwner())
			{
				float metres2 = Metres;
				float num = Mathf.Max(0f, metres2 - metres);
				m_nview.GetZDO().Set(s_fuelHash, num);
				float capacity = Capacity;
				if (metres2 > 0.2f * capacity && num <= 0.2f * capacity)
				{
					m_bike.RiderMessage((MessageType)2, "Fuel low: 20 %");
				}
				else if (metres2 > 0.1f * capacity && num <= 0.1f * capacity)
				{
					m_bike.RiderMessage((MessageType)2, "Fuel very low: 10 %");
				}
			}
		}

		public void Fill(Player player)
		{
			if (!CanFill(player))
			{
				return;
			}
			string fuelItem = FuelItem;
			if (fuelItem != null)
			{
				Container storage = m_bike.Storage;
				int num = Pour(player, ((Humanoid)player).GetInventory(), fuelItem);
				int num2 = (((Object)(object)storage != (Object)null) ? Pour(player, storage.GetInventory(), fuelItem) : 0);
				string text = FuelName.ToLowerInvariant();
				if (num + num2 == 0)
				{
					((Character)player).Message((MessageType)2, (Metres >= Capacity - 1f) ? "The tank is full" : ("No " + text + " in your bag or the saddlebags"), 0, (Sprite)null, false);
					return;
				}
				((Character)player).Message((MessageType)2, string.Format("Fuel {0} ({1} {2}{3})", Percent, num + num2, text, (num2 > 0) ? $", {num2} from the saddlebags" : ""), 0, (Sprite)null, false);
			}
		}

		public bool UseItem(Player player, ItemData item)
		{
			string text = ((item != null && (Object)(object)item.m_dropPrefab != (Object)null) ? ((Object)item.m_dropPrefab).name : null);
			if (text == null || MetresPer(text) <= 0f)
			{
				return false;
			}
			if (!CanFill(player))
			{
				return true;
			}
			int num = Pour(player, ((Humanoid)player).GetInventory(), text);
			((Character)player).Message((MessageType)2, (num == 0) ? "The tank is full" : $"Fuel {Percent} ({num} {Localization.instance.Localize(item.m_shared.m_name).ToLowerInvariant()})", 0, (Sprite)null, false);
			return true;
		}

		private bool CanFill(Player player)
		{
			if (!Enabled)
			{
				((Character)player).Message((MessageType)2, "Fuel is switched off on this world", 0, (Sprite)null, false);
				return false;
			}
			if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid())
			{
				return false;
			}
			if (m_bike.HasRider)
			{
				((Character)player).Message((MessageType)2, "Someone is riding it", 0, (Sprite)null, false);
				return false;
			}
			if (!m_bike.Standing)
			{
				((Character)player).Message((MessageType)2, "Stop the bike before filling the tank", 0, (Sprite)null, false);
				return false;
			}
			if (m_bike.BagsOpen)
			{
				((Character)player).Message((MessageType)2, "Someone has the saddlebags open", 0, (Sprite)null, false);
				return false;
			}
			m_nview.ClaimOwnership();
			return true;
		}

		private int Pour(Player player, Inventory inventory, string prefabName)
		{
			float num = MetresPer(prefabName);
			float num2 = Capacity - Metres;
			if (num <= 0f || num2 < 1f || inventory == null)
			{
				return 0;
			}
			GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(prefabName) : null);
			ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return 0;
			}
			string name = val2.m_itemData.m_shared.m_name;
			int num3 = Mathf.Min(inventory.CountItems(name, -1, true), Mathf.CeilToInt(num2 / num));
			if (num3 <= 0)
			{
				return 0;
			}
			inventory.RemoveItem(name, num3, -1, true);
			m_nview.GetZDO().Set(s_fuelHash, Mathf.Min(Capacity, Metres + (float)num3 * num));
			MotorModPlugin.Log.LogInfo((object)$"{((Object)((Component)this).gameObject).name}: {player.GetPlayerName()} added {num3} {prefabName}, fuel {Metres:0} m of {Capacity:0}");
			return num3;
		}

		public void SetFraction(float f)
		{
			if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid())
			{
				return;
			}
			if (!m_nview.IsOwner())
			{
				if (m_bike.HasRider)
				{
					return;
				}
				m_nview.ClaimOwnership();
			}
			m_nview.GetZDO().Set(s_fuelHash, Mathf.Clamp01(f) * Capacity);
		}
	}
	public class BikeHealth : MonoBehaviour
	{
		private ZNetView m_nview;

		private MotorcycleController m_bike;

		private WearNTear m_wear;

		private string m_breakReason = "wrecked";

		private readonly Dictionary<int, float> m_lastImpact = new Dictionary<int, float>();

		private BikeDefinition D
		{
			get
			{
				if (!((Object)(object)m_bike != (Object)null))
				{
					return null;
				}
				return m_bike.m_definition;
			}
		}

		public float Max
		{
			get
			{
				if (!((Object)(object)m_wear != (Object)null))
				{
					return MotorModPlugin.MaxHealth.Value;
				}
				return m_wear.m_health;
			}
		}

		public float Health
		{
			get
			{
				if (!((Object)(object)m_nview != (Object)null) || !m_nview.IsValid())
				{
					return Max;
				}
				return m_nview.GetZDO().GetFloat(ZDOVars.s_health, Max);
			}
		}

		public float Fraction => Mathf.Clamp01(Health / Mathf.Max(1f, Max));

		private void Awake()
		{
			m_nview = ((Component)this).GetComponent<ZNetView>();
			m_bike = ((Component)this).GetComponent<MotorcycleController>();
			m_wear = ((Component)this).GetComponent<WearNTear>();
			if ((Object)(object)m_wear != (Object)null)
			{
				WearNTear wear = m_wear;
				wear.m_onDestroyed = (Action)Delegate.Combine(wear.m_onDestroyed, new Action(OnBroken));
			}
		}

		private void Hurt(float damage, string what)
		{
			if (!((Object)(object)m_wear == (Object)null) && !(damage <= 0f) && m_nview.IsOwner())
			{
				if (MotorModPlugin.Verbose)
				{
					MotorModPlugin.Log.LogInfo((object)$"{((Object)((Component)this).gameObject).name}: {what} -{damage:0} health, {Mathf.Max(0f, Health - damage):0}/{Max:0}");
				}
				m_wear.ApplyDamage(damage, (HitData)null);
			}
		}

		private void OnCollisionEnter(Collision info)
		{
			//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_0208: 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_007c: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Expected O, but got Unknown
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: 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_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: 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_010d: Expected O, but got Unknown
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_0158: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid() || !m_nview.IsOwner() || info.contacts.Length == 0)
			{
				return;
			}
			ContactPoint val = info.contacts[0];
			Collider otherCollider = ((ContactPoint)(ref val)).otherCollider;
			Character val2 = (Object.op_Implicit((Object)(object)otherCollider) ? ((Component)otherCollider).GetComponentInParent<Character>() : null);
			if ((Object)(object)val2 != (Object)null)
			{
				if (val2.IsPlayer() || val2.IsTamed())
				{
					return;
				}
				Vector3 val3 = ((Component)val2).transform.position - ((Component)this).transform.position;
				val3.y = 0f;
				float num = (((Object)(object)m_bike != (Object)null) ? m_bike.Speed : 0f) * ((((Vector3)(ref val3)).sqrMagnitude > 0.0001f) ? Vector3.Dot(((Component)this).transform.forward, ((Vector3)(ref val3)).normalized) : 1f);
				if (!(num < MotorModPlugin.RamMinSpeed.Value) && Ready((Component)(object)val2))
				{
					HitData val4 = new HitData();
					val4.m_damage.m_blunt = num * MotorModPlugin.RamDamage.Value;
					val4.m_point = ((ContactPoint)(ref val)).point;
					val4.m_dir = ((((Vector3)(ref val3)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref val3)).normalized : ((Component)this).transform.forward);
					val4.m_pushForce = num * 6f;
					val4.m_hitType = (HitType)11;
					Player val5 = RiderHere();
					if ((Object)(object)val5 != (Object)null)
					{
						val4.m_attacker = ((Character)val5).GetZDOID();
					}
					val2.Damage(val4);
					if (MotorModPlugin.Verbose)
					{
						MotorModPlugin.Log.LogInfo((object)$"{((Object)((Component)this).gameObject).name}: rammed {val2.m_name} at {num:0.0} m/s for {val4.m_damage.m_blunt:0}");
					}
					Hurt(num * 1.5f, "ram");
				}
				return;
			}
			float num2 = Mathf.Abs(Vector3.Dot(info.relativeVelocity, ((ContactPoint)(ref val)).normal));
			IDestructible val6 = (Object.op_Implicit((Object)(object)otherCollider) ? ((Component)otherCollider).GetComponentInParent<IDestructible>() : null);
			if (val6 != null && (object)val6 != m_wear && num2 >= MotorModPlugin.ObjectMinSpeed.Value)
			{
				Component val7 = (Component)(object)((val6 is Component) ? val6 : null);
				if (val7 != null && Ready(val7))
				{
					HitData val8 = new HitData();
					val8.m_damage.m_blunt = num2 * MotorModPlugin.ObjectDamage.Value;
					val8.m_point = ((ContactPoint)(ref val)).point;
					val8.m_dir = ((Component)this).transform.forward;
					val8.m_hitType = (HitType)11;
					Player val9 = RiderHere();
					if ((Object)(object)val9 != (Object)null)
					{
						val8.m_attacker = ((Character)val9).GetZDOID();
					}
					val6.Damage(val8);
					if (MotorModPlugin.Verbose)
					{
						MotorModPlugin.Log.LogInfo((object)$"{((Object)((Component)this).gameObject).name}: crashed into {((Object)val7.gameObject).name} at {num2:0.0} m/s for {val8.m_damage.m_blunt:0}");
					}
				}
			}
			float value = MotorModPlugin.CrashSpeed.Value;
			if (num2 > value)
			{
				float num3 = (num2 - value) * MotorModPlugin.CrashDamage.Value;
				if (num2 >= MotorModPlugin.FatalCrashSpeed.Value)
				{
					num3 = Mathf.Max(num3, Health);
				}
				if (num3 >= Health)
				{
					m_breakReason = "crash";
				}
				Hurt(num3, "crash");
				if (m_nview.IsValid())
				{
					m_breakReason = "wrecked";
				}
			}
		}

		private bool Ready(Component c)
		{
			int instanceID = ((Object)c).GetInstanceID();
			float time = Time.time;
			if (m_lastImpact.TryGetValue(instanceID, out var value) && time - value < 1f)
			{
				return false;
			}
			if (m_lastImpact.Count > 64)
			{
				List<int> list = new List<int>();
				foreach (KeyValuePair<int, float> item in m_lastImpact)
				{
					if (time - item.Value > 5f)
					{
						list.Add(item.Key);
					}
				}
				foreach (int item2 in list)
				{
					m_lastImpact.Remove(item2);
				}
			}
			m_lastImpact[instanceID] = time;
			return true;
		}

		private Player RiderHere()
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer != (Object)null) || !((Object)(object)m_bike != (Object)null) || (object)localPlayer.GetDoodadController() != m_bike)
			{
				return null;
			}
			return localPlayer;
		}

		public void Repair()
		{
			if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid())
			{
				return;
			}
			if (!m_nview.IsOwner())
			{
				if ((Object)(object)m_bike != (Object)null && m_bike.HasRider)
				{
					return;
				}
				m_nview.ClaimOwnership();
			}
			m_nview.GetZDO().Set(ZDOVars.s_health, Max);
			m_nview.InvokeRPC(ZNetView.Everybody, "RPC_HealthChanged", new object[1] { Max });
		}

		public void BreakApart(string why)
		{
			if (!((Object)(object)m_nview == (Object)null) && m_nview.IsValid() && m_nview.IsOwner() && !((Object)(object)m_wear == (Object)null))
			{
				m_breakReason = why;
				m_wear.Remove(false);
			}
		}

		private void OnBroken()
		{
			//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_0033: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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)
			if (m_breakReason == "crash" && MotorModPlugin.CrashBreakEffect != null)
			{
				MotorModPlugin.CrashBreakEffect.Create(((Component)this).transform.position + Vector3.up * 0.5f, ((Component)this).transform.rotation, (Transform)null, 1f, -1, default(ZDOID));
			}
			Player val = RiderHere();
			if ((Object)(object)val != (Object)null)
			{
				val.StopDoodadControl();
				((Character)val).Message((MessageType)2, (m_breakReason == "sank") ? "Your bike sank and broke apart." : ((m_breakReason == "crash") ? "Your bike blew apart." : "Your bike is wrecked."), 0, (Sprite)null, false);
			}
			MotorModPlugin.Log.LogInfo((object)(((Object)((Component)this).gameObject).name + " broke (" + m_breakReason + ")"));
		}
	}
	internal static class Saddlebags
	{
		[HarmonyPatch(typeof(Container), "Interact")]
		private static class Open
		{
			private static bool Prefix(Container __instance, Humanoid character, bool hold, bool alt, ref bool __result)
			{
				MotorcycleController motorcycleController = BikeOf(__instance);
				if ((Object)(object)motorcycleController == (Object)null || hold)
				{
					return true;
				}
				Player val = (Player)(object)((character is Player) ? character : null);
				if (alt && (Object)(object)val != (Object)null && (Object)(object)motorcycleController.Fuel != (Object)null && BikeFuel.Enabled)
				{
					motorcycleController.Fuel.Fill(val);
					__result = true;
					return false;
				}
				if (motorcycleController.HasRider)
				{
					((Character)character).Message((MessageType)2, "Someone is riding it", 0, (Sprite)null, false);
					__result = true;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Container), "GetHoverText")]
		private static class Hover
		{
			private static void Postfix(Container __instance, ref string __result)
			{
				MotorcycleController motorcycleController = BikeOf(__instance);
				if (!((Object)(object)motorcycleController == (Object)null) && !((Object)(object)motorcycleController.Fuel == (Object)null) && BikeFuel.Enabled)
				{
					__result += Localization.instance.Localize("\nFuel " + motorcycleController.Fuel.Percent + (motorcycleController.Standing ? motorcycleController.Fuel.FillHint : ""));
				}
			}
		}

		public static MotorcycleController BikeOf(Container c)
		{
			if (!((Object)(object)c != (Object)null) || !((Object)(object)c.m_rootObjectOverride != (Object)null))
			{
				return null;
			}
			return ((Component)c.m_rootObjectOverride).GetComponent<MotorcycleController>();
		}
	}
	[HarmonyPatch(typeof(Piece), "CanBeRemoved")]
	internal static class NoRemovingRiddenBikes
	{
		private static void Postfix(Piece __instance, ref bool __result)
		{
			if (__result)
			{
				MotorcycleController component = ((Component)__instance).GetComponent<MotorcycleController>();
				if ((Object)(object)component != (Object)null && component.HasRider)
				{
					__result = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(WearNTear), "RPC_Damage")]
	internal static class BikeHitScale
	{
		private static void Prefix(WearNTear __instance, HitData hit)
		{
			if (hit != null && !((Object)(object)((Component)__instance).GetComponent<BikeHealth>() == (Object)null))
			{
				float value = MotorModPlugin.HitDamageScale.Value;
				if (!Mathf.Approximately(value, 1f))
				{
					((DamageTypes)(ref hit.m_damage)).Modify(Mathf.Max(0f, value));
				}
			}
		}
	}
	[HarmonyPatch(typeof(Hud), "UpdateMount")]
	internal static class FuelGauge
	{
		private static bool s_healthHidden;

		private static void Postfix(Hud __instance, Player player)
		{
			MotorcycleController motorcycleController = (((Object)(object)player != (Object)null) ? (player.GetDoodadController() as MotorcycleController) : null);
			bool flag = (Object)(object)motorcycleController != (Object)null && (Object)(object)motorcycleController.Fuel != (Object)null && BikeFuel.Enabled;
			if (flag != s_healthHidden)
			{
				s_healthHidden = flag;
				GameObject[] array = new GameObject[3];
				GuiBar mountHealthBarSlow = __instance.m_mountHealthBarSlow;
				array[0] = ((mountHealthBarSlow != null) ? ((Component)mountHealthBarSlow).gameObject : null);
				GuiBar mountHealthBarFast = __instance.m_mountHealthBarFast;
				array[1] = ((mountHealthBarFast != null) ? ((Component)mountHealthBarFast).gameObject : null);
				TextMeshProUGUI mountHealthText = __instance.m_mountHealthText;
				array[2] = ((mountHealthText != null) ? ((Component)mountHealthText).gameObject : null);
				GameObject[] array2 = (GameObject[])(object)array;
				foreach (GameObject val in array2)
				{
					if ((Object)(object)val != (Object)null)
					{
						val.SetActive(!flag);
					}
				}
			}
			if (flag)
			{
				__instance.m_mountPanel.SetActive(true);
				Piece component = ((Component)motorcycleController).GetComponent<Piece>();
				if ((Object)(object)component != (Object)null && (Object)(object)__instance.m_mountIcon != (Object)null)
				{
					__instance.m_mountIcon.overrideSprite = component.m_icon;
				}
				__instance.m_mountStaminaBar.SetValue(motorcycleController.Fuel.Fraction);
				((TMP_Text)__instance.m_mountStaminaText).text = "Fuel " + motorcycleController.Fuel.Percent;
				((TMP_Text)__instance.m_mountNameText).text = motorcycleController.m_hoverText;
			}
		}
	}
	internal static class BikePrefabSetup
	{
		public static Vector3 BagSize;

		public static Bounds BagBounds;

		private static readonly Dictionary<string, Vector3[]> s_bikePoints = new Dictionary<string, Vector3[]>();

		public static void Configure(GameObject prefab, AssetBundle bundle, BikeDefinition def, GameObject saddlebag, Sprite icon)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			int num = LayerMask.NameToLayer("vehicle");
			if (num < 0)
			{
				num = LayerMask.NameToLayer("piece");
			}
			Transform[] componentsInChildren = prefab.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Component)componentsInChildren[i]).gameObject.layer = num;
			}
			if (def.Scale.Value != 1f)
			{
				prefab.transform.localScale = Vector3.one * def.Scale.Value;
			}
			Rigidbody obj = prefab.GetComponent<Rigidbody>() ?? prefab.AddComponent<Rigidbody>();
			obj.mass = 320f;
			obj.linearDamping = 0.05f;
			obj.angularDamping = 5f;
			obj.interpolation = (RigidbodyInterpolation)1;
			obj.collisionDetectionMode = (CollisionDetectionMode)1;
			obj.constraints = (RigidbodyConstraints)112;
			ZNetView val = prefab.GetComponent<ZNetView>() ?? prefab.AddComponent<ZNetView>();
			val.m_persistent = true;
			val.m_distant = false;
			val.m_type = (ObjectType)0;
			ZSyncTransform obj2 = prefab.GetComponent<ZSyncTransform>() ?? prefab.AddComponent<ZSyncTransform>();
			obj2.m_syncPosition = true;
			obj2.m_syncRotation = true;
			obj2.m_syncBodyVelocity = true;
			MotorcycleController motorcycleController = prefab.GetComponent<MotorcycleController>() ?? prefab.AddComponent<MotorcycleController>();
			motorcycleController.m_attachPoint = FindDeep(prefab.transform, "SeatAttach");
			motorcycleController.m_visual = prefab.transform.Find("Visual");
			motorcycleController.m_wheelFront = FindDeep(prefab.transform, "WheelFront");
			motorcycleController.m_wheelRear = FindDeep(prefab.transform, "WheelRear");
			motorcycleController.m_gripLeft = FindDeep(prefab.transform, "GripLeft");
			motorcycleController.m_gripRight = FindDeep(prefab.transform, "GripRight");
			motorcycleController.m_headlight = FindDeep(prefab.transform, "Headlight");
			motorcycleController.m_hoverText = def.DisplayName;
			motorcycleController.m_definition = def;
			Piece obj3 = prefab.GetComponent<Piece>() ?? prefab.AddComponent<Piece>();
			obj3.m_name = def.DisplayName;
			obj3.m_description = def.Description;
			obj3.m_icon = icon;
			obj3.m_groundOnly = false;
			obj3.m_allowedInDungeons = false;
			obj3.m_clipGround = false;
			obj3.m_noInWater = false;
			obj3.m_canBeRemoved = true;
			WearNTear obj4 = prefab.GetComponent<WearNTear>() ?? prefab.AddComponent<WearNTear>();
			obj4.m_health = MotorModPlugin.MaxHealth.Value;
			obj4.m_noRoofWear = false;
			obj4.m_noSupportWear = false;
			obj4.m_supports = false;
			obj4.m_staticPosition = false;
			obj4.m_burnable = false;
			obj4.m_snowDamageImmune = true;
			obj4.m_ashDamageResist = true;
			obj4.m_triggerPrivateArea = true;
			obj4.m_autoCreateFragments = false;
			obj4.m_materialType = (MaterialType)2;
			if ((Object)(object)prefab.GetComponent<BikeHealth>() == (Object)null)
			{
				prefab.AddComponent<BikeHealth>();
			}
			if ((Object)(object)prefab.GetComponent<BikeFuel>() == (Object)null)
			{
				prefab.AddComponent<BikeFuel>();
			}
			if ((Object)(object)prefab.GetComponent<BikeCondition>() == (Object)null)
			{
				prefab.AddComponent<BikeCondition>();
			}
			if ((Object)(object)saddlebag != (Object)null)
			{
				AddSaddlebags(prefab, motorcycleController, val, saddlebag, num);
			}
			if (!string.IsNullOrEmpty(def.Trail))
			{
				(prefab.GetComponent<BikeTrail>() ?? prefab.AddComponent<BikeTrail>()).m_kind = def.Trail;
			}
			if ((Object)(object)prefab.GetComponent<BikeWake>() == (Object)null)
			{
				prefab.AddComponent<BikeWake>();
			}
			EngineAudio engineAudio = prefab.GetComponent<EngineAudio>() ?? prefab.AddComponent<EngineAudio>();
			engineAudio.m_startupShort = bundle.LoadAsset<AudioClip>("startup_short");
			engineAudio.m_startupFull = bundle.LoadAsset<AudioClip>("startup_full");
			engineAudio.m_idle = bundle.LoadAsset<AudioClip>("idle_loop");
			engineAudio.m_cruiseLow = bundle.LoadAsset<AudioClip>("cruise_low");
			engineAudio.m_cruiseHigh = bundle.LoadAsset<AudioClip>("cruise_high");
			engineAudio.m_cruiseFast = bundle.LoadAsset<AudioClip>("cruise_fast");
			engineAudio.m_accel = bundle.LoadAsset<AudioClip>("accel");
			engineAudio.m_revBlips = bundle.LoadAsset<AudioClip>("rev_blips");
			engineAudio.m_shutoff = bundle.LoadAsset<AudioClip>("shutoff");
			Light val2 = (Object.op_Implicit((Object)(object)motorcycleController.m_headlight) ? ((Component)motorcycleController.m_headlight).GetComponent<Light>() : null);
			MotorModPlugin.Log.LogInfo((object)(def.DisplayName + " configured: seat=" + (Object.op_Implicit((Object)(object)motorcycleController.m_attachPoint) ? "ok" : "MISSING") + " wheels=" + (Object.op_Implicit((Object)(object)motorcycleController.m_wheelFront) ? "F" : "-") + (Object.op_Implicit((Object)(object)motorcycleController.m_wheelRear) ? "R" : "-") + " grips=" + ((Object.op_Implicit((Object)(object)motorcycleController.m_gripLeft) && Object.op_Implicit((Object)(object)motorcycleController.m_gripRight)) ? "ok" : "MISSING") + " headlight=" + (Object.op_Implicit((Object)(object)val2) ? "ok" : "MISSING") + " idle=" + (Object.op_Implicit((Object)(object)engineAudio.m_idle) ? engineAudio.m_idle.length.ToString("0.0") : "MISSING") + "s"));
		}

		private static void AddSaddlebags(GameObject prefab, MotorcycleController bike, ZNetView nview, GameObject saddlebag, int layer)
		{
			//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_003f: 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_004d: Expected O, but got Unknown
			//IL_006b: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)bike.m_visual == (Object)null)
			{
				return;
			}
			if (BagSize == Vector3.zero)
			{
				BagBounds = MeasureBag(saddlebag);
				BagSize = ((Bounds)(ref BagBounds)).size;
			}
			GameObject val = new GameObject("Saddlebags")
			{
				layer = layer
			};
			val.transform.SetParent(bike.m_visual, false);
			val.transform.SetPositionAndRotation(prefab.transform.position, prefab.transform.rotation);
			for (int i = 0; i < 2; i++)
			{
				GameObject val2 = Object.Instantiate<GameObject>(saddlebag, val.transform, false);
				((Object)val2).name = ((i == 0) ? "BagLeft" : "BagRight");
				Transform[] componentsInChildren = val2.GetComponentsInChildren<Transform>(true);
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					((Component)componentsInChildren[j]).gameObject.layer = layer;
				}
				Collider[] componentsInChildren2 = val2.GetComponentsInChildren<Collider>(true);
				for (int j = 0; j < componentsInChildren2.Length; j++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren2[j], true);
				}
				((Collider)val.AddComponent<BoxCollider>()).isTrigger = true;
			}
			Container obj = val.AddComponent<Container>();
			obj.m_name = "Saddlebags";
			obj.m_width = 2;
			obj.m_height = 1;
			obj.m_privacy = (PrivacySetting)2;
			obj.m_checkGuardStone = false;
			obj.m_autoDestroyEmpty = false;
			obj.m_rootObjectOverride = nview;
			bike.m_bags = val.transform;
		}

		private static Bounds MeasureBag(GameObject saddlebag)
		{
			//IL_0002: 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_0106: 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_012e: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: 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_0065: 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_0092: 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_009c: 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_00a6: 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_00ad: 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)
			Bounds result = default(Bounds);
			bool flag = false;
			MeshFilter[] componentsInChildren = saddlebag.GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val in componentsInChildren)
			{
				if ((Object)(object)val.sharedMesh == (Object)null)
				{
					continue;
				}
				Matrix4x4 val2 = saddlebag.transform.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix;
				Bounds bounds = val.sharedMesh.bounds;
				for (int j = 0; j < 8; j++)
				{
					Vector3 val3 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1)))));
					if (!flag)
					{
						((Bounds)(ref result))..ctor(val3, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref result)).Encapsulate(val3);
					}
				}
			}
			MotorModPlugin.Log.LogInfo((object)$"Saddlebag model: {((Bounds)(ref result)).size.x:0.00} deep, {((Bounds)(ref result)).size.y:0.00} high, {((Bounds)(ref result)).size.z:0.00} wide (x {((Bounds)(ref result)).min.x:0.00} to {((Bounds)(ref result)).max.x:0.00})");
			if (!flag)
			{
				return default(Bounds);
			}
			return result;
		}

		public static float HalfWidthAt(MotorcycleController bike, float z0, float z1, float y0, float y1)
		{
			//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_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_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: 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_017a: 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_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_00d7: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			string key = ((Object)((Component)bike).gameObject).name.Replace("(Clone)", "");
			Vector3[] vertices;
			if (!s_bikePoints.TryGetValue(key, out var value))
			{
				List<Vector3> list = new List<Vector3>();
				Matrix4x4 worldToLocalMatrix = ((Component)bike).transform.worldToLocalMatrix;
				MeshFilter[] componentsInChildren = ((Component)bike.m_visual).GetComponentsInChildren<MeshFilter>(true);
				foreach (MeshFilter val in componentsInChildren)
				{
					if (!((Object)(object)val.sharedMesh == (Object)null) && val.sharedMesh.isReadable && (!((Object)(object)bike.m_bags != (Object)null) || !((Component)val).transform.IsChildOf(bike.m_bags)) && (!((Object)(object)bike.m_headlight != (Object)null) || !((Component)val).transform.IsChildOf(bike.m_headlight)))
					{
						Matrix4x4 val2 = worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix;
						vertices = val.sharedMesh.vertices;
						foreach (Vector3 val3 in vertices)
						{
							list.Add(((Matrix4x4)(ref val2)).MultiplyPoint3x4(val3));
						}
					}
				}
				value = (s_bikePoints[key] = list.ToArray());
			}
			float num = 0f;
			vertices = value;
			foreach (Vector3 val4 in vertices)
			{
				if (val4.z >= z0 && val4.z <= z1 && val4.y >= y0 && val4.y <= y1 && Mathf.Abs(val4.x) > num)
				{
					num = Mathf.Abs(val4.x);
				}
			}
			return num;
		}

		public static int PointsInside(MotorcycleController bike, Bounds box)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			HalfWidthAt(bike, 0f, 0f, 0f, 0f);
			if (!s_bikePoints.TryGetValue(((Object)((Component)bike).gameObject).name.Replace("(Clone)", ""), out var value))
			{
				return 0;
			}
			return ((IEnumerable<Vector3>)value).Count((Func<Vector3, bool>)((Bounds)(object)box).Contains);
		}

		private static Transform FindDeep(Transform root, string name)
		{
			Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (((Object)val).name == name)
				{
					return val;
				}
			}
			return null;
		}
	}
	public class BikeTrail : MonoBehaviour
	{
		private struct Mark
		{
			public Vector3 pos;

			public float time;
		}

		public string m_kind = "fire";

		private MotorcycleController m_bike;

		private ZNetView m_nview;

		private bool m_built;

		private readonly List<ParticleSystem> m_emitters = new List<ParticleSystem>();

		private const float BaseDensity = 10f;

		private Light m_glow;

		private const float GlowPeak = 1.4f;

		private readonly List<Mark> m_marks = new List<Mark>();

		private Vector3 m_lastMark = new Vector3(float.MaxValue, 0f, 0f);

		private float m_nextScan;

		private readonly Dictionary<int, float> m_lastHit = new Dictionary<int, float>();

		private const float MarkLifetime = 2.5f;

		private const float TrailHalfWidth = 1.1f;

		private void Awake()
		{
			m_bike = ((Component)this).GetComponent<MotorcycleController>();
			m_nview = ((Component)this).GetComponent<ZNetView>();
		}

		internal static GameObject Effect(string name)
		{
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(name) : null);
			if (!((Object)(object)val != (Object)null))
			{
				return Cache.GetPrefab<GameObject>(name);
			}
			return val;
		}

		private void Update()
		{
			//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_0108: 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)
			if ((Object)(object)m_bike == (Object)null || (Object)(object)m_nview == (Object)null || !m_nview.IsValid())
			{
				return;
			}
			if (!m_built && (Object)(object)ZNetScene.instance != (Object)null)
			{
				m_built = true;
				Build();
			}
			BikeDefinition definition = m_bike.m_definition;
			float num = Mathf.Abs(m_bike.SyncedSpeed);
			float num2 = Mathf.Max(1f, definition?.CfgTopSpeed.Value ?? 16f);
			bool flag = MotorModPlugin.Trails.Value && m_bike.EngineOn && num > 2f;
			float num3 = (flag ? (10f * MotorModPlugin.TrailDensity.Value * (1f + Mathf.Clamp01(num / num2))) : 0f);
			foreach (ParticleSystem emitter in m_emitters)
			{
				if (!((Object)(object)emitter == (Object)null))
				{
					EmissionModule emission = emitter.emission;
					((EmissionModule)(ref emission)).rateOverDistance = MinMaxCurve.op_Implicit(num3);
					((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f);
				}
			}
			if ((Object)(object)m_glow != (Object)null)
			{
				m_glow.intensity = Mathf.MoveTowards(m_glow.intensity, flag ? 1.4f : 0f, 3f * Time.deltaTime);
			}
			if (m_nview.IsOwner())
			{
				if (flag)
				{
					DropMark();
				}
				if (Time.time >= m_nextScan)
				{
					m_nextScan = Time.time + 0.25f;
					ScanHits();
				}
			}
		}

		private void Build()
		{
			//IL_0053: 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)
			AddEmitters(FindFlames("fire_pit", "flames (1)"));
			string kind = m_kind;
			if (!(kind == "fire_blue"))
			{
				if (kind == "fire_green")
				{
					Recolour("fx_Torch_Green");
					AddGlow(new Color(0.4f, 1f, 0.45f));
				}
			}
			else
			{
				Recolour("fx_Torch_Blue");
				AddGlow(new Color(0.4f, 0.62f, 1f));
			}
			MotorModPlugin.Log.LogInfo((object)$"{((Object)((Component)this).gameObject).name}: trail '{m_kind}' with {m_emitters.Count} emitters");
		}

		private void Recolour(string torch)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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_00b4: 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)
			//IL_00eb: 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_00fa: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Invalid comparison between Unknown and I4
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Invalid comparison between Unknown and I4
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: 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_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Effect(torch);
			ParticleSystem val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ParticleSystem>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				MotorModPlugin.Log.LogWarning((object)(((Object)((Component)this).gameObject).name + ": no flames on " + torch));
				return;
			}
			MainModule main = val2.main;
			ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
			CustomDataModule customData = val2.customData;
			foreach (ParticleSystem emitter in m_emitters)
			{
				if ((Object)(object)emitter == (Object)null)
				{
					continue;
				}
				MainModule main2 = emitter.main;
				((MainModule)(ref main2)).startColor = ((MainModule)(ref main)).startColor;
				ColorOverLifetimeModule colorOverLifetime2 = emitter.colorOverLifetime;
				((ColorOverLifetimeModule)(ref colorOverLifetime2)).enabled = ((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled;
				((ColorOverLifetimeModule)(ref colorOverLifetime2)).color = ((ColorOverLifetimeModule)(ref colorOverLifetime)).color;
				CustomDataModule customData2 = emitter.customData;
				((CustomDataModule)(ref customData2)).enabled = ((CustomDataModule)(ref customData)).enabled;
				ParticleSystemCustomData[] array = (ParticleSystemCustomData[])(object)new ParticleSystemCustomData[2]
				{
					default(ParticleSystemCustomData),
					(ParticleSystemCustomData)1
				};
				foreach (ParticleSystemCustomData val3 in array)
				{
					ParticleSystemCustomDataMode mode = ((CustomDataModule)(ref customData)).GetMode(val3);
					((CustomDataModule)(ref customData2)).SetMode(val3, mode);
					if ((int)mode == 2)
					{
						((CustomDataModule)(ref customData2)).SetColor(val3, ((CustomDataModule)(ref customData)).GetColor(val3));
					}
					else if ((int)mode == 1)
					{
						int vectorComponentCount = ((CustomDataModule)(ref customData)).GetVectorComponentCount(val3);
						((CustomDataModule)(ref customData2)).SetVectorComponentCount(val3, vectorComponentCount);
						for (int j = 0; j < vectorComponentCount; j++)
						{
							((CustomDataModule)(ref customData2)).SetVector(val3, j, ((CustomDataModule)(ref customData)).GetVector(val3, j));
						}
					}
				}
			}
		}

		private void AddGlow(Color colour)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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)
			if (!((Object)(object)m_bike.m_wheelRear == (Object)null))
			{
				GameObject val = new GameObject("TrailGlow");
				val.transform.SetParent(((Object)(object)m_bike.m_visual != (Object)null) ? m_bike.m_visual : ((Component)this).transform, false);
				val.transform.position = m_bike.m_wheelRear.position + ((Component)this).transform.up * 0.2f - ((Component)this).transform.forward * 0.4f;
				m_glow = val.AddComponent<Light>();
				m_glow.type = (LightType)2;
				m_glow.color = colour;
				m_glow.range = 4f;
				m_glow.intensity = 0f;
				m_glow.shadows = (LightShadows)0;
			}
		}

		private static GameObject FindFlames(string prefab, string child)
		{
			GameObject prefab2 = ZNetScene.instance.GetPrefab(prefab);
			if ((Object)(object)prefab2 == (Object)null)
			{
				return null;
			}
			ParticleSystem[] componentsInChildren = prefab2.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val in componentsInChildren)
			{
				if (((Object)((Component)val).gameObject).name == child)
				{
					return ((Component)val).gameObject;
				}
			}
			return null;
		}

		private void AddEmitters(GameObject source)
		{
			//IL_00fe: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: 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_0142: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: 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_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: 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_0211: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)source == (Object)null)
			{
				MotorModPlugin.Log.LogWarning((object)(((Object)((Component)this).gameObject).name + ": the campfire flames are missing"));
				return;
			}
			Transform[] array = (Transform[])(object)new Transform[2] { m_bike.m_wheelRear, m_bike.m_wheelFront };
			foreach (Transform val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				GameObject val2 = LocalCopy(source);
				Component[] componentsInChildren = val2.GetComponentsInChildren<Component>(true);
				foreach (Component val3 in componentsInChildren)
				{
					if (!(val3 is Transform) && !(val3 is ParticleSystem) && !(val3 is ParticleSystemRenderer))
					{
						Object.Destroy((Object)(object)val3);
					}
				}
				((Object)val2).name = "Trail_" + m_kind;
				val2.transform.SetParent(((Object)(object)m_bike.m_visual != (Object)null) ? m_bike.m_visual : ((Component)this).transform, false);
				val2.transform.position = val.position - ((Component)this).transform.up * Mathf.Max(0.2f, m_bike.m_wheelRadius) * 0.85f;
				val2.transform.rotation = Quaternion.identity;
				ParticleSystem[] componentsInChildren2 = val2.GetComponentsInChildren<ParticleSystem>(true);
				foreach (ParticleSystem val4 in componentsInChildren2)
				{
					MainModule main = val4.main;
					((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
					((MainModule)(ref main)).loop = true;
					((MainModule)(ref main)).startLifetimeMultiplier = Mathf.Max(0.8f, ((MainModule)(ref main)).startLifetimeMultiplier) * 1.2f;
					((MainModule)(ref main)).startSizeMultiplier = ((MainModule)(ref main)).startSizeMultiplier * 1.4f;
					((MainModule)(ref main)).gravityModifierMultiplier = -0.15f;
					ShapeModule shape = val4.shape;
					((ShapeModule)(ref shape)).enabled = true;
					((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
					((ShapeModule)(ref shape)).radius = 0.18f;
					InheritVelocityModule inheritVelocity = val4.inheritVelocity;
					((InheritVelocityModule)(ref inheritVelocity)).enabled = false;
					EmissionModule emission = val4.emission;
					((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f);
					((EmissionModule)(ref emission)).rateOverDistance = MinMaxCurve.op_Implicit(0f);
					val4.Play();
					m_emitters.Add(val4);
				}
			}
		}

		internal static GameObject LocalCopy(GameObject source)
		{
			ZNetView.m_forceDisableInit = true;
			try
			{
				return Object.Instantiate<GameObject>(source);
			}
			finally
			{
				ZNetView.m_forceDisableInit = false;
			}
		}

		private void DropMark()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0031: 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_0038: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (((Object)(object)m_bike.m_wheelRear != (Object)null) ? m_bike.m_wheelRear.position : ((Component)this).transform.position);
			Vector3 val2 = val - m_lastMark;
			if (!(((Vector3)(ref val2)).sqrMagnitude < 1f))
			{
				m_lastMark = val;
				m_marks.Add(new Mark
				{
					pos = val,
					time = Time.time
				});
				if (m_marks.Count > 64)
				{
					m_marks.RemoveAt(0);
				}
			}
		}

		private static bool NearSegment(Vector3 p, Vector3 a, Vector3 b, float reach)
		{
			//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_0015: 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_0026: 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_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_0038: 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_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_0055: 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_006e: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_0091: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(p.x, p.z);
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(a.x, a.z);
			Vector2 val3 = new Vector2(b.x, b.z) - val2;
			float num = ((((Vector2)(ref val3)).sqrMagnitude > 1E-06f) ? Mathf.Clamp01(Vector2.Dot(val - val2, val3) / ((Vector2)(ref val3)).sqrMagnitude) : 0f);
			Vector2 val4 = val2 + val3 * num - val;
			if (((Vector2)(ref val4)).sqrMagnitude > reach * reach)
			{
				return false;
			}
			return Mathf.Abs(p.y - Mathf.Lerp(a.y, b.y, num)) < 2.5f;
		}

		private void ScanHits()
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_0120: Expected O, but got Unknown
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			float now = Time.time;
			m_marks.RemoveAll((Mark m) => now - m.time > 2.5f);
			if (m_marks.Count == 0)
			{
				return;
			}
			Player val = RiderPlayer();
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				if (!IsTarget(allCharacter))
				{
					continue;
				}
				int instanceID = ((Object)allCharacter).GetInstanceID();
				if (m_lastHit.TryGetValue(instanceID, out var value) && now - value < 1f)
				{
					continue;
				}
				Vector3 position = ((Component)allCharacter).transform.position;
				float reach = 1.1f + Mathf.Clamp(allCharacter.GetRadius(), 0.2f, 1.5f);
				for (int num = 0; num < m_marks.Count; num++)
				{
					Mark mark = m_marks[num];
					Vector3 pos = mark.pos;
					Vector3 b = ((num + 1 < m_marks.Count) ? m_marks[num + 1].pos : mark.pos);
					if (NearSegment(position, pos, b, reach))
					{
						HitData val2 = new HitData();
						val2.m_point = allCharacter.GetCenterPoint();
						Vector3 val3 = ((Component)allCharacter).transform.position - mark.pos;
						val3.y = 0f;
						val2.m_dir = ((((Vector3)(ref val3)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref val3)).normalized : Vector3.forward);
						if ((Object)(object)val != (Object)null)
						{
							val2.m_attacker = ((Character)val).GetZDOID();
						}
						val2.m_damage.m_fire = MotorModPlugin.FireDamage.Value;
						allCharacter.Damage(val2);
						m_lastHit[instanceID] = now;
						break;
					}
				}
			}
		}

		private static bool IsTarget(Character c)
		{
			if ((Object)(object)c != (Object)null && !c.IsPlayer() && !c.IsTamed())
			{
				return !c.IsDead();
			}
			return false;
		}

		private Player RiderPlayer()
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer != (Object)null) || (object)localPlayer.GetDoodadController() != m_bike)
			{
				return null;
			}
			return localPlayer;
		}
	}
	internal static class BikeVanillaParts
	{
		public const string WreckBagName = "MotorModSaddlebag";

		public static GameObject WreckBag;

		private static bool s_done;

		public static void Register()
		{
			PrefabManager.OnVanillaPrefabsAvailable += delegate
			{
				Finish(sceneStarted: false);
			};
			PrefabManager.OnPrefabsRegistered += delegate
			{
				Finish(sceneStarted: true);
			};
		}

		private static void Finish(bool sceneStarted)
		{
			if (s_done)
			{
				return;
			}
			s_done = true;
			try
			{
				MakeWreckBag();
			}
			catch (Exception ex)
			{
				MotorModPlugin.Log.LogError((object)("wreck saddlebag: " + ex));
			}
			if (!sceneStarted)
			{
				try
				{
					FlamingSkulls.Create();
				}
				catch (Exception ex2)
				{
					MotorModPlugin.Log.LogError((object)("flaming skulls: " + ex2));
				}
			}
			if (sceneStarted && (Object)(object)WreckBag != (Object)null && ((Object)WreckBag).name == "MotorModSaddlebag")
			{
				PrefabManager.Instance.RegisterToZNetScene(WreckBag);
			}
			GameObject prefab = PrefabManager.Instance.GetPrefab("iron_grate");
			WearNTear val = ((prefab != null) ? prefab.GetComponent<WearNTear>() : null);
			GameObject prefab2 = PrefabManager.Instance.GetPrefab("piece_chest_wood");
			Container val2 = ((prefab2 != null) ? prefab2.GetComponent<Container>() : null);
			EffectList val3 = Effects("vfx_HitSparks", "sfx_metalbars_hit");
			EffectList val4 = Effects("vfx_Damaged_Karve", "sfx_metalbars_break");
			EffectList val5 = Effects("vfx_Damaged_Karve", "vfx_HitSparks", "sfx_metalbars_break");
			MotorModPlugin.CrashBreakEffect = Effects("fx_dynamite_explosion", "sfx_bombdynamite_explosion");
			foreach (BikeDefinition item in BikeDefinition.All)
			{
				if ((Object)(object)item.Prefab == (Object)null)
				{
					continue;
				}
				WearNTear component = item.Prefab.GetComponent<WearNTear>();
				if ((Object)(object)component != (Object)null)
				{
					component.m_hitEffect = val3;
					component.m_switchEffect = val4;
					component.m_destroyedEffect = val5;
					if ((Object)(object)val != (Object)null)
					{
						component.m_hitNoise = val.m_hitNoise;
						component.m_destroyNoise = val.m_destroyNoise;
					}
				}
				MotorcycleController component2 = item.Prefab.GetComponent<MotorcycleController>();
				Container val6 = (((Object)(object)component2 != (Object)null && (Object)(object)component2.m_bags != (Object)null) ? ((Component)component2.m_bags).GetComponent<Container>() : null);
				if ((Object)(object)val6 != (Object)null)
				{
					val6.m_destroyedLootPrefab = WreckBag;
					if ((Object)(object)val2 != (Object)null)
					{
						val6.m_bkg = val2.m_bkg;
					}
				}
			}
			MotorModPlugin.Log.LogInfo((object)string.Format("Bikes finished with the game's parts: wreck bag {0}, iron noise {1}, chest background {2}, hit/step/destroyed effects {3}/{4}/{5}, crash effect {6}", ((Object)(object)WreckBag != (Object)null) ? "ok" : "MISSING", ((Object)(object)val != (Object)null) ? "ok" : "MISSING", ((Object)(object)val2 != (Object)null) ? "ok" : "MISSING", val3.m_effectPrefabs.Length, val4.m_effectPrefabs.Length, val5.m_effectPrefabs.Length, MotorModPlugin.CrashBreakEffect.m_effectPrefabs.Length));
		}

		private static EffectList Effects(params string[] names)
		{
			//IL_0060: 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_0072: Expected O, but got Unknown
			//IL_0044: 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_0056: Expected O, but got Unknown
			List<EffectData> list = new List<EffectData>();
			foreach (string text in names)
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab(text);
				if ((Object)(object)prefab == (Object)null)
				{
					MotorModPlugin.Log.LogWarning((object)("effect " + text + " not found"));
					continue;
				}
				list.Add(new EffectData
				{
					m_prefab = prefab
				});
			}
			return new EffectList
			{
				m_effectPrefabs = list.ToArray()
			};
		}

		private static void MakeWreckBag()
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: 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_0144: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: 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_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Expected O, but got Unknown
			GameObject saddlebagPrefab = MotorModPlugin.SaddlebagPrefab;
			if ((Object)(object)saddlebagPrefab == (Object)null)
			{
				MotorModPlugin.Log.LogWarning((object)"No saddlebag model: wrecks drop the game's cargo crate");
				WreckBag = PrefabManager.Instance.GetPrefab("CargoCrate");
				return;
			}
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("MotorModSaddlebag", "CargoCrate");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			List<GameObject> list = new List<GameObject>();
			foreach (Transform item in val.transform)
			{
				Transform val2 = item;
				list.Add(((Component)val2).gameObject);
			}
			foreach (GameObject item2 in list)
			{
				Object.DestroyImmediate((Object)(object)item2);
			}
			LODGroup component = val.GetComponent<LODGroup>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			float num = 1.1f;
			Vector3 val3 = BikePrefabSetup.BagSize * num;
			GameObject obj = Object.Instantiate<GameObject>(saddlebagPrefab, val.transform, false);
			((Object)obj).name = "Bag";
			obj.transform.localScale = Vector3.one * num;
			Vector3 val4 = ((Bounds)(ref BikePrefabSetup.BagBounds)).center * num;
			obj.transform.localPosition = new Vector3(0f - val4.x, val3.y / 2f - val4.y, 0f - val4.z);
			Transform[] componentsInChildren = obj.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Component)componentsInChildren[i]).gameObject.layer = val.layer;
			}
			GameObject val5 = new GameObject("collider")
			{
				layer = val.layer
			};
			val5.transform.SetParent(val.transform, false);
			BoxCollider obj2 = val5.AddComponent<BoxCollider>();
			obj2.size = val3;
			obj2.center = new Vector3(0f, val3.y / 2f, 0f);
			Container component2 = val.GetComponent<Container>();
			component2.m_name = "Saddlebag";
			component2.m_width = 2;
			component2.m_height = 1;
			Floating component3 = val.GetComponent<Floating>();
			if ((Object)(object)component3 != (Object)null)
			{
				component3.m_waterLevelOffset += 0.12f;
			}
			PrefabManager.Instance.AddPrefab(new CustomPrefab(val, false));
			WreckBag = val;
		}
	}
	public class BikeWake : MonoBehaviour
	{
		private enum Anchor
		{
			Front,
			Rear,
			Middle
		}

		private class Layer
		{
			public ParticleSystem ps;

			public Transform t;

			public Anchor at;

			public float back;

			public float side;

			public float perMetre;

			public float perSecondAtTop;

			public float perSecondIdle;

			public Quaternion turn;
		}

		private MotorcycleController m_bike;

		private ZNetView m_nview;

		private bool m_built;

		private readonly List<Layer> m_layers = new List<Layer>();

		private void Awake()
		{
			m_bike = ((Component)this).GetComponent<MotorcycleController>();
			m_nview = ((Component)this).GetComponent<ZNetView>();
		}

		private void Update()
		{
			//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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: 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_01e1: 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_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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: 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_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)m_bike == (Object)null || (Object)(object)m_nview == (Object)null || !m_nview.IsValid())
			{
				return;
			}
			if (!m_built && (Object)(object)ZNetScene.instance != (Object)null)
			{
				m_built = true;
				Build();
			}
			if (m_layers.Count == 0)
			{
				return;
			}
			BikeDefinition definition = m_bike.m_definition;
			float num = Mathf.Abs(m_bike.SyncedSpeed);
			float num2 = Mathf.Max(1f, definition?.CfgTopSpeed.Value ?? 16f);
			float num3 = Mathf.Clamp01(num / num2);
			bool flag = MotorModPlugin.Wake.Value && m_bike.OnWaterSynced;
			float num4 = (flag ? Floating.GetLiquidLevel(((Component)this).transform.position + Vector3.up * 0.3f, 1f, (LiquidType)0) : 0f);
			if (num4 < -9000f)
			{
				flag = false;
			}
			Vector3 val = ((Component)this).transform.forward;
			val.y = 0f;
			val = ((((Vector3)(ref val)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref val)).normalized : Vector3.forward);
			Vector3 val2 = Vector3.Cross(Vector3.up, val);
			foreach (Layer layer in m_layers)
			{
				if (!((Object)(object)layer.ps == (Object)null))
				{
					if (flag)
					{
						Vector3 val3 = AnchorPoint(layer.at) - val * layer.back + val2 * layer.side;
						val3.y = num4 + 0.03f;
						layer.t.SetPositionAndRotation(val3, Quaternion.LookRotation(val) * layer.turn);
					}
					EmissionModule emission = layer.ps.emission;
					((EmissionModule)(ref emission)).rateOverDistance = MinMaxCurve.op_Implicit((flag && num > 0.5f) ? layer.perMetre : 0f);
					((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(flag ? (layer.perSecondIdle + layer.perSecondAtTop * num3 * num3) : 0f);
				}
			}
		}

		private Vector3 AnchorPoint(Anchor a)
		{
			//IL_0046: 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_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_0086: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			switch (a)
			{
			case Anchor.Front:
				if (!((Object)(object)m_bike.m_wheelFront != (Object)null))
				{
					return ((Component)this).transform.position + ((Component)this).transform.forward;
				}
				return m_bike.m_wheelFront.position;
			case Anchor.Rear:
				if (!((Object)(object)m_bike.m_wheelRear != (Object)null))
				{
					return ((Component)this).transform.position - ((Component)this).transform.forward;
				}
				return m_bike.m_wheelRear.position;
			default:
				return ((Component)this).transform.position;
			}
		}

		private void Build()
		{
			//IL_0073: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp(MotorModPlugin.WakeSize.Value, 0.2f, 3f);
			Add("Karve", "SurfaceEffects/SpeedWake/Trail", Anchor.Rear, 0.3f, 0f, 0.8f, 0f, 0f, 0.22f * num, (Quaternion?)null, 1f, 0f, 0f, stretch: false, (Color?)new Color(0.95f, 0.97f, 1f, 0.75f));
			Add("Karve", "SurfaceEffects/SpeedWake/aft_particles", Anchor.Rear, 0.3f, 0f, 0f, 16f, 0f, 0.12f * num, null, 1f);
			Add("Karve", "SurfaceEffects/WaterSurface/vfx_water_surface", Anchor.Middle, 0f, 0f, 0f, 0f, 3f, 0.25f * num, null, 1f);
			Add("fx_float_hitwater", "", Anchor.Rear, 0.35f, 0f, 0f, 90f, 0f, 0.3f * num, Quaternion.Euler(-30f, 180f, 0f), 1f, 5.5f, 14f);
			Add("fx_WaterImpact_Big", "GameObject", Anchor.Rear, 0.35f, 0f, 0f, 200f, 0f, 0.75f * num, (Quaternion?)Quaternion.Euler(-32f, 180f, 0f), 1f, 7f, 10f, stretch: true, (Color?)new Color(0.92f, 0.96f, 1f, 0.6f));
			float[] array = new float[2] { 1f, -1f };
			foreach (float num2 in array)
			{
				Add("fx_WaterImpact_Big", "GameObject", Anchor.Front, 0f, 0.2f * num2, 0f, 90f, 0f, 0.65f * num, (Quaternion?)Quaternion.Euler(-28f, 110f * num2, 0f), 1f, 3.5f, 20f, stretch: true, (Color?)new Color(0.92f, 0.96f, 1f, 0.6f));
				Add("fx_float_hitwater", "", Anchor.Front, 0f, 0.2f * num2, 0f, 30f, 0f, 0.16f * num, Quaternion.Euler(-25f, 110f * num2, 0f), 1f, 2.5f, 20f);
			}
			MotorModPlugin.Log.LogInfo((object)$"{((Object)((Component)this).gameObject).name}: water wake with {m_layers.Count} layers");
		}

		private void Add(string prefab, string path, Anchor at, float back, float side, float perMetre, float perSecondAtTop, float perSecondIdle, float size, Quaternion? aim, float speed, float throwSpeed = 0f, float cone = 0f, bool stretch = false, Color? colour = null)
		{
			//IL_014d: 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_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: 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_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: 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_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab2 = ZNetScene.instance.GetPrefab(prefab);
			Transform val = (((Object)(object)prefab2 == (Object)null) ? null : (string.IsNullOrEmpty(path) ? prefab2.transform : prefab2.transform.Find(path)));
			Transform val2 = (((Object)(object)prefab2 != (Object)null) ? prefab2.transform : null);
			if ((Object)(object)(((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<ParticleSystem>() : null) == (Object)null)
			{
				MotorModPlugin.Log.LogWarning((object)(((Object)((Component)this).gameObject).name + ": wake layer " + path + " missing"));
				return;
			}
			ZNetView.m_forceDisableInit = true;
			GameObject val3;
			try
			{
				val3 = Object.Instantiate<GameObject>(((Component)val).gameObject);
			}
			finally
			{
				ZNetView.m_forceDisableInit = false;
			}
			Component[] componentsInChildren = val3.GetComponentsInChildren<Component>(true);
			foreach (Component val4 in componentsInChildren)
			{
				if (!(val4 is Transform) && !(val4 is ParticleSystem) && !(val4 is ParticleSystemRenderer))
				{
					Object.Destroy((Object)(object)val4);
				}
			}
			for (int num = val3.transform.childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)val3.transform.GetChild(num)).gameObject);
			}
			((Object)val3).name = "Wake_" + ((Object)val).name;
			val3.transform.SetParent(((Component)this).transform, false);
			ParticleSystem component = val3.GetComponent<ParticleSystem>();
			MainModule main = component.main;
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)1;
			((MainModule)(ref main)).startSizeMultiplier = ((MainModule)(ref main)).startSizeMultiplier * size;
			((MainModule)(ref main)).startSpeedMultiplier = ((MainModule)(ref main)).startSpeedMultiplier * speed;
			ShapeModule shape = component.shape;
			if (throwSpeed > 0f)
			{
				((ShapeModule)(ref shape)).enabled = true;
				((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)4;
				((ShapeModule)(ref shape)).angle = cone;
				((ShapeModule)(ref shape)).radius = 0.08f;
				((ShapeModule)(ref shape)).position = Vector3.zero;
				((ShapeModule)(ref shape)).rotation = Vector3.zero;
				((MainModule)(ref main)).startSpeed = new MinMaxCurve(throwSpeed * 0.7f, throwSpeed * 1.15f);
				if (((MainModule)(ref main)).gravityModifierMultiplier < 0.5f)
				{
					((MainModule)(ref main)).gravityModifierMultiplier = 1f;
				}
				((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.6f, 1.1f);
			}
			else if (((ShapeMod