Decompiled source of Rains Car Mod IL2CPP v1.0.4

Mods/RainsCarMod.dll

Decompiled 10 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2CppFishNet;
using Il2CppFishNet.Connection;
using Il2CppFishNet.Managing.Object;
using Il2CppFishNet.Object;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Interaction;
using Il2CppScheduleOne.Money;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.UI;
using Il2CppScheduleOne.Vehicles;
using Il2CppSystem.Collections.Generic;
using Il2CppTMPro;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using RainsCarMod;
using RainsCarMod.Logging;
using RainsCarMod.RainsCarMod;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(CarLoader), "RainsCarModil2cpp", "1.0.4", "RainingDeath", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RainsCarMod")]
[assembly: AssemblyConfiguration("DebugMelon")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RainsCarMod")]
[assembly: AssemblyTitle("RainsCarMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 RainsCarMod
{
	public class Core : MelonMod
	{
		public override void OnInitializeMelon()
		{
			Log.LogInfo("Initializing RainsCarMod...");
		}
	}
	public class DealerConfig
	{
		public bool enableDealership = true;

		public static DealerConfig Instance;

		public static void Load()
		{
			string text = Path.Combine(MelonEnvironment.UserDataDirectory, "RainsCarMod");
			string path = Path.Combine(text, "Dealer_Config.json");
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			if (!File.Exists(path))
			{
				Instance = new DealerConfig();
				File.WriteAllText(path, JsonConvert.SerializeObject((object)Instance, (Formatting)1));
				MelonLogger.Msg("[RainsCarMod] Created default Dealer_Config.json");
				return;
			}
			try
			{
				string text2 = File.ReadAllText(path);
				Instance = JsonConvert.DeserializeObject<DealerConfig>(text2) ?? new DealerConfig();
				MelonLogger.Msg("[RainsCarMod] Loaded Dealer_Config.json");
			}
			catch
			{
				MelonLogger.Warning("[RainsCarMod] Failed to parse Dealer_Config.json, using defaults.");
				Instance = new DealerConfig();
			}
		}
	}
	public class CarLoader : MelonMod
	{
		[CompilerGenerated]
		private sealed class <DelayedSceneInit>d__11 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public CarLoader <>4__this;

			private GameObject <buildingPrefab>5__1;

			private GameObject <computerPrefab>5__2;

			private GameObject <building>5__3;

			private GameObject <computer>5__4;

			private UIManager <uiManager>5__5;

			private CarDealerInterface <comp>5__6;

			private InteractableObject <intObj>5__7;

			private Canvas <canvas>5__8;

			private Transform <camPos>5__9;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DelayedSceneInit>d__11(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<buildingPrefab>5__1 = null;
				<computerPrefab>5__2 = null;
				<building>5__3 = null;
				<computer>5__4 = null;
				<uiManager>5__5 = null;
				<comp>5__6 = null;
				<intObj>5__7 = null;
				<canvas>5__8 = null;
				<camPos>5__9 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0110: Unknown result type (might be due to invalid IL or missing references)
				//IL_0115: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if ((Object)(object)NetworkSingleton<VehicleManager>.Instance == (Object)null || NetworkSingleton<VehicleManager>.Instance.VehiclePrefabs == null)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				ClassInjector.RegisterTypeInIl2Cpp<UIManager>();
				ClassInjector.RegisterTypeInIl2Cpp<CarDealerInterface>();
				<>4__this.LoadAndRetainAssetBundle();
				<>4__this.InjectVehiclePrefabs();
				if (!DealerConfig.Instance.enableDealership)
				{
					MelonLogger.Msg("\ud83d\uded1 Dealership injection skipped due to config setting.");
					return false;
				}
				if (!LoadedPrefabs.TryGetValue("CarDealership", out <buildingPrefab>5__1))
				{
					MelonLogger.Warning("❌ CarDealership not found. Retrying bundle registration...");
					<>4__this.LoadAndRetainAssetBundle();
					<>4__this.RegisterAssetsFromBundle();
					LoadedPrefabs.TryGetValue("CarDealership", out <buildingPrefab>5__1);
				}
				if ((Object)(object)<buildingPrefab>5__1 != (Object)null)
				{
					<building>5__3 = Object.Instantiate<GameObject>(<buildingPrefab>5__1, mapExtensionPosition, mapExtensionRotation);
					((Object)<building>5__3).name = "CarDealership";
					<>4__this.SetAllChildrenActive(<building>5__3, state: true);
					<building>5__3 = null;
				}
				else
				{
					MelonLogger.Error("❌ CarDealership prefab still not found after retry.");
				}
				if (!LoadedPrefabs.TryGetValue("CarDealerComputer", out <computerPrefab>5__2))
				{
					MelonLogger.Warning("❌ CarDealerComputer not found. Retrying bundle registration...");
					<>4__this.RegisterAssetsFromBundle();
					LoadedPrefabs.TryGetValue("CarDealerComputer", out <computerPrefab>5__2);
				}
				if ((Object)(object)<computerPrefab>5__2 != (Object)null)
				{
					<computer>5__4 = Object.Instantiate<GameObject>(<computerPrefab>5__2, new Vector3(-60.05f, -1.05f, -16.22f), Quaternion.Euler(0f, 150f, 0f));
					((Object)<computer>5__4).name = "CarDealerComputer";
					<computer>5__4.SetActive(true);
					MelonLogger.Msg("\ud83d\udcbb Injected CarDealerComputer.");
					<uiManager>5__5 = (<computer>5__4.GetComponent("RainsCarMod.UIManager") as UIManager) ?? <computer>5__4.AddComponent<UIManager>();
					if ((Object)(object)<uiManager>5__5 != (Object)null)
					{
						MelonLogger.Msg("\ud83e\udde9 Attached UIManager.");
					}
					else
					{
						MelonLogger.Warning("❌ Failed to attach UIManager.");
					}
					<comp>5__6 = <computer>5__4.AddComponent<CarDealerInterface>();
					if ((Object)(object)<comp>5__6 == (Object)null)
					{
						MelonLogger.Error("❌ Failed to attach CarDealerInterface.");
						return false;
					}
					<intObj>5__7 = <computer>5__4.GetComponent<InteractableObject>();
					<canvas>5__8 = <computer>5__4.GetComponentInChildren<Canvas>(true);
					<camPos>5__9 = <>4__this.FindDeepChild(<computer>5__4.transform, "CameraPosition");
					<comp>5__6.intObj = (Component)(object)<intObj>5__7;
					<comp>5__6.canvas = <canvas>5__8;
					<comp>5__6.cameraPosition = <camPos>5__9;
					CarDealerInterface.OnUIRequested = delegate
					{
						GameObject val = GameObject.Find("CarDealerComputer");
						((val != null) ? val.GetComponentInChildren<UIManager>(true) : null)?.ShowUI();
					};
					MelonLogger.Msg("✅ Fully injected CarDealerInterface.");
					<computer>5__4 = null;
					<uiManager>5__5 = null;
					<comp>5__6 = null;
					<intObj>5__7 = null;
					<canvas>5__8 = null;
					<camPos>5__9 = null;
				}
				else
				{
					MelonLogger.Error("❌ CarDealerComputer prefab still not found after retry.");
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static readonly Dictionary<string, GameObject> LoadedPrefabs = new Dictionary<string, GameObject>();

		public static readonly Dictionary<string, Object> LoadedAssets = new Dictionary<string, Object>();

		private static Il2CppAssetBundle il2cppAssetBundle;

		private static GameObject bundleRetentionObject;

		private static GameObject _keeperRoot;

		public static readonly Vector3 mapExtensionPosition = new Vector3(-51.5491f, 19.9f, -27.9102f);

		public static readonly Quaternion mapExtensionRotation = Quaternion.Euler(270f, 150f, 0f);

		public static readonly Vector3 carSpawnPosition = new Vector3(-46.45f, -1.5f, -31.62f);

		public static readonly Quaternion carSpawnRotation = Quaternion.Euler(0f, 210f, 0f);

		public override void OnApplicationStart()
		{
			LoadAndRetainAssetBundle(loadAssets: false);
			DealerConfig.Load();
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (!(sceneName != "Main"))
			{
				MelonCoroutines.Start(DelayedSceneInit());
			}
		}

		[IteratorStateMachine(typeof(<DelayedSceneInit>d__11))]
		private IEnumerator DelayedSceneInit()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayedSceneInit>d__11(0)
			{
				<>4__this = this
			};
		}

		private void LoadAndRetainAssetBundle(bool loadAssets = true)
		{
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			if (il2cppAssetBundle != null)
			{
				MelonLogger.Msg("ℹ\ufe0f Bundle already loaded.");
				if (loadAssets)
				{
					MelonLogger.Msg("\ud83d\udd01 Re-registering all assets...");
					RegisterAssetsFromBundle();
				}
				return;
			}
			try
			{
				Assembly assembly = typeof(CarLoader).Assembly;
				using Stream stream = assembly.GetManifestResourceStream("RainsCarMod.Resources.carmod");
				if (stream == null)
				{
					MelonLogger.Error("❌ Failed to find embedded resource: RainsCarMod.Resources.carmod");
					return;
				}
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				il2cppAssetBundle = Il2CppAssetBundleManager.LoadFromMemory(Il2CppStructArray<byte>.op_Implicit(array));
				if (il2cppAssetBundle == null)
				{
					MelonLogger.Error("❌ Failed to load AssetBundle from embedded resource.");
					return;
				}
				MelonLogger.Msg("✅ Loaded embedded AssetBundle.");
				if (_keeperRoot == null)
				{
					_keeperRoot = new GameObject("CarMod_AssetKeeper")
					{
						hideFlags = (HideFlags)61
					};
				}
				Object.DontDestroyOnLoad((Object)(object)_keeperRoot);
				foreach (Object item in (Il2CppArrayBase<Object>)(object)il2cppAssetBundle.LoadAllAssets())
				{
					item.hideFlags = (HideFlags)61;
				}
				if (loadAssets)
				{
					RegisterAssetsFromBundle();
				}
			}
			catch (Exception value)
			{
				MelonLogger.Error($"❌ Exception during embedded AssetBundle load: {value}");
			}
		}

		private void RegisterAssetsFromBundle()
		{
			GameObject[] array = Il2CppArrayBase<GameObject>.op_Implicit((Il2CppArrayBase<GameObject>)(object)il2cppAssetBundle.LoadAllAssets<GameObject>());
			if (array == null || array.Length == 0)
			{
				MelonLogger.Warning("⚠\ufe0f LoadAllAssets<GameObject>() returned nothing. Trying fallback via GetAllAssetNames...");
				{
					foreach (string item in (Il2CppArrayBase<string>)(object)il2cppAssetBundle.GetAllAssetNames())
					{
						try
						{
							GameObject[] array2 = Il2CppArrayBase<GameObject>.op_Implicit((Il2CppArrayBase<GameObject>)(object)il2cppAssetBundle.LoadAssetWithSubAssets<GameObject>(item));
							GameObject[] array3 = array2;
							foreach (GameObject asset in array3)
							{
								RegisterAsset((Object)(object)asset);
							}
						}
						catch (Exception ex)
						{
							MelonLogger.Error("❌ Failed to load sub-assets from " + item + ": " + ex.Message);
						}
					}
					return;
				}
			}
			GameObject[] array4 = array;
			foreach (GameObject asset2 in array4)
			{
				RegisterAsset((Object)(object)asset2);
			}
		}

		private void RegisterAsset(Object asset)
		{
			if (asset == (Object)null)
			{
				return;
			}
			string text = asset.name?.Trim();
			if (string.IsNullOrEmpty(text))
			{
				return;
			}
			if (!LoadedAssets.ContainsKey(text))
			{
				LoadedAssets[text] = asset;
			}
			GameObject val = (GameObject)(object)((asset is GameObject) ? asset : null);
			if (val != null && !LoadedPrefabs.ContainsKey(text))
			{
				LoadedPrefabs[text] = val;
				if (text.ToLowerInvariant().Contains("dealership") && (Object)(object)val.GetComponent<UIManager>() != (Object)null)
				{
					LoadedPrefabs["CarDealership"] = val;
				}
				else if (text.ToLowerInvariant().Contains("computer") && (Object)(object)val.GetComponent<CarDealerInterface>() != (Object)null)
				{
					LoadedPrefabs["CarDealerComputer"] = val;
				}
				GameObject val2 = Object.Instantiate<GameObject>(val);
				((Object)val2).name = "KEEP_" + text;
				val2.transform.SetParent(_keeperRoot.transform);
				val2.SetActive(false);
				((Object)val2).hideFlags = (HideFlags)61;
			}
		}

		private void InjectVehiclePrefabs()
		{
			VehicleManager instance = NetworkSingleton<VehicleManager>.Instance;
			List<LandVehicle> val = ((instance != null) ? instance.VehiclePrefabs : null);
			if (val == null)
			{
				MelonLogger.Error("❌ VehicleManager.VehiclePrefabs is null.");
				return;
			}
			foreach (KeyValuePair<string, GameObject> loadedPrefab in LoadedPrefabs)
			{
				loadedPrefab.Deconstruct(out var key, out var value);
				string text = key;
				GameObject val2 = value;
				bool flag = false;
				Enumerator<LandVehicle> enumerator2 = val.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					LandVehicle current = enumerator2.Current;
					if (((current != null) ? ((Object)current).name : null) == text)
					{
						flag = true;
						break;
					}
				}
				if (flag)
				{
					continue;
				}
				LandVehicle component = val2.GetComponent<LandVehicle>();
				if (!((Object)(object)component == (Object)null))
				{
					((Object)val2).name = text;
					component.vehicleName = text;
					if (!val.Contains(component))
					{
						val.Add(component);
					}
					NetworkObject component2 = val2.GetComponent<NetworkObject>();
					if ((Object)(object)component2 != (Object)null)
					{
						RegisterWithFishNet(component2, text);
					}
					else
					{
						MelonLogger.Warning("⚠\ufe0f " + text + " is missing NetworkObject.");
					}
				}
			}
		}

		private void RegisterWithFishNet(NetworkObject netObj, string prefabKey)
		{
			PrefabObjects spawnablePrefabs = InstanceFinder.NetworkManager.SpawnablePrefabs;
			if ((Object)(object)spawnablePrefabs == (Object)null)
			{
				MelonLogger.Error("❌ NetworkManager.SpawnablePrefabs is null.");
				return;
			}
			Type type = ((object)spawnablePrefabs).GetType();
			MethodInfo method = type.GetMethod("AddObject", BindingFlags.Instance | BindingFlags.Public, null, new Type[2]
			{
				typeof(NetworkObject),
				typeof(bool)
			}, null);
			if (method == null)
			{
				MelonLogger.Error("❌ Failed to find AddObject(NetworkObject, bool) method on SpawnablePrefabs.");
				return;
			}
			method.Invoke(spawnablePrefabs, new object[2] { netObj, false });
		}

		private void SetAllChildrenActive(GameObject parent, bool state)
		{
			List<Transform> list = new List<Transform>();
			CollectChildTransformsRecursive(parent.transform, list);
			foreach (Transform item in list)
			{
				if ((Object)(object)item != (Object)null)
				{
					((Component)item).gameObject.SetActive(state);
				}
			}
		}

		private void CollectChildTransformsRecursive(Transform parent, List<Transform> list)
		{
			if (!((Object)(object)parent == (Object)null) && list != null)
			{
				list.Add(parent);
				for (int i = 0; i < parent.childCount; i++)
				{
					CollectChildTransformsRecursive(parent.GetChild(i), list);
				}
			}
		}

		private Transform FindDeepChild(Transform parent, string name)
		{
			int childCount = parent.childCount;
			for (int i = 0; i < childCount; i++)
			{
				Transform child = parent.GetChild(i);
				if (((Object)child).name == name)
				{
					return child;
				}
				Transform val = FindDeepChild(child, name);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(InteractableObject), "StartInteract")]
	public static class InteractStartPatch
	{
		public static void Postfix(InteractableObject __instance)
		{
			if (((Object)((Component)__instance).gameObject).name == "CarDealerComputer" && !((Object)(object)CarDealerInterface.Instance == (Object)null))
			{
				if (CarDealerInterface.Instance.IsOpen)
				{
					CarDealerInterface.Instance.Close();
				}
				else
				{
					CarDealerInterface.Instance.Open();
				}
			}
		}
	}
	[Serializable]
	public class VehiclePriceEntry
	{
		public string name;

		public int price;
	}
	[Serializable]
	public class VehiclePriceWrapper
	{
		public List<VehiclePriceEntry> Entries;

		public Dictionary<string, int> ToDictionary()
		{
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			if (Entries != null)
			{
				foreach (VehiclePriceEntry entry in Entries)
				{
					if (!string.IsNullOrEmpty(entry.name))
					{
						dictionary[entry.name.Replace(" ", "_")] = entry.price;
					}
				}
			}
			return dictionary;
		}
	}
	public class UIManager : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <HideInsufficientFundsMessageCoroutine>d__21 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public UIManager <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <HideInsufficientFundsMessageCoroutine>d__21(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(0.75f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.HideInsufficientFundsMessage();
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <HideThankYouMessageCoroutine>d__19 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public UIManager <>4__this;

			private Transform <popup>5__1;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <HideThankYouMessageCoroutine>d__19(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<popup>5__1 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(1.25f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<popup>5__1 = <>4__this.FindDeepChild(((Component)<>4__this).transform, "ThankYouPopup");
					if ((Object)(object)<popup>5__1 != (Object)null)
					{
						((Component)<popup>5__1).gameObject.SetActive(false);
					}
					<>4__this.HandleClose();
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private string pendingPrefabKey = null;

		private GameObject confirmPopup;

		private static Dictionary<string, int> VehiclePrices = new Dictionary<string, int>();

		public static Action OnUICloseRequested;

		private TextMeshProUGUI confirmPopupLabel;

		public TMP_FontAsset liberationFont;

		private Transform uiRoot;

		private Image vehicleIconImage;

		private Dictionary<string, string> buttonToPrefabKey = new Dictionary<string, string>();

		private void Start()
		{
			if (!DealerConfig.Instance.enableDealership)
			{
				MelonLogger.Msg("\ud83d\uded1 UIManager.Start skipped because dealership is disabled.");
				return;
			}
			uiRoot = FindDeepChild(((Component)this).transform, "Panel");
			if (!((Object)(object)uiRoot == (Object)null))
			{
				SetupConfirmPopup();
				LoadVehiclePricesFromJson();
				AddButtonListener("Buy Bugatti Tourbillon", "Bugatti_Tourbillon");
				AddButtonListener("Buy GTR R35", "GTR_R35");
				AddButtonListener("Buy GTR R34", "GTR_R34");
				AddButtonListener("Buy Demon", "Demon");
				AddButtonListener("Buy Rolls Royce Ghost", "Rolls_Royce_Ghost");
				AddButtonListener("Buy Driftcar", "driftcar");
				AddButtonListener("Buy Supercar", "supercar");
				AddButtonListener("Buy Soup Car", "canofsoupcar");
				AddButtonListener("Buy Lamborghini Veneno", "Lamborghini_Veneno");
				AddButtonListener("Buy Cyber Truck", "Cyber_Truck");
				AddButtonListener("Buy Koenigsegg CC850", "Koenigsegg_CC850");
				AddButtonListener("Buy Lancia Delta", "Lancia_Delta");
				AddButtonListener("Buy El Camino", "El_Camino");
				AddCloseListener("Close");
			}
		}

		private void SetupConfirmPopup()
		{
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			Transform obj = FindDeepChild(((Component)this).transform, "PurchaseConfirmPopup");
			confirmPopup = ((obj != null) ? ((Component)obj).gameObject : null);
			if ((Object)(object)confirmPopup == (Object)null)
			{
				MelonLogger.Warning("❌ Could not find PurchaseConfirmPopup.");
				return;
			}
			confirmPopup.SetActive(false);
			Transform obj2 = FindDeepChild(confirmPopup.transform, "VehicleIcon");
			vehicleIconImage = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null);
			Transform val = FindDeepChild(confirmPopup.transform, "ConfirmPurchaseText");
			if ((Object)(object)val != (Object)null)
			{
				confirmPopupLabel = ((Component)val).GetComponentInChildren<TextMeshProUGUI>(true);
				if ((Object)(object)confirmPopupLabel != (Object)null)
				{
					if ((Object)(object)liberationFont == (Object)null)
					{
						liberationFont = ((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => ((Object)f).name.Contains("LiberationSans")));
					}
					if ((Object)(object)liberationFont != (Object)null)
					{
						((TMP_Text)confirmPopupLabel).font = liberationFont;
						((TMP_Text)confirmPopupLabel).enableAutoSizing = true;
						((TMP_Text)confirmPopupLabel).fontSizeMin = 6f;
						((TMP_Text)confirmPopupLabel).fontSizeMax = 80f;
						((Graphic)confirmPopupLabel).color = Color.black;
						((TMP_Text)confirmPopupLabel).alignment = (TextAlignmentOptions)514;
						((TMP_Text)confirmPopupLabel).overflowMode = (TextOverflowModes)0;
						((Behaviour)confirmPopupLabel).enabled = true;
					}
					else
					{
						MelonLogger.Warning("⚠\ufe0f Liberation font not found. ConfirmPurchaseText may be invisible.");
					}
				}
				else
				{
					MelonLogger.Warning("❌ Found ConfirmPurchaseText object but not its TMP child.");
				}
			}
			else
			{
				MelonLogger.Warning("❌ Could not find ConfirmPurchaseText object.");
			}
			Transform val2 = FindDeepChild(confirmPopup.transform, "ConfirmPurchaseButton");
			Button val3 = default(Button);
			if ((Object)(object)val2 != (Object)null && ((Component)val2).TryGetComponent<Button>(ref val3))
			{
				((UnityEventBase)val3.onClick).RemoveAllListeners();
				UnityAction val4 = DelegateSupport.ConvertDelegate<UnityAction>((Delegate)new Action(ConfirmPurchase));
				((UnityEvent)val3.onClick).AddListener(val4);
				TextMeshProUGUI componentInChildren = ((Component)val2).GetComponentInChildren<TextMeshProUGUI>(true);
				if ((Object)(object)componentInChildren != (Object)null && (Object)(object)liberationFont != (Object)null)
				{
					((TMP_Text)componentInChildren).font = liberationFont;
					((TMP_Text)componentInChildren).text = "CONFIRM";
					((TMP_Text)componentInChildren).fontSize = 60f;
					((Graphic)componentInChildren).color = Color.black;
					((TMP_Text)componentInChildren).alignment = (TextAlignmentOptions)514;
					((TMP_Text)componentInChildren).overflowMode = (TextOverflowModes)0;
					((TMP_Text)componentInChildren).ForceMeshUpdate(false, false);
				}
			}
			Transform val5 = FindDeepChild(confirmPopup.transform, "CancelPurchaseButton");
			Button val6 = default(Button);
			if ((Object)(object)val5 != (Object)null && ((Component)val5).TryGetComponent<Button>(ref val6))
			{
				((UnityEventBase)val6.onClick).RemoveAllListeners();
				UnityAction val7 = DelegateSupport.ConvertDelegate<UnityAction>((Delegate)new Action(CancelPurchase));
				((UnityEvent)val6.onClick).AddListener(val7);
				TextMeshProUGUI componentInChildren2 = ((Component)val5).GetComponentInChildren<TextMeshProUGUI>(true);
				if ((Object)(object)componentInChildren2 != (Object)null && (Object)(object)liberationFont != (Object)null)
				{
					((TMP_Text)componentInChildren2).font = liberationFont;
					((TMP_Text)componentInChildren2).text = "CANCEL";
					((TMP_Text)componentInChildren2).fontSize = 60f;
					((Graphic)componentInChildren2).color = Color.black;
					((TMP_Text)componentInChildren2).alignment = (TextAlignmentOptions)514;
					((TMP_Text)componentInChildren2).overflowMode = (TextOverflowModes)0;
					((TMP_Text)componentInChildren2).ForceMeshUpdate(false, false);
				}
			}
		}

		private void AddButtonListener(string buttonName, string prefabKey)
		{
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			Transform val = FindDeepChild(uiRoot, buttonName);
			Button val2 = default(Button);
			if ((Object)(object)val == (Object)null || !((Component)val).TryGetComponent<Button>(ref val2))
			{
				MelonLogger.Warning("❌ Could not find button: " + buttonName);
				return;
			}
			if (!buttonToPrefabKey.ContainsKey(buttonName))
			{
				buttonToPrefabKey[buttonName] = prefabKey;
			}
			((UnityEventBase)val2.onClick).RemoveAllListeners();
			Action action = delegate
			{
				HandlePurchaseRequestInternal(prefabKey, buttonName);
			};
			UnityAction val3 = DelegateSupport.ConvertDelegate<UnityAction>((Delegate)action);
			((UnityEvent)val2.onClick).AddListener(val3);
			TextMeshProUGUI componentInChildren = ((Component)val).GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				if ((Object)(object)liberationFont == (Object)null)
				{
					liberationFont = ((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => ((Object)f).name.Contains("LiberationSans")));
					if (!((Object)(object)liberationFont != (Object)null))
					{
						MelonLogger.Warning("⚠\ufe0f Could not locate in-game LiberationSans font asset.");
						return;
					}
					MelonLogger.Msg("✅ Found in-game TMP font asset: " + ((Object)liberationFont).name);
				}
				((TMP_Text)componentInChildren).font = liberationFont;
				((TMP_Text)componentInChildren).text = "Buy " + prefabKey.Replace("_", " ");
				((TMP_Text)componentInChildren).enableAutoSizing = true;
				((TMP_Text)componentInChildren).fontSizeMin = 5f;
				((TMP_Text)componentInChildren).fontSizeMax = 60f;
				((TMP_Text)componentInChildren).overflowMode = (TextOverflowModes)0;
				((TMP_Text)componentInChildren).enableWordWrapping = true;
				((TMP_Text)componentInChildren).alignment = (TextAlignmentOptions)514;
				((Graphic)componentInChildren).color = new Color(0f, 0f, 0f, 1f);
				((Behaviour)componentInChildren).enabled = true;
				((TMP_Text)componentInChildren).ForceMeshUpdate(false, false);
				RectTransform component = ((Component)componentInChildren).GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					component.offsetMin = new Vector2(3f, 3f);
					component.offsetMax = new Vector2(-3f, -3f);
				}
			}
			else
			{
				MelonLogger.Warning("❌ No TMP label found under: " + buttonName);
			}
		}

		private void HandlePurchaseRequestInternal(string prefabKey, string buttonName)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			if (!VehiclePrices.TryGetValue(prefabKey, out var value))
			{
				value = 500;
			}
			pendingPrefabKey = prefabKey;
			Transform val = FindDeepChild(((Component)this).transform, buttonName);
			Transform obj = FindDeepChild(((Component)val).transform, "VehicleIcon");
			Image val2 = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null);
			if ((Object)(object)val2 != (Object)null && (Object)(object)vehicleIconImage != (Object)null)
			{
				vehicleIconImage.sprite = val2.sprite;
				((Graphic)vehicleIconImage).color = Color.white;
				vehicleIconImage.preserveAspect = true;
			}
			if ((Object)(object)confirmPopupLabel != (Object)null)
			{
				((TMP_Text)confirmPopupLabel).text = "Buy " + prefabKey.Replace("_", " ") + " for $" + value.ToString("N0");
				((TMP_Text)confirmPopupLabel).ForceMeshUpdate(false, false);
			}
			GameObject obj2 = confirmPopup;
			if (obj2 != null)
			{
				obj2.SetActive(true);
			}
			confirmPopup.transform.SetAsLastSibling();
		}

		private void AddCloseListener(string name)
		{
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			Transform val = FindDeepChild(uiRoot, name);
			Button val2 = default(Button);
			if ((Object)(object)val == (Object)null || !((Component)val).TryGetComponent<Button>(ref val2))
			{
				MelonLogger.Warning("❌ Could not find close button: " + name);
				return;
			}
			((UnityEventBase)val2.onClick).RemoveAllListeners();
			Action action = HandleClose;
			UnityAction val3 = DelegateSupport.ConvertDelegate<UnityAction>((Delegate)action);
			((UnityEvent)val2.onClick).AddListener(val3);
			TextMeshProUGUI componentInChildren = ((Component)val).GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				if ((Object)(object)liberationFont == (Object)null)
				{
					liberationFont = ((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => ((Object)f).name.Contains("LiberationSans")));
					if (!((Object)(object)liberationFont != (Object)null))
					{
						MelonLogger.Warning("⚠\ufe0f Liberation font not found for CLOSE button, skipping label assignment.");
						return;
					}
					MelonLogger.Msg("✅ Found in-game TMP font asset for CLOSE: " + ((Object)liberationFont).name);
				}
				((TMP_Text)componentInChildren).font = liberationFont;
				((TMP_Text)componentInChildren).text = "CLOSE";
				((TMP_Text)componentInChildren).enableAutoSizing = true;
				((TMP_Text)componentInChildren).fontSizeMin = 5f;
				((TMP_Text)componentInChildren).fontSizeMax = 65f;
				((Graphic)componentInChildren).color = Color.black;
				((Behaviour)componentInChildren).enabled = true;
				((TMP_Text)componentInChildren).alignment = (TextAlignmentOptions)514;
				((TMP_Text)componentInChildren).overflowMode = (TextOverflowModes)0;
				((TMP_Text)componentInChildren).ForceMeshUpdate(false, false);
				RectTransform component = ((Component)componentInChildren).GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					component.offsetMin = new Vector2(10f, 5f);
					component.offsetMax = new Vector2(-10f, -5f);
				}
			}
			else
			{
				MelonLogger.Warning("❌ No TMP component found under close button.");
			}
		}

		private void HandleClose()
		{
			OnUICloseRequested?.Invoke();
			Cursor.lockState = (CursorLockMode)1;
			Cursor.visible = false;
		}

		private void CancelPurchase()
		{
			confirmPopup.SetActive(false);
			pendingPrefabKey = null;
		}

		private void ConfirmPurchase()
		{
			confirmPopup.SetActive(false);
			if (!string.IsNullOrEmpty(pendingPrefabKey))
			{
				if (!VehiclePrices.TryGetValue(pendingPrefabKey, out var value))
				{
					value = 500;
				}
				MoneyManager instance = NetworkSingleton<MoneyManager>.Instance;
				if (instance.cashBalance < (float)value)
				{
					ShowInsufficientFundsMessage();
					return;
				}
				TrySpawnVehicle(pendingPrefabKey, InstanceFinder.ClientManager.Connection);
				ShowThankYouMessage();
				pendingPrefabKey = null;
			}
		}

		public void ShowUI()
		{
			Cursor.visible = true;
			Cursor.lockState = (CursorLockMode)0;
		}

		private void ShowThankYouMessage()
		{
			//IL_00ff: 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_0169: Unknown result type (might be due to invalid IL or missing references)
			Transform val = FindDeepChild(((Component)this).transform, "ThankYouPopup");
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Warning("❌ ThankYouPopup not found.");
				return;
			}
			TextMeshProUGUI componentInChildren = ((Component)val).GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				if ((Object)(object)liberationFont == (Object)null)
				{
					liberationFont = ((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => ((Object)f).name.Contains("LiberationSans")));
					if ((Object)(object)liberationFont != (Object)null)
					{
						MelonLogger.Msg("✅ Found LiberationSans TMP font for Thank You message: " + ((Object)liberationFont).name);
					}
					else
					{
						MelonLogger.Warning("⚠\ufe0f Liberation font not found for Thank You message.");
					}
				}
				((TMP_Text)componentInChildren).font = liberationFont;
				((TMP_Text)componentInChildren).text = "Thank You For Your Purchase";
				((TMP_Text)componentInChildren).enableAutoSizing = true;
				((TMP_Text)componentInChildren).fontSizeMin = 5f;
				((TMP_Text)componentInChildren).fontSizeMax = 45f;
				((Graphic)componentInChildren).color = Color.black;
				((Behaviour)componentInChildren).enabled = true;
				((TMP_Text)componentInChildren).fontStyle = (FontStyles)1;
				((TMP_Text)componentInChildren).alignment = (TextAlignmentOptions)514;
				((TMP_Text)componentInChildren).ForceMeshUpdate(false, false);
				RectTransform component = ((Component)componentInChildren).GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					component.offsetMin = new Vector2(5f, 5f);
					component.offsetMax = new Vector2(-5f, -5f);
				}
			}
			else
			{
				MelonLogger.Warning("❌ TMP not found under ThankYouPopup.");
			}
			((Component)val).gameObject.SetActive(true);
			((Component)val).transform.SetAsLastSibling();
			Canvas val2 = ((Component)val).GetComponent<Canvas>() ?? ((Component)val).gameObject.AddComponent<Canvas>();
			val2.overrideSorting = true;
			val2.sortingOrder = 10000;
			MelonCoroutines.Start(HideThankYouMessageCoroutine());
		}

		[IteratorStateMachine(typeof(<HideThankYouMessageCoroutine>d__19))]
		private IEnumerator HideThankYouMessageCoroutine()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <HideThankYouMessageCoroutine>d__19(0)
			{
				<>4__this = this
			};
		}

		private void ShowInsufficientFundsMessage()
		{
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			Transform val = FindDeepChild(((Component)this).transform, "InsufficientFundsPopup");
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Warning("❌ InsufficientFundsPopup not found.");
				return;
			}
			TextMeshProUGUI componentInChildren = ((Component)val).GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				if ((Object)(object)liberationFont == (Object)null)
				{
					liberationFont = ((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => ((Object)f).name.Contains("LiberationSans")));
					if ((Object)(object)liberationFont != (Object)null)
					{
						MelonLogger.Msg("✅ Found LiberationSans TMP font for Insufficient Funds popup.");
					}
					else
					{
						MelonLogger.Warning("⚠\ufe0f Liberation font not found for Insufficient Funds popup.");
					}
				}
				((TMP_Text)componentInChildren).font = liberationFont;
				((TMP_Text)componentInChildren).text = "INSUFFICIENT FUNDS";
				((TMP_Text)componentInChildren).enableAutoSizing = true;
				((TMP_Text)componentInChildren).fontSizeMin = 5f;
				((TMP_Text)componentInChildren).fontSizeMax = 65f;
				((Graphic)componentInChildren).color = Color.black;
				((TMP_Text)componentInChildren).fontStyle = (FontStyles)1;
				((TMP_Text)componentInChildren).alignment = (TextAlignmentOptions)514;
				((TMP_Text)componentInChildren).overflowMode = (TextOverflowModes)0;
				((Behaviour)componentInChildren).enabled = true;
				((TMP_Text)componentInChildren).ForceMeshUpdate(false, false);
				RectTransform component = ((Component)componentInChildren).GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					component.offsetMin = new Vector2(5f, 5f);
					component.offsetMax = new Vector2(-5f, -5f);
				}
			}
			else
			{
				MelonLogger.Warning("❌ TMP not found under InsufficientFundsPopup.");
			}
			((Component)val).gameObject.SetActive(true);
			((Component)val).transform.SetAsLastSibling();
			Canvas val2 = ((Component)val).GetComponent<Canvas>() ?? ((Component)val).gameObject.AddComponent<Canvas>();
			val2.overrideSorting = true;
			val2.sortingOrder = 10000;
			MelonCoroutines.Start(HideInsufficientFundsMessageCoroutine());
		}

		[IteratorStateMachine(typeof(<HideInsufficientFundsMessageCoroutine>d__21))]
		private IEnumerator HideInsufficientFundsMessageCoroutine()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <HideInsufficientFundsMessageCoroutine>d__21(0)
			{
				<>4__this = this
			};
		}

		private void HideInsufficientFundsMessage()
		{
			Transform val = FindDeepChild(((Component)this).transform, "InsufficientFundsPopup");
			if ((Object)(object)val != (Object)null)
			{
				((Component)val).gameObject.SetActive(false);
			}
		}

		private void LoadVehiclePricesFromJson()
		{
			try
			{
				string text = Path.Combine(MelonEnvironment.UserDataDirectory, "RainsCarMod");
				string path = Path.Combine(text, "VehiclePrices.json");
				if (!Directory.Exists(text))
				{
					Directory.CreateDirectory(text);
				}
				if (!File.Exists(path))
				{
					VehiclePriceWrapper vehiclePriceWrapper = new VehiclePriceWrapper
					{
						Entries = new List<VehiclePriceEntry>
						{
							new VehiclePriceEntry
							{
								name = "GTR R34",
								price = 60000
							},
							new VehiclePriceEntry
							{
								name = "GTR R35",
								price = 75000
							},
							new VehiclePriceEntry
							{
								name = "Demon",
								price = 70000
							},
							new VehiclePriceEntry
							{
								name = "Bugatti Tourbillon",
								price = 500000
							},
							new VehiclePriceEntry
							{
								name = "driftcar",
								price = 15000
							},
							new VehiclePriceEntry
							{
								name = "supercar",
								price = 100000
							},
							new VehiclePriceEntry
							{
								name = "canofsoupcar",
								price = 500
							},
							new VehiclePriceEntry
							{
								name = "Rolls Royce Ghost",
								price = 200000
							},
							new VehiclePriceEntry
							{
								name = "Lamborghini Veneno",
								price = 300000
							},
							new VehiclePriceEntry
							{
								name = "Cyber Truck",
								price = 55000
							},
							new VehiclePriceEntry
							{
								name = "Koenigsegg CC850",
								price = 360000
							},
							new VehiclePriceEntry
							{
								name = "Lancia_Delta",
								price = 80000
							},
							new VehiclePriceEntry
							{
								name = "El_Camino",
								price = 25000
							}
						}
					};
					File.WriteAllText(path, JsonConvert.SerializeObject((object)vehiclePriceWrapper, (Formatting)1));
					MelonLogger.Msg("[RainsCarMod] Created default VehiclePrices.json");
					VehiclePrices = vehiclePriceWrapper.ToDictionary();
				}
				else
				{
					VehiclePriceWrapper vehiclePriceWrapper2 = JsonConvert.DeserializeObject<VehiclePriceWrapper>(File.ReadAllText(path));
					if (vehiclePriceWrapper2?.Entries != null)
					{
						VehiclePrices = vehiclePriceWrapper2.ToDictionary();
						MelonLogger.Msg("[RainsCarMod] Loaded VehiclePrices.json");
					}
					else
					{
						MelonLogger.Warning("[RainsCarMod] VehiclePrices.json loaded but had no entries.");
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[RainsCarMod] Failed to load VehiclePrices.json: " + ex.Message);
			}
		}

		public static void TrySpawnVehicle(string prefabKey, NetworkConnection conn)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			if (!InstanceFinder.IsServer)
			{
				return;
			}
			NetworkObject firstObject = conn.FirstObject;
			if ((Object)(object)firstObject == (Object)null)
			{
				return;
			}
			if (!VehiclePrices.TryGetValue(prefabKey, out var value))
			{
				value = 500;
			}
			MoneyManager instance = NetworkSingleton<MoneyManager>.Instance;
			if (!(instance.cashBalance < (float)value) && CarLoader.LoadedPrefabs.TryGetValue(prefabKey, out var value2))
			{
				instance.ChangeCashBalance((float)(-value), true, false);
				GameObject val = Object.Instantiate<GameObject>(value2, CarLoader.carSpawnPosition, CarLoader.carSpawnRotation);
				InstanceFinder.ServerManager.Spawn(val, conn, default(Scene));
				LandVehicle component = val.GetComponent<LandVehicle>();
				if ((Object)(object)component != (Object)null && !NetworkSingleton<VehicleManager>.Instance.PlayerOwnedVehicles.Contains(component))
				{
					NetworkSingleton<VehicleManager>.Instance.PlayerOwnedVehicles.Add(component);
				}
			}
		}

		private Transform FindDeepChild(Transform parent, string name)
		{
			for (int i = 0; i < parent.childCount; i++)
			{
				Transform child = parent.GetChild(i);
				if (((Object)child).name == name)
				{
					return child;
				}
				Transform val = FindDeepChild(child, name);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}
	}
}
namespace RainsCarMod.Logging
{
	public static class Log
	{
		public static void LogInfo(string message)
		{
			Melon<Core>.Logger.Msg(message);
		}

		public static void LogWarning(string message)
		{
			Melon<Core>.Logger.Warning(message);
		}

		public static void LogError(string message)
		{
			Melon<Core>.Logger.Error(message);
		}

		public static void LogFatal(string message)
		{
			Melon<Core>.Logger.BigError(message);
		}
	}
}
namespace RainsCarMod.RainsCarMod
{
	public class CarDealerInterface : MonoBehaviour
	{
		public Transform cameraPosition;

		public Component intObj;

		public Canvas canvas;

		public static Action OnUIRequested;

		public static CarDealerInterface Instance;

		private bool isOpen = false;

		private Component playerMovement;

		private Component playerCamera;

		private Component playerInventory;

		public bool IsOpen => isOpen;

		private void Start()
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			playerCamera = (Component)(object)Object.FindObjectOfType<PlayerCamera>();
			Instance = this;
			if ((Object)(object)intObj != (Object)null)
			{
				PropertyInfo property = ((object)intObj).GetType().GetProperty("onInteractStart");
				if (property != null)
				{
					object? value = property.GetValue(intObj);
					UnityEvent val = (UnityEvent)((value is UnityEvent) ? value : null);
					if (val == null)
					{
					}
				}
			}
			GameObject val2 = GameObject.Find("Player_Local");
			if ((Object)(object)val2 != (Object)null)
			{
				playerMovement = (Component)(object)val2.GetComponent<PlayerMovement>();
				Transform val3 = val2.transform.Find("CameraContainer");
				if ((Object)(object)val3 != (Object)null)
				{
					playerCamera = (Component)(object)((Component)val3).GetComponent<PlayerCamera>();
				}
			}
			if ((Object)(object)cameraPosition != (Object)null)
			{
				cameraPosition.position = new Vector3(-59.7f, -1.03f, -16.8f);
				cameraPosition.rotation = Quaternion.Euler(0f, 330f, 0f);
			}
			if ((Object)(object)canvas != (Object)null)
			{
				Transform val4 = ((Component)canvas).transform.Find("Panel");
				if ((Object)(object)val4 != (Object)null)
				{
					((Component)val4).gameObject.SetActive(true);
				}
			}
			UIManager.OnUICloseRequested = Close;
		}

		private void Update()
		{
			if (isOpen && Input.GetKeyDown((KeyCode)27))
			{
				Close();
			}
		}

		private List<Transform> GetAllChildTransforms(Transform root)
		{
			List<Transform> val = new List<Transform>();
			CollectChildTransformsRecursive(root, val);
			return val;
		}

		private void CollectChildTransformsRecursive(Transform parent, List<Transform> list)
		{
			if (!((Object)(object)parent == (Object)null))
			{
				list.Add(parent);
				for (int i = 0; i < parent.childCount; i++)
				{
					CollectChildTransformsRecursive(parent.GetChild(i), list);
				}
			}
		}

		public void Interacted()
		{
			if (!isOpen)
			{
				Open();
			}
		}

		public void Open()
		{
			//IL_0032: 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)
			isOpen = true;
			OnUIRequested?.Invoke();
			PlayerCamera instance = PlayerSingleton<PlayerCamera>.Instance;
			PlayerMovement instance2 = PlayerSingleton<PlayerMovement>.Instance;
			PlayerInventory instance3 = PlayerSingleton<PlayerInventory>.Instance;
			instance.OverrideTransform(cameraPosition.position, cameraPosition.rotation, 0.15f, false);
			instance.OverrideFOV(65f, 0.15f);
			instance.SetCanLook(false);
			instance.FreeMouse();
			instance.AddActiveUIElement("RainsCarDealer");
			instance2.CanMove = false;
			instance3.SetInventoryEnabled(false);
			Singleton<HUD>.Instance.SetCrosshairVisible(false);
			Cursor.visible = true;
			Cursor.lockState = (CursorLockMode)0;
		}

		public void Close()
		{
			isOpen = false;
			PlayerCamera instance = PlayerSingleton<PlayerCamera>.Instance;
			PlayerMovement instance2 = PlayerSingleton<PlayerMovement>.Instance;
			PlayerInventory instance3 = PlayerSingleton<PlayerInventory>.Instance;
			instance.StopTransformOverride(0.15f, true, true);
			instance.StopFOVOverride(0.15f);
			instance.SetCanLook(true);
			instance.RemoveActiveUIElement("RainsCarDealer");
			instance.LockMouse();
			instance2.CanMove = true;
			instance3.SetInventoryEnabled(true);
			Singleton<HUD>.Instance.SetCrosshairVisible(true);
			Cursor.visible = false;
			Cursor.lockState = (CursorLockMode)1;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}