Decompiled source of GlowStickOnBody Restored v1.2.1

BepInEx/plugins/GlowStickOnBodyRestored/GlowStickOnBodyRestored.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AK;
using Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GameData;
using HarmonyLib;
using Player;
using TargetTransforms;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("GlowStickOnBodyRestored")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1")]
[assembly: AssemblyProduct("GlowStickOnBodyRestored")]
[assembly: AssemblyTitle("GlowStickOnBodyRestored")]
[assembly: AssemblyVersion("1.2.1.0")]
namespace GlowStickOnBodyRestored;

internal readonly struct PaletteColor
{
	public readonly float R;

	public readonly float G;

	public readonly float B;

	public readonly float A;

	public PaletteColor(float r, float g, float b, float a)
	{
		R = r;
		G = g;
		B = b;
		A = a;
	}

	public PaletteColor LightColor()
	{
		return new PaletteColor(R * A, G * A, B * A, A);
	}
}
internal static class PaletteParser
{
	public static bool TryParse(string text, out PaletteColor[] colors)
	{
		colors = null;
		if (string.IsNullOrWhiteSpace(text))
		{
			return false;
		}
		string[] array = text.Split('|');
		PaletteColor[] array2 = new PaletteColor[array.Length];
		for (int i = 0; i < array.Length; i++)
		{
			string text2 = array[i].Trim();
			if (text2.StartsWith("#", StringComparison.Ordinal))
			{
				text2 = text2.Substring(1);
			}
			if ((text2.Length != 6 && text2.Length != 8) || !uint.TryParse(text2, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out var result))
			{
				return false;
			}
			if (text2.Length == 6)
			{
				result = (result << 8) | 0xFF;
			}
			array2[i] = new PaletteColor((float)((result >> 24) & 0xFF) / 255f, (float)((result >> 16) & 0xFF) / 255f, (float)((result >> 8) & 0xFF) / 255f, (float)(result & 0xFF) / 255f);
		}
		colors = array2;
		return true;
	}
}
internal sealed class PaletteCycle
{
	private uint _rng;

	private PaletteColor[] _palette;

	private bool _randomOrder;

	private bool _randomInterval;

	private double _min;

	private double _max;

	private double _remaining;

	private int _index;

	public int Index => _index;

	public double Remaining => _remaining;

	public int SwitchCount { get; private set; }

	public PaletteCycle(uint seed)
	{
		_rng = ((seed == 0) ? 1u : seed);
	}

	public PaletteColor Evaluate(PaletteColor[] palette, bool randomOrder, bool randomInterval, double fixedSeconds, double minSeconds, double maxSeconds, double deltaSeconds)
	{
		if (palette == null || palette.Length == 0)
		{
			throw new ArgumentException("Palette must contain a color", "palette");
		}
		double num = ValidInterval(randomInterval ? minSeconds : fixedSeconds);
		double num2 = (randomInterval ? ValidInterval(maxSeconds) : num);
		if (num2 < num)
		{
			double num3 = num;
			num = num2;
			num2 = num3;
		}
		if (_palette != palette || _randomOrder != randomOrder || _randomInterval != randomInterval || _min != num || _max != num2)
		{
			_palette = palette;
			_randomOrder = randomOrder;
			_randomInterval = randomInterval;
			_min = num;
			_max = num2;
			_index = 0;
			SwitchCount = 0;
			_remaining = NextInterval();
		}
		if (palette.Length == 1)
		{
			return palette[0];
		}
		if (!double.IsFinite(deltaSeconds) || deltaSeconds <= 0.0)
		{
			return palette[_index];
		}
		double num4 = deltaSeconds;
		int num5 = 0;
		while (num4 >= _remaining && num5++ < 1024)
		{
			num4 -= _remaining;
			if (randomOrder)
			{
				int num6 = (int)(NextFloat() * (double)(palette.Length - 1));
				_index = ((num6 >= _index) ? (num6 + 1) : num6);
			}
			else
			{
				_index = (_index + 1) % palette.Length;
			}
			SwitchCount++;
			_remaining = NextInterval();
		}
		if (num4 < _remaining)
		{
			_remaining -= num4;
		}
		return palette[_index];
	}

	private static double ValidInterval(double value)
	{
		if (!double.IsFinite(value))
		{
			return 1.0;
		}
		return Math.Max(0.05, Math.Min(value, 3600.0));
	}

	private double NextInterval()
	{
		if (!_randomInterval)
		{
			return _min;
		}
		return _min + (_max - _min) * NextFloat();
	}

	private double NextFloat()
	{
		_rng = _rng * 1664525 + 1013904223;
		return (double)(_rng >> 8) / 16777216.0;
	}
}
[BepInPlugin("HawChow.GlowStickOnBodyRestored", "GlowStickOnBody Restored", "1.2.1")]
public class EntryPoint : BasePlugin
{
	internal static ManualLogSource Logger;

	public override void Load()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		Logger = ((BasePlugin)this).Log;
		ModConfig.Init(((BasePlugin)this).Config);
		new Harmony("HawChow.GlowStickOnBodyRestored").PatchAll(typeof(EntryPoint).Assembly);
		((BasePlugin)this).Log.LogInfo((object)"[GSOB-Restored] 加载成功,荧光棒随身挂载已就绪");
		((BasePlugin)this).Log.LogInfo((object)("[GSOB-Rainbow] 彩虹变色默认开启(config 可关):" + $"启用={ModConfig.Enabled.Value} 风格={ModConfig.Style.Value}" + $" 周期={ModConfig.PeriodSeconds.Value}s 间隔={ModConfig.RandomIntervalSeconds.Value}s" + $" 材质同步={ModConfig.SyncBodyMaterial.Value} 仅挂身={ModConfig.OnlyMounted.Value}"));
		((BasePlugin)this).Log.LogInfo((object)("[GSOB-Life] 寿命策略:永久发光=" + ModConfig.Permanent.Value + $" 倍率={ModConfig.LifeMultiplier.Value} 仅挂身={ModConfig.PermanentMountedOnly.Value}"));
	}
}
internal static class ModConfig
{
	public const string Section = "彩虹变色";

	public const string LifeSection = "荧光棒寿命";

	public static ConfigEntry<bool> Enabled;

	public static ConfigEntry<string> Style;

	public static ConfigEntry<float> PeriodSeconds;

	public static ConfigEntry<float> RandomIntervalSeconds;

	public static ConfigEntry<bool> SyncBodyMaterial;

	public static ConfigEntry<bool> OnlyMounted;

	public static ConfigEntry<bool> Diag;

	public static ConfigEntry<string> PaletteColors;

	public static ConfigEntry<bool> PaletteRandomOrder;

	public static ConfigEntry<bool> PaletteRandomInterval;

	public static ConfigEntry<float> PaletteFixedSeconds;

	public static ConfigEntry<float> PaletteMinSeconds;

	public static ConfigEntry<float> PaletteMaxSeconds;

	private const string DefaultPalette = "#FF0000FF|#00FF00FF|#0000FFFF";

	private static string _parsedPaletteText;

	private static PaletteColor[] _palette;

	public static ConfigEntry<bool> Permanent;

	public static ConfigEntry<bool> PermanentMountedOnly;

	public static ConfigEntry<float> LifeMultiplier;

	public static bool UseCustomPalette => string.Equals(Style.Value?.Trim(), "自定义色组", StringComparison.OrdinalIgnoreCase);

	public static PaletteColor[] GetPalette()
	{
		string text = PaletteColors.Value ?? "";
		if (_palette != null && _parsedPaletteText == text)
		{
			return _palette;
		}
		_parsedPaletteText = text;
		if (!PaletteParser.TryParse(text, out var colors))
		{
			ManualLogSource logger = EntryPoint.Logger;
			if (logger != null)
			{
				logger.LogWarning((object)"[GSOB-Rainbow] 自定义色组无效,使用默认红绿蓝;格式:#RRGGBBAA|#RRGGBB。");
			}
			PaletteParser.TryParse("#FF0000FF|#00FF00FF|#0000FFFF", out colors);
		}
		_palette = colors;
		return _palette;
	}

	public static void Init(ConfigFile cfg)
	{
		Enabled = cfg.Bind<bool>("彩虹变色", "启用彩虹变色", true, "总开关。开启后荧光棒的颜色会循环变化(默认开启);设为 false 即完全恢复原版颜色。");
		Style = cfg.Bind<string>("彩虹变色", "变色风格", "平滑色相环", "平滑色相环 = 连续彩虹;随机艳色过渡 = 随机鲜艳目标色;自定义色组 = 按用户设置的 RGBA 颜色循环。");
		PeriodSeconds = cfg.Bind<float>("彩虹变色", "色相循环周期(秒)", 3f, "平滑色相环走完整圈彩虹所需秒数(默认 3.0)。数值越小变色越快。");
		RandomIntervalSeconds = cfg.Bind<float>("彩虹变色", "随机换色间隔(秒)", 1f, "随机艳色过渡风格的换色间隔秒数(默认 1.0,与 Rainbow_Scouts 一致)。");
		SyncBodyMaterial = cfg.Bind<bool>("彩虹变色", "棒体材质同步变色", true, "true = 荧光棒本体材质(含自发光)一起变彩;false = 只变光源颜色,模型保持原色。");
		OnlyMounted = cfg.Bind<bool>("彩虹变色", "仅对挂身的荧光棒生效", false, "false(默认)= 所有荧光棒都变彩,含投掷落地与手持;true = 只给挂在身上的荧光棒变彩。");
		Diag = cfg.Bind<bool>("彩虹变色", "输出诊断日志", false, "true = 每秒打印一次当前颜色与命中数量([GSOB-Rainbow] 行),用于排查与会话取证。");
		PaletteColors = cfg.Bind<string>("彩虹变色", "自定义颜色列表", "#FF0000FF|#00FF00FF|#0000FFFF", "将变色风格设为自定义色组后生效。使用 #RRGGBBAA 或 #RRGGBB,颜色之间用 | 分隔;AA 为透明度,00=透明,FF=不透明。可增减颜色。");
		PaletteRandomOrder = cfg.Bind<bool>("彩虹变色", "自定义随机颜色顺序", false, "false 按列表顺序循环;true 随机选择下一种颜色(相邻不重复)。");
		PaletteRandomInterval = cfg.Bind<bool>("彩虹变色", "自定义随机换色间隔", false, "false 使用固定间隔;true 每次从随机最小和最大间隔之间选取秒数。");
		PaletteFixedSeconds = cfg.Bind<float>("彩虹变色", "自定义固定间隔(秒)", 1f, "固定换色间隔,范围 0.05 到 3600 秒。");
		PaletteMinSeconds = cfg.Bind<float>("彩虹变色", "自定义随机最小间隔(秒)", 0.5f, "随机换色的最小间隔,范围 0.05 到 3600 秒。");
		PaletteMaxSeconds = cfg.Bind<float>("彩虹变色", "自定义随机最大间隔(秒)", 2f, "随机换色的最大间隔,范围 0.05 到 3600 秒;若小于最小值则自动交换。");
		Permanent = cfg.Bind<bool>("荧光棒寿命", "荧光棒永久发光", true, "开启后荧光棒不会随时间长灭、也不会消失(默认开启);关闭则回到原版寿命。换新棒时旧棒仍会正常让位淡出。");
		LifeMultiplier = cfg.Bind<float>("荧光棒寿命", "寿命倍率", 1f, "只在「荧光棒永久发光=false」时决定寿命长短:1.0 = 原版,2.0 = 双倍,0.1 = 最短;低于 0.1 会被夹到 0.1。");
		PermanentMountedOnly = cfg.Bind<bool>("荧光棒寿命", "永久发光仅限挂身的荧光棒", false, "false(默认)= 所有荧光棒都永久;true = 只有挂在身上那支永久,投掷到地上的照常熄灭。");
	}

	public static RainbowSettings Snapshot()
	{
		return new RainbowSettings
		{
			Enabled = Enabled.Value,
			Style = RainbowSettings.ParseStyle(Style.Value),
			PeriodSeconds = PeriodSeconds.Value,
			IntervalSeconds = RandomIntervalSeconds.Value,
			OnlyMounted = OnlyMounted.Value
		};
	}
}
internal enum GlowAction
{
	None,
	KeepAlive,
	Revive
}
internal static class GlowLife
{
	public const int StateZero = 0;

	public const int StateFadeIn = 1;

	public const int StateOne = 2;

	public const int StateFadeOut = 3;

	public const int StateDone = 4;

	public const float MinMultiplier = 0.1f;

	public static bool ShouldManage(bool enabled, bool onlyMounted, bool isMounted)
	{
		if (enabled)
		{
			return !onlyMounted || isMounted;
		}
		return false;
	}

	public static bool IsSuperseded(bool exists, bool valid)
	{
		if (exists)
		{
			return !valid;
		}
		return false;
	}

	public static GlowAction Decide(bool manage, bool superseded, int stateValue)
	{
		if (!manage || superseded)
		{
			return GlowAction.None;
		}
		switch (stateValue)
		{
		case 3:
		case 4:
			return GlowAction.Revive;
		case 1:
		case 2:
			return GlowAction.KeepAlive;
		default:
			return GlowAction.None;
		}
	}

	public static float ClampMultiplier(float value)
	{
		if (float.IsNaN(value) || float.IsInfinity(value))
		{
			return 1f;
		}
		if (!(value < 0.1f))
		{
			return value;
		}
		return 0.1f;
	}

	public static float TargetLifeTime(float baseline, float current, float multiplier)
	{
		float num = ((baseline > 0f && !float.IsNaN(baseline) && !float.IsInfinity(baseline)) ? baseline : current);
		if (num <= 0f || float.IsNaN(num) || float.IsInfinity(num))
		{
			return current;
		}
		return num * ClampMultiplier(multiplier);
	}
}
internal static class Patches
{
	[HarmonyPatch(typeof(ThrowingWeapon), "Update")]
	internal static class Patch_OnThrowingWeaponUpdate
	{
		public static void Postfix(ThrowingWeapon __instance)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.m_ready && !__instance.m_inThrowCharge && !__instance.m_inThrowRelease && !__instance.m_hasThrown && ((ItemEquippable)__instance).IsEnabled && !((Object)(object)((Item)__instance).Owner == (Object)null) && !((ItemEquippable)__instance).FireButtonPressed && ((ItemEquippable)__instance).CanWield && InputMapper.GetButtonDown.Invoke((InputAction)7, ((Item)__instance).Owner.InputFilter) && ((GameDataBlockBase<ItemDataBlock>)(object)((Item)__instance).ItemDataBlock).name.Contains("GlowStick"))
			{
				FakeThrow(__instance);
				__instance.m_hasThrown = true;
			}
		}

		private static void FakeThrow(ThrowingWeapon glowstick)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_004b: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			((ItemEquippable)glowstick).Sound.Post(EVENTS.GLOWSTICKBOUNCE, ((Component)glowstick).transform.position);
			PlayerBackpackManager.LocalBackpack.AmmoStorage.UpdateBulletsInPack((AmmoType)5, -1);
			ItemReplicationManager.ThrowItem(new pItemData
			{
				itemID_gearCRC = ((GameDataBlockBase<ItemDataBlock>)(object)((Item)glowstick).ItemDataBlock).persistentID
			}, (delItemCallback)null, (ItemMode)3, ZeroPos, ((Component)glowstick).transform.rotation, ((Item)glowstick).Owner.FPSCamera.CameraRayDir * 0f, ZeroPos, ((Agent)((Item)glowstick).Owner).CourseNode, ((Item)glowstick).Owner);
			glowstick.m_ready = false;
			glowstick.m_waitingForReady = true;
			glowstick.m_gotoReadyTimer = Clock.Time + 0.5f;
			((Item)glowstick).Owner.FPItemHolder.ItemHiddenTrigger = true;
			((Item)glowstick).Owner.Sync.SendThrowStatus((StatusEnum)2, false);
		}
	}

	[HarmonyPatch(typeof(ItemReplicationManager), "OnItemSpawn")]
	internal static class Patch_OnItemSpawn
	{
		public static void Postfix(ItemReplicationManager __instance, pItemSpawnData spawnData, ItemReplicator replicator)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_002f: 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)
			if (((Object)((Component)replicator.Item).gameObject).name.Contains("Consumable_GlowStick_Instance") && spawnData.position.x == 0f && spawnData.position.y == -2000f && spawnData.position.z == 0f)
			{
				StickManager.SetParent(replicator.Item);
			}
		}
	}

	[HarmonyPatch(typeof(GlowstickInstance), "Update")]
	internal static class Patch_Update
	{
		public static void Postfix(GlowstickInstance __instance)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Invalid comparison between Unknown and I4
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Invalid comparison between Unknown and I4
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected I4, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			int instanceID = ((Object)((Component)((Component)__instance).transform).gameObject).GetInstanceID();
			if (!StickManager.IsLocalStick.ContainsKey(instanceID))
			{
				return;
			}
			PlayerAgent owner = ((Item)__instance).Owner;
			GameObject gameObject = ((Component)((Component)__instance).transform).gameObject;
			if ((int)__instance.m_state == 1 && __instance.m_progression == 0f)
			{
				__instance.s_lightLifeTime *= 0.5f;
				((LightBase)__instance.m_light).Range = __instance.s_lightRange * (StickManager.IsLocalStick[instanceID] ? 4f : 2f);
			}
			if (!StickManager.IsValidStick[instanceID] && (int)__instance.m_state == 2)
			{
				__instance.m_progression = 1f;
				__instance.m_progressionSpeed = 1f / 3f;
				__instance.m_state = (eFadeState)3;
			}
			if ((int)__instance.m_state == 4)
			{
				bool value;
				bool superseded = GlowLife.IsSuperseded(StickManager.IsValidStick.TryGetValue(instanceID, out value), value);
				if (GlowLife.Decide(GlowLife.ShouldManage(ModConfig.Permanent.Value, ModConfig.PermanentMountedOnly.Value, StickManager.IsLocalStick[instanceID]), superseded, (int)__instance.m_state) != GlowAction.Revive)
				{
					gameObject.transform.parent = null;
					((Component)__instance.m_light).transform.position = ZeroPos;
					gameObject.transform.localPosition = ZeroPos;
					return;
				}
				__instance.m_state = (eFadeState)2;
				__instance.m_progression = 1f;
			}
			if (StickManager.IsLocalStick[instanceID] && ((Agent)owner).IsLocallyOwned)
			{
				Vector3 position = owner.FPSCamera.Position;
				position.y -= 0.8f;
				Vector3 val = position;
				Vector3 val2 = ((LookCameraController)owner.FPSCamera).FlatForward;
				position = val + ((Vector3)(ref val2)).normalized * -0.3f;
				Vector3 val3 = position;
				val2 = ((LookCameraController)owner.FPSCamera).FlatRight;
				position = val3 + ((Vector3)(ref val2)).normalized * 0.4f;
				if (position.y < ((Agent)owner).Position.y + 0.2f)
				{
					position.y = ((Agent)owner).Position.y + 0.2f;
				}
				((Component)__instance.m_light).transform.position = position;
			}
		}
	}

	[HarmonyPatch(typeof(GlowstickInstance), "OnDespawn")]
	internal static class Patch_OnDespawn
	{
		public static void Postfix(GlowstickInstance __instance)
		{
			int instanceID = ((Object)((Component)((Component)__instance).transform).gameObject).GetInstanceID();
			if (StickManager.IsLocalStick.ContainsKey(instanceID))
			{
				StickManager.IsLocalStick.Remove(instanceID);
				StickManager.IsValidStick.Remove(instanceID);
			}
			RainbowRegistry.Forget(instanceID);
			GlowLifeRegistry.Forget(instanceID);
			StickTint.Forget(instanceID);
		}
	}

	[HarmonyPatch(typeof(GameStateManager), "DoChangeState")]
	internal static class Patch_DoChangeState
	{
		public static void Postfix(GameStateManager __instance, eGameStateName nextState)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Expected I4, but got Unknown
			//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_004c: 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)
			int num = (int)nextState;
			if (num == 10 || num == 11)
			{
				StickManager.IsLocalStick.Clear();
				StickManager.IsValidStick.Clear();
				RainbowRegistry.Clear();
				GlowLifeRegistry.Clear();
				StickTint.Clear();
			}
			if (num == 7 || num == 10)
			{
				CellSound.Post(EVENTS.GLOWSTICKBOUNCE, Vector3.zero - Vector3.up * 100f);
			}
		}
	}

	[HarmonyPatch(typeof(GlowstickInstance), "Update")]
	internal static class Patch_PermanentGlow
	{
		public static void Postfix(GlowstickInstance __instance)
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected I4, but got Unknown
			if (!ModConfig.Permanent.Value && ModConfig.LifeMultiplier.Value == 1f)
			{
				return;
			}
			GameObject gameObject;
			try
			{
				gameObject = ((Component)((Component)__instance).transform).gameObject;
			}
			catch
			{
				return;
			}
			if ((Object)(object)gameObject == (Object)null)
			{
				return;
			}
			int instanceID = ((Object)gameObject).GetInstanceID();
			bool flag = StickManager.IsLocalStick.ContainsKey(instanceID);
			bool flag2 = GlowLife.ShouldManage(ModConfig.Permanent.Value, ModConfig.PermanentMountedOnly.Value, flag);
			bool value;
			bool flag3 = GlowLife.IsSuperseded(StickManager.IsValidStick.TryGetValue(instanceID, out value), value);
			if (flag2 || ModConfig.LifeMultiplier.Value != 1f)
			{
				float s_lightLifeTime = __instance.s_lightLifeTime;
				float num = GlowLife.TargetLifeTime(GlowLifeRegistry.Baseline(instanceID, s_lightLifeTime), s_lightLifeTime, ModConfig.LifeMultiplier.Value);
				bool flag4 = flag2 && !flag3;
				if (flag4)
				{
					__instance.s_lightLifeTime = num;
				}
				else if (GlowLifeRegistry.ShouldApplyOnce(instanceID, num))
				{
					__instance.s_lightLifeTime = num;
				}
				bool revived = false;
				if (GlowLife.Decide(flag4, flag3, (int)__instance.m_state) == GlowAction.Revive)
				{
					__instance.m_state = (eFadeState)2;
					__instance.m_progression = 1f;
					revived = true;
				}
				GlowLifeRegistry.Report(__instance, flag4, flag, num, revived);
			}
		}
	}

	[HarmonyPatch(typeof(GlowstickInstance), "Update")]
	internal static class Patch_RainbowGlowstickUpdate
	{
		public static void Postfix(GlowstickInstance __instance)
		{
			//IL_013e: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			if (!ModConfig.Enabled.Value)
			{
				return;
			}
			GameObject gameObject;
			try
			{
				gameObject = ((Component)((Component)__instance).transform).gameObject;
			}
			catch
			{
				return;
			}
			if ((Object)(object)gameObject == (Object)null)
			{
				return;
			}
			int instanceID = ((Object)gameObject).GetInstanceID();
			bool flag = StickManager.IsLocalStick.ContainsKey(instanceID);
			if (!RainbowPolicy.ShouldApply(enabled: true, ModConfig.OnlyMounted.Value, flag))
			{
				return;
			}
			RainbowSettings settings = ModConfig.Snapshot();
			RainbowCycle rainbowCycle = RainbowRegistry.Get(instanceID);
			Color lightColorTarget = __instance.m_LightColorTarget;
			bool useCustomPalette = ModConfig.UseCustomPalette;
			Color val = default(Color);
			if (useCustomPalette)
			{
				val = RainbowRegistry.CustomColor(instanceID, Time.deltaTime);
			}
			else
			{
				Rgb rgb = rainbowCycle.Apply(Time.time, Time.deltaTime, new Rgb(lightColorTarget.r, lightColorTarget.g, lightColorTarget.b), settings, flag);
				((Color)(ref val))..ctor(rgb.R, rgb.G, rgb.B, (lightColorTarget.a <= 0f) ? 1f : lightColorTarget.a);
			}
			Color color = (__instance.m_LightColorTarget = (useCustomPalette ? RainbowRegistry.LightColor(val) : val));
			try
			{
				if ((Object)(object)__instance.m_light != (Object)null)
				{
					((LightBase)__instance.m_light).Color = color;
				}
			}
			catch
			{
			}
			if (ModConfig.SyncBodyMaterial.Value)
			{
				StickTint.Apply(gameObject, val, flag, useCustomPalette);
			}
			RainbowRegistry.Report(rainbowCycle, val, flag);
		}
	}

	[HarmonyPatch(typeof(ThrowingWeapon), "Update")]
	internal static class Patch_RainbowHeldGlowStick
	{
		public static void Postfix(ThrowingWeapon __instance)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			if (!ModConfig.Enabled.Value || !ModConfig.SyncBodyMaterial.Value || ModConfig.OnlyMounted.Value)
			{
				return;
			}
			string text = null;
			try
			{
				ItemDataBlock itemDataBlock = ((Item)__instance).ItemDataBlock;
				if (itemDataBlock != null)
				{
					text = ((GameDataBlockBase<ItemDataBlock>)(object)itemDataBlock).name;
				}
			}
			catch
			{
			}
			if (string.IsNullOrEmpty(text) || !text.Contains("GlowStick"))
			{
				return;
			}
			GameObject gameObject;
			try
			{
				gameObject = ((Component)((Component)__instance).transform).gameObject;
			}
			catch
			{
				return;
			}
			if (!((Object)(object)gameObject == (Object)null))
			{
				int instanceID = ((Object)gameObject).GetInstanceID();
				RainbowCycle rainbowCycle = RainbowRegistry.Get(instanceID);
				Color color = default(Color);
				if (ModConfig.UseCustomPalette)
				{
					color = RainbowRegistry.CustomColor(instanceID, Time.deltaTime);
				}
				else
				{
					Rgb rgb = rainbowCycle.Apply(Time.time, Time.deltaTime, new Rgb(1f, 1f, 1f), ModConfig.Snapshot(), isMounted: true);
					((Color)(ref color))..ctor(rgb.R, rgb.G, rgb.B, 1f);
				}
				StickTint.Apply(gameObject, color, mounted: false, ModConfig.UseCustomPalette);
			}
		}
	}

	private static readonly Vector3 ZeroPos = new Vector3(0f, -2000f, 0f);
}
internal static class GlowLifeRegistry
{
	private static readonly Dictionary<int, float> BaselineLife = new Dictionary<int, float>();

	private static readonly HashSet<int> MultiplierApplied = new HashSet<int>();

	private static float _nextReport;

	private static int _targets;

	private static int _permanentTargets;

	private static int _mountedTargets;

	private static int _revives;

	private static float _lastLife = -1f;

	public static float Baseline(int instanceId, float current)
	{
		if (BaselineLife.TryGetValue(instanceId, out var value) && value > 0f)
		{
			return value;
		}
		if (current > 0f)
		{
			BaselineLife[instanceId] = current;
			return current;
		}
		return current;
	}

	public static bool ShouldApplyOnce(int instanceId, float target)
	{
		if (MultiplierApplied.Contains(instanceId))
		{
			return false;
		}
		MultiplierApplied.Add(instanceId);
		return true;
	}

	public static void Forget(int instanceId)
	{
		BaselineLife.Remove(instanceId);
		MultiplierApplied.Remove(instanceId);
	}

	public static void Clear()
	{
		BaselineLife.Clear();
		MultiplierApplied.Clear();
		_targets = 0;
		_permanentTargets = 0;
		_mountedTargets = 0;
		_revives = 0;
		_lastLife = -1f;
	}

	public static void Report(GlowstickInstance instance, bool permanent, bool mounted, float lifeTime, bool revived)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected I4, but got Unknown
		_targets++;
		if (permanent)
		{
			_permanentTargets++;
		}
		if (mounted)
		{
			_mountedTargets++;
		}
		if (revived)
		{
			_revives++;
		}
		int num = (int)instance.m_state;
		if (num == 2 || num == 1)
		{
			_lastLife = lifeTime;
		}
		float time = Time.time;
		if (time < _nextReport)
		{
			return;
		}
		_nextReport = time + 1f;
		if (!ModConfig.Diag.Value)
		{
			_targets = 0;
			_permanentTargets = 0;
			_mountedTargets = 0;
			return;
		}
		ManualLogSource logger = EntryPoint.Logger;
		if (logger != null)
		{
			logger.LogInfo((object)string.Format(CultureInfo.InvariantCulture, "[GSOB-Life] permanent={0} mounted={1} state={2} life={3:0.###} targets={4} permanentTargets={5} mountedTargets={6} revives={7} multiplier={8}", permanent, mounted, num, _lastLife, _targets, _permanentTargets, _mountedTargets, _revives, ModConfig.LifeMultiplier.Value));
		}
		_targets = 0;
		_permanentTargets = 0;
		_mountedTargets = 0;
		_revives = 0;
	}
}
internal static class RainbowRegistry
{
	private static readonly Dictionary<int, RainbowCycle> Cycles = new Dictionary<int, RainbowCycle>();

	private static readonly Dictionary<int, PaletteCycle> PaletteCycles = new Dictionary<int, PaletteCycle>();

	private static float _nextReport;

	private static int _targets;

	private static int _mountedTargets;

	private static float _lastHue = -1f;

	public static Color LightColor(Color color)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: 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_003e: Unknown result type (might be due to invalid IL or missing references)
		PaletteColor paletteColor = new PaletteColor(color.r, color.g, color.b, color.a).LightColor();
		return new Color(paletteColor.R, paletteColor.G, paletteColor.B, paletteColor.A);
	}

	public static Color CustomColor(int instanceId, float deltaTime)
	{
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		if (!PaletteCycles.TryGetValue(instanceId, out var value))
		{
			value = new PaletteCycle((uint)((instanceId * -1640531535) | 1));
			PaletteCycles[instanceId] = value;
		}
		PaletteColor paletteColor = value.Evaluate(ModConfig.GetPalette(), ModConfig.PaletteRandomOrder.Value, ModConfig.PaletteRandomInterval.Value, ModConfig.PaletteFixedSeconds.Value, ModConfig.PaletteMinSeconds.Value, ModConfig.PaletteMaxSeconds.Value, deltaTime);
		return new Color(paletteColor.R, paletteColor.G, paletteColor.B, paletteColor.A);
	}

	public static RainbowCycle Get(int instanceId)
	{
		if (!Cycles.TryGetValue(instanceId, out var value))
		{
			value = new RainbowCycle((uint)((int)(instanceId * 2654435761u) | 1));
			Cycles[instanceId] = value;
		}
		return value;
	}

	public static void Forget(int instanceId)
	{
		Cycles.Remove(instanceId);
		PaletteCycles.Remove(instanceId);
	}

	public static void Clear()
	{
		Cycles.Clear();
		PaletteCycles.Clear();
		_targets = 0;
		_mountedTargets = 0;
		_lastHue = -1f;
	}

	public static void Report(RainbowCycle cycle, Color color, bool mounted)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: 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)
		_targets++;
		if (mounted)
		{
			_mountedTargets++;
		}
		float time = Time.time;
		if (time < _nextReport)
		{
			return;
		}
		_nextReport = time + 1f;
		if (!ModConfig.Diag.Value)
		{
			_targets = 0;
			_mountedTargets = 0;
			return;
		}
		float num = (ModConfig.UseCustomPalette ? new Rgb(color.r, color.g, color.b).Hue() : cycle.CurrentHue);
		bool flag = _lastHue < 0f || Math.Abs(num - _lastHue) > 0.0005f;
		_lastHue = num;
		ManualLogSource logger = EntryPoint.Logger;
		if (logger != null)
		{
			logger.LogInfo((object)string.Format(CultureInfo.InvariantCulture, "[GSOB-Rainbow] hue={0:0.000} rgb=({1:0.000},{2:0.000},{3:0.000}) changed={4} targets={5} mounted={6} style={7} onlyMounted={8}", num, color.r, color.g, color.b, flag, _targets, _mountedTargets, ModConfig.Style.Value, ModConfig.OnlyMounted.Value));
		}
		_targets = 0;
		_mountedTargets = 0;
	}
}
internal static class StickTint
{
	private sealed class Target
	{
		public Material[] Materials = Array.Empty<Material>();

		public int[] PropIds = Array.Empty<int>();

		public string[] PropNames = Array.Empty<string>();

		public float[] EmissionScale = Array.Empty<float>();

		public Light[] UnityLights = Array.Empty<Light>();

		public EffectLight[] EffectLights = Array.Empty<EffectLight>();

		public bool ProbeLogged;
	}

	private static readonly Dictionary<int, Target> Cache = new Dictionary<int, Target>();

	private static readonly int EmissionId = Shader.PropertyToID("_EmissionColor");

	private static readonly string[] FallbackPropNames = new string[6] { "_Color", "_BaseColor", "_TintColor", "_SwatchColor", "_MainColor", "_GlowColor" };

	private static readonly string[] ExcludeHints = new string[13]
	{
		"specular", "rim", "shadow", "ambient", "outline", "fog", "mask", "emission", "back", "front",
		"detail", "eye", "hair"
	};

	public static void Apply(GameObject go, Color color, bool mounted, bool alphaAffectsLight = false)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		int instanceID;
		try
		{
			instanceID = ((Object)go).GetInstanceID();
		}
		catch
		{
			return;
		}
		if (!Cache.TryGetValue(instanceID, out var value) || value == null)
		{
			value = Build(go);
			Cache[instanceID] = value;
		}
		try
		{
			ApplyTo(value, color, alphaAffectsLight);
		}
		catch
		{
			Cache.Remove(instanceID);
		}
		if (!value.ProbeLogged && ModConfig.Diag.Value)
		{
			value.ProbeLogged = true;
			ManualLogSource logger = EntryPoint.Logger;
			if (logger != null)
			{
				logger.LogInfo((object)string.Format(CultureInfo.InvariantCulture, "[GSOB-Rainbow] body-probe obj={0} mats={1} props={2} emission={3} lights={4} mounted={5}", ((Object)go).name, value.Materials.Length, string.Join("|", value.PropNames), JoinFloats(value.EmissionScale), value.UnityLights.Length + value.EffectLights.Length, mounted));
			}
		}
	}

	public static void Forget(int instanceId)
	{
		Cache.Remove(instanceId);
	}

	public static void Clear()
	{
		Cache.Clear();
	}

	private static Target Build(GameObject go)
	{
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: 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_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		Target target = new Target();
		List<Material> list = new List<Material>();
		List<float> list2 = new List<float>();
		List<int> list3 = new List<int>();
		List<string> list4 = new List<string>();
		foreach (Renderer item2 in CollectRenderers(go))
		{
			Material val = null;
			try
			{
				val = item2.material;
			}
			catch
			{
			}
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			list.Add(val);
			float item = 0f;
			try
			{
				if (val.HasProperty(EmissionId))
				{
					Color color = val.GetColor(EmissionId);
					item = Mathf.Max(color.r, Mathf.Max(color.g, color.b));
				}
			}
			catch
			{
			}
			list2.Add(item);
			CollectColorProps(val, list3, list4);
		}
		target.Materials = list.ToArray();
		target.EmissionScale = list2.ToArray();
		target.PropIds = list3.ToArray();
		target.PropNames = list4.ToArray();
		List<Light> list5 = new List<Light>();
		try
		{
			foreach (Light componentsInChild in go.GetComponentsInChildren<Light>(true))
			{
				if ((Object)(object)componentsInChild != (Object)null)
				{
					list5.Add(componentsInChild);
				}
			}
		}
		catch
		{
		}
		target.UnityLights = list5.ToArray();
		List<EffectLight> list6 = new List<EffectLight>();
		try
		{
			foreach (EffectLight componentsInChild2 in go.GetComponentsInChildren<EffectLight>(true))
			{
				if ((Object)(object)componentsInChild2 != (Object)null)
				{
					list6.Add(componentsInChild2);
				}
			}
		}
		catch
		{
		}
		target.EffectLights = list6.ToArray();
		return target;
	}

	private static List<Renderer> CollectRenderers(GameObject go)
	{
		List<Renderer> list = new List<Renderer>();
		try
		{
			foreach (MeshRenderer componentsInChild in go.GetComponentsInChildren<MeshRenderer>(true))
			{
				if ((Object)(object)componentsInChild != (Object)null)
				{
					list.Add((Renderer)(object)componentsInChild);
				}
			}
		}
		catch
		{
		}
		try
		{
			foreach (SkinnedMeshRenderer componentsInChild2 in go.GetComponentsInChildren<SkinnedMeshRenderer>(true))
			{
				if ((Object)(object)componentsInChild2 != (Object)null)
				{
					list.Add((Renderer)(object)componentsInChild2);
				}
			}
		}
		catch
		{
		}
		return list;
	}

	private static void CollectColorProps(Material material, List<int> ids, List<string> names)
	{
		Shader val = null;
		try
		{
			val = material.shader;
		}
		catch
		{
		}
		if ((Object)(object)val != (Object)null)
		{
			int num = 0;
			try
			{
				num = val.GetPropertyCount();
			}
			catch
			{
				num = 0;
			}
			for (int i = 0; i < num; i++)
			{
				string text = null;
				try
				{
					text = val.GetPropertyName(i);
				}
				catch
				{
				}
				if (!string.IsNullOrEmpty(text) && IsColorLike(text))
				{
					AddProp(text, ids, names);
				}
			}
		}
		string[] fallbackPropNames = FallbackPropNames;
		foreach (string text2 in fallbackPropNames)
		{
			try
			{
				if (material.HasProperty(text2))
				{
					AddProp(text2, ids, names);
				}
			}
			catch
			{
			}
		}
	}

	private static void AddProp(string propName, List<int> ids, List<string> names)
	{
		int item = Shader.PropertyToID(propName);
		if (!ids.Contains(item))
		{
			ids.Add(item);
			names.Add(propName);
		}
	}

	private static bool IsColorLike(string propName)
	{
		string text = propName.ToLowerInvariant();
		if (!text.Contains("color") && !text.Contains("colour") && !text.Contains("swatch") && !text.Contains("tint") && !text.Contains("glow"))
		{
			return false;
		}
		string[] excludeHints = ExcludeHints;
		foreach (string value in excludeHints)
		{
			if (text.Contains(value))
			{
				return false;
			}
		}
		return true;
	}

	private static void ApplyTo(Target target, Color color, bool alphaAffectsLight)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < target.Materials.Length; i++)
		{
			Material val = target.Materials[i];
			if (!((Object)(object)val == (Object)null))
			{
				for (int j = 0; j < target.PropIds.Length; j++)
				{
					val.SetColor(target.PropIds[j], color);
				}
				float num = target.EmissionScale[i];
				if (num > 0.0001f)
				{
					val.SetColor(EmissionId, new Color(color.r * num, color.g * num, color.b * num, color.a));
				}
			}
		}
		for (int k = 0; k < target.UnityLights.Length; k++)
		{
			Light val2 = target.UnityLights[k];
			if ((Object)(object)val2 != (Object)null)
			{
				val2.color = (alphaAffectsLight ? RainbowRegistry.LightColor(color) : color);
			}
		}
		for (int l = 0; l < target.EffectLights.Length; l++)
		{
			EffectLight val3 = target.EffectLights[l];
			if ((Object)(object)val3 != (Object)null)
			{
				((LightBase)val3).Color = (alphaAffectsLight ? RainbowRegistry.LightColor(color) : color);
			}
		}
	}

	private static string JoinFloats(float[] values)
	{
		string[] array = new string[values.Length];
		for (int i = 0; i < values.Length; i++)
		{
			array[i] = values[i].ToString("0.###", CultureInfo.InvariantCulture);
		}
		return string.Join("|", array);
	}
}
internal enum RainbowStyle
{
	SmoothHue,
	RandomVivid
}
internal struct Rgb
{
	public float R;

	public float G;

	public float B;

	public float Max => Math.Max(R, Math.Max(G, B));

	public float Min => Math.Min(R, Math.Min(G, B));

	public Rgb(float r, float g, float b)
	{
		R = r;
		G = g;
		B = b;
	}

	public float Hue()
	{
		float max = Max;
		float num = max - Min;
		if (num <= 1E-06f)
		{
			return -1f;
		}
		float num2 = ((max - R <= 1E-07f) ? ((G - B) / num % 6f) : ((!(max - G <= 1E-07f)) ? ((R - G) / num + 4f) : ((B - R) / num + 2f)));
		if (num2 < 0f)
		{
			num2 += 6f;
		}
		return num2 / 6f;
	}

	public static Rgb FromHue(float hue)
	{
		float num = (hue - (float)Math.Floor(hue)) * 6f;
		int num2 = (int)Math.Floor(num) % 6;
		float num3 = num - (float)Math.Floor(num);
		float num4 = 1f - num3;
		return num2 switch
		{
			0 => new Rgb(1f, num3, 0f), 
			1 => new Rgb(num4, 1f, 0f), 
			2 => new Rgb(0f, 1f, num3), 
			3 => new Rgb(0f, num4, 1f), 
			4 => new Rgb(num3, 0f, 1f), 
			_ => new Rgb(1f, 0f, num4), 
		};
	}

	public override string ToString()
	{
		return string.Format(CultureInfo.InvariantCulture, "({0:0.000},{1:0.000},{2:0.000})", R, G, B);
	}
}
internal struct RainbowSettings
{
	public bool Enabled;

	public RainbowStyle Style;

	public double PeriodSeconds;

	public double IntervalSeconds;

	public bool OnlyMounted;

	public static RainbowStyle ParseStyle(string value)
	{
		if (value == null || !value.Contains("随机"))
		{
			return RainbowStyle.SmoothHue;
		}
		return RainbowStyle.RandomVivid;
	}
}
internal static class RainbowPolicy
{
	public static bool ShouldApply(bool enabled, bool onlyMounted, bool isMounted)
	{
		if (enabled)
		{
			return !onlyMounted || isMounted;
		}
		return false;
	}
}
internal sealed class RainbowCycle
{
	private const float MinHueStep = 0.12f;

	private const double MinPeriod = 0.01;

	private const double MinInterval = 0.05;

	private uint _rng;

	private bool _primed;

	private double _timer;

	private float _hueFrom;

	private float _hueTo;

	public int SwitchCount { get; private set; }

	public int EvaluateCount { get; private set; }

	public float CurrentHue { get; private set; }

	public Rgb SegmentStart => Rgb.FromHue(_hueFrom);

	public Rgb SegmentEnd => Rgb.FromHue(_hueTo);

	public RainbowCycle(uint seed = 2654435769u)
	{
		_rng = ((seed == 0) ? 1u : seed);
	}

	public static Rgb EvaluateSmoothHue(double time, double periodSeconds)
	{
		double num = ((periodSeconds <= 0.01) ? 0.01 : periodSeconds);
		double num2 = time % num;
		if (num2 < 0.0)
		{
			num2 += num;
		}
		return Rgb.FromHue((float)(num2 / num));
	}

	public static float LerpHue(float from, float to, float t)
	{
		float num = to - from;
		if (num > 0.5f)
		{
			num -= 1f;
		}
		else if (num < -0.5f)
		{
			num += 1f;
		}
		float num2 = from + num * t;
		return num2 - (float)Math.Floor(num2);
	}

	public Rgb Evaluate(double time, double deltaSeconds, RainbowStyle style, double periodSeconds, double intervalSeconds)
	{
		EvaluateCount++;
		if (style == RainbowStyle.SmoothHue)
		{
			Rgb result = EvaluateSmoothHue(time, periodSeconds);
			CurrentHue = result.Hue();
			return result;
		}
		double num = ((intervalSeconds <= 0.05) ? 0.05 : intervalSeconds);
		if (!_primed)
		{
			_hueFrom = NextHue(0f);
			_hueTo = NextHue(_hueFrom);
			_primed = true;
			_timer = 0.0;
		}
		_timer += ((deltaSeconds > 0.0) ? deltaSeconds : 0.0);
		if (_timer >= num)
		{
			_timer = 0.0;
			_hueFrom = _hueTo;
			_hueTo = NextHue(_hueFrom);
			SwitchCount++;
		}
		double num2 = _timer / num;
		if (num2 > 1.0)
		{
			num2 = 1.0;
		}
		float hue = (CurrentHue = LerpHue(_hueFrom, _hueTo, (float)num2));
		return Rgb.FromHue(hue);
	}

	public Rgb Apply(double time, double deltaSeconds, Rgb original, RainbowSettings settings, bool isMounted)
	{
		if (!RainbowPolicy.ShouldApply(settings.Enabled, settings.OnlyMounted, isMounted))
		{
			CurrentHue = original.Hue();
			return original;
		}
		return Evaluate(time, deltaSeconds, settings.Style, settings.PeriodSeconds, settings.IntervalSeconds);
	}

	public void Reset()
	{
		_primed = false;
		_timer = 0.0;
		SwitchCount = 0;
	}

	private float NextHue(float previous)
	{
		for (int i = 0; i < 32; i++)
		{
			float num = NextFloat();
			float num2 = Math.Abs(num - previous);
			if (num2 > 0.5f)
			{
				num2 = 1f - num2;
			}
			if (num2 >= 0.12f)
			{
				return num;
			}
		}
		return LerpHue(previous, previous + 0.5f, 1f);
	}

	private float NextFloat()
	{
		_rng = _rng * 1664525 + 1013904223;
		return (float)(_rng >> 8) / 16777216f;
	}
}
internal static class StickManager
{
	public static readonly Dictionary<int, bool> IsLocalStick = new Dictionary<int, bool>();

	public static readonly Dictionary<int, bool> IsValidStick = new Dictionary<int, bool>();

	private static readonly Vector3 Pos1 = new Vector3(0f, 3f, 0f);

	private static readonly Vector3 Pos2 = new Vector3(0f, 1f, 0f);

	private static readonly Vector3 PosLeg = new Vector3(-0.14f, 0f, 0.1f);

	private static readonly Vector3 AngLeg = new Vector3(0f, 90f, 100f);

	private static readonly Vector3 Scale = new Vector3(1E-05f, 1E-05f, 1E-05f);

	public static void SetParent(Item item)
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		PlayerAgent owner = item.Owner;
		if ((Object)(object)owner == (Object)null)
		{
			return;
		}
		_ = ((Component)((Component)owner).transform).gameObject;
		GameObject gameObject = ((Component)((Component)item).transform).gameObject;
		BoxCollider component = gameObject.GetComponent<BoxCollider>();
		if ((Object)(object)component != (Object)null)
		{
			((Collider)component).enabled = false;
		}
		Rigidbody component2 = gameObject.GetComponent<Rigidbody>();
		if ((Object)(object)component2 != (Object)null)
		{
			component2.mass = 0f;
			component2.velocity = Vector3.zero;
			component2.detectCollisions = false;
			component2.useGravity = false;
			component2.freezeRotation = true;
		}
		foreach (GlowstickInstance componentsInChild in ((Component)owner).gameObject.GetComponentsInChildren<GlowstickInstance>())
		{
			int instanceID = ((Object)((Component)((Component)componentsInChild).transform).gameObject).GetInstanceID();
			if (IsValidStick.ContainsKey(instanceID))
			{
				IsValidStick[instanceID] = false;
			}
		}
		gameObject.transform.parent = ((Component)owner).transform;
		IsValidStick[((Object)gameObject).GetInstanceID()] = true;
		if (((Agent)owner).IsLocallyOwned)
		{
			gameObject.transform.localPosition = Pos1;
			IsLocalStick[((Object)gameObject).GetInstanceID()] = true;
			gameObject.transform.localScale = Scale;
			return;
		}
		gameObject.transform.localPosition = Pos2;
		IsLocalStick[((Object)gameObject).GetInstanceID()] = false;
		foreach (TargetTransform componentsInChild2 in ((Component)owner).GetComponentsInChildren<TargetTransform>(true))
		{
			if (((Object)((Component)componentsInChild2).gameObject).name == "RightUpperLeg_Roll")
			{
				gameObject.transform.parent = ((Component)componentsInChild2).gameObject.transform;
				gameObject.transform.localPosition = PosLeg;
				gameObject.transform.localEulerAngles = AngLeg;
				break;
			}
		}
	}
}