using System;
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 ImmortalSnail;
using LCSoundTool;
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("tracerx.CarminaBuranaSnail")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CarminaBuranaSnail")]
[assembly: AssemblyTitle("tracerx.CarminaBuranaSnail")]
[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.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 CarminaBuranaSnail
{
[BepInPlugin("tracerx.CarminaBuranaSnail", "CarminaBuranaSnail", "1.0.0")]
public class CarminaBuranaSnail : BaseUnityPlugin
{
public static CarminaBuranaSnail Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
internal static Harmony? Harmony { get; set; }
public static Config MyConfig { get; internal set; }
public static ManualLogSource LoggerInstance { get; private set; }
private void Awake()
{
MyConfig = new Config(((BaseUnityPlugin)this).Config);
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
LoggerInstance = Logger;
Patch();
Logger.LogInfo((object)"tracerx.CarminaBuranaSnail v1.0.0 has loaded!");
}
internal static void Patch()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("tracerx.CarminaBuranaSnail");
}
Logger.LogDebug((object)"Plugin CarminaBuranaSnail loaded successfully.");
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 class Config
{
public ConfigEntry<float> ConfigVolume;
public ConfigEntry<bool> ConfigPlayWhenSnailCanSeeTarget;
public ConfigEntry<bool> ConfigPlayWhenLookingAtSnail;
public ConfigEntry<int> ConfigDistance;
public ConfigEntry<bool> ConfigPauseWhenNotLooking;
public ConfigEntry<string> ConfigAudioFile;
public Config(ConfigFile cfg)
{
ConfigVolume = cfg.Bind<float>("Volume", "MusicVolume", 1f, "Volume of the music. Must be between 0 and 1.");
ConfigPlayWhenSnailCanSeeTarget = cfg.Bind<bool>("Looking Mechanic", "PlayWhenSnailCanSeeTarget", true, "Play the music when the snail can see the target.");
ConfigPlayWhenLookingAtSnail = cfg.Bind<bool>("Looking Mechanic", "PlayWhenLookingAtSnail", false, "Play the music when the player is looking at the snail. Everything below this only works if one the two options is set to true.");
ConfigDistance = cfg.Bind<int>("Looking Mechanic", "Distance", 50, "Play the music only when the player is looking at a certain distance of the snail.");
ConfigPauseWhenNotLooking = cfg.Bind<bool>("Looking Mechanic", "PauseWhenNotLooking", true, "Whether to pause the music when not looking at the snail, or stop it and start it over again when looking again. true = Pause, false = Stop.");
ConfigAudioFile = cfg.Bind<string>("Audio to play", "AudioFilePath", "o_fortuna.mp3", "Path to the audio file to play when looking at the snail.");
}
}
public class SnailMusicController : MonoBehaviour
{
public SnailAI SnailInstance;
public void Update()
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
CarminaBuranaSnail.LoggerInstance.LogDebug((object)"SnailMusicController.Update");
if (!CarminaBuranaSnail.MyConfig.ConfigPlayWhenLookingAtSnail.Value && !CarminaBuranaSnail.MyConfig.ConfigPlayWhenSnailCanSeeTarget.Value)
{
return;
}
PlayerControllerB targetPlayer = ((EnemyAI)SnailInstance).targetPlayer;
float num = Vector3.Distance(((Component)SnailInstance).transform.position, ((Component)targetPlayer).transform.position);
bool flag = num < (float)CarminaBuranaSnail.MyConfig.ConfigDistance.Value;
if (CarminaBuranaSnail.MyConfig.ConfigPlayWhenSnailCanSeeTarget.Value && !Physics.Linecast(((Component)SnailInstance).transform.position + Vector3.up * 0.5f, ((Component)targetPlayer.gameplayCamera).transform.position, StartOfRound.Instance.collidersAndRoomMaskAndDefault) && flag)
{
if (!((EnemyAI)SnailInstance).creatureSFX.isPlaying)
{
((EnemyAI)SnailInstance).creatureSFX.Play();
}
}
else if (GameNetworkManager.Instance.localPlayerController.HasLineOfSightToPosition(((Component)SnailInstance).transform.position, 70f, CarminaBuranaSnail.MyConfig.ConfigDistance.Value, -1f))
{
if (!((EnemyAI)SnailInstance).creatureSFX.isPlaying)
{
((EnemyAI)SnailInstance).creatureSFX.Play();
}
}
else if (CarminaBuranaSnail.MyConfig.ConfigPauseWhenNotLooking.Value)
{
((EnemyAI)SnailInstance).creatureSFX.Pause();
}
else
{
((EnemyAI)SnailInstance).creatureSFX.Stop();
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "tracerx.CarminaBuranaSnail";
public const string PLUGIN_NAME = "CarminaBuranaSnail";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace CarminaBuranaSnail.Patches
{
[HarmonyPatch(typeof(SnailAI))]
public class SnailAIPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPatch(SnailAI __instance)
{
AudioClip audioClip = SoundTool.GetAudioClip(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), CarminaBuranaSnail.MyConfig.ConfigAudioFile.Value);
((EnemyAI)__instance).creatureSFX = ((Component)__instance).gameObject.AddComponent<AudioSource>();
((EnemyAI)__instance).creatureSFX.clip = audioClip;
((EnemyAI)__instance).creatureSFX.loop = true;
((EnemyAI)__instance).creatureSFX.volume = CarminaBuranaSnail.MyConfig.ConfigVolume.Value;
((EnemyAI)__instance).creatureSFX.spatialBlend = 1f;
((Component)__instance).gameObject.AddComponent<SnailMusicController>().SnailInstance = __instance;
if (!CarminaBuranaSnail.MyConfig.ConfigPlayWhenLookingAtSnail.Value)
{
((EnemyAI)__instance).creatureSFX.Play();
}
}
}
}