Decompiled source of PEAKRandomRagdoll v2.0.2

Plugins/PEAKRandomRagdoll.dll

Decompiled 18 hours ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
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("PEAKRandomRagdoll")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PEAKRandomRagdoll")]
[assembly: AssemblyTitle("PEAKRandomRagdoll")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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;
		}
	}
}
[BepInPlugin("prozi.randomragdoll", "Random Ragdoll", "2.0.0")]
public class Plugin : BaseUnityPlugin
{
	public static Plugin Instance;

	private Coroutine ragdollLoopCoroutine;

	private void Awake()
	{
		Instance = this;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"=================================");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Random Ragdoll loaded!");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"=================================");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"About to add RagdollNetwork component...");
		try
		{
			((Component)this).gameObject.AddComponent<RagdollNetwork>();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"RagdollNetwork component added successfully.");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("FAILED to add RagdollNetwork: " + ex));
		}
	}

	public static void Log(string message)
	{
		if ((Object)(object)Instance != (Object)null)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)("[Random Ragdoll] " + message));
		}
	}

	public void StartRandomRagdoll()
	{
		if (ragdollLoopCoroutine == null)
		{
			ragdollLoopCoroutine = ((MonoBehaviour)this).StartCoroutine(RandomRagdollLoop());
		}
	}

	public void StopRandomRagdoll()
	{
		if (ragdollLoopCoroutine != null)
		{
			((MonoBehaviour)this).StopCoroutine(ragdollLoopCoroutine);
			ragdollLoopCoroutine = null;
		}
	}

	private IEnumerator RandomRagdollLoop()
	{
		while (true)
		{
			float num = Random.Range(60f, 600f);
			Log("Next ragdoll in " + num.ToString("F1") + " seconds.");
			yield return (object)new WaitForSeconds(num);
			RagdollNetwork.RagdollAll();
		}
	}
}
public class RagdollNetwork : MonoBehaviourPunCallbacks
{
	private bool wasMasterClient;

	private void Start()
	{
		Debug.Log((object)"[Random Ragdoll] RagdollNetwork.Start() called.");
		Plugin.Log("RagdollNetwork.Start() called.");
		UpdateRagdollLoopState();
	}

	private void Update()
	{
		if ((PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient) != wasMasterClient)
		{
			UpdateRagdollLoopState();
		}
	}

	public override void OnJoinedRoom()
	{
		UpdateRagdollLoopState();
	}

	public override void OnLeftRoom()
	{
		UpdateRagdollLoopState();
	}

	public override void OnMasterClientSwitched(Player newMasterClient)
	{
		UpdateRagdollLoopState();
	}

	private void UpdateRagdollLoopState()
	{
		bool flag = (wasMasterClient = PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient);
		if (!((Object)(object)Plugin.Instance == (Object)null))
		{
			if (flag)
			{
				Plugin.Instance.StartRandomRagdoll();
			}
			else
			{
				Plugin.Instance.StopRandomRagdoll();
			}
		}
	}

	public static void RagdollAll()
	{
		if (!PhotonNetwork.InRoom)
		{
			Plugin.Log("Not in a room.");
		}
		else
		{
			if (!PhotonNetwork.IsMasterClient)
			{
				return;
			}
			Character[] array = Object.FindObjectsByType<Character>((FindObjectsSortMode)0);
			Plugin.Log("Ragdoll event started! Candidates: " + array.Length);
			int num = 0;
			Character[] array2 = array;
			foreach (Character val in array2)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.data == (Object)null) && !((Object)(object)((MonoBehaviourPun)val).photonView == (Object)null) && !val.data.dead && !val.data.passedOut && !val.data.fullyPassedOut && !(val.data.fallSeconds > 0f))
				{
					try
					{
						((MonoBehaviourPun)val).photonView.RPC("RPCA_Fall", (RpcTarget)0, new object[2] { 2f, 0f });
						Plugin.Log("Ragdoll: " + ((Object)val).name);
						num++;
					}
					catch (Exception ex)
					{
						Plugin.Log("Ragdoll error on " + ((Object)val).name + ": " + ex);
					}
				}
			}
			Plugin.Log("Ragdoll event finished! Ragdolled " + num + " player(s).");
		}
	}
}