Decompiled source of Randomize Car v1.2.1

RandomizeCar.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RandomizeCar")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RandomizeCar")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("108b7680-98bf-4ec7-a679-b71b06a4fdcd")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace RandomizeCar
{
	[BepInPlugin("Distance.RandomizeCar", "Randomize Car", "1.2.1")]
	public sealed class Mod : BaseUnityPlugin
	{
		private const string modGUID = "Distance.RandomizeCar";

		private const string modName = "Randomize Car";

		private const string modVersion = "1.2.1";

		public static string CarKey = "Randomize Cars";

		public static string ColorKey = "Randomize Colors";

		public static string IncludeCustomKey = "Include Custom Cars";

		private static readonly Harmony harmony = new Harmony("Distance.RandomizeCar");

		public static ManualLogSource Log = new ManualLogSource("Randomize Car");

		public static Mod Instance;

		public static ConfigEntry<bool> RandomizeCars { get; set; }

		public static ConfigEntry<bool> RandomizeColors { get; set; }

		public static ConfigEntry<bool> IncludeCustomCars { get; set; }

		private void Awake()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Log = Logger.CreateLogSource("Distance.RandomizeCar");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Thanks for using Randomize Car!");
			RandomizeCars = ((BaseUnityPlugin)this).Config.Bind<bool>("General", CarKey, false, new ConfigDescription("Toggle whether or not cars randomize", (AcceptableValueBase)null, new object[0]));
			RandomizeColors = ((BaseUnityPlugin)this).Config.Bind<bool>("General", ColorKey, false, new ConfigDescription("Toggle whether or not colors randomize", (AcceptableValueBase)null, new object[0]));
			IncludeCustomCars = ((BaseUnityPlugin)this).Config.Bind<bool>("General", IncludeCustomKey, false, new ConfigDescription("Toggle whether or not custom cars are included in randomization", (AcceptableValueBase)null, new object[0]));
			RandomizeCars.SettingChanged += OnConfigChanged;
			RandomizeColors.SettingChanged += OnConfigChanged;
			IncludeCustomCars.SettingChanged += OnConfigChanged;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading...");
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded!");
		}

		private void OnConfigChanged(object sender, EventArgs e)
		{
			SettingChangedEventArgs val = (SettingChangedEventArgs)(object)((e is SettingChangedEventArgs) ? e : null);
			if (val != null)
			{
			}
		}
	}
}
namespace RandomizeCar.Patches
{
	[HarmonyPatch(typeof(ApplicationEx), "LoadLevel")]
	internal static class ApplicationEx__LoadLevel
	{
		[HarmonyPrefix]
		internal static void RandomizeCarPrefix()
		{
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0067: Unknown result type (might be due to invalid IL or missing references)
			Random random = new Random();
			ProfileManager profileManager_ = G.Sys.ProfileManager_;
			Profile currentProfile_ = profileManager_.CurrentProfile_;
			if (Mod.RandomizeCars.Value)
			{
				List<string> list = new List<string>();
				if (!Mod.IncludeCustomCars.Value)
				{
					UnlockableCar[] unlockableCars_ = ProfileManager.unlockableCars_;
					foreach (UnlockableCar val in unlockableCars_)
					{
						list.Add(profileManager_.CarInfos_[val.index_].name_);
					}
				}
				else
				{
					list = new List<string>(profileManager_.knownCars_.Keys);
				}
				int index = random.Next(0, list.Count);
				if (list[index] == "Catalyst" && !G.Sys.SteamworksManager_.OwnsCatalystDLC())
				{
					currentProfile_.CarName_ = "Spectrum";
				}
				else
				{
					currentProfile_.CarName_ = list[index];
				}
				Mod.Log.LogInfo((object)("Car Name: " + currentProfile_.CarName_));
			}
			if (Mod.RandomizeColors.Value)
			{
				currentProfile_.CarColors_ = new CarColors(Random.ColorHSV(), Random.ColorHSV(), Random.ColorHSV(), Random.ColorHSV());
			}
		}
	}
}