Decompiled source of Artifact of Greed v0.8.0

RoR2Greed.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using R2API;
using R2API.Networking;
using R2API.Networking.Interfaces;
using R2API.ScriptableObjects;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RoR2Greed")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+cd69edd25640b0b9c944bd8894a5e7361a1f066b")]
[assembly: AssemblyProduct("RoR2Greed")]
[assembly: AssemblyTitle("RoR2Greed")]
[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;
		}
	}
}
namespace RoR2Greed
{
	internal static class GoldHud
	{
		private static readonly Color Gold = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)200, (byte)40, byte.MaxValue));

		private static readonly Dictionary<CharacterMaster, uint> Peaks = new Dictionary<CharacterMaster, uint>();

		private static readonly Dictionary<HealthBarStyle, HealthBarStyle> GoldStyles = new Dictionary<HealthBarStyle, HealthBarStyle>();

		public static readonly Dictionary<SpriteAsNumberManager, uint> ShownGold = new Dictionary<SpriteAsNumberManager, uint>();

		public static void Reset()
		{
			Peaks.Clear();
			ShownGold.Clear();
		}

		public static void ResetPeaks()
		{
			Peaks.Clear();
		}

		public static string Format(uint money)
		{
			return $"$$$ {money} $$$";
		}

		public static bool TryGetMaster(HealthComponent health, out CharacterMaster master)
		{
			master = null;
			if (!Object.op_Implicit((Object)(object)health) || !Plugin.Active || !Object.op_Implicit((Object)(object)Run.instance))
			{
				return false;
			}
			CharacterBody body = health.body;
			if (!Object.op_Implicit((Object)(object)body) || !body.isPlayerControlled)
			{
				return false;
			}
			master = body.master;
			return Object.op_Implicit((Object)(object)master);
		}

		public static float Fill(CharacterMaster master)
		{
			uint val = (uint)Mathf.Max(Run.instance.GetDifficultyScaledCost(Plugin.StartGold.Value), 1);
			Peaks.TryGetValue(master, out var value);
			value = Math.Max(Math.Max(value, master.money), val);
			Peaks[master] = value;
			return Mathf.Clamp01((float)master.money / (float)value);
		}

		public static HealthBarStyle GoldStyle(HealthBarStyle original)
		{
			//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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (GoldStyles.TryGetValue(original, out var value) && Object.op_Implicit((Object)(object)value))
			{
				return value;
			}
			value = Object.Instantiate<HealthBarStyle>(original);
			value.instantHealthBarStyle.baseColor = Gold;
			value.trailingOverHealthBarStyle.baseColor = Gold;
			value.flashOnHealthCritical = false;
			GoldStyles[original] = value;
			return value;
		}
	}
	[HarmonyPatch(typeof(HealthComponent), "GetHealthBarValues")]
	internal static class HealthBarValuesPatch
	{
		private static void Postfix(HealthComponent __instance, ref HealthBarValues __result)
		{
			if (GoldHud.TryGetMaster(__instance, out var master))
			{
				__result.healthFraction *= GoldHud.Fill(master);
				__result.ospFraction = 0f;
				__result.hasInfusion = false;
				__result.isBoss = false;
				__result.isVoid = false;
			}
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class HealthBarStylePatch
	{
		private static void Postfix(HealthBar __instance, ref HealthBarStyle __result)
		{
			if (Object.op_Implicit((Object)(object)__result) && GoldHud.TryGetMaster(__instance.source, out var _))
			{
				__result = GoldHud.GoldStyle(__result);
			}
		}
	}
	[HarmonyPatch(typeof(HealthBar), "UpdateHealthbar")]
	internal static class HealthBarTextPatch
	{
		private static void Postfix(HealthBar __instance)
		{
			SpriteAsNumberManager spriteAsNumberManager = __instance.spriteAsNumberManager;
			if (!GoldHud.TryGetMaster(__instance.source, out var master))
			{
				if (Object.op_Implicit((Object)(object)spriteAsNumberManager))
				{
					GoldHud.ShownGold.Remove(spriteAsNumberManager);
				}
				return;
			}
			uint money = master.money;
			if (Object.op_Implicit((Object)(object)spriteAsNumberManager))
			{
				if (!GoldHud.ShownGold.TryGetValue(spriteAsNumberManager, out var value) || value != money)
				{
					GoldHud.ShownGold[spriteAsNumberManager] = money;
					spriteAsNumberManager.SetHitPointValues(0, 0);
				}
				return;
			}
			if (Object.op_Implicit((Object)(object)__instance.currentHealthText))
			{
				((TMP_Text)__instance.currentHealthText).text = GoldHud.Format(money);
			}
			if (Object.op_Implicit((Object)(object)__instance.fullHealthText))
			{
				((TMP_Text)__instance.fullHealthText).text = "";
			}
		}
	}
	[HarmonyPatch(typeof(SpriteAsNumberManager), "SetHitPointValues")]
	internal static class GoldNumberPatch
	{
		private const float LabelExtraHeight = 4f;

		private static readonly Dictionary<SpriteAsNumberManager, HGTextMeshProUGUI> Labels = new Dictionary<SpriteAsNumberManager, HGTextMeshProUGUI>();

		private static bool Prefix(SpriteAsNumberManager __instance)
		{
			if (!GoldHud.ShownGold.TryGetValue(__instance, out var value))
			{
				return true;
			}
			__instance.TrySetup();
			__instance.SetVisible(false);
			((TMP_Text)GetLabel(__instance)).text = GoldHud.Format(value);
			return false;
		}

		private static HGTextMeshProUGUI GetLabel(SpriteAsNumberManager numbers)
		{
			//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)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_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_006b: 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)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			if (Labels.TryGetValue(numbers, out var value) && Object.op_Implicit((Object)(object)value))
			{
				return value;
			}
			GameObject val = new GameObject("GoldAmount", new Type[1] { typeof(RectTransform) })
			{
				layer = ((Component)numbers).gameObject.layer
			};
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent(((Component)numbers).transform, false);
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			val2.offsetMin = new Vector2(0f, -4f);
			val2.offsetMax = new Vector2(0f, 4f);
			value = val.AddComponent<HGTextMeshProUGUI>();
			((TMP_Text)value).alignment = (TextAlignmentOptions)514;
			((TMP_Text)value).enableWordWrapping = false;
			((TMP_Text)value).enableAutoSizing = true;
			((TMP_Text)value).fontSizeMin = 10f;
			((TMP_Text)value).fontSizeMax = 40f;
			((Graphic)value).raycastTarget = false;
			Labels[numbers] = value;
			return value;
		}
	}
	[HarmonyPatch(typeof(HUD), "Update")]
	internal static class HideMoneyPatch
	{
		private static void Postfix(HUD __instance)
		{
			float alpha = (Plugin.Active ? 0f : 1f);
			if (Object.op_Implicit((Object)(object)__instance.moneyText))
			{
				SetAlpha(((Component)__instance.moneyText).gameObject, alpha);
			}
			if (Object.op_Implicit((Object)(object)__instance.lunarCoinContainer))
			{
				SetAlpha(__instance.lunarCoinContainer, alpha);
			}
		}

		private static void SetAlpha(GameObject target, float alpha)
		{
			CanvasGroup val = target.GetComponent<CanvasGroup>();
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = target.AddComponent<CanvasGroup>();
			}
			val.alpha = alpha;
		}
	}
	[HarmonyPatch(typeof(PurchaseInteraction), "Start")]
	internal static class LunarShopPatch
	{
		private const int SmallChestCost = 25;

		private const int ShopCoins = 2;

		private static void Postfix(PurchaseInteraction __instance)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			if (Plugin.Enabled && Object.op_Implicit((Object)(object)Run.instance) && (int)__instance.costType == 3)
			{
				int num = (Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<ShopTerminalBehavior>()) ? 2 : Mathf.Max(__instance.cost, 1));
				float num2 = Run.instance.GetDifficultyScaledCost(25);
				__instance.NetworkcostType = (CostTypeIndex)1;
				__instance.Networkcost = Mathf.Max(Mathf.RoundToInt(num2 * (float)num / 2f), 1);
			}
		}
	}
	[BepInPlugin("alexey.ror2greed", "RoR2 Greed", "0.8.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private class PlayerState
		{
			public CharacterBody Body;

			public float Remainder;

			public float HealRemainder;
		}

		public const string Guid = "alexey.ror2greed";

		public static ArtifactDef Artifact;

		public static ConfigEntry<int> StartGold;

		public static ConfigEntry<int> HealthBarCost;

		public static ConfigEntry<float> HealGoldRate;

		public static ConfigEntry<float> RegenGoldRate;

		private static readonly Dictionary<CharacterMaster, PlayerState> States = new Dictionary<CharacterMaster, PlayerState>();

		public static bool Active
		{
			get
			{
				if (Object.op_Implicit((Object)(object)RunArtifactManager.instance))
				{
					return RunArtifactManager.instance.IsArtifactEnabled(Artifact);
				}
				return false;
			}
		}

		public static bool Enabled
		{
			get
			{
				if (NetworkServer.active)
				{
					return Active;
				}
				return false;
			}
		}

		private void Awake()
		{
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			StartGold = ((BaseUnityPlugin)this).Config.Bind<int>("Balance", "StartGold", 100, "Золото на старте забега и после воскрешения.");
			HealthBarCost = ((BaseUnityPlugin)this).Config.Bind<int>("Balance", "HealthBarCost", 50, "Сколько золота на первой минуте стоит урон на полную полоску здоровья. Дальше цена растёт вместе с ценами сундуков.");
			HealGoldRate = ((BaseUnityPlugin)this).Config.Bind<float>("Balance", "HealGoldRate", 0.1f, "Какая часть цены здоровья возвращается золотом при лечении предметами и способностями.");
			RegenGoldRate = ((BaseUnityPlugin)this).Config.Bind<float>("Balance", "RegenGoldRate", 0.03f, "То же для пассивной регенерации.");
			LanguageAPI.Add("ARTIFACT_GREED_NAME", "Артефакт жадности");
			LanguageAPI.Add("ARTIFACT_GREED_DESC", "Золото заменяет здоровье. Урон отнимает деньги, а когда их становится ноль, вы умираете.");
			LanguageAPI.Add("GREED_ROULETTE_NOTHING", "<style=cShrine>Рулетка: ставка сгорела.</style>");
			LanguageAPI.Add("GREED_ROULETTE_GOLD", "<style=cShrine>Рулетка: +{0} золота.</style>");
			LanguageAPI.Add("GREED_ROULETTE_JACKPOT", "<style=cShrine>ДЖЕКПОТ! Рулетка: +{0} золота.</style>");
			LanguageAPI.Add("GREED_ROULETTE_ITEM", "<style=cShrine>Рулетка выдала предмет.</style>");
			LanguageAPI.Add("GREED_SHRINE_WIN", "<style=cShrine>Алтарь удвоил ставку: +{0} золота.</style>");
			LanguageAPI.Add("GREED_SHRINE_LOSE", "<style=cShrine>Алтарь забрал ставку: -{0} золота.</style>");
			Artifact = ScriptableObject.CreateInstance<ArtifactDef>();
			Artifact.cachedName = "ArtifactOfGreed";
			Artifact.nameToken = "ARTIFACT_GREED_NAME";
			Artifact.descriptionToken = "ARTIFACT_GREED_DESC";
			Artifact.smallIconSelectedSprite = MakeCoin(new Color(1f, 0.78f, 0.15f));
			Artifact.smallIconDeselectedSprite = MakeCoin(new Color(0.35f, 0.35f, 0.35f));
			ContentAddition.AddArtifactDef(Artifact);
			AddCode();
			NetworkingAPI.RegisterMessageType<SpinMessage>();
			NetworkingAPI.RegisterMessageType<SpinRequest>();
			new Harmony("alexey.ror2greed").PatchAll(typeof(Plugin).Assembly);
			Run.onRunStartGlobal += delegate
			{
				States.Clear();
				GoldHud.Reset();
			};
			Stage.onStageStartGlobal += delegate
			{
				GoldHud.ResetPeaks();
				Roulette.ResetSpins();
			};
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Артефакт жадности добавлен");
		}

		private static void AddCode()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_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)
			ArtifactCode val = ScriptableObject.CreateInstance<ArtifactCode>();
			val.topRow = new Vector3Int(5, 1, 5);
			val.middleRow = new Vector3Int(1, 3, 1);
			val.bottomRow = new Vector3Int(5, 1, 5);
			ArtifactCodeAPI.AddCode(Artifact, val);
		}

		private void FixedUpdate()
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			Roulette.Tick();
			if (!Enabled)
			{
				return;
			}
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				CharacterMaster master = instance.master;
				if (!Object.op_Implicit((Object)(object)master))
				{
					continue;
				}
				CharacterBody body = master.GetBody();
				if (!Object.op_Implicit((Object)(object)body))
				{
					continue;
				}
				if (!States.TryGetValue(master, out var value))
				{
					States[master] = new PlayerState
					{
						Body = body
					};
					master.money = (uint)Mathf.Max(StartGold.Value, 1);
				}
				else if ((Object)(object)value.Body != (Object)(object)body)
				{
					value.Body = body;
					if (master.money == 0)
					{
						master.money = (uint)Mathf.Max(StartGold.Value, 1);
					}
				}
				else if (master.money == 0 && !Roulette.IsSpinning(master) && Object.op_Implicit((Object)(object)body.healthComponent) && body.healthComponent.alive)
				{
					body.healthComponent.Suicide((GameObject)null, (GameObject)null, default(DamageTypeCombo));
				}
			}
		}

		public static void Charge(HealthComponent health, float lostHealth, bool nonLethal)
		{
			CharacterMaster master = health.body.master;
			if (Object.op_Implicit((Object)(object)master) && Object.op_Implicit((Object)(object)Run.instance) && States.TryGetValue(master, out var value))
			{
				float num = Run.instance.GetDifficultyScaledCost(HealthBarCost.Value);
				float num2 = lostHealth / Mathf.Max(health.fullHealth, 1f) * num + value.Remainder;
				uint num3 = (uint)Mathf.FloorToInt(num2);
				value.Remainder = num2 - (float)num3;
				uint num4 = (nonLethal ? 1u : 0u);
				master.money = ((master.money > num3 + num4) ? (master.money - num3) : Math.Min(master.money, num4));
			}
		}

		public static void Reward(HealthComponent health, float healed, float rate)
		{
			CharacterMaster master = health.body.master;
			if (Object.op_Implicit((Object)(object)master) && Object.op_Implicit((Object)(object)Run.instance) && States.TryGetValue(master, out var value))
			{
				float num = Run.instance.GetDifficultyScaledCost(HealthBarCost.Value);
				float num2 = healed / Mathf.Max(health.fullHealth, 1f) * num * rate + value.HealRemainder;
				uint num3 = (uint)Mathf.FloorToInt(num2);
				value.HealRemainder = num2 - (float)num3;
				master.money += num3;
			}
		}

		private static Sprite MakeCoin(Color color)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_00d6: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//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_0055: 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_0061: 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_006c: 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)
			//IL_0078: 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)
			Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false);
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(64f, 64f);
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num = Vector2.Distance(new Vector2((float)j, (float)i), val2) / 64f;
					Color val3 = Color.clear;
					if (num < 0.92f)
					{
						val3 = color;
					}
					if (num < 0.72f)
					{
						val3 = color * 0.72f;
					}
					if (num < 0.5f)
					{
						val3 = color;
					}
					val3.a = ((num < 0.92f) ? 1f : 0f);
					val.SetPixel(j, i, val3);
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), val2);
		}
	}
	[HarmonyPatch(typeof(ArtifactDef), "CreatePickupDef")]
	internal static class PickupModelPatch
	{
		private static void Prefix(ArtifactDef __instance)
		{
			ArtifactDef glass = Artifacts.Glass;
			if (!((Object)(object)__instance != (Object)(object)Plugin.Artifact) && Object.op_Implicit((Object)(object)glass))
			{
				__instance.pickupModelPrefab = glass.pickupModelPrefab;
				__instance.pickupModelReference = glass.pickupModelReference;
			}
		}
	}
	[HarmonyPatch(typeof(HealthComponent), "TakeDamageProcess")]
	internal static class DamagePatch
	{
		private const float StandIn = 1000000f;

		private static readonly HashSet<HealthComponent> Active = new HashSet<HealthComponent>();

		private static void Prefix(HealthComponent __instance, out float __state)
		{
			__state = -1f;
			CharacterBody body = __instance.body;
			if (Plugin.Enabled && Object.op_Implicit((Object)(object)body) && body.isPlayerControlled && __instance.alive && Active.Add(__instance))
			{
				__state = __instance.health;
				__instance.Networkhealth = 1000000f;
			}
		}

		private static void Finalizer(HealthComponent __instance, DamageInfo damageInfo, float __state)
		{
			//IL_0061: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			if (__state < 0f)
			{
				return;
			}
			Active.Remove(__instance);
			float health = __instance.health;
			if (!(health <= 0f))
			{
				__instance.Networkhealth = __state;
				bool flag = Object.op_Implicit((Object)(object)damageInfo.attacker) && Object.op_Implicit((Object)(object)damageInfo.attacker.GetComponent<ShrineBloodBehavior>());
				if (health > 1f && health < 1000000f && !flag)
				{
					bool nonLethal = DamageTypeCombo.op_Implicit(damageInfo.damageType & DamageTypeCombo.op_Implicit((DamageType)1)) != 0;
					Plugin.Charge(__instance, 1000000f - health, nonLethal);
				}
			}
		}
	}
	[HarmonyPatch(typeof(HealthComponent), "Heal")]
	internal static class HealPatch
	{
		private static void Prefix(HealthComponent __instance, float amount, ProcChainMask procChainMask, bool nonRegen)
		{
			CharacterBody body = __instance.body;
			if (Plugin.Enabled && Object.op_Implicit((Object)(object)body) && body.isPlayerControlled && __instance.alive && !(amount <= 0f) && !((ProcChainMask)(ref procChainMask)).HasProc((ProcType)13) && !body.HasBuff(Buffs.HealingDisabled))
			{
				Plugin.Reward(__instance, amount, nonRegen ? Plugin.HealGoldRate.Value : Plugin.RegenGoldRate.Value);
			}
		}
	}
	[HarmonyPatch(typeof(ConvertPlayerMoneyToExperience), "FixedUpdate")]
	internal static class KeepGoldPatch
	{
		private static bool Prefix(ConvertPlayerMoneyToExperience __instance)
		{
			if (!Plugin.Enabled)
			{
				return true;
			}
			Object.Destroy((Object)(object)__instance);
			return false;
		}
	}
	internal static class Roulette
	{
		public struct Prize
		{
			public float Weight;

			public float GoldMultiplier;

			public int ItemTier;

			public string Token;

			public string Label;

			public Color Color;
		}

		public const float ReachDistance = 25f;

		private const float DropSpeed = 20f;

		private static BazaarController handledBazaar;

		private static bool wheelBusy;

		public static readonly Prize[] Prizes = new Prize[8]
		{
			new Prize
			{
				Weight = 32f,
				Token = "GREED_ROULETTE_NOTHING",
				Label = "ПУСТО",
				Color = new Color(0.22f, 0.2f, 0.2f)
			},
			new Prize
			{
				Weight = 18f,
				GoldMultiplier = 2f,
				Token = "GREED_ROULETTE_GOLD",
				Label = "x2",
				Color = new Color(0.8f, 0.55f, 0.1f)
			},
			new Prize
			{
				Weight = 16f,
				ItemTier = 1,
				Token = "GREED_ROULETTE_ITEM",
				Label = "БЕЛЫЙ",
				Color = new Color(0.72f, 0.72f, 0.72f)
			},
			new Prize
			{
				Weight = 1.5f,
				GoldMultiplier = 10f,
				Token = "GREED_ROULETTE_JACKPOT",
				Label = "x10",
				Color = new Color(0.75f, 0.1f, 0.75f)
			},
			new Prize
			{
				Weight = 18f,
				GoldMultiplier = 0.5f,
				Token = "GREED_ROULETTE_GOLD",
				Label = "x0.5",
				Color = new Color(0.5f, 0.32f, 0.12f)
			},
			new Prize
			{
				Weight = 7f,
				GoldMultiplier = 3f,
				Token = "GREED_ROULETTE_GOLD",
				Label = "x3",
				Color = new Color(0.95f, 0.7f, 0.15f)
			},
			new Prize
			{
				Weight = 6f,
				ItemTier = 2,
				Token = "GREED_ROULETTE_ITEM",
				Label = "ЗЕЛЁНЫЙ",
				Color = new Color(0.2f, 0.65f, 0.25f)
			},
			new Prize
			{
				Weight = 1.5f,
				ItemTier = 3,
				Token = "GREED_ROULETTE_ITEM",
				Label = "КРАСНЫЙ",
				Color = new Color(0.8f, 0.15f, 0.15f)
			}
		};

		private static readonly HashSet<CharacterMaster> Spinning = new HashSet<CharacterMaster>();

		public static bool IsSpinning(CharacterMaster master)
		{
			return Spinning.Contains(master);
		}

		public static void ResetSpins()
		{
			Spinning.Clear();
			wheelBusy = false;
		}

		public static uint BetFor(uint money, int percent)
		{
			return Math.Min((uint)Mathf.CeilToInt((float)(money * Mathf.Clamp(percent, 1, 100)) / 100f), money);
		}

		public static void Tick()
		{
			//IL_0059: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Active)
			{
				return;
			}
			BazaarController instance = BazaarController.instance;
			if (!Object.op_Implicit((Object)(object)instance) || (Object)(object)instance == (Object)(object)handledBazaar)
			{
				return;
			}
			CharacterBody val = FindShopkeeper();
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.modelLocator) && Object.op_Implicit((Object)(object)val.modelLocator.modelTransform))
			{
				handledBazaar = instance;
				Vector3 footPosition = val.footPosition;
				((Component)val.modelLocator.modelTransform).gameObject.SetActive(false);
				Collider[] componentsInChildren = ((Component)val).GetComponentsInChildren<Collider>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].enabled = false;
				}
				WheelView.Create(footPosition);
			}
		}

		private static CharacterBody FindShopkeeper()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			foreach (CharacterBody readOnlyInstances in CharacterBody.readOnlyInstancesList)
			{
				if (readOnlyInstances.bodyIndex == BodyPrefabs.ShopkeeperBody.bodyIndex)
				{
					return readOnlyInstances;
				}
			}
			return null;
		}

		public static void Spin(CharacterBody body, int percent)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			WheelView instance = WheelView.Instance;
			if (!Object.op_Implicit((Object)(object)instance) || wheelBusy || !Object.op_Implicit((Object)(object)Run.instance) || !Plugin.Enabled || !Object.op_Implicit((Object)(object)body) || !Object.op_Implicit((Object)(object)body.master) || Vector3.Distance(body.corePosition, instance.GroundPosition) > 25f)
			{
				return;
			}
			CharacterMaster master = body.master;
			uint num = BetFor(master.money, percent);
			if (num == 0)
			{
				return;
			}
			float num2 = 0f;
			Prize[] prizes = Prizes;
			for (int i = 0; i < prizes.Length; i++)
			{
				Prize prize = prizes[i];
				num2 += prize.Weight;
			}
			float num3 = Run.instance.treasureRng.nextNormalizedFloat * num2;
			int num4 = 0;
			for (int j = 0; j < Prizes.Length; j++)
			{
				num4 = j;
				num3 -= Prizes[j].Weight;
				if (num3 <= 0f)
				{
					break;
				}
			}
			master.money -= num;
			wheelBusy = true;
			Spinning.Add(master);
			NetMessageExtensions.Send((INetMessage)(object)new SpinMessage
			{
				PrizeIndex = num4,
				Bet = num
			}, (NetworkDestination)1);
			((MonoBehaviour)instance).StartCoroutine(PayOut(instance, master, Prizes[num4], num));
		}

		private static IEnumerator PayOut(WheelView wheel, CharacterMaster master, Prize prize, uint bet)
		{
			yield return (object)new WaitForSeconds(4f);
			wheelBusy = false;
			Spinning.Remove(master);
			if (Object.op_Implicit((Object)(object)master))
			{
				uint num = (uint)Mathf.RoundToInt((float)bet * prize.GoldMultiplier);
				master.money += num;
				if (prize.ItemTier > 0)
				{
					DropItem(wheel, master, prize.ItemTier);
				}
				SimpleChatMessage val = new SimpleChatMessage();
				val.baseToken = prize.Token;
				val.paramTokens = new string[1] { num.ToString() };
				Chat.SendBroadcastChat((ChatMessageBase)(object)val);
			}
		}

		private static void DropItem(WheelView wheel, CharacterMaster master, int tier)
		{
			//IL_0041: 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)
			//IL_0063: 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)
			//IL_0055: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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)
			Run instance = Run.instance;
			List<PickupIndex> list = tier switch
			{
				2 => instance.availableTier2DropList, 
				1 => instance.availableTier1DropList, 
				_ => instance.availableTier3DropList, 
			};
			if (list.Count != 0)
			{
				PickupIndex val = list[instance.treasureRng.RangeInt(0, list.Count)];
				CharacterBody body = master.GetBody();
				Vector3 val2 = (Object.op_Implicit((Object)(object)body) ? (body.corePosition - wheel.GroundPosition) : Vector3.forward);
				val2.y = 0f;
				Vector3 val3 = ((Vector3)(ref val2)).normalized * 20f * 0.5f + Vector3.up * 20f;
				PickupDropletController.CreatePickupDroplet(val, wheel.GroundPosition + Vector3.up * 2f, val3);
			}
		}
	}
	internal class SpinRequest : INetMessage, ISerializableObject
	{
		public NetworkInstanceId Body;

		public int Percent;

		public void Serialize(NetworkWriter writer)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			writer.Write(Body);
			writer.Write(Percent);
		}

		public void Deserialize(NetworkReader reader)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Body = reader.ReadNetworkId();
			Percent = reader.ReadInt32();
		}

		public void OnReceived()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = NetworkServer.FindLocalObject(Body);
			if (Object.op_Implicit((Object)(object)val))
			{
				Roulette.Spin(val.GetComponent<CharacterBody>(), Percent);
			}
		}
	}
	internal class SpinMessage : INetMessage, ISerializableObject
	{
		public int PrizeIndex;

		public uint Bet;

		public void Serialize(NetworkWriter writer)
		{
			writer.Write(PrizeIndex);
			writer.Write(Bet);
		}

		public void Deserialize(NetworkReader reader)
		{
			PrizeIndex = reader.ReadInt32();
			Bet = reader.ReadUInt32();
		}

		public void OnReceived()
		{
			if (Object.op_Implicit((Object)(object)WheelView.Instance))
			{
				WheelView.Instance.Play(PrizeIndex, Bet);
			}
		}
	}
	[HarmonyPatch(typeof(ShrineBloodBehavior), "AddShrineStack")]
	internal static class BloodShrinePatch
	{
		public static bool MuteChat;

		private static void Prefix(ShrineBloodBehavior __instance, out float __state)
		{
			__state = __instance.goldToPaidHpRatio;
			if (Plugin.Enabled)
			{
				__instance.goldToPaidHpRatio = 0f;
				MuteChat = true;
			}
		}

		private static void Postfix(ShrineBloodBehavior __instance, Interactor interactor)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			MuteChat = false;
			if (!Plugin.Enabled)
			{
				return;
			}
			object obj;
			if (!Object.op_Implicit((Object)(object)interactor))
			{
				obj = null;
			}
			else
			{
				CharacterBody component = ((Component)interactor).GetComponent<CharacterBody>();
				obj = ((component != null) ? component.master : null);
			}
			CharacterMaster val = (CharacterMaster)obj;
			PurchaseInteraction component2 = ((Component)__instance).GetComponent<PurchaseInteraction>();
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)component2))
			{
				uint money = val.money;
				uint val2 = (uint)Mathf.FloorToInt((float)(money * component2.cost) / 100f);
				val2 = Math.Min(val2, (money != 0) ? (money - 1) : 0u);
				if (val2 != 0)
				{
					bool flag = Util.CheckRoll(50f, val);
					val.money = (flag ? (money + val2) : (money - val2));
					SimpleChatMessage val3 = new SimpleChatMessage();
					val3.baseToken = (flag ? "GREED_SHRINE_WIN" : "GREED_SHRINE_LOSE");
					val3.paramTokens = new string[1] { val2.ToString() };
					Chat.SendBroadcastChat((ChatMessageBase)(object)val3);
				}
			}
		}

		private static void Finalizer(ShrineBloodBehavior __instance, float __state)
		{
			__instance.goldToPaidHpRatio = __state;
			MuteChat = false;
		}
	}
	[HarmonyPatch(typeof(Chat), "SendBroadcastChat", new Type[] { typeof(ChatMessageBase) })]
	internal static class ShrineChatPatch
	{
		private static bool Prefix()
		{
			return !BloodShrinePatch.MuteChat;
		}
	}
	internal class WheelView : MonoBehaviour
	{
		public const float SpinSeconds = 4f;

		private const float CanvasSize = 512f;

		private const float WorldSize = 9f;

		private const float HeightAboveGround = 7f;

		private const float TiltDegrees = 14f;

		private const int DiscDepthLayers = 16;

		private const int HubDepthLayers = 8;

		private const float DepthStep = 3f;

		private const float HubSize = 96f;

		private const float StandWidth = 70f;

		private const float ResultSeconds = 4f;

		private static readonly int[] BetPercents = new int[4] { 10, 25, 50, 75 };

		private const int AllInPercent = 100;

		private const float MinSectorWeight = 7f;

		private const float MaxViewDistance = 150f;

		private const int FullTurns = 5;

		public static WheelView Instance;

		private RectTransform disc;

		private HGTextMeshProUGUI betLabel;

		private HGTextMeshProUGUI hintLabel;

		private HGTextMeshProUGUI resultLabel;

		private Canvas canvas;

		private float[] sectorStarts;

		private float[] sectorSizes;

		private float spinTime = -1f;

		private float startAngle;

		private float targetAngle;

		private float resultTimer;

		private int betStep;

		private bool allIn;

		private int pendingPrize;

		private uint pendingBet;

		public Vector3 GroundPosition { get; private set; }

		public static void Create(Vector3 groundPosition)
		{
			//IL_0018: 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_0023: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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)
			//IL_004d: 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)
			GameObject val = new GameObject("GreedRouletteWheel", new Type[1] { typeof(RectTransform) });
			val.transform.position = groundPosition + Vector3.up * 7f;
			val.transform.localScale = Vector3.one * 0.017578125f;
			Instance = val.AddComponent<WheelView>();
			Instance.GroundPosition = groundPosition;
			Instance.Build();
		}

		private void Build()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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)
			//IL_0097: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			canvas = ((Component)this).gameObject.AddComponent<Canvas>();
			canvas.renderMode = (RenderMode)2;
			((RectTransform)((Component)this).transform).sizeDelta = new Vector2(512f, 512f);
			MeasureSectors();
			Sprite sprite = MakeDiscSprite();
			Sprite sprite2 = MakeCircleSprite();
			float num = 398.22223f;
			for (int num2 = 16; num2 > 0; num2--)
			{
				RectTransform obj = MakeImage("Stand", ((Component)this).transform, null, 70f);
				obj.sizeDelta = new Vector2(70f, num);
				obj.anchoredPosition3D = new Vector3(0f, (0f - num) / 2f, (float)num2 * 3f);
				((Graphic)((Component)obj).GetComponent<Image>()).color = new Color(0.16f, 0.12f, 0.08f);
			}
			for (int num3 = 16; num3 > 0; num3--)
			{
				RectTransform obj2 = MakeImage("DiscDepth", ((Component)this).transform, sprite2, 512f);
				obj2.anchoredPosition3D = new Vector3(0f, 0f, (float)num3 * 3f);
				((Graphic)((Component)obj2).GetComponent<Image>()).color = new Color(0.45f, 0.32f, 0.08f);
			}
			disc = MakeImage("Disc", ((Component)this).transform, sprite, 512f);
			for (int i = 0; i < Roulette.Prizes.Length; i++)
			{
				AddPrizeLabel(i);
			}
			for (int j = 0; j < 8; j++)
			{
				RectTransform obj3 = MakeImage("Hub", ((Component)this).transform, sprite2, 96f);
				obj3.anchoredPosition3D = new Vector3(0f, 0f, (float)(-j) * 3f);
				float num4 = ((j == 7) ? 1f : 0.6f);
				((Graphic)((Component)obj3).GetComponent<Image>()).color = new Color(1f * num4, 0.78f * num4, 0.15f * num4);
			}
			MakeImage("Pointer", ((Component)this).transform, MakePointerSprite(), 80f).anchoredPosition = new Vector2(0f, 256f);
			betLabel = MakeLabel("Bet", ((Component)this).transform, 40f);
			((TMP_Text)betLabel).rectTransform.anchoredPosition = new Vector2(0f, -292f);
			((TMP_Text)betLabel).rectTransform.sizeDelta = new Vector2(512f, 56f);
			hintLabel = MakeLabel("Hint", ((Component)this).transform, 26f);
			((TMP_Text)hintLabel).rectTransform.anchoredPosition = new Vector2(0f, -340f);
			((TMP_Text)hintLabel).rectTransform.sizeDelta = new Vector2(512f, 40f);
			((TMP_Text)hintLabel).text = "[1] -   [2] +   [3] ВА-БАНК   [4] КРУТИТЬ";
			resultLabel = MakeLabel("Result", ((Component)this).transform, 46f);
			((TMP_Text)resultLabel).rectTransform.anchoredPosition = new Vector2(0f, 326f);
			((TMP_Text)resultLabel).rectTransform.sizeDelta = new Vector2(512f, 64f);
		}

		private void MeasureSectors()
		{
			Roulette.Prize[] prizes = Roulette.Prizes;
			sectorStarts = new float[prizes.Length];
			sectorSizes = new float[prizes.Length];
			float num = 0f;
			Roulette.Prize[] array = prizes;
			for (int i = 0; i < array.Length; i++)
			{
				Roulette.Prize prize = array[i];
				num += Mathf.Max(prize.Weight, 7f);
			}
			float num2 = 0f;
			for (int j = 0; j < prizes.Length; j++)
			{
				sectorStarts[j] = num2;
				sectorSizes[j] = Mathf.Max(prizes[j].Weight, 7f) / num * 360f;
				num2 += sectorSizes[j];
			}
		}

		private void AddPrizeLabel(int index)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			float num = sectorStarts[index] + sectorSizes[index] / 2f;
			HGTextMeshProUGUI obj = MakeLabel("Prize", (Transform)(object)disc, 30f);
			((TMP_Text)obj).text = Roulette.Prizes[index].Label;
			RectTransform rectTransform = ((TMP_Text)obj).rectTransform;
			rectTransform.sizeDelta = new Vector2(150f, 40f);
			float num2 = num * (MathF.PI / 180f);
			rectTransform.anchoredPosition = new Vector2(Mathf.Sin(num2), Mathf.Cos(num2)) * 512f * 0.31f;
			((Transform)rectTransform).localEulerAngles = new Vector3(0f, 0f, 90f - num);
		}

		private static RectTransform MakeImage(string name, Transform parent, Sprite sprite, float size)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent(parent, false);
			val2.sizeDelta = new Vector2(size, size);
			Image obj = val.AddComponent<Image>();
			obj.sprite = sprite;
			((Graphic)obj).raycastTarget = false;
			return val2;
		}

		private static HGTextMeshProUGUI MakeLabel(string name, Transform parent, float size)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			HGTextMeshProUGUI obj = val.AddComponent<HGTextMeshProUGUI>();
			((TMP_Text)obj).fontSize = size;
			((TMP_Text)obj).alignment = (TextAlignmentOptions)514;
			((TMP_Text)obj).enableWordWrapping = false;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		private Sprite MakeDiscSprite()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00cb: 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_012f: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			Color val = default(Color);
			((Color)(ref val))..ctor(1f, 0.78f, 0.15f);
			Texture2D val2 = new Texture2D(512, 512, (TextureFormat)4, false);
			Roulette.Prize[] prizes = Roulette.Prizes;
			for (int i = 0; i < 512; i++)
			{
				for (int j = 0; j < 512; j++)
				{
					float num = ((float)j + 0.5f) / 512f * 2f - 1f;
					float num2 = ((float)i + 0.5f) / 512f * 2f - 1f;
					float num3 = Mathf.Sqrt(num * num + num2 * num2);
					float num4 = Mathf.Repeat(Mathf.Atan2(num, num2) * 57.29578f, 360f);
					Color val3 = Color.clear;
					if (num3 < 1f)
					{
						val3 = val;
					}
					if (num3 < 0.94f)
					{
						int num5 = FindSector(num4);
						val3 = prizes[num5].Color;
						if (Mathf.Min(num4 - sectorStarts[num5], sectorStarts[num5] + sectorSizes[num5] - num4) * (MathF.PI / 180f) * num3 < 0.008f)
						{
							val3 = val;
						}
					}
					if (num3 < 0.14f)
					{
						((Color)(ref val3))..ctor(0.12f, 0.1f, 0.08f);
					}
					val2.SetPixel(j, i, val3);
				}
			}
			val2.Apply();
			return Sprite.Create(val2, new Rect(0f, 0f, 512f, 512f), new Vector2(0.5f, 0.5f));
		}

		private int FindSector(float angle)
		{
			for (int num = sectorStarts.Length - 1; num > 0; num--)
			{
				if (angle >= sectorStarts[num])
				{
					return num;
				}
			}
			return 0;
		}

		private static Sprite MakeCircleSprite()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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)
			Texture2D val = new Texture2D(256, 256, (TextureFormat)4, false);
			for (int i = 0; i < 256; i++)
			{
				for (int j = 0; j < 256; j++)
				{
					float num = ((float)j + 0.5f) / 256f * 2f - 1f;
					float num2 = ((float)i + 0.5f) / 256f * 2f - 1f;
					val.SetPixel(j, i, (num * num + num2 * num2 < 1f) ? Color.white : Color.clear);
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 256f, 256f), new Vector2(0.5f, 0.5f));
		}

		private static Sprite MakePointerSprite()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = ((float)i + 0.5f) / 64f * 0.5f;
					bool flag = Mathf.Abs(((float)j + 0.5f) / 64f - 0.5f) < num;
					val.SetPixel(j, i, flag ? Color.white : Color.clear);
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f));
		}

		public void Play(int prizeIndex, uint bet)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			float num = sectorSizes[prizeIndex] * 0.15f;
			float num2 = sectorStarts[prizeIndex] + Random.Range(num, sectorSizes[prizeIndex] - num);
			startAngle = Mathf.Repeat(((Transform)disc).localEulerAngles.z, 360f);
			targetAngle = startAngle + 1800f + Mathf.Repeat(num2 - startAngle, 360f);
			spinTime = 0f;
			pendingPrize = prizeIndex;
			pendingBet = bet;
			((TMP_Text)resultLabel).text = "";
		}

		private void ShowResult()
		{
			Roulette.Prize prize = Roulette.Prizes[pendingPrize];
			uint num = (uint)Mathf.RoundToInt((float)pendingBet * prize.GoldMultiplier);
			((TMP_Text)resultLabel).text = ((prize.ItemTier > 0) ? (prize.Label + " ПРЕДМЕТ") : ((num != 0) ? ("+" + num) : "ПУСТО"));
			resultTimer = 4f;
		}

		private void Update()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//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_00f6: Unknown result type (might be due to invalid IL or missing references)
			Camera val = FindCamera();
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			Vector3 val2 = ((Component)this).transform.position - ((Component)val).transform.position;
			((Behaviour)canvas).enabled = ((Vector3)(ref val2)).magnitude < 150f;
			val2.y = 0f;
			if (((Vector3)(ref val2)).sqrMagnitude > 0.01f)
			{
				((Component)this).transform.rotation = Quaternion.LookRotation(val2) * Quaternion.Euler(14f, 0f, 0f);
			}
			if (spinTime >= 0f)
			{
				spinTime += Time.deltaTime;
				float num = Mathf.Clamp01(spinTime / 4f);
				float num2 = 1f - Mathf.Pow(1f - num, 3f);
				((Transform)disc).localEulerAngles = new Vector3(0f, 0f, Mathf.Lerp(startAngle, targetAngle, num2));
				if (num >= 1f)
				{
					spinTime = -1f;
					ShowResult();
				}
			}
			if (resultTimer > 0f)
			{
				resultTimer -= Time.deltaTime;
				if (resultTimer <= 0f)
				{
					((TMP_Text)resultLabel).text = "";
				}
			}
			UpdateControls();
		}

		private void UpdateControls()
		{
			//IL_00a5: 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_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser();
			CharacterBody val = ((firstLocalUser != null) ? firstLocalUser.cachedBody : null);
			CharacterMaster val2 = ((firstLocalUser != null) ? firstLocalUser.cachedMaster : null);
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)Run.instance))
			{
				return;
			}
			int percent = (allIn ? 100 : BetPercents[betStep]);
			uint num = Roulette.BetFor(val2.money, percent);
			((TMP_Text)betLabel).text = (allIn ? "ВА-БАНК 100%" : (percent + "%")) + ": $$$ " + num + " $$$";
			bool flag = Vector3.Distance(val.corePosition, GroundPosition) <= 25f;
			((Behaviour)hintLabel).enabled = flag;
			if (flag && !(spinTime >= 0f) && !ChatBox.IsActive && !PauseManager.isPaused)
			{
				if (Input.GetKeyDown((KeyCode)49))
				{
					allIn = false;
					betStep = Mathf.Max(betStep - 1, 0);
				}
				if (Input.GetKeyDown((KeyCode)50))
				{
					allIn = false;
					betStep = Mathf.Min(betStep + 1, BetPercents.Length - 1);
				}
				if (Input.GetKeyDown((KeyCode)51))
				{
					allIn = !allIn;
				}
				if (Input.GetKeyDown((KeyCode)52) && num != 0)
				{
					NetMessageExtensions.Send((INetMessage)(object)new SpinRequest
					{
						Body = ((NetworkBehaviour)val).netId,
						Percent = percent
					}, (NetworkDestination)2);
				}
			}
		}

		private static Camera FindCamera()
		{
			ReadOnlyCollection<CameraRigController> readOnlyInstancesList = CameraRigController.readOnlyInstancesList;
			if (readOnlyInstancesList.Count <= 0)
			{
				return null;
			}
			return readOnlyInstancesList[0].sceneCam;
		}

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