using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Spantle.LethalLadderMusic")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A mod for Lethal Company that plays fitting music when you climb a ladder.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LethalLadderMusic")]
[assembly: AssemblyTitle("Spantle.LethalLadderMusic")]
[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 LethalLadderMusic
{
[BepInPlugin("Spantle.LethalLadderMusic", "LethalLadderMusic", "1.0.0")]
public class LethalLadderMusicPlugin : BaseUnityPlugin
{
private readonly Harmony harmony = new Harmony("Spantle.LethalLadderMusic");
public static ManualLogSource logger;
public static ConfigEntry<int> volume;
public static ConfigEntry<bool> allPlayers;
public static ConfigEntry<bool> music0Enable;
public static ConfigEntry<bool> music1Enable;
public static ConfigEntry<float> music1DownPitch;
public static List<AudioClip> ladderMusic = new List<AudioClip>();
public static int ladderMusicIndex = 0;
public static int music1Index = 1;
private void Awake()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Expected O, but got Unknown
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Expected O, but got Unknown
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Expected O, but got Unknown
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Expected O, but got Unknown
logger = ((BaseUnityPlugin)this).Logger;
volume = ((BaseUnityPlugin)this).Config.Bind<int>("Main settings", "Volume", 50, new ConfigDescription("The volume percentage that the music will play at.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
allPlayers = ((BaseUnityPlugin)this).Config.Bind<bool>("Main settings", "Applies to other players", true, new ConfigDescription("If set to true, then all players will play music when they are climbing a ladder. If set to false, only you will play music. This only affects your perspective.", (AcceptableValueBase)null, Array.Empty<object>()));
music0Enable = ((BaseUnityPlugin)this).Config.Bind<bool>("Snake Eater", "Can be randomly chosen", true, new ConfigDescription("If set to true, then \"Snake Eater\" has a chance to play while climbing a ladder. (Randomly picked every time you land on a moon)", (AcceptableValueBase)null, Array.Empty<object>()));
music1Enable = ((BaseUnityPlugin)this).Config.Bind<bool>("Can we get much higher? (Dark Fantasy)", "Can be randomly chosen", true, new ConfigDescription("If set to true, then \"Can we get much higher? (Dark Fantasy)\" has a chance to play while climbing a ladder. (Randomly picked every time you land on a moon)", (AcceptableValueBase)null, Array.Empty<object>()));
music1DownPitch = ((BaseUnityPlugin)this).Config.Bind<float>("Can we get much higher? (Dark Fantasy)", "Going down pitch", 0.8f, new ConfigDescription("The pitch of the music while going down a ladder.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
AssetBundle val = AssetBundle.LoadFromMemory(Resources.Music);
if (music0Enable.Value)
{
ladderMusic.Add(val.LoadAsset<AudioClip>("assets/snake eater.ogg"));
}
if (music1Enable.Value)
{
ladderMusic.Add(val.LoadAsset<AudioClip>("assets/higher.ogg"));
music1Index = ladderMusic.Count - 1;
}
harmony.PatchAll(typeof(PlayerControllerB_Patch));
harmony.PatchAll(typeof(RoundManager_Patch));
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Spantle.LethalLadderMusic is loaded!");
}
}
public class SnakeEater
{
private readonly PlayerControllerB player;
private readonly AudioSource audioSource;
private bool isPlaying;
private bool isClimbingUp;
private int isMoving;
private float oldY;
public SnakeEater(PlayerControllerB player)
{
audioSource = player.itemAudio;
this.player = player;
RefreshClip();
}
public void RefreshClip()
{
if ((Object)(object)audioSource == (Object)null)
{
LethalLadderMusicPlugin.logger.LogWarning((object)"We've got an undefined audioSource on a player here! This isn't ideal but should be OK...");
return;
}
audioSource.clip = LethalLadderMusicPlugin.ladderMusic[LethalLadderMusicPlugin.ladderMusicIndex];
audioSource.loop = true;
audioSource.volume = (float)LethalLadderMusicPlugin.volume.Value / 100f;
}
public void Update()
{
if (player.isClimbingLadder)
{
float y = player.oldPlayerPosition.y;
float num = oldY - y;
if ((double)Mathf.Abs(num) > 0.1)
{
isClimbingUp = Mathf.Sign(num) < 0f;
isMoving = 10;
}
isMoving--;
if (isMoving > 0)
{
IsClimbing();
}
else
{
IsNotClimbing();
}
oldY = y;
}
else
{
IsNotClimbing();
isMoving = 0;
}
}
private void AdditionalMusicLogic()
{
if (LethalLadderMusicPlugin.ladderMusicIndex == LethalLadderMusicPlugin.music1Index)
{
if (isClimbingUp)
{
audioSource.pitch = 1f;
}
else
{
audioSource.pitch = 0.8f;
}
}
}
private void IsClimbing()
{
AdditionalMusicLogic();
if (!isPlaying)
{
isPlaying = true;
audioSource.Play();
}
}
private void IsNotClimbing()
{
if (isPlaying)
{
isPlaying = false;
audioSource.Pause();
}
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
public static class PlayerControllerB_Patch
{
public static Dictionary<PlayerControllerB, SnakeEater> snakeEaters = new Dictionary<PlayerControllerB, SnakeEater>();
private static SnakeEater Solidify(PlayerControllerB __instance)
{
if (!snakeEaters.TryGetValue(__instance, out var value))
{
value = new SnakeEater(__instance);
snakeEaters.Add(__instance, value);
}
return value;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerControllerB), "Start")]
private static void Start(PlayerControllerB __instance)
{
Solidify(__instance);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerControllerB), "OnDestroy")]
private static void OnDestroy(PlayerControllerB __instance)
{
snakeEaters.Remove(__instance);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerControllerB), "Update")]
private static void Update(PlayerControllerB __instance)
{
Solidify(__instance).Update();
}
}
[HarmonyPatch(typeof(RoundManager))]
public static class RoundManager_Patch
{
[HarmonyPostfix]
[HarmonyPatch(typeof(RoundManager), "InitializeRandomNumberGenerators")]
private static void StartGame(RoundManager __instance)
{
LethalLadderMusicPlugin.ladderMusicIndex = __instance.LevelRandom.Next(0, LethalLadderMusicPlugin.ladderMusic.Count);
LethalLadderMusicPlugin.logger.LogInfo((object)$"Random ladder music set to: {LethalLadderMusicPlugin.ladderMusicIndex}");
foreach (KeyValuePair<PlayerControllerB, SnakeEater> snakeEater in PlayerControllerB_Patch.snakeEaters)
{
snakeEater.Value.RefreshClip();
}
}
}
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resources
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan == null)
{
resourceMan = new ResourceManager("LethalLadderMusic.Resources", typeof(Resources).Assembly);
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal static byte[] Music => (byte[])ResourceManager.GetObject("Music", resourceCulture);
internal Resources()
{
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "Spantle.LethalLadderMusic";
public const string PLUGIN_NAME = "LethalLadderMusic";
public const string PLUGIN_VERSION = "1.0.0";
}
}