Decompiled source of SebTruck v1.1.7

BepInEx\plugins\SebTruck\SebTruck.dll

Decompiled 3 weeks ago
using System;
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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SebBinds;
using SebCore;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("SebTruck")]
[assembly: AssemblyProduct("SebTruck")]
[assembly: AssemblyFileVersion("1.1.7")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.1.7.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 SebTruck
{
	internal static class FancyGauge
	{
		internal const double MilesPerKm = 0.621371;

		internal static double DialAngle(double value01)
		{
			double num = Math.Max(0.0, Math.Min(1.0, value01));
			return (225.0 - 270.0 * num) * Math.PI / 180.0;
		}

		internal static double DistanceKm(float speedKmh, float deltaSeconds)
		{
			if (!(speedKmh > 0f) || !(deltaSeconds > 0f))
			{
				return 0.0;
			}
			return (double)speedKmh * (double)deltaSeconds / 3600.0;
		}

		internal static void OdometerWheels(double value, int[] digits, double[] rolls)
		{
			double num = Math.Max(0.0, value);
			double num2 = num - Math.Floor(num);
			for (int i = 0; i < digits.Length; i++)
			{
				digits[i] = (int)(Math.Floor(num / Math.Pow(10.0, i)) % 10.0);
				rolls[i] = num2;
				if (digits[i] != 9)
				{
					num2 = 0.0;
				}
			}
		}

		internal static string FormatOdometer(double km, bool miles, bool trip)
		{
			double num = Math.Max(0.0, miles ? (km * 0.621371) : km);
			if (trip)
			{
				return (Math.Floor(num % 1000.0 * 10.0) / 10.0).ToString("000.0", CultureInfo.InvariantCulture);
			}
			return ((long)Math.Floor(num) % 1000000).ToString("000000", CultureInfo.InvariantCulture);
		}
	}
	[BepInPlugin("shibe.easydeliveryco.sebtruck", "SebTruck", "1.1.7")]
	[BepInDependency("shibe.easydeliveryco.sebcore", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal enum SpeedUnit
		{
			Kmh,
			Mph
		}

		internal enum HudStyle
		{
			Off,
			Rally,
			Fancy
		}

		internal enum HudOdometerMode
		{
			Off,
			Total,
			Trip
		}

		private enum IndicatorMode
		{
			Off,
			Left,
			Right,
			Hazards
		}

		private sealed class IndicatorCache
		{
			public readonly List<Light> Left = new List<Light>();

			public readonly List<Light> Right = new List<Light>();

			public readonly Dictionary<int, (float intensity, bool enabled)> Defaults = new Dictionary<int, (float, bool)>();

			public readonly List<Material> LeftMats = new List<Material>();

			public readonly List<Material> RightMats = new List<Material>();

			public readonly Dictionary<int, (Color emissionColor, Color emissiveColor, bool emissionKeyword)> MatDefaults = new Dictionary<int, (Color, Color, bool)>();
		}

		private sealed class TurnSignalLightRig
		{
			public GameObject Root;

			public Light FL;

			public Light FR;

			public Light RL;

			public Light RR;

			public bool BaseComputed;

			public Vector3 BaseFL;

			public Vector3 BaseFR;

			public Vector3 BaseRL;

			public Vector3 BaseRR;
		}

		private sealed class TailLightCache
		{
			public readonly List<Light> Lights = new List<Light>();

			public readonly Dictionary<int, (float intensity, bool enabled)> Defaults = new Dictionary<int, (float, bool)>();

			public readonly List<Component> Flares = new List<Component>();

			public readonly Dictionary<int, (float intensity, bool enabled)> FlareDefaults = new Dictionary<int, (float, bool)>();
		}

		private sealed class StoryHandlingDefaults
		{
			public float maxDrivePower;

			public float maxSpeed;

			public float steeringAngle;

			public float downForce;

			public float[] maxFrictionForce;
		}

		private sealed class RallyHandlingDefaults
		{
			public float mass;

			public float gripScalar;

			public float turningRadius;

			public float torqueCurveMultiplier;

			public float redlineRPM;
		}

		private struct PaintDefaults
		{
			public Texture baseMap;

			public Texture mainTex;
		}

		private sealed class HeadlightTuningCache
		{
			public readonly List<Light> Lights = new List<Light>(16);

			public float NextRescanTime;
		}

		[HarmonyPatch]
		private static class Headlights_Toggle_Patch
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				return from m in AccessTools.GetDeclaredMethods(typeof(Headlights))
					where m != null && string.Equals(m.Name, "Toggle", StringComparison.Ordinal)
					select m;
			}

			private static bool Prefix()
			{
				return GetIgnitionEnabledEffective();
			}

			private static void Postfix(Headlights __instance)
			{
				try
				{
					if (!((Object)(object)__instance == (Object)null))
					{
						sCarController componentInParent = ((Component)__instance).GetComponentInParent<sCarController>();
						if (!((Object)(object)componentInParent == (Object)null))
						{
							ApplyHeadlightTuning(componentInParent);
						}
					}
				}
				catch
				{
				}
			}
		}

		[HarmonyPatch]
		private static class Headlights_Break_Patch
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				return from m in AccessTools.GetDeclaredMethods(typeof(Headlights))
					where m != null && string.Equals(m.Name, "Break", StringComparison.Ordinal)
					select m;
			}

			private static bool Prefix()
			{
				return GetIgnitionEnabledEffective();
			}
		}

		internal const string PrefKeyManualTransmissionEnabled = "SebTruck_ManualTransmission";

		internal const string PrefKeyRallyManualTransmissionEnabled = "SebTruck_RallyManualTransmission";

		internal const string PrefKeyManualGearCount = "SebTruck_ManualGearCount";

		internal const string PrefKeyManualSpeedMultForward = "SebTruck_ManualSpeedMultFwd";

		internal const string PrefKeyManualSpeedMultReverse = "SebTruck_ManualSpeedMultRev";

		internal const string PrefKeyIgnitionEnabled = "SebTruck_IgnitionEnabled";

		internal const string PrefKeyIgnitionFeatureEnabled = "SebTruck_IgnitionFeatureEnabled";

		internal const string PrefKeyIgnitionHoldSeconds = "SebTruck_IgnitionHoldSeconds";

		internal const string PrefKeyIgnitionSfxEnabled = "SebTruck_IgnitionSfxEnabled";

		internal const string PrefKeyIgnitionSfxVolume = "SebTruck_IgnitionSfxVolume";

		internal const string PrefKeyIndicatorFeatureEnabled = "SebTruck_IndicatorFeatureEnabled";

		internal const string PrefKeyIndicatorSfxEnabled = "SebTruck_IndicatorSfxEnabled";

		internal const string PrefKeyIndicatorSfxVolume = "SebTruck_IndicatorSfxVolume";

		internal const string PrefKeyIndicatorBlinkSeconds = "SebTruck_IndicatorBlinkSeconds";

		internal const string PrefKeyTurnSignalLightIntensity = "SebTruck_TurnSignalLightIntensity";

		internal const string PrefKeyBackupAlarmEnabled = "SebTruck_BackupAlarmEnabled";

		internal const string PrefKeyBackupAlarmHazardsEnabled = "SebTruck_BackupAlarmHazardsEnabled";

		internal const string PrefKeyBackupAlarmVolume = "SebTruck_BackupAlarmVolume";

		internal const string PrefKeyBackupAlarmInterval = "SebTruck_BackupAlarmInterval";

		internal const string PrefKeyBackupAlarmTone = "SebTruck_BackupAlarmTone";

		internal static readonly Vector3 TurnSignalLightFrontOffset = new Vector3(0f, 0f, 0.05f);

		internal static readonly Vector3 TurnSignalLightRearOffset = new Vector3(0f, -0.3f, 0.05f);

		internal const string PrefKeyHudShowSpeed = "SebTruck_HudShowSpeed";

		internal const string PrefKeyHudShowTach = "SebTruck_HudShowTach";

		internal const string PrefKeyHudShowGear = "SebTruck_HudShowGear";

		internal const string PrefKeyHudStyle = "SebTruck_HudStyle";

		internal const string PrefKeyHudSpeedUnits = "SebTruck_HudSpeedUnits";

		internal const string PrefKeyRallyHudShowSpeed = "SebTruck_RallyHudShowSpeedV2";

		internal const string PrefKeyRallyHudShowTach = "SebTruck_RallyHudShowTach";

		internal const string PrefKeyRallyHudShowGear = "SebTruck_RallyHudShowGear";

		internal const string PrefKeyRallyHudSpeedUnits = "SebTruck_RallyHudSpeedUnits";

		internal const string PrefKeyHeadlightIntensityMult = "SebTruck_HeadlightIntensityMult";

		internal const string PrefKeyHeadlightRangeMult = "SebTruck_HeadlightRangeMult";

		internal const string PrefKeyWheelScale = "SebTruck_WheelScale";

		internal const string PrefKeyHandlingPowerMult = "SebTruck_HandlingPowerMult";

		internal const string PrefKeyHandlingSpeedMult = "SebTruck_HandlingSpeedMult";

		internal const string PrefKeyHandlingSteeringMult = "SebTruck_HandlingSteeringMult";

		internal const string PrefKeyHandlingGripMult = "SebTruck_HandlingGripMult";

		internal const string PrefKeyHandlingDownforceMult = "SebTruck_HandlingDownforceMult";

		internal const string PrefKeyHandlingMassMult = "SebTruck_HandlingMassMult";

		private const string SaveKeySnowcats = "cats";

		private const string SaveKeyDisplayBobble = "displayBobble";

		private const string SaveKeyEquippedPaint = "playerEquipedPaint";

		private static readonly List<int> _tmpIntList = new List<int>(64);

		private static bool _manualTransmissionEnabled;

		private static int _manualGear = 1;

		private static int _rallyModeCacheFrame = -1;

		private static bool _rallyModeCached;

		public const string PluginGuid = "shibe.easydeliveryco.sebtruck";

		public const string PluginName = "SebTruck";

		public const string PluginVersion = "1.1.7";

		internal static ManualLogSource Log;

		private static ConfigEntry<bool> _debugLogging;

		private static ConfigEntry<string> _ignitionSfxOnPath;

		private static Object _ignitionSfxOn;

		private static GameObject _ignitionHoldSfxGo;

		private static Component _ignitionHoldSfxSource;

		private static GameObject _indicatorClickSfxGo;

		private static Component _indicatorClickSfxSource;

		private static bool _turnSignalEmissivesTriedLoad;

		private static Texture2D _turnSignalEmissiveOff;

		private static Texture2D _turnSignalEmissiveLeft;

		private static Texture2D _turnSignalEmissiveRight;

		private static Texture2D _turnSignalEmissiveBoth;

		private static Texture2D _turnSignalEmissiveBrakeOff;

		private static Texture2D _turnSignalEmissiveBrakeLeft;

		private static Texture2D _turnSignalEmissiveBrakeRight;

		private static Texture2D _turnSignalEmissiveBrakeBoth;

		internal const string PrefKeyMountSnowTires = "SebTruck_MountSnowTires";

		internal const string PrefKeyMountIceChains = "SebTruck_MountIceChains";

		internal const string PrefKeyMountRamBar = "SebTruck_MountRamBar";

		internal const string PrefKeyHorn = "SebTruck_Horn";

		internal static readonly string[] HornLabels = new string[2] { "Meow", "Woof" };

		private static readonly string[] HornClipNames = new string[2] { "meowHorn", "hornAlt" };

		private static readonly FieldInfo HeadlightsHornField = AccessTools.Field(typeof(Headlights), "horn");

		private static readonly Object[] HornClipCache = (Object[])(object)new Object[HornClipNames.Length];

		private static Object _gameHorn;

		private static Object _appliedHorn;

		private static float _nextHornClipScan;

		private static TruckUpgrades _truckUpgrades;

		internal const string PrefKeyRallyHudStyle = "SebTruck_RallyHudStyle";

		internal const string PrefKeyHudOdometer = "SebTruck_HudOdometer";

		private const string SaveKeyOdometerKm = "SebTruck_OdometerKm";

		private const string SaveKeyTripKm = "SebTruck_TripKm";

		private const float SpeedoRadius = 22f;

		private const float TachRadius = 18f;

		private const float DialGap = 6f;

		private const int RadioLift = 34;

		private static MiniRenderer _radioLiftedRenderer;

		private static double _odometerPendingKm;

		private static float _odometerNextFlush;

		private static int _odometerFrame = -1;

		private static sEasyRally _easyRally;

		private static readonly int[] OdometerDigits = new int[6];

		private static readonly double[] OdometerRolls = new double[6];

		private static sCarController _currentCar;

		private static int _currentCarFrame = -1;

		private static bool _isInWalkingMode;

		private static float _currentSpeedKmh;

		private static float _currentSignedSpeedKmh;

		private static float _currentSpeedMult = 1f;

		private static float _lastThrottle01;

		private static float _neutralRev01;

		private static float _storyVirtualRpm;

		private static int _storyVirtualRpmLastGear = 1;

		private static float _ignitionHoldStart = -1f;

		private static bool _ignitionHoldConsumed;

		private static bool _ignitionHoldWasDown;

		private static bool _ignitionIgnoreHoldUntilRelease;

		private static float _ignitionOffSince = -1f;

		private static bool _ignitionPrevHeadlightsOn;

		private static bool _ignitionPrevRadioOn;

		private static GameObject _backupBeepGo;

		private static Component _backupBeepSource;

		private static Object _backupBeepClip;

		private static float _backupBeepClipTone = -1f;

		private static float _backupBeepClipDuration = -1f;

		private static float _backupNextBeepTime;

		private static bool _backupAlarmHazardsActive;

		private static IndicatorMode _indicatorMode;

		private static bool _indicatorBlinkOn;

		private static float _indicatorNextBlinkTime;

		private static float _indicatorPauseStart = -1f;

		private const float IndicatorCancelArmThreshold = 0.35f;

		private const float IndicatorCancelCenterThreshold = 0.12f;

		private static bool _indicatorCancelArmed;

		private static IndicatorMode _indicatorCancelArmedForMode;

		private static readonly Dictionary<int, IndicatorCache> _indicatorCaches = new Dictionary<int, IndicatorCache>();

		private static readonly Dictionary<int, bool> _truckBraking = new Dictionary<int, bool>();

		private static readonly Dictionary<int, bool> _isTruckCarById = new Dictionary<int, bool>();

		private static readonly Dictionary<int, TurnSignalLightRig> _turnSignalLightRigs = new Dictionary<int, TurnSignalLightRig>();

		private static readonly Dictionary<int, TailLightCache> _tailLightCaches = new Dictionary<int, TailLightCache>();

		private static readonly Dictionary<int, (float maxSpeedScale, float drivePowerScale)> _carScaleDefaults = new Dictionary<int, (float, float)>();

		private static readonly Dictionary<int, StoryHandlingDefaults> _storyHandlingDefaults = new Dictionary<int, StoryHandlingDefaults>();

		private static readonly Dictionary<int, RallyHandlingDefaults> _rallyHandlingDefaults = new Dictionary<int, RallyHandlingDefaults>();

		private static readonly Dictionary<int, (float intensity, float range)> _lightDefaults = new Dictionary<int, (float, float)>();

		private static readonly Dictionary<int, (Vector3 Base, Vector3 Applied)> _visualScaleDefaults = new Dictionary<int, (Vector3, Vector3)>();

		private static Type _engineSfxRuntimeType;

		private static FieldInfo _engineCarField;

		private static FieldInfo _engineIdleField;

		private static FieldInfo _engineDriveField;

		private static FieldInfo _engineIntenseField;

		private static FieldInfo _engineDistortionField;

		private static FieldInfo _radioTargetVolumeField;

		private static FieldInfo _radioRadioVolumeField;

		private static FieldInfo _radioSourceField;

		private static FieldInfo _radioNoiseField;

		private static FieldInfo _rallyWheelTurningRadiusField;

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

		private static Type _headlightsRuntimeType;

		private static FieldInfo _headlightsHeadLightsField;

		private static FieldInfo _headlightsCarMatField;

		private static FieldInfo _headlightsEmissiveRegularField;

		private static FieldInfo _headlightsHeadlightsOnField;

		private static FieldInfo _headlightsModelField;

		private static Texture2D _ignitionBlackEmissiveTex;

		private static readonly Dictionary<string, Material> _paintMaterialCache = new Dictionary<string, Material>(StringComparer.OrdinalIgnoreCase);

		private static readonly Dictionary<int, PaintDefaults> _paintDefaultsByCarId = new Dictionary<int, PaintDefaults>();

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

		private static FieldInfo _carDamageCarMatField;

		private static int _paintLastCarId;

		private static int _paintLastIndex = int.MinValue;

		private static bool _rallyManualCheatTogglePending;

		private static readonly Dictionary<int, HeadlightTuningCache> _headlightTuningCaches = new Dictionary<int, HeadlightTuningCache>();

		private static readonly HashSet<int> _tmpHeadlightLightIds = new HashSet<int>();

		private const float StoryIdleRpm = 1000f;

		private const float StoryRedlineRpm = 7200f;

		private const float StoryRedlineDisplayRpm = 7700f;

		private const float StoryEngineInertia = 0.5f;

		private const float StoryEngineTorqueMultiplier = 2.5f;

		private const float StoryEngineInitialFrictionTorque = 10f;

		private const float StoryEngineFrictionLossCoefficient = 0.025f;

		internal static bool HasAnyUnlockedBobbleheads()
		{
			try
			{
				string text = sSaveSystem.GetString("cats", "");
				if (string.IsNullOrEmpty(text))
				{
					return false;
				}
				for (int i = 0; i < text.Length; i++)
				{
					if (text[i] == '1')
					{
						return true;
					}
				}
				return false;
			}
			catch
			{
				return false;
			}
		}

		internal static int GetSelectedBobbleIndex()
		{
			try
			{
				return sSaveSystem.GetInt("displayBobble", -1);
			}
			catch
			{
				return -1;
			}
		}

		internal static string GetBobbleLabel(int index)
		{
			if (index >= 0)
			{
				return "#" + (index + 1);
			}
			return "None";
		}

		internal static bool IsBobbleUnlocked(int index)
		{
			if (index < 0)
			{
				return true;
			}
			try
			{
				string text = sSaveSystem.GetString("cats", "");
				if (string.IsNullOrEmpty(text))
				{
					return false;
				}
				if (index >= text.Length)
				{
					return false;
				}
				return text[index] == '1';
			}
			catch
			{
				return false;
			}
		}

		internal static int GetSelectedBobbleIndexUnlockedOrNone()
		{
			int selectedBobbleIndex = GetSelectedBobbleIndex();
			if (!IsBobbleUnlocked(selectedBobbleIndex))
			{
				return -1;
			}
			return selectedBobbleIndex;
		}

		internal static void SetSelectedBobbleIndex(int index)
		{
			if (!IsBobbleUnlocked(index))
			{
				index = -1;
			}
			try
			{
				sSaveSystem.SetInt("displayBobble", index);
			}
			catch
			{
			}
			try
			{
				SnowcatManager val = Object.FindFirstObjectByType<SnowcatManager>();
				if ((Object)(object)val != (Object)null)
				{
					MethodInfo methodInfo = AccessTools.Method(typeof(SnowcatManager), "SetDisplayBobble", (Type[])null, (Type[])null);
					if (methodInfo != null)
					{
						methodInfo.Invoke(val, new object[1] { index });
					}
				}
			}
			catch
			{
			}
		}

		internal static void CycleBobbleheadSelection()
		{
			int selectedBobbleIndexUnlockedOrNone = GetSelectedBobbleIndexUnlockedOrNone();
			_tmpIntList.Clear();
			try
			{
				string text = sSaveSystem.GetString("cats", "");
				if (!string.IsNullOrEmpty(text))
				{
					for (int i = 0; i < text.Length; i++)
					{
						if (text[i] == '1')
						{
							_tmpIntList.Add(i);
						}
					}
				}
			}
			catch
			{
			}
			if (_tmpIntList.Count == 0)
			{
				SetSelectedBobbleIndex(-1);
				return;
			}
			if (selectedBobbleIndexUnlockedOrNone < 0)
			{
				SetSelectedBobbleIndex(_tmpIntList[0]);
				return;
			}
			int num = _tmpIntList.IndexOf(selectedBobbleIndexUnlockedOrNone);
			if (num < 0)
			{
				SetSelectedBobbleIndex(_tmpIntList[0]);
			}
			else if (num + 1 >= _tmpIntList.Count)
			{
				SetSelectedBobbleIndex(-1);
			}
			else
			{
				SetSelectedBobbleIndex(_tmpIntList[num + 1]);
			}
		}

		private static bool TryGetCosmeticInfo(out sCosmeticInfo info)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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)
			info = null;
			try
			{
				info = Object.FindFirstObjectByType<sCosmeticInfo>();
				if ((Object)(object)info != (Object)null)
				{
					return true;
				}
			}
			catch
			{
			}
			try
			{
				sCosmeticInfo[] array = Resources.FindObjectsOfTypeAll<sCosmeticInfo>();
				if (array != null)
				{
					for (int i = 0; i < array.Length; i++)
					{
						if (!((Object)(object)array[i] != (Object)null))
						{
							continue;
						}
						try
						{
							if (!((Object)(object)((Component)array[i]).gameObject != (Object)null))
							{
								continue;
							}
							Scene scene = ((Component)array[i]).gameObject.scene;
							if (((Scene)(ref scene)).IsValid())
							{
								scene = ((Component)array[i]).gameObject.scene;
								if (((Scene)(ref scene)).isLoaded)
								{
									info = array[i];
									return true;
								}
							}
						}
						catch
						{
						}
					}
					for (int j = 0; j < array.Length; j++)
					{
						if ((Object)(object)array[j] != (Object)null)
						{
							info = array[j];
							return true;
						}
					}
				}
			}
			catch
			{
			}
			try
			{
				info = Object.FindFirstObjectByType<sCosmeticInfo>();
				return (Object)(object)info != (Object)null;
			}
			catch
			{
				info = null;
				return false;
			}
		}

		internal static int GetSelectedPaintIndex()
		{
			try
			{
				return sSaveSystem.GetInt("playerEquipedPaint", -1);
			}
			catch
			{
				return -1;
			}
		}

		internal static string GetPaintLabel(int index)
		{
			if (index < 0)
			{
				return "Default";
			}
			if (!TryGetCosmeticInfo(out var info) || (Object)(object)info == (Object)null || info.cosmetics == null)
			{
				return "#" + index;
			}
			if (index >= info.cosmetics.Length)
			{
				return "#" + index;
			}
			if (!string.IsNullOrWhiteSpace(info.cosmetics[index].name))
			{
				return info.cosmetics[index].name;
			}
			return "#" + index;
		}

		internal static bool TryGetPaintCosmeticName(int index, out string name)
		{
			name = string.Empty;
			if (index < 0)
			{
				return false;
			}
			if (!TryGetCosmeticInfo(out var info) || (Object)(object)info == (Object)null || info.cosmetics == null)
			{
				return false;
			}
			if (index >= info.cosmetics.Length)
			{
				return false;
			}
			string name2 = info.cosmetics[index].name;
			if (string.IsNullOrWhiteSpace(name2))
			{
				return false;
			}
			name = name2.Trim();
			return true;
		}

		internal static bool IsPaintUnlocked(int index)
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Invalid comparison between Unknown and I4
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Invalid comparison between Unknown and I4
			if (index < 0)
			{
				return true;
			}
			if (!TryGetCosmeticInfo(out var info) || (Object)(object)info == (Object)null || info.cosmetics == null)
			{
				return false;
			}
			if (index >= info.cosmetics.Length)
			{
				return false;
			}
			try
			{
				string text = ((info.cosmetics[index].name != null) ? info.cosmetics[index].name.Trim() : string.Empty);
				if ((int)info.cosmetics[index].type != 2 && (string.IsNullOrWhiteSpace(text) || !text.EndsWith(" Paint", StringComparison.OrdinalIgnoreCase)))
				{
					return false;
				}
				bool unlocked = info.cosmetics[index].unlocked;
				if (string.IsNullOrWhiteSpace(text))
				{
					return unlocked;
				}
				return sSaveSystem.GetBool("costmeticUnlocked_" + text, unlocked);
			}
			catch
			{
				return (int)info.cosmetics[index].type == 2 && info.cosmetics[index].unlocked;
			}
		}

		internal static bool TryGetPaintCosmeticTexture(int index, out Texture texture)
		{
			texture = null;
			if (index < 0)
			{
				return false;
			}
			try
			{
				if (!TryGetCosmeticInfo(out var info) || (Object)(object)info == (Object)null || info.cosmetics == null)
				{
					return false;
				}
				if (index >= info.cosmetics.Length)
				{
					return false;
				}
				texture = info.cosmetics[index].texture;
				return (Object)(object)texture != (Object)null;
			}
			catch
			{
				texture = null;
				return false;
			}
		}

		internal static int GetSelectedPaintIndexUnlockedOrDefault()
		{
			int selectedPaintIndex = GetSelectedPaintIndex();
			if (!IsPaintUnlocked(selectedPaintIndex))
			{
				return -1;
			}
			return selectedPaintIndex;
		}

		internal static void SetSelectedPaintIndex(int index)
		{
			if (!IsPaintUnlocked(index))
			{
				index = -1;
			}
			try
			{
				if (TryGetCosmeticInfo(out var info) && (Object)(object)info != (Object)null)
				{
					info.SetPlayerEquiped(index, (Type)2);
					return;
				}
			}
			catch
			{
			}
			try
			{
				sSaveSystem.SetInt("playerEquipedPaint", index);
			}
			catch
			{
			}
		}

		internal static void CyclePaintSelection()
		{
			int selectedPaintIndexUnlockedOrDefault = GetSelectedPaintIndexUnlockedOrDefault();
			_tmpIntList.Clear();
			if (TryGetCosmeticInfo(out var info) && (Object)(object)info != (Object)null && info.cosmetics != null)
			{
				for (int i = 0; i < info.cosmetics.Length; i++)
				{
					if (IsPaintUnlocked(i))
					{
						_tmpIntList.Add(i);
					}
				}
			}
			if (_tmpIntList.Count == 0)
			{
				SetSelectedPaintIndex(-1);
				return;
			}
			if (selectedPaintIndexUnlockedOrDefault < 0)
			{
				SetSelectedPaintIndex(_tmpIntList[0]);
				return;
			}
			int num = _tmpIntList.IndexOf(selectedPaintIndexUnlockedOrDefault);
			if (num < 0)
			{
				SetSelectedPaintIndex(_tmpIntList[0]);
			}
			else if (num + 1 >= _tmpIntList.Count)
			{
				SetSelectedPaintIndex(-1);
			}
			else
			{
				SetSelectedPaintIndex(_tmpIntList[num + 1]);
			}
		}

		internal static bool HasAnyUnlockedPaints()
		{
			if (!TryGetCosmeticInfo(out var info) || (Object)(object)info == (Object)null || info.cosmetics == null)
			{
				return false;
			}
			for (int i = 0; i < info.cosmetics.Length; i++)
			{
				if (IsPaintUnlocked(i))
				{
					return true;
				}
			}
			return false;
		}

		internal static int GetManualGearCount()
		{
			return Mathf.Clamp(PlayerPrefs.GetInt("SebTruck_ManualGearCount", 5), 3, 6);
		}

		internal static void SetManualGearCount(int count)
		{
			count = Mathf.Clamp(count, 3, 6);
			PlayerPrefs.SetInt("SebTruck_ManualGearCount", count);
			if (_manualGear > count)
			{
				_manualGear = count;
			}
		}

		internal static int NextManualGearCount(int count)
		{
			count++;
			if (count > 6)
			{
				count = 3;
			}
			return count;
		}

		internal static bool GetManualTransmissionEnabled()
		{
			return PlayerPrefs.GetInt("SebTruck_ManualTransmission", 0) != 0;
		}

		internal static void SetManualTransmissionEnabled(bool enabled)
		{
			bool manualTransmissionEnabled = GetManualTransmissionEnabled();
			_manualTransmissionEnabled = enabled;
			PlayerPrefs.SetInt("SebTruck_ManualTransmission", enabled ? 1 : 0);
			if (!enabled)
			{
				_manualGear = Mathf.Clamp(_manualGear, 1, GetManualGearCount());
			}
			else if (_manualGear == 0)
			{
				_manualGear = 1;
			}
			if (manualTransmissionEnabled != enabled)
			{
				LogDebug("Manual transmission: " + (enabled ? "ON" : "OFF"));
			}
		}

		internal static void ToggleManualTransmission()
		{
			SetManualTransmissionEnabled(!GetManualTransmissionEnabled());
		}

		internal static bool IsRallyModeActive()
		{
			int frameCount = Time.frameCount;
			if (_rallyModeCacheFrame == frameCount)
			{
				return _rallyModeCached;
			}
			_rallyModeCacheFrame = frameCount;
			_rallyModeCached = sEasyRally.rallyModeActive && (Object)(object)Object.FindFirstObjectByType<sEasyRally>() != (Object)null;
			return _rallyModeCached;
		}

		private static sRallyDriving GetCurrentRallyDriving()
		{
			try
			{
				sEasyRally val = Object.FindFirstObjectByType<sEasyRally>();
				if ((Object)(object)val != (Object)null && (Object)(object)val.currentCar != (Object)null)
				{
					return val.currentCar;
				}
				return Object.FindFirstObjectByType<sRallyDriving>();
			}
			catch
			{
				return null;
			}
		}

		internal static string GetCurrentRallyVariantLabel()
		{
			try
			{
				sUpgradeSync val = Object.FindFirstObjectByType<sUpgradeSync>();
				if ((Object)(object)val == (Object)null || (Object)(object)val.car == (Object)null)
				{
					return "Rally";
				}
				if ((Object)(object)val.car == (Object)(object)val.slowRWD)
				{
					return "Slow RWD";
				}
				if ((Object)(object)val.car == (Object)(object)val.fastRWD)
				{
					return "Fast RWD";
				}
				if ((Object)(object)val.car == (Object)(object)val.slowAWD)
				{
					return "Slow AWD";
				}
				if ((Object)(object)val.car == (Object)(object)val.fastAWD)
				{
					return "Fast AWD";
				}
			}
			catch
			{
			}
			return "Rally";
		}

		internal static bool IsManualTransmissionEnabledEffective()
		{
			if (GetManualTransmissionEnabled())
			{
				return !IsRallyModeActive();
			}
			return false;
		}

		internal static bool GetRallyManualTransmissionEnabled()
		{
			return PlayerPrefs.GetInt("SebTruck_RallyManualTransmission", 0) != 0;
		}

		internal static void SetRallyManualTransmissionEnabled(bool enabled)
		{
			PlayerPrefs.SetInt("SebTruck_RallyManualTransmission", enabled ? 1 : 0);
			PlayerPrefs.Save();
		}

		internal static int GetManualGear()
		{
			return _manualGear;
		}

		internal static void SetManualGearDirect(int gear)
		{
			if (IsManualTransmissionEnabledEffective())
			{
				int manualGearCount = GetManualGearCount();
				int manualGear = _manualGear;
				gear = ((gear > 0) ? Mathf.Clamp(gear, 1, manualGearCount) : ((gear < 0) ? (-1) : 0));
				_manualGear = gear;
				if (manualGear != _manualGear)
				{
					LogDebug("Gear: " + manualGear + " -> " + _manualGear);
				}
			}
		}

		internal static string GetManualGearLabel()
		{
			if (_manualGear < 0)
			{
				return "R";
			}
			if (_manualGear == 0)
			{
				return "N";
			}
			return _manualGear.ToString();
		}

		internal static void ShiftManualGear(int delta)
		{
			if (!IsManualTransmissionEnabledEffective())
			{
				_manualGear = Mathf.Clamp(_manualGear, 1, GetManualGearCount());
				return;
			}
			int manualGear = _manualGear;
			int manualGearCount = GetManualGearCount();
			int manualGear2 = _manualGear;
			if (manualGear2 == 0)
			{
				manualGear2 = ((delta > 0) ? 1 : (-1));
			}
			else if (manualGear2 < 0)
			{
				manualGear2 = ((delta <= 0) ? (-1) : 0);
			}
			else
			{
				manualGear2 += delta;
				if (manualGear2 > manualGearCount)
				{
					manualGear2 = manualGearCount;
				}
				if (manualGear2 < 1)
				{
					manualGear2 = 0;
				}
			}
			_manualGear = manualGear2;
			if (manualGear != _manualGear)
			{
				LogDebug("Shift: " + manualGear + " -> " + _manualGear);
			}
		}

		internal static bool GetIgnitionEnabled()
		{
			return PlayerPrefs.GetInt("SebTruck_IgnitionEnabled", 1) != 0;
		}

		internal static void SetIgnitionEnabled(bool enabled)
		{
			PlayerPrefs.SetInt("SebTruck_IgnitionEnabled", enabled ? 1 : 0);
		}

		internal static bool GetIgnitionFeatureEnabled()
		{
			return PlayerPrefs.GetInt("SebTruck_IgnitionFeatureEnabled", 1) != 0;
		}

		internal static void SetIgnitionFeatureEnabled(bool enabled)
		{
			PlayerPrefs.SetInt("SebTruck_IgnitionFeatureEnabled", enabled ? 1 : 0);
		}

		internal static float GetIgnitionHoldSeconds()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_IgnitionHoldSeconds", 1.35f), 0.25f, 5f);
		}

		internal static void SetIgnitionHoldSeconds(float seconds)
		{
			PlayerPrefs.SetFloat("SebTruck_IgnitionHoldSeconds", Mathf.Clamp(seconds, 0.25f, 5f));
		}

		internal static bool GetIgnitionSfxEnabled()
		{
			return PlayerPrefs.GetInt("SebTruck_IgnitionSfxEnabled", 1) != 0;
		}

		internal static void SetIgnitionSfxEnabled(bool enabled)
		{
			PlayerPrefs.SetInt("SebTruck_IgnitionSfxEnabled", enabled ? 1 : 0);
		}

		internal static float GetIgnitionSfxVolume()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_IgnitionSfxVolume", 0.15f), 0f, 1f);
		}

		internal static void SetIgnitionSfxVolume(float volume01)
		{
			PlayerPrefs.SetFloat("SebTruck_IgnitionSfxVolume", Mathf.Clamp01(volume01));
		}

		internal static bool GetIgnitionEnabledEffective()
		{
			//IL_002b: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (!GetIgnitionFeatureEnabled())
			{
				return true;
			}
			bool flag = false;
			try
			{
				BindingScheme[] array = (BindingScheme[])Enum.GetValues(typeof(BindingScheme));
				for (int i = 0; i < array.Length; i++)
				{
					int num = (int)array[i];
					BindingInput binding = BindingStore.GetBinding((BindingScheme)num, (BindingLayer)0, (BindAction)16);
					BindingInput binding2 = BindingStore.GetBinding((BindingScheme)num, (BindingLayer)1, (BindAction)16);
					if ((int)binding.Kind != 0 || (int)binding2.Kind != 0)
					{
						flag = true;
						break;
					}
				}
			}
			catch
			{
				flag = true;
			}
			if (!flag)
			{
				return true;
			}
			return GetIgnitionEnabled();
		}

		internal static bool GetIndicatorFeatureEnabled()
		{
			return PlayerPrefs.GetInt("SebTruck_IndicatorFeatureEnabled", 1) != 0;
		}

		internal static void SetIndicatorFeatureEnabled(bool enabled)
		{
			PlayerPrefs.SetInt("SebTruck_IndicatorFeatureEnabled", enabled ? 1 : 0);
		}

		internal static bool GetIndicatorSfxEnabled()
		{
			return PlayerPrefs.GetInt("SebTruck_IndicatorSfxEnabled", 1) != 0;
		}

		internal static void SetIndicatorSfxEnabled(bool enabled)
		{
			PlayerPrefs.SetInt("SebTruck_IndicatorSfxEnabled", enabled ? 1 : 0);
		}

		internal static float GetIndicatorSfxVolume()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_IndicatorSfxVolume", 1f), 0f, 1f);
		}

		internal static void SetIndicatorSfxVolume(float volume01)
		{
			PlayerPrefs.SetFloat("SebTruck_IndicatorSfxVolume", Mathf.Clamp01(volume01));
		}

		internal static float GetIndicatorBlinkSeconds()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_IndicatorBlinkSeconds", 0.45f), 0.15f, 1.5f);
		}

		internal static void SetIndicatorBlinkSeconds(float seconds)
		{
			PlayerPrefs.SetFloat("SebTruck_IndicatorBlinkSeconds", Mathf.Clamp(seconds, 0.15f, 1.5f));
		}

		internal static float GetTurnSignalLightIntensity()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_TurnSignalLightIntensity", 0.15f), 0f, 1f);
		}

		internal static void SetTurnSignalLightIntensity(float intensity)
		{
			PlayerPrefs.SetFloat("SebTruck_TurnSignalLightIntensity", Mathf.Clamp(intensity, 0f, 1f));
		}

		internal static bool GetBackupAlarmEnabled()
		{
			return PlayerPrefs.GetInt("SebTruck_BackupAlarmEnabled", 0) != 0;
		}

		internal static void SetBackupAlarmEnabled(bool enabled)
		{
			PlayerPrefs.SetInt("SebTruck_BackupAlarmEnabled", enabled ? 1 : 0);
		}

		internal static bool GetBackupAlarmHazardsEnabled()
		{
			return PlayerPrefs.GetInt("SebTruck_BackupAlarmHazardsEnabled", 0) != 0;
		}

		internal static void SetBackupAlarmHazardsEnabled(bool enabled)
		{
			PlayerPrefs.SetInt("SebTruck_BackupAlarmHazardsEnabled", enabled ? 1 : 0);
		}

		internal static float GetBackupAlarmVolume()
		{
			return Mathf.Clamp01(PlayerPrefs.GetFloat("SebTruck_BackupAlarmVolume", 0.55f));
		}

		internal static void SetBackupAlarmVolume(float volume)
		{
			PlayerPrefs.SetFloat("SebTruck_BackupAlarmVolume", Mathf.Clamp01(volume));
		}

		internal static float GetBackupAlarmInterval()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_BackupAlarmInterval", 0.65f), 0.25f, 1.5f);
		}

		internal static void SetBackupAlarmInterval(float seconds)
		{
			PlayerPrefs.SetFloat("SebTruck_BackupAlarmInterval", Mathf.Clamp(seconds, 0.25f, 1.5f));
			_backupBeepClip = null;
		}

		internal static float GetBackupAlarmTone()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_BackupAlarmTone", 950f), 450f, 1800f);
		}

		internal static void SetBackupAlarmTone(float hz)
		{
			PlayerPrefs.SetFloat("SebTruck_BackupAlarmTone", Mathf.Clamp(hz, 450f, 1800f));
			_backupBeepClip = null;
		}

		internal static bool GetHudShowSpeed()
		{
			return PlayerPrefs.GetInt("SebTruck_HudShowSpeed", 1) != 0;
		}

		internal static void SetHudShowSpeed(bool enabled)
		{
			PlayerPrefs.SetInt("SebTruck_HudShowSpeed", enabled ? 1 : 0);
		}

		internal static bool GetHudShowTach()
		{
			return PlayerPrefs.GetInt("SebTruck_HudShowTach", 1) != 0;
		}

		internal static void SetHudShowTach(bool enabled)
		{
			PlayerPrefs.SetInt("SebTruck_HudShowTach", enabled ? 1 : 0);
		}

		internal static bool GetHudShowGear()
		{
			return PlayerPrefs.GetInt("SebTruck_HudShowGear", 1) != 0;
		}

		internal static void SetHudShowGear(bool enabled)
		{
			PlayerPrefs.SetInt("SebTruck_HudShowGear", enabled ? 1 : 0);
		}

		internal static HudStyle GetHudStyle()
		{
			return (HudStyle)Mathf.Clamp(PlayerPrefs.GetInt("SebTruck_HudStyle", 0), 0, 2);
		}

		internal static void SetHudStyle(HudStyle style)
		{
			PlayerPrefs.SetInt("SebTruck_HudStyle", (int)style);
		}

		internal static HudStyle NextHudStyle(HudStyle style)
		{
			return (HudStyle)((int)(style + 1) % 3);
		}

		internal static string GetHudStyleLabel(HudStyle style)
		{
			if (style != HudStyle.Off)
			{
				return style.ToString();
			}
			return "Off";
		}

		internal static SpeedUnit GetHudSpeedUnit()
		{
			return (SpeedUnit)Mathf.Clamp(PlayerPrefs.GetInt("SebTruck_HudSpeedUnits", 0), 0, 1);
		}

		internal static void SetHudSpeedUnit(SpeedUnit unit)
		{
			PlayerPrefs.SetInt("SebTruck_HudSpeedUnits", (int)unit);
		}

		internal static SpeedUnit NextHudSpeedUnit(SpeedUnit unit)
		{
			if (unit != SpeedUnit.Kmh)
			{
				return SpeedUnit.Kmh;
			}
			return SpeedUnit.Mph;
		}

		internal static string GetHudSpeedUnitLabel(SpeedUnit unit)
		{
			if (unit != SpeedUnit.Mph)
			{
				return "km/h";
			}
			return "mph";
		}

		internal static float ConvertSpeedForHud(float kmh)
		{
			if (GetHudSpeedUnit() != SpeedUnit.Mph)
			{
				return kmh;
			}
			return kmh * 0.621371f;
		}

		internal static bool GetRallyHudShowSpeed()
		{
			return true;
		}

		internal static void SetRallyHudShowSpeed(bool enabled)
		{
		}

		internal static bool GetRallyHudShowTach()
		{
			return true;
		}

		internal static void SetRallyHudShowTach(bool enabled)
		{
		}

		internal static bool GetRallyHudShowGear()
		{
			return true;
		}

		internal static void SetRallyHudShowGear(bool enabled)
		{
		}

		internal static SpeedUnit GetRallyHudSpeedUnit()
		{
			return (SpeedUnit)Mathf.Clamp(PlayerPrefs.GetInt("SebTruck_RallyHudSpeedUnits", 0), 0, 1);
		}

		internal static void SetRallyHudSpeedUnit(SpeedUnit unit)
		{
			PlayerPrefs.SetInt("SebTruck_RallyHudSpeedUnits", (int)unit);
		}

		internal static float GetManualSpeedMultForward()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_ManualSpeedMultFwd", 1f), 0.25f, 2f);
		}

		internal static void SetManualSpeedMultForward(float mult)
		{
			PlayerPrefs.SetFloat("SebTruck_ManualSpeedMultFwd", Mathf.Clamp(mult, 0.25f, 2f));
		}

		internal static float GetManualSpeedMultReverse()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_ManualSpeedMultRev", 1f), 0.25f, 2f);
		}

		internal static void SetManualSpeedMultReverse(float mult)
		{
			PlayerPrefs.SetFloat("SebTruck_ManualSpeedMultRev", Mathf.Clamp(mult, 0.25f, 2f));
		}

		internal static float GetHeadlightIntensityMult()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_HeadlightIntensityMult", 1f), 0.1f, 3f);
		}

		internal static void SetHeadlightIntensityMult(float mult)
		{
			PlayerPrefs.SetFloat("SebTruck_HeadlightIntensityMult", Mathf.Clamp(mult, 0.1f, 3f));
		}

		internal static float GetHeadlightRangeMult()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_HeadlightRangeMult", 1f), 0.1f, 1f);
		}

		internal static void SetHeadlightRangeMult(float mult)
		{
			PlayerPrefs.SetFloat("SebTruck_HeadlightRangeMult", Mathf.Clamp(mult, 0.1f, 1f));
		}

		internal static float GetWheelScale()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_WheelScale", 1f), 0.5f, 2f);
		}

		internal static void SetWheelScale(float scale)
		{
			PlayerPrefs.SetFloat("SebTruck_WheelScale", Mathf.Clamp(scale, 0.5f, 2f));
		}

		internal static float GetHandlingPowerMult()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_HandlingPowerMult", 1f), 0.25f, 3f);
		}

		internal static void SetHandlingPowerMult(float mult)
		{
			PlayerPrefs.SetFloat("SebTruck_HandlingPowerMult", Mathf.Clamp(mult, 0.25f, 3f));
		}

		internal static float GetHandlingSpeedMult()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_HandlingSpeedMult", 1f), 0.25f, 3f);
		}

		internal static void SetHandlingSpeedMult(float mult)
		{
			PlayerPrefs.SetFloat("SebTruck_HandlingSpeedMult", Mathf.Clamp(mult, 0.25f, 3f));
		}

		internal static float GetHandlingSteeringMult()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_HandlingSteeringMult", 1f), 0.25f, 3f);
		}

		internal static void SetHandlingSteeringMult(float mult)
		{
			PlayerPrefs.SetFloat("SebTruck_HandlingSteeringMult", Mathf.Clamp(mult, 0.25f, 3f));
		}

		internal static float GetHandlingGripMult()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_HandlingGripMult", 1f), 0.25f, 3f);
		}

		internal static void SetHandlingGripMult(float mult)
		{
			PlayerPrefs.SetFloat("SebTruck_HandlingGripMult", Mathf.Clamp(mult, 0.25f, 3f));
		}

		internal static float GetHandlingDownforceMult()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_HandlingDownforceMult", 1f), 0f, 3f);
		}

		internal static void SetHandlingDownforceMult(float mult)
		{
			PlayerPrefs.SetFloat("SebTruck_HandlingDownforceMult", Mathf.Clamp(mult, 0f, 3f));
		}

		internal static float GetHandlingMassMult()
		{
			return Mathf.Clamp(PlayerPrefs.GetFloat("SebTruck_HandlingMassMult", 1f), 0.25f, 3f);
		}

		internal static void SetHandlingMassMult(float mult)
		{
			PlayerPrefs.SetFloat("SebTruck_HandlingMassMult", Mathf.Clamp(mult, 0.25f, 3f));
		}

		internal static void ResetVehicleDefaults()
		{
			SetMirrorQuality(0);
			SetManualTransmissionEnabled(enabled: false);
			SetRallyManualTransmissionEnabled(enabled: false);
			SetManualGearCount(5);
			SetIgnitionFeatureEnabled(enabled: true);
			SetIgnitionEnabled(enabled: true);
			SetIgnitionHoldSeconds(1.35f);
			SetIgnitionSfxEnabled(enabled: true);
			SetIgnitionSfxVolume(0.15f);
			SetIndicatorFeatureEnabled(enabled: true);
			SetIndicatorSfxEnabled(enabled: true);
			SetIndicatorSfxVolume(1f);
			SetIndicatorBlinkSeconds(0.45f);
			SetTurnSignalLightIntensity(0.15f);
			SetManualSpeedMultForward(1f);
			SetManualSpeedMultReverse(1f);
			SetHeadlightIntensityMult(1f);
			SetHeadlightRangeMult(1f);
			SetWheelScale(1f);
			ResetHandlingDefaults(save: false);
			PlayerPrefs.Save();
		}

		internal static void ResetTransmissionDefaults()
		{
			SetManualTransmissionEnabled(enabled: false);
			SetManualGearCount(5);
			PlayerPrefs.Save();
		}

		internal static void ResetRallyTransmissionDefaults()
		{
			SetRallyManualTransmissionEnabled(enabled: false);
		}

		internal static void ResetIgnitionDefaults()
		{
			SetIgnitionFeatureEnabled(enabled: true);
			SetIgnitionEnabled(enabled: true);
			SetIgnitionHoldSeconds(1.35f);
			SetIgnitionSfxEnabled(enabled: true);
			SetIgnitionSfxVolume(0.15f);
			PlayerPrefs.Save();
		}

		internal static void ResetIndicatorDefaults()
		{
			SetIndicatorFeatureEnabled(enabled: true);
			SetIndicatorSfxEnabled(enabled: true);
			SetIndicatorSfxVolume(1f);
			SetIndicatorBlinkSeconds(0.45f);
			SetTurnSignalLightIntensity(0.15f);
			PlayerPrefs.Save();
		}

		internal static void ResetTweaksDefaults()
		{
			SetMirrorQuality(0);
			SetManualSpeedMultForward(1f);
			SetManualSpeedMultReverse(1f);
			SetHeadlightIntensityMult(1f);
			SetHeadlightRangeMult(1f);
			SetWheelScale(1f);
			PlayerPrefs.Save();
		}

		internal static void ResetBackupAlarmDefaults()
		{
			SetBackupAlarmEnabled(enabled: false);
			SetBackupAlarmHazardsEnabled(enabled: false);
			SetBackupAlarmVolume(0.55f);
			SetBackupAlarmInterval(0.65f);
			SetBackupAlarmTone(950f);
			PlayerPrefs.Save();
		}

		internal static void ResetHandlingDefaults(bool save = true)
		{
			SetHandlingPowerMult(1f);
			SetHandlingSpeedMult(1f);
			SetHandlingSteeringMult(1f);
			SetHandlingGripMult(1f);
			SetHandlingDownforceMult(1f);
			SetHandlingMassMult(1f);
			if (save)
			{
				PlayerPrefs.Save();
			}
		}

		internal static void ResetHudDefaults()
		{
			SetHudSpeedUnit(SpeedUnit.Kmh);
			SetHudStyle(HudStyle.Off);
			SetHudShowSpeed(enabled: true);
			SetHudShowTach(enabled: true);
			SetHudShowGear(enabled: true);
			SetRallyHudSpeedUnit(SpeedUnit.Kmh);
			SetHudOdometerMode(HudOdometerMode.Total);
			SetRallyHudStyle(HudStyle.Rally);
			PlayerPrefs.Save();
		}

		private void Awake()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			_debugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "debug_logging", false, "Log debug information (verbose).");
			_ignitionSfxOnPath = ((BaseUnityPlugin)this).Config.Bind<string>("Ignition", "sfx_on_path", "", "Optional ignition ON sound. File name inside the plugin's sfx folder (e.g. ignition_on.wav). Leave blank to use sfx/ignition_on.wav.");
			TryMigrateLegacyIgnitionSfxVolumeFromConfig();
			TryLoadIgnitionSfx();
			TryLoadTurnSignalEmissives();
			new Harmony("shibe.easydeliveryco.sebtruck").PatchAll(typeof(Plugin));
			try
			{
				BindAction[] array = new BindAction[5];
				RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				SebBindsApi.RegisterActionsPage("sebtruck", "Truck", (BindAction[])(object)array);
			}
			catch
			{
			}
			Log.LogInfo((object)"Loaded");
		}

		private static Type FindTypeInLoadedAssemblies(string fullName)
		{
			try
			{
				Type type = Type.GetType(fullName + ", UnityEngine.ImageConversionModule", throwOnError: false);
				if (type != null)
				{
					return type;
				}
			}
			catch
			{
			}
			try
			{
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				foreach (Assembly assembly in assemblies)
				{
					if (assembly == null)
					{
						continue;
					}
					try
					{
						Type type2 = assembly.GetType(fullName, throwOnError: false);
						if (type2 != null)
						{
							return type2;
						}
					}
					catch
					{
					}
				}
			}
			catch
			{
			}
			return null;
		}

		private static bool TryLoadImageIntoTexture(Texture2D tex, byte[] bytes)
		{
			if ((Object)(object)tex == (Object)null || bytes == null || bytes.Length == 0)
			{
				return false;
			}
			try
			{
				Type type = FindTypeInLoadedAssemblies("UnityEngine.ImageConversion");
				if (type == null)
				{
					return false;
				}
				MethodInfo methodInfo = null;
				try
				{
					methodInfo = type.GetMethod("LoadImage", BindingFlags.Static | BindingFlags.Public, null, new Type[3]
					{
						typeof(Texture2D),
						typeof(byte[]),
						typeof(bool)
					}, null);
				}
				catch
				{
				}
				if (methodInfo != null)
				{
					return !(methodInfo.Invoke(null, new object[3] { tex, bytes, true }) is bool flag) || flag;
				}
				try
				{
					methodInfo = type.GetMethod("LoadImage", BindingFlags.Static | BindingFlags.Public, null, new Type[2]
					{
						typeof(Texture2D),
						typeof(byte[])
					}, null);
				}
				catch
				{
				}
				if (methodInfo != null)
				{
					return !(methodInfo.Invoke(null, new object[2] { tex, bytes }) is bool flag2) || flag2;
				}
			}
			catch
			{
			}
			return false;
		}

		private static Texture2D LoadPngOrNull(string path)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			if (string.IsNullOrWhiteSpace(path) || !File.Exists(path))
			{
				return null;
			}
			try
			{
				byte[] array = File.ReadAllBytes(path);
				if (array == null || array.Length < 16)
				{
					return null;
				}
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				((Texture)val).wrapMode = (TextureWrapMode)1;
				((Texture)val).filterMode = (FilterMode)0;
				((Object)val).hideFlags = (HideFlags)61;
				((Object)val).name = Path.GetFileName(path);
				if (!TryLoadImageIntoTexture(val, array))
				{
					return null;
				}
				return val;
			}
			catch
			{
				return null;
			}
		}

		private static void TryLoadTurnSignalEmissives()
		{
			if (_turnSignalEmissivesTriedLoad)
			{
				return;
			}
			_turnSignalEmissivesTriedLoad = true;
			try
			{
				string path = Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location) ?? string.Empty, "emissives");
				_turnSignalEmissiveOff = LoadPngOrNull(Path.Combine(path, "truck_texture Emissive.png"));
				_turnSignalEmissiveLeft = LoadPngOrNull(Path.Combine(path, "truck_texture Emissive_left_signal.png"));
				_turnSignalEmissiveRight = LoadPngOrNull(Path.Combine(path, "truck_texture Emissive_right_signal.png"));
				_turnSignalEmissiveBoth = LoadPngOrNull(Path.Combine(path, "truck_texture Emissive_both_signal.png"));
				_turnSignalEmissiveBrakeOff = LoadPngOrNull(Path.Combine(path, "truck_texture Emissive-Breaking.png"));
				_turnSignalEmissiveBrakeLeft = LoadPngOrNull(Path.Combine(path, "truck_texture Emissive-Breaking_left_signal.png"));
				_turnSignalEmissiveBrakeRight = LoadPngOrNull(Path.Combine(path, "truck_texture Emissive-Breaking_right_signal.png"));
				_turnSignalEmissiveBrakeBoth = LoadPngOrNull(Path.Combine(path, "truck_texture Emissive-Breaking_both_signal.png"));
				int num = 0;
				if ((Object)(object)_turnSignalEmissiveOff != (Object)null)
				{
					num++;
				}
				if ((Object)(object)_turnSignalEmissiveLeft != (Object)null)
				{
					num++;
				}
				if ((Object)(object)_turnSignalEmissiveRight != (Object)null)
				{
					num++;
				}
				if ((Object)(object)_turnSignalEmissiveBoth != (Object)null)
				{
					num++;
				}
				if ((Object)(object)_turnSignalEmissiveBrakeOff != (Object)null)
				{
					num++;
				}
				if ((Object)(object)_turnSignalEmissiveBrakeLeft != (Object)null)
				{
					num++;
				}
				if ((Object)(object)_turnSignalEmissiveBrakeRight != (Object)null)
				{
					num++;
				}
				if ((Object)(object)_turnSignalEmissiveBrakeBoth != (Object)null)
				{
					num++;
				}
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogInfo((object)("Turn signal emissives: loaded " + num + "/8"));
				}
			}
			catch
			{
			}
		}

		internal static Texture2D GetTurnSignalEmissive(bool braking, int indicatorMode, bool blinkOn)
		{
			TryLoadTurnSignalEmissives();
			Texture2D result = (braking ? _turnSignalEmissiveBrakeOff : _turnSignalEmissiveOff);
			if (!blinkOn || indicatorMode == 0)
			{
				return result;
			}
			Texture2D val = (braking ? _turnSignalEmissiveBrakeLeft : _turnSignalEmissiveLeft);
			Texture2D val2 = (braking ? _turnSignalEmissiveBrakeRight : _turnSignalEmissiveRight);
			Texture2D val3 = (braking ? _turnSignalEmissiveBrakeBoth : _turnSignalEmissiveBoth);
			switch (indicatorMode)
			{
			case 1:
				if (!((Object)(object)val != (Object)null))
				{
					return result;
				}
				return val;
			case 2:
				if (!((Object)(object)val2 != (Object)null))
				{
					return result;
				}
				return val2;
			case 3:
				if (!((Object)(object)val3 != (Object)null))
				{
					return result;
				}
				return val3;
			default:
				return result;
			}
		}

		private static void TryMigrateLegacyIgnitionSfxVolumeFromConfig()
		{
			try
			{
				if (PlayerPrefs.HasKey("SebTruck_IgnitionSfxVolume"))
				{
					return;
				}
				string path = Path.Combine(Paths.ConfigPath, "shibe.easydeliveryco.sebtruck.cfg");
				if (!File.Exists(path))
				{
					return;
				}
				bool flag = false;
				float num = -1f;
				string[] array = File.ReadAllLines(path);
				foreach (string text in array)
				{
					string text2 = ((text != null) ? text.Trim() : string.Empty);
					if (string.IsNullOrWhiteSpace(text2) || text2.StartsWith("#") || text2.StartsWith(";"))
					{
						continue;
					}
					if (text2.StartsWith("[") && text2.EndsWith("]"))
					{
						flag = string.Equals(text2.Substring(1, text2.Length - 2).Trim(), "Ignition", StringComparison.OrdinalIgnoreCase);
					}
					else
					{
						if (!flag)
						{
							continue;
						}
						int num2 = text2.IndexOf('=');
						if (num2 <= 0)
						{
							continue;
						}
						string a = text2.Substring(0, num2).Trim();
						string s = text2.Substring(num2 + 1).Trim();
						if (string.Equals(a, "sfx_volume", StringComparison.OrdinalIgnoreCase))
						{
							if (float.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
							{
								num = Mathf.Clamp01(result);
							}
							else if (float.TryParse(s, out result))
							{
								num = Mathf.Clamp01(result);
							}
							break;
						}
					}
				}
				if (num >= 0f)
				{
					SetIgnitionSfxVolume(num);
					PlayerPrefs.Save();
					LogDebug("Migrated legacy ignition volume from config: " + num.ToString("0.00", CultureInfo.InvariantCulture));
				}
			}
			catch
			{
			}
		}

		internal static void LogDebug(string msg)
		{
			if (_debugLogging != null && _debugLogging.Value)
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogMessage((object)msg);
				}
			}
		}

		private static void TryLoadIgnitionSfx()
		{
			string dir = Path.GetDirectoryName(typeof(Plugin).Assembly.Location) ?? string.Empty;
			_ignitionSfxOn = LoadWavOrNull(Resolve((_ignitionSfxOnPath != null) ? _ignitionSfxOnPath.Value : string.Empty, "ignition_on"));
			ManualLogSource log = Log;
			if (log != null)
			{
				log.LogInfo((object)("Ignition SFX: on=" + (_ignitionSfxOn != (Object)null)));
			}
			string Resolve(string cfg, string baseName)
			{
				string path = Path.Combine(dir, "sfx");
				if (string.IsNullOrWhiteSpace(cfg))
				{
					string text = Path.Combine(path, baseName + ".wav");
					if (!File.Exists(text))
					{
						return string.Empty;
					}
					return text;
				}
				if (Path.IsPathRooted(cfg))
				{
					return cfg;
				}
				string text2 = Path.Combine(path, cfg);
				if (!File.Exists(text2))
				{
					return string.Empty;
				}
				return text2;
			}
		}

		private static Object LoadWavOrNull(string path)
		{
			if (string.IsNullOrWhiteSpace(path))
			{
				return null;
			}
			if (!string.Equals(Path.GetExtension(path), ".wav", StringComparison.OrdinalIgnoreCase))
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogWarning((object)("Ignition SFX: only .wav is supported in this build: " + path));
				}
				return null;
			}
			try
			{
				int channels;
				int sampleRate;
				float[] array = WavPcm16.Read(File.ReadAllBytes(path), out channels, out sampleRate);
				return CreateAudioClip("ignition_on", array.Length / channels, channels, sampleRate, array);
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("Ignition SFX load failed: " + path + " (" + ex.Message + ")"));
				}
				return null;
			}
		}

		private static Object CreateAudioClip(string name, int samplesPerChannel, int channels, int sampleRate, float[] data)
		{
			try
			{
				Type type = Type.GetType("UnityEngine.AudioClip, UnityEngine.AudioModule");
				if (type == null)
				{
					return null;
				}
				MethodInfo method = type.GetMethod("Create", BindingFlags.Static | BindingFlags.Public, null, new Type[5]
				{
					typeof(string),
					typeof(int),
					typeof(int),
					typeof(int),
					typeof(bool)
				}, null);
				if (method == null)
				{
					return null;
				}
				object obj = method.Invoke(null, new object[5] { name, samplesPerChannel, channels, sampleRate, false });
				if (obj == null)
				{
					return null;
				}
				MethodInfo method2 = type.GetMethod("SetData", new Type[2]
				{
					typeof(float[]),
					typeof(int)
				});
				if (method2 != null)
				{
					method2.Invoke(obj, new object[2] { data, 0 });
				}
				return (Object)((obj is Object) ? obj : null);
			}
			catch
			{
				return null;
			}
		}

		internal static void PlayIgnitionOnSfx(sCarController car)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			if (!GetIgnitionSfxEnabled() || _ignitionSfxOn == (Object)null || (Object)(object)car == (Object)null)
			{
				return;
			}
			float ignitionSfxVolume = GetIgnitionSfxVolume();
			try
			{
				GameObject val = null;
				if ((Object)(object)car.headlights != (Object)null)
				{
					val = ((Component)car.headlights).gameObject;
				}
				if ((Object)(object)val == (Object)null)
				{
					val = ((Component)car).gameObject;
				}
				GameObject val2 = new GameObject("SebTruck_IgnitionSFX");
				((Object)val2).hideFlags = (HideFlags)61;
				val2.transform.SetParent(val.transform, false);
				Type type = Type.GetType("UnityEngine.AudioSource, UnityEngine.AudioModule");
				if (!(type == null))
				{
					Component c = val2.AddComponent(type);
					SetProp(c, "spatialBlend", 0f);
					SetProp(c, "volume", ignitionSfxVolume);
					SetProp(c, "playOnAwake", false);
					SetProp(c, "loop", false);
					SetProp(c, "clip", _ignitionSfxOn);
					Call(c, "Play");
					Object.Destroy((Object)(object)val2, 5f);
				}
			}
			catch
			{
			}
		}

		private static void SetProp(Component c, string name, object value)
		{
			if ((Object)(object)c == (Object)null || string.IsNullOrWhiteSpace(name))
			{
				return;
			}
			try
			{
				PropertyInfo property = ((object)c).GetType().GetProperty(name);
				if (property != null && property.CanWrite)
				{
					property.SetValue(c, value, null);
				}
			}
			catch
			{
			}
		}

		private static float GetFloatProp(Component c, string name, float def = 0f)
		{
			if ((Object)(object)c == (Object)null || string.IsNullOrWhiteSpace(name))
			{
				return def;
			}
			try
			{
				PropertyInfo property = ((object)c).GetType().GetProperty(name);
				if (property != null && property.CanRead)
				{
					object value = property.GetValue(c, null);
					if (value is float result)
					{
						return result;
					}
					if (value is double num)
					{
						return (float)num;
					}
					if (value is int num2)
					{
						return num2;
					}
				}
			}
			catch
			{
			}
			return def;
		}

		private static void Call(Component c, string method, params object[] args)
		{
			if ((Object)(object)c == (Object)null || string.IsNullOrWhiteSpace(method))
			{
				return;
			}
			try
			{
				MethodInfo[] methods = ((object)c).GetType().GetMethods();
				MethodInfo methodInfo = null;
				foreach (MethodInfo methodInfo2 in methods)
				{
					if (!(methodInfo2 == null) && string.Equals(methodInfo2.Name, method, StringComparison.Ordinal))
					{
						ParameterInfo[] parameters = methodInfo2.GetParameters();
						if (parameters != null && parameters.Length == ((args != null) ? args.Length : 0))
						{
							methodInfo = methodInfo2;
							break;
						}
					}
				}
				if (methodInfo != null)
				{
					methodInfo.Invoke(c, args);
				}
			}
			catch
			{
			}
		}

		internal static void PlayIndicatorClick(sCarController car, bool highPitch)
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			if (!GetIndicatorSfxEnabled() || (Object)(object)car == (Object)null || car.GuyActive)
			{
				return;
			}
			Headlights headlights = car.headlights;
			if ((Object)(object)headlights == (Object)null)
			{
				return;
			}
			try
			{
				object? obj = AccessTools.Field(((object)headlights).GetType(), "headlightsOff")?.GetValue(headlights);
				Object val = (Object)((obj is Object) ? obj : null);
				if (val == (Object)null)
				{
					return;
				}
				float num = 0.22f * GetIndicatorSfxVolume();
				if (num <= 0.001f)
				{
					return;
				}
				float num2 = (highPitch ? 1.08f : 0.92f);
				if ((Object)(object)_indicatorClickSfxGo == (Object)null)
				{
					_indicatorClickSfxGo = new GameObject("SebTruck_IndicatorClickSFX");
					((Object)_indicatorClickSfxGo).hideFlags = (HideFlags)61;
					Type type = Type.GetType("UnityEngine.AudioSource, UnityEngine.AudioModule");
					if (type == null)
					{
						return;
					}
					_indicatorClickSfxSource = _indicatorClickSfxGo.AddComponent(type);
					SetProp(_indicatorClickSfxSource, "loop", false);
					SetProp(_indicatorClickSfxSource, "playOnAwake", false);
					SetProp(_indicatorClickSfxSource, "spatialBlend", 1f);
					SetProp(_indicatorClickSfxSource, "dopplerLevel", 0f);
					SetProp(_indicatorClickSfxSource, "minDistance", 3f);
					SetProp(_indicatorClickSfxSource, "maxDistance", 30f);
				}
				if ((Object)(object)_indicatorClickSfxGo.transform.parent != (Object)(object)((Component)car).transform)
				{
					_indicatorClickSfxGo.transform.SetParent(((Component)car).transform, false);
				}
				_indicatorClickSfxGo.transform.localPosition = Vector3.zero;
				SetProp(_indicatorClickSfxSource, "volume", num);
				SetProp(_indicatorClickSfxSource, "pitch", num2);
				Call(_indicatorClickSfxSource, "PlayOneShot", val, num);
			}
			catch
			{
			}
		}

		internal static void StartIgnitionHoldSfx(sCarController car)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			if (!GetIgnitionSfxEnabled() || _ignitionSfxOn == (Object)null || (Object)(object)car == (Object)null || car.GuyActive)
			{
				return;
			}
			float ignitionSfxVolume = GetIgnitionSfxVolume();
			if (ignitionSfxVolume <= 0.001f)
			{
				return;
			}
			try
			{
				if ((Object)(object)_ignitionHoldSfxGo == (Object)null)
				{
					_ignitionHoldSfxGo = new GameObject("SebTruck_IgnitionHoldSFX");
					((Object)_ignitionHoldSfxGo).hideFlags = (HideFlags)61;
					Type type = Type.GetType("UnityEngine.AudioSource, UnityEngine.AudioModule");
					if (type == null)
					{
						return;
					}
					_ignitionHoldSfxSource = _ignitionHoldSfxGo.AddComponent(type);
					SetProp(_ignitionHoldSfxSource, "loop", false);
					SetProp(_ignitionHoldSfxSource, "playOnAwake", false);
					SetProp(_ignitionHoldSfxSource, "spatialBlend", 1f);
					SetProp(_ignitionHoldSfxSource, "dopplerLevel", 0f);
					SetProp(_ignitionHoldSfxSource, "minDistance", 5f);
					SetProp(_ignitionHoldSfxSource, "maxDistance", 40f);
				}
				if ((Object)(object)_ignitionHoldSfxGo.transform.parent != (Object)(object)((Component)car).transform)
				{
					_ignitionHoldSfxGo.transform.SetParent(((Component)car).transform, false);
				}
				_ignitionHoldSfxGo.transform.localPosition = Vector3.zero;
				SetProp(_ignitionHoldSfxSource, "volume", ignitionSfxVolume);
				SetProp(_ignitionHoldSfxSource, "clip", _ignitionSfxOn);
				bool flag = false;
				try
				{
					PropertyInfo property = ((object)_ignitionHoldSfxSource).GetType().GetProperty("isPlaying");
					if (property != null)
					{
						flag = (bool)property.GetValue(_ignitionHoldSfxSource, null);
					}
				}
				catch
				{
				}
				if (!flag)
				{
					Call(_ignitionHoldSfxSource, "Play");
				}
			}
			catch
			{
			}
		}

		internal static void StopIgnitionHoldSfx()
		{
			try
			{
				if ((Object)(object)_ignitionHoldSfxSource != (Object)null)
				{
					Call(_ignitionHoldSfxSource, "Stop");
				}
			}
			catch
			{
			}
		}

		internal static bool GetMountSnowTires()
		{
			return PlayerPrefs.GetInt("SebTruck_MountSnowTires", 1) != 0;
		}

		internal static void SetMountSnowTires(bool mounted)
		{
			PlayerPrefs.SetInt("SebTruck_MountSnowTires", mounted ? 1 : 0);
		}

		internal static bool GetMountIceChains()
		{
			return PlayerPrefs.GetInt("SebTruck_MountIceChains", 1) != 0;
		}

		internal static void SetMountIceChains(bool mounted)
		{
			PlayerPrefs.SetInt("SebTruck_MountIceChains", mounted ? 1 : 0);
		}

		internal static bool GetMountRamBar()
		{
			return PlayerPrefs.GetInt("SebTruck_MountRamBar", 1) != 0;
		}

		internal static void SetMountRamBar(bool mounted)
		{
			PlayerPrefs.SetInt("SebTruck_MountRamBar", mounted ? 1 : 0);
		}

		internal static bool HasSnowTiresUpgrade()
		{
			if ((Object)(object)_truckUpgrades != (Object)null)
			{
				return _truckUpgrades.hasTires;
			}
			return false;
		}

		internal static bool HasIceChainsUpgrade()
		{
			if ((Object)(object)_truckUpgrades != (Object)null)
			{
				return _truckUpgrades.hasChains;
			}
			return false;
		}

		internal static bool HasRamBarUpgrade()
		{
			if ((Object)(object)_truckUpgrades != (Object)null)
			{
				return _truckUpgrades.hasBumper;
			}
			return false;
		}

		internal static int GetHornIndex()
		{
			return (PlayerPrefs.GetInt("SebTruck_Horn", 0) == 1) ? 1 : 0;
		}

		internal static void SetHornIndex(int index)
		{
			PlayerPrefs.SetInt("SebTruck_Horn", Mathf.Clamp(index, 0, HornLabels.Length - 1));
		}

		internal static void ResetEquipmentDefaults()
		{
			SetMountSnowTires(mounted: true);
			SetMountIceChains(mounted: true);
			SetMountRamBar(mounted: true);
			SetHornIndex(0);
			PlayerPrefs.Save();
		}

		[HarmonyPatch(typeof(TruckUpgrades), "LateUpdate")]
		[HarmonyPostfix]
		private static void TruckUpgrades_LateUpdate_Postfix(TruckUpgrades __instance, SnowTires ___snowTires, BumperBar ___bumper)
		{
			_truckUpgrades = __instance;
			if ((Object)(object)___bumper != (Object)null)
			{
				___bumper.active = __instance.hasBumper && GetMountRamBar();
			}
			if (!((Object)(object)___snowTires == (Object)null))
			{
				___snowTires.hasSnowTires = __instance.hasTires && GetMountSnowTires();
				___snowTires.hasIceChains = __instance.hasChains && GetMountIceChains();
			}
		}

		private static bool HideUnmountedRamBar()
		{
			int num;
			if ((Object)(object)_truckUpgrades != (Object)null && _truckUpgrades.hasBumper)
			{
				num = ((!GetMountRamBar()) ? 1 : 0);
				if (num != 0)
				{
					_truckUpgrades.hasBumper = false;
				}
			}
			else
			{
				num = 0;
			}
			return (byte)num != 0;
		}

		private static Exception RestoreRamBar(Exception exception, bool hidden)
		{
			if (hidden && (Object)(object)_truckUpgrades != (Object)null)
			{
				_truckUpgrades.hasBumper = true;
			}
			return exception;
		}

		[HarmonyPatch(typeof(CarDamage), "CheckDeadVelocity")]
		[HarmonyPrefix]
		private static void CarDamage_CheckDeadVelocity_RamBarPrefix(out bool __state)
		{
			__state = HideUnmountedRamBar();
		}

		[HarmonyPatch(typeof(CarDamage), "CheckDeadVelocity")]
		[HarmonyFinalizer]
		private static Exception CarDamage_CheckDeadVelocity_RamBarFinalizer(Exception __exception, bool __state)
		{
			return RestoreRamBar(__exception, __state);
		}

		[HarmonyPatch(typeof(Crashable), "OnCollisionEnter")]
		[HarmonyPrefix]
		private static void Crashable_OnCollisionEnter_RamBarPrefix(out bool __state)
		{
			__state = HideUnmountedRamBar();
		}

		[HarmonyPatch(typeof(Crashable), "OnCollisionEnter")]
		[HarmonyFinalizer]
		private static Exception Crashable_OnCollisionEnter_RamBarFinalizer(Exception __exception, bool __state)
		{
			return RestoreRamBar(__exception, __state);
		}

		[HarmonyPatch(typeof(Crashable), "MakeRigidbody")]
		[HarmonyPrefix]
		private static void Crashable_MakeRigidbody_RamBarPrefix(out bool __state)
		{
			__state = HideUnmountedRamBar();
		}

		[HarmonyPatch(typeof(Crashable), "MakeRigidbody")]
		[HarmonyFinalizer]
		private static Exception Crashable_MakeRigidbody_RamBarFinalizer(Exception __exception, bool __state)
		{
			return RestoreRamBar(__exception, __state);
		}

		[HarmonyPatch(typeof(Headlights), "Update")]
		[HarmonyPrefix]
		private static void Headlights_Update_Prefix(Headlights __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && !(HeadlightsHornField == null))
			{
				object? value = HeadlightsHornField.GetValue(__instance);
				Object val = (Object)((value is Object) ? value : null);
				if (val != _appliedHorn)
				{
					_gameHorn = val;
				}
				Object val2 = GetSelectedHornClip();
				if (val2 == (Object)null)
				{
					val2 = _gameHorn;
				}
				if (val2 != val)
				{
					HeadlightsHornField.SetValue(__instance, val2);
				}
				_appliedHorn = val2;
			}
		}

		private static Object GetSelectedHornClip()
		{
			int hornIndex = GetHornIndex();
			string text = HornClipNames[hornIndex];
			if (HornClipCache[hornIndex] != (Object)null)
			{
				return HornClipCache[hornIndex];
			}
			if (Time.unscaledTime < _nextHornClipScan)
			{
				return null;
			}
			_nextHornClipScan = Time.unscaledTime + 5f;
			Type type = Type.GetType("UnityEngine.AudioClip, UnityEngine.AudioModule");
			if (type == null)
			{
				return null;
			}
			Object[] array = Resources.FindObjectsOfTypeAll(type);
			foreach (Object val in array)
			{
				if (val != (Object)null && val.name == text)
				{
					HornClipCache[hornIndex] = val;
					return val;
				}
			}
			return null;
		}

		private static Object CreateAudioClip(string name, float[] data, int sampleRate)
		{
			Type type = Type.GetType("UnityEngine.AudioClip, UnityEngine.AudioModule");
			MethodInfo methodInfo = type?.GetMethod("Create", new Type[5]
			{
				typeof(string),
				typeof(int),
				typeof(int),
				typeof(int),
				typeof(bool)
			});
			if (methodInfo == null)
			{
				return null;
			}
			object? obj = methodInfo.Invoke(null, new object[5] { name, data.Length, 1, sampleRate, false });
			Object val = (Object)((obj is Object) ? obj : null);
			if (val != (Object)null)
			{
				type.GetMethod("SetData", new Type[2]
				{
					typeof(float[]),
					typeof(int)
				})?.Invoke(val, new object[2] { data, 0 });
			}
			return val;
		}

		internal static HudStyle GetRallyHudStyle()
		{
			if (PlayerPrefs.GetInt("SebTruck_RallyHudStyle", 1) != 2)
			{
				return HudStyle.Rally;
			}
			return HudStyle.Fancy;
		}

		internal static void SetRallyHudStyle(HudStyle style)
		{
			PlayerPrefs.SetInt("SebTruck_RallyHudStyle", (int)style);
		}

		internal static HudOdometerMode GetHudOdometerMode()
		{
			return (HudOdometerMode)Mathf.Clamp(PlayerPrefs.GetInt("SebTruck_HudOdometer", 1), 0, 2);
		}

		internal static void SetHudOdometerMode(HudOdometerMode mode)
		{
			PlayerPrefs.SetInt("SebTruck_HudOdometer", (int)mode);
		}

		private static void AccumulateOdometer(float speedKmh)
		{
			if (_odometerFrame != Time.frameCount && !PauseSystem.paused && !IsRallyModeActive())
			{
				_odometerFrame = Time.frameCount;
				_odometerPendingKm += FancyGauge.DistanceKm(speedKmh, Time.deltaTime);
				if (Time.unscaledTime >= _odometerNextFlush)
				{
					_odometerNextFlush = Time.unscaledTime + 5f;
					FlushOdometer();
				}
			}
		}

		private static void FlushOdometer()
		{
			if (!(_odometerPendingKm <= 0.0) && !((Object)(object)sSaveSystem.instance == (Object)null))
			{
				sSaveSystem.SetFloat("SebTruck_OdometerKm", (float)((double)sSaveSystem.GetFloat("SebTruck_OdometerKm", 0f) + _odometerPendingKm));
				sSaveSystem.SetFloat("SebTruck_TripKm", (float)((double)sSaveSystem.GetFloat("SebTruck_TripKm", 0f) + _odometerPendingKm));
				_odometerPendingKm = 0.0;
			}
		}

		internal static double GetOdometerKm(bool trip)
		{
			if ((Object)(object)sSaveSystem.instance == (Object)null)
			{
				return _odometerPendingKm;
			}
			return (double)sSaveSystem.GetFloat(trip ? "SebTruck_TripKm" : "SebTruck_OdometerKm", 0f) + _odometerPendingKm;
		}

		internal static void ResetTrip()
		{
			FlushOdometer();
			if ((Object)(object)sSaveSystem.instance != (Object)null)
			{
				sSaveSystem.SetFloat("SebTruck_TripKm", 0f);
			}
		}

		internal static string FormatStoryOdometer(bool trip)
		{
			bool flag = GetHudSpeedUnit() == SpeedUnit.Mph;
			return FancyGauge.FormatOdometer(GetOdometerKm(trip), flag, trip) + (flag ? "mi" : "km");
		}

		private static double GetRallyOdometerKm()
		{
			if ((Object)(object)_easyRally == (Object)null)
			{
				_easyRally = Object.FindFirstObjectByType<sEasyRally>();
			}
			if (!((Object)(object)_easyRally != (Object)null))
			{
				return -1.0;
			}
			return (double)_easyRally.distanceTraveled / 1000.0;
		}

		private static void DrawStoryFancyHud(MiniRenderer R, bool showSpeed, bool showTach, bool showGear, bool engineOn, string status)
		{
			float num = (showSpeed ? 44f : 0f) + ((showTach || showGear) ? 42f : 0f);
			float x = (float)R.width - 72f - num;
			float y = (float)R.height - 70f;
			HudOdometerMode hudOdometerMode = GetHudOdometerMode();
			bool trip = hudOdometerMode == HudOdometerMode.Trip;
			double odometerKm = ((hudOdometerMode == HudOdometerMode.Off || !showSpeed) ? (-1.0) : GetOdometerKm(trip));
			float speed = (engineOn ? ConvertSpeedForHud(_currentSpeedKmh) : 0f);
			float rpmNorm = (engineOn ? GetEstimatedRpmNormForHud() : 0f);
			DrawFancyHudParts(R, x, y, showSpeed, showTach, showGear, GetManualGear(), rpmNorm, engineOn && IsAtStoryRevLimiter(), speed, GetHudSpeedUnit(), status, odometerKm, trip);
		}

		private static void DrawFancyHudParts(MiniRenderer R, float x, float y, bool showSpeed, bool showTach, bool showGear, int gear, float rpmNorm, bool atLimiter, float speed, SpeedUnit units, string status, double odometerKm, bool trip)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			float num = y + 22f;
			float num2 = x;
			R.fontOptions.alignment = (Alignment)0;
			if (showSpeed)
			{
				num2 = x + 22f;
				float num3 = ((units == SpeedUnit.Mph) ? 100f : 160f);
				int majorTicks = ((units == SpeedUnit.Mph) ? 10 : 8);
				DrawDial(R, num2, num, 22f, majorTicks, 2f, speed / num3, jitter: false);
				PutCentered(R, Mathf.RoundToInt(Mathf.Max(0f, speed)).ToString(), num2, num + 6f);
				num2 += 28f;
			}
			if (showTach || showGear)
			{
				float cx = num2 + 18f;
				if (showTach)
				{
					DrawDial(R, cx, num, 18f, 8, 0.85f, rpmNorm, atLimiter);
				}
				if (showGear)
				{
					PutCentered(R, (gear < 0) ? "R" : ((gear == 0) ? "N" : gear.ToString()), cx, num + 5f);
				}
			}
			float num4 = y + 44f + 3f;
			if (!string.IsNullOrEmpty(status))
			{
				R.put(status, x, num4);
			}
			else if (odometerKm >= 0.0)
			{
				DrawRollingOdometer(R, x, num4, odometerKm, units == SpeedUnit.Mph, trip);
			}
		}

		private static void DrawRollingOdometer(MiniRenderer R, float x, float y, double km, bool miles, bool trip)
		{
			double num = (miles ? (km * 0.621371) : km);
			int num2 = (trip ? 4 : 6);
			FancyGauge.OdometerWheels(trip ? (num * 10.0) : num, OdometerDigits, OdometerRolls);
			for (int num3 = num2 - 1; num3 >= 0; num3--)
			{
				if (trip && num3 == 0)
				{
					R.put(".", x, y);
					x += 8f;
				}
				DrawOdometerWheel(R, x, y, OdometerDigits[num3], OdometerRolls[num3]);
				x += 8f;
			}
			R.put(miles ? "mi" : "km", x, y);
		}

		private static void DrawOdometerWheel(MiniRenderer R, float x, float y, int digit, double roll)
		{
			int num = Mathf.Clamp(Mathf.RoundToInt((float)roll * 8f), 0, 8);
			float num2 = (float)(48 + digit - 32) * 8f;
			float num3 = (float)(48 + (digit + 1) % 10 - 32) * 8f;
			if (num < 8)
			{
				R.spr(R.fontSheet, num2, (float)num, x, y, 8f, 8f - (float)num, false, 8f, 8f - (float)num);
			}
			if (num > 0)
			{
				R.spr(R.fontSheet, num3, 0f, x, y + 8f - (float)num, 8f, (float)num, false, 8f, (float)num);
			}
		}

		[HarmonyPatch(typeof(sHUD), "RadioDisplay")]
		[HarmonyPrefix]
		private static void SHUD_RadioDisplay_Prefix(MiniRenderer ___R)
		{
			if (!((Object)(object)___R == (Object)null) && !((Object)(object)_radioLiftedRenderer != (Object)null) && !IsRallyModeActive() && GetHudStyle() == HudStyle.Fancy)
			{
				___R.height -= 34;
				_radioLiftedRenderer = ___R;
			}
		}

		[HarmonyPatch(typeof(sHUD), "RadioDisplay")]
		[HarmonyFinalizer]
		private static Exception SHUD_RadioDisplay_Finalizer(Exception __exception)
		{
			RestoreRadioLift();
			return __exception;
		}

		private static void RestoreRadioLift()
		{
			if ((Object)(object)_radioLiftedRenderer != (Object)null)
			{
				MiniRenderer radioLiftedRenderer = _radioLiftedRenderer;
				radioLiftedRenderer.height += 34;
				_radioLiftedRenderer = null;
			}
		}

		private static void DrawDial(MiniRenderer R, float cx, float cy, float radius, int majorTicks, float redFrom01, float value01, bool jitter)
		{
			int num = Mathf.CeilToInt(radius * 4.71f);
			for (int i = 0; i <= num; i++)
			{
				DialDot(R, cx, cy, radius, (float)i / (float)num);
			}
			for (int j = 0; j <= majorTicks; j++)
			{
				float num2 = (float)j / (float)majorTicks;
				float num3 = ((num2 >= redFrom01) ? 5f : 3f);
				for (float num4 = radius - num3; num4 < radius; num4 += 1f)
				{
					DialDot(R, cx, cy, num4, num2);
				}
			}
			float value2 = Mathf.Clamp01(value01) - (jitter ? (Random.value * 0.05f) : 0f);
			for (float num5 = 2f; num5 <= radius - 3f; num5 += 1f)
			{
				DialDot(R, cx, cy, num5, value2);
			}
			R.spr(48f, 32f, Mathf.Round(cx) - 1f, Mathf.Round(cy) - 1f, 2f, 2f);
		}

		private static void DialDot(MiniRenderer R, float cx, float cy, float r, float value01)
		{
			double num = FancyGauge.DialAngle(value01);
			R.spr(49f, 33f, Mathf.Round(cx + (float)Math.Cos(num) * r), Mathf.Round(cy - (float)Math.Sin(num) * r), 1f, 1f);
		}

		private static void PutCentered(MiniRenderer R, string text, float cx, float y)
		{
			R.put(text, Mathf.Round(cx - (float)text.Length * 4f), y);
		}

		internal static int GetMirrorQuality()
		{
			return ModGraphics.GetMirrorQuality();
		}

		internal static string GetMirrorQualityLabel(int quality)
		{
			if (quality != 0)
			{
				return (1 << Mathf.Clamp(quality, 0, 3)) + "x";
			}
			return "Original";
		}

		internal static void SetMirrorQuality(int quality)
		{
			ModGraphics.SetMirrorQuality(quality);
		}

		private void OnEnable()
		{
			ModGraphics.EnableMirrorQuality(true);
		}

		private void OnDisable()
		{
			ModGraphics.EnableMirrorQuality(false);
		}

		private static void EnsureHeadlightsRefs(object instance)
		{
			if (instance != null)
			{
				Type type = instance.GetType();
				if (!(_headlightsRuntimeType == type))
				{
					_headlightsRuntimeType = type;
					_headlightsHeadLightsField = AccessTools.Field(type, "headLights");
					_headlightsCarMatField = AccessTools.Field(type, "carMat");
					_headlightsEmissiveRegularField = AccessTools.Field(type, "emissiveRegular");
					_headlightsHeadlightsOnField = AccessTools.Field(type, "headlightsOn");
					_headlightsModelField = AccessTools.Field(type, "model");
				}
			}
		}

		private static void EnsureRadioRefs()
		{
			if (!(_radioTargetVolumeField != null))
			{
				_radioTargetVolumeField = AccessTools.Field(typeof(sRadioSystem), "targetVolume");
				_radioRadioVolumeField = AccessTools.Field(typeof(sRadioSystem), "radioVolume");
				_radioSourceField = AccessTools.Field(typeof(sRadioSystem), "source");
				_radioNoiseField = AccessTools.Field(typeof(sRadioSystem), "noise");
			}
		}

		private static void EnsureRallyWheelRefs()
		{
			if (_rallyWheelTurningRadiusField != null)
			{
				return;
			}
			try
			{
				_rallyWheelTurningRadiusField = AccessTools.Field(typeof(Wheel), "turningRadius");
			}
			catch
			{
				_rallyWheelTurningRadiusField = null;
			}
		}

		private static void EnsureCarDamageRefs()
		{
			if (_carDamageCarMatField != null)
			{
				return;
			}
			try
			{
				_carDamageCarMatField = AccessTools.Field(typeof(CarDamage), "carMat");
			}
			catch
			{
				_carDamageCarMatField = null;
			}
		}

		private static Material FindMaterialByName(string name)
		{
			if (string.IsNullOrWhiteSpace(name))
			{
				return null;
			}
			string text = name.Trim();
			if (_paintMaterialCache.TryGetValue(text, out var value))
			{
				return value;
			}
			try
			{
				Material[] array = Resources.FindObjectsOfTypeAll<Material>();
				if (array != null)
				{
					foreach (Material val in array)
					{
						if ((Object)(object)val != (Object)null && string.Equals(((Object)val).name, text, StringComparison.OrdinalIgnoreCase))
						{
							_paintMaterialCache[text] = val;
							return val;
						}
					}
				}
			}
			catch
			{
			}
			_paintMaterialCache[text] = null;
			return null;
		}

		private static string DeriveTruckPaintMaterialName(string cosmeticName)
		{
			if (string.IsNullOrWhiteSpace(cosmeticName))
			{
				return string.Empty;
			}
			string text = cosmeticName.Trim();
			if (text.Length == 0)
			{
				return string.Empty;
			}
			if (text.StartsWith("truck_texture", StringComparison.OrdinalIgnoreCase))
			{
				return text;
			}
			if (text.EndsWith(" paint", StringComparison.OrdinalIgnoreCase))
			{
				text = text.Substring(0, text.Length - 5).Trim();
			}
			string text2 = text.ToLowerInvariant().Replace(' ', '_');
			if (text2 == "default" || text2 == "white")
			{
				return "truck_texture";
			}
			return "truck_texture_" + text2;
		}

		private static bool IsTailgateRenderer(MeshRenderer mr)
		{
			if ((Object)(object)mr == (Object)null)
			{
				return false;
			}
			try
			{
				string name = ((Object)mr).name;
				if (!string.IsNullOrWhiteSpace(name) && name.IndexOf("tailgate", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		private static int ComputeTailgateSignature(sCarController car)
		{
			if ((Object)(object)car == (Object)null)
			{
				return 0;
			}
			int num = 17;
			try
			{
				MeshRenderer[] componentsInChildren = ((Component)car).GetComponentsInChildren<MeshRenderer>(true);
				if (componentsInChildren != null)
				{
					foreach (MeshRenderer val in componentsInChildren)
					{
						if (IsTailgateRenderer(val))
						{
							num = num * 31 + ((Object)val).GetInstanceID();
							num = num * 31 + (((Object)(object)((Component)val).gameObject != (Object)null && ((Component)val).gameObject.activeInHierarchy) ? 1 : 0);
						}
					}
				}
			}
			catch
			{
			}
			return num;
		}

		private static bool IsTruckPaintMaterial(Material m)
		{
			if ((Object)(object)m == (Object)null)
			{
				return false;
			}
			try
			{
				return ((Object)m).name != null && ((Object)m).name.IndexOf("truck_texture", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			catch
			{
				return false;
			}
		}

		private static void ApplyTailgatePaintMaterialIfPresent(sCarController car, Material paintMat)
		{
			if ((Object)(object)car == (Object)null || (Object)(object)paintMat == (Object)null)
			{
				return;
			}
			try
			{
				MeshRenderer[] componentsInChildren = ((Component)car).GetComponentsInChildren<MeshRenderer>(true);
				if (componentsInChildren == null)
				{
					return;
				}
				foreach (MeshRenderer val in componentsInChildren)
				{
					if (!IsTailgateRenderer(val))
					{
						continue;
					}
					Material[] sharedMaterials = ((Renderer)val).sharedMaterials;
					if (sharedMaterials == null || sharedMaterials.Length == 0)
					{
						continue;
					}
					bool flag = false;
					for (int j = 0; j < sharedMaterials.Length; j++)
					{
						if (IsTruckPaintMaterial(sharedMaterials[j]) && sharedMaterials[j] != paintMat)
						{
							sharedMaterials[j] = paintMat;
							flag = true;
						}
					}
					if (flag)
					{
						((Renderer)val).sharedMaterials = sharedMaterials;
					}
				}
			}
			catch
			{
			}
		}

		private static void ApplyTruckPaintIfNeeded(sCarController car)
		{
			if ((Object)(object)car == (Object)null || !IsTruckCar(car))
			{
				return;
			}
			int instanceID = ((Object)car).GetInstanceID();
			int selectedPaintIndex = GetSelectedPaintIndex();
			bool num = instanceID != _paintLastCarId || selectedPaintIndex != _paintLastIndex;
			float unscaledTime = Time.unscaledTime;
			bool flag = num;
			if (!flag && (!_paintNextTailgateRescanTimeByCarId.TryGetValue(instanceID, out var value) || unscaledTime >= value))
			{
				flag = true;
			}
			if (!num && !flag)
			{
				return;
			}
			_paintLastCarId = instanceID;
			_paintLastIndex = selectedPaintIndex;
			_paintNextTailgateRescanTimeByCarId[instanceID] = unscaledTime + 1f;
			try
			{
				Headlights headlights = car.headlights;
				if ((Object)(object)headlights == (Object)null)
				{
					return;
				}
				EnsureHeadlightsRefs(headlights);
				GameObject val = (GameObject)((_headlightsModelField != null) ? /*isinst with value type is only supported in some contexts*/: null);
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				MeshRenderer component = val.GetComponent<MeshRenderer>();
				if ((Object)(object)component == (Object)null)
				{
					return;
				}
				Material material = ((Renderer)component).material;
				if ((Object)(object)material == (Object)null)
				{
					return;
				}
				if (!_paintDefaultsByCarId.ContainsKey(instanceID))
				{
					PaintDefaults value2 = default(PaintDefaults);
					try
					{
						if (material.HasProperty("_BaseMap"))
						{
							value2.baseMap = material.GetTexture("_BaseMap");
						}
					}
					catch
					{
					}
					try
					{
						if (material.HasProperty("_MainTex"))
						{
							value2.mainTex = material.GetTexture("_MainTex");
						}
					}
					catch
					{
					}
					_paintDefaultsByCarId[instanceID] = value2;
				}
				bool flag2 = false;
				Texture texture;
				if (selectedPaintIndex < 0)
				{
					if (_paintDefaultsByCarId.TryGetValue(instanceID, out var value3))
					{
						try
						{
							if (material.HasProperty("_BaseMap"))
							{
								material.SetTexture("_BaseMap", value3.baseMap);
							}
						}
						catch
						{
						}
						try
						{
							if (material.HasProperty("_MainTex"))
							{
								material.SetTexture("_MainTex", value3.mainTex);
							}
						}
						catch
						{
						}
						flag2 = true;
					}
				}
				else if (TryGetPaintCosmeticTexture(selectedPaintIndex, out texture) && (Object)(object)texture != (Object)null)
				{
					try
					{
						if (material.HasProperty("_BaseMap"))
						{
							material.SetTexture("_BaseMap", texture);
						}
					}
					catch
					{
					}
					try
					{
						if (material.HasProperty("_MainTex"))
						{
							material.SetTexture("_MainTex", texture);
						}
					}
					catch
					{
					}
					flag2 = true;
				}
				if (!flag2)
				{
					string name = ((selectedPaintIndex < 0) ? "truck_texture" : null);
					if (selectedPaintIndex >= 0 && !TryGetPaintCosmeticName(selectedPaintIndex, out name))
					{
						return;
					}
					Material val2 = FindMaterialByName(name);
					if ((Object)(object)val2 == (Object)null)
					{
						string text = DeriveTruckPaintMaterialName(name);
						val2 = FindMaterialByName(text);
						if ((Object)(object)val2 == (Object)null && string.Equals(text, "truck_texture", StringComparison.OrdinalIgnoreCase))
						{
							val2 = FindMaterialByName("truck_texture_white");
						}
						if ((Object)(object)val2 == (Object)null)
						{
							LogDebug("Paint material not found: " + name + " (derived=" + text + ")");
							return;
						}
					}
					((Renderer)component).material = val2;
					material = ((Renderer)component).material;
				}
				try
				{
					_headlightsCarMatField?.SetValue(headlights, material);
				}
				catch
				{
				}
				if (flag)
				{
					ApplyTailgatePaintMaterialIfPresent(car, material);
				}
				EnsureCarDamageRefs();
				if (!(_carDamageCarMatField != null))
				{
					return;
				}
				CarDamage componentInChildren = ((Component)car).GetComponentInChildren<CarDamage>(true);
				if (!((Object)(object)componentInChildren != (Object)null))
				{
					return;
				}
				try
				{
					_carDamageCarMatField.SetValue(componentInChildren, material);
				}
				catch
				{
				}
			}
			catch
			{
			}
		}

		private static void MuteRadioProximityIfIgnitionOff(sRadioSystem radio)
		{
			if ((Object)(object)radio == (Object)null || (Object)(object)radio.car == (Object)null || !radio.car.GuyActive || !GetIgnitionFeatureEnabled() || GetIgnitionEnabledEffective())
			{
				return;
			}
			EnsureRadioRefs();
			try
			{
				_radioTargetVolumeField?.SetValue(radio, 0f);
				_radioRadioVolumeField?.SetValue(radio, 0f);
				Component val = (Component)((_radioSourceField != null) ? /*isinst with value type is only supported in some contexts*/: null);
				if ((Object)(object)val != (Object)null)
				{
					SetProp(val, "volume", 0f);
				}
				Component val2 = (Component)((_radioNoiseField != null) ? /*isinst with value type is only supported in some contexts*/: null);
				if ((Object)(object)val2 != (Object)null)
				{
					SetProp(val2, "volume", 0f);
				}
			}
			catch
			{
			}
		}

		private static bool IsTruckCar(sCarController car)
		{
			if ((Object)(object)car == (Object)null)
			{
				return false;
			}
			int instanceID;
			try
			{
				instanceID = ((Object)car).GetInstanceID();
			}
			catch
			{
				return false;
			}
			if (_isTruckCarById.TryGetValue(instanceID, out var value))
			{
				return value;
			}
			try
			{
				bool flag = (Object)(object)((Component)car).GetComponentInChildren<sTruckSFX>(true) != (Object)null;
				_isTruckCarById[instanceID] = flag;
				return flag;
			}
			catch
			{
				_isTruckCarById[instanceID] = false;
				return false;
			}
		}

		private static bool GetTruckBraking(sCarController car)
		{
			if ((Object)(object)car == (Object)null)
			{
				return false;
			}
			int instanceID = ((Object)car).GetInstanceID();
			if (_truckBraking.TryGetValue(instanceID, out var value))
			{
				return value;
			}
			return false;
		}

		private static void SetTruckBraking(sCarController car, bool braking)
		{
			if (!((Object)(object)car == (Object)null))
			{
				_truckBraking[((Object)car).GetInstanceID()] = braking;
			}
		}

		private static void ApplyTruckEmissionMap(sCarController car)
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)car == (Object)null || !GetIgnitionEnabledEffective() || !IsTruckCar(car))
			{
				return;
			}
			Headlights headlights = car.headlights;
			if ((Object)(object)headlights == (Object)null)
			{
				return;
			}
			EnsureHeadlightsRefs(headlights);
			Material val = (Material)((_headlightsCarMatField != null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			bool truckBraking = GetTruckBraking(car);
			IndicatorMode indicatorMode = ((_backupAlarmHazardsActive && GetBackupAlarmHazardsEnabled()) ? IndicatorMode.Hazards : _indicatorMode);
			bool blinkOn = indicatorMode != IndicatorMode.Off && _indicatorBlinkOn;
			Texture2D turnSignalEmissive = GetTurnSignalEmissive(truckBraking, (int)indicatorMode, blinkOn);
			if (!((Object)(object)turnSignalEmissive != (Object)null))
			{
				return;
			}
			val.SetTexture("_EmissionMap", (Texture)(object)turnSignalEmissive);
			try
			{
				if (val.HasProperty("_EmissionColor"))
				{
					val.SetColor("_EmissionColor", Color.white);
				}
			}
			catch
			{
			}
		}

		private static bool TryComputeModelBoundsInCarLocal(sCarController car, out Vector3 min, out Vector3 max)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: 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_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: 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_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0139: 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_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			min = Vector3.zero;
			max = Vector3.zero;
			if ((Object)(object)car == (Object)null)
			{
				return false;
			}
			Headlights headlights = car.headlights;
			if ((Object)(object)headlights == (Object)null)
			{
				return false;
			}
			EnsureHeadlightsRefs(headlights);
			GameObject val = (GameObject)((_headlightsModelField != null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			bool any = false;
			Vector3 vMin = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
			Vector3 vMax = new Vector3(float.MinValue, float.MinValue, float.MinValue);
			try
			{
				MeshFilter[] componentsInChildren = val.GetComponentsInChildren<MeshFilter>(true);
				if (componentsInChildren != null)
				{
					foreach (MeshFilter val2 in componentsInChildren)
					{
						if ((Object)(object)val2 == (Object)null || (Object)(object)val2.sharedMesh == (Object)null)
						{
							continue;
						}
						Bounds bounds = val2.sharedMesh.bounds;
						Vector3 center = ((Bounds)(ref bounds)).center;
						Vector3 extents = ((Bounds)(ref bounds)).extents;
						Transform transform = ((Component)val2).transform;
						for (int j = -1; j <= 1; j += 2)
						{
							for (int k = -1; k <= 1; k += 2)
							{
								for (int l = -1; l <= 1; l += 2)
								{
									Vector3 val3 = center + new Vector3(extents.x * (float)j, extents.y * (float)k, extents.z * (float)l);
									Vector3 val4 = transform.TransformPoint(val3);
									AddPoint(((Component)car).transform.InverseTransformPoint(val4));
								}
							}
						}
					}
				}
			}
			catch
			{
			}
			if (!any)
			{
				try
				{
					Renderer[] componentsInChildren2 = val.GetComponentsInChildren<Renderer>(true);
					if (componentsInChildren2 != null)
					{
						foreach (Renderer val5 in componentsInChildren2)
						{
							if ((Object)(object)val5 == (Object)null)
							{
								continue;
							}
							Bounds bounds2 = val5.bounds;
							Vector3 center2 = ((Bounds)(ref bounds2)).center;
							Vector3 extents2 = ((Bounds)(ref bounds2)).extents;
							for (int n = -1; n <= 1; n += 2)
							{
								for (int num = -1; num <= 1; num += 2)
								{
									for (int num2 = -1; num2 <= 1; num2 += 2)
									{
										Vector3 val6 = center2 + new Vector3(extents2.x * (float)n, extents2.y * (float)num, extents2.z * (float)num2);
										AddPoint(((Component)car).transform.InverseTransformPoint(val6));
									}
								}
							}
						}
					}
				}
				catch
				{
				}
			}
			if (!any)
			{
				return false;
			}
			min = vMin;
			max = vMax;
			return true;
			void AddPoint(Vector3 p)
			{
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				if (!any)
				{
					any = true;
					vMin = p;
					vMax = p;
				}
				else
				{
					vMin = Vector3.Min(vMin, p);
					vMax = Vector3.Max(vMax, p);
				}
			}
		}

		private static void EnsureTurnSignalLightRig(sCarController car)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)car == (Object)null)
			{
				return;
			}
			int instanceID = ((Object)car).GetInstanceID();
			if (_turnSignalLightRigs.TryGetValue(instanceID, out var value) && value != null && (Object)(object)value.Root != (Object)null)
			{
				if ((Object)(object)value.Root.transform.parent != (Object)(object)((Component)car).transform)
				{
					value.Root.transform.SetParent(((Component)car).transform, false);
				}
				return;
			}
			value = new TurnSignalLightRig();
			_turnSignalLightRigs[instanceID] = value;
			GameObject root = new GameObject("SebTruck_TurnSignalLights");
			((Object)root).hideFlags = (HideFlags)61;
			root.transform.SetParent(((Component)car).transform, false);
			root.transform.localPosition = Vector3.zero;
			value.Root = root;
			value.FL = NewLight("FL");
			value.FR = NewLight("FR");
			value.RL = NewLight("RL");
			value.RR = NewLight("RR");
			value.BaseComputed = false;
			Light NewLight(string name)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: 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_002b: 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)
				GameObject val = new GameObject(name)
				{
					hideFlags = (HideFlags)61
				};
				val.transform.SetParent(root.transform, false);
				val.transform.localPosition = Vector3.zero;
				Light obj = val.AddComponent<Light>();
				obj.type = (LightType)0;
				obj.shadows = (LightShadows)0;
				obj.color = new Color(1f, 0.55f, 0.12f);
				obj.spotAngle = 95f;
				obj.innerSpotAngle