using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using HarmonyLib.Tools;
using LethalConfig;
using LethalConfig.ConfigItems;
using Microsoft.CodeAnalysis;
using UnityEngine;
[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("LCLondonLoopCompanyCruiserMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Take the LL to your CC with this rocking Mario Kart 8 Deluxe song!")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("LCLondonLoopCompanyCruiserMod")]
[assembly: AssemblyTitle("LCLondonLoopCompanyCruiserMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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 LCLondonLoopCompanyCruiserMod
{
public class MusicManager : MonoBehaviour
{
public AudioSource LondonLoopAudio;
private bool is2D;
public bool fadeOut;
private float fadeOutMultiplier = 3f;
private void Start()
{
Plugin.Logger.LogDebug((object)"LondonLoop MusicManager Start!!");
LondonLoopAudio = ((Component)this).gameObject.GetComponent<AudioSource>();
}
private void Update()
{
if (!LondonLoopAudio.isPlaying)
{
return;
}
if (LondonLoopAudio.time > 57f)
{
Plugin.Logger.LogDebug((object)"looping song on Update()!!");
AudioSource londonLoopAudio = LondonLoopAudio;
londonLoopAudio.time -= 48f;
}
if (fadeOut)
{
AudioSource londonLoopAudio2 = LondonLoopAudio;
londonLoopAudio2.volume -= Time.deltaTime * (1f / fadeOutMultiplier);
if (LondonLoopAudio.volume < 0.05f)
{
fadeOut = false;
LondonLoopAudio.Stop();
LondonLoopAudio.time = 0f;
Plugin.Logger.LogDebug((object)"stopped song");
}
}
}
public void Toggle2D3D(VehicleController __instance)
{
if (fadeOut)
{
Plugin.Logger.LogDebug((object)"currently fading out, toggle returning");
return;
}
is2D = (Object)(object)__instance.currentDriver == (Object)(object)StartOfRound.Instance.localPlayerController;
Plugin.Logger.LogDebug((object)$"setting is2D to: {is2D}");
if (is2D)
{
LondonLoopAudio.spatialBlend = 0f;
LondonLoopAudio.volume = (float)Plugin.Config.ambientVolume.Value / 100f;
}
else
{
LondonLoopAudio.spatialBlend = 1f;
LondonLoopAudio.volume = (float)Plugin.Config.ambientVolume.Value / 100f * 0.8f;
}
Plugin.Logger.LogDebug((object)$"spatialBlend: {LondonLoopAudio.spatialBlend} | volume: {LondonLoopAudio.volume}");
}
}
public class Patches
{
[HarmonyPatch]
public class VehicleControllerPatch
{
[HarmonyPrefix]
[HarmonyPatch(typeof(VehicleController), "Start")]
public static void InitializeMusic(VehicleController __instance)
{
if (Plugin.Config.ambientOrRadio.Value)
{
GameObject val = Object.Instantiate<GameObject>(Plugin.LondonLoopPrefab, ((Component)__instance).gameObject.transform, false);
val.AddComponent<MusicManager>();
}
else if (Plugin.Config.radioAddOrOverwrite.Value)
{
List<AudioClip> list = new List<AudioClip>();
list.AddRange(__instance.radioClips);
list.Add(Plugin.LondonLoopMusicRadio);
__instance.radioClips = list.ToArray();
Plugin.Logger.LogDebug((object)"config: add");
}
else
{
AudioClip[] radioClips = (AudioClip[])(object)new AudioClip[1] { Plugin.LondonLoopMusicRadio };
__instance.radioClips = radioClips;
Plugin.Logger.LogDebug((object)"config: overwrite");
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(VehicleController), "Update")]
public static void UpdateMuteRadio(VehicleController __instance)
{
if (__instance.ignitionStarted && __instance.radioAudio.isPlaying && Plugin.Config.ambientOrRadio.Value && Plugin.Config.ambientMuteRadio.Value && ((Component)__instance).GetComponentInChildren<MusicManager>().LondonLoopAudio.isPlaying)
{
__instance.radioAudio.volume = 0f;
__instance.radioInterference.volume = 0f;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(VehicleController), "SetIgnition")]
public static void StartMusic(VehicleController __instance, ref bool started)
{
if (Plugin.Config.ambientOrRadio.Value & started)
{
MusicManager componentInChildren = ((Component)__instance).gameObject.GetComponentInChildren<MusicManager>();
if (!componentInChildren.LondonLoopAudio.isPlaying)
{
componentInChildren.LondonLoopAudio.Play();
componentInChildren.Toggle2D3D(__instance);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(VehicleController), "RemoveKey")]
public static void StopMusicRemoveKey(VehicleController __instance)
{
if (Plugin.Config.ambientOrRadio.Value)
{
MusicManager componentInChildren = ((Component)__instance).gameObject.GetComponentInChildren<MusicManager>();
componentInChildren.fadeOut = true;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(VehicleController), "DestroyCar")]
public static void StopMusicDestroyCar(VehicleController __instance)
{
if (Plugin.Config.ambientOrRadio.Value)
{
MusicManager componentInChildren = ((Component)__instance).gameObject.GetComponentInChildren<MusicManager>();
componentInChildren.LondonLoopAudio.Stop();
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(VehicleController), "SetPlayerInControlOfVehicleClientRpc")]
public static void ToggleMusicSetPlayer(VehicleController __instance)
{
if (Plugin.Config.ambientOrRadio.Value)
{
MusicManager componentInChildren = ((Component)__instance).gameObject.GetComponentInChildren<MusicManager>();
if (componentInChildren.LondonLoopAudio.isPlaying)
{
componentInChildren.Toggle2D3D(__instance);
}
else if (!componentInChildren.LondonLoopAudio.isPlaying && __instance.ignitionStarted)
{
componentInChildren.LondonLoopAudio.Play();
componentInChildren.Toggle2D3D(__instance);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(VehicleController), "RemovePlayerControlOfVehicleClientRpc")]
public static void ToggleMusicRemovePlayer(VehicleController __instance)
{
if (Plugin.Config.ambientOrRadio.Value)
{
MusicManager componentInChildren = ((Component)__instance).gameObject.GetComponentInChildren<MusicManager>();
if (componentInChildren.LondonLoopAudio.isPlaying)
{
componentInChildren.Toggle2D3D(__instance);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "WritePlayerNotes")]
public static void StopMusic()
{
if (Plugin.Config.ambientOrRadio.Value)
{
VehicleController[] array = Object.FindObjectsOfType<VehicleController>();
VehicleController[] array2 = array;
foreach (VehicleController val in array2)
{
MusicManager componentInChildren = ((Component)val).gameObject.GetComponentInChildren<MusicManager>();
componentInChildren.fadeOut = true;
}
}
}
}
}
[BepInPlugin("LCLondonLoopCompanyCruiserMod", "LCLondonLoopCompanyCruiserMod", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
public class Config
{
public static ConfigEntry<bool> ambientOrRadio;
public static ConfigEntry<int> ambientVolume;
public static ConfigEntry<bool> ambientMuteRadio;
public static ConfigEntry<bool> radioAddOrOverwrite;
public Config(ConfigFile cfg)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Expected O, but got Unknown
ambientOrRadio = cfg.Bind<bool>("Customization", "Ambient Or Radio", true, "Set whether London Loop plays while the engine is running (true), or over the Cruiser's radio (false).");
ambientVolume = cfg.Bind<int>("Customization", "Ambient Volume", 80, new ConfigDescription("If [Ambient Or Radio] is set to true, set how loud the volume of London Loop is.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
ambientMuteRadio = cfg.Bind<bool>("Customization", "Ambient Mutes Radio", true, "If [Ambient Or Radio] is set to true, set whether the radio is silent while London Loop is playing (true), or if London Loop and the radio's music can overlap (false).");
radioAddOrOverwrite = cfg.Bind<bool>("Customization", "Add Or Overwrite", false, "If [Ambient Or Radio] is set to false, set whether London Loop gets added to the radio's playlist (true), or tries to be the only song on the radio (false).");
}
}
internal static ManualLogSource Logger;
public static AssetBundle LondonLoopAssetBundle;
public static GameObject LondonLoopPrefab;
public static AudioClip LondonLoopMusicRadio;
public static string sAssemblyLocation;
public static bool LethalConfigCompatible;
public static Config MyConfig { get; internal set; }
private void Awake()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin LCLondonLoopCompanyCruiserMod is loaded!");
Harmony val = new Harmony("LCLondonLoopCompanyCruiserMod");
val.PatchAll();
HarmonyFileLog.Enabled = false;
MyConfig = new Config(((BaseUnityPlugin)this).Config);
sAssemblyLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
LondonLoopAssetBundle = AssetBundle.LoadFromFile(Path.Combine(sAssemblyLocation, "londonloopassetbundle"));
if ((Object)(object)LondonLoopAssetBundle == (Object)null)
{
Logger.LogError((object)"Failed to load LondonLoopAssetBundle");
return;
}
LondonLoopPrefab = LondonLoopAssetBundle.LoadAsset<GameObject>("Assets/LondonLoopAudio.prefab");
Logger.LogInfo((object)"Loaded LondonLoopAssetBundle");
DisplayConfigs();
LethalConfigCompatible = CheckForPlugin("LethalConfig");
if (LethalConfigCompatible)
{
AddLethalConfig();
}
}
private static void DisplayConfigs()
{
if (Config.ambientOrRadio.Value)
{
Logger.LogInfo((object)"Config [Ambient Or Radio] is set to TRUE. London Loop will play while the Cruiser's engine is running.");
Logger.LogInfo((object)$"Config [Ambient Volume] is set to a value of {Config.ambientVolume.Value}.");
if (Config.ambientMuteRadio.Value)
{
Logger.LogInfo((object)"Config [Ambient Mutes Radio] is set to TRUE. The radio will be muted while London Loop is playing.");
}
else
{
Logger.LogInfo((object)"Config [Ambient Mutes Radio] is set to FALSE. The radio can play music regardless of London Loop.");
}
}
else
{
Logger.LogInfo((object)"Config [Ambient Or Radio] is set to FALSE. The London Loop music will play over the radio.");
LondonLoopMusicRadio = LondonLoopAssetBundle.LoadAsset<AudioClip>("Assets/MK8DX London Loop (Body).ogg");
if (Config.radioAddOrOverwrite.Value)
{
Logger.LogInfo((object)"Config [Add Or Overwrite] is set to TRUE. London Loop will get added to the radio's playlist.");
}
else
{
Logger.LogInfo((object)"Config [Add Or Overwrite] is set to FALSE. London Loop will try to be the only song on the radio.");
}
}
}
private static bool CheckForPlugin(string pluginName, bool printDebug = true)
{
foreach (PluginInfo value in Chainloader.PluginInfos.Values)
{
if (value.Metadata.Name == pluginName)
{
if (printDebug)
{
Logger.LogDebug((object)("Successfully found " + pluginName));
}
return true;
}
}
if (printDebug)
{
Logger.LogDebug((object)("Failed to find " + pluginName));
}
return false;
}
private static void AddLethalConfig()
{
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Expected O, but got Unknown
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Expected O, but got Unknown
LethalConfigManager.SetModIcon(LondonLoopAssetBundle.LoadAsset<Sprite>("Assets/icon.png"));
LethalConfigManager.SetModDescription("Take the LL to your CC with this rocking Mario Kart 8 Deluxe song!\n\n(Only creates LethalConfig options if config [Ambient Or Radio] is set to true from Thunderstore.)");
LethalConfigManager.SkipAutoGenFor((ConfigEntryBase)(object)Config.ambientOrRadio);
LethalConfigManager.SkipAutoGenFor((ConfigEntryBase)(object)Config.radioAddOrOverwrite);
if (!Config.ambientOrRadio.Value)
{
LethalConfigManager.SkipAutoGenFor((ConfigEntryBase)(object)Config.ambientVolume);
LethalConfigManager.SkipAutoGenFor((ConfigEntryBase)(object)Config.ambientMuteRadio);
return;
}
LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(Config.ambientVolume, false));
LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Config.ambientMuteRadio, false));
Config.ambientVolume.SettingChanged += delegate
{
MusicManager musicManager = Object.FindObjectOfType<MusicManager>();
if ((Object)(object)musicManager != (Object)null)
{
musicManager.Toggle2D3D(((Component)((Component)musicManager).gameObject.transform.parent).gameObject.GetComponent<VehicleController>());
}
};
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "LCLondonLoopCompanyCruiserMod";
public const string PLUGIN_NAME = "LCLondonLoopCompanyCruiserMod";
public const string PLUGIN_VERSION = "1.1.0";
}
}