using System;
using System.Collections;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 AutoReviveMod
{
[BepInPlugin("autorevive", "Auto Revive", "1.3.0")]
public class AutoRevivePlugin : BaseUnityPlugin
{
public static ManualLogSource log;
public static ConfigEntry<float> ReviveTimeConfig;
public static ConfigEntry<bool> RevivePostDebuffConfig;
public static ConfigEntry<string> ReviveKeyConfig;
private static float ReviveTime;
private static float _deathTimer;
private static bool _reviveTriggered;
private TextMeshProUGUI reviveText;
private TextMeshProUGUI reviveCountdownText;
private Canvas canvas;
private int _lastRemainingSeconds = -1;
private void Awake()
{
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Expected O, but got Unknown
ReviveTimeConfig = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ReviveTime", 120f, "Time(second) needed to automatically revive player. Minimum 15 seconds, if set below 15, it will be 15 by default.");
RevivePostDebuffConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnablePostDebuff", true, "Whether to apply debuff(curse and hunger) after revival");
ReviveKeyConfig = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ReviveKey", "R", "Key to press to revive after the timer ends. Use a key name such as R, F, Space, Return, Escape, F1, Alpha1, Keypad0, etc.");
if (ReviveTimeConfig.Value < 15f)
{
ReviveTime = 15f;
}
else
{
ReviveTime = ReviveTimeConfig.Value;
}
Harmony val = new Harmony("autorevive");
val.PatchAll();
log = ((BaseUnityPlugin)this).Logger;
log.LogInfo((object)"Auto Revive on");
CreateReviveHintUI();
((MonoBehaviour)this).StartCoroutine(WaitGame2LoadFont());
}
private void Update()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_027d: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: Unknown result type (might be due to invalid IL or missing references)
//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
//IL_0306: Unknown result type (might be due to invalid IL or missing references)
//IL_033c: Unknown result type (might be due to invalid IL or missing references)
if ((Object)Character.localCharacter == (Object)null || (Object)Character.localCharacter.data == (Object)null)
{
ResetTimerUI();
}
else if (Character.localCharacter.data.dead)
{
_deathTimer += Time.deltaTime;
if (!((Behaviour)reviveText).enabled)
{
((Behaviour)reviveText).enabled = true;
}
float num = ReviveTime - _deathTimer;
num = Mathf.Max(0f, num);
int num2 = Mathf.CeilToInt(num);
if (num2 != _lastRemainingSeconds)
{
_lastRemainingSeconds = num2;
int num3 = Mathf.FloorToInt(num / 60f);
int num4 = Mathf.FloorToInt(num % 60f);
if (num <= 10f)
{
((Graphic)reviveText).color = Color.red;
((TMP_Text)reviveText).text = "REVIVE IMMINENT";
}
else if (num <= 30f)
{
((Graphic)reviveText).color = Color.yellow;
((TMP_Text)reviveText).text = $"REVIVE IN {num3:00}:{num4:00}";
}
else
{
((Graphic)reviveText).color = Color.white;
((TMP_Text)reviveText).text = $"You Died. {num3:00}:{num4:00} Before Revive";
}
}
if (num <= 10f)
{
float num5 = 1f + Mathf.Sin(Time.time * 6f) * 0.05f;
((TMP_Text)reviveText).transform.localScale = Vector3.one * num5;
}
else
{
((TMP_Text)reviveText).transform.localScale = Vector3.one;
}
if (num <= 10f && num > 0f)
{
if (!((Behaviour)reviveCountdownText).enabled)
{
((Behaviour)reviveCountdownText).enabled = true;
}
((TMP_Text)reviveCountdownText).text = num2.ToString();
float num6 = num % 1f;
float num7 = Mathf.Lerp(1f, 3f, num6);
((TMP_Text)reviveCountdownText).transform.localScale = Vector3.one * num7;
float num8 = Mathf.Lerp(0f, 0.4f, num6);
((Graphic)reviveCountdownText).color = new Color(1f, 0f, 0f, num8);
}
else if (((Behaviour)reviveCountdownText).enabled)
{
((Behaviour)reviveCountdownText).enabled = false;
}
if (!(_deathTimer >= ReviveTime))
{
return;
}
((Graphic)reviveText).color = Color.yellow;
((TMP_Text)reviveText).text = "PRESS " + GetReviveKeyDisplayName() + " TO RESURRECT";
((TMP_Text)reviveText).transform.localScale = Vector3.one;
if (((Behaviour)reviveCountdownText).enabled)
{
((Behaviour)reviveCountdownText).enabled = false;
}
if (!_reviveTriggered && IsReviveKeyPressed())
{
if (ReviveLocalPlayer())
{
_reviveTriggered = true;
log.LogInfo((object)"Pressed R to revive, reviving local player");
}
else
{
log.LogWarning((object)"Revive failed: no alive player found to revive near");
}
}
}
else
{
ResetTimerUI();
}
}
private bool IsValidReviveTarget(Character character, Character local)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
//IL_0027: Expected O, but got Unknown
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Expected O, but got Unknown
if ((Object)character == (Object)null)
{
return false;
}
if ((Object)character == (Object)local)
{
return false;
}
if ((Object)character.data == (Object)null)
{
return false;
}
if (character.data.dead)
{
return false;
}
if (character.data.fullyPassedOut)
{
return false;
}
return true;
}
private Character FindReviveTarget(Character local)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
if ((Object)local.Ghost != (Object)null && (Object)local.Ghost.m_target != (Object)null)
{
Character target = local.Ghost.m_target;
if (IsValidReviveTarget(target, local))
{
return target;
}
}
foreach (Character allCharacter in Character.AllCharacters)
{
if (IsValidReviveTarget(allCharacter, local))
{
return allCharacter;
}
}
return null;
}
private bool ReviveLocalPlayer()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Expected O, but got Unknown
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
//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)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
Character localCharacter = Character.localCharacter;
if ((Object)localCharacter == (Object)null || !((MonoBehaviourPun)localCharacter).photonView.IsMine)
{
return false;
}
Character val = FindReviveTarget(localCharacter);
if ((Object)val == (Object)null)
{
return false;
}
Vector3 val2 = val.Center + Vector3.up * 1.5f + Vector3.back * 1.5f;
((MonoBehaviourPun)localCharacter).photonView.RPC("RPCA_ReviveAtPosition", (RpcTarget)0, new object[3] { val2, RevivePostDebuffConfig.Value, -1 });
return true;
}
private void ApplyGameFont()
{
TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
TMP_FontAsset[] array2 = array;
TMP_FontAsset[] array3 = array2;
foreach (TMP_FontAsset val in array3)
{
if (((Object)val).name == "DarumaDropOne-Regular SDF")
{
((TMP_Text)reviveText).font = val;
return;
}
}
log.LogWarning((object)"No game font found, use unity built-in font only");
}
private IEnumerator WaitGame2LoadFont()
{
yield return (object)new WaitForSeconds(8f);
ApplyGameFont();
}
private void CreateReviveHintUI()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Expected O, but got Unknown
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("AutoReviveCanvas");
canvas = val.AddComponent<Canvas>();
canvas.renderMode = (RenderMode)0;
Object.DontDestroyOnLoad((Object)val);
GameObject val2 = new GameObject("ReviveText");
val2.transform.SetParent(val.transform);
reviveText = val2.AddComponent<TextMeshProUGUI>();
((TMP_Text)reviveText).fontSize = 36f;
((TMP_Text)reviveText).alignment = (TextAlignmentOptions)514;
((TMP_Text)reviveText).text = "";
((Behaviour)reviveText).enabled = false;
RectTransform component = ((Component)reviveText).GetComponent<RectTransform>();
component.anchorMin = new Vector2(0.5f, 0.8f);
component.anchorMax = new Vector2(0.5f, 0.8f);
component.anchoredPosition = Vector2.zero;
component.sizeDelta = new Vector2(600f, 100f);
GameObject val3 = new GameObject("CountdownText");
val3.transform.SetParent(val.transform);
reviveCountdownText = val3.AddComponent<TextMeshProUGUI>();
((TMP_Text)reviveCountdownText).fontSize = 250f;
((TMP_Text)reviveCountdownText).alignment = (TextAlignmentOptions)514;
((TMP_Text)reviveCountdownText).fontStyle = (FontStyles)1;
((TMP_Text)reviveCountdownText).text = "";
((Behaviour)reviveCountdownText).enabled = false;
RectTransform component2 = ((Component)reviveCountdownText).GetComponent<RectTransform>();
component2.anchorMin = new Vector2(0.5f, 0.5f);
component2.anchorMax = new Vector2(0.5f, 0.5f);
component2.anchoredPosition = Vector2.zero;
component2.sizeDelta = new Vector2(800f, 800f);
}
private static bool IsReviveKeyPressed()
{
//IL_001c: 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)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
string reviveKeyDisplayName = GetReviveKeyDisplayName();
try
{
Keyboard current = Keyboard.current;
if (current != null && Enum.TryParse<Key>(reviveKeyDisplayName, ignoreCase: true, out Key result) && (int)result != 0 && ((ButtonControl)current[result]).wasPressedThisFrame)
{
return true;
}
}
catch (Exception)
{
}
try
{
KeyCode result2;
return Enum.TryParse<KeyCode>(reviveKeyDisplayName, ignoreCase: true, out result2) && Input.GetKeyDown(result2);
}
catch (Exception)
{
return false;
}
}
private static string GetReviveKeyDisplayName()
{
if (ReviveKeyConfig != null && !string.IsNullOrEmpty(ReviveKeyConfig.Value))
{
return ReviveKeyConfig.Value.Trim().ToUpperInvariant();
}
return "R";
}
private void ResetTimerUI()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Expected O, but got Unknown
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
_deathTimer = 0f;
_reviveTriggered = false;
_lastRemainingSeconds = -1;
if ((Object)reviveText != (Object)null && ((Behaviour)reviveText).enabled)
{
((TMP_Text)reviveText).text = "";
((Behaviour)reviveText).enabled = false;
((TMP_Text)reviveText).transform.localScale = Vector3.one;
}
if ((Object)reviveCountdownText != (Object)null && ((Behaviour)reviveCountdownText).enabled)
{
((TMP_Text)reviveCountdownText).text = "";
((Behaviour)reviveCountdownText).enabled = false;
}
}
[HarmonyPatch(typeof(GlobalEvents), "TriggerRunEnded")]
[HarmonyPostfix]
public static void OnRunEnded()
{
_deathTimer = 0f;
}
}
}