Decompiled source of Revive Potion v1.0.1

RevivePotion.dll

Decompiled 2 weeks ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using REPOLib.Modules;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RevivePotion")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RevivePotion")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("be47d6c1-2612-46ea-bb4b-a7765861ef07")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RevivePotion;

[BepInPlugin("scriptova.revivepotion", "Revive Potion", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInProcess("REPO.exe")]
public class Plugin : BaseUnityPlugin
{
	private const string modGUID = "scriptova.revivepotion";

	private const string modName = "Revive Potion";

	private const string modVersion = "1.0.0";

	internal static ManualLogSource mls;

	private static Plugin Instance;

	private AssetBundle assetBundle;

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony val = new Harmony("scriptova.revivepotion");
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		mls = Logger.CreateLogSource("scriptova.revivepotion");
		assetBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "revivepotion"));
		LoadRevivePotion();
		val.PatchAll();
		mls.LogInfo((object)"RevivePotion Mods are Onine.");
	}

	private void LoadRevivePotion()
	{
		GameObject val = assetBundle.LoadAsset<GameObject>("Assets/REPO/Mods/RevivePotion/RevivePotion.prefab");
		val.AddComponent<RevivePotion>();
		RevivePotion component = val.GetComponent<RevivePotion>();
		GameObject val2 = assetBundle.LoadAsset<GameObject>("Assets/REPO/Mods/RevivePotion/ReviveField.prefab");
		val2.AddComponent<ReviveField>();
		component.reviveField = val2;
		Utilities.FixAudioMixerGroups(val2);
		Item val3 = assetBundle.LoadAsset<Item>("Assets/REPO/Mods/RevivePotion/RevivePotion.asset");
		val3.prefab = val;
		Items.RegisterItem(val3);
		mls.LogInfo((object)(((Object)val3).name ?? ""));
		mls.LogInfo((object)"Revive Potion Loaded!");
	}
}
internal class RevivePotion : MonoBehaviour
{
	public GameObject reviveField;

	private PhysGrabObject physGrabObject;

	private Vector3 startPosition;

	private Quaternion startRotation;

	private void Start()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//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_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		startPosition = ((Component)this).transform.position;
		startRotation = ((Component)this).transform.rotation;
		physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
		PhysGrabObjectImpactDetector component = ((Component)this).GetComponent<PhysGrabObjectImpactDetector>();
		if (SemiFunc.RunIsLevel() || SemiFunc.RunIsArena())
		{
			component.onDestroy.AddListener(new UnityAction(CreateReviveField));
		}
		else
		{
			component.destroyDisable = true;
		}
	}

	private void CreateReviveField()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		NavMeshHit val = default(NavMeshHit);
		if (NavMesh.SamplePosition(((Component)this).transform.position, ref val, 20f, -1))
		{
			Object.Instantiate<GameObject>(reviveField, ((NavMeshHit)(ref val)).position + new Vector3(0f, 0.05f, 0f), Quaternion.identity, ((Component)LevelGenerator.Instance).transform);
		}
	}
}
internal class ReviveField : MonoBehaviour
{
	private float timer;

	private PlayerDeathHead myPlayerDeathHead;

	private void Start()
	{
		timer = 35f;
		foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
		{
			if ((Object)(object)player != (Object)null && player.photonView.IsMine)
			{
				myPlayerDeathHead = player.playerDeathHead;
			}
		}
	}

	private void Update()
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//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_0059: Unknown result type (might be due to invalid IL or missing references)
		timer -= Time.deltaTime;
		if (timer <= 0f)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		Vector3 val = ((Component)myPlayerDeathHead).transform.position - ((Component)this).transform.position;
		if (timer < 31f && ((Vector3)(ref val)).magnitude < 1.65f)
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(PlayerDeathHead), "inExtractionPoint");
			if (!(bool)fieldInfo.GetValue(myPlayerDeathHead))
			{
				fieldInfo.SetValue(myPlayerDeathHead, true);
				PlayerAvatarPatch.active = true;
				myPlayerDeathHead.Revive();
				fieldInfo.SetValue(myPlayerDeathHead, false);
			}
		}
	}
}
[HarmonyPatch(typeof(PlayerAvatar), "ReviveRPC")]
internal class PlayerAvatarPatch
{
	internal static bool active;

	private static void Postfix(PlayerAvatar __instance, bool _revivedByTruck)
	{
		if (active && __instance.photonView.IsMine)
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(PlayerHealth), "maxHealth");
			__instance.playerHealth.HealOther((int)fieldInfo.GetValue(__instance.playerHealth), true);
			active = false;
		}
	}
}