using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 REPOLib.Modules;
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("SolarAaron")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DefeatRespawner")]
[assembly: AssemblyTitle("DefeatRespawner")]
[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 DefeatRespawner
{
[BepInPlugin("SolarAaron.DefeatRespawner", "DefeatRespawner", "0.0.7")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class DefeatRespawner : BaseUnityPlugin
{
internal static DefeatRespawner Instance { get; private set; }
public ConfigEntry<int>? ConfigMutations { get; private set; }
public ConfigEntry<int>? ConfigChance { get; private set; }
public ConfigEntry<bool> OrbTradeoff { get; private set; }
internal static ManualLogSource Logger => Instance.BaseLogger;
private ManualLogSource BaseLogger => ((BaseUnityPlugin)this).Logger;
internal Harmony? Harmony { get; set; }
private void Awake()
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Expected O, but got Unknown
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Expected O, but got Unknown
Instance = this;
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
ConfigMutations = ((BaseUnityPlugin)this).Config.Bind<int>("General", "numOfRespawns", 3, new ConfigDescription("Number of Respawns per enemy death (1 death -> # new enemies)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
ConfigChance = ((BaseUnityPlugin)this).Config.Bind<int>("General", "respawnChance", 25, new ConfigDescription("Chance of Respawn happening per respawn", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
OrbTradeoff = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "orbTradeoff", false, new ConfigDescription("Small enemies drop orbs but are affected by respawn", (AcceptableValueBase)null, Array.Empty<object>()));
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();
Logger.LogInfo((object)"Defeat Respawner: Patched!!");
}
internal void Unpatch()
{
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private void Update()
{
}
}
[HarmonyPatch(typeof(EnemyHealth), "Death")]
public class EnemyHealthPatch
{
private static void Prefix(EnemyHealth __instance)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Expected O, but got Unknown
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
//IL_0276: Unknown result type (might be due to invalid IL or missing references)
//IL_0335: Unknown result type (might be due to invalid IL or missing references)
//IL_033a: Unknown result type (might be due to invalid IL or missing references)
//IL_034d: Unknown result type (might be due to invalid IL or missing references)
//IL_0377: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)__instance))
{
DefeatRespawner.Logger.LogDebug((object)"Instance is null, skipping check");
return;
}
Enemy val = (Enemy)AccessTools.Field(typeof(EnemyHealth), "enemy").GetValue(__instance);
int instanceID = ((Object)val).GetInstanceID();
HashSet<LevelPoint> bannedPoints = new HashSet<LevelPoint>();
EnemyParent componentInParent = ((Component)val).GetComponentInParent<EnemyParent>();
foreach (LevelPoint item in SemiFunc.LevelPointsGetAllCloseToPlayers())
{
foreach (LevelPoint item2 in SemiFunc.LevelPointGetWithinDistance(((Component)item).transform.position, 0f, 10f))
{
bannedPoints.Add(item2);
}
}
foreach (LevelPoint item3 in SemiFunc.LevelPointGetWithinDistance(((Component)__instance).transform.position, 0f, 10f))
{
bannedPoints.Add(item3);
}
if (!__instance.spawnValuable && DefeatRespawner.Instance.OrbTradeoff.Value)
{
FieldRef<EnemyHealth, int> val2 = AccessTools.FieldRefAccess<EnemyHealth, int>("spawnValuableCurrent");
__instance.spawnValuable = true;
DefeatRespawner.Logger.LogDebug((object)$"DEBUG: spawn valuable current was {val2.Invoke(__instance)}");
val2.Invoke(__instance) = 0;
}
string enemyName = componentInParent.enemyName;
EnemySetup val3 = default(EnemySetup);
if (enemyName == null || !__instance.spawnValuable || !Enemies.TryGetEnemyByName(enemyName, ref val3))
{
return;
}
FieldRef<LevelPoint, bool> inStartRoomRef = AccessTools.FieldRefAccess<LevelPoint, bool>("inStartRoom");
for (int i = 0; i < DefeatRespawner.Instance.ConfigMutations.Value; i++)
{
if (Random.Range(0, 100) >= DefeatRespawner.Instance.ConfigChance.Value)
{
continue;
}
List<LevelPoint> list = (from arg in SemiFunc.LevelPointsGetAll()
where !bannedPoints.Contains(arg) && !inStartRoomRef.Invoke(arg)
select arg).ToList();
ListExtension.Shuffle<LevelPoint>((IList<LevelPoint>)list);
list.Add(null);
LevelPoint val4 = list[0];
if ((Object)(object)val4 == (Object)null)
{
List<LevelPoint> list2 = SemiFunc.LevelPointGetWithinDistance(((Component)val).transform.position, 1f, 10f);
if (list2 != null && list2.Count > 0)
{
val4 = list2[0];
}
if ((Object)(object)val4 == (Object)null)
{
DefeatRespawner.Logger.LogError((object)"Level point not found for revived spawn.");
continue;
}
}
foreach (LevelPoint item4 in SemiFunc.LevelPointGetWithinDistance(((Component)val4).transform.position, 0f, 10f))
{
bannedPoints.Add(item4);
}
Enemies.SpawnEnemy(val3, ((Component)val4).transform.position, Quaternion.identity, false);
SemiFunc.EnemyGetNearest(((Component)val4).transform.position, 2f, false);
DefeatRespawner.Logger.LogInfo((object)$"Respawned: {enemyName} | ID: {instanceID} at {((Component)val4).transform.position}");
}
}
}
}