using System;
using System.Collections;
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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SinglePlayerRevive")]
[assembly: AssemblyTitle("SinglePlayerRevive")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 SinglePlayerRevive
{
[BepInPlugin("Omniscye.SinglePlayerRevive", "SinglePlayerRevive", "1.0")]
public class SinglePlayerRevive : BaseUnityPlugin
{
internal static SinglePlayerRevive Instance { get; private set; }
internal static ManualLogSource Logger => Instance._logger;
private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;
internal Harmony? Harmony { get; set; }
private void Awake()
{
Instance = this;
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
Patch();
Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
}
internal void Patch()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_0026: Expected O, but got Unknown
if (Harmony == null)
{
Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
Harmony val2 = val;
Harmony = val;
}
Harmony.PatchAll();
}
internal void Unpatch()
{
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private void Update()
{
}
}
}
namespace Empress.SingleplayerRevive
{
[BepInPlugin("com.empress.Singleplayer_Revive", "Singleplayer_Revive", "1.0.1")]
public class SingleplayerRevivePlugin : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <ReviveRoutine>d__12 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
private float <delay>5__1;
private Exception <caught>5__2;
private PlayerController <pc>5__3;
private PlayerAvatar <avatar>5__4;
private PlayerHealth <ph>5__5;
private int <target>5__6;
private int <delta>5__7;
private Exception <e>5__8;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ReviveRoutine>d__12(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<caught>5__2 = null;
<pc>5__3 = null;
<avatar>5__4 = null;
<ph>5__5 = null;
<e>5__8 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
ReviveInProgress = true;
<delay>5__1 = Mathf.Max(0f, CReviveDelay.Value);
if (<delay>5__1 > 0f)
{
<>2__current = (object)new WaitForSeconds(<delay>5__1);
<>1__state = 1;
return true;
}
goto IL_0080;
case 1:
<>1__state = -1;
goto IL_0080;
case 2:
{
<>1__state = -1;
ReviveInProgress = false;
if (<caught>5__2 != null)
{
ManualLogSource log = Log;
if (log != null)
{
log.LogError((object)<caught>5__2);
}
}
return false;
}
IL_0080:
<caught>5__2 = null;
try
{
<pc>5__3 = PlayerController.instance;
<avatar>5__4 = (((Object)(object)<pc>5__3 != (Object)null) ? <pc>5__3.playerAvatarScript : null);
if ((Object)(object)<avatar>5__4 == (Object)null)
{
Log.LogWarning((object)"No local PlayerAvatar found. Aborting revive.");
ReviveInProgress = false;
return false;
}
if (!<avatar>5__4.isDisabled && !<avatar>5__4.deadSet)
{
ReviveInProgress = false;
return false;
}
<avatar>5__4.Revive(false);
<ph>5__5 = <avatar>5__4.playerHealth;
if ((Object)(object)<ph>5__5 != (Object)null)
{
<target>5__6 = Mathf.Clamp(CReviveHealth.Value, 1, Mathf.Max(1, <ph>5__5.maxHealth));
<delta>5__7 = <target>5__6 - Mathf.Max(0, <ph>5__5.health);
if (<delta>5__7 > 0)
{
<ph>5__5.Heal(<delta>5__7, false);
}
}
<pc>5__3 = null;
<avatar>5__4 = null;
<ph>5__5 = null;
}
catch (Exception ex)
{
<e>5__8 = ex;
<caught>5__2 = <e>5__8;
}
<>2__current = null;
<>1__state = 2;
return true;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
public const string PluginGuid = "com.empress.Singleplayer_Revive";
public const string PluginName = "Singleplayer_Revive";
public const string PluginVersion = "1.0.1";
internal static ManualLogSource Log;
internal static Harmony Harmony;
internal static ConfigEntry<bool> CEnabled;
internal static ConfigEntry<float> CReviveDelay;
internal static ConfigEntry<int> CReviveHealth;
internal static ConfigEntry<bool> CRestrictToSoloInMP;
internal static bool ReviveInProgress;
private void Awake()
{
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
CEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master enable/disable.");
CReviveDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ReviveDelaySeconds", 2f, "Delay before reviving the player.");
CReviveHealth = ((BaseUnityPlugin)this).Config.Bind<int>("General", "ReviveHealth", 50, "Health set after revive (clamped to [1..maxHealth]).");
CRestrictToSoloInMP = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RestrictToSoloInMP", true, "Only revive in MP if room PlayerCount <= 1.");
Harmony = new Harmony("com.empress.Singleplayer_Revive");
Harmony.PatchAll(typeof(Patch_RunManager_ChangeLevel));
Log.LogInfo((object)"Singleplayer_Revive 1.0.1 loaded.");
}
private void OnDestroy()
{
Harmony harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
[IteratorStateMachine(typeof(<ReviveRoutine>d__12))]
internal static IEnumerator ReviveRoutine()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ReviveRoutine>d__12(0);
}
}
[HarmonyPatch(typeof(RunManager), "ChangeLevel")]
internal static class Patch_RunManager_ChangeLevel
{
[HarmonyPrefix]
[HarmonyPriority(600)]
private static bool Prefix(RunManager __instance, bool _completedLevel, bool _levelFailed, ChangeLevelType _changeLevelType)
{
try
{
if (!SingleplayerRevivePlugin.CEnabled.Value)
{
return true;
}
if (!_levelFailed)
{
return true;
}
if (!SemiFunc.RunIsLevel())
{
return true;
}
if (SingleplayerRevivePlugin.ReviveInProgress)
{
return false;
}
if (GameManager.Multiplayer() && SingleplayerRevivePlugin.CRestrictToSoloInMP.Value)
{
try
{
Room currentRoom = PhotonNetwork.CurrentRoom;
int num = ((currentRoom != null) ? currentRoom.PlayerCount : 0);
SingleplayerRevivePlugin.Log.LogDebug((object)$"Room player count = {num}");
if (num > 1)
{
return true;
}
}
catch (Exception ex)
{
SingleplayerRevivePlugin.Log.LogWarning((object)("PlayerCount check failed: " + ex.Message));
return true;
}
}
PlayerController instance = PlayerController.instance;
PlayerAvatar val = (((Object)(object)instance != (Object)null) ? instance.playerAvatarScript : null);
if ((Object)(object)val == (Object)null || !val.isDisabled)
{
return true;
}
__instance.allPlayersDead = false;
((MonoBehaviour)__instance).StartCoroutine(SingleplayerRevivePlugin.ReviveRoutine());
SingleplayerRevivePlugin.Log.LogInfo((object)"Suppressed run fail and revived local player (solo).");
return false;
}
catch (Exception ex2)
{
ManualLogSource log = SingleplayerRevivePlugin.Log;
if (log != null)
{
log.LogError((object)ex2);
}
return true;
}
}
}
}