using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using Photon.Pun;
using UnityEngine;
using UnityEngine.SceneManagement;
using Zorro.Core;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("PoisonShuffle")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PoisonShuffle")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("48c13e53-847c-4952-ad1a-63c73fc11bb4")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PoisonShuffle;
[BepInPlugin("com.hiccup.poisonshuffle", "Random Poison Shuffle", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private bool _alreadyShuffled;
private void Awake()
{
Debug.Log((object)"[PoisonShuffle] plugin loaded");
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode _)
{
if (!_alreadyShuffled && !(((Scene)(ref scene)).name != "Level_11"))
{
_alreadyShuffled = true;
ItemDatabase instance = SingletonAsset<ItemDatabase>.Instance;
int num = ((!PhotonNetwork.InRoom || string.IsNullOrEmpty(PhotonNetwork.CurrentRoom.Name)) ? DateTime.Now.GetHashCode() : PhotonNetwork.CurrentRoom.Name.GetHashCode());
Debug.Log((object)$"[PoisonShuffle] Using seed {num}");
Random rng = new Random(num);
ShufflePoison(rng, instance);
}
}
private static void ShufflePoison(Random rng, ItemDatabase db)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
foreach (KeyValuePair<ushort, Item> item in db.itemLookup)
{
Item value = item.Value;
if ((Object)(object)value == (Object)null)
{
continue;
}
bool flag = ((Enum)value.itemTags).HasFlag((Enum)(object)(ItemTags)4);
bool flag2 = ((Enum)value.itemTags).HasFlag((Enum)(object)(ItemTags)8);
if (!flag && !flag2)
{
continue;
}
bool flag3 = rng.NextDouble() < 0.5;
Action_InflictPoison val = ((Component)value).GetComponent<Action_InflictPoison>();
if (flag3)
{
if (!Object.op_Implicit((Object)(object)val))
{
val = ((Component)value).gameObject.AddComponent<Action_InflictPoison>();
val.inflictionTime = Random.Range(2f, 5f);
val.poisonPerSecond = Random.Range(0.015f, 0.075f);
val.delay = Random.Range(0f, 5f);
}
((Behaviour)val).enabled = true;
((ItemAction)val).OnConsumed = true;
Debug.Log((object)("[PoisonShuffle] " + ((Object)value).name + " set **POISONOUS**"));
}
else
{
if (Object.op_Implicit((Object)(object)val))
{
((Behaviour)val).enabled = false;
}
Debug.Log((object)("[PoisonShuffle] " + ((Object)value).name + " set safe"));
}
}
Item[] array = Object.FindObjectsOfType<Item>();
foreach (Item val2 in array)
{
if ((Object)(object)val2 == (Object)null)
{
continue;
}
bool flag4 = ((Enum)val2.itemTags).HasFlag((Enum)(object)(ItemTags)4);
bool flag5 = ((Enum)val2.itemTags).HasFlag((Enum)(object)(ItemTags)8);
if (!flag4 && !flag5)
{
continue;
}
bool flag6 = rng.NextDouble() < 0.5;
Action_InflictPoison val3 = ((Component)val2).GetComponent<Action_InflictPoison>();
if (flag6)
{
if (!Object.op_Implicit((Object)(object)val3))
{
val3 = ((Component)val2).gameObject.AddComponent<Action_InflictPoison>();
val3.inflictionTime = Random.Range(2f, 5f);
val3.poisonPerSecond = Random.Range(0.015f, 0.075f);
val3.delay = Random.Range(0f, 5f);
}
((Behaviour)val3).enabled = true;
((ItemAction)val3).OnConsumed = true;
Debug.Log((object)("[PoisonShuffle] " + ((Object)val2).name + " instance set **POISONOUS**"));
}
else
{
if (Object.op_Implicit((Object)(object)val3))
{
((Behaviour)val3).enabled = false;
}
Debug.Log((object)("[PoisonShuffle] " + ((Object)val2).name + " instance set safe"));
}
}
}
}