Decompiled source of Formula 1 Company v1.2.1

formula1Company.dll

Decompiled 2 months ago
using System;
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 BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using UnityEngine;
using formula1Company.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("formula1Company")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f943906db12047b36ad65ee36dce364d32ae1e7e")]
[assembly: AssemblyProduct("formula1Company")]
[assembly: AssemblyTitle("formula1Company")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace formula1Company
{
	[BepInPlugin("filo.formula1Company", "Formula 1 Company", "1.2.0")]
	public class Formula1Company : BaseUnityPlugin
	{
		private const string GUID = "filo.formula1Company";

		private const string NAME = "Formula 1 Company";

		private const string VERSION = "1.2.0";

		public static Formula1Company instance;

		private readonly Harmony harmony = new Harmony("filo.formula1Company");

		private ConfigEntry<int> tyreRarity;

		private ConfigEntry<int> carRarity;

		private ConfigEntry<int> helmetRarity;

		private ConfigEntry<int> minTyreValue;

		private ConfigEntry<int> maxTyreValue;

		private ConfigEntry<int> minCarValue;

		private ConfigEntry<int> maxCarValue;

		private ConfigEntry<int> minHelmetValue;

		private ConfigEntry<int> maxHelmetValue;

		private ConfigEntry<bool> useCustomSounds;

		internal static AssetBundle AudioBundle;

		internal static List<AudioClip> SoundFx;

		private void Awake()
		{
			instance = this;
			GetConfig();
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "formula1companybundle");
			AssetBundle bundle = AssetBundle.LoadFromFile(text);
			RegisterItems(bundle);
			if (useCustomSounds.Value)
			{
				string text2 = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "f1companyaudiobundle");
				AudioBundle = AssetBundle.LoadFromFile(text2);
				if (text2 != null)
				{
					SoundFx = AudioBundle.LoadAllAssets<AudioClip>().ToList();
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load F1 audio asset bundle!");
				}
				harmony.PatchAll(typeof(StartOfRoundPatch));
				harmony.PatchAll(typeof(WalkieTalkiePatch));
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"\n\nGentlemen, a short view back to the past. Thirty years ago, Niki Lauda told us ‘take a monkey, place him into the cockpit and he is able to drive the car.’ Thirty years later, Sebastian told us ‘I had to start my car like a computer, it’s very complicated.’ And Nico Rosberg said that during the race – I don’t remember what race - he pressed the wrong button on the wheel. Question for you both: is Formula One driving today too complicated with twenty and more buttons on the wheel, are you too much under effort, under pressure? What are your wishes for the future concerning the technical programme during the race? Less buttons, more? Or less and more communication with your engineers?\n\nFormula 1 Company Successfully loaded!\n");
		}

		private void GetConfig()
		{
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
			tyreRarity = ((BaseUnityPlugin)this).Config.Bind<int>("Item Rarities", "TyreRarity", 14, "Base rarity of tyres (Soft, Medium, Hard)\nHigher number = more common.");
			carRarity = ((BaseUnityPlugin)this).Config.Bind<int>("Item Rarities", "CarRarity", 12, "Base rarity of models of F1 cars\nHigher number = more common.");
			helmetRarity = ((BaseUnityPlugin)this).Config.Bind<int>("Item Rarities", "HelmetRarity", 10, "Base rarity of racing helmet\nHigher number = more common.");
			minTyreValue = ((BaseUnityPlugin)this).Config.Bind<int>("Item Prices", "MinTyrePrice", 135, "Minimum price of tyres");
			maxTyreValue = ((BaseUnityPlugin)this).Config.Bind<int>("Item Prices", "MaxTyrePrice", 175, "Maximum price of tyres");
			minCarValue = ((BaseUnityPlugin)this).Config.Bind<int>("Item Prices", "MinCarPrice", 50, "Minimum price of car models");
			maxCarValue = ((BaseUnityPlugin)this).Config.Bind<int>("Item Prices", "MaxCarPrice", 80, "Maximum price of car models");
			minHelmetValue = ((BaseUnityPlugin)this).Config.Bind<int>("Item Prices", "MinHelmetPrice", 60, "Minimum price of racing helmet");
			maxHelmetValue = ((BaseUnityPlugin)this).Config.Bind<int>("Item Prices", "MaxHelmetPrice", 100, "Maximum price of racing helmet");
			useCustomSounds = ((BaseUnityPlugin)this).Config.Bind<bool>("Sounds", "UseCustomSounds", true, "Setting this to true will replace some in-game sounds to F1 themed sounds");
			ClearOrphanedEntries(((BaseUnityPlugin)this).Config);
			((BaseUnityPlugin)this).Config.Save();
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
		}

		private static void ClearOrphanedEntries(ConfigFile cfg)
		{
			PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg);
			dictionary.Clear();
		}

		private void RegisterItems(AssetBundle bundle)
		{
			RegisterSoft(bundle);
			RegisterMedium(bundle);
			RegisterHard(bundle);
			RegisterFerrari(bundle);
			RegisterMclaren(bundle);
			RegisterMercedes(bundle);
			RegisterRedbull(bundle);
			RegisterHelmet(bundle);
		}

		private void RegisterHelmet(AssetBundle bundle)
		{
			Item val = bundle.LoadAsset<Item>("Assets/formula1Company/Helmet/HelmetScrap.asset");
			val.maxValue = maxHelmetValue.Value;
			val.minValue = minHelmetValue.Value;
			int value = helmetRarity.Value;
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Utilities.FixMixerGroups(val.spawnPrefab);
			Items.RegisterScrap(val, value, (LevelTypes)(-1));
		}

		private void RegisterFerrari(AssetBundle bundle)
		{
			Item val = bundle.LoadAsset<Item>("Assets/formula1Company/Cars/Ferrari/FerrariScrap.asset");
			val.maxValue = maxCarValue.Value;
			val.minValue = minCarValue.Value;
			int value = carRarity.Value;
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Utilities.FixMixerGroups(val.spawnPrefab);
			Items.RegisterScrap(val, value, (LevelTypes)(-1));
		}

		private void RegisterRedbull(AssetBundle bundle)
		{
			Item val = bundle.LoadAsset<Item>("Assets/formula1Company/Cars/Red Bull/RedbullScrap.asset");
			val.maxValue = maxCarValue.Value;
			val.minValue = minCarValue.Value;
			int value = carRarity.Value;
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Utilities.FixMixerGroups(val.spawnPrefab);
			Items.RegisterScrap(val, value, (LevelTypes)(-1));
		}

		private void RegisterMercedes(AssetBundle bundle)
		{
			Item val = bundle.LoadAsset<Item>("Assets/formula1Company/Cars/Mercedes/MercedesScrap.asset");
			val.maxValue = maxCarValue.Value;
			val.minValue = minCarValue.Value;
			int value = carRarity.Value;
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Utilities.FixMixerGroups(val.spawnPrefab);
			Items.RegisterScrap(val, value, (LevelTypes)(-1));
		}

		private void RegisterMclaren(AssetBundle bundle)
		{
			Item val = bundle.LoadAsset<Item>("Assets/formula1Company/Cars/McLaren/McLarenScrap.asset");
			val.maxValue = maxCarValue.Value;
			val.minValue = minCarValue.Value;
			int value = carRarity.Value;
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Utilities.FixMixerGroups(val.spawnPrefab);
			Items.RegisterScrap(val, value, (LevelTypes)(-1));
		}

		private void RegisterSoft(AssetBundle bundle)
		{
			Item val = bundle.LoadAsset<Item>("Assets/formula1Company/Tyres/TyreSoftItem.asset");
			val.maxValue = maxTyreValue.Value;
			val.minValue = minTyreValue.Value;
			int value = tyreRarity.Value;
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Utilities.FixMixerGroups(val.spawnPrefab);
			Items.RegisterScrap(val, value, (LevelTypes)(-1));
		}

		private void RegisterHard(AssetBundle bundle)
		{
			Item val = bundle.LoadAsset<Item>("Assets/formula1Company/Tyres/TyreHardItem.asset");
			val.maxValue = maxTyreValue.Value;
			val.minValue = minTyreValue.Value;
			int value = tyreRarity.Value;
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Utilities.FixMixerGroups(val.spawnPrefab);
			Items.RegisterScrap(val, value, (LevelTypes)(-1));
		}

		private void RegisterMedium(AssetBundle bundle)
		{
			Item val = bundle.LoadAsset<Item>("Assets/formula1Company/Tyres/TyreMediumItem.asset");
			val.maxValue = maxTyreValue.Value;
			val.minValue = minTyreValue.Value;
			int value = tyreRarity.Value;
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Utilities.FixMixerGroups(val.spawnPrefab);
			Items.RegisterScrap(val, value, (LevelTypes)(-1));
		}
	}
}
namespace formula1Company.Patches
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void OverrideEjectAudio(ref AudioClip ___alarmSFX)
		{
			AudioClip val = null;
			for (int i = 0; i < Formula1Company.SoundFx.Count; i++)
			{
				if (((Object)Formula1Company.SoundFx[i]).name.Equals("tuturuturuMaxVerstappen"))
				{
					val = Formula1Company.SoundFx[i];
					break;
				}
			}
			if (!((Object)(object)val == (Object)null))
			{
				___alarmSFX = val;
			}
		}

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void OverrideShipIntro(ref AudioClip ___shipIntroSpeechSFX)
		{
			AudioClip val = null;
			for (int i = 0; i < Formula1Company.SoundFx.Count; i++)
			{
				if (((Object)Formula1Company.SoundFx[i]).name.Equals("question"))
				{
					val = Formula1Company.SoundFx[i];
					break;
				}
			}
			if (!((Object)(object)val == (Object)null))
			{
				___shipIntroSpeechSFX = val;
			}
		}
	}
	[HarmonyPatch(typeof(WalkieTalkie))]
	internal class WalkieTalkiePatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void OverrideWalkieTalkieBeep(ref AudioClip[] ___startTransmissionSFX)
		{
			AudioClip val = null;
			for (int i = 0; i < Formula1Company.SoundFx.Count; i++)
			{
				if (((Object)Formula1Company.SoundFx[i]).name.Equals("radioBeep"))
				{
					val = Formula1Company.SoundFx[i];
					break;
				}
			}
			if (!((Object)(object)val == (Object)null))
			{
				for (int j = 0; j < ___startTransmissionSFX.Length; j++)
				{
					___startTransmissionSFX[j] = val;
				}
			}
		}
	}
}