Decompiled source of DanceHealingOnShip v2.7.0

DanceHealingOnShip.dll

Decompiled 4 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 System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using DanceHealingOnShip.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("DanceHealingOnShip")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Dance to heal yourself on the ship!")]
[assembly: AssemblyFileVersion("2.7.0.0")]
[assembly: AssemblyInformationalVersion("2.7.0")]
[assembly: AssemblyProduct("DanceHealingOnShip")]
[assembly: AssemblyTitle("DanceHealingOnShip")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.7.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DanceHealingOnShip
{
	[BepInPlugin("DanceHealingOnShip", "DanceHealingOnShip", "2.7.0")]
	public class DanceHealingOnShip : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("DanceHealingOnShip");

		public static DanceHealingOnShip Instance;

		internal static ManualLogSource Mls;

		public static Dictionary<string, float> ExecutedInstances;

		public static Dictionary<string, CancellationTokenSource> TokenSources;

		public static Dictionary<string, bool> HasShownMessage;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Mls = Logger.CreateLogSource("DanceHealingOnShip");
			Mls.LogInfo((object)"DanceHealingOnShip is loaded - version 2.7.0");
			_harmony.PatchAll(typeof(DanceHealingOnShip));
			_harmony.PatchAll(typeof(PlayerControllerBPatch));
			_harmony.PatchAll(typeof(StartRoundPatch));
			ExecutedInstances = new Dictionary<string, float>();
			HasShownMessage = new Dictionary<string, bool>();
			TokenSources = new Dictionary<string, CancellationTokenSource>();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "DanceHealingOnShip";

		public const string PLUGIN_NAME = "DanceHealingOnShip";

		public const string PLUGIN_VERSION = "2.7.0";
	}
}
namespace DanceHealingOnShip.Patches
{
	internal class PlayerControllerBPatch
	{
		private const float HealingCooldownTime = 60f;

		[HarmonyPatch(typeof(PlayerControllerB), "PerformEmote")]
		[HarmonyPostfix]
		private static async void OnDancingOnShip(PlayerControllerB __instance)
		{
			string playerUsername = __instance.playerUsername;
			if (__instance.performingEmote && __instance.health < 95 && __instance.isInHangarShipRoom && (!DanceHealingOnShip.ExecutedInstances.ContainsKey(playerUsername) || __instance.timeSincePlayerMoving - DanceHealingOnShip.ExecutedInstances[playerUsername] >= 60f))
			{
				if (DanceHealingOnShip.TokenSources.ContainsKey(playerUsername))
				{
					DanceHealingOnShip.TokenSources[playerUsername].Cancel();
					DanceHealingOnShip.Mls.LogInfo((object)(playerUsername + " removed before healing action"));
				}
				if (!DanceHealingOnShip.HasShownMessage.ContainsKey(playerUsername) || !DanceHealingOnShip.HasShownMessage[playerUsername])
				{
					DanceHealingOnShip.HasShownMessage[playerUsername] = true;
				}
				CancellationTokenSource cts = new CancellationTokenSource();
				DanceHealingOnShip.TokenSources[playerUsername] = cts;
				try
				{
					while (__instance.health <= 90 && __instance.performingEmote)
					{
						__instance.health += 10;
						__instance.DamagePlayer(-10, false, true, (CauseOfDeath)0, 0, false, default(Vector3));
						await Task.Delay(1000, cts.Token);
					}
					if (__instance.health == 100)
					{
						DanceHealingOnShip.ExecutedInstances[playerUsername] = __instance.timeSincePlayerMoving;
					}
					if (__instance.health >= 20)
					{
						__instance.criticallyInjured = false;
					}
					if ((Object)(object)__instance == (Object)(object)GameNetworkManager.Instance.localPlayerController)
					{
						HUDManager.Instance.DisplayTip("Full health!", "You are now at full health!", false, false, "LC_Tip1");
						HUDManager.Instance.UpdateHealthUI(__instance.health, true);
					}
					DanceHealingOnShip.Mls.LogInfo((object)(playerUsername + " has been healed"));
				}
				catch (TaskCanceledException)
				{
					if ((Object)(object)__instance == (Object)(object)GameNetworkManager.Instance.localPlayerController)
					{
						HUDManager.Instance.UpdateHealthUI(__instance.health, true);
					}
					DanceHealingOnShip.Mls.LogInfo((object)(playerUsername + " has stopped healing"));
					DanceHealingOnShip.TokenSources.Remove(playerUsername);
				}
			}
			else
			{
				DanceHealingOnShip.Mls.LogInfo((object)(playerUsername + " is not in the ship or is not injured"));
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartRoundPatch
	{
		[HarmonyPatch("StartGame")]
		[HarmonyPostfix]
		private static void StartGame()
		{
			Fullreset();
		}

		[HarmonyPatch("EndOfGame")]
		[HarmonyPostfix]
		private static void EndOfGame()
		{
			Fullreset();
		}

		[HarmonyPatch("EndOfGameClientRpc")]
		[HarmonyPostfix]
		private static void EndOfGameClientRpc()
		{
			Fullreset();
		}

		private static void Fullreset()
		{
			DanceHealingOnShip.ExecutedInstances.Clear();
			DanceHealingOnShip.TokenSources.Clear();
			DanceHealingOnShip.Mls.LogInfo((object)"Diccionary reseted");
		}
	}
}