using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using Dungeonator;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("LuckyChest")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9c9e21aa02260f3d4e4053f66b6e26c7e0bef895")]
[assembly: AssemblyProduct("LuckyChest")]
[assembly: AssemblyTitle("LuckyChest")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LuckyChest
{
[BepInPlugin("silstrom.luckychest", "LuckyChest", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static bool IsEnabled;
private void Awake()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
new Harmony("silstrom.luckychest").PatchAll();
}
private void Start()
{
ETGModConsole.Log((object)"LuckyChest v1.0.0 Initialized", false);
ETGModConsole.Commands.AddUnit("luckychest", (Action<string[]>)delegate(string[] args)
{
if (args.Length != 0)
{
string text = args[0].ToLower();
if (text == "on")
{
IsEnabled = true;
ETGModConsole.Log((object)"<color=#00FF00>LuckyChest Enabled</color> - All chests will become random synergy chests", false);
}
else if (text == "off")
{
IsEnabled = false;
ETGModConsole.Log((object)"<color=#FF0000>LuckyChest Disabled</color> - Chests return to normal", false);
}
else
{
ETGModConsole.Log((object)"Usage: luckychest <on|off>", false);
}
}
else
{
string text2 = (IsEnabled ? "<color=#00FF00>Enabled</color>" : "<color=#FF0000>Disabled</color>");
ETGModConsole.Log((object)("LuckyChest current status: " + text2), false);
ETGModConsole.Log((object)"Usage: luckychest <on|off>", false);
}
});
}
}
}
namespace LuckyChest.Patches
{
[HarmonyPatch]
public static class ChestReplacePatch
{
private static Chest _synergyChestPrefab;
private static Chest GetSynergyChestPrefab()
{
if ((Object)(object)_synergyChestPrefab == (Object)null && GameManager.HasInstance && (Object)(object)GameManager.Instance.RewardManager != (Object)null)
{
_synergyChestPrefab = GameManager.Instance.RewardManager.Synergy_Chest;
}
return _synergyChestPrefab;
}
private static void SetupReplacedChest(Chest chest)
{
if (!((Object)(object)chest == (Object)null))
{
chest.PreventFuse = true;
}
}
[HarmonyPatch(typeof(RewardManager), "GetTargetChestPrefab")]
[HarmonyPostfix]
public static void GetTargetChestPrefab_Postfix(RewardManager __instance, ref Chest __result)
{
if (Plugin.IsEnabled && (Object)(object)__instance.Synergy_Chest != (Object)null)
{
__result = __instance.Synergy_Chest;
}
}
[HarmonyPatch(typeof(Chest), "Spawn", new Type[]
{
typeof(Chest),
typeof(Vector3),
typeof(RoomHandler),
typeof(bool)
})]
[HarmonyPrefix]
public static void Spawn_Prefix(ref Chest chestPrefab)
{
if (Plugin.IsEnabled && !((Object)(object)chestPrefab == (Object)null) && (chestPrefab.lootTable == null || !chestPrefab.lootTable.CompletesSynergy) && !chestPrefab.IsRainbowChest)
{
Chest synergyChestPrefab = GetSynergyChestPrefab();
if ((Object)(object)synergyChestPrefab != (Object)null)
{
chestPrefab = synergyChestPrefab;
}
}
}
[HarmonyPatch(typeof(Chest), "Spawn", new Type[]
{
typeof(Chest),
typeof(Vector3),
typeof(RoomHandler),
typeof(bool)
})]
[HarmonyPostfix]
public static void Spawn_Postfix(Chest __result)
{
if (Plugin.IsEnabled)
{
SetupReplacedChest(__result);
}
}
[HarmonyPatch(typeof(Chest), "ConfigureOnPlacement")]
[HarmonyPrefix]
public static bool ConfigureOnPlacement_Prefix(Chest __instance, RoomHandler room)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Invalid comparison between Unknown and I4
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.IsEnabled)
{
return true;
}
if (__instance.lootTable != null && __instance.lootTable.CompletesSynergy)
{
SetupReplacedChest(__instance);
return true;
}
if (__instance.IsRainbowChest)
{
return true;
}
Chest synergyChestPrefab = GetSynergyChestPrefab();
if ((Object)(object)synergyChestPrefab == (Object)null)
{
return true;
}
Vector3 position = ((BraveBehaviour)__instance).transform.position;
bool isTruthChest = __instance.IsTruthChest;
bool flag = (int)__instance.ChestIdentifier == 1;
Object.Destroy((Object)(object)((Component)__instance).gameObject);
Chest component = Object.Instantiate<GameObject>(((Component)synergyChestPrefab).gameObject, position, Quaternion.identity).GetComponent<Chest>();
if ((Object)(object)component != (Object)null)
{
component.ConfigureOnPlacement(room);
room.RegisterInteractable((IPlayerInteractable)(object)component);
if (isTruthChest || flag)
{
component.ForceUnlock();
}
SetupReplacedChest(component);
}
return false;
}
[HarmonyPatch(typeof(RewardManager), "GenerationSpawnRewardChestAt")]
[HarmonyPostfix]
public static void GenerationSpawnRewardChestAt_Postfix(Chest __result)
{
if (Plugin.IsEnabled)
{
SetupReplacedChest(__result);
}
}
}
[HarmonyPatch]
public static class SynergyAlwaysRedPatch
{
[HarmonyPatch(typeof(RewardManager), "AnyPlayerHasItemInSynergyContainingOtherItem")]
[HarmonyPrefix]
public static bool AnyPlayerHasItem_Prefix(ref bool __result)
{
if (!Plugin.IsEnabled)
{
return true;
}
__result = false;
return false;
}
}
}