Decompiled source of Rabies v1.0.2

Rabies.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Rabies")]
[assembly: AssemblyTitle("Rabies")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace Empress.RabiesMod
{
	[BepInPlugin("Empress.RabiesMod", "RabiesMod", "1.0.1")]
	public class RabiesPlugin : BaseUnityPlugin, IOnEventCallback
	{
		public const string PluginGuid = "Empress.RabiesMod";

		public const string PluginName = "RabiesMod";

		public const string PluginVersion = "1.0.1";

		private const byte RabiesEventCode = 160;

		private const int EventType_Assign = 0;

		private const int EventType_TransferRequest = 1;

		private const int EventType_TransferComplete = 2;

		private const int EventType_Death = 3;

		private ConfigEntry<KeyCode> _triggerKey;

		private ConfigEntry<int> _rabiesChance;

		private int _infectedViewID = -1;

		private float _rabiesTimer = 0f;

		private bool _isRoundActive = false;

		private void Awake()
		{
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			_triggerKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "PassRabiesKey", (KeyCode)118, "Key to pass rabies to a nearby player.");
			_rabiesChance = ((BaseUnityPlugin)this).Config.Bind<int>("General", "RabiesChance", 10, "Percentage chance (0-100) for rabies to start.");
		}

		private void Start()
		{
			PhotonNetwork.AddCallbackTarget((object)this);
		}

		private void OnDestroy()
		{
			PhotonNetwork.RemoveCallbackTarget((object)this);
		}

		private void Update()
		{
			if (!SemiFunc.RunIsLevel() || SemiFunc.IsMainMenu() || SemiFunc.RunIsLobby() || !LevelGenerator.Instance.Generated)
			{
				_isRoundActive = false;
				_infectedViewID = -1;
				return;
			}
			if (PhotonNetwork.IsMasterClient)
			{
				MasterClientLogic();
			}
			if (_isRoundActive && _infectedViewID != -1)
			{
				ClientLogic();
			}
		}

		private void MasterClientLogic()
		{
			if (!_isRoundActive && GameDirector.instance.PlayerList.Count > 0)
			{
				((MonoBehaviour)this).StartCoroutine(StartRabiesRound());
			}
			if (_isRoundActive && _infectedViewID != -1)
			{
				_rabiesTimer -= Time.deltaTime;
				if (_rabiesTimer <= 0f)
				{
					SendRabiesEvent(3, _infectedViewID);
					_isRoundActive = false;
				}
			}
		}

		private IEnumerator StartRabiesRound()
		{
			_isRoundActive = true;
			yield return (object)new WaitForSeconds(5f);
			if (Random.Range(0, 100) < _rabiesChance.Value)
			{
				List<PlayerAvatar> players = GameDirector.instance.PlayerList;
				if (players.Count > 0)
				{
					PlayerAvatar victim = players[Random.Range(0, players.Count)];
					SendRabiesEvent(timerData: Random.Range(120f, 180f), type: 0, targetViewID: victim.photonView.ViewID);
				}
			}
		}

		private void ClientLogic()
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar instance = PlayerAvatar.instance;
			if (!((Object)(object)instance == (Object)null) && !instance.isDisabled)
			{
				PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(_infectedViewID);
				if ((Object)(object)val != (Object)null && !val.isDisabled)
				{
					val.playerHealth.EyeMaterialOverride((EyeOverrideState)1, 0.5f, 100);
				}
				if (instance.photonView.ViewID == _infectedViewID && Input.GetKeyDown(_triggerKey.Value))
				{
					AttemptTransmission(instance);
				}
			}
		}

		private void AttemptTransmission(PlayerAvatar localPlayer)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			float num = 2.5f;
			PlayerAvatar val = SemiFunc.PlayerGetNearestPlayerAvatarWithinRange(num, ((Component)localPlayer).transform.position, false, default(LayerMask));
			if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)localPlayer && !val.isDisabled)
			{
				SendRabiesEvent(1, val.photonView.ViewID);
			}
		}

		private void SendRabiesEvent(int type, int targetViewID, float timerData = 0f)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			object[] array = new object[4] { type, targetViewID, _infectedViewID, timerData };
			RaiseEventOptions val = new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)1
			};
			PhotonNetwork.RaiseEvent((byte)160, (object)array, val, SendOptions.SendReliable);
		}

		public void OnEvent(EventData photonEvent)
		{
			if (photonEvent.Code == 160)
			{
				object[] array = (object[])photonEvent.CustomData;
				int num = (int)array[0];
				int num2 = (int)array[1];
				int num3 = (int)array[2];
				float duration = (float)array[3];
				switch (num)
				{
				case 0:
					HandleAssign(num2, duration);
					break;
				case 1:
					HandleTransferRequest(num2);
					break;
				case 2:
					HandleTransferComplete(num2);
					break;
				case 3:
					HandleDeath(num2);
					break;
				}
			}
		}

		private void HandleAssign(int victimID, float duration)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			_isRoundActive = true;
			_infectedViewID = victimID;
			if (PhotonNetwork.IsMasterClient)
			{
				_rabiesTimer = duration;
			}
			PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(victimID);
			if ((Object)(object)val != (Object)null)
			{
				if (val.isLocal)
				{
					SemiFunc.UIBigMessage("YOU HAVE RABIES!", "death", 5f, Color.red, Color.black);
					SemiFunc.UIFocusText("Press 'V' near a player to pass it!", Color.white, Color.red, 5f);
				}
				else
				{
					SemiFunc.UIFocusText(val.playerName + " has Rabies! Run!", Color.yellow, Color.red, 5f);
				}
			}
		}

		private void HandleTransferRequest(int newVictimID)
		{
			if (PhotonNetwork.IsMasterClient)
			{
				SendRabiesEvent(2, newVictimID);
			}
		}

		private void HandleTransferComplete(int newVictimID)
		{
			//IL_004f: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			int infectedViewID = _infectedViewID;
			_infectedViewID = newVictimID;
			PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(infectedViewID);
			PlayerAvatar val2 = SemiFunc.PlayerAvatarGetFromPhotonID(newVictimID);
			if ((Object)(object)val != (Object)null)
			{
				val.playerHealth.EyeMaterialOverride((EyeOverrideState)0, 0.1f, 100);
				if (val.isLocal)
				{
					SemiFunc.UIFocusText("You are cured... for now.", Color.green, Color.white, 5f);
				}
			}
			if ((Object)(object)val2 != (Object)null)
			{
				if (val2.isLocal)
				{
					SemiFunc.UIBigMessage("YOU HAVE RABIES!", "death", 5f, Color.red, Color.black);
					SemiFunc.UIFocusText("Pass it before time runs out!", Color.white, Color.red, 5f);
				}
				else
				{
					SemiFunc.UIFocusText(val2.playerName + " now has Rabies!", Color.yellow, Color.red, 5f);
				}
			}
		}

		private void HandleDeath(int victimID)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			_infectedViewID = -1;
			PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(victimID);
			if ((Object)(object)val != (Object)null)
			{
				val.PlayerDeath(-1);
				SemiFunc.UIBigMessage("RABIES CLAIMED A SOUL", "skull", 5f, Color.red, Color.black);
			}
			SemiFunc.UIFocusText("Rabies has been eradicated!", Color.green, Color.white, 5f);
		}
	}
}