Decompiled source of InfiniteReviveUses v1.0.0

InfiniteReviveUses.DLL

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
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 BoplFixedMath;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks.Data;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("InfiniteReviveUses")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("No longer do you need multiple revive abilities to duplicate! Have infinitely many revives from just one ability!")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("InfiniteReviveUses")]
[assembly: AssemblyTitle("InfiniteReviveUses")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 InfiniteReviveUses
{
	[BepInPlugin("me.antimality.InfiniteReviveUses", "InfiniteReviveUses", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private static Harmony harmony;

		internal static ConfigFile config;

		internal static ConfigEntry<int> maxUsesSetting;

		internal static ConfigEntry<float> cooldownSetting;

		private void Awake()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			config = ((BaseUnityPlugin)this).Config;
			Log.LogInfo((object)"Plugin InfiniteReviveUses is loaded!");
			harmony = new Harmony("me.antimality.InfiniteReviveUses");
			maxUsesSetting = config.Bind<int>("Settings", "Max revive uses", -1, "-1 for unlimited, 0 to disable revives.");
			if (maxUsesSetting.Value < 0)
			{
				maxUsesSetting.Value = int.MaxValue;
				config.Save();
			}
			cooldownSetting = config.Bind<float>("Settings", "Revive cooldown", 10f, "Default is 10.");
			if (cooldownSetting.Value < 0f)
			{
				cooldownSetting.Value = 0f;
				config.Save();
			}
			harmony.PatchAll(typeof(Patch));
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
		}
	}
	[HarmonyPatch]
	public class Patch
	{
		private static readonly Dictionary<Revive, List<RevivePositionIndicator>> anchors = new Dictionary<Revive, List<RevivePositionIndicator>>();

		private static int maxUses;

		private static Fix cooldown;

		[HarmonyPatch(typeof(Revive), "SetReviveFlag")]
		[HarmonyPrefix]
		public static bool SetReviveFlagReplacement(GameObject indicator, ref Revive __instance, ref Player ___player, ref RevivePositionIndicator ___reviveIndicator)
		{
			if (Plugin.maxUsesSetting.Value == 0)
			{
				indicator.GetComponent<RevivePositionIndicator>().End();
				return false;
			}
			___reviveIndicator = indicator.GetComponent<RevivePositionIndicator>();
			___player = PlayerHandler.Get().GetPlayer(((Component)__instance).GetComponent<IPlayerIdHolder>().GetPlayerId());
			___player.ExtraLife = (ReviveStatus)1;
			___player.ReviveInstance = __instance;
			___player.RespawnPositions.Add(___reviveIndicator);
			if (anchors.ContainsKey(__instance))
			{
				anchors[__instance].Add(___reviveIndicator);
			}
			else
			{
				anchors[__instance] = new List<RevivePositionIndicator>(1) { ___reviveIndicator };
			}
			if (anchors[__instance].Count > maxUses)
			{
				RevivePositionIndicator val = anchors[__instance][0];
				___player.RespawnPositions.Remove(val);
				val.End();
				anchors[__instance].Remove(val);
			}
			return false;
		}

		[HarmonyPatch(typeof(Ability), "Awake")]
		[HarmonyPostfix]
		public static void CustomizeCooldown(ref Ability __instance)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (((Object)__instance).name.StartsWith("Revival"))
			{
				__instance.Cooldown = cooldown;
			}
		}

		[HarmonyPatch(typeof(GameSession), "Init")]
		[HarmonyPostfix]
		public static void OnGameStart()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_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)
			if (GameLobby.isOnlineGame)
			{
				try
				{
					maxUses = int.Parse(((Lobby)(ref SteamManager.instance.currentLobby)).GetData("reviveMaxUses"), CultureInfo.InvariantCulture);
					cooldown = (Fix)float.Parse(((Lobby)(ref SteamManager.instance.currentLobby)).GetData("reviveCooldown"), CultureInfo.InvariantCulture);
					return;
				}
				catch (FormatException)
				{
					maxUses = 1;
					cooldown = (Fix)10f;
					Plugin.Log.LogError((object)"Host doesn't have InfiniteReviveUses mod. Disabling functionality.");
					return;
				}
			}
			maxUses = Plugin.maxUsesSetting.Value;
			cooldown = (Fix)Plugin.cooldownSetting.Value;
		}

		[HarmonyPatch(typeof(SteamManager), "OnLobbyEnteredCallback")]
		[HarmonyPostfix]
		public static void OnEnterLobby(Lobby lobby)
		{
			if (SteamManager.LocalPlayerIsLobbyOwner)
			{
				((Lobby)(ref lobby)).SetData("reviveMaxUses", Plugin.maxUsesSetting.Value.ToString());
				((Lobby)(ref lobby)).SetData("reviveCooldown", Plugin.cooldownSetting.Value.ToString());
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "InfiniteReviveUses";

		public const string PLUGIN_NAME = "InfiniteReviveUses";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}