using System;
using System.Collections;
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.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
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("scooxstad.snakeeater")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.6.0")]
[assembly: AssemblyInformationalVersion("1.1.6+a40078e58633d5a9e116493358243700e8bda186")]
[assembly: AssemblyProduct("SnakeEater")]
[assembly: AssemblyTitle("scooxstad.snakeeater")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.6.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.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;
}
}
[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 SnakeEater
{
[BepInPlugin("scooxstad.snakeeater", "SnakeEater", "1.1.6")]
public class SnakeEater : BaseUnityPlugin
{
internal static ConfigEntry<bool> Restart;
internal static ConfigEntry<bool> Restrict;
internal static ConfigEntry<float> HeightThreshold;
internal static ConfigEntry<float> AudioVolume;
internal static ConfigEntry<float> AudioFadeIn;
internal static ConfigEntry<float> AudioDelay;
public static SnakeEater Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
internal static Harmony? Harmony { get; set; }
internal static AudioClip SnakeEaterAudio { get; set; }
internal static AudioSource SnakeEaterAudioSource { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(directoryName, "snakeeater"));
SnakeEaterAudio = val.LoadAsset<AudioClip>("SnakeEater");
SnakeEaterAudio.LoadAudioData();
Patch();
InitializeConfig();
try
{
InitializeLethalConfigIntegration();
}
catch (FileNotFoundException)
{
Logger.LogInfo((object)"LethalConfig.dll not found");
}
Logger.LogInfo((object)"scooxstad.snakeeater v1.1.6 has loaded!");
}
internal void InitializeConfig()
{
AudioVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio Properties", "Volume", 1f, "Playback volume relative to source audio file");
AudioFadeIn = ((BaseUnityPlugin)this).Config.Bind<float>("Audio Properties", "Fade-in duration", 0.3f, "Duration of fade-in to playback in seconds");
AudioDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Audio Properties", "Delay", 1f, "Time after mounting a ladder before playback beings in seconds");
Restart = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Restart audio", true, "Restarts the audio each time an applicable ladder is mounted");
Restrict = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Restrict ladders", true, "Only allow ladders past a certain height threshold to begin playback");
HeightThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Height threshold", 12f, "Minimum height which will allow playback when \"Restrict ladders\" is enabled");
}
internal void InitializeLethalConfigIntegration()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Expected O, but got Unknown
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Expected O, but got Unknown
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Expected O, but got Unknown
//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
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got Unknown
LethalConfigManager.SetModDescription("SnakeEater");
LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Restart, false));
LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Restrict, false));
LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(HeightThreshold, false));
ConfigEntry<float> audioVolume = AudioVolume;
FloatSliderOptions val = new FloatSliderOptions();
((BaseRangeOptions<float>)val).Max = 2f;
((BaseRangeOptions<float>)val).Min = 0f;
((BaseOptions)val).RequiresRestart = false;
LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(audioVolume, val));
LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(AudioFadeIn, false));
LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(AudioDelay, false));
AudioVolume.SettingChanged += delegate
{
SnakeEaterAudioSource.volume = AudioVolume.Value / 2f;
};
}
internal static void Patch()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("scooxstad.snakeeater");
}
Logger.LogDebug((object)"Patching...");
Harmony.PatchAll();
Logger.LogDebug((object)"Finished patching!");
}
internal static void Unpatch()
{
Logger.LogDebug((object)"Unpatching...");
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Logger.LogDebug((object)"Finished unpatching!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "scooxstad.snakeeater";
public const string PLUGIN_NAME = "SnakeEater";
public const string PLUGIN_VERSION = "1.1.6";
}
}
namespace SnakeEater.Patches
{
[HarmonyPatch(typeof(InteractTrigger))]
internal class InteractTriggerPatch
{
private static Coroutine PlaybackCoroutine;
[HarmonyPatch("SetUsingLadderOnLocalClient")]
[HarmonyPrefix]
internal static void TogglePlayback(InteractTrigger __instance, bool isUsing)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
float num = Vector3.Distance(__instance.bottomOfLadderPosition.position, __instance.topOfLadderPosition.position);
if (isUsing)
{
if (!SnakeEater.Restrict.Value || (SnakeEater.Restrict.Value && SnakeEater.HeightThreshold.Value <= num))
{
PlaybackCoroutine = ((MonoBehaviour)__instance).StartCoroutine(BeginPlayback());
}
return;
}
if (PlaybackCoroutine != null)
{
((MonoBehaviour)__instance).StopCoroutine(PlaybackCoroutine);
}
if (SnakeEater.SnakeEaterAudioSource.isPlaying)
{
SnakeEater.SnakeEaterAudioSource.Pause();
}
}
internal static IEnumerator BeginPlayback()
{
yield return (object)new WaitForSeconds(SnakeEater.AudioDelay.Value);
AudioSource audioSource = SnakeEater.SnakeEaterAudioSource;
if (SnakeEater.Restart.Value)
{
audioSource.time = 0f;
}
audioSource.volume = 0f;
audioSource.Play();
float fadeInDuration = SnakeEater.AudioFadeIn.Value;
float targetVolume = SnakeEater.AudioVolume.Value / 2f;
float timeElapsed = 0f;
if (fadeInDuration > 0f)
{
while (timeElapsed < fadeInDuration)
{
audioSource.volume = Mathf.Lerp(0f, targetVolume, timeElapsed / fadeInDuration);
timeElapsed += Time.deltaTime;
yield return null;
}
}
else
{
audioSource.volume = SnakeEater.AudioVolume.Value / 2f;
}
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
[HarmonyPatch("ConnectClientToPlayerObject")]
[HarmonyPostfix]
private static void AttachAudioSource(PlayerControllerB __instance)
{
AudioSource val = ((Component)__instance).gameObject.AddComponent<AudioSource>();
if ((Object)(object)val != (Object)null)
{
val.playOnAwake = false;
val.clip = SnakeEater.SnakeEaterAudio;
SnakeEater.SnakeEaterAudioSource = val;
SnakeEater.Logger.LogInfo((object)"Audio source attached");
}
else
{
SnakeEater.Logger.LogError((object)"Failed to attach Snake Eater audio source");
}
}
}
}