Decompiled source of Porta Punishment v2.1.0

PortaPunishment/LC_PortaPunishment.dll

Decompiled a year ago
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("LC_PortaPunishment")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LC_PortaPunishment")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4A9D61E3-5459-463F-82C2-99D4CB4C90A1")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LC_PortaPunishment;

public struct AudioAssets
{
	public AudioClip voiceMessage;

	public AudioClip executionMusic;

	public AudioAssets(AudioClip voiceMessage, AudioClip executionMusic)
	{
		this.voiceMessage = voiceMessage;
		this.executionMusic = executionMusic;
	}
}
public static class BundleLoader
{
	public static AudioAssets Load()
	{
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Expected O, but got Unknown
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Expected O, but got Unknown
		string text = ((BaseUnityPlugin)ModBase.Instance).Info.Location.TrimEnd("LC_PortaPunishment.dll".ToCharArray()) + "portapunishmentbundle";
		ModBase.Instance.MLS.LogInfo((object)("Using AssetBundlePath: " + text));
		AssetBundle val = AssetBundle.LoadFromFile(text);
		Object[] source = val.LoadAllAssets();
		AudioClip val2 = (AudioClip)source.Where((Object t) => t.name == "VoiceMessage").FirstOrDefault();
		AudioClip val3 = (AudioClip)source.Where((Object t) => t.name == "ExecutionMusic").FirstOrDefault();
		if (val2.length < 1f)
		{
			ModBase.Instance.MLS.LogError((object)"VoiceMessage is too short!");
		}
		if (val3.length < 1f)
		{
			ModBase.Instance.MLS.LogError((object)"ExecutionMusic is too short!");
		}
		return new AudioAssets(val2, val3);
	}
}
[HarmonyPatch(typeof(StartOfRound))]
public class ExecutionPatch
{
	[HarmonyPostfix]
	[HarmonyPatch("playersFiredGameOver")]
	public static IEnumerator Patch(IEnumerator result, StartOfRound __instance)
	{
		result = Event(__instance);
		return result;
	}

	private static IEnumerator Event(StartOfRound __instance)
	{
		__instance.shipDoorAudioSource.PlayOneShot(ModBase.Instance.AudioAssets.executionMusic);
		yield return (object)new WaitForSeconds(13.5f);
		__instance.speakerAudioSource.PlayOneShot(ModBase.Instance.AudioAssets.voiceMessage);
		yield return (object)new WaitForSeconds(28.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();
		}
	}
}
[BepInPlugin("com.porta137.portapunishment", "PortaPunishment", "1.0.0")]
public class ModBase : BaseUnityPlugin
{
	private const string GUID = "com.porta137.portapunishment";

	private const string NAME = "PortaPunishment";

	private const string VERSION = "1.0.0";

	public Harmony harmony = new Harmony("com.porta137.portapunishment");

	public static ModBase Instance;

	internal ManualLogSource MLS;

	public AudioAssets AudioAssets;

	private void Awake()
	{
		if (!Object.op_Implicit((Object)(object)Instance))
		{
			Instance = this;
		}
		MLS = Logger.CreateLogSource("com.porta137.portapunishment");
		MLS.LogInfo((object)"Loading Portas Punishment");
		AudioAssets = BundleLoader.Load();
		MLS.LogInfo((object)"Bundle loaded, patching...");
		harmony.PatchAll();
		MLS.LogInfo((object)"Mod loading Complete!");
	}
}