using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.ResourceManagement.AsyncOperations;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
namespace Prototype;
[BepInPlugin("prototype.stage5.scrapper", "GuaranteedScrapper", "0.1.0")]
public class GuaranteedScrapper : BaseUnityPlugin
{
public const string version = "0.1.0";
public const string identifier = "prototype.stage5.scrapper";
private static AsyncOperationHandle<InteractableSpawnCard> handle;
private static Harmony instance;
private static uint counter;
internal void Awake()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
handle = Addressables.LoadAssetAsync<InteractableSpawnCard>((object)"RoR2/Base/Scrapper/iscScrapper.asset");
SceneCatalog.onMostRecentSceneDefChanged += OnMostRecentSceneDefChanged;
}
private void OnMostRecentSceneDefChanged(SceneDef scene)
{
//IL_0068: 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)
Harmony obj = instance;
if (obj != null)
{
obj.UnpatchSelf();
}
if (NetworkServer.active)
{
counter = 0u;
if (scene.stageOrder == 5)
{
instance = Harmony.CreateAndPatchAll(((object)this).GetType(), (string)null);
}
if (scene.cachedName == "skymeadow")
{
NetworkServer.Spawn(Object.Instantiate<GameObject>(((SpawnCard)handle.WaitForCompletion()).prefab, new Vector3(-102.33f, -87.75f, -123.75f), Quaternion.Euler(0f, 195f, 0f)));
}
}
}
[HarmonyPatch(typeof(SceneDirector), "SelectCard")]
[HarmonyPostfix]
private static void SelectCard(SceneDirector __instance, ref DirectorCard __result)
{
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Expected O, but got Unknown
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Expected O, but got Unknown
if (__result == null || (Object)(object)__result.spawnCard == (Object)null)
{
return;
}
DirectorCardCategorySelection val = null;
if (Object.op_Implicit((Object)(object)ClassicStageInfo.instance))
{
val = ClassicStageInfo.instance.interactableCategories;
}
DirectorCard[] source = (DirectorCard[])(object)new DirectorCard[0];
if (Object.op_Implicit((Object)(object)val))
{
for (int i = 0; i < val.categories.Length; i++)
{
ref Category reference = ref val.categories[i];
if (reference.name == "Duplicator")
{
source = reference.cards;
}
}
}
InteractableSpawnCard val2 = handle.WaitForCompletion();
if (source.Contains(__result) && (Object)(object)__result.spawnCard != (Object)(object)val2)
{
if (counter % 2 != 0 && __result.IsAvailable())
{
__instance.interactableCredit -= __result.spawnCard.directorCreditCost;
__result = new DirectorCard();
__instance.rng.Next();
__instance.rng.Next();
}
else if (counter == 0)
{
__result = new DirectorCard
{
spawnCard = (SpawnCard)(object)val2
};
}
counter++;
}
}
}