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.6")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.1.6.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 { [BepInPlugin("shibe.easydeliveryco.sebtruck", "SebTruck", "1.1.6")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { internal enum SpeedUnit { Kmh, Mph } internal enum HudReadoutAnchor { BottomLeft, BottomRight } internal enum HudStyle { Classic, Rally } private enum IndicatorMode { Off, Left, Right, Hazards } private sealed class IndicatorCache { public readonly List Left = new List(); public readonly List Right = new List(); public readonly Dictionary Defaults = new Dictionary(); public readonly List LeftMats = new List(); public readonly List RightMats = new List(); public readonly Dictionary MatDefaults = new Dictionary(); } 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 Lights = new List(); public readonly Dictionary Defaults = new Dictionary(); public readonly List Flares = new List(); public readonly Dictionary FlareDefaults = new Dictionary(); } 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 Lights = new List(16); public float NextRescanTime; } [HarmonyPatch] private static class Headlights_Toggle_Patch { private static IEnumerable 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(); if (!((Object)(object)componentInParent == (Object)null)) { ApplyHeadlightTuning(componentInParent); } } } catch { } } } [HarmonyPatch] private static class Headlights_Break_Patch { private static IEnumerable 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 PrefKeyHudReadoutAnchor = "SebTruck_HudReadoutAnchor"; internal const string PrefKeyHudSpeedAnchor = "SebTruck_HudSpeedAnchor"; internal const string PrefKeyHudTachAnchor = "SebTruck_HudTachAnchor"; internal const string PrefKeyHudGearAnchor = "SebTruck_HudGearAnchor"; 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 _tmpIntList = new List(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.6"; internal static ManualLogSource Log; private static ConfigEntry _debugLogging; private static ConfigEntry _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; 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 BindingScheme[] _bindingSchemes = (BindingScheme[])(object)new BindingScheme[3] { default(BindingScheme), (BindingScheme)1, (BindingScheme)2 }; private static readonly Dictionary _indicatorCaches = new Dictionary(); private static readonly Dictionary _truckBraking = new Dictionary(); private static readonly Dictionary _isTruckCarById = new Dictionary(); private static readonly Dictionary _turnSignalLightRigs = new Dictionary(); private static readonly Dictionary _tailLightCaches = new Dictionary(); private static readonly Dictionary _carScaleDefaults = new Dictionary(); private static readonly Dictionary _storyHandlingDefaults = new Dictionary(); private static readonly Dictionary _rallyHandlingDefaults = new Dictionary(); private static readonly Dictionary _lightDefaults = new Dictionary(); private static readonly Dictionary _visualScaleDefaults = new Dictionary(); 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 _enginePitchMulApplied = new Dictionary(); 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 _paintMaterialCache = new Dictionary(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary _paintDefaultsByCarId = new Dictionary(); private static readonly Dictionary _paintNextTailgateRescanTimeByCarId = new Dictionary(); private static FieldInfo _carDamageCarMatField; private static int _paintLastCarId; private static int _paintLastIndex = int.MinValue; private static bool _rallyManualCheatTogglePending; private static readonly Dictionary _headlightTuningCaches = new Dictionary(); private static readonly HashSet _tmpHeadlightLightIds = new HashSet(); 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(); 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(); if ((Object)(object)info != (Object)null) { return true; } } catch { } try { sCosmeticInfo[] array = Resources.FindObjectsOfTypeAll(); 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(); 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() != (Object)null; return _rallyModeCached; } private static sRallyDriving GetCurrentRallyDriving() { try { sEasyRally val = Object.FindFirstObjectByType(); if ((Object)(object)val != (Object)null && (Object)(object)val.currentCar != (Object)null) { return val.currentCar; } return Object.FindFirstObjectByType(); } catch { return null; } } internal static string GetCurrentRallyVariantLabel() { try { sUpgradeSync val = Object.FindFirstObjectByType(); 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", 0) != 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, 1); } internal static void SetHudStyle(HudStyle style) { PlayerPrefs.SetInt("SebTruck_HudStyle", (int)style); } internal static HudStyle NextHudStyle(HudStyle style) { if (style != HudStyle.Classic) { return HudStyle.Classic; } return HudStyle.Rally; } internal static string GetHudStyleLabel(HudStyle style) { if (style != HudStyle.Rally) { return "Classic"; } return "Rally"; } 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 HudReadoutAnchor GetHudReadoutAnchor() { return (HudReadoutAnchor)Mathf.Clamp(PlayerPrefs.GetInt("SebTruck_HudReadoutAnchor", 0), 0, 1); } internal static void SetHudReadoutAnchor(HudReadoutAnchor anchor) { PlayerPrefs.SetInt("SebTruck_HudReadoutAnchor", (int)anchor); } internal static HudReadoutAnchor NextHudReadoutAnchor(HudReadoutAnchor anchor) { if (anchor != HudReadoutAnchor.BottomLeft) { return HudReadoutAnchor.BottomLeft; } return HudReadoutAnchor.BottomRight; } internal static string GetHudReadoutAnchorLabel(HudReadoutAnchor anchor) { if (anchor != HudReadoutAnchor.BottomRight) { return "Bottom Left"; } return "Bottom Right"; } internal static HudReadoutAnchor GetHudSpeedAnchor() { if (!PlayerPrefs.HasKey("SebTruck_HudSpeedAnchor")) { return GetHudReadoutAnchor(); } return (HudReadoutAnchor)Mathf.Clamp(PlayerPrefs.GetInt("SebTruck_HudSpeedAnchor", (int)GetHudReadoutAnchor()), 0, 1); } internal static void SetHudSpeedAnchor(HudReadoutAnchor anchor) { PlayerPrefs.SetInt("SebTruck_HudSpeedAnchor", (int)anchor); } internal static HudReadoutAnchor GetHudTachAnchor() { if (!PlayerPrefs.HasKey("SebTruck_HudTachAnchor")) { return GetHudReadoutAnchor(); } return (HudReadoutAnchor)Mathf.Clamp(PlayerPrefs.GetInt("SebTruck_HudTachAnchor", (int)GetHudReadoutAnchor()), 0, 1); } internal static void SetHudTachAnchor(HudReadoutAnchor anchor) { PlayerPrefs.SetInt("SebTruck_HudTachAnchor", (int)anchor); } internal static HudReadoutAnchor GetHudGearAnchor() { if (!PlayerPrefs.HasKey("SebTruck_HudGearAnchor")) { return GetHudReadoutAnchor(); } return (HudReadoutAnchor)Mathf.Clamp(PlayerPrefs.GetInt("SebTruck_HudGearAnchor", (int)GetHudReadoutAnchor()), 0, 1); } internal static void SetHudGearAnchor(HudReadoutAnchor anchor) { PlayerPrefs.SetInt("SebTruck_HudGearAnchor", (int)anchor); } 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() { 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() { 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.Classic); SetHudShowSpeed(enabled: false); SetHudShowTach(enabled: true); SetHudShowGear(enabled: true); SetRallyHudSpeedUnit(SpeedUnit.Kmh); SetHudReadoutAnchor(HudReadoutAnchor.BottomLeft); PlayerPrefs.DeleteKey("SebTruck_HudSpeedAnchor"); PlayerPrefs.DeleteKey("SebTruck_HudTachAnchor"); PlayerPrefs.DeleteKey("SebTruck_HudGearAnchor"); 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("Debug", "debug_logging", false, "Log debug information (verbose)."); _ignitionSfxOnPath = ((BaseUnityPlugin)this).Config.Bind("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 { byte[] array = File.ReadAllBytes(path); if (array.Length < 44) { throw new Exception("WAV too small"); } if (Encoding.ASCII.GetString(array, 0, 4) != "RIFF" || Encoding.ASCII.GetString(array, 8, 4) != "WAVE") { throw new Exception("Not a RIFF/WAVE file"); } int num = BitConverter.ToInt16(array, 22); int sampleRate = BitConverter.ToInt32(array, 24); int num2 = BitConverter.ToInt16(array, 34); if (num2 != 16) { throw new Exception("Unsupported bit depth: " + num2); } int num3 = 12; int num4 = -1; int num5 = 0; while (num3 + 8 <= array.Length) { string text = Encoding.ASCII.GetString(array, num3, 4); int num6 = BitConverter.ToInt32(array, num3 + 4); int num7 = num3 + 8; if (num7 + num6 > array.Length) { break; } if (text == "data") { num4 = num7; num5 = num6; break; } num3 = num7 + num6; if ((num3 & 1) == 1) { num3++; } } if (num4 < 0 || num5 <= 0) { throw new Exception("Missing data chunk"); } int num8 = num5 / 2; float[] array2 = new float[num8]; int num9 = 0; for (int i = 0; i + 1 < num5; i += 2) { short num10 = BitConverter.ToInt16(array, num4 + i); array2[num9++] = (float)num10 / 32768f; } return CreateAudioClip("ignition_on", num8 / Math.Max(1, num), num, sampleRate, array2); } 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 { } } 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(); 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(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(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(); 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(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(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(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(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(); obj.type = (LightType)0; obj.shadows = (LightShadows)0; obj.color = new Color(1f, 0.55f, 0.12f); obj.spotAngle = 95f; obj.innerSpotAngle = 45f; ((Behaviour)obj).enabled = false; return obj; } } private static void ApplyTurnSignalLightParams(TurnSignalLightRig rig) { if (rig != null) { ApplyFront(rig.FL, -20f); ApplyFront(rig.FR, 20f); ApplyRear(rig.RL, 175f); ApplyRear(rig.RR, 185f); } static void ApplyFront(Light l, float y) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)l == (Object)null)) { l.spotAngle = 110f; l.innerSpotAngle = 15f; ((Component)l).transform.localRotation = Quaternion.Euler(45f, y, 0f); } } static void ApplyRear(Light l, float y) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)l == (Object)null)) { l.spotAngle = 145f; l.innerSpotAngle = 30f; ((Component)l).transform.localRotation = Quaternion.Euler(30f, y, 0f); } } } private static void EnsureTurnSignalLightBasePositions(sCarController car) { //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_011e: 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_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)car == (Object)null) { return; } int instanceID = ((Object)car).GetInstanceID(); if (_turnSignalLightRigs.TryGetValue(instanceID, out var value) && value != null && !value.BaseComputed) { if (TryComputeModelBoundsInCarLocal(car, out var min, out var max)) { float num = 0.08f; float num2 = 0.12f; float num3 = min.x - num; float num4 = max.x + num; float num5 = max.z + num2; float num6 = min.z - num2; float num7 = Mathf.Lerp(min.y, max.y, 0.42f); value.BaseFL = new Vector3(num3, num7, num5); value.BaseFR = new Vector3(num4, num7, num5); value.BaseRL = new Vector3(num3, num7, num6); value.BaseRR = new Vector3(num4, num7, num6); value.BaseComputed = true; } else { value.BaseFL = new Vector3(-0.75f, 0.55f, 1.45f); value.BaseFR = new Vector3(0.75f, 0.55f, 1.45f); value.BaseRL = new Vector3(-0.8f, 0.55f, -1.55f); value.BaseRR = new Vector3(0.8f, 0.55f, -1.55f); value.BaseComputed = true; } } } private static void SetLightOn(Light l, bool on, float intensity, float range) { if (!((Object)(object)l == (Object)null)) { l.range = range; l.intensity = intensity; ((Behaviour)l).enabled = on && intensity > 0.0001f && range > 0.0001f; } } private static void UpdateTurnSignalWorldLights(sCarController car, bool leftOn, bool rightOn, bool forceOff) { //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011e: 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_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_012d: 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_0148: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)car == (Object)null || !IsTruckCar(car)) { return; } if (forceOff || !GetIgnitionEnabledEffective()) { int instanceID = ((Object)car).GetInstanceID(); if (_turnSignalLightRigs.TryGetValue(instanceID, out var value) && value != null) { SetLightOn(value.FL, on: false, 0f, 0f); SetLightOn(value.FR, on: false, 0f, 0f); SetLightOn(value.RL, on: false, 0f, 0f); SetLightOn(value.RR, on: false, 0f, 0f); } return; } EnsureTurnSignalLightRig(car); EnsureTurnSignalLightBasePositions(car); int instanceID2 = ((Object)car).GetInstanceID(); if (_turnSignalLightRigs.TryGetValue(instanceID2, out var value2) && value2 != null) { float turnSignalLightIntensity = GetTurnSignalLightIntensity(); float num = 0f; Vector3 turnSignalLightFrontOffset = TurnSignalLightFrontOffset; Vector3 turnSignalLightRearOffset = TurnSignalLightRearOffset; ApplyTurnSignalLightParams(value2); Vector3 localPosition = value2.BaseFL + turnSignalLightFrontOffset + new Vector3(0f - num, 0f, 0f); Vector3 localPosition2 = value2.BaseFR + turnSignalLightFrontOffset + new Vector3(num, 0f, 0f); Vector3 localPosition3 = value2.BaseRL + turnSignalLightRearOffset + new Vector3(0f - num, 0f, 0f); Vector3 localPosition4 = value2.BaseRR + turnSignalLightRearOffset + new Vector3(num, 0f, 0f); if ((Object)(object)value2.FL != (Object)null) { ((Component)value2.FL).transform.localPosition = localPosition; } if ((Object)(object)value2.FR != (Object)null) { ((Component)value2.FR).transform.localPosition = localPosition2; } if ((Object)(object)value2.RL != (Object)null) { ((Component)value2.RL).transform.localPosition = localPosition3; } if ((Object)(object)value2.RR != (Object)null) { ((Component)value2.RR).transform.localPosition = localPosition4; } SetLightOn(value2.FL, leftOn, turnSignalLightIntensity, 6f); SetLightOn(value2.RL, leftOn, turnSignalLightIntensity, 6f); SetLightOn(value2.FR, rightOn, turnSignalLightIntensity, 6f); SetLightOn(value2.RR, rightOn, turnSignalLightIntensity, 6f); } } private static void UpdateIndicatorAutoCancel(float steerX) { if (_indicatorMode != IndicatorMode.Left && _indicatorMode != IndicatorMode.Right) { _indicatorCancelArmed = false; _indicatorCancelArmedForMode = _indicatorMode; return; } if (_indicatorCancelArmedForMode != _indicatorMode) { _indicatorCancelArmedForMode = _indicatorMode; _indicatorCancelArmed = false; } if (!_indicatorCancelArmed) { if (_indicatorMode == IndicatorMode.Left && steerX <= -0.35f) { _indicatorCancelArmed = true; } else if (_indicatorMode == IndicatorMode.Right && steerX >= 0.35f) { _indicatorCancelArmed = true; } } else if (Mathf.Abs(steerX) <= 0.12f) { _indicatorMode = IndicatorMode.Off; _indicatorBlinkOn = false; _indicatorNextBlinkTime = 0f; _indicatorCancelArmed = false; } } private static Texture2D GetIgnitionBlackEmissionTex() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_ignitionBlackEmissiveTex != (Object)null) { return _ignitionBlackEmissiveTex; } _ignitionBlackEmissiveTex = new Texture2D(2, 2, (TextureFormat)4, false); _ignitionBlackEmissiveTex.SetPixels((Color[])(object)new Color[4] { Color.black, Color.black, Color.black, Color.black }); _ignitionBlackEmissiveTex.Apply(false, true); ((Object)_ignitionBlackEmissiveTex).hideFlags = (HideFlags)61; return _ignitionBlackEmissiveTex; } private static void ForceVehicleLightsOff(sCarController car) { //IL_00b4: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)car == (Object)null) { return; } Headlights headlights = car.headlights; if ((Object)(object)headlights == (Object)null) { return; } EnsureHeadlightsRefs(headlights); GameObject val = (GameObject)((_headlightsHeadLightsField != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val != (Object)null && val.activeSelf) { val.SetActive(false); } try { headlights.headlightsOn = false; } catch { } Material val2 = (Material)((_headlightsCarMatField != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val2 != (Object)null) { val2.SetTexture("_EmissionMap", (Texture)(object)GetIgnitionBlackEmissionTex()); if (val2.HasProperty("_EmissionColor")) { val2.SetColor("_EmissionColor", Color.black); } } ForceTailLightsOff(car); SetIndicators(car, IndicatorMode.Off, blinkOn: false, forceOff: true); } private static void ForceTailLightsOff(sCarController car) { if ((Object)(object)car == (Object)null) { return; } TailLightCache tailLightCache = GetTailLightCache(car); for (int i = 0; i < tailLightCache.Lights.Count; i++) { Light val = tailLightCache.Lights[i]; if (!((Object)(object)val == (Object)null)) { int instanceID = ((Object)val).GetInstanceID(); if (!tailLightCache.Defaults.ContainsKey(instanceID)) { tailLightCache.Defaults[instanceID] = (val.intensity, ((Behaviour)val).enabled); } val.intensity = 0f; ((Behaviour)val).enabled = false; } } for (int j = 0; j < tailLightCache.Flares.Count; j++) { Component val2 = tailLightCache.Flares[j]; if ((Object)(object)val2 == (Object)null) { continue; } int instanceID2 = ((Object)val2).GetInstanceID(); if (!tailLightCache.FlareDefaults.ContainsKey(instanceID2)) { float item = 0f; bool item2 = true; try { PropertyInfo property = ((object)val2).GetType().GetProperty("intensity"); if (property != null) { item = (float)property.GetValue(val2, null); } } catch { } try { PropertyInfo property2 = ((object)val2).GetType().GetProperty("enabled"); if (property2 != null) { item2 = (bool)property2.GetValue(val2, null); } } catch { } tailLightCache.FlareDefaults[instanceID2] = (item, item2); } try { SetProp(val2, "intensity", 0f); } catch { } try { SetProp(val2, "enabled", false); } catch { } } } private static void RestoreTailLights(sCarController car) { if ((Object)(object)car == (Object)null) { return; } int instanceID = ((Object)car).GetInstanceID(); if (!_tailLightCaches.TryGetValue(instanceID, out var value) || value == null) { return; } for (int i = 0; i < value.Lights.Count; i++) { Light val = value.Lights[i]; if (!((Object)(object)val == (Object)null)) { int instanceID2 = ((Object)val).GetInstanceID(); if (value.Defaults.TryGetValue(instanceID2, out (float, bool) value2)) { ((Behaviour)val).enabled = value2.Item2; val.intensity = value2.Item1; } } } for (int j = 0; j < value.Flares.Count; j++) { Component val2 = value.Flares[j]; if ((Object)(object)val2 == (Object)null) { continue; } int instanceID3 = ((Object)val2).GetInstanceID(); if (value.FlareDefaults.TryGetValue(instanceID3, out (float, bool) value3)) { try { SetProp(val2, "enabled", value3.Item2); } catch { } try { SetProp(val2, "intensity", value3.Item1); } catch { } } } } private static TailLightCache GetTailLightCache(sCarController car) { //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) int instanceID = ((Object)car).GetInstanceID(); if (_tailLightCaches.TryGetValue(instanceID, out var value) && value != null) { return value; } TailLightCache tailLightCache = new TailLightCache(); _tailLightCaches[instanceID] = tailLightCache; GameObject val = null; try { Headlights headlights = car.headlights; if ((Object)(object)headlights != (Object)null) { EnsureHeadlightsRefs(headlights); val = (GameObject)((_headlightsHeadLightsField != null) ? /*isinst with value type is only supported in some contexts*/: null); } } catch { val = null; } Light[] array; try { array = ((Component)car).GetComponentsInChildren(true); } catch { array = null; } if (array == null) { return tailLightCache; } foreach (Light val2 in array) { if (!((Object)(object)val2 == (Object)null) && (!((Object)(object)val != (Object)null) || !((Object)(object)((Component)val2).transform != (Object)null) || !((Component)val2).transform.IsChildOf(val.transform))) { string text = ((Object)val2).name ?? string.Empty; bool flag = text.IndexOf("tail", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("brake", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("rear", StringComparison.OrdinalIgnoreCase) >= 0; bool flag2 = val2.color.r > 0.7f && val2.color.g < 0.45f && val2.color.b < 0.45f; bool flag3 = false; try { flag3 = ((Component)car).transform.InverseTransformPoint(((Component)val2).transform.position).z < -0.2f; } catch { flag3 = false; } if ((flag || (flag2 && flag3)) && !tailLightCache.Lights.Contains(val2)) { tailLightCache.Lights.Add(val2); } } } try { Component[] componentsInChildren = ((Component)car).GetComponentsInChildren(true); if (componentsInChildren != null) { foreach (Component val3 in componentsInChildren) { if ((Object)(object)val3 == (Object)null) { continue; } string name = ((object)val3).GetType().Name; if (name == null || name.IndexOf("LensFlareComponentSRP", StringComparison.OrdinalIgnoreCase) < 0) { continue; } bool flag4 = false; try { flag4 = ((Component)car).transform.InverseTransformPoint(val3.transform.position).z < -0.2f; } catch { flag4 = false; } if (flag4) { string text2 = ((Object)val3).name ?? string.Empty; if ((text2.IndexOf("tail", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("rear", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("brake", StringComparison.OrdinalIgnoreCase) >= 0) && !tailLightCache.Flares.Contains(val3)) { tailLightCache.Flares.Add(val3); } } } } } catch { } return tailLightCache; } private static IndicatorCache GetIndicatorCache(sCarController car) { //IL_04a9: Unknown result type (might be due to invalid IL or missing references) //IL_0616: Unknown result type (might be due to invalid IL or missing references) //IL_0618: Unknown result type (might be due to invalid IL or missing references) //IL_04b7: Unknown result type (might be due to invalid IL or missing references) //IL_04c5: Unknown result type (might be due to invalid IL or missing references) //IL_05ee: Unknown result type (might be due to invalid IL or missing references) //IL_05f3: Unknown result type (might be due to invalid IL or missing references) //IL_049a: Unknown result type (might be due to invalid IL or missing references) //IL_049f: Unknown result type (might be due to invalid IL or missing references) //IL_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0452: Unknown result type (might be due to invalid IL or missing references) //IL_0457: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0471: Unknown result type (might be due to invalid IL or missing references) //IL_0476: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_05a6: Unknown result type (might be due to invalid IL or missing references) //IL_05ab: Unknown result type (might be due to invalid IL or missing references) //IL_05ad: Unknown result type (might be due to invalid IL or missing references) //IL_05b2: Unknown result type (might be due to invalid IL or missing references) //IL_05cc: Unknown result type (might be due to invalid IL or missing references) //IL_05d1: Unknown result type (might be due to invalid IL or missing references) int instanceID = ((Object)car).GetInstanceID(); if (_indicatorCaches.TryGetValue(instanceID, out var value) && value != null) { return value; } IndicatorCache indicatorCache = new IndicatorCache(); _indicatorCaches[instanceID] = indicatorCache; GameObject val = null; try { Headlights headlights = car.headlights; if ((Object)(object)headlights != (Object)null) { EnsureHeadlightsRefs(headlights); val = (GameObject)((_headlightsHeadLightsField != null) ? /*isinst with value type is only supported in some contexts*/: null); } } catch { val = null; } Light[] array; try { array = ((Component)car).GetComponentsInChildren(true); } catch { array = null; } if (array != null) { foreach (Light val2 in array) { if ((Object)(object)val2 == (Object)null || ((Object)(object)val != (Object)null && (Object)(object)((Component)val2).transform != (Object)null && ((Component)val2).transform.IsChildOf(val.transform))) { continue; } string text = ((Object)val2).name ?? string.Empty; bool flag = text.IndexOf("indicator", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("blinker", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("turn", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("signal", StringComparison.OrdinalIgnoreCase) >= 0; bool flag2 = val2.color.r > 0.7f && val2.color.g > 0.25f && val2.color.b < 0.35f; bool flag3 = false; float num = 0f; try { Vector3 val3 = ((Component)car).transform.InverseTransformPoint(((Component)val2).transform.position); num = val3.x; flag3 = val3.z > 0.2f; } catch { flag3 = false; } if (flag || (flag2 && flag3)) { bool flag4 = text.IndexOf("left", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("_l", StringComparison.OrdinalIgnoreCase) >= 0; bool flag5 = text.IndexOf("right", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("_r", StringComparison.OrdinalIgnoreCase) >= 0; if (!flag4 && !flag5) { flag4 = num < 0f; flag5 = !flag4; } if (flag4 && !indicatorCache.Left.Contains(val2)) { indicatorCache.Left.Add(val2); } if (flag5 && !indicatorCache.Right.Contains(val2)) { indicatorCache.Right.Add(val2); } } } } try { Renderer[] componentsInChildren = ((Component)car).GetComponentsInChildren(true); if (componentsInChildren != null) { foreach (Renderer val4 in componentsInChildren) { if ((Object)(object)val4 == (Object)null) { continue; } float num2 = 0f; float num3 = 0f; try { Vector3 val5 = ((Component)car).transform.InverseTransformPoint(((Component)val4).transform.position); num2 = val5.x; num3 = val5.z; } catch { num3 = 0f; } if (num3 < -0.35f) { continue; } string text2 = ((Object)val4).name ?? string.Empty; bool flag6 = text2.IndexOf("indicator", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("blinker", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("blink", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("turn", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("signal", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("lamp", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("light", StringComparison.OrdinalIgnoreCase) >= 0; Material[] array2 = null; try { array2 = val4.materials; } catch { array2 = null; } if (array2 == null || array2.Length == 0) { continue; } foreach (Material val6 in array2) { if ((Object)(object)val6 == (Object)null || !val6.HasProperty("_EmissionColor")) { continue; } string text3 = ((Object)val6).name ?? string.Empty; bool flag7 = text3.IndexOf("indicator", StringComparison.OrdinalIgnoreCase) >= 0 || text3.IndexOf("blinker", StringComparison.OrdinalIgnoreCase) >= 0 || text3.IndexOf("blink", StringComparison.OrdinalIgnoreCase) >= 0 || text3.IndexOf("turn", StringComparison.OrdinalIgnoreCase) >= 0 || text3.IndexOf("signal", StringComparison.OrdinalIgnoreCase) >= 0 || text3.IndexOf("lamp", StringComparison.OrdinalIgnoreCase) >= 0 || text3.IndexOf("light", StringComparison.OrdinalIgnoreCase) >= 0; Color val7 = Color.white; bool flag8 = false; try { if (val6.HasProperty("_BaseColor")) { val7 = val6.GetColor("_BaseColor"); flag8 = true; } } catch { } try { if (!flag8 && val6.HasProperty("_Color")) { val7 = val6.GetColor("_Color"); flag8 = true; } } catch { } if (!((val7.r > 0.7f && val7.g > 0.25f && val7.b < 0.35f) || flag6 || flag7)) { continue; } bool flag9 = text2.IndexOf("left", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("_l", StringComparison.OrdinalIgnoreCase) >= 0; bool flag10 = text2.IndexOf("right", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("_r", StringComparison.OrdinalIgnoreCase) >= 0; if (!flag9 && !flag10) { flag9 = num2 < 0f; flag10 = !flag9; } if (flag9 && !indicatorCache.LeftMats.Contains(val6)) { indicatorCache.LeftMats.Add(val6); } if (flag10 && !indicatorCache.RightMats.Contains(val6)) { indicatorCache.RightMats.Add(val6); } int instanceID2 = ((Object)val6).GetInstanceID(); if (indicatorCache.MatDefaults.ContainsKey(instanceID2)) { continue; } Color item = Color.black; Color item2 = Color.black; bool item3 = false; try { if (val6.HasProperty("_EmissionColor")) { item = val6.GetColor("_EmissionColor"); } } catch { } try { if (val6.HasProperty("_EmissiveColor")) { item2 = val6.GetColor("_EmissiveColor"); } } catch { } try { item3 = val6.IsKeywordEnabled("_EMISSION"); } catch { } indicatorCache.MatDefaults[instanceID2] = (item, item2, item3); } } } } catch { } if (_debugLogging != null && _debugLogging.Value) { LogDebug("Indicators: lights left=" + indicatorCache.Left.Count + " right=" + indicatorCache.Right.Count + " mats left=" + indicatorCache.LeftMats.Count + " right=" + indicatorCache.RightMats.Count); } return indicatorCache; } private static void SetIndicators(sCarController car, IndicatorMode mode, bool blinkOn, bool forceOff) { IndicatorCache cache; if (!((Object)(object)car == (Object)null)) { cache = GetIndicatorCache(car); bool flag = blinkOn && (mode == IndicatorMode.Left || mode == IndicatorMode.Hazards); bool flag2 = blinkOn && (mode == IndicatorMode.Right || mode == IndicatorMode.Hazards); Apply(cache.Left, flag); Apply(cache.Right, flag2); ApplyMat(cache.LeftMats, flag); ApplyMat(cache.RightMats, flag2); } void Apply(List ls, bool on) { for (int i = 0; i < ls.Count; i++) { Light val = ls[i]; if (!((Object)(object)val == (Object)null)) { int instanceID = ((Object)val).GetInstanceID(); if (!cache.Defaults.ContainsKey(instanceID)) { cache.Defaults[instanceID] = (val.intensity, ((Behaviour)val).enabled); } if (on) { (float, bool) tuple = cache.Defaults[instanceID]; ((Behaviour)val).enabled = tuple.Item2; val.intensity = tuple.Item1; } else { val.intensity = 0f; ((Behaviour)val).enabled = false; } } } } void ApplyMat(List ms, bool on) { //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < ms.Count; i++) { Material val = ms[i]; if (!((Object)(object)val == (Object)null)) { int instanceID = ((Object)val).GetInstanceID(); if (!cache.MatDefaults.TryGetValue(instanceID, out (Color, Color, bool) value)) { value = (Color.black, Color.black, false); } if (on) { var (val2, val3, _) = value; if (((Color)(ref val2)).maxColorComponent <= 0.01f && ((Color)(ref val3)).maxColorComponent <= 0.01f) { val2 = new Color(1f, 0.55f, 0.12f) * 2f; val3 = val2; } try { val.EnableKeyword("_EMISSION"); } catch { } try { if (val.HasProperty("_EmissionColor")) { val.SetColor("_EmissionColor", val2); } } catch { } try { if (val.HasProperty("_EmissiveColor")) { val.SetColor("_EmissiveColor", val3); } } catch { } } else if (forceOff) { try { val.DisableKeyword("_EMISSION"); } catch { } try { if (val.HasProperty("_EmissionColor")) { val.SetColor("_EmissionColor", Color.black); } } catch { } try { if (val.HasProperty("_EmissiveColor")) { val.SetColor("_EmissiveColor", Color.black); } } catch { } } else { try { if (!value.Item3) { val.DisableKeyword("_EMISSION"); } else { val.EnableKeyword("_EMISSION"); } } catch { } try { if (val.HasProperty("_EmissionColor")) { val.SetColor("_EmissionColor", value.Item1); } } catch { } try { if (val.HasProperty("_EmissiveColor")) { val.SetColor("_EmissiveColor", value.Item2); } } catch { } } } } } } private static void UpdateIndicators(sCarController car) { if ((Object)(object)car == (Object)null) { return; } if (!GetIndicatorFeatureEnabled()) { _backupAlarmHazardsActive = false; _indicatorMode = IndicatorMode.Off; _indicatorBlinkOn = false; _indicatorNextBlinkTime = 0f; _indicatorPauseStart = -1f; SetIndicators(car, IndicatorMode.Off, blinkOn: false, forceOff: false); ApplyTruckEmissionMap(car); UpdateTurnSignalWorldLights(car, leftOn: false, rightOn: false, forceOff: true); return; } if (!GetIgnitionEnabledEffective()) { _backupAlarmHazardsActive = false; _indicatorMode = IndicatorMode.Off; _indicatorBlinkOn = false; _indicatorNextBlinkTime = 0f; _indicatorPauseStart = -1f; SetIndicators(car, IndicatorMode.Off, blinkOn: false, forceOff: true); UpdateTurnSignalWorldLights(car, leftOn: false, rightOn: false, forceOff: true); return; } IndicatorMode indicatorMode = ((_backupAlarmHazardsActive && GetBackupAlarmHazardsEnabled()) ? IndicatorMode.Hazards : _indicatorMode); if (indicatorMode == IndicatorMode.Off) { _indicatorBlinkOn = false; _indicatorPauseStart = -1f; SetIndicators(car, IndicatorMode.Off, blinkOn: false, forceOff: false); ApplyTruckEmissionMap(car); UpdateTurnSignalWorldLights(car, leftOn: false, rightOn: false, forceOff: false); return; } if (PauseSystem.paused) { if (_indicatorPauseStart < 0f) { _indicatorPauseStart = Time.unscaledTime; } bool leftOn = _indicatorBlinkOn && (indicatorMode == IndicatorMode.Left || indicatorMode == IndicatorMode.Hazards); bool rightOn = _indicatorBlinkOn && (indicatorMode == IndicatorMode.Right || indicatorMode == IndicatorMode.Hazards); UpdateTurnSignalWorldLights(car, leftOn, rightOn, forceOff: false); return; } if (_indicatorPauseStart >= 0f) { float num = Time.unscaledTime - _indicatorPauseStart; if (_indicatorNextBlinkTime > 0f) { _indicatorNextBlinkTime += num; } _indicatorPauseStart = -1f; } bool indicatorBlinkOn = _indicatorBlinkOn; float unscaledTime = Time.unscaledTime; float indicatorBlinkSeconds = GetIndicatorBlinkSeconds(); if (_indicatorNextBlinkTime <= 0f) { _indicatorBlinkOn = true; _indicatorNextBlinkTime = unscaledTime + indicatorBlinkSeconds; } else if (unscaledTime >= _indicatorNextBlinkTime) { _indicatorBlinkOn = !_indicatorBlinkOn; _indicatorNextBlinkTime = unscaledTime + indicatorBlinkSeconds; } if (_indicatorBlinkOn != indicatorBlinkOn) { PlayIndicatorClick(car, _indicatorBlinkOn); } SetIndicators(car, indicatorMode, _indicatorBlinkOn, forceOff: false); ApplyTruckEmissionMap(car); bool leftOn2 = _indicatorBlinkOn && (indicatorMode == IndicatorMode.Left || indicatorMode == IndicatorMode.Hazards); bool rightOn2 = _indicatorBlinkOn && (indicatorMode == IndicatorMode.Right || indicatorMode == IndicatorMode.Hazards); UpdateTurnSignalWorldLights(car, leftOn2, rightOn2, forceOff: false); } private static void RestoreVehicleLightState(sCarController car, bool wantOn) { //IL_00fb: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)car == (Object)null) { return; } Headlights headlights = car.headlights; if ((Object)(object)headlights == (Object)null) { return; } EnsureHeadlightsRefs(headlights); GameObject val = (GameObject)((_headlightsHeadLightsField != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val != (Object)null) { val.SetActive(wantOn); } try { headlights.headlightsOn = wantOn; } catch { } Material val2 = (Material)((_headlightsCarMatField != null) ? /*isinst with value type is only supported in some contexts*/: null); Texture val3 = (Texture)((_headlightsEmissiveRegularField != null) ? /*isinst with value type is only supported in some contexts*/: null); if (!((Object)(object)val2 != (Object)null) || !((Object)(object)val3 != (Object)null)) { return; } Texture val4 = val3; if (IsTruckCar(car)) { Texture2D turnSignalEmissive = GetTurnSignalEmissive(GetTruckBraking(car), 0, blinkOn: false); if ((Object)(object)turnSignalEmissive != (Object)null) { val4 = (Texture)(object)turnSignalEmissive; } } val2.SetTexture("_EmissionMap", val4); if (val2.HasProperty("_EmissionColor")) { val2.SetColor("_EmissionColor", Color.white); } } private static void ApplyIgnitionStateChange(bool ignitionOn) { sCarController currentCar = _currentCar; if ((Object)(object)currentCar == (Object)null || currentCar.GuyActive) { return; } LogDebug("Ignition: " + (ignitionOn ? "ON" : "OFF")); Headlights headlights = currentCar.headlights; sRadioSystem instance = sRadioSystem.instance; bool flag = (Object)(object)instance != (Object)null && instance.car == currentCar; object obj = (flag ? GetRadioSource(instance) : null); bool flag2 = obj != null && GetBehaviourEnabled(obj); if (!ignitionOn) { _ignitionPrevHeadlightsOn = (Object)(object)headlights != (Object)null && headlights.headlightsOn; _ignitionPrevRadioOn = flag && flag2; _ignitionOffSince = Time.unscaledTime; ForceVehicleLightsOff(currentCar); if ((Object)(object)headlights != (Object)null) { try { AccessTools.Method(((object)headlights).GetType(), "PlaySound", new Type[1] { typeof(bool) }, (Type[])null)?.Invoke(headlights, new object[1] { false }); } catch { } } if (flag && flag2) { instance.ToggleRadio(); } } else { _ignitionOffSince = -1f; RestoreVehicleLightState(currentCar, _ignitionPrevHeadlightsOn); RestoreTailLights(currentCar); if (flag && _ignitionPrevRadioOn && !flag2) { instance.ToggleRadio(); } if (IsManualTransmissionEnabledEffective()) { _manualGear = 1; } } } private static void EnforceIgnitionOffForCurrentCar() { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) sCarController currentCar = _currentCar; if ((Object)(object)currentCar == (Object)null || currentCar.GuyActive) { return; } if (currentCar.player >= 0 && currentCar.player < sInputManager.players.Length) { sInputManager.players[currentCar.player].headlightsPressed = false; sInputManager.players[currentCar.player].radioPressed = false; sInputManager.players[currentCar.player].radioInput = Vector2.zero; } ForceVehicleLightsOff(currentCar); _indicatorMode = IndicatorMode.Off; _indicatorBlinkOn = false; sRadioSystem instance = sRadioSystem.instance; if ((Object)(object)instance != (Object)null && instance.car == currentCar) { object radioSource = GetRadioSource(instance); if (radioSource != null && GetBehaviourEnabled(radioSource)) { instance.ToggleRadio(); } } } private static object GetRadioSource(sRadioSystem radio) { if ((Object)(object)radio == (Object)null) { return null; } try { return AccessTools.Field(((object)radio).GetType(), "source")?.GetValue(radio); } catch { return null; } } private static bool GetBehaviourEnabled(object behaviour) { if (behaviour == null) { return false; } try { PropertyInfo property = behaviour.GetType().GetProperty("enabled"); if (property != null) { return (bool)property.GetValue(behaviour, null); } } catch { } return false; } private static void ApplyHeadlightTuning(sCarController car) { if ((Object)(object)car == (Object)null) { return; } Headlights headlights = car.headlights; if ((Object)(object)headlights == (Object)null) { return; } int instanceID = ((Object)car).GetInstanceID(); if (!_headlightTuningCaches.TryGetValue(instanceID, out var cache) || cache == null) { cache = new HeadlightTuningCache(); _headlightTuningCaches[instanceID] = cache; } float unscaledTime = Time.unscaledTime; HashSet seen; if (cache.Lights.Count == 0 || unscaledTime >= cache.NextRescanTime) { cache.Lights.Clear(); cache.NextRescanTime = unscaledTime + 2f; EnsureHeadlightsRefs(headlights); object root = (object)((_headlightsHeadLightsField != null) ? /*isinst with value type is only supported in some contexts*/: null); _tmpHeadlightLightIds.Clear(); seen = _tmpHeadlightLightIds; AddLightsFrom((GameObject)root); try { Transform val = (((Object)(object)((Component)headlights).transform != (Object)null && ((Component)headlights).transform.childCount > 0) ? ((Component)headlights).transform.GetChild(0) : null); AddLightsFrom(((Object)(object)val != (Object)null) ? ((Component)val).gameObject : null); } catch { } try { Light[] componentsInChildren = ((Component)headlights).GetComponentsInChildren(true); if (componentsInChildren != null) { foreach (Light val2 in componentsInChildren) { if (!((Object)(object)val2 == (Object)null)) { int instanceID2 = ((Object)val2).GetInstanceID(); if (seen.Add(instanceID2)) { cache.Lights.Add(val2); } } } } } catch { } } List lights = cache.Lights; if (lights.Count == 0) { return; } float num = GetHeadlightIntensityMult(); float num2 = GetHeadlightRangeMult(); if (!GetIgnitionEnabledEffective()) { num = 0f; num2 = 0f; } for (int j = 0; j < lights.Count; j++) { Light val3 = lights[j]; if (!((Object)(object)val3 == (Object)null)) { int instanceID3 = ((Object)val3).GetInstanceID(); if (!_lightDefaults.TryGetValue(instanceID3, out (float, float) value)) { value = (val3.intensity, val3.range); _lightDefaults[instanceID3] = value; } val3.intensity = value.Item1 * num; val3.range = value.Item2 * num2; } } void AddLightsFrom(GameObject val4) { if ((Object)(object)val4 == (Object)null) { return; } try { Light[] componentsInChildren2 = val4.GetComponentsInChildren(true); if (componentsInChildren2 != null) { foreach (Light val5 in componentsInChildren2) { if (!((Object)(object)val5 == (Object)null)) { int instanceID4 = ((Object)val5).GetInstanceID(); if (seen.Add(instanceID4)) { cache.Lights.Add(val5); } } } } } catch { } } } private static void EnsureEngineSfxRefs(object instance) { if (instance != null) { Type type = instance.GetType(); if (!(_engineSfxRuntimeType == type)) { _engineSfxRuntimeType = type; _engineCarField = AccessTools.Field(type, "car"); _engineIdleField = AccessTools.Field(type, "idle"); _engineDriveField = AccessTools.Field(type, "drive"); _engineIntenseField = AccessTools.Field(type, "intense"); _engineDistortionField = AccessTools.Field(type, "distortionFilter"); } } } private static void ApplySpeedScaleTuning(sCarController car) { if ((Object)(object)car == (Object)null) { return; } int instanceID = ((Object)car).GetInstanceID(); if (!_carScaleDefaults.ContainsKey(instanceID)) { _carScaleDefaults[instanceID] = (car.maxSpeedScale, car.drivePowerScale); } (float, float) tuple = _carScaleDefaults[instanceID]; if (car.GuyActive) { car.maxSpeedScale = tuple.Item1; car.drivePowerScale = tuple.Item2; _currentSpeedMult = 1f; return; } float num; if (IsManualTransmissionEnabledEffective()) { num = ((_manualGear < 0) ? GetManualSpeedMultReverse() : GetManualSpeedMultForward()); } else { float num2 = 0f; try { if (car.player >= 0 && car.player < sInputManager.players.Length) { num2 = sInputManager.players[car.player].driveInput.y; } } catch { num2 = 0f; } num = ((num2 < 0f) ? GetManualSpeedMultReverse() : GetManualSpeedMultForward()); } car.maxSpeedScale = tuple.Item1 * num; car.drivePowerScale = tuple.Item2; _currentSpeedMult = num; } private static void ApplyVisualScaleTuning(sCarController car) { if ((Object)(object)car == (Object)null || !IsTruckCar(car)) { return; } float wheelScale = GetWheelScale(); if (car.wheels == null) { return; } for (int i = 0; i < car.wheels.Length; i++) { Wheel val = car.wheels[i]; if (val != null && !((Object)(object)val.view == (Object)null)) { ApplyTransformScale(val.view, wheelScale); } } } private static void ApplyTransformScale(Transform t, float scale) { //IL_0034: 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) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)t == (Object)null)) { int instanceID = ((Object)t).GetInstanceID(); if (!_visualScaleDefaults.TryGetValue(instanceID, out var value)) { value = t.localScale; _visualScaleDefaults[instanceID] = value; } t.localScale = value * Mathf.Clamp(scale, 0.5f, 2f); } } private static void ApplyStoryHandlingTuning(sCarController car) { if ((Object)(object)car == (Object)null || car.overridePhysics) { return; } int instanceID = ((Object)car).GetInstanceID(); if (!_storyHandlingDefaults.TryGetValue(instanceID, out var value)) { value = new StoryHandlingDefaults { maxDrivePower = car.maxDrivePower, maxSpeed = car.maxSpeed, steeringAngle = car.steeringAngle, downForce = car.downForce, maxFrictionForce = ((car.wheels == null) ? null : new float[car.wheels.Length]) }; if (car.wheels != null) { for (int i = 0; i < car.wheels.Length; i++) { value.maxFrictionForce[i] = ((car.wheels[i] != null) ? car.wheels[i].maxFrictionForce : 0f); } } _storyHandlingDefaults[instanceID] = value; } car.maxDrivePower = value.maxDrivePower * GetHandlingPowerMult(); car.maxSpeed = value.maxSpeed * GetHandlingSpeedMult(); car.steeringAngle = value.steeringAngle * GetHandlingSteeringMult(); car.downForce = value.downForce * GetHandlingDownforceMult(); if (car.wheels == null || value.maxFrictionForce == null) { return; } float handlingGripMult = GetHandlingGripMult(); int num = Mathf.Min(car.wheels.Length, value.maxFrictionForce.Length); for (int j = 0; j < num; j++) { if (car.wheels[j] != null) { car.wheels[j].maxFrictionForce = value.maxFrictionForce[j] * handlingGripMult; } } } private static void ApplyRallyHandlingTuning(sRallyDriving car) { if ((Object)(object)car == (Object)null) { return; } int instanceID = ((Object)car).GetInstanceID(); if (!_rallyHandlingDefaults.TryGetValue(instanceID, out var value)) { value = new RallyHandlingDefaults { mass = car.mass, gripScalar = car.gripScalar, turningRadius = car.turningRadius, torqueCurveMultiplier = (((Object)(object)car.engine != (Object)null) ? car.engine.torqueCurveMultiplier : 0f), redlineRPM = (((Object)(object)car.engine != (Object)null) ? car.engine.redlineRPM : 0f) }; _rallyHandlingDefaults[instanceID] = value; } car.mass = value.mass * GetHandlingMassMult(); car.gripScalar = value.gripScalar * GetHandlingGripMult(); car.turningRadius = value.turningRadius / Mathf.Max(0.01f, GetHandlingSteeringMult()); if ((Object)(object)car.rb != (Object)null) { car.rb.mass = car.mass; } if ((Object)(object)car.engine != (Object)null) { car.engine.torqueCurveMultiplier = value.torqueCurveMultiplier * GetHandlingPowerMult(); car.engine.redlineRPM = value.redlineRPM * GetHandlingSpeedMult(); } if (car.wheels == null) { return; } EnsureRallyWheelRefs(); for (int i = 0; i < car.wheels.Length; i++) { Wheel val = car.wheels[i]; if (val != null) { try { _rallyWheelTurningRadiusField?.SetValue(val, car.turningRadius); } catch { } } } } private static float GetMaxSpeedForGearKmh(int gear) { int manualGearCount = GetManualGearCount(); gear = Mathf.Clamp(gear, 1, manualGearCount); float num = Mathf.Pow(5.8f, 1f / (float)Mathf.Max(1, manualGearCount - 1)); return 25f * Mathf.Pow(num, (float)(gear - 1)); } private static float GetMaxSpeedForCurrentGearKmh() { int manualGear = _manualGear; if (manualGear == 0) { return 1f; } float maxSpeedForGearKmh = GetMaxSpeedForGearKmh(Mathf.Clamp(Mathf.Abs(manualGear), 1, GetManualGearCount())); return Mathf.Max(1f, maxSpeedForGearKmh * Mathf.Max(0.01f, _currentSpeedMult)); } private static void ResetStoryVirtualRpmForCurrentIgnition() { _storyVirtualRpm = (GetIgnitionEnabledEffective() ? 1000f : 0f); _storyVirtualRpmLastGear = _manualGear; } private static float GetStoryGearRpmTarget(float throttle) { if (_manualGear == 0) { return Mathf.Lerp(1000f, 7200f, _neutralRev01); } float num = Mathf.Clamp01(Mathf.Abs(_currentSignedSpeedKmh) / GetMaxSpeedForCurrentGearKmh()); float num2 = Mathf.Clamp01(throttle) * 0.03f; float num3 = Mathf.Clamp01(num + num2); return Mathf.Lerp(1000f, 7200f, num3); } private static float EvaluateStoryRallyTorqueCurve(float rpm) { if (rpm <= 0f) { return 0.71691895f; } if (rpm < 1018.26434f) { return Mathf.Lerp(0.71691895f, 90.08408f, rpm / 1018.26434f); } if (rpm < 4491.81f) { return Mathf.Lerp(90.08408f, 99.910545f, Mathf.InverseLerp(1018.26434f, 4491.81f, rpm)); } if (rpm < 6998.332f) { return Mathf.Lerp(99.910545f, 99.24677f, Mathf.InverseLerp(4491.81f, 6998.332f, rpm)); } if (rpm < 10000f) { return Mathf.Lerp(99.24677f, 1.0767212f, Mathf.InverseLerp(6998.332f, 10000f, rpm)); } return 1.0767212f; } private static float GetStoryRallyRpmRate(float target, float throttle) { float num = Mathf.Max(1000f, _storyVirtualRpm); float num2 = EvaluateStoryRallyTorqueCurve(num) * 2.5f * Mathf.Max(0.12f, Mathf.Clamp01(throttle)); float num3 = 10f + num * 0.025f; return Mathf.Clamp(((target > num) ? Mathf.Max(0f, num2 - num3 * 0.35f) : num3) / 0.5f * (30f / (float)Math.PI), (target > num) ? 900f : 1200f, (target > num) ? 4800f : 3600f); } private static void UpdateStoryVirtualRpm(bool engineOn) { if (!engineOn) { _storyVirtualRpm = Mathf.MoveTowards(_storyVirtualRpm, 0f, Time.deltaTime * 4500f); return; } float num = Mathf.Clamp01(_lastThrottle01); float num2; if (IsManualTransmissionEnabledEffective()) { if (_manualGear != _storyVirtualRpmLastGear) { _storyVirtualRpm = Mathf.Max(1000f, GetStoryGearRpmTarget(0f)); _storyVirtualRpmLastGear = _manualGear; } num2 = GetStoryGearRpmTarget(num); } else { float num3 = Mathf.Clamp01(_currentSpeedKmh / (140f * Mathf.Max(0.01f, _currentSpeedMult))) * 0.55f; float num4 = Mathf.Pow(num, 0.7f) * 0.35f; num2 = Mathf.Lerp(1000f, 7200f, Mathf.Max(num3, num4)); _storyVirtualRpmLastGear = _manualGear; } num2 = Mathf.Max(1000f, num2); float storyRallyRpmRate = GetStoryRallyRpmRate(num2, num); _storyVirtualRpm = Mathf.MoveTowards((_storyVirtualRpm <= 1f) ? 1000f : _storyVirtualRpm, num2, Time.deltaTime * storyRallyRpmRate); } internal static float GetEstimatedRpm() { if (!GetIgnitionEnabledEffective()) { return Mathf.Max(0f, _storyVirtualRpm); } return Mathf.Max(1000f, _storyVirtualRpm); } internal static float GetEstimatedRpmNormForSound() { if (GetIgnitionEnabledEffective()) { return Mathf.Clamp(GetEstimatedRpm() / 7200f, 0f, 1.2f); } return 0f; } internal static float GetEstimatedRpmNormForHud() { if (GetIgnitionEnabledEffective()) { return Mathf.Clamp(GetEstimatedRpm() / 7700f, 0f, 1.2f); } return 0f; } internal static float ComputeManualAccel(float gas) { if (!IsManualTransmissionEnabledEffective()) { return gas; } if (_manualGear == 0) { return 0f; } float num = Mathf.Max(0f, _currentSpeedKmh); float maxSpeedForCurrentGearKmh = GetMaxSpeedForCurrentGearKmh(); float num2 = Mathf.Clamp01(num / Mathf.Max(1f, maxSpeedForCurrentGearKmh)); float num3 = Mathf.Pow(1f - num2, 0.55f); float num4 = Mathf.Lerp(0.55f, 1.2f, num3); int manualGearCount = GetManualGearCount(); int num5 = Mathf.Clamp(Mathf.Abs(_manualGear), 1, manualGearCount); float num6 = ((manualGearCount <= 1) ? 1f : (((float)num5 - 1f) / ((float)manualGearCount - 1f))); float num7 = Mathf.Lerp(1.25f, 0.85f, Mathf.Clamp01(num6)); num4 *= num7; float num8 = Mathf.Clamp01(gas) * num4; if (_manualGear >= 0) { return num8; } return 0f - num8; } [HarmonyPatch(typeof(sCarController), "Update")] [HarmonyPrefix] private static void SCarController_Update_Prefix(sCarController __instance) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null) { return; } _currentCar = __instance; bool isInWalkingMode = _isInWalkingMode; _isInWalkingMode = __instance.GuyActive; _currentCarFrame = Time.frameCount; if (!isInWalkingMode && _isInWalkingMode) { _manualGear = 1; _neutralRev01 = 0f; ResetStoryVirtualRpmForCurrentIgnition(); } if ((Object)(object)__instance.rb != (Object)null) { Vector3 linearVelocity = __instance.rb.linearVelocity; _currentSpeedKmh = ((Vector3)(ref linearVelocity)).magnitude * 3.6f; try { _currentSignedSpeedKmh = Vector3.Dot(__instance.rb.linearVelocity, ((Component)__instance).transform.forward) * 3.6f; } catch { _currentSignedSpeedKmh = _currentSpeedKmh; } } ApplyStoryHandlingTuning(__instance); ApplyHeadlightTuning(__instance); ApplySpeedScaleTuning(__instance); ApplyVisualScaleTuning(__instance); ApplyTruckPaintIfNeeded(__instance); if (!GetIgnitionEnabledEffective()) { EnforceIgnitionOffForCurrentCar(); } UpdateIndicators(__instance); if (!IsRallyModeActive()) { bool reverseActive = !__instance.GuyActive && GetIgnitionEnabledEffective() && (IsManualTransmissionEnabledEffective() ? (GetManualGear() == -1) : (_currentSignedSpeedKmh < -0.5f)); UpdateBackupAlarm(__instance, reverseActive); } } [HarmonyPatch(typeof(sRallyDriving), "Setup")] [HarmonyPrefix] private static void SRallyDriving_Setup_Prefix(sRallyDriving __instance) { ApplyRallyHandlingTuning(__instance); } [HarmonyPatch(typeof(sRallyDriving), "Setup")] [HarmonyPostfix] private static void SRallyDriving_Setup_Postfix(sRallyDriving __instance) { ApplyRallyHandlingTuning(__instance); } [HarmonyPatch(typeof(sRallyDriving), "FixedUpdate")] [HarmonyPrefix] private static void SRallyDriving_FixedUpdate_Prefix(sRallyDriving __instance) { ApplyRallyHandlingTuning(__instance); } [HarmonyPatch(typeof(sRallyDriving), "CollectPlayerInput")] [HarmonyPrefix] private static void SRallyDriving_CollectPlayerInput_Prefix(sRallyDriving __instance) { if (!((Object)(object)__instance == (Object)null)) { bool rallyManualTransmissionEnabled = GetRallyManualTransmissionEnabled(); bool flag = !__instance.automatic; if (rallyManualTransmissionEnabled != flag) { _rallyManualCheatTogglePending = true; } } } [HarmonyPatch(typeof(sRallyDriving), "CollectPlayerInput")] [HarmonyPostfix] private static void SRallyDriving_CollectPlayerInput_Postfix(sRallyDriving __instance) { if (!((Object)(object)__instance == (Object)null)) { bool rallyManualTransmissionEnabled = GetRallyManualTransmissionEnabled(); __instance.automatic = !rallyManualTransmissionEnabled; if (__instance.playerNumber >= 0 && __instance.playerNumber < sInputManager.players.Length && (Object)(object)__instance.car != (Object)null) { sInputManager.players[__instance.playerNumber].manualShifting = !__instance.car.GuyActive && rallyManualTransmissionEnabled; } bool reverseActive = (Object)(object)__instance.car != (Object)null && !__instance.car.GuyActive && (Object)(object)__instance.gearbox != (Object)null && __instance.gearbox.currentGear == 0; UpdateBackupAlarm(__instance.car, reverseActive); } } private static void UpdateBackupAlarm(sCarController car, bool reverseActive) { if (!GetBackupAlarmEnabled() || (Object)(object)car == (Object)null || car.GuyActive || !reverseActive || PauseSystem.paused) { _backupAlarmHazardsActive = false; _backupNextBeepTime = 0f; return; } _backupAlarmHazardsActive = true; float backupAlarmVolume = GetBackupAlarmVolume(); if (!(backupAlarmVolume <= 0.001f) && !(Time.unscaledTime < _backupNextBeepTime)) { Component val = EnsureBackupBeepSource(car); Object val2 = EnsureBackupBeepClip(); if (!((Object)(object)val == (Object)null) && !(val2 == (Object)null)) { float backupAlarmInterval = GetBackupAlarmInterval(); Call(val, "PlayOneShot", val2, backupAlarmVolume); _backupNextBeepTime = Time.unscaledTime + backupAlarmInterval * 2f; } } } private static Component EnsureBackupBeepSource(sCarController car) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_011e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_backupBeepGo == (Object)null || (Object)(object)_backupBeepSource == (Object)null) { _backupBeepGo = new GameObject("SebTruck_BackupAlarmSFX"); ((Object)_backupBeepGo).hideFlags = (HideFlags)61; Type type = Type.GetType("UnityEngine.AudioSource, UnityEngine.AudioModule"); if (type == null) { return null; } _backupBeepSource = _backupBeepGo.AddComponent(type); SetProp(_backupBeepSource, "playOnAwake", false); SetProp(_backupBeepSource, "loop", false); SetProp(_backupBeepSource, "spatialBlend", 1f); SetProp(_backupBeepSource, "minDistance", 2f); SetProp(_backupBeepSource, "maxDistance", 35f); } if ((Object)(object)_backupBeepGo.transform.parent != (Object)(object)((Component)car).transform) { _backupBeepGo.transform.SetParent(((Component)car).transform, false); _backupBeepGo.transform.localPosition = new Vector3(0f, 0.6f, -1.4f); } return _backupBeepSource; } private static Object EnsureBackupBeepClip() { float backupAlarmTone = GetBackupAlarmTone(); float backupAlarmInterval = GetBackupAlarmInterval(); if (_backupBeepClip != (Object)null && Mathf.Abs(_backupBeepClipTone - backupAlarmTone) < 0.1f && Mathf.Abs(_backupBeepClipDuration - backupAlarmInterval) < 0.001f) { return _backupBeepClip; } int num = Mathf.Max(1, Mathf.RoundToInt(44100f * backupAlarmInterval)); float[] array = new float[num]; for (int i = 0; i < num; i++) { float num2 = (float)i / 44100f; float num3 = Mathf.Min(1f, Mathf.Min((float)i / 352.80002f, (float)(num - i - 1) / 529.2f)); float num4 = Mathf.Sin(num2 * backupAlarmTone * (float)Math.PI * 2f); array[i] = num4 * num3 * 0.14f; } Type type = Type.GetType("UnityEngine.AudioClip, UnityEngine.AudioModule"); if (type == null) { return null; } MethodInfo method = type.GetMethod("Create", new Type[5] { typeof(string), typeof(int), typeof(int), typeof(int), typeof(bool) }); if (method == null) { return null; } object? obj = method.Invoke(null, new object[5] { "SebTruck_BackupBeep", num, 1, 44100, false }); _backupBeepClip = (Object)((obj is Object) ? obj : null); if (_backupBeepClip == (Object)null) { return null; } type.GetMethod("SetData", new Type[2] { typeof(float[]), typeof(int) })?.Invoke(_backupBeepClip, new object[2] { array, 0 }); _backupBeepClipTone = backupAlarmTone; _backupBeepClipDuration = backupAlarmInterval; return _backupBeepClip; } [HarmonyPatch(typeof(sAutoGearshift), "FixedUpdate")] [HarmonyPrefix] private static bool SAutoGearshift_FixedUpdate_Prefix() { return !GetRallyManualTransmissionEnabled(); } [HarmonyPatch(typeof(sCheatManager), "HasCheat", new Type[] { typeof(int), typeof(bool) })] [HarmonyPostfix] private static void SCheatManager_HasCheat_Postfix(int index, ref bool __result) { if (index == 11 && _rallyManualCheatTogglePending) { _rallyManualCheatTogglePending = false; __result = true; } } private static bool PressedAnyBinding(BindAction action) { //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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Invalid comparison between Unknown and I4 //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) BindingEvaluator.BeginFrame(); for (int i = 0; i < _bindingSchemes.Length; i++) { BindingScheme val = _bindingSchemes[i]; BindingInput modifierBinding = BindingStore.GetModifierBinding(val); BindingLayer val2 = (BindingLayer)(((int)modifierBinding.Kind != 0 && BindingEvaluator.IsDown(modifierBinding)) ? 1 : 0); BindingInput binding = BindingStore.GetBinding(val, val2, action); if ((int)binding.Kind == 0 && (int)val2 == 1) { binding = BindingStore.GetBinding(val, (BindingLayer)0, action); } if ((int)binding.Kind != 0 && BindingEvaluator.WasPressedThisFrame(binding)) { return true; } } return false; } [HarmonyPatch(typeof(sInputManager), "Update")] [HarmonyPostfix] private static void SInputManager_Update_Postfix() { if (IsRallyModeActive() && sEasyRally.menuOpen && !PauseSystem.paused && PressedAnyBinding((BindAction)13)) { SetRallyManualTransmissionEnabled(!GetRallyManualTransmissionEnabled()); } } [HarmonyPatch(typeof(sInputManager), "GetInput")] [HarmonyPostfix] [HarmonyPriority(0)] private static void SInputManager_GetInput_Postfix(sInputManager __instance) { //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Invalid comparison between Unknown and I4 //IL_04dc: Unknown result type (might be due to invalid IL or missing references) //IL_04e1: Unknown result type (might be due to invalid IL or missing references) //IL_04ed: Unknown result type (might be due to invalid IL or missing references) //IL_04ef: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null) { return; } sCarController val = _currentCar; if ((Object)(object)val == (Object)null) { val = Object.FindFirstObjectByType(); } BindingScheme[] schemes; if ((Object)(object)val == (Object)null || val.GuyActive) { _ignitionHoldStart = -1f; _ignitionHoldConsumed = false; _ignitionHoldWasDown = false; _ignitionIgnoreHoldUntilRelease = false; } else { if (PauseSystem.paused || __instance.lockInput) { return; } BindingEvaluator.BeginFrame(); schemes = _bindingSchemes; bool ignitionFeatureEnabled = GetIgnitionFeatureEnabled(); bool flag = PressedAny((BindAction)16); bool flag2 = DownAny((BindAction)16); bool flag3 = ReleasedAny((BindAction)16); bool indicatorFeatureEnabled = GetIndicatorFeatureEnabled(); bool flag4 = PressedAny((BindAction)119); bool flag5 = PressedAny((BindAction)120); bool flag6 = PressedAny((BindAction)121); if (!ignitionFeatureEnabled) { _ignitionHoldStart = -1f; _ignitionHoldConsumed = false; _ignitionHoldWasDown = flag2; _ignitionIgnoreHoldUntilRelease = false; flag = false; flag2 = false; flag3 = false; } if (ignitionFeatureEnabled && GetIgnitionEnabled() && flag) { StopIgnitionHoldSfx(); _ignitionHoldStart = -1f; _ignitionHoldConsumed = false; _ignitionIgnoreHoldUntilRelease = true; SetIgnitionEnabled(enabled: false); ApplyIgnitionStateChange(ignitionOn: false); LogDebug("Ignition toggled OFF"); } if (ignitionFeatureEnabled && !GetIgnitionEnabled() && flag2 && !_ignitionIgnoreHoldUntilRelease) { if (_ignitionHoldStart < 0f) { _ignitionHoldStart = Time.unscaledTime; _ignitionHoldConsumed = false; LogDebug("Ignition hold started"); StartIgnitionHoldSfx(val); } float ignitionHoldSeconds = GetIgnitionHoldSeconds(); if (!_ignitionHoldConsumed && Time.unscaledTime - _ignitionHoldStart >= ignitionHoldSeconds) { SetIgnitionEnabled(enabled: true); ApplyIgnitionStateChange(ignitionOn: true); _ignitionHoldConsumed = true; LogDebug("Ignition hold complete"); } } if (flag3) { if (ignitionFeatureEnabled && !GetIgnitionEnabled()) { StopIgnitionHoldSfx(); } _ignitionIgnoreHoldUntilRelease = false; _ignitionHoldStart = -1f; _ignitionHoldConsumed = false; if (ignitionFeatureEnabled && !GetIgnitionEnabled()) { LogDebug("Ignition hold cancelled"); } } if (indicatorFeatureEnabled && GetIgnitionEnabledEffective()) { if (flag6) { _indicatorMode = ((_indicatorMode != IndicatorMode.Hazards) ? IndicatorMode.Hazards : IndicatorMode.Off); _indicatorNextBlinkTime = 0f; } if (flag4) { _indicatorMode = ((_indicatorMode != IndicatorMode.Left) ? IndicatorMode.Left : IndicatorMode.Off); _indicatorNextBlinkTime = 0f; } if (flag5) { _indicatorMode = ((_indicatorMode != IndicatorMode.Right) ? IndicatorMode.Right : IndicatorMode.Off); _indicatorNextBlinkTime = 0f; } } else { _indicatorMode = IndicatorMode.Off; } UpdateIndicatorAutoCancel(__instance.driveInput.x); _ignitionHoldWasDown = flag2; if (PressedAny((BindAction)13)) { if (IsRallyModeActive()) { SetRallyManualTransmissionEnabled(!GetRallyManualTransmissionEnabled()); } else { ToggleManualTransmission(); } } bool flag7 = (int)SebBindsApi.GetShiftMode() == 1; if (!flag7 && !IsRallyModeActive() && PressedAny((BindAction)14)) { if (!GetManualTransmissionEnabled()) { SetManualTransmissionEnabled(enabled: true); } ShiftManualGear(1); } if (!flag7 && !IsRallyModeActive() && PressedAny((BindAction)15)) { if (!GetManualTransmissionEnabled()) { SetManualTransmissionEnabled(enabled: true); } ShiftManualGear(-1); } if (!IsRallyModeActive()) { if (flag7) { int gear; bool flag8 = TryGetHeldDirectGear(out gear); if (flag8 && !GetManualTransmissionEnabled()) { SetManualTransmissionEnabled(enabled: true); } if (flag8 || GetManualTransmissionEnabled()) { SetManualGearDirect(flag8 ? gear : 0); } } else { SetDirectGearIfPressed((BindAction)19, -1); SetDirectGearIfPressed((BindAction)20, 0); SetDirectGearIfPressed((BindAction)21, 1); SetDirectGearIfPressed((BindAction)22, 2); SetDirectGearIfPressed((BindAction)23, 3); SetDirectGearIfPressed((BindAction)24, 4); SetDirectGearIfPressed((BindAction)25, 5); SetDirectGearIfPressed((BindAction)26, 6); } } if (PauseSystem.paused) { return; } float y = __instance.driveInput.y; float num = Mathf.Clamp01(y); if (num < 0f) { num = 0f; } float num2 = Mathf.Clamp01(0f - y); float num3 = (__instance.brakePressed ? 1f : 0f); num2 = Mathf.Max(num2, num3); _lastThrottle01 = num; if (IsManualTransmissionEnabledEffective() && GetManualGear() == 0) { _neutralRev01 = Mathf.Lerp(_neutralRev01, _lastThrottle01, Time.deltaTime * 8f); } else { _neutralRev01 = Mathf.Lerp(_neutralRev01, 0f, Time.deltaTime * 6f); } UpdateStoryVirtualRpm(GetIgnitionEnabledEffective()); bool flag9 = false; float num5; if (IsManualTransmissionEnabledEffective()) { int manualGear = GetManualGear(); float num4 = ComputeManualAccel(num); float currentSignedSpeedKmh = _currentSignedSpeedKmh; if (manualGear > 0) { num5 = ((!(currentSignedSpeedKmh > 1f)) ? Mathf.Max(0f, num4 - num2) : (num4 - num2)); } else if (manualGear < 0) { if (num2 > 0.05f) { num5 = 0f; flag9 = true; } else { num5 = 0f - Mathf.Abs(num4); } } else { num5 = 0f; } } else { num5 = __instance.driveInput.y; } num5 = Mathf.Clamp(num5, -1f, 1f); if (!GetIgnitionEnabledEffective()) { num5 = 0f; } Vector2 driveInput = __instance.driveInput; driveInput.y = num5; __instance.driveInput = driveInput; if (flag9) { __instance.brakePressed = true; } } static bool Down(BindingInput b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) if ((int)b.Kind != 0) { return BindingEvaluator.IsDown(b); } return false; } bool DownAny(BindAction a) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < schemes.Length; i++) { if (Down(GetBind(schemes[i], a))) { return true; } } return false; } static BindingInput GetBind(BindingScheme s, BindAction action) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_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_0025: 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) //IL_001a: Invalid comparison between Unknown and I4 //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) BindingLayer val2 = LayerFor(s); BindingInput binding = BindingStore.GetBinding(s, val2, action); if ((int)binding.Kind == 0 && (int)val2 == 1) { binding = BindingStore.GetBinding(s, (BindingLayer)0, action); } return binding; } static BindingLayer LayerFor(BindingScheme s) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) BindingInput modifierBinding = BindingStore.GetModifierBinding(s); if ((int)modifierBinding.Kind != 0 && BindingEvaluator.IsDown(modifierBinding)) { return (BindingLayer)1; } return (BindingLayer)0; } static bool Pressed(BindingInput b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) if ((int)b.Kind != 0) { return BindingEvaluator.WasPressedThisFrame(b); } return false; } bool PressedAny(BindAction a) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < schemes.Length; i++) { if (Pressed(GetBind(schemes[i], a))) { return true; } } return false; } static bool Released(BindingInput b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) if ((int)b.Kind != 0) { return BindingEvaluator.WasReleasedThisFrame(b); } return false; } bool ReleasedAny(BindAction a) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < schemes.Length; i++) { if (Released(GetBind(schemes[i], a))) { return true; } } return false; } void SetDirectGearIfPressed(BindAction action, int manualGearDirect) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) if (PressedAny(action)) { if (!GetManualTransmissionEnabled()) { SetManualTransmissionEnabled(enabled: true); } SetManualGearDirect(manualGearDirect); } } bool TryGetHeldDirectGear(out int reference) { if (DownAny((BindAction)19)) { reference = -1; return true; } if (DownAny((BindAction)20)) { reference = 0; return true; } if (DownAny((BindAction)21)) { reference = 1; return true; } if (DownAny((BindAction)22)) { reference = 2; return true; } if (DownAny((BindAction)23)) { reference = 3; return true; } if (DownAny((BindAction)24)) { reference = 4; return true; } if (DownAny((BindAction)25)) { reference = 5; return true; } if (DownAny((BindAction)26)) { reference = 6; return true; } reference = 0; return false; } } [HarmonyPatch(typeof(sRadioSystem), "Update")] [HarmonyPostfix] private static void SRadioSystem_Update_Postfix(sRadioSystem __instance) { MuteRadioProximityIfIgnitionOff(__instance); } [HarmonyPatch(typeof(Headlights), "Break")] [HarmonyPostfix] private static void Headlights_Break_Postfix(Headlights __instance, bool breaking) { if (!((Object)(object)__instance == (Object)null)) { sCarController val = null; try { val = ((Component)__instance).GetComponentInParent(); } catch { } if (!((Object)(object)val == (Object)null)) { SetTruckBraking(val, breaking); ApplyTruckEmissionMap(val); } } } [HarmonyPatch(typeof(sHUD), "DoFuelMath")] [HarmonyPrefix] private static bool SHUD_DoFuelMath_Prefix() { if (!GetIgnitionEnabledEffective()) { return false; } return true; } [HarmonyPatch(typeof(sHUD), "DoTemperature")] [HarmonyPostfix] private static void SHUD_DoTemperature_Postfix(sHUD __instance) { if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.navigation == (Object)null) && !((Object)(object)__instance.navigation.car == (Object)null) && !__instance.navigation.car.GuyActive && GetIgnitionFeatureEnabled() && !GetIgnitionEnabledEffective()) { if (_ignitionOffSince < 0f) { _ignitionOffSince = Time.unscaledTime; } if (!(Time.unscaledTime - _ignitionOffSince < 15f)) { __instance.AddWarning("truck temperature low"); float num = __instance.temperatureRate * 0.5f; __instance.temperature = Mathf.Clamp(__instance.temperature - Time.deltaTime * num, 0f, __instance.temperatureLimit); } } } [HarmonyPatch(typeof(sEngineSFX), "Update")] [HarmonyPostfix] private static void SEngineSFX_Update_Postfix(sEngineSFX __instance) { if ((Object)(object)__instance == (Object)null) { return; } EnsureEngineSfxRefs(__instance); sCarController val = (sCarController)((_engineCarField != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val == (Object)null || ((Object)(object)_currentCar != (Object)null && val != _currentCar)) { return; } if (GetIgnitionFeatureEnabled() && !GetIgnitionEnabledEffective()) { try { Component val2 = (Component)((_engineIdleField != null) ? /*isinst with value type is only supported in some contexts*/: null); Component val3 = (Component)((_engineDriveField != null) ? /*isinst with value type is only supported in some contexts*/: null); Component val4 = (Component)((_engineIntenseField != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val2 != (Object)null) { SetProp(val2, "volume", 0f); } if ((Object)(object)val3 != (Object)null) { SetProp(val3, "volume", 0f); } if ((Object)(object)val4 != (Object)null) { SetProp(val4, "volume", 0f); } Component val5 = (Component)((_engineDistortionField != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val5 != (Object)null) { SetProp(val5, "distortionLevel", 0f); } return; } catch { return; } } if (val.GuyActive || !IsManualTransmissionEnabledEffective()) { return; } float estimatedRpmNormForSound = GetEstimatedRpmNormForSound(); float num = Mathf.Clamp01((estimatedRpmNormForSound - 1f) / 0.2f); float num2 = ((_manualGear == 0) ? Mathf.Clamp01(_neutralRev01) : 0f); float num3 = Mathf.Clamp01((estimatedRpmNormForSound - 0.92f) / 0.07999998f); float pitchMul = 1f + num2 * 0.85f + num * 0.35f; object src = (object)((_engineIdleField != null) ? /*isinst with value type is only supported in some contexts*/: null); Component val6 = (Component)((_engineDriveField != null) ? /*isinst with value type is only supported in some contexts*/: null); Component val7 = (Component)((_engineIntenseField != null) ? /*isinst with value type is only supported in some contexts*/: null); ApplyPitchMul((Component)src); ApplyPitchMul(val6); ApplyPitchMul(val7); if (num2 > 0.01f) { if ((Object)(object)val6 != (Object)null) { float floatProp = GetFloatProp(val6, "volume"); SetProp(val6, "volume", Mathf.Max(floatProp, num2 * 0.55f)); } if ((Object)(object)val7 != (Object)null) { float floatProp2 = GetFloatProp(val7, "volume"); SetProp(val7, "volume", Mathf.Max(floatProp2, num2 * 0.35f)); } } if (num3 > 0.01f) { float num4 = Mathf.Min(1f, num3 * 0.35f + num * 0.45f); float num5 = Mathf.Min(1f, num3 * 0.22f + num * 0.35f); if ((Object)(object)val6 != (Object)null) { float floatProp3 = GetFloatProp(val6, "volume"); SetProp(val6, "volume", Mathf.Max(floatProp3, num4)); } if ((Object)(object)val7 != (Object)null) { float floatProp4 = GetFloatProp(val7, "volume"); SetProp(val7, "volume", Mathf.Max(floatProp4, num5)); } } if (num > 0.01f) { float num6 = Mathf.Lerp(7f, 14f, num); float num7 = Mathf.Repeat(Time.time * num6, 1f); float num8 = 1f - num7; float num9 = ((num7 < 0.12f) ? Mathf.Lerp(0.25f, 1f, num7 / 0.12f) : 1f); float num10 = Mathf.Lerp(1f, 0.72f, num); float num11 = Mathf.Lerp(1f, num8, num) * num9; float num12 = num10 * num11; float num13 = 1f + Mathf.Sin(Time.time * 55f) * 0.012f * num; if ((Object)(object)val6 != (Object)null) { SetProp(val6, "volume", GetFloatProp(val6, "volume") * num12); SetProp(val6, "pitch", GetFloatProp(val6, "pitch", 1f) * num13); } if ((Object)(object)val7 != (Object)null) { SetProp(val7, "volume", GetFloatProp(val7, "volume") * num12); SetProp(val7, "pitch", GetFloatProp(val7, "pitch", 1f) * num13); } } Component val8 = (Component)((_engineDistortionField != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val8 != (Object)null) { float num14 = GetFloatProp(val8, "distortionLevel"); if (num > 0f) { num14 = Mathf.Max(num14, 0.1f + num * 0.55f); } if (num2 > 0.1f) { num14 = Mathf.Max(num14, 0.05f + num2 * 0.1f); } SetProp(val8, "distortionLevel", num14); } void ApplyPitchMul(Component val9) { if (!((Object)(object)val9 == (Object)null)) { int instanceID = ((Object)val9).GetInstanceID(); float num15 = 1f; if (_enginePitchMulApplied.TryGetValue(instanceID, out var value) && value > 0.0001f) { num15 = value; } float floatProp5 = GetFloatProp(val9, "pitch", 1f); SetProp(val9, "pitch", floatProp5 / num15 * pitchMul); _enginePitchMulApplied[instanceID] = pitchMul; } } } [HarmonyPatch(typeof(sPathFinder), "DoResetCar")] [HarmonyPostfix] private static void SPathFinder_DoResetCar_Postfix() { if (IsManualTransmissionEnabledEffective()) { _manualGear = 1; _neutralRev01 = 0f; ResetStoryVirtualRpmForCurrentIgnition(); } } [HarmonyPatch(typeof(sHUD), "RadioDisplay")] [HarmonyPostfix] private static void SHUD_RadioDisplay_Postfix(object __instance) { sHUD val = (sHUD)((__instance is sHUD) ? __instance : null); if ((Object)(object)val == (Object)null) { return; } bool flag = IsRallyModeActive(); sCarController val2 = _currentCar; if ((Object)(object)val2 == (Object)null) { val2 = Object.FindFirstObjectByType(); } if ((Object)(object)val2 == (Object)null || val2.GuyActive) { return; } FieldInfo fieldInfo = AccessTools.Field(typeof(sHUD), "R"); MiniRenderer R = (MiniRenderer)((fieldInfo != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)R == (Object)null) { return; } bool ignitionFeatureEnabled = GetIgnitionFeatureEnabled(); bool ignitionEnabledEffective = GetIgnitionEnabledEffective(); bool flag2 = ignitionFeatureEnabled && !GetIgnitionEnabled() && _ignitionHoldStart >= 0f && !_ignitionHoldConsumed; bool flag3 = ignitionFeatureEnabled && !ignitionEnabledEffective && !flag2; bool flag4 = IsManualTransmissionEnabledEffective(); bool flag5 = !flag && ignitionEnabledEffective && GetHudShowSpeed(); bool flag6 = !flag && ignitionEnabledEffective && flag4 && GetHudShowTach(); bool flag7 = !flag && ignitionEnabledEffective && flag4 && GetHudShowGear(); if (!flag2 && !flag3 && !flag5 && !flag6 && !flag7) { return; } float xLeft = 68f; float xRight = (float)R.width - 68f; float yLeft = (float)R.height - 64f + 22f; float yRight = yLeft; if (flag) { yLeft += 10f; yRight += 10f; } HudReadoutAnchor hudSpeedAnchor = GetHudSpeedAnchor(); HudReadoutAnchor hudTachAnchor = GetHudTachAnchor(); HudReadoutAnchor hudGearAnchor = GetHudGearAnchor(); if (flag2) { float num = Mathf.Max(0.01f, GetIgnitionHoldSeconds()); float num2 = Mathf.Clamp01((Time.unscaledTime - _ignitionHoldStart) / num); PutLine(hudSpeedAnchor, "START " + Mathf.RoundToInt(num2 * 100f) + "%"); } else if (flag3) { PutLine(hudSpeedAnchor, "ENGN OFF"); } if (!flag) { if (GetHudStyle() == HudStyle.Rally) { DrawStoryRallyStyleHud(R, 68f, 40f, flag5, flag6, flag7); } else { DrawStoryClassicTelemetry(R, PutLine, flag5, flag6, flag7, hudTachAnchor, hudGearAnchor, xRight, ref yLeft, ref yRight); } } void PutLine(HudReadoutAnchor a, string text) { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) if (!string.IsNullOrEmpty(text)) { if (a == HudReadoutAnchor.BottomRight) { R.fontOptions.alignment = (Alignment)2; R.fput(text, xRight, yRight, 0f, 13f, 0f, -1); yRight += 10f; } else { R.fontOptions.alignment = (Alignment)0; R.put(text, xLeft, yLeft); yLeft += 10f; } } } } private static void DrawStoryClassicTelemetry(MiniRenderer R, Action putLine, bool showSpeed, bool showTach, bool showGear, HudReadoutAnchor aTach, HudReadoutAnchor aGear, float xRight, ref float yLeft, ref float yRight) { //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) if (showSpeed) { float num = ConvertSpeedForHud(_currentSpeedKmh); int num2 = Mathf.Max(0, Mathf.RoundToInt(num)); putLine(GetHudSpeedAnchor(), num2 + GetHudSpeedUnitLabel(GetHudSpeedUnit())); } if (showTach) { float estimatedRpm = GetEstimatedRpm(); float num3 = Mathf.Clamp(GetEstimatedRpmNormForHud(), 0f, 1.2f); string text = ((GetManualGear() > 0 && GetManualGear() == GetManualGearCount()) ? "" : ((num3 >= 1f) ? "!!" : ((num3 >= 0.92f) ? "!" : ""))); putLine(aTach, Mathf.RoundToInt(estimatedRpm) + "rpm" + text); } if (showGear) { int manualGear = GetManualGear(); int manualGearCount = GetManualGearCount(); string text2 = "RN"; for (int i = 1; i <= manualGearCount; i++) { text2 += i; } if (aGear == HudReadoutAnchor.BottomRight) { float num4 = xRight - 8f * (float)text2.Length; R.fontOptions.alignment = (Alignment)0; R.put(text2, num4, yRight); int num5 = ((manualGear >= 0) ? ((manualGear == 0) ? 1 : (Mathf.Clamp(manualGear, 1, manualGearCount) + 1)) : 0); yRight += 10f; R.put("^", num4 + 8f * (float)num5, yRight); yRight += 10f; } else { R.fontOptions.alignment = (Alignment)0; R.put(text2, 68f, yLeft); int num6 = ((manualGear >= 0) ? ((manualGear == 0) ? 1 : (Mathf.Clamp(manualGear, 1, manualGearCount) + 1)) : 0); yLeft += 10f; R.put("^", 68f + 8f * (float)num6, yLeft); yLeft += 10f; } } } private static void DrawStoryRallyStyleHud(MiniRenderer R, float x, float y, bool showSpeed, bool showTach, bool showGear) { int manualGearCount = GetManualGearCount(); int manualGear = GetManualGear(); float rpmNorm = Mathf.Clamp(GetEstimatedRpmNormForHud(), 0f, 1.2f); float speed = ConvertSpeedForHud(_currentSpeedKmh); DrawRallyStyleHudParts(R, x, y, showSpeed, showTach, showGear, manualGear, manualGearCount, rpmNorm, speed, GetHudSpeedUnitLabel(GetHudSpeedUnit())); } private static void DrawRallyDrivingHud(sRallyDriving car, MiniRenderer R, float x, float y) { //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)car == (Object)null || (Object)(object)R == (Object)null || (Object)(object)car.car == (Object)null || car.car.GuyActive || car.drawDebugInfo) { return; } bool rallyHudShowSpeed = GetRallyHudShowSpeed(); bool rallyHudShowTach = GetRallyHudShowTach(); bool rallyHudShowGear = GetRallyHudShowGear(); if (rallyHudShowSpeed || rallyHudShowTach || rallyHudShowGear) { int gearCount = (((Object)(object)car.gearbox != (Object)null && car.gearbox.gearRatios != null) ? Mathf.Max(1, car.gearbox.gearRatios.Length - 2) : 6); int gear = (((Object)(object)car.gearbox != (Object)null) ? RallyGearboxIndexToDisplayGear(car.gearbox.currentGear) : 0); float num = (((Object)(object)car.engine != (Object)null) ? Mathf.Max(1f, car.engine.redlineRPM + 500f) : 1f); float rpmNorm = Mathf.Clamp((((Object)(object)car.engine != (Object)null) ? car.engine.engineRPM : 0f) / num, 0f, 1.2f); float num2; if (!((Object)(object)car.rb != (Object)null)) { num2 = 0f; } else { Vector3 linearVelocity = car.rb.linearVelocity; num2 = ((Vector3)(ref linearVelocity)).magnitude * 3.6f; } float num3 = num2; SpeedUnit rallyHudSpeedUnit = GetRallyHudSpeedUnit(); float speed = ((rallyHudSpeedUnit == SpeedUnit.Mph) ? (num3 * 0.621371f) : num3); DrawRallyStyleHudParts(R, x, y, rallyHudShowSpeed, rallyHudShowTach, rallyHudShowGear, gear, gearCount, rpmNorm, speed, GetHudSpeedUnitLabel(rallyHudSpeedUnit)); } } private static int RallyGearboxIndexToDisplayGear(int currentGear) { if (currentGear <= 0) { return -1; } if (currentGear == 1) { return 0; } return currentGear - 1; } private static string FormatRallyGearLine(int gear, int gearCount) { gearCount = Mathf.Clamp(gearCount, 1, "RN123456789".Length - 2); int num = ((gear >= 0) ? ((gear == 0) ? 1 : (Mathf.Clamp(gear, 1, gearCount) + 1)) : 0); string text = ""; for (int i = 0; i < gearCount + 2; i++) { text += "RN123456789"[i]; text = ((num != i + 1) ? (text + ((num == i) ? "]" : " ")) : (text + "[")); } return text; } private static void DrawRallyStyleHudParts(MiniRenderer R, float x, float y, bool showSpeed, bool showTach, bool showGear, int gear, int gearCount, float rpmNorm, float speed, string unit) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) float num = y; if (showGear) { R.fontOptions.alignment = (Alignment)0; R.put(FormatRallyGearLine(gear, gearCount), x, num); num += 10f; } if (showTach) { float num2 = Mathf.Clamp(rpmNorm, 0f, 1.2f); int num3 = Mathf.Clamp((int)(8f * num2), 0, 8); float num4 = num2 * 8f - (float)num3; bool flag = rpmNorm >= 1f; bool flag2 = !flag || Mathf.FloorToInt(Time.unscaledTime * 8f) % 2 == 0; for (int i = 0; i < num3; i++) { if (!flag || i != 7 || flag2) { R.spr(160f, 48f, (float)(int)(x + (float)i * 16f), num, 8f, 2f, false, 16f, 2f); } } if (num3 < 8 && flag2) { int num5 = (int)((1f - num4) * 6f); int num6 = 160 + num5 % 2 * 8; int num7 = 48 + num5 / 2 * 5; R.spr((float)num6, (float)num7, (float)(int)(x + (float)num3 * 16f), num, 8f, 2f, false, 16f, 2f); } num += 4f; } if (showSpeed) { R.fontOptions.alignment = (Alignment)0; R.put(Mathf.Round(speed) + unit, x, num); } } private static MiniRenderer GetCurrentHudRenderer() { try { sHUD val = Object.FindFirstObjectByType(); if ((Object)(object)val == (Object)null) { return null; } FieldInfo fieldInfo = AccessTools.Field(typeof(sHUD), "R"); return (MiniRenderer)((fieldInfo != null) ? /*isinst with value type is only supported in some contexts*/: null); } catch { return null; } } [HarmonyPatch(typeof(sHUD), "DebugDraw")] [HarmonyPrefix] private static bool SHUD_DebugDraw_Prefix(Action Draw, float x, float y) { if (Draw != null) { object? target = Draw.Target; sRallyDriving val = (sRallyDriving)((target is sRallyDriving) ? target : null); if (val != null && Draw.Method != null && Draw.Method.Name == "DrawCarHUD") { try { DrawRallyDrivingHud(val, GetCurrentHudRenderer(), x, y); } catch { } return false; } } return true; } } public static class SebTruckApi { public static void SetManualGear(int gear) { if (Plugin.IsManualTransmissionEnabledEffective()) { int manualGearCount = Plugin.GetManualGearCount(); gear = ((gear > 0) ? Mathf.Clamp(gear, 1, manualGearCount) : ((gear < 0) ? (-1) : 0)); Plugin.SetManualGearDirect(gear); } } public static bool IsManualEnabled() { return Plugin.IsManualTransmissionEnabledEffective(); } public static int GetManualGearCount() { return Plugin.GetManualGearCount(); } } public class TruckMenuWindow : CartridgeWindowBase { private enum Page { Handling, Ignition, TurnSignals, BackupAlarm, Hud, Tweaks } public const string FileName = "truck"; public const string ListenerName = "SebTruckMenu"; public const string ListenerData = "listener_SebTruckMenu"; private string _toastMsg; private float _toastUntil; private Page _page; protected override void DrawWindow(Rect p) { //IL_027e: Unknown result type (might be due to invalid IL or missing references) float center = ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f - 16f; float num = ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f; float num2 = ((Rect)(ref p)).y + 10f; float num3 = 12f; float num4 = 4f; base.Util.Label("Truck", num, num2); num2 += num3; float num5 = ((Rect)(ref p)).y + ((Rect)(ref p)).height - 18f; float num6 = ((Rect)(ref p)).x + 40f; float num7 = ((Rect)(ref p)).x + ((Rect)(ref p)).width - 40f; if (base.Util.SimpleButtonRaw("Prev", num6, num5)) { _page = (Page)((int)(_page + 6 - 1) % 6); } if (base.Util.SimpleButtonRaw("Back", num, num5)) { ((CartridgeWindowBase)this).BackButtonPressed(); return; } if (base.Util.SimpleButtonRaw("Next", num7, num5)) { _page = (Page)((int)(_page + 1) % 6); } base.Util.Label((int)(_page + 1) + "/" + 6, ((Rect)(ref p)).x + ((Rect)(ref p)).width - 18f, ((Rect)(ref p)).y + 10f); num2 += num4; string text = ((_page == Page.Hud) ? "HUD" : _page.ToString()); if (_page == Page.TurnSignals) { text = "Turn Signals"; } else if (_page == Page.BackupAlarm) { text = "Backup Alarm"; } base.Util.Label(text, num, num2); num2 += num3; float num8 = num5 - 12f; float num9 = num8 - 12f; if (!string.IsNullOrWhiteSpace(_toastMsg) && Time.unscaledTime < _toastUntil) { base.Util.Label(_toastMsg, num, num9); } if (base.Util.SimpleButtonRaw("Reset Defaults", num, num8)) { if (_page == Page.Handling) { if (Plugin.IsRallyModeActive()) { Plugin.ResetRallyTransmissionDefaults(); } else { Plugin.ResetTransmissionDefaults(); } Plugin.ResetHandlingDefaults(); } else if (_page == Page.Ignition) { Plugin.ResetIgnitionDefaults(); } else if (_page == Page.TurnSignals) { Plugin.ResetIndicatorDefaults(); } else if (_page == Page.BackupAlarm) { Plugin.ResetBackupAlarmDefaults(); } else if (_page == Page.Hud) { Plugin.ResetHudDefaults(); } else { Plugin.ResetTweaksDefaults(); } } num2 += num4; DrawPage(p, center, num, ref num2, num3); } private void DrawPage(Rect p, float center, float cx, ref float y, float line) { //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: 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) bool flag = Plugin.IsRallyModeActive(); bool flag2 = Plugin.IsManualTransmissionEnabledEffective(); if (_page == Page.Handling) { if (flag) { bool rallyManualTransmissionEnabled = Plugin.GetRallyManualTransmissionEnabled(); if (base.Util.CycleButtonRaw("Transmission", rallyManualTransmissionEnabled ? "Manual" : "Auto", center, y)) { Plugin.SetRallyManualTransmissionEnabled(!rallyManualTransmissionEnabled); } y += line; } else { if (base.Util.CycleButtonRaw("Transmission", flag2 ? "Manual" : "Auto", center, y)) { Plugin.ToggleManualTransmission(); } y += line; if (flag2) { int manualGearCount = Plugin.GetManualGearCount(); if (base.Util.CycleButtonRaw("Max Gears", manualGearCount.ToString(), center, y)) { Plugin.SetManualGearCount(Plugin.NextManualGearCount(manualGearCount)); } y += line; } } ShiftMode shiftMode = SebBindsApi.GetShiftMode(); if (base.Util.CycleButtonRaw("Shift Mode", SebBindsApi.GetShiftModeLabel(shiftMode), center, y)) { SebBindsApi.SetShiftMode(SebBindsApi.NextShiftMode(shiftMode)); } y += line; y += 2f; base.Util.Label(flag ? Plugin.GetCurrentRallyVariantLabel() : "Story Truck", cx, y); y += line; float handlingPowerMult = Plugin.GetHandlingPowerMult(); base.Util.ValueLabel($"{handlingPowerMult:0.00}x", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float? num = base.Util.Slider("Power", Mathf.InverseLerp(0.5f, 2f, handlingPowerMult), center, y, ref base.MouseYLock); if (num.HasValue) { Plugin.SetHandlingPowerMult(Mathf.Lerp(0.5f, 2f, num.Value)); } y += line; float handlingSpeedMult = Plugin.GetHandlingSpeedMult(); base.Util.ValueLabel($"{handlingSpeedMult:0.00}x", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float? num2 = base.Util.Slider("Top Speed", Mathf.InverseLerp(0.5f, 2f, handlingSpeedMult), center, y, ref base.MouseYLock); if (num2.HasValue) { Plugin.SetHandlingSpeedMult(Mathf.Lerp(0.5f, 2f, num2.Value)); } y += line; float handlingSteeringMult = Plugin.GetHandlingSteeringMult(); base.Util.ValueLabel($"{handlingSteeringMult:0.00}x", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float? num3 = base.Util.Slider("Steering", Mathf.InverseLerp(0.5f, 2f, handlingSteeringMult), center, y, ref base.MouseYLock); if (num3.HasValue) { Plugin.SetHandlingSteeringMult(Mathf.Lerp(0.5f, 2f, num3.Value)); } y += line; float handlingGripMult = Plugin.GetHandlingGripMult(); base.Util.ValueLabel($"{handlingGripMult:0.00}x", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float? num4 = base.Util.Slider("Grip", Mathf.InverseLerp(0.5f, 2f, handlingGripMult), center, y, ref base.MouseYLock); if (num4.HasValue) { Plugin.SetHandlingGripMult(Mathf.Lerp(0.5f, 2f, num4.Value)); } y += line; if (flag) { float handlingMassMult = Plugin.GetHandlingMassMult(); base.Util.ValueLabel($"{handlingMassMult:0.00}x", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float? num5 = base.Util.Slider("Mass", Mathf.InverseLerp(0.5f, 2f, handlingMassMult), center, y, ref base.MouseYLock); if (num5.HasValue) { Plugin.SetHandlingMassMult(Mathf.Lerp(0.5f, 2f, num5.Value)); } } else { float handlingDownforceMult = Plugin.GetHandlingDownforceMult(); base.Util.ValueLabel($"{handlingDownforceMult:0.00}x", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float? num6 = base.Util.Slider("Downforce", Mathf.InverseLerp(0f, 2f, handlingDownforceMult), center, y, ref base.MouseYLock); if (num6.HasValue) { Plugin.SetHandlingDownforceMult(Mathf.Lerp(0f, 2f, num6.Value)); } } y += line; return; } if (_page == Page.Ignition) { bool ignitionFeatureEnabled = Plugin.GetIgnitionFeatureEnabled(); if (base.Util.CycleButtonRaw("Ignition", ignitionFeatureEnabled ? "Enabled" : "Disabled", center, y)) { Plugin.SetIgnitionFeatureEnabled(!ignitionFeatureEnabled); } y += line; float ignitionHoldSeconds = Plugin.GetIgnitionHoldSeconds(); base.Util.ValueLabel($"{ignitionHoldSeconds:0.00}s", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float? num7 = base.Util.Slider("Ignition Time", Mathf.InverseLerp(0.25f, 3f, ignitionHoldSeconds), center, y, ref base.MouseYLock); if (num7.HasValue) { Plugin.SetIgnitionHoldSeconds(Mathf.Lerp(0.25f, 3f, num7.Value)); } y += line; bool ignitionSfxEnabled = Plugin.GetIgnitionSfxEnabled(); if (base.Util.CycleButtonRaw("Ignition SFX", ignitionSfxEnabled ? "On" : "Off", center, y)) { Plugin.SetIgnitionSfxEnabled(!ignitionSfxEnabled); } y += line; float ignitionSfxVolume = Plugin.GetIgnitionSfxVolume(); base.Util.ValueLabel($"{Mathf.RoundToInt(ignitionSfxVolume * 100f)}%", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float? num8 = base.Util.Slider("Ignition Vol.", ignitionSfxVolume, center, y, ref base.MouseYLock); if (num8.HasValue) { Plugin.SetIgnitionSfxVolume(num8.Value); } y += line; return; } if (_page == Page.TurnSignals) { bool indicatorFeatureEnabled = Plugin.GetIndicatorFeatureEnabled(); if (base.Util.CycleButtonRaw("Turn Signals", indicatorFeatureEnabled ? "Enabled" : "Disabled", center, y)) { Plugin.SetIndicatorFeatureEnabled(!indicatorFeatureEnabled); } y += line; float indicatorBlinkSeconds = Plugin.GetIndicatorBlinkSeconds(); base.Util.ValueLabel($"{indicatorBlinkSeconds:0.00}s", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float? num9 = base.Util.Slider("Blink Rate", Mathf.InverseLerp(0.2f, 1.2f, indicatorBlinkSeconds), center, y, ref base.MouseYLock); if (num9.HasValue) { Plugin.SetIndicatorBlinkSeconds(Mathf.Lerp(0.2f, 1.2f, num9.Value)); } y += line; float turnSignalLightIntensity = Plugin.GetTurnSignalLightIntensity(); base.Util.ValueLabel($"{turnSignalLightIntensity:0.00}", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float? num10 = base.Util.Slider("Intensity", Mathf.InverseLerp(0f, 1f, turnSignalLightIntensity), center, y, ref base.MouseYLock); if (num10.HasValue) { Plugin.SetTurnSignalLightIntensity(Mathf.Lerp(0f, 1f, num10.Value)); } y += line; bool indicatorSfxEnabled = Plugin.GetIndicatorSfxEnabled(); if (base.Util.CycleButtonRaw("Signal SFX", indicatorSfxEnabled ? "On" : "Off", center, y)) { Plugin.SetIndicatorSfxEnabled(!indicatorSfxEnabled); } y += line; float indicatorSfxVolume = Plugin.GetIndicatorSfxVolume(); base.Util.ValueLabel($"{Mathf.RoundToInt(indicatorSfxVolume * 100f)}%", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float? num11 = base.Util.Slider("Signal Vol.", indicatorSfxVolume, center, y, ref base.MouseYLock); if (num11.HasValue) { Plugin.SetIndicatorSfxVolume(num11.Value); } y += line; return; } if (_page == Page.BackupAlarm) { bool backupAlarmEnabled = Plugin.GetBackupAlarmEnabled(); if (base.Util.CycleButtonRaw("Backup Alarm", backupAlarmEnabled ? "On" : "Off", center, y)) { Plugin.SetBackupAlarmEnabled(!backupAlarmEnabled); } y += line; bool backupAlarmHazardsEnabled = Plugin.GetBackupAlarmHazardsEnabled(); if (base.Util.CycleButtonRaw("4-Ways", backupAlarmHazardsEnabled ? "On" : "Off", center, y)) { Plugin.SetBackupAlarmHazardsEnabled(!backupAlarmHazardsEnabled); } y += line; float backupAlarmVolume = Plugin.GetBackupAlarmVolume(); base.Util.ValueLabel($"{Mathf.RoundToInt(backupAlarmVolume * 100f)}%", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float? num12 = base.Util.Slider("Volume", backupAlarmVolume, center, y, ref base.MouseYLock); if (num12.HasValue) { Plugin.SetBackupAlarmVolume(num12.Value); } y += line; float backupAlarmInterval = Plugin.GetBackupAlarmInterval(); base.Util.ValueLabel($"{backupAlarmInterval:0.00}s", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float? num13 = base.Util.Slider("Beep Rate", Mathf.InverseLerp(1.2f, 0.35f, backupAlarmInterval), center, y, ref base.MouseYLock); if (num13.HasValue) { Plugin.SetBackupAlarmInterval(Mathf.Lerp(1.2f, 0.35f, num13.Value)); } y += line; float backupAlarmTone = Plugin.GetBackupAlarmTone(); base.Util.ValueLabel($"{Mathf.RoundToInt(backupAlarmTone)}hz", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float? num14 = base.Util.Slider("Tone", Mathf.InverseLerp(450f, 1800f, backupAlarmTone), center, y, ref base.MouseYLock); if (num14.HasValue) { Plugin.SetBackupAlarmTone(Mathf.Lerp(450f, 1800f, num14.Value)); } y += line; return; } if (_page == Page.Hud) { if (flag) { Plugin.SpeedUnit rallyHudSpeedUnit = Plugin.GetRallyHudSpeedUnit(); if (base.Util.CycleButtonRaw("Units", Plugin.GetHudSpeedUnitLabel(rallyHudSpeedUnit), center, y)) { Plugin.SetRallyHudSpeedUnit(Plugin.NextHudSpeedUnit(rallyHudSpeedUnit)); } y += line; base.Util.Label("Rally HUD always shown", cx, y); y += line; return; } Plugin.HudStyle hudStyle = Plugin.GetHudStyle(); if (base.Util.CycleButtonRaw("Style", Plugin.GetHudStyleLabel(hudStyle), center, y)) { Plugin.SetHudStyle(Plugin.NextHudStyle(hudStyle)); } y += line; Plugin.SpeedUnit hudSpeedUnit = Plugin.GetHudSpeedUnit(); if (base.Util.CycleButtonRaw("Units", Plugin.GetHudSpeedUnitLabel(hudSpeedUnit), center, y)) { Plugin.SetHudSpeedUnit(Plugin.NextHudSpeedUnit(hudSpeedUnit)); } y += line; bool hudShowSpeed = Plugin.GetHudShowSpeed(); bool? flag3 = base.Util.Toggle("Speedomtr", hudShowSpeed, center, y); if (flag3.HasValue) { Plugin.SetHudShowSpeed(flag3.Value); } y += line; if (flag2) { bool hudShowTach = Plugin.GetHudShowTach(); bool? flag4 = base.Util.Toggle("Tachomtr", hudShowTach, center, y); if (flag4.HasValue) { Plugin.SetHudShowTach(flag4.Value); } y += line; bool hudShowGear = Plugin.GetHudShowGear(); bool? flag5 = base.Util.Toggle("Gear Ind", hudShowGear, center, y); if (flag5.HasValue) { Plugin.SetHudShowGear(flag5.Value); } y += line; } if (hudStyle != Plugin.HudStyle.Classic) { return; } Plugin.HudReadoutAnchor hudSpeedAnchor = Plugin.GetHudSpeedAnchor(); if (base.Util.CycleButtonRaw("Speedomtr Pos", Plugin.GetHudReadoutAnchorLabel(hudSpeedAnchor), center, y)) { Plugin.SetHudSpeedAnchor(Plugin.NextHudReadoutAnchor(hudSpeedAnchor)); } y += line; if (flag2) { Plugin.HudReadoutAnchor hudTachAnchor = Plugin.GetHudTachAnchor(); if (base.Util.CycleButtonRaw("Tachomtr Pos", Plugin.GetHudReadoutAnchorLabel(hudTachAnchor), center, y)) { Plugin.SetHudTachAnchor(Plugin.NextHudReadoutAnchor(hudTachAnchor)); } y += line; Plugin.HudReadoutAnchor hudGearAnchor = Plugin.GetHudGearAnchor(); if (base.Util.CycleButtonRaw("Gear Ind. Pos", Plugin.GetHudReadoutAnchorLabel(hudGearAnchor), center, y)) { Plugin.SetHudGearAnchor(Plugin.NextHudReadoutAnchor(hudGearAnchor)); } } return; } float manualSpeedMultForward = Plugin.GetManualSpeedMultForward(); base.Util.ValueLabel($"{Mathf.RoundToInt(manualSpeedMultForward * 100f)}%", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float num15 = Mathf.InverseLerp(0.5f, 1.5f, manualSpeedMultForward); float? num16 = base.Util.Slider("Speed Mult.", num15, center, y, ref base.MouseYLock); if (num16.HasValue) { Plugin.SetManualSpeedMultForward(Mathf.Lerp(0.5f, 1.5f, num16.Value)); } y += line; float manualSpeedMultReverse = Plugin.GetManualSpeedMultReverse(); base.Util.ValueLabel($"{Mathf.RoundToInt(manualSpeedMultReverse * 100f)}%", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float num17 = Mathf.InverseLerp(0.5f, 1.5f, manualSpeedMultReverse); float? num18 = base.Util.Slider("Revrs Mult.", num17, center, y, ref base.MouseYLock); if (num18.HasValue) { Plugin.SetManualSpeedMultReverse(Mathf.Lerp(0.5f, 1.5f, num18.Value)); } y += line; float headlightIntensityMult = Plugin.GetHeadlightIntensityMult(); base.Util.ValueLabel($"{headlightIntensityMult:0.00}x", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float num19 = Mathf.InverseLerp(0.25f, 2f, headlightIntensityMult); float? num20 = base.Util.Slider("Headlgt Bright", num19, center, y, ref base.MouseYLock); if (num20.HasValue) { Plugin.SetHeadlightIntensityMult(Mathf.Lerp(0.25f, 2f, num20.Value)); } y += line; float headlightRangeMult = Plugin.GetHeadlightRangeMult(); base.Util.ValueLabel($"{headlightRangeMult:0.00}x", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float num21 = Mathf.InverseLerp(0.25f, 1f, headlightRangeMult); float? num22 = base.Util.Slider("Headlght Dist", num21, center, y, ref base.MouseYLock); if (num22.HasValue) { Plugin.SetHeadlightRangeMult(Mathf.Lerp(0.25f, 1f, num22.Value)); } y += line; y += 2f; base.Util.Label("Cosmetics", cx, y); y += line; float wheelScale = Plugin.GetWheelScale(); base.Util.ValueLabel($"{wheelScale:0.00}x", ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f, y); float num23 = Mathf.InverseLerp(0.5f, 2f, wheelScale); float? num24 = base.Util.Slider("Wheel Scale", num23, center, y, ref base.MouseYLock); if (num24.HasValue) { Plugin.SetWheelScale(Mathf.Lerp(0.5f, 2f, num24.Value)); } y += line; int selectedBobbleIndexUnlockedOrNone = Plugin.GetSelectedBobbleIndexUnlockedOrNone(); if (base.Util.CycleButtonRaw("Bobblehead", Plugin.GetBobbleLabel(selectedBobbleIndexUnlockedOrNone), center, y)) { if (!Plugin.HasAnyUnlockedBobbleheads()) { _toastMsg = "No Bobbleheads unlocked."; _toastUntil = Time.unscaledTime + 2f; } else { Plugin.CycleBobbleheadSelection(); } } y += line; int selectedPaintIndexUnlockedOrDefault = Plugin.GetSelectedPaintIndexUnlockedOrDefault(); if (base.Util.CycleButtonRaw("Truck Paint", Plugin.GetPaintLabel(selectedPaintIndexUnlockedOrDefault), center, y)) { if (!Plugin.HasAnyUnlockedPaints()) { _toastMsg = "No Paints unlocked."; _toastUntil = Time.unscaledTime + 2f; } else { Plugin.CyclePaintSelection(); } } } } }