Decompiled source of REPO lucky block v1.1.0

REPO_lucky_block.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using REPOLib.Modules;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("REPO_lucky_block")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+72b724b4ced6c76df5941a41dd6a460d24aaced1")]
[assembly: AssemblyProduct("REPO_lucky_block")]
[assembly: AssemblyTitle("REPO_lucky_block")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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;
		}
	}
}
public class DebugMenu : MonoBehaviour
{
	private enum Page
	{
		Main,
		ForceEvent,
		BlocksOnMap
	}

	private bool _open;

	private int _selectedIndex;

	private Page _page;

	private Vector2 _scroll = Vector2.zero;

	private List<LuckyBlock> _blockCache = new List<LuckyBlock>();

	private string _lastEventMsg = "";

	private const float WIN_W = 360f;

	private const float WIN_H = 420f;

	private const float ROW_H = 26f;

	private const float BTN_H = 22f;

	private const float PAD = 8f;

	private const float HOLD_DELAY = 0.28f;

	private const float REPEAT_RATE = 0.07f;

	private float _upTimer = -1f;

	private float _downTimer = -1f;

	private float _enterTimer = -1f;

	private static readonly Color COL_SELECTED = new Color(1f, 0.85f, 0f);

	private static readonly Color COL_NORMAL = Color.white;

	private static readonly Color COL_GOLD = new Color(1f, 0.8f, 0.1f);

	private static readonly Color COL_DIM = new Color(1f, 1f, 1f, 0.35f);

	private static readonly Color COL_GREEN = new Color(0.4f, 1f, 0.4f);

	private static readonly Color COL_RED = new Color(1f, 0.35f, 0.35f);

	private const int MAIN_ITEMS = 5;

	public static DebugMenu Instance { get; private set; }

	private static int EventCount => LuckyEventRegistry.All.Count + 1;

	private void Awake()
	{
		if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
		else
		{
			Instance = this;
		}
	}

	private void Update()
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown((KeyCode)287))
		{
			_open = !_open;
			if (_open)
			{
				RefreshBlockCache();
			}
			_selectedIndex = 0;
			_scroll = Vector2.zero;
			_page = Page.Main;
			_lastEventMsg = "";
			ResetTimers();
		}
		if (_open)
		{
			float deltaTime = Time.deltaTime;
			HandleHeld((KeyCode)273, ref _upTimer, deltaTime, NavigateUp);
			HandleHeld((KeyCode)274, ref _downTimer, deltaTime, NavigateDown);
			HandleHeld((KeyCode)13, ref _enterTimer, deltaTime, ActivateSelected);
			if (Input.GetKeyDown((KeyCode)271) || Input.GetKey((KeyCode)271))
			{
				HandleHeld((KeyCode)271, ref _enterTimer, deltaTime, ActivateSelected);
			}
		}
	}

	private void HandleHeld(KeyCode key, ref float timer, float dt, Action action)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown(key))
		{
			action();
			timer = -0.28f;
		}
		else if (Input.GetKey(key))
		{
			timer += dt;
			while (timer >= 0f)
			{
				action();
				timer -= 0.07f;
			}
		}
		else
		{
			timer = -0.28f;
		}
	}

	private void ResetTimers()
	{
		_upTimer = (_downTimer = (_enterTimer = -0.28f));
	}

	private int PageItemCount()
	{
		return _page switch
		{
			Page.Main => 5, 
			Page.ForceEvent => 1 + EventCount, 
			Page.BlocksOnMap => 1 + _blockCache.Count, 
			_ => 0, 
		};
	}

	private void NavigateUp()
	{
		int num = PageItemCount();
		if (num != 0)
		{
			_selectedIndex = (_selectedIndex - 1 + num) % num;
			SyncScroll();
		}
	}

	private void NavigateDown()
	{
		int num = PageItemCount();
		if (num != 0)
		{
			_selectedIndex = (_selectedIndex + 1) % num;
			SyncScroll();
		}
	}

	private void GoTo(Page p)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		if (p == Page.BlocksOnMap)
		{
			RefreshBlockCache();
		}
		_page = p;
		_selectedIndex = 0;
		_scroll = Vector2.zero;
		ResetTimers();
	}

	private void SyncScroll()
	{
		if (_page == Page.Main)
		{
			return;
		}
		float num = 96f;
		float num2 = 420f - num - 8f - 24f;
		float num3 = (float)(_selectedIndex - 1) * 26f;
		float num4 = num3 + 26f;
		int num5 = PageItemCount() - 1;
		if (_selectedIndex == 0)
		{
			_scroll.y = 0f;
			return;
		}
		if (_selectedIndex == num5)
		{
			_scroll.y = Mathf.Max(0f, (float)num5 * 26f - num2);
			return;
		}
		if (num3 < _scroll.y)
		{
			_scroll.y = num3;
		}
		if (num4 > _scroll.y + num2)
		{
			_scroll.y = num4 - num2;
		}
	}

	private void ActivateSelected()
	{
		switch (_page)
		{
		case Page.Main:
			ActivateMain();
			break;
		case Page.ForceEvent:
			ActivateForceEvent();
			break;
		case Page.BlocksOnMap:
			ActivateBlocksOnMap();
			break;
		}
	}

	private void ActivateMain()
	{
		switch (_selectedIndex)
		{
		case 0:
			DoSpawnInFront();
			break;
		case 1:
			DoForceRandomNearest();
			break;
		case 2:
			GoTo(Page.ForceEvent);
			break;
		case 3:
			GoTo(Page.BlocksOnMap);
			break;
		case 4:
			DoForceSpawnLevel();
			break;
		}
	}

	private void ActivateForceEvent()
	{
		if (_selectedIndex == 0)
		{
			GoTo(Page.Main);
			return;
		}
		int eventIdx = _selectedIndex - 1;
		DoForceEvent(eventIdx);
	}

	private void ActivateBlocksOnMap()
	{
		if (_selectedIndex == 0)
		{
			GoTo(Page.Main);
			return;
		}
		int num = _selectedIndex - 1;
		if (num < _blockCache.Count && (Object)(object)_blockCache[num] != (Object)null)
		{
			ForceOpenBlock(_blockCache[num]);
		}
	}

	private void DoSpawnInFront()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)PlayerAvatar.instance == (Object)null))
		{
			LuckyBlockSpawner.SpawnOne(SpawnUtils.GetSpawnPositionInFront(PlayerAvatar.instance, 2.5f));
		}
	}

	private void DoForceRandomNearest()
	{
		LuckyBlock luckyBlock = FindNearestBlock();
		if ((Object)(object)luckyBlock != (Object)null)
		{
			ForceOpenBlock(luckyBlock);
		}
		else
		{
			Debug.Log((object)"[LuckyBlock] Debug: no blocks in scene.");
		}
	}

	private void DoForceSpawnLevel()
	{
		if (!SemiFunc.RunIsLevel())
		{
			Debug.Log((object)"[LuckyBlock] Debug: not in a level scene.");
			return;
		}
		LuckyBlockSpawner.ResetSpawnFlag();
		LuckyBlockSpawner.SpawnForCurrentLevel("ForceSpawnLevel (debug)");
	}

	private void DoForceEvent(int eventIdx)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		PlayerAvatar instance = PlayerAvatar.instance;
		if ((Object)(object)instance == (Object)null)
		{
			return;
		}
		if (!SemiFunc.IsMasterClientOrSingleplayer())
		{
			_lastEventMsg = "Host only — events are master-authoritative";
			return;
		}
		Vector3 spawnPositionInFront = SpawnUtils.GetSpawnPositionInFront(instance, 2.5f);
		IReadOnlyList<LuckyEvent> all = LuckyEventRegistry.All;
		if (eventIdx >= 0 && eventIdx < all.Count)
		{
			LuckyBlockEvents.TriggerSpecific(eventIdx, instance, spawnPositionInFront);
			_lastEventMsg = all[eventIdx].Label;
		}
		else
		{
			LuckyBlockEvents.Roll(instance, spawnPositionInFront);
			_lastEventMsg = "Full Roll fired";
		}
	}

	private void ForceOpenBlock(LuckyBlock b)
	{
		typeof(LuckyBlock).GetMethod("Open", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(b, null);
	}

	private LuckyBlock FindNearestBlock()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		LuckyBlock[] array = Object.FindObjectsOfType<LuckyBlock>();
		if (array.Length == 0)
		{
			return null;
		}
		if ((Object)(object)PlayerAvatar.instance == (Object)null)
		{
			return array[0];
		}
		LuckyBlock result = null;
		float num = float.MaxValue;
		Vector3 position = ((Component)PlayerAvatar.instance).transform.position;
		LuckyBlock[] array2 = array;
		foreach (LuckyBlock luckyBlock in array2)
		{
			float num2 = Vector3.Distance(((Component)luckyBlock).transform.position, position);
			if (num2 < num)
			{
				num = num2;
				result = luckyBlock;
			}
		}
		return result;
	}

	private void RefreshBlockCache()
	{
		_blockCache.Clear();
		_blockCache.AddRange(Object.FindObjectsOfType<LuckyBlock>());
	}

	private void OnGUI()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		if (_open)
		{
			float num = (float)Screen.height - 420f - 10f;
			GUI.Box(new Rect(10f, num, 360f, 420f), "");
			float num2 = 10f + 8f;
			float cy = num + 8f;
			float num3 = 344f;
			switch (_page)
			{
			case Page.Main:
				DrawMain(num2, cy, num3);
				break;
			case Page.ForceEvent:
				DrawForceEvent(num2, cy, num3);
				break;
			case Page.BlocksOnMap:
				DrawBlocksOnMap(num2, cy, num3);
				break;
			}
			float num4 = num + 420f - 8f - 18f;
			GUI.color = COL_DIM;
			GUI.Label(new Rect(num2, num4, num3, 18f), "↑↓ navigate (wrap+hold)   ENTER select (hold)   F6 close");
			GUI.color = Color.white;
		}
	}

	private void DrawMain(float cx, float cy, float cw)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		GUI.color = COL_GOLD;
		GUI.Label(new Rect(cx, cy, cw, 22f), "<b>[ LUCKY BLOCK DEBUG ]</b>");
		GUI.color = Color.white;
		cy += 30f;
		int num = Object.FindObjectsOfType<LuckyBlock>().Length;
		int num2 = (((Object)(object)RunManager.instance != (Object)null) ? (SemiFunc.RunGetLevelsCompleted() + 1) : 0);
		GUI.color = COL_DIM;
		GUI.Label(new Rect(cx, cy, cw, 22f), $"  Lvl {num2}   Blocks: {num}   " + "Master: " + (SemiFunc.IsMasterClientOrSingleplayer() ? "✓" : "✗"));
		cy += 24f;
		string text = (ModeManager.IsPrivate ? "Private  (custom item, press E)" : "Public   (valuable, grab it)");
		GUI.Label(new Rect(cx, cy, cw, 22f), "  Edition: " + text + "  (config + restart)");
		GUI.color = Color.white;
		cy += 28f;
		DrawItem(cx, cy, cw, "Spawn Lucky Block in Front", 0);
		cy += 26f;
		DrawItem(cx, cy, cw, "Force Random Event on Nearest", 1);
		cy += 26f;
		DrawItem(cx, cy, cw, "→ Force Specific Event", 2);
		cy += 26f;
		DrawItem(cx, cy, cw, $"→ Blocks on Map  ({num})", 3);
		cy += 26f;
		DrawItem(cx, cy, cw, "Force-Spawn Level Blocks", 4);
		cy += 26f;
		DrawEventLog(cx, cy, cw);
	}

	private void DrawEventLog(float cx, float cy, float cw)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		if (!LuckyEventLog.Enabled)
		{
			return;
		}
		cy += 6f;
		GUI.color = COL_GOLD;
		GUI.Label(new Rect(cx, cy, cw, 22f), $"<b>[ LAST EVENTS  ({LuckyEventLog.Duration:F0}s window) ]</b>");
		GUI.color = Color.white;
		cy += 22f;
		List<RandomEventRoller.EventLogEntry> visible = LuckyEventLog.GetVisible();
		if (visible.Count == 0)
		{
			GUI.color = COL_DIM;
			GUI.Label(new Rect(cx, cy, cw, 22f), "  No events yet.");
			GUI.color = Color.white;
			return;
		}
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		foreach (RandomEventRoller.EventLogEntry item in visible)
		{
			float num = realtimeSinceStartup - item.TimeLogged;
			bool num2 = num > LuckyEventLog.Duration;
			GUI.color = (num2 ? COL_DIM : ((num < 10f) ? COL_GREEN : COL_NORMAL));
			string text = (num2 ? "old" : $"{num:F0}s");
			GUI.Label(new Rect(cx, cy, cw, 22f), "  " + item.Timestamp + "  " + item.Label + "  (" + text + ")");
			GUI.color = Color.white;
			cy += 20f;
		}
	}

	private void DrawForceEvent(float cx, float cy, float cw)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		GUI.color = COL_GOLD;
		GUI.Label(new Rect(cx, cy, cw, 22f), "<b>[ Force Specific Event ]</b>");
		GUI.color = Color.white;
		cy += 28f;
		if (_lastEventMsg.Length > 0)
		{
			GUI.color = COL_GREEN;
			GUI.Label(new Rect(cx, cy, cw, 22f), "  ✓  " + _lastEventMsg);
			GUI.color = Color.white;
		}
		else
		{
			GUI.color = COL_DIM;
			GUI.Label(new Rect(cx, cy, cw, 22f), "  Spawns block in front + fires chosen event");
			GUI.color = Color.white;
		}
		cy += 30f;
		DrawItem(cx, cy, cw, "← Back", 0);
		cy += 28f;
		IReadOnlyList<LuckyEvent> all = LuckyEventRegistry.All;
		float num = 420f - (cy - ((float)Screen.height - 420f - 10f)) - 8f - 24f;
		float num2 = Mathf.Max((float)EventCount * 26f, num);
		_scroll = GUI.BeginScrollView(new Rect(cx, cy, cw, num), _scroll, new Rect(0f, 0f, cw - 16f, num2));
		Color val = default(Color);
		for (int i = 0; i < EventCount; i++)
		{
			bool flag = _selectedIndex == i + 1;
			string text;
			if (i >= all.Count)
			{
				text = "Full Roll         (random spin, all events)";
				val = COL_GOLD;
			}
			else
			{
				LuckyEvent luckyEvent = all[i];
				switch (luckyEvent.Category)
				{
				case LuckyEventCategory.Lucky:
					val = COL_GREEN;
					break;
				case LuckyEventCategory.Unlucky:
					val = COL_RED;
					break;
				case LuckyEventCategory.Chaotic:
					((Color)(ref val))..ctor(1f, 0.55f, 0f);
					break;
				default:
					((Color)(ref val))..ctor(0.7f, 0.6f, 1f);
					break;
				}
				bool flag2 = luckyEvent.RequiresAllClients && SemiFunc.IsMultiplayer() && !ModeManager.IsPrivate;
				text = luckyEvent.Label + (flag2 ? "  [private only]" : "");
				if (flag2)
				{
					val = COL_DIM;
				}
			}
			GUI.color = (flag ? COL_SELECTED : val);
			GUI.Label(new Rect(0f, (float)i * 26f, cw - 16f, 22f), (flag ? "► " : "  ") + text);
			GUI.color = Color.white;
		}
		GUI.EndScrollView();
	}

	private void DrawBlocksOnMap(float cx, float cy, float cw)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		GUI.color = COL_GOLD;
		GUI.Label(new Rect(cx, cy, cw, 22f), "<b>[ Blocks on Map ]</b>");
		GUI.color = Color.white;
		cy += 28f;
		DrawItem(cx, cy, cw, "← Back", 0);
		cy += 30f;
		RefreshBlockCache();
		float num = 420f - (cy - ((float)Screen.height - 420f - 10f)) - 8f - 24f;
		float num2 = Mathf.Max((float)_blockCache.Count * 26f, num);
		_scroll = GUI.BeginScrollView(new Rect(cx, cy, cw, num), _scroll, new Rect(0f, 0f, cw - 16f, num2));
		Vector3 val = (((Object)(object)PlayerAvatar.instance != (Object)null) ? ((Component)PlayerAvatar.instance).transform.position : Vector3.zero);
		for (int i = 0; i < _blockCache.Count; i++)
		{
			LuckyBlock luckyBlock = _blockCache[i];
			if (!((Object)(object)luckyBlock == (Object)null))
			{
				bool flag = _selectedIndex == i + 1;
				Vector3 position = ((Component)luckyBlock).transform.position;
				float num3 = Vector3.Distance(position, val);
				GUI.color = (flag ? COL_SELECTED : COL_GOLD);
				GUI.Label(new Rect(0f, (float)i * 26f, cw - 16f, 22f), (flag ? "► " : "  ") + $"Block {i + 1}:  ({position.x:F1}, {position.y:F1}, {position.z:F1})  | {num3:F1}m  [ENTER=open]");
				GUI.color = Color.white;
			}
		}
		if (_blockCache.Count == 0)
		{
			GUI.color = COL_DIM;
			GUI.Label(new Rect(0f, 0f, cw - 16f, 22f), "  No lucky blocks in scene.");
			GUI.color = Color.white;
		}
		GUI.EndScrollView();
	}

	private void DrawItem(float cx, float cy, float cw, string label, int idx)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		bool flag = _selectedIndex == idx;
		GUI.color = (flag ? COL_SELECTED : COL_NORMAL);
		GUI.Label(new Rect(cx, cy, cw, 22f), (flag ? "► " : "  ") + label);
		GUI.color = Color.white;
	}
}
internal static class EventHelpers
{
	private static FieldInfo _fValCurrent;

	private static FieldInfo _fValOriginal;

	private static FieldInfo _fValSet;

	private static FieldInfo _fExtCurrent;

	private static FieldInfo _fGrabbedObj;

	private static bool _reflected;

	private static Item _grenadeItem;

	private static void EnsureReflection()
	{
		if (!_reflected)
		{
			_reflected = true;
			Type? typeFromHandle = typeof(ValuableObject);
			_fValCurrent = typeFromHandle.GetField("dollarValueCurrent", BindingFlags.Instance | BindingFlags.NonPublic);
			_fValOriginal = typeFromHandle.GetField("dollarValueOriginal", BindingFlags.Instance | BindingFlags.NonPublic);
			_fValSet = typeFromHandle.GetField("dollarValueSet", BindingFlags.Instance | BindingFlags.NonPublic);
			_fExtCurrent = typeof(RoundDirector).GetField("extractionPointCurrent", BindingFlags.Instance | BindingFlags.NonPublic);
			_fGrabbedObj = typeof(PhysGrabber).GetField("grabbedPhysGrabObject", BindingFlags.Instance | BindingFlags.NonPublic);
		}
	}

	internal static void Announce(string label)
	{
		LuckyFx.Broadcast("announce", label);
	}

	internal static List<PlayerAvatar> GetAllPlayers()
	{
		List<PlayerAvatar> list = new List<PlayerAvatar>();
		foreach (PlayerAvatar item in SemiFunc.PlayerGetAll())
		{
			if ((Object)(object)item != (Object)null)
			{
				list.Add(item);
			}
		}
		return list;
	}

	internal static void TeleportPlayer(PlayerAvatar avatar, Vector3 pos)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)avatar == (Object)null)
		{
			return;
		}
		avatar.Spawn(pos, ((Component)avatar).transform.rotation);
		if ((Object)(object)avatar == (Object)(object)PlayerAvatar.instance)
		{
			TeleportLocalController(pos);
		}
		else if (SemiFunc.IsMultiplayer() && ModeManager.IsPrivate)
		{
			PhotonView component = ((Component)avatar).GetComponent<PhotonView>();
			if ((Object)(object)component != (Object)null)
			{
				LuckyFx.Broadcast("teleport", string.Format(CultureInfo.InvariantCulture, "{0},{1:F2},{2:F2},{3:F2}", component.ViewID, pos.x, pos.y, pos.z));
			}
		}
	}

	internal static void TeleportLocalController(Vector3 pos)
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		PlayerController instance = PlayerController.instance;
		if (!((Object)(object)instance == (Object)null))
		{
			if ((Object)(object)instance.rb != (Object)null)
			{
				instance.rb.velocity = Vector3.zero;
				instance.rb.position = pos;
			}
			((Component)instance).transform.position = pos;
		}
	}

	internal static void UpgradePlayer(PlayerAvatar avatar, string upgradeName, int amount = 1)
	{
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)avatar == (Object)null || (Object)(object)PunManager.instance == (Object)null)
		{
			return;
		}
		string text = SemiFunc.PlayerGetSteamID(avatar);
		if (string.IsNullOrEmpty(text))
		{
			return;
		}
		if (SemiFunc.IsMultiplayer())
		{
			PhotonView component = ((Component)PunManager.instance).GetComponent<PhotonView>();
			if ((Object)(object)component != (Object)null)
			{
				component.RPC("TesterUpgradeCommandRPC", (RpcTarget)0, new object[3] { text, upgradeName, amount });
			}
		}
		else
		{
			PunManager.instance.TesterUpgradeCommandRPC(text, upgradeName, amount, default(PhotonMessageInfo));
		}
	}

	internal static void HealPlayer(PlayerAvatar avatar, int amount)
	{
		if ((Object)(object)avatar != (Object)null && (Object)(object)avatar.playerHealth != (Object)null)
		{
			avatar.playerHealth.HealOther(amount, true);
		}
	}

	internal static List<Enemy> GetSpawnedEnemies()
	{
		List<Enemy> list = new List<Enemy>();
		if ((Object)(object)EnemyDirector.instance == (Object)null)
		{
			return list;
		}
		foreach (EnemyParent item in EnemyDirector.instance.enemiesSpawned)
		{
			if (!((Object)(object)item == (Object)null))
			{
				Enemy componentInChildren = ((Component)item).GetComponentInChildren<Enemy>(true);
				if ((Object)(object)componentInChildren != (Object)null && ((Component)componentInChildren).gameObject.activeInHierarchy)
				{
					list.Add(componentInChildren);
				}
			}
		}
		return list;
	}

	internal static void TeleportEnemy(Enemy enemy, Vector3 pos)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)enemy != (Object)null)
		{
			enemy.EnemyTeleported(pos);
		}
	}

	internal static List<ValuableObject> GetLooseValuables()
	{
		List<ValuableObject> list = new List<ValuableObject>();
		List<GameObject> list2 = (((Object)(object)RoundDirector.instance != (Object)null) ? RoundDirector.instance.dollarHaulList : null);
		ValuableObject[] array = Object.FindObjectsOfType<ValuableObject>();
		foreach (ValuableObject val in array)
		{
			if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).GetComponent<LuckyBlock>() != (Object)null))
			{
				LuckyBlockItem component = ((Component)val).GetComponent<LuckyBlockItem>();
				if ((!((Object)(object)component != (Object)null) || !component.IsLucky) && (list2 == null || !list2.Contains(((Component)val).gameObject)))
				{
					list.Add(val);
				}
			}
		}
		return list;
	}

	internal static float GetValuableValue(ValuableObject v)
	{
		EnsureReflection();
		if ((Object)(object)v == (Object)null || _fValCurrent == null)
		{
			return 0f;
		}
		return (float)_fValCurrent.GetValue(v);
	}

	internal static void SetValuableValue(ValuableObject v, float value)
	{
		EnsureReflection();
		if ((Object)(object)v == (Object)null || _fValCurrent == null)
		{
			return;
		}
		value = Mathf.Max(0f, Mathf.Round(value));
		_fValCurrent.SetValue(v, value);
		_fValOriginal?.SetValue(v, value);
		_fValSet?.SetValue(v, true);
		if (SemiFunc.IsMultiplayer())
		{
			PhotonView component = ((Component)v).GetComponent<PhotonView>();
			if ((Object)(object)component != (Object)null && component.ViewID != 0)
			{
				component.RPC("DollarValueSetRPC", (RpcTarget)1, new object[1] { value });
			}
		}
	}

	internal static void TeleportPhysObject(PhysGrabObject o, Vector3 pos)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)o != (Object)null)
		{
			o.Teleport(pos, ((Component)o).transform.rotation);
		}
	}

	internal static void DestroyValuable(ValuableObject v)
	{
		if (!((Object)(object)v == (Object)null))
		{
			PhysGrabObjectImpactDetector component = ((Component)v).GetComponent<PhysGrabObjectImpactDetector>();
			if ((Object)(object)component != (Object)null)
			{
				component.DestroyObject(true);
			}
			else
			{
				Object.Destroy((Object)(object)((Component)v).gameObject);
			}
		}
	}

	internal static ExtractionPoint GetActiveExtraction()
	{
		EnsureReflection();
		if ((Object)(object)RoundDirector.instance == (Object)null || _fExtCurrent == null)
		{
			return null;
		}
		object? value = _fExtCurrent.GetValue(RoundDirector.instance);
		return (ExtractionPoint)((value is ExtractionPoint) ? value : null);
	}

	internal static void SetHaulGoal(ExtractionPoint ep, int value)
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)ep == (Object)null)
		{
			return;
		}
		value = Mathf.Max(1, value);
		if (SemiFunc.IsMultiplayer())
		{
			PhotonView component = ((Component)ep).GetComponent<PhotonView>();
			if ((Object)(object)component != (Object)null && component.ViewID != 0)
			{
				component.RPC("HaulGoalSetRPC", (RpcTarget)0, new object[1] { value });
			}
		}
		else
		{
			ep.HaulGoalSetRPC(value, default(PhotonMessageInfo));
		}
	}

	internal static List<Vector3> GetRandomLevelPoints(int count)
	{
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		List<LevelPoint> list = new List<LevelPoint>();
		if ((Object)(object)LevelGenerator.Instance != (Object)null)
		{
			foreach (LevelPoint levelPathPoint in LevelGenerator.Instance.LevelPathPoints)
			{
				if ((Object)(object)levelPathPoint != (Object)null && !levelPathPoint.Truck && (Object)(object)((Component)levelPathPoint).GetComponentInParent<StartRoom>() == (Object)null)
				{
					list.Add(levelPathPoint);
				}
			}
		}
		List<Vector3> list2 = new List<Vector3>(count);
		if (list.Count == 0)
		{
			PlayerAvatar instance = PlayerAvatar.instance;
			return SpawnUtils.GetFloorRing(((Object)(object)instance != (Object)null) ? ((Component)instance).transform.position : Vector3.zero, count, 5f);
		}
		for (int i = 0; i < count; i++)
		{
			LevelPoint val = list[Random.Range(0, list.Count)];
			list2.Add(((Component)val).transform.position + Vector3.up * 0.5f);
		}
		return list2;
	}

	private static Item FindGrenadeItem()
	{
		if ((Object)(object)_grenadeItem != (Object)null)
		{
			return _grenadeItem;
		}
		foreach (Item allItem in Items.AllItems)
		{
			string text = ((Object)allItem).name.ToLowerInvariant();
			if (text.Contains("grenade") && !text.Contains("mine") && !text.Contains("human"))
			{
				_grenadeItem = allItem;
				break;
			}
		}
		return _grenadeItem;
	}

	internal static void SpawnGrenadeAt(Vector3 pos, float fuse)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		Item val = FindGrenadeItem();
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		GameObject val2 = (SemiFunc.IsMultiplayer() ? Items.SpawnItem(val, pos, Quaternion.identity) : Object.Instantiate<GameObject>(((PrefabRef<GameObject>)(object)val.prefab).Prefab, pos, Quaternion.identity));
		if (!((Object)(object)val2 == (Object)null))
		{
			ItemGrenade componentInChildren = val2.GetComponentInChildren<ItemGrenade>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.isSpawnedGrenade = true;
				componentInChildren.tickTime = fuse;
			}
			ItemToggle componentInChildren2 = val2.GetComponentInChildren<ItemToggle>();
			if ((Object)(object)componentInChildren2 != (Object)null)
			{
				componentInChildren2.toggleState = true;
			}
		}
	}

	internal static void ReleaseLocalGrab()
	{
		EnsureReflection();
		PhysGrabber instance = PhysGrabber.instance;
		if (!((Object)(object)instance == (Object)null) && instance.grabbed && !(_fGrabbedObj == null))
		{
			object? value = _fGrabbedObj.GetValue(instance);
			PhysGrabObject val = (PhysGrabObject)((value is PhysGrabObject) ? value : null);
			if (!((Object)(object)val == (Object)null))
			{
				PhotonView component = ((Component)val).GetComponent<PhotonView>();
				int num = (((Object)(object)component != (Object)null) ? component.ViewID : 0);
				instance.OverrideGrabRelease(num, 1f);
			}
		}
	}
}
public class EvTreasureMigration : LuckyEvent
{
	public override string Id => "TreasureMigration";

	public override string Label => "Treasure Migration — all loot scatters";

	public override LuckyEventCategory Category => LuckyEventCategory.Chaotic;

	public override float DefaultWeight => 2f;

	public override bool CanRun(LuckyEventContext ctx)
	{
		return EventHelpers.GetLooseValuables().Count > 2;
	}

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		List<ValuableObject> looseValuables = EventHelpers.GetLooseValuables();
		List<Vector3> randomLevelPoints = EventHelpers.GetRandomLevelPoints(looseValuables.Count);
		for (int i = 0; i < looseValuables.Count && i < randomLevelPoints.Count; i++)
		{
			EventHelpers.TeleportPhysObject(((Component)looseValuables[i]).GetComponent<PhysGrabObject>(), randomLevelPoints[i]);
		}
	}
}
public class EvPositionSwap : LuckyEvent
{
	public override string Id => "PositionSwap";

	public override string Label => "Musical Chairs — everyone swaps positions";

	public override LuckyEventCategory Category => LuckyEventCategory.Chaotic;

	public override float DefaultWeight => 3f;

	public override bool CanRun(LuckyEventContext ctx)
	{
		return EventHelpers.GetAllPlayers().Count >= 2;
	}

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		List<PlayerAvatar> allPlayers = EventHelpers.GetAllPlayers();
		List<Vector3> list = new List<Vector3>(allPlayers.Count);
		foreach (PlayerAvatar item in allPlayers)
		{
			list.Add(((Component)item).transform.position);
		}
		for (int i = 0; i < allPlayers.Count; i++)
		{
			EventHelpers.TeleportPlayer(allPlayers[i], list[(i + 1) % list.Count]);
		}
	}
}
public class EvMeteorShower : LuckyEvent
{
	public override string Id => "MeteorShower";

	public override string Label => "Meteor Shower — grenades rain on everyone";

	public override LuckyEventCategory Category => LuckyEventCategory.Chaotic;

	public override float DefaultWeight => 2.5f;

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = default(Vector3);
		foreach (PlayerAvatar allPlayer in EventHelpers.GetAllPlayers())
		{
			if (!((Object)(object)allPlayer == (Object)null))
			{
				Vector3 position = ((Component)allPlayer).transform.position;
				for (int i = 0; i < 3; i++)
				{
					((Vector3)(ref val))..ctor(Random.Range(-2.5f, 2.5f), 0f, Random.Range(-2.5f, 2.5f));
					EventHelpers.SpawnGrenadeAt(position + val + Vector3.up * 6f, 1.6f);
				}
			}
		}
	}
}
public class EvEarthquake : LuckyEvent
{
	public override string Id => "Earthquake";

	public override string Label => "Earthquake — everything gets launched";

	public override LuckyEventCategory Category => LuckyEventCategory.Chaotic;

	public override float DefaultWeight => 3f;

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		PhysGrabObject[] array = Object.FindObjectsOfType<PhysGrabObject>();
		Vector3 val2 = default(Vector3);
		foreach (PhysGrabObject val in array)
		{
			if (!((Object)(object)val == (Object)null))
			{
				Rigidbody component = ((Component)val).GetComponent<Rigidbody>();
				if (!((Object)(object)component == (Object)null) && !component.isKinematic)
				{
					((Vector3)(ref val2))..ctor(Random.Range(-1.5f, 1.5f), Random.Range(2f, 4f), Random.Range(-1.5f, 1.5f));
					component.AddForce(val2, (ForceMode)2);
				}
			}
		}
		LuckyFx.Broadcast("shake", "5,1.5");
	}
}
public class EvVacuumPulse : LuckyEvent
{
	public override string Id => "VacuumPulse";

	public override string Label => "Vacuum Pulse — loot flies to the block";

	public override LuckyEventCategory Category => LuckyEventCategory.Chaotic;

	public override float DefaultWeight => 2f;

	public override bool CanRun(LuckyEventContext ctx)
	{
		return EventHelpers.GetLooseValuables().Count > 1;
	}

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		List<ValuableObject> looseValuables = EventHelpers.GetLooseValuables();
		List<Vector3> floorRing = SpawnUtils.GetFloorRing(ctx.BlockPos, Mathf.Max(3, looseValuables.Count), 2.2f);
		int num = 0;
		foreach (ValuableObject item in looseValuables)
		{
			EventHelpers.TeleportPhysObject(((Component)item).GetComponent<PhysGrabObject>(), floorRing[num++ % floorRing.Count] + Vector3.up * 0.4f);
		}
	}
}
public class EvEnemyScatter : LuckyEvent
{
	public override string Id => "EnemyScatter";

	public override string Label => "The Rapture — every enemy teleports away";

	public override LuckyEventCategory Category => LuckyEventCategory.Chaotic;

	public override float DefaultWeight => 2f;

	public override bool CanRun(LuckyEventContext ctx)
	{
		return EventHelpers.GetSpawnedEnemies().Count > 0;
	}

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		List<Enemy> spawnedEnemies = EventHelpers.GetSpawnedEnemies();
		List<Vector3> randomLevelPoints = EventHelpers.GetRandomLevelPoints(spawnedEnemies.Count);
		for (int i = 0; i < spawnedEnemies.Count && i < randomLevelPoints.Count; i++)
		{
			EventHelpers.TeleportEnemy(spawnedEnemies[i], randomLevelPoints[i]);
		}
	}
}
public class EvZeroGLoot : LuckyEvent
{
	public override string Id => "ZeroGLoot";

	public override string Label => "Zero-G Loot — valuables float for 15s";

	public override LuckyEventCategory Category => LuckyEventCategory.Chaotic;

	public override float DefaultWeight => 3f;

	public override bool CanRun(LuckyEventContext ctx)
	{
		return EventHelpers.GetLooseValuables().Count > 0;
	}

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		foreach (ValuableObject looseValuable in EventHelpers.GetLooseValuables())
		{
			PhysGrabObject component = ((Component)looseValuable).GetComponent<PhysGrabObject>();
			if (!((Object)(object)component == (Object)null))
			{
				component.OverrideZeroGravity(15f);
				Rigidbody component2 = ((Component)component).GetComponent<Rigidbody>();
				if ((Object)(object)component2 != (Object)null && !component2.isKinematic)
				{
					component2.AddForce(Vector3.up * 1.2f, (ForceMode)2);
				}
			}
		}
	}
}
public class EvValuable : LuckyEvent
{
	public override string Id => "Valuable";

	public override string Label => "Random Valuable";

	public override LuckyEventCategory Category => LuckyEventCategory.Lucky;

	public override float DefaultWeight => 14f;

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		SpawnUtils.SpawnRandomValuable(SpawnUtils.GetSpawnPositionInFront(ctx.Opener, 2.5f));
	}
}
public class EvJackpot : LuckyEvent
{
	public override string Id => "Jackpot";

	public override string Label => "Jackpot — 3 Valuables";

	public override LuckyEventCategory Category => LuckyEventCategory.Lucky;

	public override float DefaultWeight => 4f;

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		foreach (Vector3 item in SpawnUtils.GetFloorRing(ctx.BlockPos, 3, 1.8f))
		{
			SpawnUtils.SpawnRandomValuable(item);
		}
	}
}
public class EvItem : LuckyEvent
{
	public override string Id => "Item";

	public override string Label => "Random Item";

	public override LuckyEventCategory Category => LuckyEventCategory.Lucky;

	public override float DefaultWeight => 10f;

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		SpawnUtils.SpawnRandomItem(SpawnUtils.GetSpawnPositionInFront(ctx.Opener, 2.5f));
	}
}
public class EvToolChest : LuckyEvent
{
	public override string Id => "ToolChest";

	public override string Label => "Tool Chest — 2 Items";

	public override LuckyEventCategory Category => LuckyEventCategory.Lucky;

	public override float DefaultWeight => 3f;

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		foreach (Vector3 item in SpawnUtils.GetFloorRing(ctx.BlockPos, 2, 1.5f))
		{
			SpawnUtils.SpawnRandomItem(item);
		}
	}
}
public class EvPotion : LuckyEvent
{
	public override string Id => "Potion";

	public override string Label => "Potion (breaks on floor)";

	public override LuckyEventCategory Category => LuckyEventCategory.Lucky;

	public override float DefaultWeight => 6f;

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		SpawnUtils.SpawnPotion(SpawnUtils.GetSpawnPositionInFront(ctx.Opener, 2.5f));
	}
}
public class EvLuckyCluster : LuckyEvent
{
	public override string Id => "LuckyCluster";

	public override string Label => "Lucky Cluster — 3 New Blocks";

	public override LuckyEventCategory Category => LuckyEventCategory.Lucky;

	public override float DefaultWeight => 6f;

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		LuckyBlockManager.Instance?.SpawnBlocks(SpawnUtils.GetFloorRing(ctx.BlockPos, 3, 2f));
	}
}
public class EvHealingWave : LuckyEvent
{
	public override string Id => "HealingWave";

	public override string Label => "Healing Wave — +50 HP everyone";

	public override LuckyEventCategory Category => LuckyEventCategory.Lucky;

	public override float DefaultWeight => 5f;

	public override void Execute(LuckyEventContext ctx)
	{
		foreach (PlayerAvatar allPlayer in EventHelpers.GetAllPlayers())
		{
			EventHelpers.HealPlayer(allPlayer, 50);
		}
	}
}
public abstract class EvUpgradeBase : LuckyEvent
{
	public override LuckyEventCategory Category => LuckyEventCategory.Lucky;

	protected abstract string UpgradeName { get; }

	public override void Execute(LuckyEventContext ctx)
	{
		EventHelpers.UpgradePlayer(ctx.Opener, UpgradeName);
	}
}
public class EvUpgradeSpeed : EvUpgradeBase
{
	public override string Id => "UpgradeSpeed";

	public override string Label => "Adrenaline — Sprint Speed +1";

	public override float DefaultWeight => 2.5f;

	protected override string UpgradeName => "Speed";
}
public class EvUpgradeJump : EvUpgradeBase
{
	public override string Id => "UpgradeJump";

	public override string Label => "Moon Boots — Extra Jump +1";

	public override float DefaultWeight => 2.5f;

	protected override string UpgradeName => "ExtraJump";
}
public class EvUpgradeStamina : EvUpgradeBase
{
	public override string Id => "UpgradeStamina";

	public override string Label => "Iron Lungs — Stamina +1";

	public override float DefaultWeight => 2.5f;

	protected override string UpgradeName => "Stamina";
}
public class EvUpgradeHealth : EvUpgradeBase
{
	public override string Id => "UpgradeHealth";

	public override string Label => "Vitality — Max Health +1";

	public override float DefaultWeight => 2.5f;

	protected override string UpgradeName => "Health";
}
public class EvUpgradeStrength : EvUpgradeBase
{
	public override string Id => "UpgradeStrength";

	public override string Label => "Strong Arms — Grab Strength +1";

	public override float DefaultWeight => 2f;

	protected override string UpgradeName => "Strength";
}
public class EvUpgradeRange : EvUpgradeBase
{
	public override string Id => "UpgradeRange";

	public override string Label => "Long Reach — Grab Range +1";

	public override float DefaultWeight => 2f;

	protected override string UpgradeName => "Range";
}
public class EvEnemyFreeze : LuckyEvent
{
	public override string Id => "EnemyFreeze";

	public override string Label => "Deep Freeze — enemies frozen 10s";

	public override LuckyEventCategory Category => LuckyEventCategory.Lucky;

	public override float DefaultWeight => 4f;

	public override bool CanRun(LuckyEventContext ctx)
	{
		return EventHelpers.GetSpawnedEnemies().Count > 0;
	}

	public override void Execute(LuckyEventContext ctx)
	{
		foreach (Enemy spawnedEnemy in EventHelpers.GetSpawnedEnemies())
		{
			spawnedEnemy.Freeze(10f);
		}
	}
}
public class EvGoldenTouch : LuckyEvent
{
	public override string Id => "GoldenTouch";

	public override string Label => "Golden Touch — all loot +25% value";

	public override LuckyEventCategory Category => LuckyEventCategory.Lucky;

	public override float DefaultWeight => 3f;

	public override bool CanRun(LuckyEventContext ctx)
	{
		return EventHelpers.GetLooseValuables().Count > 0;
	}

	public override void Execute(LuckyEventContext ctx)
	{
		foreach (ValuableObject looseValuable in EventHelpers.GetLooseValuables())
		{
			float valuableValue = EventHelpers.GetValuableValue(looseValuable);
			if (valuableValue > 0f)
			{
				EventHelpers.SetValuableValue(looseValuable, valuableValue * 1.25f);
			}
		}
	}
}
public class EvScavengerHunt : LuckyEvent
{
	public override string Id => "ScavengerHunt";

	public override string Label => "Scavenger Hunt — one hidden valuable ×10";

	public override LuckyEventCategory Category => LuckyEventCategory.Lucky;

	public override float DefaultWeight => 3f;

	public override bool CanRun(LuckyEventContext ctx)
	{
		return EventHelpers.GetLooseValuables().Count > 0;
	}

	public override void Execute(LuckyEventContext ctx)
	{
		List<ValuableObject> looseValuables = EventHelpers.GetLooseValuables();
		ValuableObject v = looseValuables[Random.Range(0, looseValuables.Count)];
		float valuableValue = EventHelpers.GetValuableValue(v);
		if (valuableValue > 0f)
		{
			EventHelpers.SetValuableValue(v, valuableValue * 10f);
		}
	}
}
public class EvLuckyDiscount : LuckyEvent
{
	public override string Id => "LuckyDiscount";

	public override string Label => "Lucky Discount — quota −15%";

	public override LuckyEventCategory Category => LuckyEventCategory.Lucky;

	public override float DefaultWeight => 2f;

	public override bool CanRun(LuckyEventContext ctx)
	{
		ExtractionPoint activeExtraction = EventHelpers.GetActiveExtraction();
		if ((Object)(object)activeExtraction != (Object)null)
		{
			return activeExtraction.haulGoal > 0;
		}
		return false;
	}

	public override void Execute(LuckyEventContext ctx)
	{
		ExtractionPoint activeExtraction = EventHelpers.GetActiveExtraction();
		if (!((Object)(object)activeExtraction == (Object)null))
		{
			EventHelpers.SetHaulGoal(activeExtraction, Mathf.RoundToInt((float)activeExtraction.haulGoal * 0.85f));
		}
	}
}
public class EvMonster : LuckyEvent
{
	public override string Id => "Monster";

	public override string Label => "Random Monster";

	public override LuckyEventCategory Category => LuckyEventCategory.Unlucky;

	public override float DefaultWeight => 8f;

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		SpawnUtils.SpawnRandomMonster(SpawnUtils.GetSpawnPositionInFront(ctx.Opener, 2.5f), (MonoBehaviour)(object)LuckyBlockPlugin.Instance);
	}
}
public class EvMonsterPack : LuckyEvent
{
	public override string Id => "MonsterPack";

	public override string Label => "Monster Pack — 2 Monsters";

	public override LuckyEventCategory Category => LuckyEventCategory.Unlucky;

	public override float DefaultWeight => 2.5f;

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		foreach (Vector3 item in SpawnUtils.GetFloorRing(ctx.BlockPos, 2, 3f))
		{
			SpawnUtils.SpawnRandomMonster(item, (MonoBehaviour)(object)LuckyBlockPlugin.Instance);
		}
	}
}
public class EvExplosiveFeet : LuckyEvent
{
	public override string Id => "ExplosiveFeet";

	public override string Label => "Explosive at Feet";

	public override LuckyEventCategory Category => LuckyEventCategory.Unlucky;

	public override float DefaultWeight => 7f;

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		SpawnUtils.SpawnRandomExplosive(SpawnUtils.GetSpawnPositionOnPlayer(ctx.Opener));
	}
}
public class EvClusterSmall : LuckyEvent
{
	public override string Id => "ClusterSmall";

	public override string Label => "Small Cluster — 3 bombs around player";

	public override LuckyEventCategory Category => LuckyEventCategory.Unlucky;

	public override float DefaultWeight => 5f;

	public override void Execute(LuckyEventContext ctx)
	{
		SpawnUtils.SpawnExplosiveCluster(ctx.Opener);
	}
}
public class EvClusterLarge : LuckyEvent
{
	public override string Id => "ClusterLarge";

	public override string Label => "Large Cluster — 5 bombs around block";

	public override LuckyEventCategory Category => LuckyEventCategory.Unlucky;

	public override float DefaultWeight => 3f;

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		SpawnUtils.SpawnLargeExplosiveCluster(ctx.BlockPos);
	}
}
public class EvTumble : LuckyEvent
{
	public override string Id => "Tumble";

	public override string Label => "Knockdown — tumble lock 3s";

	public override LuckyEventCategory Category => LuckyEventCategory.Unlucky;

	public override float DefaultWeight => 4f;

	public override void Execute(LuckyEventContext ctx)
	{
		RandomEventRoller.ForceTumbleLock(ctx.Opener);
	}
}
public class EvTeleportRoulette : LuckyEvent
{
	public override string Id => "TeleportRoulette";

	public override string Label => "Teleport Roulette — opener sent somewhere";

	public override LuckyEventCategory Category => LuckyEventCategory.Unlucky;

	public override float DefaultWeight => 3f;

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		List<Vector3> randomLevelPoints = EventHelpers.GetRandomLevelPoints(1);
		if (randomLevelPoints.Count > 0)
		{
			EventHelpers.TeleportPlayer(ctx.Opener, randomLevelPoints[0]);
		}
	}
}
public class EvPiedPiper : LuckyEvent
{
	public override string Id => "PiedPiper";

	public override string Label => "Pied Piper — every enemy comes to YOU";

	public override LuckyEventCategory Category => LuckyEventCategory.Unlucky;

	public override float DefaultWeight => 2f;

	public override bool CanRun(LuckyEventContext ctx)
	{
		return EventHelpers.GetSpawnedEnemies().Count > 0;
	}

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)ctx.Opener == (Object)null)
		{
			return;
		}
		List<Vector3> floorRing = SpawnUtils.GetFloorRing(((Component)ctx.Opener).transform.position, Mathf.Max(1, EventHelpers.GetSpawnedEnemies().Count), 4f);
		int num = 0;
		foreach (Enemy spawnedEnemy in EventHelpers.GetSpawnedEnemies())
		{
			EventHelpers.TeleportEnemy(spawnedEnemy, floorRing[num++ % floorRing.Count]);
		}
	}
}
public class EvTaxman : LuckyEvent
{
	public override string Id => "Taxman";

	public override string Label => "The Taxman — cheapest valuable repossessed";

	public override LuckyEventCategory Category => LuckyEventCategory.Unlucky;

	public override float DefaultWeight => 3f;

	public override bool CanRun(LuckyEventContext ctx)
	{
		return EventHelpers.GetLooseValuables().Count > 1;
	}

	public override void Execute(LuckyEventContext ctx)
	{
		ValuableObject val = null;
		float num = float.MaxValue;
		foreach (ValuableObject looseValuable in EventHelpers.GetLooseValuables())
		{
			float valuableValue = EventHelpers.GetValuableValue(looseValuable);
			if (valuableValue > 0f && valuableValue < num)
			{
				num = valuableValue;
				val = looseValuable;
			}
		}
		if ((Object)(object)val != (Object)null)
		{
			EventHelpers.DestroyValuable(val);
		}
	}
}
public class EvReversePayday : LuckyEvent
{
	public override string Id => "ReversePayday";

	public override string Label => "Reverse Payday — quota +15%";

	public override LuckyEventCategory Category => LuckyEventCategory.Unlucky;

	public override float DefaultWeight => 2f;

	public override bool CanRun(LuckyEventContext ctx)
	{
		ExtractionPoint activeExtraction = EventHelpers.GetActiveExtraction();
		if ((Object)(object)activeExtraction != (Object)null)
		{
			return activeExtraction.haulGoal > 0;
		}
		return false;
	}

	public override void Execute(LuckyEventContext ctx)
	{
		ExtractionPoint activeExtraction = EventHelpers.GetActiveExtraction();
		if (!((Object)(object)activeExtraction == (Object)null))
		{
			EventHelpers.SetHaulGoal(activeExtraction, Mathf.RoundToInt((float)activeExtraction.haulGoal * 1.15f));
		}
	}
}
public class EvHoardersCurse : LuckyEvent
{
	public override string Id => "HoardersCurse";

	public override string Label => "Hoarder's Curse — all loot piles up in one room";

	public override LuckyEventCategory Category => LuckyEventCategory.Unlucky;

	public override float DefaultWeight => 2f;

	public override bool CanRun(LuckyEventContext ctx)
	{
		return EventHelpers.GetLooseValuables().Count > 2;
	}

	public override void Execute(LuckyEventContext ctx)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		List<Vector3> randomLevelPoints = EventHelpers.GetRandomLevelPoints(1);
		if (randomLevelPoints.Count == 0)
		{
			return;
		}
		Vector3 val = randomLevelPoints[0];
		int num = 0;
		Vector3 val2 = default(Vector3);
		foreach (ValuableObject looseValuable in EventHelpers.GetLooseValuables())
		{
			PhysGrabObject component = ((Component)looseValuable).GetComponent<PhysGrabObject>();
			((Vector3)(ref val2))..ctor(Random.Range(-0.8f, 0.8f), 0.3f + (float)(num++ % 5) * 0.3f, Random.Range(-0.8f, 0.8f));
			EventHelpers.TeleportPhysObject(component, val + val2);
		}
	}
}
public class EvBlackout : LuckyEvent
{
	public override string Id => "Blackout";

	public override string Label => "Blackout — lights out for 30s";

	public override LuckyEventCategory Category => LuckyEventCategory.Wacky;

	public override float DefaultWeight => 3f;

	public override bool RequiresAllClients => true;

	public override void Execute(LuckyEventContext ctx)
	{
		LuckyFx.Broadcast("blackout", "30");
	}
}
public class EvLowGravity : LuckyEvent
{
	public override string Id => "LowGravity";

	public override string Label => "Low Gravity — 20s of moon physics";

	public override LuckyEventCategory Category => LuckyEventCategory.Wacky;

	public override float DefaultWeight => 3f;

	public override bool RequiresAllClients => true;

	public override void Execute(LuckyEventContext ctx)
	{
		LuckyFx.Broadcast("lowgrav", "20");
	}
}
public class EvRaveLights : LuckyEvent
{
	public override string Id => "RaveLights";

	public override string Label => "Rave — rainbow lighting for 20s";

	public override LuckyEventCategory Category => LuckyEventCategory.Wacky;

	public override float DefaultWeight => 2.5f;

	public override bool RequiresAllClients => true;

	public override void Execute(LuckyEventContext ctx)
	{
		LuckyFx.Broadcast("rave", "20");
	}
}
public class EvFalseAlarm : LuckyEvent
{
	public override string Id => "FalseAlarm";

	public override string Label => "False Alarm — something is coming...";

	public override LuckyEventCategory Category => LuckyEventCategory.Wacky;

	public override float DefaultWeight => 3f;

	public override bool RequiresAllClients => true;

	public override void Execute(LuckyEventContext ctx)
	{
		LuckyFx.Broadcast("falsealarm", "");
	}
}
public class EvButterFingers : LuckyEvent
{
	public override string Id => "ButterFingers";

	public override string Label => "Butter Fingers — everyone drops their grab";

	public override LuckyEventCategory Category => LuckyEventCategory.Wacky;

	public override float DefaultWeight => 3f;

	public override bool RequiresAllClients => true;

	public override void Execute(LuckyEventContext ctx)
	{
		LuckyFx.Broadcast("butterfingers", "");
	}
}
public class EvTinyPlayers : LuckyEvent
{
	public override string Id => "TinyPlayers";

	public override string Label => "Honey I Shrunk the Crew — tiny for 30s";

	public override LuckyEventCategory Category => LuckyEventCategory.Wacky;

	public override float DefaultWeight => 2f;

	public override bool RequiresAllClients => true;

	public override void Execute(LuckyEventContext ctx)
	{
		LuckyFx.Broadcast("avatarscale", "0.5,30");
	}
}
public class EvGiantPlayers : LuckyEvent
{
	public override string Id => "GiantPlayers";

	public override string Label => "Growth Spurt — giant avatars for 30s";

	public override LuckyEventCategory Category => LuckyEventCategory.Wacky;

	public override float DefaultWeight => 2f;

	public override bool RequiresAllClients => true;

	public override void Execute(LuckyEventContext ctx)
	{
		LuckyFx.Broadcast("avatarscale", "1.6,30");
	}
}
public class EvDanceParty : LuckyEvent
{
	public override string Id => "DanceParty";

	public override string Label => "Dance Party — everybody boogie 15s";

	public override LuckyEventCategory Category => LuckyEventCategory.Wacky;

	public override float DefaultWeight => 2.5f;

	public override bool RequiresAllClients => true;

	public override void Execute(LuckyEventContext ctx)
	{
		LuckyFx.Broadcast("danceparty", "15");
	}
}
public enum LuckyEventCategory
{
	Lucky,
	Unlucky,
	Chaotic,
	Wacky
}
public class LuckyEventContext
{
	public PlayerAvatar Opener;

	public Vector3 BlockPos;
}
public abstract class LuckyEvent
{
	internal ConfigEntry<bool> ConfigEnabled;

	internal ConfigEntry<float> ConfigWeight;

	public abstract string Id { get; }

	public abstract string Label { get; }

	public abstract LuckyEventCategory Category { get; }

	public abstract float DefaultWeight { get; }

	public virtual bool RequiresAllClients => false;

	public bool Enabled
	{
		get
		{
			if (ConfigEnabled != null)
			{
				return ConfigEnabled.Value;
			}
			return true;
		}
	}

	public float Weight
	{
		get
		{
			if (ConfigWeight == null)
			{
				return DefaultWeight;
			}
			return Mathf.Max(0f, ConfigWeight.Value);
		}
	}

	public virtual bool CanRun(LuckyEventContext ctx)
	{
		return true;
	}

	public abstract void Execute(LuckyEventContext ctx);
}
public static class LuckyEventLog
{
	internal static ConfigEntry<bool> ConfigEnabled;

	internal static ConfigEntry<int> ConfigMaxEntries;

	internal static ConfigEntry<float> ConfigDuration;

	public static bool Enabled
	{
		get
		{
			if (ConfigEnabled != null)
			{
				return ConfigEnabled.Value;
			}
			return true;
		}
	}

	public static int MaxEntries
	{
		get
		{
			if (ConfigMaxEntries == null)
			{
				return 3;
			}
			return Mathf.Max(1, ConfigMaxEntries.Value);
		}
	}

	public static float Duration
	{
		get
		{
			if (ConfigDuration == null)
			{
				return 60f;
			}
			return Mathf.Max(1f, ConfigDuration.Value);
		}
	}

	public static void BindConfig(ConfigFile config)
	{
		ConfigEnabled = config.Bind<bool>("EventLog", "Enabled", true, "Show the recent-events log in the F6 debug window.");
		ConfigMaxEntries = config.Bind<int>("EventLog", "MaxEntries", 3, "How many recent events to show at most.");
		ConfigDuration = config.Bind<float>("EventLog", "DurationSeconds", 60f, "Events older than this disappear from the log — except the newest one, which stays visible permanently.");
	}

	public static List<RandomEventRoller.EventLogEntry> GetVisible()
	{
		List<RandomEventRoller.EventLogEntry> list = new List<RandomEventRoller.EventLogEntry>();
		List<RandomEventRoller.EventLogEntry> eventLog = RandomEventRoller.EventLog;
		if (eventLog.Count == 0)
		{
			return list;
		}
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		foreach (RandomEventRoller.EventLogEntry item in eventLog)
		{
			if (list.Count >= MaxEntries)
			{
				break;
			}
			if (realtimeSinceStartup - item.TimeLogged <= Duration)
			{
				list.Add(item);
			}
		}
		if (list.Count == 0)
		{
			list.Add(eventLog[0]);
		}
		return list;
	}
}
public static class LuckyEventRegistry
{
	private static readonly List<LuckyEvent> _events = new List<LuckyEvent>();

	private static bool _built;

	public static IReadOnlyList<LuckyEvent> All => _events;

	public static void Build()
	{
		if (_built)
		{
			return;
		}
		_built = true;
		Type[] types = Assembly.GetExecutingAssembly().GetTypes();
		foreach (Type type in types)
		{
			if (!type.IsAbstract && typeof(LuckyEvent).IsAssignableFrom(type))
			{
				try
				{
					_events.Add((LuckyEvent)Activator.CreateInstance(type));
				}
				catch (Exception ex)
				{
					Debug.LogError((object)("[LuckyBlock] Failed to create event '" + type.Name + "': " + ex.Message));
				}
			}
		}
		_events.Sort(delegate(LuckyEvent a, LuckyEvent b)
		{
			int num = a.Category.CompareTo(b.Category);
			return (num == 0) ? string.CompareOrdinal(a.Id, b.Id) : num;
		});
		Debug.Log((object)$"[LuckyBlock] Event registry built: {_events.Count} events.");
	}

	public static void BindConfig(ConfigFile config)
	{
		foreach (LuckyEvent @event in _events)
		{
			string text = $"Events.{@event.Category}";
			@event.ConfigEnabled = config.Bind<bool>(text, @event.Id + ".Enabled", true, "Enable '" + @event.Label + "'.");
			@event.ConfigWeight = config.Bind<float>(text, @event.Id + ".Weight", @event.DefaultWeight, "Roll weight for '" + @event.Label + "' (0 disables it). Higher = more frequent.");
		}
	}

	public static void Roll(LuckyEventContext ctx)
	{
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		if (!SemiFunc.IsMasterClientOrSingleplayer())
		{
			return;
		}
		List<LuckyEvent> list = new List<LuckyEvent>();
		float num = 0f;
		foreach (LuckyEvent @event in _events)
		{
			if (IsEligible(@event, ctx))
			{
				list.Add(@event);
				num += @event.Weight;
			}
		}
		if (list.Count == 0 || num <= 0f)
		{
			Debug.LogWarning((object)"[LuckyBlock] Roll: no eligible events — falling back to a valuable.");
			SpawnUtils.SpawnRandomValuable(SpawnUtils.GetSpawnPositionInFront(ctx.Opener, 2.5f));
			return;
		}
		float num2 = Random.value * num;
		float num3 = 0f;
		LuckyEvent ev = list[list.Count - 1];
		foreach (LuckyEvent item in list)
		{
			num3 += item.Weight;
			if (num2 < num3)
			{
				ev = item;
				break;
			}
		}
		Fire(ev, ctx);
	}

	public static void Fire(LuckyEvent ev, LuckyEventContext ctx)
	{
		try
		{
			ev.Execute(ctx);
			EventHelpers.Announce($"[{ev.Category}] {ev.Label}");
		}
		catch (Exception arg)
		{
			Debug.LogError((object)$"[LuckyBlock] Event '{ev.Id}' failed: {arg}");
		}
	}

	private static bool IsEligible(LuckyEvent ev, LuckyEventContext ctx)
	{
		if (!ev.Enabled || ev.Weight <= 0f)
		{
			return false;
		}
		if (ev.RequiresAllClients && SemiFunc.IsMultiplayer() && !ModeManager.IsPrivate)
		{
			return false;
		}
		try
		{
			return ev.CanRun(ctx);
		}
		catch
		{
			return false;
		}
	}
}
public static class LuckyFx
{
	public const string ANNOUNCE = "announce";

	public const string BLACKOUT = "blackout";

	public const string LOW_GRAVITY = "lowgrav";

	public const string SHAKE = "shake";

	public const string RAVE = "rave";

	public const string FALSE_ALARM = "falsealarm";

	public const string BUTTERFINGERS = "butterfingers";

	public const string AVATAR_SCALE = "avatarscale";

	public const string DANCE_PARTY = "danceparty";

	public const string TELEPORT = "teleport";

	private static bool _blackoutActive;

	private static bool _lowGravActive;

	private static bool _raveActive;

	private static bool _scaleActive;

	public static void Broadcast(string id, string args)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		string text = ((args != null && args.Length > 0) ? (id + "|" + args) : id);
		Run(text);
		if (SemiFunc.IsMultiplayer() && ModeManager.IsPrivate && LuckyBlockPlugin.FxEvent != null)
		{
			LuckyBlockPlugin.FxEvent.RaiseEvent((object)text, NetworkingEvents.RaiseOthers, SendOptions.SendReliable);
		}
	}

	public static void Run(string payload)
	{
		if (string.IsNullOrEmpty(payload))
		{
			return;
		}
		int num = payload.IndexOf('|');
		string text = ((num >= 0) ? payload.Substring(0, num) : payload);
		string text2 = ((num >= 0) ? payload.Substring(num + 1) : "");
		try
		{
			switch (text)
			{
			case "announce":
				RandomEventRoller.LogEvent(text2, "[LuckyBlock]");
				break;
			case "blackout":
				Start(Blackout(ParseF(text2, 0, 30f)));
				break;
			case "lowgrav":
				Start(LowGravity(ParseF(text2, 0, 20f)));
				break;
			case "shake":
				Start(Shake(ParseF(text2, 0, 6f), ParseF(text2, 1, 1.5f)));
				break;
			case "rave":
				Start(Rave(ParseF(text2, 0, 20f)));
				break;
			case "falsealarm":
				FalseAlarm();
				break;
			case "butterfingers":
				EventHelpers.ReleaseLocalGrab();
				break;
			case "avatarscale":
				Start(AvatarScale(ParseF(text2, 0, 0.5f), ParseF(text2, 1, 30f)));
				break;
			case "danceparty":
				DanceParty(ParseF(text2, 0, 15f));
				break;
			case "teleport":
				TeleportSelf(text2);
				break;
			default:
				Debug.LogWarning((object)("[LuckyBlock] Unknown FX id '" + text + "'."));
				break;
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[LuckyBlock] FX '" + text + "' failed: " + ex.Message));
		}
	}

	private static void Start(IEnumerator routine)
	{
		LuckyBlockPlugin.StartManagedCoroutine(routine);
	}

	private static float ParseF(string args, int index, float fallback)
	{
		if (string.IsNullOrEmpty(args))
		{
			return fallback;
		}
		string[] array = args.Split(',');
		if (index >= array.Length)
		{
			return fallback;
		}
		if (!float.TryParse(array[index], NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
		{
			return fallback;
		}
		return result;
	}

	private static IEnumerator Blackout(float duration)
	{
		if (_blackoutActive)
		{
			yield break;
		}
		_blackoutActive = true;
		List<KeyValuePair<Light, float>> dimmed = new List<KeyValuePair<Light, float>>();
		Light[] array = Object.FindObjectsOfType<Light>();
		foreach (Light val in array)
		{
			if (!((Object)(object)val == (Object)null) && !(val.intensity <= 0.01f))
			{
				dimmed.Add(new KeyValuePair<Light, float>(val, val.intensity));
				val.intensity = 0.02f;
			}
		}
		Color ambient = RenderSettings.ambientLight;
		RenderSettings.ambientLight = Color.black;
		yield return (object)new WaitForSeconds(duration);
		foreach (KeyValuePair<Light, float> item in dimmed)
		{
			if ((Object)(object)item.Key != (Object)null)
			{
				item.Key.intensity = item.Value;
			}
		}
		RenderSettings.ambientLight = ambient;
		_blackoutActive = false;
	}

	private static IEnumerator LowGravity(float duration)
	{
		if (!_lowGravActive)
		{
			_lowGravActive = true;
			Vector3 original = Physics.gravity;
			Physics.gravity = original * 0.25f;
			yield return (object)new WaitForSeconds(duration);
			Physics.gravity = original;
			_lowGravActive = false;
		}
	}

	private static IEnumerator Shake(float duration, float strength)
	{
		CameraShake shaker = Object.FindObjectOfType<CameraShake>();
		float elapsed = 0f;
		while (elapsed < duration)
		{
			if ((Object)(object)shaker != (Object)null)
			{
				shaker.Shake(strength, 0.3f);
			}
			elapsed += 0.25f;
			yield return (object)new WaitForSeconds(0.25f);
		}
	}

	private static IEnumerator Rave(float duration)
	{
		if (!_raveActive)
		{
			_raveActive = true;
			Color original = RenderSettings.ambientLight;
			float elapsed = 0f;
			while (elapsed < duration)
			{
				RenderSettings.ambientLight = Color.HSVToRGB(Mathf.Repeat(elapsed * 0.5f, 1f), 0.9f, 0.8f);
				elapsed += Time.deltaTime;
				yield return null;
			}
			RenderSettings.ambientLight = original;
			_raveActive = false;
		}
	}

	private static void FalseAlarm()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		ChatManager instance = ChatManager.instance;
		if (!((Object)(object)instance == (Object)null))
		{
			instance.PossessChatScheduleStart(9);
			instance.PossessChat((PossessChatID)0, "something is coming . . .", 0.06f, new Color(0.9f, 0.1f, 0.1f), 0f, false, 0, (UnityEvent)null);
			instance.PossessChat((PossessChatID)0, "nevermind. probably nothing", 0.05f, new Color(0.6f, 0.6f, 0.6f), 3f, false, 0, (UnityEvent)null);
			instance.PossessChatScheduleEnd();
		}
	}

	private static IEnumerator AvatarScale(float scale, float duration)
	{
		if (_scaleActive)
		{
			yield break;
		}
		_scaleActive = true;
		List<KeyValuePair<Transform, Vector3>> scaled = new List<KeyValuePair<Transform, Vector3>>();
		foreach (PlayerAvatar allPlayer in EventHelpers.GetAllPlayers())
		{
			if (!((Object)(object)allPlayer == (Object)null) && !((Object)(object)allPlayer.playerAvatarVisuals == (Object)null))
			{
				Transform transform = ((Component)allPlayer.playerAvatarVisuals).transform;
				scaled.Add(new KeyValuePair<Transform, Vector3>(transform, transform.localScale));
				transform.localScale *= scale;
			}
		}
		yield return (object)new WaitForSeconds(duration);
		foreach (KeyValuePair<Transform, Vector3> item in scaled)
		{
			if ((Object)(object)item.Key != (Object)null)
			{
				item.Key.localScale = item.Value;
			}
		}
		_scaleActive = false;
	}

	private static void TeleportSelf(string args)
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		PlayerAvatar instance = PlayerAvatar.instance;
		if (!((Object)(object)instance == (Object)null))
		{
			PhotonView component = ((Component)instance).GetComponent<PhotonView>();
			if (!((Object)(object)component == (Object)null) && (int)ParseF(args, 0, -1f) == component.ViewID)
			{
				EventHelpers.TeleportLocalController(new Vector3(ParseF(args, 1, 0f), ParseF(args, 2, 0f), ParseF(args, 3, 0f)));
			}
		}
	}

	private static void DanceParty(float duration)
	{
		MonoBehaviour instance = (MonoBehaviour)(object)LuckyBlockPlugin.Instance;
		if ((Object)(object)instance == (Object)null)
		{
			return;
		}
		foreach (PlayerAvatar allPlayer in EventHelpers.GetAllPlayers())
		{
			RandomEventRoller.ForceBoomboxDance(allPlayer, duration, instance, "[LuckyBlock]");
		}
	}
}
public class LuckyBlock : MonoBehaviour
{
	private PhysGrabObject _grab;

	private PhysGrabObjectImpactDetector _impact;

	private bool _triggered;

	private void Awake()
	{
		RandomEventRoller.Init();
		_grab = ((Component)this).GetComponent<PhysGrabObject>();
		_impact = ((Component)this).GetComponent<PhysGrabObjectImpactDetector>();
	}

	private void Update()
	{
		if (!_triggered && SemiFunc.IsMasterClientOrSingleplayer() && (Object)(object)_grab != (Object)null && _grab.grabbed)
		{
			Trigger(ResolveGrabber());
		}
	}

	private void Open()
	{
		Trigger(ResolveGrabber());
	}

	private void Trigger(PlayerAvatar grabber)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		if (!_triggered)
		{
			_triggered = true;
			if ((Object)(object)grabber == (Object)null)
			{
				grabber = PlayerAvatar.instance;
			}
			Vector3 position = ((Component)this).transform.position;
			LuckyBlockEvents.Roll(grabber, position);
			if ((Object)(object)_impact != (Object)null)
			{
				_impact.DestroyObject(true);
			}
			else
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}
	}

	private PlayerAvatar ResolveGrabber()
	{
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_grab != (Object)null && _grab.playerGrabbing != null && _grab.playerGrabbing.Count > 0)
		{
			PhysGrabber val = _grab.playerGrabbing[0];
			if ((Object)(object)val != (Object)null && (Object)(object)val.playerAvatar != (Object)null)
			{
				return val.playerAvatar;
			}
		}
		List<PlayerAvatar> list = SemiFunc.PlayerGetAllPlayerAvatarWithinRange(8f, ((Component)this).transform.position, false, default(LayerMask));
		if (list != null && list.Count > 0 && (Object)(object)list[0] != (Object)null)
		{
			return list[0];
		}
		return PlayerAvatar.instance;
	}
}
public static class LuckyBlockEvents
{
	private static LuckyEventContext MakeContext(PlayerAvatar player, Vector3 blockPos)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)player == (Object)null)
		{
			player = PlayerAvatar.instance;
		}
		if (blockPos == Vector3.zero && (Object)(object)player != (Object)null)
		{
			blockPos = ((Component)player).transform.position;
		}
		return new LuckyEventContext
		{
			Opener = player,
			BlockPos = blockPos
		};
	}

	public static void Roll(PlayerAvatar opener, Vector3 blockPos)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		if (SemiFunc.IsMasterClientOrSingleplayer())
		{
			LuckyEventContext luckyEventContext = MakeContext(opener, blockPos);
			if (!((Object)(object)luckyEventContext.Opener == (Object)null))
			{
				LuckyEventRegistry.Roll(luckyEventContext);
			}
		}
	}

	public static void TriggerSpecific(int eventIdx, PlayerAvatar player, Vector3 blockPos)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		if (!SemiFunc.IsMasterClientOrSingleplayer())
		{
			return;
		}
		LuckyEventContext luckyEventContext = MakeContext(player, blockPos);
		if (!((Object)(object)luckyEventContext.Opener == (Object)null))
		{
			IReadOnlyList<LuckyEvent> all = LuckyEventRegistry.All;
			if (eventIdx >= 0 && eventIdx < all.Count)
			{
				LuckyEventRegistry.Fire(all[eventIdx], luckyEventContext);
			}
			else
			{
				LuckyEventRegistry.Roll(luckyEventContext);
			}
		}
	}
}
public class LuckyBlockItem : MonoBehaviour
{
	private bool _isLucky;

	internal bool _consumed;

	private bool _activatedLocal;

	private PhysGrabObject _grab;

	private PhotonView _view;

	internal bool IsLucky => _isLucky;

	private void Awake()
	{
		RandomEventRoller.Init();
		_grab = ((Component)this).GetComponent<PhysGrabObject>() ?? ((Component)this).GetComponentInParent<PhysGrabObject>();
		_view = ((Component)this).GetComponent<PhotonView>() ?? ((Component)this).GetComponentInParent<PhotonView>();
	}

	private void Update()
	{
		if (_isLucky && !_activatedLocal && !((Object)(object)_grab == (Object)null) && ModeManager.IsPrivate && _grab.grabbedLocal && SemiFunc.InputDown((InputKey)2))
		{
			Activate();
		}
	}

	internal void SetLucky()
	{
		MakeLucky();
		if (SemiFunc.IsMultiplayer() && (Object)(object)_view != (Object)null && _view.ViewID != 0)
		{
			_view.RPC("SetLuckyRPC", (RpcTarget)4, Array.Empty<object>());
		}
	}

	[PunRPC]
	private void SetLuckyRPC()
	{
		MakeLucky();
	}

	private void MakeLucky()
	{
		_isLucky = true;
		LuckyBlockSkin.Apply(((Component)this).gameObject, 1f / 6f);
	}

	private void Open()
	{
		Activate();
	}

	private void Activate()
	{
		if (!_activatedLocal)
		{
			_activatedLocal = true;
			int num = SemiFunc.PhotonViewIDPlayerAvatarLocal();
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				ActivateOnHost(((Component)this).gameObject, num);
			}
			else if ((Object)(object)_view != (Object)null && _view.ViewID != 0)
			{
				_view.RPC("ActivateRPC", (RpcTarget)2, new object[1] { num });
			}
		}
	}

	[PunRPC]
	private void ActivateRPC(int playerViewID)
	{
		ActivateOnHost(((Component)this).gameObject, playerViewID);
	}

	internal static void ActivateOnHost(GameObject item, int playerViewID)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)item == (Object)null || !SemiFunc.IsMasterClientOrSingleplayer())
		{
			return;
		}
		LuckyBlockItem component = item.GetComponent<LuckyBlockItem>();
		if ((Object)(object)component != (Object)null)
		{
			if (component._consumed)
			{
				return;
			}
			component._consumed = true;
		}
		PlayerAvatar opener = ResolvePlayer(playerViewID);
		Vector3 position = item.transform.position;
		LuckyBlockEvents.Roll(opener, position);
		if (SemiFunc.IsMultiplayer())
		{
			PhotonNetwork.Destroy(item);
		}
		else
		{
			Object.Destroy((Object)(object)item);
		}
	}

	private static PlayerAvatar ResolvePlayer(int viewID)
	{
		if (viewID > 0)
		{
			PhotonView val = PhotonView.Find(viewID);
			PlayerAvatar val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<PlayerAvatar>() : null);
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
		}
		return PlayerAvatar.instance;
	}
}
[HarmonyPatch(typeof(ItemAttributes), "Awake")]
internal static class LuckyBlockItem_AttachPatch
{
	private static void Postfix(ItemAttributes __instance)
	{
		if (!((Object)(object)__instance == (Object)null))
		{
			string text = (((Object)(object)__instance.item != (Object)null) ? __instance.item.itemName : null);
			string value = "Drone Battery";
			if (((text != null && text.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0) || ((Object)((Component)__instance).gameObject).name.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0) && (Object)(object)((Component)__instance).GetComponent<LuckyBlockItem>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<LuckyBlockItem>();
			}
		}
	}
}
[HarmonyPatch(typeof(ItemAttributes), "GetItemNameLocalized")]
internal static class LuckyBlockItem_NamePatch
{
	private static void Postfix(ItemAttributes __instance, ref string __result)
	{
		LuckyBlockItem luckyBlockItem = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponent<LuckyBlockItem>() : null);
		if ((Object)(object)luckyBlockItem != (Object)null && luckyBlockItem.IsLucky)
		{
			__result = "Lucky Block";
		}
	}
}
public class LuckyBlockManager : MonoBehaviour
{
	public static LuckyBlockManager Instance { get; private set; }

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
	}

	internal List<GameObject> SpawnBlocks(List<Vector3> positions)
	{
		List<GameObject> list = new List<GameObject>();
		if (positions == null || positions.Count == 0)
		{
			return list;
		}
		if (SemiFunc.IsMultiplayer() && !SemiFunc.IsMasterClientOrSingleplayer())
		{
			Debug.LogWarning((object)"[LuckyBlock] Only the host can spawn lucky blocks.");
			return list;
		}
		if (!ModeManager.IsPrivate)
		{
			return SpawnPublic(positions, list);
		}
		return SpawnPrivate(positions, list);
	}

	private List<GameObject> SpawnPrivate(List<Vector3> positions, List<GameObject> spawned)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)SpawnUtils.GetLuckyItem() == (Object)null)
		{
			Debug.LogError((object)"[LuckyBlock] PRIVATE mode: base item 'Drone Battery' not found. Switch back to Public mode (F6 menu).");
			return spawned;
		}
		foreach (Vector3 position in positions)
		{
			GameObject val = SpawnUtils.SpawnLuckyItem(position);
			if (!((Object)(object)val == (Object)null))
			{
				LuckyBlockItem componentInChildren = val.GetComponentInChildren<LuckyBlockItem>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.SetLucky();
				}
				else
				{
					Debug.LogError((object)"[LuckyBlock] spawned item has no LuckyBlockItem component.");
				}
				spawned.Add(val);
				Debug.Log((object)$"[LuckyBlock] Lucky ITEM spawned at {position:F1} (private edition).");
			}
		}
		return spawned;
	}

	private List<GameObject> SpawnPublic(List<Vector3> positions, List<GameObject> spawned)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		foreach (Vector3 position in positions)
		{
			GameObject val = SpawnUtils.SpawnLuckyValuable(position);
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)$"[LuckyBlock] Failed to spawn lucky valuable at {position:F1}.");
				continue;
			}
			if ((Object)(object)val.GetComponent<LuckyBlock>() == (Object)null)
			{
				val.AddComponent<LuckyBlock>();
			}
			LuckyBlockSkin.Apply(val);
			if (SemiFunc.IsMultiplayer())
			{
				PhotonView component = val.GetComponent<PhotonView>();
				if ((Object)(object)component != (Object)null && component.ViewID != 0 && LuckyBlockPlugin.SkinEvent != null)
				{
					LuckyBlockPlugin.SkinEvent.RaiseEvent((object)component.ViewID, NetworkingEvents.RaiseOthers, SendOptions.SendReliable);
				}
			}
			spawned.Add(val);
			Debug.Log((object)$"[LuckyBlock] Lucky six-pack spawned at {position:F1}.");
		}
		return spawned;
	}

	internal void ClearBlocks()
	{
	}
}
public enum LuckyBlockMode
{
	PublicServer,
	PrivateServer
}
public static class ModeManager
{
	internal static ConfigEntry<LuckyBlockMode> EditionConfig;

	public static LuckyBlockMode CurrentEdition
	{
		get
		{
			if (EditionConfig == null)
			{
				return LuckyBlockMode.PublicServer;
			}
			return EditionConfig.Value;
		}
	}

	public static bool IsPrivate => CurrentEdition == LuckyBlockMode.PrivateServer;

	public static void SetEdition(LuckyBlockMode mode)
	{
		if (EditionConfig != null)
		{
			EditionConfig.Value = mode;
		}
	}
}
[BepInPlugin("com.tonnom.luckyblock", "REPO_lucky_block", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class LuckyBlockPlugin : BaseUnityPlugin
{
	private static MonoBehaviour _coroutineHost;

	private Harmony _harmony;

	public static LuckyBlockPlugin Instance { get; private set; }

	internal static NetworkedEvent SkinEvent { get; private set; }

	internal static NetworkedEvent FxEvent { get; private set; }

	private void Awake()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Expected O, but got Unknown
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Expected O, but got Unknown
		Instance = this;
		_coroutineHost = (MonoBehaviour)(object)this;
		((Component)this).gameObject.AddComponent<LuckyBlockManager>();
		_harmony = new Harmony("com.tonnom.luckyblock");
		_harmony.PatchAll();
		SkinEvent = new NetworkedEvent("LuckyBlock Skin", (Action<EventData>)OnSkinEvent);
		FxEvent = new NetworkedEvent("LuckyBlock FX", (Action<EventData>)OnFxEvent);
		ModeManager.EditionConfig = ((BaseUnityPlugin)this).Config.Bind<LuckyBlockMode>("General", "Edition", LuckyBlockMode.PublicServer, "PublicServer = host-only, no client install needed (lucky block is a valuable, grab it). PrivateServer = everyone must install the mod (lucky block is a custom item, press E).");
		LuckyEventRegistry.Build();
		LuckyEventRegistry.BindConfig(((BaseUnityPlugin)this).Config);
		LuckyEventLog.BindConfig(((BaseUnityPlugin)this).Config);
		SceneManager.sceneLoaded += OnSceneLoaded;
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"[LuckyBlock] Plugin loaded — Manager alive: {(Object)(object)LuckyBlockManager.Instance != (Object)null}. F6 for debug menu.");
	}

	private static void OnSkinEvent(EventData e)
	{
		if (((e != null) ? e.CustomData : null) is int viewID)
		{
			StartManagedCoroutine(SkinWhenReady(viewID));
		}
	}

	private static IEnumerator SkinWhenReady(int viewID)
	{
		for (int i = 0; i < 120; i++)
		{
			PhotonView val = PhotonView.Find(viewID);
			if ((Object)(object)val != (Object)null)
			{
				LuckyBlockSkin.Apply(((Component)val).gameObject);
				break;
			}
			yield return null;
		}
	}

	private static void OnFxEvent(EventData e)
	{
		if (((e != null) ? e.CustomData : null) is string payload)
		{
			LuckyFx.Run(payload);
		}
	}

	internal static void StartManagedCoroutine(IEnumerator routine)
	{
		if ((Object)(object)_coroutineHost != (Object)null)
		{
			_coroutineHost.StartCoroutine(routine);
		}
		else
		{
			Debug.LogWarning((object)"[LuckyBlock] CoroutineHost missing — coroutine dropped.");
		}
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected O, but got Unknown
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Expected O, but got Unknown
		LuckyBlockManager.Instance?.ClearBlocks();
		if ((Object)(object)Object.FindObjectOfType<LuckyBlockStatusPanel>() == (Object)null)
		{
			GameObject val = new GameObject("LuckyBlock_StatusPanel");
			val.AddComponent<LuckyBlockStatusPanel>();
			Object.DontDestroyOnLoad((Object)val);
		}
		if ((Object)(object)Object.FindObjectOfType<DebugMenu>() == (Object)null)
		{
			GameObject val2 = new GameObject("LuckyBlock_DebugMenu");
			val2.AddComponent<DebugMenu>();
			Object.DontDestroyOnLoad((Object)val2);
		}
		LuckyBlockSpawner.ResetSpawnFlag();
		StartManagedCoroutine(BackupSpawnCoroutine());
	}

	private static IEnumerator BackupSpawnCoroutine()
	{
		yield return (object)new WaitForSeconds(1f);
		if ((Object)(object)RunManager.instance == (Object)null || !SemiFunc.RunIsLevel() || !SemiFunc.IsMasterClientOrSingleplayer())
		{
			yield break;
		}
		for (float waited = 0f; waited < 15f; waited += 0.5f)
		{
			if ((Object)(object)LevelGenerator.Instance != (Object)null && LevelGenerator.Instance.Generated)
			{
				break;
			}
			yield return (object)new WaitForSeconds(0.5f);
		}
		if (!((Object)(object)LevelGenerator.Instance == (Object)null) && LevelGenerator.Instance.Generated && SemiFunc.RunIsLevel())
		{
			LuckyBlockSpawner.SpawnForCurrentLevel("BackupCoroutine");
		}
	}
}
public class CoroutineHost : MonoBehaviour
{
}
internal static class LuckyBlockSkin
{
	private const string SKIN_NAME = "LuckyBlockSkin";

	private static Texture2D _tex;

	private static Material _mat;

	private static Mesh _cubeMesh;

	internal static void Apply(GameObject valuable, float scale = 1f)
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)valuable == (Object)null || (Object)(object)valuable.transform.Find("LuckyBlockSkin") != (Object)null)
		{
			return;
		}
		Material material = GetMaterial();
		Mesh cubeMesh = GetCubeMesh();
		if (!((Object)(object)material == (Object)null) && !((Object)(object)cubeMesh == (Object)null))
		{
			Bounds val = ComputeBounds(valuable);
			float num = Mathf.Max(new float[3]
			{
				((Bounds)(ref val)).size.x,
				((Bounds)(ref val)).size.y,
				((Bounds)(ref val)).size.z
			}) * 1.05f;
			if (num <= 0.001f)
			{
				num = 0.5f;
			}
			num = Mathf.Clamp(num, 0.2f, 1f) * scale;
			GameObject val2 = new GameObject("LuckyBlockSkin");
			val2.transform.SetParent(valuable.transform, false);
			val2.transform.localRotation = Quaternion.identity;
			val2.transform.position = ((Bounds)(ref val)).center;
			Vector3 lossyScale = valuable.transform.lossyScale;
			val2.transform.localScale = new Vector3(num / Mathf.Max(0.0001f, lossyScale.x), num / Mathf.Max(0.0001f, lossyScale.y), num / Mathf.Max(0.0001f, lossyScale.z));
			val2.AddComponent<MeshFilter>().sharedMesh = cubeMesh;
			((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterial = material;
		}
	}

	private static Bounds ComputeBounds(GameObject go)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		Bounds result = default(Bounds);
		bool flag = false;
		Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>();
		foreach (Renderer val in componentsInChildren)
		{
			if (!((Object)(object)val == (Object)null) && !(((Object)((Component)val).gameObject).name == "LuckyBlockSkin") && (val is MeshRenderer || val is SkinnedMeshRenderer))
			{
				if (!flag)
				{
					result = val.bounds;
					flag = true;
				}
				else
				{
					((Bounds)(ref result)).Encapsulate(val.bounds);
				}
			}
		}
		if (!flag)
		{
			((Bounds)(ref result))..ctor(go.transform.position, Vector3.one * 0.5f);
		}
		return result;
	}

	private static Mesh GetCubeMesh()
	{
		if ((Object)(object)_cubeMesh != (Object)null)
		{
			return _cubeMesh;
		}
		GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3);
		_cubeMesh = obj.GetComponent<MeshFilter>().sharedMesh;
		Object.Destroy((Object)(object)obj);
		return _cubeMesh;
	}

	private static Material GetMaterial()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_mat != (Object)null)
		{
			return _mat;
		}
		Texture2D texture = GetTexture();
		Shader val = Shader.Find("Standard");
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		_mat = new Material(val)
		{
			name = "LuckyBlockMat",
			mainTexture = (Texture)(object)texture
		};
		_mat.SetFloat("_Glossiness", 0.1f);
		_mat.SetFloat("_Metallic", 0f);
		_mat.EnableKeyword("_EMISSION");
		_mat.SetColor("_EmissionColor", new Color(0.3f, 0.24f, 0f));
		if ((Object)(object)texture != (Object)null)
		{
			_mat.SetTexture("_EmissionMap", (Texture)(object)texture);
		}
		return _mat;
	}

	private static Texture2D GetTexture()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		if ((Object)(object)_tex != (Object)null)
		{
			return _tex;
		}
		_tex = new Texture2D(2, 2, (TextureFormat)4, false);
		string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)LuckyBlockPlugin.Instance).Info.Location), "lucky_block.png");
		if (File.Exists(text))
		{
			ImageConversion.LoadImage(_tex, File.ReadAllBytes(text));
			((Texture)_tex).filterMode = (FilterMode)0;
			((Texture)_tex).wrapMode = (TextureWrapMode)1;
			_tex.Apply();
		}
		else
		{
			Debug.LogError((object)("[LuckyBlock] Skin texture not found at '" + text + "'. Block will be untextured."));
		}
		return _tex;
	}
}
[HarmonyPatch(typeof(SemiFunc), "OnLevelGenDone")]
internal static class OnLevelGenDone_Patch
{
	private static void Postfix()
	{
		try
		{
			if (!((Object)(object)RunManager.instance == (Object)null) && SemiFunc.RunIsLevel() && SemiFunc.IsMasterClientOrSingleplayer())
			{
				LuckyBlockSpawner.SpawnForCurrentLevel("OnLevelGenDone");
			}
		}
		catch (Exception arg)
		{
			Debug.LogError((object)$"[LuckyBlock] Spawn postfix failed (ignored): {arg}");
		}
	}
}
internal static class LuckyBlockSpawner
{
	private const float MIN_BLOCK_SPACING = 4f;

	private static bool _spawnedThisLoad;

	internal static void ResetSpawnFlag()
	{
		_spawnedThisLoad = false;
	}

	internal static void SpawnForCurrentLevel(string caller = "?")
	{
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: 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_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: 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_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		if (_spawnedThisLoad)
		{
			Debug.Log((object)("[LuckyBlock] SpawnForCurrentLevel(" + caller + "): already spawned — skip."));
			return;
		}
		if ((Object)(object)LuckyBlockManager.Instance == (Object)null)
		{
			Debug.LogError((object)"[LuckyBlock] LuckyBlockManager.Instance is null — cannot spawn.");
			return;
		}
		_spawnedThisLoad = true;
		int currentLevel = GetCurrentLevel();
		int blockCount = GetBlockCount(currentLevel);
		Debug.Log((object)$"[LuckyBlock] Spawning {blockCount} block(s) for level {currentLevel} (caller: {caller}).");
		List<LevelPoint> list = new List<LevelPoint>();
		if ((Object)(object)LevelGenerator.Instance != (Object)null)
		{
			foreach (LevelPoint levelPathPoint in LevelGenerator.Instance.LevelPathPoints)
			{
				if ((Object)(object)levelPathPoint != (Object)null && !levelPathPoint.Truck && (Object)(object)((Component)levelPathPoint).GetComponentInParent<StartRoom>() == (Object