using System;
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("PortasModdedSounds")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PortasModdedSounds")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("DC3E08B9-C047-4227-B3CE-F102ACCF9D92")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PortasModdedSounds
{
public struct AudioAssets
{
public AudioClip jackbox;
public AudioClip bug1;
public AudioClip bug2;
public AudioClip bug3;
public AudioClip bugFly;
public AudioClip greatAsset;
public AudioClip iceCream;
public AudioClip Fired;
public AudioAssets(AudioClip jackbox, AudioClip bug1, AudioClip bug2, AudioClip bug3, AudioClip bugFly, AudioClip greatAsset, AudioClip iceCream, AudioClip fired)
{
this.jackbox = jackbox;
this.bug1 = bug1;
this.bug2 = bug2;
this.bug3 = bug3;
this.bugFly = bugFly;
this.greatAsset = greatAsset;
this.iceCream = iceCream;
Fired = fired;
}
}
public static class AssetLoader
{
public static AudioAssets Load()
{
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Expected O, but got Unknown
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Expected O, but got Unknown
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Expected O, but got Unknown
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Expected O, but got Unknown
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Expected O, but got Unknown
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Expected O, but got Unknown
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Expected O, but got Unknown
//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Expected O, but got Unknown
AssetBundle val = AssetBundle.LoadFromFile(ModBase.Instance.AssetBundlePath);
Object[] array = val.LoadAllAssets();
Object[] array2 = array;
foreach (Object val2 in array2)
{
ModBase.Instance.MLS.LogInfo((object)("Asset: " + val2.name));
}
AudioClip val3 = (AudioClip)array.Where((Object t) => t.name == "GreatAsset").FirstOrDefault();
AudioClip val4 = (AudioClip)array.Where((Object t) => t.name == "March").FirstOrDefault();
AudioClip val5 = (AudioClip)array.Where((Object t) => t.name == "Bug1").FirstOrDefault();
AudioClip val6 = (AudioClip)array.Where((Object t) => t.name == "Bug2").FirstOrDefault();
AudioClip val7 = (AudioClip)array.Where((Object t) => t.name == "Bug3").FirstOrDefault();
AudioClip val8 = (AudioClip)array.Where((Object t) => t.name == "BugFly").FirstOrDefault();
AudioClip val9 = (AudioClip)array.Where((Object t) => t.name == "IceCream").FirstOrDefault();
AudioClip fired = (AudioClip)array.Where((Object t) => t.name == "Fired").FirstOrDefault();
if (val4.length < 1f)
{
ModBase.Instance.MLS.LogError((object)"Jackbox is too short!");
}
if (val5.length < 1f)
{
ModBase.Instance.MLS.LogError((object)"Bug1 is too short!");
}
if (val6.length < 1f)
{
ModBase.Instance.MLS.LogError((object)"Bug2 is too short!");
}
if (val7.length < 1f)
{
ModBase.Instance.MLS.LogError((object)"Bug3 is too short!");
}
if (val8.length < 1f)
{
ModBase.Instance.MLS.LogError((object)"BugFly is too short!");
}
if (val3.length < 1f)
{
ModBase.Instance.MLS.LogError((object)"GreatAsset is too short!");
}
if (val9.length < 1f)
{
ModBase.Instance.MLS.LogError((object)"IceCream is too short!");
}
ModBase.Instance.MLS.LogInfo((object)"Loaded all assets!");
return new AudioAssets(val4, val5, val6, val7, val8, val3, val9, fired);
}
}
[BepInPlugin("com.porta137.portamoddedsounds", "PortaModdedSounds", "1.0.0")]
public class ModBase : BaseUnityPlugin
{
private const string GUID = "com.porta137.portamoddedsounds";
private const string NAME = "PortaModdedSounds";
private const string VERSION = "1.0.0";
public Harmony harmony = new Harmony("com.porta137.portamoddedsounds");
public static ModBase Instance;
internal ManualLogSource MLS;
public string AssetBundlePath;
public AssetBundle assetBundle;
public AudioAssets assets;
private void Awake()
{
if (!Object.op_Implicit((Object)(object)Instance))
{
Instance = this;
}
MLS = Logger.CreateLogSource("com.porta137.portamoddedsounds");
MLS.LogInfo((object)"Loading Portas Modded Sounds");
AssetBundlePath = ((BaseUnityPlugin)Instance).Info.Location.TrimEnd("PortasModdedSounds.dll".ToCharArray()) + "bundle";
MLS.LogInfo((object)("Using AssetBundlePath: " + AssetBundlePath));
MLS.LogInfo((object)"Loading AudioAssets");
assets = AssetLoader.Load();
MLS.LogInfo((object)"Bundle loaded, patching...");
harmony.PatchAll();
MLS.LogInfo((object)"Mod loading Complete!");
}
}
}
namespace PortasModdedSounds.Patches
{
[HarmonyPatch(typeof(StartOfRound))]
public class AAAA
{
[HarmonyPostfix]
[HarmonyPatch("playersFiredGameOver")]
public static IEnumerator Patch(IEnumerator result, StartOfRound __instance)
{
result = FiredSeq(__instance);
return result;
}
public static IEnumerator FiredSeq(StartOfRound __instance)
{
__instance.speakerAudioSource.PlayOneShot(ModBase.Instance.assets.Fired);
yield return (object)new WaitForSeconds(35.13f);
((Component)__instance.shipAnimatorObject).gameObject.GetComponent<Animator>().SetBool("AlarmRinging", true);
__instance.shipRoomLights.SetShipLightsOnLocalClientOnly(false);
__instance.shipDoorAudioSource.PlayOneShot(__instance.alarmSFX);
yield return (object)new WaitForSeconds(9.37f);
__instance.shipDoorsAnimator.SetBool("OpenInOrbit", true);
__instance.shipDoorAudioSource.PlayOneShot(__instance.airPressureSFX);
__instance.starSphereObject.SetActive(true);
__instance.starSphereObject.transform.position = ((Component)GameNetworkManager.Instance.localPlayerController).transform.position;
yield return (object)new WaitForSeconds(0.25f);
__instance.suckingPlayersOutOfShip = true;
__instance.suckingFurnitureOutOfShip = true;
PlaceableShipObject[] array = Object.FindObjectsOfType<PlaceableShipObject>();
for (int i = 0; i < array.Length; i++)
{
if ((Object)(object)array[i].parentObject == (Object)null)
{
Debug.Log((object)("Error! No parentObject for placeable object: " + __instance.unlockablesList.unlockables[array[i].unlockableID].unlockableName));
}
array[i].parentObject.StartSuckingOutOfShip();
if (__instance.unlockablesList.unlockables[array[i].unlockableID].spawnPrefab)
{
Collider[] componentsInChildren = ((Component)array[i].parentObject).GetComponentsInChildren<Collider>();
for (int j = 0; j < componentsInChildren.Length; j++)
{
componentsInChildren[j].enabled = false;
}
}
}
GameNetworkManager.Instance.localPlayerController.inSpecialInteractAnimation = true;
GameNetworkManager.Instance.localPlayerController.DropAllHeldItems(true, false);
HUDManager.Instance.UIAudio.PlayOneShot(__instance.suckedIntoSpaceSFX);
yield return (object)new WaitForSeconds(6f);
SoundManager.Instance.SetDiageticMixerSnapshot(3, 2f);
HUDManager.Instance.ShowPlayersFiredScreen(true);
yield return (object)new WaitForSeconds(2f);
__instance.starSphereObject.SetActive(false);
__instance.shipDoorAudioSource.Stop();
__instance.speakerAudioSource.Stop();
__instance.suckingFurnitureOutOfShip = false;
if (((NetworkBehaviour)__instance).IsServer)
{
GameNetworkManager.Instance.ResetSavedGameValues();
}
Debug.Log((object)"Calling reset ship!");
__instance.ResetShip();
Object.FindObjectOfType<Terminal>().SetItemSales();
yield return (object)new WaitForSeconds(6f);
((Component)__instance.shipAnimatorObject).gameObject.GetComponent<Animator>().SetBool("AlarmRinging", false);
GameNetworkManager.Instance.localPlayerController.TeleportPlayer(__instance.playerSpawnPositions[(int)(IntPtr)checked((long)GameNetworkManager.Instance.localPlayerController.playerClientId)].position, false, 0f, false, true);
__instance.shipDoorsAnimator.SetBool("OpenInOrbit", false);
__instance.currentPlanetPrefab.transform.position = ((Component)__instance.planetContainer).transform.position;
__instance.suckingPlayersOutOfShip = false;
typeof(StartOfRound).GetField("choseRandomFlyDirForPlayer", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance, false);
__instance.suckingPower = 0f;
__instance.shipRoomLights.SetShipLightsOnLocalClientOnly(true);
yield return (object)new WaitForSeconds(2f);
if (((NetworkBehaviour)__instance).IsServer)
{
FieldInfo reviedField = typeof(StartOfRound).GetField("playersRevived", BindingFlags.Instance | BindingFlags.NonPublic);
reviedField.SetValue(__instance, (int)reviedField.GetValue(__instance) + 1);
yield return (object)new WaitUntil((Func<bool>)(() => (int)reviedField.GetValue(__instance) >= GameNetworkManager.Instance.connectedPlayers));
reviedField.SetValue(__instance, 0);
__instance.EndPlayersFiredSequenceClientRpc();
}
else
{
__instance.PlayerHasRevivedServerRpc();
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
public class GreatAssetPatch
{
[HarmonyPatch("Start")]
[HarmonyPrefix]
public static void Prefix(StartOfRound __instance)
{
__instance.shipIntroSpeechSFX = ModBase.Instance.assets.greatAsset;
ModBase.Instance.MLS.LogInfo((object)"Patched StartOfRound");
}
}
[HarmonyPatch(typeof(HoarderBugAI))]
public class HoardingBugPatch
{
[HarmonyPatch("Start")]
[HarmonyPrefix]
public static void Prefix(ref AudioClip[] ___chitterSFX, ref AudioClip ___angryVoiceSFX)
{
___chitterSFX = (AudioClip[])(object)new AudioClip[3]
{
ModBase.Instance.assets.bug1,
ModBase.Instance.assets.bug2,
ModBase.Instance.assets.bug3
};
___angryVoiceSFX = ModBase.Instance.assets.bugFly;
}
}
[HarmonyPatch(typeof(ItemDropship))]
public class IceCreamPatch
{
[HarmonyPatch("Start")]
[HarmonyPrefix]
public static void Prefix(ItemDropship __instance)
{
AudioSource component = ((Component)((Component)__instance).transform.Find("Music")).gameObject.GetComponent<AudioSource>();
AudioSource component2 = ((Component)((Component)((Component)__instance).transform.Find("Music")).transform.Find("Music (1)")).gameObject.GetComponent<AudioSource>();
component.clip = ModBase.Instance.assets.iceCream;
component2.clip = ModBase.Instance.assets.iceCream;
}
}
[HarmonyPatch(typeof(JesterAI))]
public class JackintheboxPatch
{
[HarmonyPatch("Start")]
[HarmonyPrefix]
public static void Prefix(ref AudioClip ___popGoesTheWeaselTheme)
{
___popGoesTheWeaselTheme = ModBase.Instance.assets.jackbox;
}
}
}