using System;
using System.CodeDom.Compiler;
using System.Collections;
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")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Play the HELLDIVERS 2 Extraction theme/music when voting to leave or right before midnight.")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2")]
[assembly: AssemblyProduct("LethalExtraction")]
[assembly: AssemblyTitle("Spantle.LethalExtraction")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.2.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 LethalExtraction
{
[BepInPlugin("Spantle.LethalExtraction", "LethalExtraction", "1.1.2")]
public class LethalExtractionPlugin : BaseUnityPlugin
{
private readonly Harmony harmony = new Harmony("Spantle.LethalExtraction");
public static ManualLogSource logger;
public static AudioClip musicShip;
public static AudioClip musicInside;
public static AudioClip musicOutside;
public static AudioClip musicSuccess;
public static AudioClip musicFailure;
public static ConfigEntry<int> volume;
public static ConfigEntry<bool> alwaysPlayEndTheme;
public static bool PlayingMusic;
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
logger = ((BaseUnityPlugin)this).Logger;
volume = ((BaseUnityPlugin)this).Config.Bind<int>("Client-side settings", "Volume", 20, new ConfigDescription("The volume percentage that the music will play at.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
alwaysPlayEndTheme = ((BaseUnityPlugin)this).Config.Bind<bool>("Client-side settings", "Always play end theme", false, new ConfigDescription("If set to true, then the ending success/failure theme will always play. If set to false, then it will only play if the Extraction theme played.", (AcceptableValueBase)null, Array.Empty<object>()));
AssetBundle obj = AssetBundle.LoadFromMemory(Resources.lethalextractionmusic);
musicShip = obj.LoadAsset<AudioClip>("Assets/ship.ogg");
musicInside = obj.LoadAsset<AudioClip>("Assets/inside.ogg");
musicOutside = obj.LoadAsset<AudioClip>("Assets/outside.ogg");
musicSuccess = obj.LoadAsset<AudioClip>("Assets/success.ogg");
musicFailure = obj.LoadAsset<AudioClip>("Assets/failure.ogg");
harmony.PatchAll(typeof(TimeOfDay_Patch));
harmony.PatchAll(typeof(StartOfRound_Patch));
((BaseUnityPlugin)this).Logger.LogInfo((object)"Ready to serve Democracy and fight for Super Earth! Spantle.LethalExtraction has loaded!");
}
public static void PlaySound(AudioClip audioClip)
{
HUDManager.Instance.UIAudio.PlayOneShot(audioClip, (float)volume.Value / 100f);
}
}
[HarmonyPatch(typeof(TimeOfDay))]
public static class TimeOfDay_Patch
{
public enum PlayerLocation
{
InsideFactory,
InsideShip,
Outside
}
public static PlayerLocation GetPlayerLocation(PlayerControllerB player)
{
if (player.isInsideFactory)
{
return PlayerLocation.InsideFactory;
}
if (player.isInElevator)
{
return PlayerLocation.InsideShip;
}
return PlayerLocation.Outside;
}
public static PlayerControllerB GetCurrentPlayer()
{
return StartOfRound.Instance.localPlayerController;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(TimeOfDay), "SetShipLeaveEarlyClientRpc")]
private static void SetShipLeaveEarlyClientRpc(TimeOfDay __instance)
{
LethalExtractionPlugin.logger.LogInfo((object)"Everyone voted to leave.");
((MonoBehaviour)__instance).StartCoroutine(StartExtractionMusic());
}
[HarmonyPrefix]
[HarmonyPatch(typeof(TimeOfDay), "TimeOfDayEvents")]
private static void TimeOfDayEvents(TimeOfDay __instance)
{
if (__instance.currentLevel.planetHasTime && !StartOfRound.Instance.shipIsLeaving && !__instance.shipLeavingAlertCalled && __instance.currentDayTime / __instance.totalTime > 0.9f)
{
LethalExtractionPlugin.logger.LogInfo((object)"Midnight approaches.");
((MonoBehaviour)__instance).StartCoroutine(StartExtractionMusic());
}
}
private static IEnumerator StartExtractionMusic()
{
if (LethalExtractionPlugin.PlayingMusic)
{
yield break;
}
LethalExtractionPlugin.PlayingMusic = true;
PlayerControllerB val = GetCurrentPlayer();
if (val.isPlayerDead)
{
val = GetCurrentPlayer().spectatedPlayerScript;
}
if ((Object)(object)val == (Object)null)
{
LethalExtractionPlugin.PlayingMusic = false;
yield break;
}
PlayerLocation playerLocation = GetPlayerLocation(val);
LethalExtractionPlugin.logger.LogInfo((object)("Starting extraction music for: " + playerLocation));
AudioClip val2 = LethalExtractionPlugin.musicInside;
switch (playerLocation)
{
case PlayerLocation.InsideShip:
val2 = LethalExtractionPlugin.musicShip;
break;
case PlayerLocation.InsideFactory:
val2 = LethalExtractionPlugin.musicInside;
break;
case PlayerLocation.Outside:
val2 = LethalExtractionPlugin.musicOutside;
break;
}
LethalExtractionPlugin.PlaySound(val2);
yield return (object)new WaitForSeconds(val2.length);
LethalExtractionPlugin.PlayingMusic = false;
}
}
[HarmonyPatch(typeof(StartOfRound))]
public static class StartOfRound_Patch
{
private static bool PlayingEndMusic;
[HarmonyPrefix]
[HarmonyPatch(typeof(StartOfRound), "EndOfGameClientRpc")]
private static void EndOfGameClientRpc(StartOfRound __instance)
{
((MonoBehaviour)__instance).StartCoroutine(StartEndMusic(__instance.allPlayersDead));
}
private static IEnumerator StartEndMusic(bool failure)
{
if (!PlayingEndMusic && (LethalExtractionPlugin.alwaysPlayEndTheme.Value || LethalExtractionPlugin.PlayingMusic))
{
PlayingEndMusic = true;
LethalExtractionPlugin.logger.LogInfo((object)"Game over.");
if (LethalExtractionPlugin.PlayingMusic)
{
HUDManager.Instance.UIAudio.Stop();
LethalExtractionPlugin.PlayingMusic = false;
}
AudioClip val = LethalExtractionPlugin.musicSuccess;
if (failure)
{
val = LethalExtractionPlugin.musicFailure;
}
LethalExtractionPlugin.PlaySound(val);
yield return (object)new WaitForSeconds(val.length);
PlayingEndMusic = false;
}
}
}
[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("LethalExtraction.Resources", typeof(Resources).Assembly);
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal static byte[] lethalextractionmusic => (byte[])ResourceManager.GetObject("lethalextractionmusic", resourceCulture);
internal Resources()
{
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "Spantle.LethalExtraction";
public const string PLUGIN_NAME = "LethalExtraction";
public const string PLUGIN_VERSION = "1.1.2";
}
}