Decompiled source of SharedDamage v0.1.0

plugins/com.github.Ryocery.SharedDamage.dll

Decompiled 2 months ago
using System;
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 BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
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("com.github.Ryocery.SharedDamage")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+ee6443f1dc6dc73a1b5f7e2348607ab0fc491ab6")]
[assembly: AssemblyProduct("com.github.Ryocery.SharedDamage")]
[assembly: AssemblyTitle("SharedDamage")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.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.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;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace SharedDamage
{
	[BepInPlugin("com.github.Ryocery.SharedDamage", "SharedDamage", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal const byte SHARED_DAMAGE_EVENT_CODE = 199;

		public const string Id = "com.github.Ryocery.SharedDamage";

		internal static ManualLogSource Log { get; private set; }

		internal static ConfigEntry<bool> EnablePoison { get; private set; }

		internal static ConfigEntry<bool> EnableInjury { get; private set; }

		internal static ConfigEntry<bool> EnableThorns { get; private set; }

		internal static ConfigEntry<bool> EnableCold { get; private set; }

		internal static ConfigEntry<bool> EnableCurse { get; private set; }

		internal static ConfigEntry<bool> EnableDrowsy { get; private set; }

		internal static ConfigEntry<bool> EnableHot { get; private set; }

		public static string Name => "SharedDamage";

		public static string Version => "0.1.0";

		private void Awake()
		{
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
			EnablePoison = ((BaseUnityPlugin)this).Config.Bind<bool>("Shared Status Effects", "EnablePoison", true, "Share Poison damage");
			EnableInjury = ((BaseUnityPlugin)this).Config.Bind<bool>("Shared Status Effects", "EnableInjury", true, "Share Injury damage");
			EnableThorns = ((BaseUnityPlugin)this).Config.Bind<bool>("Shared Status Effects", "EnableThorns", true, "Share Thorns damage");
			EnableCold = ((BaseUnityPlugin)this).Config.Bind<bool>("Shared Status Effects", "EnableCold", true, "Share Cold damage");
			EnableCurse = ((BaseUnityPlugin)this).Config.Bind<bool>("Shared Status Effects", "EnableCurse", false, "Share Curse damage");
			EnableDrowsy = ((BaseUnityPlugin)this).Config.Bind<bool>("Shared Status Effects", "EnableDrowsy", true, "Share Drowsy damage");
			EnableHot = ((BaseUnityPlugin)this).Config.Bind<bool>("Shared Status Effects", "EnableHot", true, "Share Hot damage");
			PhotonNetwork.NetworkingClient.EventReceived += OnSharedDamageEvent;
			Harmony val = new Harmony("com.github.Ryocery.SharedDamage");
			try
			{
				val.PatchAll();
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Failed to load mod: {arg}");
			}
		}

		private void OnDestroy()
		{
			if (PhotonNetwork.NetworkingClient != null)
			{
				PhotonNetwork.NetworkingClient.EventReceived -= OnSharedDamageEvent;
			}
		}

		private void OnSharedDamageEvent(EventData photonEvent)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			if (photonEvent.Code != 199)
			{
				return;
			}
			object[] array = (object[])photonEvent.CustomData;
			int num = (int)array[0];
			float num2 = (float)array[1];
			int sender = photonEvent.Sender;
			Character localCharacter = Character.localCharacter;
			if (!((Object)(object)localCharacter == (Object)null) && !localCharacter.data.dead && !localCharacter.warping && ((MonoBehaviourPun)localCharacter).photonView.Owner.ActorNumber != sender)
			{
				STATUSTYPE val = (STATUSTYPE)num;
				SharedDamagePatch.isReceivingSharedDamage.Add(((MonoBehaviourPun)localCharacter).photonView.ViewID);
				try
				{
					localCharacter.refs.afflictions.AddStatus(val, num2, false);
					Log.LogInfo((object)$"Received shared damage: {num2} {val}");
				}
				finally
				{
					SharedDamagePatch.isReceivingSharedDamage.Remove(((MonoBehaviourPun)localCharacter).photonView.ViewID);
				}
			}
		}
	}
	[HarmonyPatch(typeof(CharacterAfflictions))]
	public class SharedDamagePatch
	{
		internal static readonly HashSet<int> isReceivingSharedDamage = new HashSet<int>();

		[HarmonyPostfix]
		[HarmonyPatch("AddStatus", new Type[]
		{
			typeof(STATUSTYPE),
			typeof(float),
			typeof(bool)
		})]
		public static void AddStatusPostfix(CharacterAfflictions __instance, STATUSTYPE statusType, float amount, bool fromRPC, bool __result)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!fromRPC && __instance.character.IsLocal && !(amount <= 0f) && __result && !__instance.character.data.dead && !__instance.character.warping && ShouldPropagate(statusType) && !isReceivingSharedDamage.Contains(((MonoBehaviourPun)__instance.character).photonView.ViewID))
				{
					SendSharedDamageEvent(statusType, amount);
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Error in AddStatusPostfix: {arg}");
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("SetStatus", new Type[]
		{
			typeof(STATUSTYPE),
			typeof(float)
		})]
		public static void SetStatusPrefix(CharacterAfflictions __instance, STATUSTYPE statusType, out float __state)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			__state = __instance.GetCurrentStatus(statusType);
		}

		[HarmonyPostfix]
		[HarmonyPatch("SetStatus", new Type[]
		{
			typeof(STATUSTYPE),
			typeof(float)
		})]
		public static void SetStatusPostfix(CharacterAfflictions __instance, STATUSTYPE statusType, float amount, float __state)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (__instance.character.IsLocal && !__instance.character.data.dead && !__instance.character.warping && ShouldPropagate(statusType) && !isReceivingSharedDamage.Contains(((MonoBehaviourPun)__instance.character).photonView.ViewID))
				{
					float num = amount - __state;
					if (num > 0f)
					{
						SendSharedDamageEvent(statusType, num);
					}
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Error in SetStatusPostfix: {arg}");
			}
		}

		private static bool ShouldPropagate(STATUSTYPE statusType)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected I4, but got Unknown
			return (int)statusType switch
			{
				3 => Plugin.EnablePoison.Value, 
				0 => Plugin.EnableInjury.Value, 
				9 => Plugin.EnableThorns.Value, 
				2 => Plugin.EnableCold.Value, 
				5 => Plugin.EnableCurse.Value, 
				6 => Plugin.EnableDrowsy.Value, 
				8 => Plugin.EnableHot.Value, 
				_ => false, 
			};
		}

		private static void SendSharedDamageEvent(STATUSTYPE statusType, float amount)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected I4, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			object[] array = new object[2]
			{
				(int)statusType,
				amount
			};
			RaiseEventOptions val = new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)0
			};
			PhotonNetwork.RaiseEvent((byte)199, (object)array, val, SendOptions.SendReliable);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}