Decompiled source of Hura Revive v1.0.0

HuraRevive.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
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("HuraRevive")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HuraRevive")]
[assembly: AssemblyTitle("HuraRevive")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Hura;

internal static class Log
{
	private const string PREFIX = "[Hura] ";

	public static void Message(string text)
	{
		Mod.ModLogger.LogMessage((object)("[Hura] " + text));
	}

	public static void Warning(string text)
	{
		Mod.ModLogger.LogWarning((object)("[Hura] " + text));
	}

	public static void Error(string text)
	{
		Mod.ModLogger.LogError((object)("[Hura] " + text));
	}
}
public class LuggageRevive
{
	public static List<Type> SupportedTypes = new List<Type>
	{
		typeof(Luggage),
		typeof(LuggageCursed)
	};

	[HarmonyPatch(typeof(Luggage), "GetInteractionText")]
	[HarmonyPostfix]
	internal static void GetInteractionText_Patch(Luggage __instance, ref string __result)
	{
		if (Settings.ReviveEnabled && IsSupported(__instance) && Character.PlayerIsDeadOrDown())
		{
			__result = __result + " + " + LocalizedText.GetText("REVIVESCOUTS", true);
		}
	}

	[HarmonyPatch(typeof(Spawner), "SpawnItems")]
	[HarmonyPostfix]
	internal static void SpawnItems_Patch(Luggage __instance, List<Transform> spawnSpots)
	{
		if (Settings.ReviveEnabled && IsSupported(__instance) && PhotonNetwork.IsMasterClient && Ascents.canReviveDead)
		{
			RespawnAllPlayersAtLuggage(__instance);
		}
	}

	private static bool IsSupported(Luggage luggage)
	{
		return SupportedTypes.Contains(((object)luggage).GetType());
	}

	private static void RespawnAllPlayersAtLuggage(Luggage luggage)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: 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)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = ((Component)luggage).transform.up * 2f;
		Vector3 val2 = ((Component)luggage).transform.position + val;
		foreach (Character allCharacter in Character.AllCharacters)
		{
			if (allCharacter.data.dead || allCharacter.data.fullyPassedOut)
			{
				((MonoBehaviourPun)allCharacter).photonView.RPC("RPCA_ReviveAtPosition", (RpcTarget)0, new object[2]
				{
					val2,
					Settings.ReviveWithMalus
				});
			}
		}
	}
}
[BepInPlugin("Peak.Hura.Revive", "HuraRevive", "1.0.0")]
public class Mod : BaseUnityPlugin
{
	private const string GUID = "Peak.Hura.Revive";

	private const string NAME = "HuraRevive";

	private const string VERSION = "1.0.0";

	private readonly Harmony _harmony = new Harmony("Peak.Hura.Revive");

	private readonly Type[] _patches = new Type[1] { typeof(LuggageRevive) };

	internal static Mod Instance { get; private set; }

	internal static ManualLogSource ModLogger => ((BaseUnityPlugin)Instance).Logger;

	private void Awake()
	{
		Instance = this;
		try
		{
			Settings.Bind(this);
			Patch();
		}
		catch (Exception ex)
		{
			Log.Error("Initialization Error: " + ex.Message);
		}
	}

	private void Patch()
	{
		Type[] patches = _patches;
		foreach (Type type in patches)
		{
			_harmony.PatchAll(type);
		}
	}
}
internal static class Settings
{
	private static ConfigEntry<bool> _enableRevive;

	private static ConfigEntry<bool> _reviveWithMalus;

	internal static bool ReviveEnabled => _enableRevive.Value;

	internal static bool ReviveWithMalus => _reviveWithMalus.Value;

	internal static void Bind(Mod mod)
	{
		_enableRevive = ((BaseUnityPlugin)mod).Config.Bind<bool>("General", "Enable Revive", true, "When enabled, player will revive when a case is opened.");
		_reviveWithMalus = ((BaseUnityPlugin)mod).Config.Bind<bool>("General", "Revive With Malus", true, "When enabled, player will revive with the usual revive malus (hunger + curse).");
		((BaseUnityPlugin)mod).Config.Save();
	}
}