using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using Dungeonator;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ETGCoopMultipleItems")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ETGCoopMultipleItems")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("898aa5f6-a0a8-4a48-9d9b-1b3ebaffa0b4")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ETGCoopMultipleItems;
[BepInPlugin("ETGCoopMultipleItems", "Averito Coop Multiple Items Mod", "1.0")]
public class ETGCoopMultipleItems : BaseUnityPlugin
{
[HarmonyPatch(typeof(RewardPedestal), "Spawn", new Type[]
{
typeof(RewardPedestal),
typeof(IntVector2),
typeof(RoomHandler)
})]
public class BossPedestalSpawnPatch
{
public static void Postfix(RewardPedestal __result, RewardPedestal pedestalPrefab, IntVector2 basePosition, RoomHandler room)
{
lastPedestalPrefab = pedestalPrefab;
}
}
[HarmonyPatch(typeof(GameManager), "DoGameOver")]
public class GameManagerDoGameOverPatch
{
public static void Postfix(string gameOverSource)
{
Debug.Log((object)"[ETGCoopMultipleItems] Clear clonedContents");
clonedContents = new HashSet<string>();
}
}
[HarmonyPatch(typeof(RewardPedestal), "DetermineContents")]
public class BossPedestalDetermineContentsPatch
{
[CompilerGenerated]
private sealed class <ClonePedestalWhenReady>d__1 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public RewardPedestal __instance;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ClonePedestalWhenReady>d__1(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: 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_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: 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)
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
break;
case 1:
<>1__state = -1;
break;
}
if (!((Behaviour)((BraveBehaviour)__instance).specRigidbody).enabled)
{
<>2__current = null;
<>1__state = 1;
return true;
}
RewardPedestal _instance = __instance;
PickupObject contents = __instance.contents;
Debug.Log((object)string.Format("[ETGCoopMultipleItems] __instance = {0}; contents = {1}", _instance, ((contents != null) ? ((Object)contents).name : null) ?? "NULL"));
if ((Object)(object)__instance.contents == (Object)null)
{
return false;
}
if (clonedContents.Contains(__instance.contents.DisplayName))
{
return false;
}
clonedContents.Add(__instance.contents.DisplayName);
Debug.Log((object)("[ETGCoopMultipleItems] Помечен ключ " + __instance.contents.DisplayName));
PlayerController[] allPlayers = GameManager.Instance.AllPlayers;
Debug.Log((object)$"[ETGCoopMultipleItems] Игроков = {allPlayers.Length}");
if (allPlayers.Length < 2)
{
return false;
}
IntVector2 val = Vector2Extensions.ToIntVector2(((BraveBehaviour)__instance).specRigidbody.UnitBottomLeft, (VectorConversions)2) + new IntVector2(0, -2);
Debug.Log((object)$"[ETGCoopMultipleItems] Cloning pedestal to {val}");
RewardPedestal val2 = RewardPedestal.Spawn(lastPedestalPrefab, val);
if ((Object)(object)val2 == (Object)null)
{
return false;
}
val2.overrideMimicChance = 0f;
val2.contents = __instance.contents;
PickupObject contents2 = val2.contents;
Debug.Log((object)string.Format("[ETGCoopMultipleItems] Cloned pedestal contents: {0} at position {1}", ((contents2 != null) ? ((Object)contents2).name : null) ?? "NULL", val));
return false;
}
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 static void Postfix(RewardPedestal __instance)
{
if (!((Object)(object)__instance == (Object)null))
{
((MonoBehaviour)__instance).StartCoroutine(ClonePedestalWhenReady(__instance));
}
}
private static IEnumerator ClonePedestalWhenReady(RewardPedestal __instance)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ClonePedestalWhenReady>d__1(0)
{
__instance = __instance
};
}
}
[HarmonyPatch(typeof(Chest), "Open")]
public class Chest_Open_Patch
{
public static void Postfix(Chest __instance)
{
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Invalid comparison between Unknown and I4
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Invalid comparison between Unknown and I4
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)("[ETGCoopMultipleItems] Is Rainbow Chest: " + (__instance.IsRainbowChest ? "true" : "false")));
if (__instance.IsRainbowChest)
{
return;
}
PlayerController[] allPlayers = GameManager.Instance.AllPlayers;
bool flag = allPlayers.Length > 1;
bool flag2 = false;
PlayerController[] array = allPlayers;
foreach (PlayerController val in array)
{
if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)((BraveBehaviour)val).healthHaver) || !((BraveBehaviour)val).healthHaver.IsAlive)
{
flag2 = true;
break;
}
}
Debug.Log((object)$"[ETGCoopMultipleItems] anyDead = {flag2}; coopActive = {flag}; players = {allPlayers.ToList().Count}");
if (!flag || flag2)
{
return;
}
PickupObject val2 = null;
if ((int)__instance.ChestType == 1)
{
val2 = GetRandomFromLootTable(__instance, (GameObject go) => (Object)(object)go.GetComponent<Gun>() != (Object)null);
Debug.Log((object)"[ETGCoopMultipleItems] Generate weapon item");
}
else if ((int)__instance.ChestType == 2)
{
val2 = GetRandomFromLootTable(__instance, (GameObject go) => (Object)(object)go.GetComponent<Gun>() == (Object)null);
Debug.Log((object)"[ETGCoopMultipleItems] Generate item");
}
else
{
val2 = GetRandomFromLootTable(__instance);
Debug.Log((object)"[ETGCoopMultipleItems] Generate generic item");
}
if ((Object)(object)val2 != (Object)null)
{
LootEngine.SpawnItem(((Component)val2).gameObject, ((BraveBehaviour)__instance).transform.position, Vector2.zero, 1f, false, true, false);
Debug.Log((object)("[ETGCoopMultipleItems] Spawned extra item: " + ((Object)val2).name));
}
}
private static PickupObject GetRandomFromLootTable(Chest chest, Func<GameObject, bool> predicate = null)
{
if (chest.lootTable == null)
{
return null;
}
List<WeightedGameObject> list = chest.lootTable.lootTable.defaultItemDrops.elements.Where((WeightedGameObject item) => item != null && (Object)(object)item.gameObject != (Object)null && (predicate == null || predicate(item.gameObject))).ToList();
if (list.Count == 0)
{
return null;
}
return list[Random.Range(0, list.Count)].gameObject.GetComponent<PickupObject>();
}
}
private static RewardPedestal lastPedestalPrefab;
private static HashSet<string> clonedContents = new HashSet<string>();
private void Awake()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
((BaseUnityPlugin)this).Logger.LogInfo((object)"[ETGCoopMultipleItems] Mod loaded!");
new Harmony("ETGCoopMultipleItems").PatchAll();
}
}