Decompiled source of REPOConomyPlus v2.0.0

plugins/REPOConomyPlus.dll

Decompiled 16 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using Newtonsoft.Json;
using Photon.Pun;
using Photon.Realtime;
using REPOConomyMod;
using REPOConomyMod.Config;
using REPOConomyMod.Menu;
using REPOConomyMod.Stats;
using REPOConomyPlus;
using TMPro;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("REPOConomyPlus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("REPOConomyPlus")]
[assembly: AssemblyTitle("REPOConomyPlus")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 REPOConomyPlus
{
	public static class LevelScalingImprovements
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static class Patch_LevelGenerator_TileGeneration_Transpiler
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e7: Expected O, but got Unknown
				//IL_0203: Unknown result type (might be due to invalid IL or missing references)
				//IL_020d: Expected O, but got Unknown
				//IL_0227: Unknown result type (might be due to invalid IL or missing references)
				//IL_0231: Expected O, but got Unknown
				//IL_0246: Unknown result type (might be due to invalid IL or missing references)
				//IL_0250: Expected O, but got Unknown
				//IL_026c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0276: Expected O, but got Unknown
				//IL_0290: Unknown result type (might be due to invalid IL or missing references)
				//IL_029a: Expected O, but got Unknown
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				if (list.Count <= 20)
				{
					REPOConomyPlugin.Logger.LogError((object)"[Transpiler] Less than 20 instructions found - cannot patch!");
					return list;
				}
				int num = -1;
				int num2 = -1;
				for (int i = 3; i < list.Count - 1; i++)
				{
					if (list[i].opcode == OpCodes.Ldfld && list[i].operand is FieldInfo fieldInfo && fieldInfo.Name == "ModuleAmount" && i + 1 < list.Count && list[i + 1].opcode == OpCodes.Ldc_I4_3)
					{
						num = i - 3;
						REPOConomyPlugin.Logger.LogInfo((object)$"[Transpiler] Found ModuleAmount insert point at index {num}");
						break;
					}
				}
				for (int j = 1; j < list.Count - 4; j++)
				{
					if (list[j].opcode == OpCodes.Ldarg_0 && j + 1 < list.Count && list[j + 1].opcode == OpCodes.Ldc_I4_M1 && j + 4 < list.Count && list[j + 4].opcode == OpCodes.Ldfld && list[j + 4].operand is FieldInfo fieldInfo2 && fieldInfo2.Name == "ExtractionAmount")
					{
						num2 = j - 1;
						REPOConomyPlugin.Logger.LogInfo((object)$"[Transpiler] Found ExtractionAmount insert point at index {num2}");
						break;
					}
				}
				if (num == -1)
				{
					REPOConomyPlugin.Logger.LogError((object)"[Transpiler] Failed to find ModuleAmount insertion point!");
					return list;
				}
				if (num2 == -1)
				{
					REPOConomyPlugin.Logger.LogError((object)"[Transpiler] Failed to find ExtractionAmount insertion point!");
					return list;
				}
				List<CodeInstruction> list2 = new List<CodeInstruction>
				{
					new CodeInstruction(OpCodes.Ldloc_1, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(LevelScalingImprovements), "GetNewModuleCount", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(LevelGenerator), "ModuleAmount"))
				};
				list.InsertRange(num, list2);
				List<CodeInstruction> collection = new List<CodeInstruction>
				{
					new CodeInstruction(OpCodes.Ldloc_1, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(LevelScalingImprovements), "GetNewExtractionCount", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(LevelGenerator), "ExtractionAmount"))
				};
				list.InsertRange(num2 + list2.Count, collection);
				REPOConomyPlugin.Logger.LogInfo((object)"[Transpiler] Successfully patched TileGeneration!");
				return list;
			}
		}

		private static int GetVanillaModuleAmount(int levelsCompleted)
		{
			int num = Mathf.Min(5 + levelsCompleted, 10);
			if (levelsCompleted >= 10)
			{
				num += Mathf.Min(levelsCompleted - 9, 5);
			}
			return num;
		}

		private static int GetVanillaExtractionAmount(int levelsCompleted)
		{
			int vanillaModuleAmount = GetVanillaModuleAmount(levelsCompleted);
			if (vanillaModuleAmount >= 15)
			{
				return 4;
			}
			if (vanillaModuleAmount >= 10)
			{
				return 3;
			}
			if (vanillaModuleAmount >= 8)
			{
				return 2;
			}
			if (vanillaModuleAmount >= 6)
			{
				return 1;
			}
			return 0;
		}

		public static int GetScaledModuleAmount(int levelsCompleted)
		{
			if (!REPOConfig.EnableLevelScaling.Value)
			{
				return GetVanillaModuleAmount(levelsCompleted);
			}
			int num = Mathf.Min(levelsCompleted, REPOConfig.LevelScalingMaxModulesLevel.Value);
			int value = REPOConfig.LevelScalingModulesInterval.Value;
			float num2 = REPOConfig.LevelScalingModulesPerInterval.Value;
			if (REPOConfig.EnableMultiplicativeScaling.Value)
			{
				int num3 = Mathf.FloorToInt((float)(num + 1) / (float)value);
				int num4 = 0;
				for (int i = 0; i < num3; i++)
				{
					num4 += (int)Mathf.Pow(num2, (float)i);
				}
				return REPOConfig.LevelScalingMinModules.Value + num4;
			}
			return REPOConfig.LevelScalingMinModules.Value + Mathf.FloorToInt((float)(num + 1) / (float)value) * (int)num2;
		}

		public static int GetScaledExtractionAmount(int levelsCompleted)
		{
			if (!REPOConfig.EnableLevelScaling.Value)
			{
				return GetVanillaExtractionAmount(levelsCompleted);
			}
			int value = REPOConfig.LevelScalingExtractionsInterval.Value;
			int value2 = REPOConfig.LevelScalingExtractionsPerInterval.Value;
			if (REPOConfig.EnableMultiplicativeScaling.Value)
			{
				int num = (levelsCompleted + 1) / value;
				int num2 = 0;
				for (int i = 0; i < num; i++)
				{
					num2 += (int)Mathf.Pow((float)value2, (float)i);
				}
				return Mathf.Min(REPOConfig.LevelScalingBaseExtractions.Value + num2, REPOConfig.LevelScalingMaxExtractions.Value);
			}
			return Mathf.Min(REPOConfig.LevelScalingBaseExtractions.Value + (levelsCompleted + 1) / value * value2, REPOConfig.LevelScalingMaxExtractions.Value);
		}

		public static float GetScaledHaulMultiplier(int levelsCompleted)
		{
			if (!REPOConfig.EnableLevelScaling.Value)
			{
				return 0.7f;
			}
			int num = Mathf.Min(levelsCompleted, REPOConfig.LevelScalingMaxHaulLevel.Value);
			if (REPOConfig.EnableMultiplicativeScaling.Value)
			{
				return Mathf.Min(REPOConfig.LevelScalingBaseHaulMultiplier.Value * Mathf.Pow(1f + REPOConfig.LevelScalingHaulIncreasePerLevel.Value, (float)num), REPOConfig.LevelScalingMaxHaulMultiplier.Value);
			}
			return Mathf.Min(REPOConfig.LevelScalingBaseHaulMultiplier.Value + (float)num * REPOConfig.LevelScalingHaulIncreasePerLevel.Value, REPOConfig.LevelScalingMaxHaulMultiplier.Value);
		}

		private static int GetNewModuleCount()
		{
			if ((Object)(object)RunManager.instance == (Object)null)
			{
				return 6;
			}
			if (SemiFunc.RunIsArena() || SemiFunc.RunIsShop() || SemiFunc.MenuLevel() || SemiFunc.RunIsLobby())
			{
				return 6;
			}
			int levelsCompleted = RunManager.instance.levelsCompleted;
			int num = GetScaledModuleAmount(levelsCompleted);
			if (REPOEventManager.CrampedFacility)
			{
				num = Mathf.Min(num + 4, 25);
			}
			if (REPOEventManager.SpaciousFacility)
			{
				num = Mathf.Max(num - 3, 2);
			}
			REPOConomyPlugin.Logger.LogInfo((object)$"[LevelScaling] New ModuleCount: {num} for level {levelsCompleted + 1}");
			return num;
		}

		private static int GetNewExtractionCount()
		{
			if ((Object)(object)RunManager.instance == (Object)null)
			{
				return 1;
			}
			if (SemiFunc.RunIsArena() || SemiFunc.RunIsShop() || SemiFunc.MenuLevel() || SemiFunc.RunIsLobby())
			{
				return 0;
			}
			int levelsCompleted = RunManager.instance.levelsCompleted;
			int num = GetScaledExtractionAmount(levelsCompleted);
			if (REPOEventManager.ManyExtractions)
			{
				num = 9;
			}
			REPOConomyPlugin.Logger.LogInfo((object)$"[LevelScaling] New ExtractionCount: {num} for level {levelsCompleted + 1}");
			return num;
		}
	}
	[HarmonyPatch(typeof(RoundDirector), "StartRoundLogic")]
	public static class Patch_RoundDirector_StartRoundLogic
	{
		public static bool IsHaulScaled;

		private static void Prefix(RoundDirector __instance, ref int value)
		{
			if (SemiFunc.IsMasterClientOrSingleplayer() && !((Object)(object)RunManager.instance == (Object)null) && !((Object)(object)__instance == (Object)null) && !SemiFunc.RunIsArena() && !SemiFunc.RunIsShop() && !SemiFunc.MenuLevel() && !SemiFunc.RunIsLobby())
			{
				if (IsHaulScaled)
				{
					REPOConomyPlugin.Logger.LogInfo((object)"[LevelScaling] Haul already scaled, skipping double apply.");
				}
				else if (REPOConfig.EnableLevelScaling.Value)
				{
					float scaledHaulMultiplier = LevelScalingImprovements.GetScaledHaulMultiplier(RunManager.instance.levelsCompleted);
					float num = value;
					value = Mathf.RoundToInt(num * (scaledHaulMultiplier / 0.7f));
					IsHaulScaled = true;
					REPOConomyPlugin.Logger.LogInfo((object)$"[LevelScaling] Haul goal scaled: {value} (original: {num}, multiplier: {scaledHaulMultiplier:F2})");
				}
			}
		}
	}
}
namespace REPOConomyMod
{
	public sealed class ChallengeDefinition
	{
		public string id;

		public string name;

		public string description;

		public REPOConomyPlugin.EconomyType economy;

		public REPOConomyPlugin.EconomyType rewardEconomy;

		public string rewardModifierId;

		public ShopEconomyType rewardShopEconomy;

		public string shopEconomy;

		public string[] modifierIds;

		public Color color;
	}
	public static class ChallengeManager
	{
		private sealed class ChallengeSaveMeta
		{
			public string challengeId;

			public int targetLevel;

			public string challengeName;
		}

		[CompilerGenerated]
		private sealed class <ReturnToMainMenuAfterDelay>d__52 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Color popupColor;

			public string popupBody;

			private int <i>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ReturnToMainMenuAfterDelay>d__52(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				//IL_0169: Unknown result type (might be due to invalid IL or missing references)
				//IL_0173: Expected O, but got Unknown
				//IL_019b: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0137: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSecondsRealtime(3.5f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					try
					{
						if ((Object)(object)RunManager.instance == (Object)null)
						{
							return false;
						}
						if (!SemiFunc.IsMasterClientOrSingleplayer())
						{
							return false;
						}
						if ((Object)(object)StatsManager.instance != (Object)null)
						{
							FieldInfo fieldInfo = AccessTools.Field(typeof(StatsManager), "saveFileCurrent");
							string text = fieldInfo?.GetValue(StatsManager.instance) as string;
							if (!string.IsNullOrWhiteSpace(text))
							{
								StatsManager.instance.SaveFileDelete(text);
								fieldInfo?.SetValue(StatsManager.instance, string.Empty);
							}
						}
						RunManager.instance.ResetProgress();
						RunManager.instance.ChangeLevel(false, false, (ChangeLevelType)4);
					}
					catch (Exception ex2)
					{
						REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Failed to return to main menu: " + ex2.Message));
						return false;
					}
					<i>5__2 = 0;
					goto IL_0159;
				case 2:
					<>1__state = -1;
					<i>5__2++;
					goto IL_0159;
				case 3:
					{
						<>1__state = -1;
						try
						{
							if ((Object)(object)MenuManager.instance != (Object)null)
							{
								MenuManager.instance.PagePopUp("Challenge Complete", popupColor, popupBody, "OK", false);
							}
						}
						catch (Exception ex)
						{
							REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Failed to show completion popup: " + ex.Message));
						}
						return false;
					}
					IL_0159:
					if (<i>5__2 < 120 && (!((Object)(object)MenuManager.instance != (Object)null) || !MenuManager.instance.PageCheck((MenuPageIndex)0)))
					{
						<>2__current = (object)new WaitForSecondsRealtime(0.1f);
						<>1__state = 2;
						return true;
					}
					<>2__current = (object)new WaitForSecondsRealtime(0.35f);
					<>1__state = 3;
					return true;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static bool activeChallengeProgressBlocked;

		private const string ChallengeSaveNamePrefix = "Challenge - ";

		public static readonly int[] Targets = new int[3] { 10, 25, 50 };

		public static readonly ChallengeDefinition[] Challenges = new ChallengeDefinition[7]
		{
			new ChallengeDefinition
			{
				id = "glass_bank",
				name = "Glass Bank",
				description = "High value, fragile loot, and explosive mistakes.",
				economy = REPOConomyPlugin.EconomyType.GoldenHour,
				rewardEconomy = REPOConomyPlugin.EconomyType.GlassBankDividend,
				rewardModifierId = "glass_dividend",
				rewardShopEconomy = ShopEconomyType.CollectorsVaultSale,
				shopEconomy = "LuxuryTax",
				modifierIds = new string[3] { "value_lottery", "valuables_fragile", "explosive_valuables" },
				color = new Color(1f, 0.78f, 0.22f)
			},
			new ChallengeDefinition
			{
				id = "pit_contract",
				name = "Pit Contract",
				description = "Enemies survive pits while extraction becomes messy.",
				economy = REPOConomyPlugin.EconomyType.BlackMarketSurge,
				rewardEconomy = REPOConomyPlugin.EconomyType.PitContractInsurance,
				rewardModifierId = "pit_insurance",
				rewardShopEconomy = ShopEconomyType.HazardPayMarket,
				shopEconomy = "SupplyShortage",
				modifierIds = new string[3] { "pit_immunity", "single_extraction", "heavy_burden" },
				color = new Color(0.7f, 0.45f, 1f)
			},
			new ChallengeDefinition
			{
				id = "storm_runner",
				name = "Storm Runner",
				description = "Fast bodies, unstable movement, constant pressure.",
				economy = REPOConomyPlugin.EconomyType.Turbulence,
				rewardEconomy = REPOConomyPlugin.EconomyType.StormRunnerSurge,
				rewardModifierId = "storm_surge",
				rewardShopEconomy = ShopEconomyType.AdrenalineClearance,
				shopEconomy = "EnergySurcharge",
				modifierIds = new string[3] { "speed_demons", "explosive_tumble", "slippery_hands" },
				color = new Color(0.25f, 0.9f, 1f)
			},
			new ChallengeDefinition
			{
				id = "silent_debt",
				name = "Silent Debt",
				description = "Darkness, quiet danger, and punishing market swings.",
				economy = REPOConomyPlugin.EconomyType.MarketEclipse,
				rewardEconomy = REPOConomyPlugin.EconomyType.SilentDebtEclipse,
				rewardModifierId = "debt_silence",
				rewardShopEconomy = ShopEconomyType.BlackoutWholesale,
				shopEconomy = "BlackoutTariff",
				modifierIds = new string[3] { "total_darkness", "too_quiet", "player_deaf" },
				color = new Color(0.35f, 0.36f, 0.46f)
			},
			new ChallengeDefinition
			{
				id = "clone_lottery",
				name = "Clone Lottery",
				description = "Enemies return, values swing, and greed gets loud.",
				economy = REPOConomyPlugin.EconomyType.JackpotMirage,
				rewardEconomy = REPOConomyPlugin.EconomyType.CloneLotteryJackpot,
				rewardModifierId = "lucky_echoes",
				rewardShopEconomy = ShopEconomyType.DuplicateDiscount,
				shopEconomy = "GamblersDream",
				modifierIds = new string[3] { "shadow_clones", "value_lottery", "found_map" },
				color = new Color(0.35f, 1f, 0.55f)
			},
			new ChallengeDefinition
			{
				id = "magnet_shift",
				name = "Magnet Shift",
				description = "Moving loot, strange physics, and cart pressure.",
				economy = REPOConomyPlugin.EconomyType.ValueVortex,
				rewardEconomy = REPOConomyPlugin.EconomyType.MagnetShiftVortex,
				rewardModifierId = "magnetic_margin",
				rewardShopEconomy = ShopEconomyType.PolarizedPricing,
				shopEconomy = "SplitMarket",
				modifierIds = new string[3] { "magnetic_valuables", "runaway_valuables", "scale_in_cart" },
				color = new Color(0.95f, 0.35f, 0.85f)
			},
			new ChallengeDefinition
			{
				id = "last_invoice",
				name = "Last Invoice",
				description = "A brutal final mix of damage, explosions, and bad prices.",
				economy = REPOConomyPlugin.EconomyType.MarketKraken,
				rewardEconomy = REPOConomyPlugin.EconomyType.LastInvoiceJudgement,
				rewardModifierId = "final_notice",
				rewardShopEconomy = ShopEconomyType.JudgementLiquidation,
				shopEconomy = "HyperInflation",
				modifierIds = new string[3] { "kamikaze_enemies", "double_enemy_damage", "shared_pain" },
				color = new Color(1f, 0.25f, 0.18f)
			}
		};

		public static bool HasActiveChallenge
		{
			get
			{
				REPOStatsManager rEPOStatsManager = REPOStatsManager.EnsureInstance();
				if ((Object)(object)rEPOStatsManager != (Object)null)
				{
					return !string.IsNullOrWhiteSpace(rEPOStatsManager.stats.activeChallengeId);
				}
				return false;
			}
		}

		public static ChallengeDefinition ActiveChallenge
		{
			get
			{
				REPOStatsManager rEPOStatsManager = REPOStatsManager.EnsureInstance();
				if ((Object)(object)rEPOStatsManager == (Object)null)
				{
					return null;
				}
				return GetChallenge(rEPOStatsManager.stats.activeChallengeId);
			}
		}

		public static int ActiveTarget
		{
			get
			{
				REPOStatsManager rEPOStatsManager = REPOStatsManager.EnsureInstance();
				if (!((Object)(object)rEPOStatsManager != (Object)null))
				{
					return 0;
				}
				return rEPOStatsManager.stats.activeChallengeTarget;
			}
		}

		public static bool ActiveChallengeProgressBlocked
		{
			get
			{
				if (HasActiveChallenge)
				{
					return activeChallengeProgressBlocked;
				}
				return false;
			}
		}

		public static ChallengeDefinition GetChallenge(string id)
		{
			if (string.IsNullOrWhiteSpace(id))
			{
				return null;
			}
			return Challenges.FirstOrDefault((ChallengeDefinition c) => string.Equals(c.id, id, StringComparison.OrdinalIgnoreCase));
		}

		public static int GetCompletedTierCount(string challengeId)
		{
			REPOStatsManager rEPOStatsManager = REPOStatsManager.EnsureInstance();
			if ((Object)(object)rEPOStatsManager == (Object)null || string.IsNullOrWhiteSpace(challengeId))
			{
				return 0;
			}
			if (!rEPOStatsManager.stats.challengeCompletedTiers.TryGetValue(challengeId, out var value))
			{
				return 0;
			}
			return Mathf.Clamp(value, 0, Targets.Length);
		}

		public static int GetTotalCompletedTiers()
		{
			REPOStatsManager rEPOStatsManager = REPOStatsManager.EnsureInstance();
			if ((Object)(object)rEPOStatsManager == (Object)null)
			{
				return 0;
			}
			return rEPOStatsManager.stats.challengeCompletedTiers.Values.Sum((int v) => Mathf.Clamp(v, 0, Targets.Length));
		}

		public static int GetFullyCompletedChallenges()
		{
			return Challenges.Count((ChallengeDefinition c) => GetCompletedTierCount(c.id) >= Targets.Length);
		}

		public static bool AreAllChallengesCompleted()
		{
			return GetFullyCompletedChallenges() >= Challenges.Length;
		}

		public static bool IsChallengeRewardEconomy(REPOConomyPlugin.EconomyType economy)
		{
			return Challenges.Any((ChallengeDefinition c) => c.rewardEconomy == economy);
		}

		public static bool IsRewardEconomyUnlocked(REPOConomyPlugin.EconomyType economy)
		{
			ChallengeDefinition challengeDefinition = Challenges.FirstOrDefault((ChallengeDefinition c) => c.rewardEconomy == economy);
			if (challengeDefinition != null)
			{
				return GetCompletedTierCount(challengeDefinition.id) >= Targets.Length;
			}
			return false;
		}

		public static bool IsChallengeRewardModifier(string modifierId)
		{
			return Challenges.Any((ChallengeDefinition c) => string.Equals(c.rewardModifierId, modifierId, StringComparison.OrdinalIgnoreCase));
		}

		public static bool IsRewardModifierUnlocked(string modifierId)
		{
			ChallengeDefinition challengeDefinition = Challenges.FirstOrDefault((ChallengeDefinition c) => string.Equals(c.rewardModifierId, modifierId, StringComparison.OrdinalIgnoreCase));
			if (challengeDefinition != null)
			{
				return GetCompletedTierCount(challengeDefinition.id) >= Targets.Length;
			}
			return false;
		}

		public static bool IsChallengeRewardShopEconomy(ShopEconomyType shopEconomy)
		{
			return Challenges.Any((ChallengeDefinition c) => c.rewardShopEconomy == shopEconomy);
		}

		public static bool IsRewardShopEconomyUnlocked(ShopEconomyType shopEconomy)
		{
			ChallengeDefinition challengeDefinition = Challenges.FirstOrDefault((ChallengeDefinition c) => c.rewardShopEconomy == shopEconomy);
			if (challengeDefinition != null)
			{
				return GetCompletedTierCount(challengeDefinition.id) >= Targets.Length;
			}
			return false;
		}

		public static bool IsRewardPackUnlocked(ChallengeDefinition challenge)
		{
			if (challenge != null)
			{
				return GetCompletedTierCount(challenge.id) >= Targets.Length;
			}
			return false;
		}

		public static string GetRewardSummary(ChallengeDefinition challenge)
		{
			if (challenge == null)
			{
				return string.Empty;
			}
			return $"{challenge.rewardModifierId} (Modifier), {challenge.rewardEconomy} (Economy), {challenge.rewardShopEconomy} (Shop)";
		}

		public static void StartChallenge(string challengeId, int targetLevel)
		{
			ChallengeDefinition challenge = GetChallenge(challengeId);
			if (challenge != null)
			{
				REPOStatsManager rEPOStatsManager = REPOStatsManager.EnsureInstance();
				if (!((Object)(object)rEPOStatsManager == (Object)null))
				{
					rEPOStatsManager.stats.activeChallengeId = challenge.id;
					rEPOStatsManager.stats.activeChallengeTarget = Mathf.Clamp(targetLevel, Targets[0], Targets[Targets.Length - 1]);
					rEPOStatsManager.stats.activeChallengeRunStarted = false;
					rEPOStatsManager.stats.activeChallengeRunSaveKey = string.Empty;
					activeChallengeProgressBlocked = false;
					rEPOStatsManager.SaveStats();
					REPOConomyPlugin.Logger.LogInfo((object)$"[Challenges] Started {challenge.id} target {rEPOStatsManager.stats.activeChallengeTarget}");
					REPOConomyNetworkHandler.SyncBlackMarketToClients();
				}
			}
		}

		public static void ClearActiveChallenge()
		{
			REPOStatsManager rEPOStatsManager = REPOStatsManager.EnsureInstance();
			if (!((Object)(object)rEPOStatsManager == (Object)null))
			{
				rEPOStatsManager.stats.activeChallengeId = string.Empty;
				rEPOStatsManager.stats.activeChallengeTarget = 0;
				rEPOStatsManager.stats.activeChallengeRunStarted = false;
				rEPOStatsManager.stats.activeChallengeRunSaveKey = string.Empty;
				activeChallengeProgressBlocked = false;
				rEPOStatsManager.SaveStats();
				REPOConomyNetworkHandler.SyncBlackMarketToClients();
			}
		}

		public static void OnLevelStarted(int currentLevel)
		{
			REPOStatsManager rEPOStatsManager = REPOStatsManager.EnsureInstance();
			if ((Object)(object)rEPOStatsManager == (Object)null)
			{
				return;
			}
			ChallengeDefinition activeChallenge = ActiveChallenge;
			int activeTarget = ActiveTarget;
			if (activeChallenge == null || activeTarget <= 0)
			{
				return;
			}
			REPOConomyNetworkHandler.SyncBlackMarketToClients();
			string currentSaveKeyForChallenge = REPOBlackMarketManager.GetCurrentSaveKeyForChallenge();
			bool flag = !string.IsNullOrWhiteSpace(rEPOStatsManager.stats.activeChallengeRunSaveKey) && string.Equals(rEPOStatsManager.stats.activeChallengeRunSaveKey, currentSaveKeyForChallenge, StringComparison.OrdinalIgnoreCase);
			if (!rEPOStatsManager.stats.activeChallengeRunStarted || !flag)
			{
				if (currentLevel > 1)
				{
					ChallengeSaveMeta challengeSaveMeta = LoadChallengeSaveMeta(currentSaveKeyForChallenge);
					if (challengeSaveMeta == null || !string.Equals(challengeSaveMeta.challengeId, activeChallenge.id, StringComparison.OrdinalIgnoreCase) || challengeSaveMeta.targetLevel != activeTarget)
					{
						activeChallengeProgressBlocked = true;
						REPOConomyPlugin.Logger.LogInfo((object)$"[Challenges] {activeChallenge.id} is waiting for a fresh run before progress can count. Current level: {currentLevel}, save: {currentSaveKeyForChallenge}");
						REPOConomyNetworkHandler.SyncBlackMarketToClients();
						return;
					}
					activeChallengeProgressBlocked = false;
					rEPOStatsManager.stats.activeChallengeRunStarted = true;
					rEPOStatsManager.stats.activeChallengeRunSaveKey = currentSaveKeyForChallenge;
					rEPOStatsManager.SaveStats();
					EnforceCurrentChallengeSaveName(activeChallenge);
					REPOConomyPlugin.Logger.LogInfo((object)$"[Challenges] Continuing marked challenge save {currentSaveKeyForChallenge} for {activeChallenge.id} target {activeTarget}");
					REPOConomyNetworkHandler.SyncBlackMarketToClients();
				}
				else
				{
					activeChallengeProgressBlocked = false;
					rEPOStatsManager.stats.activeChallengeRunStarted = true;
					rEPOStatsManager.stats.activeChallengeRunSaveKey = currentSaveKeyForChallenge;
					MarkCurrentSaveForChallenge(activeChallenge, rEPOStatsManager.stats.activeChallengeTarget);
					rEPOStatsManager.SaveStats();
				}
			}
			else if (activeChallengeProgressBlocked)
			{
				activeChallengeProgressBlocked = false;
				EnforceCurrentChallengeSaveName(activeChallenge);
				REPOConomyNetworkHandler.SyncBlackMarketToClients();
			}
			else
			{
				EnforceCurrentChallengeSaveName(activeChallenge);
			}
			if (currentLevel < activeTarget)
			{
				return;
			}
			int num = Array.IndexOf(Targets, activeTarget) + 1;
			if (num > 0)
			{
				int completedTierCount = GetCompletedTierCount(activeChallenge.id);
				if (num > completedTierCount + 1)
				{
					REPOConomyPlugin.Logger.LogWarning((object)$"[Challenges] Ignored out-of-order completion for {activeChallenge.id}: tier {num}, previous {completedTierCount}");
				}
				else if (num > completedTierCount)
				{
					rEPOStatsManager.stats.challengeCompletedTiers[activeChallenge.id] = num;
					rEPOStatsManager.stats.totalChallengeTierCompletions++;
					rEPOStatsManager.stats.activeChallengeId = string.Empty;
					rEPOStatsManager.stats.activeChallengeTarget = 0;
					rEPOStatsManager.stats.activeChallengeRunStarted = false;
					rEPOStatsManager.stats.activeChallengeRunSaveKey = string.Empty;
					activeChallengeProgressBlocked = false;
					DeleteChallengeSaveMeta(REPOBlackMarketManager.GetCurrentSaveKeyForChallenge());
					rEPOStatsManager.SaveStats();
					REPOConomyNetworkHandler.SyncBlackMarketToClients();
					REPOConomyNetworkHandler.SyncChallengeCompletionToClients(activeChallenge.id, num);
					ShowCompletionMessage(activeChallenge, num);
					TryAnnounceChallengeReward(activeChallenge, num);
					ShowCompletionPopupAndReturnToMainMenu(activeChallenge, num);
				}
			}
		}

		public static void ApplySyncedCompletion(string challengeId, int completedTier)
		{
			ChallengeDefinition challenge = GetChallenge(challengeId);
			if (challenge == null)
			{
				REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Ignored synced unknown challenge: " + challengeId));
				return;
			}
			completedTier = Mathf.Clamp(completedTier, 1, Targets.Length);
			REPOStatsManager rEPOStatsManager = REPOStatsManager.EnsureInstance();
			if ((Object)(object)rEPOStatsManager == (Object)null)
			{
				return;
			}
			int completedTierCount = GetCompletedTierCount(challenge.id);
			if (completedTier > completedTierCount)
			{
				rEPOStatsManager.stats.challengeCompletedTiers[challenge.id] = completedTier;
				rEPOStatsManager.stats.totalChallengeTierCompletions += completedTier - completedTierCount;
				if (string.Equals(rEPOStatsManager.stats.activeChallengeId, challenge.id, StringComparison.OrdinalIgnoreCase))
				{
					rEPOStatsManager.stats.activeChallengeId = string.Empty;
					rEPOStatsManager.stats.activeChallengeTarget = 0;
					rEPOStatsManager.stats.activeChallengeRunStarted = false;
					rEPOStatsManager.stats.activeChallengeRunSaveKey = string.Empty;
					activeChallengeProgressBlocked = false;
				}
				rEPOStatsManager.SaveStats();
				REPOConomyNetworkHandler.SyncBlackMarketToClients();
				REPOConomyPlugin.Logger.LogInfo((object)$"[Challenges] Applied synced completion: {challenge.id} tier {completedTier}");
				ShowCompletionMessage(challenge, completedTier);
				TryAnnounceChallengeReward(challenge, completedTier);
			}
		}

		public static bool CanLoadSaveFromMenu(string saveFileName, out string title, out string message)
		{
			title = string.Empty;
			message = string.Empty;
			ChallengeSaveMeta challengeSaveMeta = LoadChallengeSaveMeta(SanitizeSaveKey(saveFileName));
			ChallengeDefinition activeChallenge = ActiveChallenge;
			if (challengeSaveMeta == null)
			{
				if (activeChallenge != null && ActiveTarget > 0)
				{
					title = "Challenge Save Required";
					message = "This save was not started with the active challenge.\n\nProgress will not count here.\nCreate a new save for this challenge, or disable the challenge before loading this save.";
					return false;
				}
				return true;
			}
			ChallengeDefinition challenge = GetChallenge(challengeSaveMeta.challengeId);
			if (activeChallenge != null && string.Equals(activeChallenge.id, challengeSaveMeta.challengeId, StringComparison.OrdinalIgnoreCase) && ActiveTarget == challengeSaveMeta.targetLevel)
			{
				return true;
			}
			string arg = challenge?.name ?? challengeSaveMeta.challengeName ?? challengeSaveMeta.challengeId;
			title = "Challenge Save";
			message = $"This save was started with challenge:\n{arg} to level {challengeSaveMeta.targetLevel}\n\nEnable this exact challenge to continue this save.";
			return false;
		}

		public static void OnVanillaSaveCreated(string saveFileName)
		{
			ChallengeDefinition activeChallenge = ActiveChallenge;
			int activeTarget = ActiveTarget;
			if (activeChallenge != null && activeTarget > 0 && !string.IsNullOrWhiteSpace(saveFileName))
			{
				SaveChallengeSaveMeta(SanitizeSaveKey(saveFileName), activeChallenge, activeTarget);
				SetRuntimeTeamName(BuildChallengeSaveName(activeChallenge, null));
				REPOConomyPlugin.Logger.LogInfo((object)$"[Challenges] Marked new save '{saveFileName}' for {activeChallenge.id} target {activeTarget}");
			}
		}

		public static void BeforeVanillaSaveFileSave()
		{
			ChallengeDefinition activeChallenge = ActiveChallenge;
			if (activeChallenge == null)
			{
				return;
			}
			string currentRawSaveName = GetCurrentRawSaveName();
			if (!string.IsNullOrWhiteSpace(currentRawSaveName))
			{
				ChallengeSaveMeta challengeSaveMeta = LoadChallengeSaveMeta(SanitizeSaveKey(currentRawSaveName));
				if (challengeSaveMeta != null && string.Equals(challengeSaveMeta.challengeId, activeChallenge.id, StringComparison.OrdinalIgnoreCase))
				{
					SetRuntimeTeamName(BuildChallengeSaveName(activeChallenge, challengeSaveMeta));
				}
			}
		}

		public static bool CanRenameSaveFromMenu(string saveFileName, out string title, out string message)
		{
			title = string.Empty;
			message = string.Empty;
			ChallengeSaveMeta challengeSaveMeta = LoadChallengeSaveMeta(SanitizeSaveKey(saveFileName));
			if (challengeSaveMeta == null)
			{
				return true;
			}
			string teamName = BuildChallengeSaveName(GetChallenge(challengeSaveMeta.challengeId), challengeSaveMeta);
			ForceSaveTeamName(saveFileName, teamName);
			title = "Challenge Save";
			message = "Challenge save names are locked while the challenge run exists.";
			return false;
		}

		public static string GetSaveListDisplayName(string saveFileName, string currentName)
		{
			ChallengeSaveMeta challengeSaveMeta = LoadChallengeSaveMeta(SanitizeSaveKey(saveFileName));
			if (challengeSaveMeta == null)
			{
				return currentName;
			}
			string text = BuildChallengeSaveName(GetChallenge(challengeSaveMeta.challengeId), challengeSaveMeta);
			ForceSaveTeamName(saveFileName, text);
			return text;
		}

		private static void MarkCurrentSaveForChallenge(ChallengeDefinition challenge, int targetLevel)
		{
			if (challenge != null)
			{
				string currentSaveKeyForChallenge = REPOBlackMarketManager.GetCurrentSaveKeyForChallenge();
				string currentRawSaveName = GetCurrentRawSaveName();
				SaveChallengeSaveMeta(currentSaveKeyForChallenge, challenge, targetLevel);
				ForceSaveTeamName(currentRawSaveName, BuildChallengeSaveName(challenge, null));
			}
		}

		private static void EnforceCurrentChallengeSaveName(ChallengeDefinition challenge)
		{
			if (challenge != null)
			{
				string currentRawSaveName = GetCurrentRawSaveName();
				if (!string.IsNullOrWhiteSpace(currentRawSaveName))
				{
					ForceSaveTeamName(currentRawSaveName, BuildChallengeSaveName(challenge, null));
				}
			}
		}

		private static string BuildChallengeSaveName(ChallengeDefinition challenge, ChallengeSaveMeta meta)
		{
			string text = challenge?.name ?? meta?.challengeName ?? "Challenge";
			return "Challenge - " + text;
		}

		private static void SaveChallengeSaveMeta(string saveKey, ChallengeDefinition challenge, int targetLevel)
		{
			try
			{
				string challengeSaveMetaPath = GetChallengeSaveMetaPath(saveKey);
				Directory.CreateDirectory(Path.GetDirectoryName(challengeSaveMetaPath));
				File.WriteAllLines(challengeSaveMetaPath, new string[3]
				{
					challenge.id ?? string.Empty,
					targetLevel.ToString(),
					challenge.name ?? string.Empty
				});
			}
			catch (Exception ex)
			{
				REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Failed to save challenge save meta: " + ex.Message));
			}
		}

		private static ChallengeSaveMeta LoadChallengeSaveMeta(string saveKey)
		{
			try
			{
				string challengeSaveMetaPath = GetChallengeSaveMetaPath(saveKey);
				if (!File.Exists(challengeSaveMetaPath))
				{
					return null;
				}
				string[] array = File.ReadAllLines(challengeSaveMetaPath);
				if (array.Length < 2 || string.IsNullOrWhiteSpace(array[0]))
				{
					return null;
				}
				int.TryParse(array[1], out var result);
				return new ChallengeSaveMeta
				{
					challengeId = array[0],
					targetLevel = result,
					challengeName = ((array.Length >= 3) ? array[2] : string.Empty)
				};
			}
			catch (Exception ex)
			{
				REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Failed to load challenge save meta: " + ex.Message));
				return null;
			}
		}

		private static void DeleteChallengeSaveMeta(string saveKey)
		{
			try
			{
				string challengeSaveMetaPath = GetChallengeSaveMetaPath(saveKey);
				if (File.Exists(challengeSaveMetaPath))
				{
					File.Delete(challengeSaveMetaPath);
				}
			}
			catch (Exception ex)
			{
				REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Failed to delete challenge save meta: " + ex.Message));
			}
		}

		private static string GetChallengeSaveMetaPath(string saveKey)
		{
			return Path.Combine(Application.persistentDataPath, "REPOConomyPlus", "Challenges", SanitizeSaveKey(saveKey) + ".txt");
		}

		private static string SanitizeSaveKey(string saveKey)
		{
			if (string.IsNullOrWhiteSpace(saveKey))
			{
				return "active_run";
			}
			char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
			foreach (char oldChar in invalidFileNameChars)
			{
				saveKey = saveKey.Replace(oldChar, '_');
			}
			if (!string.IsNullOrWhiteSpace(saveKey))
			{
				return saveKey;
			}
			return "active_run";
		}

		private static string GetCurrentRawSaveName()
		{
			try
			{
				string text = AccessTools.Field(typeof(StatsManager), "saveFileCurrent")?.GetValue(StatsManager.instance) as string;
				if (!string.IsNullOrWhiteSpace(text))
				{
					return text;
				}
			}
			catch
			{
			}
			return string.Empty;
		}

		private static void ForceSaveTeamName(string saveFileName, string teamName)
		{
			if (string.IsNullOrWhiteSpace(saveFileName) || string.IsNullOrWhiteSpace(teamName) || (Object)(object)StatsManager.instance == (Object)null)
			{
				return;
			}
			try
			{
				if (string.Equals(GetCurrentRawSaveName(), saveFileName, StringComparison.OrdinalIgnoreCase))
				{
					SetRuntimeTeamName(teamName);
				}
			}
			catch (Exception ex)
			{
				REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Failed to lock challenge save name: " + ex.Message));
			}
		}

		private static void SetRuntimeTeamName(string teamName)
		{
			if (!((Object)(object)StatsManager.instance == (Object)null) && !string.IsNullOrWhiteSpace(teamName))
			{
				AccessTools.Field(typeof(StatsManager), "teamName")?.SetValue(StatsManager.instance, teamName);
				AccessTools.Field(typeof(StatsManager), "teamNameChanged")?.SetValue(StatsManager.instance, true);
			}
		}

		public static bool TryApplyEconomyPreset()
		{
			ChallengeDefinition activeChallenge = ActiveChallenge;
			if (activeChallenge == null)
			{
				return false;
			}
			REPOConomyPlugin.ApplyChallengeEconomy(activeChallenge.economy);
			REPOConomyPlugin.CurrentRollMode = REPOConomyPlugin.PercentRollMode.Stable;
			REPOConomyPlugin.Logger.LogInfo((object)$"[Challenges] Economy locked to {activeChallenge.economy} for {activeChallenge.id}");
			return true;
		}

		public static bool TryApplyModifierPreset()
		{
			ChallengeDefinition activeChallenge = ActiveChallenge;
			if (activeChallenge == null)
			{
				return false;
			}
			REPOEventManager.ActiveEvents.Clear();
			REPOEventManager.ResetMultipliers();
			string[] array = activeChallenge.modifierIds ?? Array.Empty<string>();
			foreach (string modifierId in array)
			{
				GameEvent gameEvent = REPOEventManager.AllEvents.FirstOrDefault((GameEvent e) => string.Equals(e.id, modifierId, StringComparison.OrdinalIgnoreCase));
				if (gameEvent == null)
				{
					REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Modifier '" + modifierId + "' not found for " + activeChallenge.id));
					continue;
				}
				REPOEventManager.ActiveEvents.Add(gameEvent);
				gameEvent.onActivate?.Invoke();
			}
			REPOEventManager.TrackActiveModifiersForStats();
			if (PhotonNetwork.IsMasterClient)
			{
				REPOEventManager.SyncModifiersToClients();
				REPOConomyNetworkHandler.SyncSharedPoolToClients();
				REPOConomyNetworkHandler.SyncBlackMarketToClients();
			}
			REPOConomyPlugin.Logger.LogInfo((object)("[Challenges] Applied modifier preset for " + activeChallenge.id));
			return true;
		}

		public static bool TryApplyShopEconomyPreset(Random rng)
		{
			ChallengeDefinition activeChallenge = ActiveChallenge;
			if (activeChallenge == null || string.IsNullOrWhiteSpace(activeChallenge.shopEconomy))
			{
				return false;
			}
			if (!Enum.TryParse<ShopEconomyType>(activeChallenge.shopEconomy, ignoreCase: true, out var result))
			{
				REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Shop economy '" + activeChallenge.shopEconomy + "' not found for " + activeChallenge.id));
				return false;
			}
			ShopEconomyManager.ApplyChallengeShopEconomy(result, rng);
			REPOConomyPlugin.Logger.LogInfo((object)$"[Challenges] Shop economy locked to {result} for {activeChallenge.id}");
			return true;
		}

		private static void ShowCompletionMessage(ChallengeDefinition challenge, int completedTier)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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)
			int num = Targets[Mathf.Clamp(completedTier - 1, 0, Targets.Length - 1)];
			string text = $"{challenge.name} completed to level {num}";
			if ((Object)(object)BigMessageUI.instance != (Object)null)
			{
				SemiFunc.UIBigMessage(text.ToUpperInvariant(), "{check}", 28f, challenge.color, Color.white);
			}
			if (completedTier >= Targets.Length && (Object)(object)BigMessageUI.instance != (Object)null)
			{
				SemiFunc.UIBigMessage(challenge.name.ToUpperInvariant() + " MASTERED", "{star}", 30f, challenge.color, Color.white);
			}
		}

		private static void TryAnnounceChallengeReward(ChallengeDefinition challenge, int completedTier)
		{
			//IL_008b: 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)
			REPOStatsManager rEPOStatsManager = REPOStatsManager.EnsureInstance();
			if ((Object)(object)rEPOStatsManager == (Object)null || challenge == null || completedTier < Targets.Length)
			{
				return;
			}
			string key = challenge.id + "_reward_pack";
			if (!(rEPOStatsManager.stats.challengeRewardUnlockAnnouncements.TryGetValue(key, out var value) && value))
			{
				rEPOStatsManager.stats.challengeRewardUnlockAnnouncements[key] = true;
				rEPOStatsManager.SaveStats();
				if ((Object)(object)BigMessageUI.instance != (Object)null)
				{
					SemiFunc.UIBigMessage(challenge.name.ToUpperInvariant() + " REWARD PACK UNLOCKED", "{star}", 32f, challenge.color, Color.white);
				}
			}
		}

		private static void ShowCompletionPopupAndReturnToMainMenu(ChallengeDefinition challenge, int completedTier)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			int num = Targets[Mathf.Clamp(completedTier - 1, 0, Targets.Length - 1)];
			string arg = ((completedTier < Targets.Length) ? $"Unlocked next target: level {Targets[completedTier]}" : ("Unlocked rewards: " + GetRewardSummary(challenge)));
			string popupBody = $"{challenge.name}\nReach level {num} completed!\n\n{arg}";
			if ((Object)(object)REPOConomyPlugin.Instance != (Object)null)
			{
				((MonoBehaviour)REPOConomyPlugin.Instance).StartCoroutine(ReturnToMainMenuAfterDelay(challenge.color, popupBody));
			}
			else if ((Object)(object)EconomyController.Instance != (Object)null)
			{
				((MonoBehaviour)EconomyController.Instance).StartCoroutine(ReturnToMainMenuAfterDelay(challenge.color, popupBody));
			}
		}

		[IteratorStateMachine(typeof(<ReturnToMainMenuAfterDelay>d__52))]
		private static IEnumerator ReturnToMainMenuAfterDelay(Color popupColor, string popupBody)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ReturnToMainMenuAfterDelay>d__52(0)
			{
				popupColor = popupColor,
				popupBody = popupBody
			};
		}
	}
	[HarmonyPatch(typeof(MenuPageSaves), "OnLoadGame")]
	internal static class ChallengeSaveLoadGuardPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(MenuPageSaves __instance)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string text = AccessTools.Field(typeof(MenuPageSaves), "currentSaveFileName")?.GetValue(__instance) as string;
				if (string.IsNullOrWhiteSpace(text))
				{
					return true;
				}
				if (ChallengeManager.CanLoadSaveFromMenu(text, out var title, out var message))
				{
					return true;
				}
				MenuManager instance = MenuManager.instance;
				if (instance != null)
				{
					instance.PagePopUp(title, Color.red, message, "OK", true);
				}
				MenuManager instance2 = MenuManager.instance;
				if (instance2 != null)
				{
					instance2.MenuEffectClick((MenuClickEffectType)2, (MenuPage)null, 1f, 1f, false);
				}
				return false;
			}
			catch (Exception ex)
			{
				REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Save load guard failed: " + ex.Message));
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(MenuPageSaves), "OnNewGame")]
	internal static class RemoveSaveLimitPatch
	{
		[HarmonyPrefix]
		private static bool Prefix()
		{
			try
			{
				if (SemiFunc.MainMenuIsMultiplayer())
				{
					SemiFunc.MenuActionHostGame((string)null, (List<string>)null);
				}
				else
				{
					SemiFunc.MenuActionSingleplayerGame((string)null, (List<string>)null);
				}
				return false;
			}
			catch (Exception ex)
			{
				REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Save limit bypass failed: " + ex.Message));
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(StatsManager), "SaveFileCreate")]
	internal static class ChallengeSaveCreatePatch
	{
		[HarmonyPostfix]
		private static void Postfix(StatsManager __instance)
		{
			try
			{
				ChallengeManager.OnVanillaSaveCreated(AccessTools.Field(typeof(StatsManager), "saveFileCurrent")?.GetValue(__instance) as string);
			}
			catch (Exception ex)
			{
				REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Save create hook failed: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(StatsManager), "SaveFileSave")]
	internal static class ChallengeSaveFileSavePatch
	{
		[HarmonyPrefix]
		private static void Prefix()
		{
			try
			{
				ChallengeManager.BeforeVanillaSaveFileSave();
			}
			catch (Exception ex)
			{
				REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Save name hook failed: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(MenuPageSavesRename), "ButtonConfirm")]
	internal static class ChallengeSaveRenameGuardPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(MenuPageSavesRename __instance)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string text = AccessTools.Field(typeof(MenuPageSavesRename), "fileName")?.GetValue(__instance) as string;
				if (string.IsNullOrWhiteSpace(text))
				{
					return true;
				}
				if (ChallengeManager.CanRenameSaveFromMenu(text, out var title, out var message))
				{
					return true;
				}
				MenuManager instance = MenuManager.instance;
				if (instance != null)
				{
					instance.PagePopUp(title, Color.yellow, message, "OK", true);
				}
				MenuManager instance2 = MenuManager.instance;
				if (instance2 != null)
				{
					instance2.MenuEffectClick((MenuClickEffectType)2, (MenuPage)null, 1f, 1f, false);
				}
				return false;
			}
			catch (Exception ex)
			{
				REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Save rename guard failed: " + ex.Message));
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(MenuPageSaves), "UpdateSaveDetails")]
	internal static class ChallengeSaveDisplayNamePatch
	{
		[HarmonyPostfix]
		private static void Postfix(MenuElementSaveFile _menuSaveFile, string _saveFileName)
		{
			try
			{
				if (!((Object)(object)_menuSaveFile?.saveFileHeader == (Object)null) && !string.IsNullOrWhiteSpace(_saveFileName))
				{
					((TMP_Text)_menuSaveFile.saveFileHeader).text = ChallengeManager.GetSaveListDisplayName(_saveFileName, ((TMP_Text)_menuSaveFile.saveFileHeader).text);
				}
			}
			catch (Exception ex)
			{
				REPOConomyPlugin.Logger.LogWarning((object)("[Challenges] Save display patch failed: " + ex.Message));
			}
		}
	}
	[Serializable]
	public class CustomEconomyData
	{
		public string id;

		public string name_en;

		public string name_ru;

		public string name_ko;

		public string desc_en;

		public string desc_ru;

		public string desc_ko;

		public float[] color;

		public float min;

		public float max;

		public bool useDelta;
	}
	public static class CustomEconomyLoader
	{
		public static List<CustomEconomyData> CustomEvents = new List<CustomEconomyData>();

		public static void LoadCustomEvents()
		{
			string text = Path.Combine(Paths.ConfigPath, "CustomEvents");
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
				REPOConomyPlugin.Logger.LogInfo((object)("[REPOConomy] Created folder for custom events: " + text));
			}
			string[] files = Directory.GetFiles(text, "*.json", SearchOption.TopDirectoryOnly);
			int num = 0;
			int num2 = 0;
			string[] array = files;
			foreach (string text2 in array)
			{
				try
				{
					List<CustomEconomyData> list = JsonConvert.DeserializeObject<List<CustomEconomyData>>(File.ReadAllText(text2));
					if (list != null)
					{
						foreach (CustomEconomyData item in list)
						{
							if (!string.IsNullOrEmpty(item.id))
							{
								CustomEvents.Add(item);
								REPOConomyPlugin.Logger.LogInfo((object)("[REPOConomy] Loaded custom event: " + item.name_en + " (" + text2 + ")"));
								num++;
							}
							else
							{
								REPOConomyPlugin.Logger.LogWarning((object)("[REPOConomy] Invalid custom event in file: " + text2 + " (missing ID)"));
								num2++;
							}
						}
					}
					else
					{
						REPOConomyPlugin.Logger.LogWarning((object)("[REPOConomy] JSON file does not contain a valid event list: " + text2));
						num2++;
					}
				}
				catch (Exception ex)
				{
					REPOConomyPlugin.Logger.LogWarning((object)("[REPOConomy] Failed to load custom event from " + text2 + ": " + ex.Message));
					num2++;
				}
			}
			REPOConomyPlugin.Logger.LogInfo((object)$"[REPOConomy] Loaded {num} custom events. Failed: {num2}");
		}
	}
	public class EconomyController : MonoBehaviour
	{
		public static EconomyController Instance;

		public static bool UIShownOnce;

		public static bool ShowChancesInLevel;

		public static bool ShopEconomyUIShownOnce;

		public static bool BlackMarketHintShownOnce;

		private bool economyResetPending = true;

		private bool showGUI;

		private float displayTimer = 20f;

		private string lastSceneType = "";

		private bool showShopGUI;

		private float shopDisplayTimer = 15f;

		private Vector2 scrollPosition = Vector2.zero;

		private float scrollSpeed = 100f;

		private float autoScrollTimer;

		private float autoScrollDelay = 1.5f;

		private bool autoScrollActive;

		private float autoScrollSpeed = 30f;

		private float cachedContentHeight;

		private float cachedScrollableHeight;

		private float fadeAlpha;

		private float bmFadeAlpha;

		private float targetFadeAlpha;

		private float glowPulse;

		private Texture2D bgTexture;

		private Texture2D gradientTexture;

		private Texture2D glowTexture;

		private Texture2D separatorTexture;

		private GUIStyle noScrollbarStyle;

		private void Awake()
		{
			Instance = this;
			InitializeTextures();
			InitializeStyles();
		}

		private void InitializeStyles()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			noScrollbarStyle = new GUIStyle();
		}

		private void InitializeTextures()
		{
			//IL_0018: 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)
			bgTexture = MakeTexture(2, 2, new Color(0.05f, 0.05f, 0.08f, 0.95f));
			gradientTexture = MakeGradientTexture();
			glowTexture = MakeGlowTexture();
			separatorTexture = MakeTexture(2, 2, new Color(0.3f, 0.6f, 1f, 0.3f));
		}

		private Texture2D MakeTexture(int width, int height, Color col)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			Color[] array = (Color[])(object)new Color[width * height];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = col;
			}
			Texture2D val = new Texture2D(width, height);
			val.SetPixels(array);
			val.Apply();
			return val;
		}

		private Texture2D MakeGradientTexture()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_002c: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			int num = 256;
			Texture2D val = new Texture2D(1, num);
			for (int i = 0; i < num; i++)
			{
				float num2 = (float)i / (float)num;
				Color val2 = Color.Lerp(new Color(0.1f, 0.15f, 0.25f, 0.9f), new Color(0.05f, 0.05f, 0.08f, 0.95f), num2);
				val.SetPixel(0, i, val2);
			}
			val.Apply();
			return val;
		}

		private Texture2D MakeGlowTexture()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			int num = 64;
			Texture2D val = new Texture2D(num, num);
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					float num2 = ((float)j - (float)num / 2f) / ((float)num / 2f);
					float num3 = ((float)i - (float)num / 2f) / ((float)num / 2f);
					float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3);
					float num5 = Mathf.Max(0f, 1f - num4) * 0.5f;
					val.SetPixel(j, i, new Color(0.3f, 0.6f, 1f, num5));
				}
			}
			val.Apply();
			return val;
		}

		private void Update()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			fadeAlpha = Mathf.Lerp(fadeAlpha, targetFadeAlpha, Time.deltaTime * 8f);
			float num = ((REPOBlackMarketManager.IsShopHintVisible() && SemiFunc.RunIsShop()) ? 1f : 0f);
			bmFadeAlpha = Mathf.Lerp(bmFadeAlpha, num, Time.deltaTime * 8f);
			glowPulse = Mathf.Sin(Time.time * 2f) * 0.3f + 0.7f;
			string currentSceneType = GetCurrentSceneType();
			if (Input.GetKeyDown(REPOConfig.UIToggleHotkey.Value))
			{
				if (currentSceneType == "Shop")
				{
					showShopGUI = !showShopGUI;
					if (showShopGUI)
					{
						shopDisplayTimer = 15f;
					}
				}
				else
				{
					showGUI = !showGUI;
					targetFadeAlpha = (showGUI ? 1f : 0f);
					displayTimer = 20f;
					scrollPosition = Vector2.zero;
					autoScrollTimer = 0f;
					autoScrollActive = false;
				}
			}
			string text = lastSceneType;
			if (currentSceneType != lastSceneType)
			{
				lastSceneType = currentSceneType;
				switch (currentSceneType)
				{
				case "Level":
					economyResetPending = true;
					UIShownOnce = false;
					showGUI = false;
					targetFadeAlpha = 0f;
					autoScrollTimer = 0f;
					autoScrollActive = false;
					if (text == "Shop")
					{
						showShopGUI = false;
						ShopEconomyUIShownOnce = false;
						BlackMarketHintShownOnce = false;
					}
					break;
				case "Lobby":
					if (text == "Shop")
					{
						showShopGUI = false;
						ShopEconomyUIShownOnce = false;
						BlackMarketHintShownOnce = false;
					}
					break;
				case "Shop":
					showGUI = false;
					targetFadeAlpha = 0f;
					autoScrollTimer = 0f;
					autoScrollActive = false;
					break;
				}
			}
			bool flag = economyResetPending;
			if (flag)
			{
				bool flag2 = ((currentSceneType == "Level" || currentSceneType == "Lobby") ? true : false);
				flag = flag2;
			}
			if (flag)
			{
				REPOConomyPlugin.ResetEconomy();
				economyResetPending = false;
			}
			if (showGUI && (REPOConomyPlugin.HasEconomy || currentSceneType == "Lobby"))
			{
				displayTimer -= Time.deltaTime;
				if (displayTimer <= 0f)
				{
					showGUI = false;
					targetFadeAlpha = 0f;
					autoScrollTimer = 0f;
					autoScrollActive = false;
				}
				bool flag3 = false;
				float num2 = Mathf.Max(0f, cachedContentHeight - cachedScrollableHeight);
				if (Input.GetKey((KeyCode)274))
				{
					scrollPosition.y += scrollSpeed * Time.deltaTime;
					scrollPosition.y = Mathf.Min(scrollPosition.y, num2);
					flag3 = true;
					autoScrollTimer = 0f;
					autoScrollActive = false;
				}
				if (Input.GetKey((KeyCode)273))
				{
					scrollPosition.y -= scrollSpeed * Time.deltaTime;
					scrollPosition.y = Mathf.Max(0f, scrollPosition.y);
					flag3 = true;
					autoScrollTimer = 0f;
					autoScrollActive = false;
				}
				if (!flag3)
				{
					if (!autoScrollActive)
					{
						autoScrollTimer += Time.deltaTime;
						if (autoScrollTimer >= autoScrollDelay)
						{
							autoScrollActive = true;
						}
					}
					else
					{
						scrollPosition.y += autoScrollSpeed * Time.deltaTime;
						scrollPosition.y = Mathf.Min(scrollPosition.y, num2);
						if (scrollPosition.y >= num2)
						{
							autoScrollActive = false;
						}
					}
				}
			}
			if (showShopGUI && REPOConomyPlugin.HasShopEconomy)
			{
				shopDisplayTimer -= Time.deltaTime;
				if (shopDisplayTimer <= 0f)
				{
					showShopGUI = false;
				}
			}
		}

		private string GetCurrentSceneType()
		{
			if (SemiFunc.RunIsLevel())
			{
				return "Level";
			}
			if (SemiFunc.RunIsLobby())
			{
				return "Lobby";
			}
			if (SemiFunc.RunIsShop())
			{
				return "Shop";
			}
			return "Other";
		}

		public void ResetGUI()
		{
			//IL_001e: 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)
			showGUI = true;
			targetFadeAlpha = 1f;
			displayTimer = 20f;
			scrollPosition = Vector2.zero;
			autoScrollTimer = 0f;
			autoScrollActive = false;
		}

		public void ShowGUI()
		{
			//IL_001e: 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)
			showGUI = true;
			targetFadeAlpha = 1f;
			displayTimer = 20f;
			scrollPosition = Vector2.zero;
			autoScrollTimer = 0f;
			autoScrollActive = false;
		}

		public void ShowShopEconomyGUI()
		{
			showShopGUI = true;
			shopDisplayTimer = 15f;
		}

		private void OnGUI()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			if (showShopGUI && REPOConomyPlugin.HasShopEconomy && SemiFunc.RunIsShop())
			{
				DrawShopEconomyGUI();
			}
			if (REPOBlackMarketManager.IsShopHintVisible() && SemiFunc.RunIsShop())
			{
				DrawBlackMarketHintGUI();
			}
			if (!(fadeAlpha < 0.01f) && showGUI && (REPOConomyPlugin.HasEconomy || SemiFunc.RunIsLobby()) && (SemiFunc.RunIsLevel() || SemiFunc.RunIsLobby()))
			{
				Color color = GUI.color;
				GUI.color = new Color(1f, 1f, 1f, fadeAlpha);
				int currentLevel = REPOConomyPlugin.GetCurrentLevel();
				float num = (float)Screen.width / 2f;
				float num2 = (float)Screen.height * 0.12f;
				float num3 = Mathf.Min((float)Screen.width * 0.45f, 700f);
				float num4 = 500f;
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(num - num3 / 2f, num2, num3, num4);
				DrawGlowEffect(val);
				DrawModernBackground(val);
				DrawHeaderSection(val);
				DrawContentSection(val);
				DrawFooterSection(val, currentLevel);
				GUI.color = color;
			}
		}

		private void DrawShopEconomyGUI()
		{
			//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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_0102: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: 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_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Expected O, but got Unknown
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Expected O, but got Unknown
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: 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_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Expected O, but got Unknown
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Expected O, but got Unknown
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0444: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Expected O, but got Unknown
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0509: Unknown result type (might be due to invalid IL or missing references)
			string value = REPOConfig.UILanguage.Value;
			bool num = value == "Russian";
			ShopEconomyType currentShopEconomy = REPOConomyPlugin.CurrentShopEconomy;
			string shopEconomyName = ShopEconomyManager.GetShopEconomyName(currentShopEconomy, value);
			string shopEconomyDescription = ShopEconomyManager.GetShopEconomyDescription(currentShopEconomy, value);
			string priceModifierText = ShopEconomyManager.GetPriceModifierText(value);
			Color shopEconomyColor = ShopEconomyManager.GetShopEconomyColor(currentShopEconomy);
			float num2 = Mathf.Clamp01(shopDisplayTimer / 2f);
			float num3 = ((shopDisplayTimer > 13f) ? ((15f - shopDisplayTimer) / 2f) : num2);
			num3 = Mathf.Clamp01(num3);
			float num4 = Mathf.Min((float)Screen.width * 0.4f, 500f);
			float num5 = 215f;
			float num6 = (float)Screen.width / 2f;
			float num7 = (float)Screen.height * 0.08f;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(num6 - num4 / 2f, num7, num4, num5);
			GUI.color = new Color(0.05f, 0.05f, 0.08f, 0.9f * num3);
			GUI.DrawTexture(val, (Texture)(object)bgTexture);
			GUI.color = new Color(shopEconomyColor.r, shopEconomyColor.g, shopEconomyColor.b, 0.6f * num3);
			float num8 = 2f;
			GUI.DrawTexture(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width, num8), (Texture)(object)Texture2D.whiteTexture);
			GUI.DrawTexture(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y + ((Rect)(ref val)).height - num8, ((Rect)(ref val)).width, num8), (Texture)(object)Texture2D.whiteTexture);
			GUI.DrawTexture(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, num8, ((Rect)(ref val)).height), (Texture)(object)Texture2D.whiteTexture);
			GUI.DrawTexture(new Rect(((Rect)(ref val)).x + ((Rect)(ref val)).width - num8, ((Rect)(ref val)).y, num8, ((Rect)(ref val)).height), (Texture)(object)Texture2D.whiteTexture);
			GUI.color = Color.white;
			GUIStyle val2 = new GUIStyle(GUI.skin.label)
			{
				fontSize = 14,
				alignment = (TextAnchor)4,
				fontStyle = (FontStyle)1
			};
			val2.normal.textColor = new Color(0.7f, 0.7f, 0.7f, num3);
			string text = (num ? "\ud83d\udcb0 ЭКОНОМИКА МАГАЗИНА" : "\ud83d\udcb0 SHOP ECONOMY");
			GUI.Label(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y + 10f, ((Rect)(ref val)).width, 25f), text, val2);
			GUIStyle val3 = new GUIStyle(GUI.skin.label)
			{
				fontSize = 22,
				alignment = (TextAnchor)4,
				fontStyle = (FontStyle)1
			};
			val3.normal.textColor = new Color(shopEconomyColor.r, shopEconomyColor.g, shopEconomyColor.b, num3);
			GUI.Label(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y + 40f, ((Rect)(ref val)).width, 35f), shopEconomyName, val3);
			GUIStyle val4 = new GUIStyle(GUI.skin.label)
			{
				fontSize = 13,
				alignment = (TextAnchor)4,
				fontStyle = (FontStyle)2,
				wordWrap = true
			};
			val4.normal.textColor = new Color(0.8f, 0.8f, 0.8f, num3);
			GUI.Label(new Rect(((Rect)(ref val)).x + 15f, ((Rect)(ref val)).y + 78f, ((Rect)(ref val)).width - 30f, 56f), shopEconomyDescription, val4);
			GUIStyle val5 = new GUIStyle(GUI.skin.label)
			{
				fontSize = 14,
				alignment = (TextAnchor)4,
				fontStyle = (FontStyle)1
			};
			Color textColor = default(Color);
			if (REPOConomyPlugin.ShopPriceMultiplier < 1f)
			{
				((Color)(ref textColor))..ctor(0.3f, 0.9f, 0.3f, num3);
			}
			else if (REPOConomyPlugin.ShopPriceMultiplier > 1f)
			{
				((Color)(ref textColor))..ctor(0.9f, 0.3f, 0.3f, num3);
			}
			else
			{
				((Color)(ref textColor))..ctor(0.7f, 0.7f, 0.7f, num3);
			}
			val5.normal.textColor = textColor;
			string text2 = (num ? "Цены: " : "Prices: ");
			GUI.Label(new Rect(((Rect)(ref val)).x + 12f, ((Rect)(ref val)).y + 140f, ((Rect)(ref val)).width - 24f, 36f), text2 + priceModifierText, val5);
			GUIStyle val6 = new GUIStyle(GUI.skin.label)
			{
				fontSize = 10,
				alignment = (TextAnchor)4
			};
			val6.normal.textColor = new Color(0.5f, 0.5f, 0.5f, num3 * 0.7f);
			string text3 = (num ? $"[{REPOConfig.UIToggleHotkey.Value}] для закрытия" : $"Press [{REPOConfig.UIToggleHotkey.Value}] to close");
			GUI.Label(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y + num5 - 25f, ((Rect)(ref val)).width, 20f), text3, val6);
			GUI.color = Color.white;
		}

		private void DrawBlackMarketHintGUI()
		{
			//IL_0097: 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)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Expected O, but got Unknown
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Expected O, but got Unknown
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			string shopHintText = REPOBlackMarketManager.GetShopHintText();
			if (!string.IsNullOrWhiteSpace(shopHintText))
			{
				float num = bmFadeAlpha;
				if (!(num < 0.01f))
				{
					float num2 = Mathf.Min((float)Screen.width * 0.5f, 640f);
					float num3 = (shopHintText.Contains("\n") ? 112f : 76f);
					float num4 = (float)Screen.width / 2f;
					float num5 = (float)Screen.height * 0.74f;
					Rect val = default(Rect);
					((Rect)(ref val))..ctor(num4 - num2 / 2f, num5, num2, num3);
					GUI.color = new Color(0.05f, 0.04f, 0.03f, 0.9f * num);
					GUI.DrawTexture(val, (Texture)(object)bgTexture);
					GUI.color = new Color(1f, 0.62f, 0.14f, 0.9f * num);
					float num6 = 2f;
					GUI.DrawTexture(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width, num6), (Texture)(object)Texture2D.whiteTexture);
					GUI.DrawTexture(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y + ((Rect)(ref val)).height - num6, ((Rect)(ref val)).width, num6), (Texture)(object)Texture2D.whiteTexture);
					GUI.DrawTexture(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, num6, ((Rect)(ref val)).height), (Texture)(object)Texture2D.whiteTexture);
					GUI.DrawTexture(new Rect(((Rect)(ref val)).x + ((Rect)(ref val)).width - num6, ((Rect)(ref val)).y, num6, ((Rect)(ref val)).height), (Texture)(object)Texture2D.whiteTexture);
					GUIStyle val2 = new GUIStyle(GUI.skin.label)
					{
						fontSize = 15,
						alignment = (TextAnchor)4,
						fontStyle = (FontStyle)1,
						wordWrap = true
					};
					val2.normal.textColor = new Color(1f, 0.78f, 0.35f, num);
					GUIStyle val3 = new GUIStyle(GUI.skin.label)
					{
						fontSize = 12,
						alignment = (TextAnchor)4,
						wordWrap = true
					};
					val3.normal.textColor = new Color(0.95f, 0.9f, 0.82f, num);
					string value = REPOConfig.UILanguage.Value;
					string text = ((value == "Korean") ? "암시장" : ((!(value == "Russian")) ? "BLACK MARKET" : "ЧЁРНЫЙ РЫНОК"));
					string text2 = text;
					GUI.color = Color.white;
					GUI.Label(new Rect(((Rect)(ref val)).x + 14f, ((Rect)(ref val)).y + 8f, ((Rect)(ref val)).width - 28f, 24f), text2, val2);
					GUI.Label(new Rect(((Rect)(ref val)).x + 18f, ((Rect)(ref val)).y + 34f, ((Rect)(ref val)).width - 36f, ((Rect)(ref val)).height - 42f), shopHintText, val3);
					GUI.color = Color.white;
				}
			}
		}

		private void DrawGlowEffect(Rect rect)
		{
			//IL_003d: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			float num = 30f * glowPulse;
			Rect val = new Rect(((Rect)(ref rect)).x - num, ((Rect)(ref rect)).y - num, ((Rect)(ref rect)).width + num * 2f, ((Rect)(ref rect)).height + num * 2f);
			GUI.color = new Color(0.3f, 0.6f, 1f, 0.15f * fadeAlpha);
			GUI.DrawTexture(val, (Texture)(object)glowTexture, (ScaleMode)0);
			GUI.color = Color.white;
		}

		private void DrawModernBackground(Rect rect)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			Rect val = new Rect(((Rect)(ref rect)).x - 2f, ((Rect)(ref rect)).y - 2f, ((Rect)(ref rect)).width + 4f, ((Rect)(ref rect)).height + 4f);
			GUI.color = new Color(0.3f, 0.6f, 1f, 0.4f * fadeAlpha);
			GUI.DrawTexture(val, (Texture)(object)bgTexture);
			GUI.color = new Color(1f, 1f, 1f, fadeAlpha);
			GUI.DrawTexture(rect, (Texture)(object)gradientTexture, (ScaleMode)0);
			DrawBorder(rect, new Color(0.2f, 0.4f, 0.8f, 0.6f * fadeAlpha), 1f);
		}

		private void DrawBorder(Rect rect, Color color, float thickness)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_0070: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			GUI.color = color;
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width, thickness), (Texture)(object)Texture2D.whiteTexture);
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y + ((Rect)(ref rect)).height - thickness, ((Rect)(ref rect)).width, thickness), (Texture)(object)Texture2D.whiteTexture);
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, thickness, ((Rect)(ref rect)).height), (Texture)(object)Texture2D.whiteTexture);
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x + ((Rect)(ref rect)).width - thickness, ((Rect)(ref rect)).y, thickness, ((Rect)(ref rect)).height), (Texture)(object)Texture2D.whiteTexture);
			GUI.color = Color.white;
		}

		private void DrawHeaderSection(Rect mainRect)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Expected O, but got Unknown
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			string value = REPOConfig.UILanguage.Value;
			KeyCode value2 = REPOConfig.UIToggleHotkey.Value;
			string text = ((object)(KeyCode)(ref value2)).ToString();
			string currentSceneType = GetCurrentSceneType();
			string text3;
			if (currentSceneType == "Lobby" || (currentSceneType == "Level" && ShowChancesInLevel))
			{
				string text2 = ((value == "Korean") ? "이벤트 확률" : ((!(value == "Russian")) ? "EVENT DROP CHANCES" : "ШАНСЫ ВЫПАДЕНИЯ СОБЫТИЙ"));
				text3 = text2;
			}
			else
			{
				string text2 = ((value == "Korean") ? "활성 이벤트" : ((!(value == "Russian")) ? "ACTIVE EVENTS" : "АКТИВНЫЕ СОБЫТИЯ"));
				text3 = text2;
			}
			string text4 = text3;
			Rect val = new Rect(((Rect)(ref mainRect)).x, ((Rect)(ref mainRect)).y, ((Rect)(ref mainRect)).width, 60f);
			GUI.color = new Color(0.15f, 0.25f, 0.4f, 0.5f * fadeAlpha);
			GUI.DrawTexture(val, (Texture)(object)bgTexture);
			GUI.color = Color.white;
			GUIStyle val2 = new GUIStyle(GUI.skin.label)
			{
				fontSize = 28,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)4
			};
			val2.normal.textColor = new Color(0.7f, 0.9f, 1f, fadeAlpha);
			GUIStyle val3 = val2;
			GUI.color = new Color(0f, 0f, 0f, 0.5f * fadeAlpha);
			GUI.Label(new Rect(((Rect)(ref mainRect)).x + 2f, ((Rect)(ref mainRect)).y + 12f, ((Rect)(ref mainRect)).width, 40f), text4, val3);
			GUI.color = new Color(1f, 1f, 1f, fadeAlpha);
			GUI.Label(new Rect(((Rect)(ref mainRect)).x, ((Rect)(ref mainRect)).y + 10f, ((Rect)(ref mainRect)).width, 40f), text4, val3);
			GUIStyle val4 = new GUIStyle(GUI.skin.label)
			{
				fontSize = 12,
				alignment = (TextAnchor)4
			};
			val4.normal.textColor = new Color(0.6f, 0.8f, 1f, 0.7f * fadeAlpha);
			GUIStyle val5 = val4;
			text3 = ((value == "Korean") ? ("[" + text + "] 키를 눌러 전환") : ((!(value == "Russian")) ? ("Press [" + text + "] to toggle") : ("Нажмите [" + text + "] для переключения")));
			string text5 = text3;
			GUI.Label(new Rect(((Rect)(ref mainRect)).x, ((Rect)(ref mainRect)).y + 40f, ((Rect)(ref mainRect)).width, 20f), text5, val5);
			Rect val6 = new Rect(((Rect)(ref mainRect)).x, ((Rect)(ref mainRect)).y + 58f, ((Rect)(ref mainRect)).width, 2f);
			GUI.color = new Color(0.3f, 0.6f, 1f, 0.6f * fadeAlpha * glowPulse);
			GUI.DrawTexture(val6, (Texture)(object)Texture2D.whiteTexture);
		}

		private void DrawContentSection(Rect mainRect)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref mainRect)).x + 15f, ((Rect)(ref mainRect)).y + 70f, ((Rect)(ref mainRect)).width - 30f, ((Rect)(ref mainRect)).height - 130f);
			cachedScrollableHeight = ((Rect)(ref val)).height;
			string currentSceneType = GetCurrentSceneType();
			cachedContentHeight = CalculateActualContentHeight(((Rect)(ref val)).width - 20f, currentSceneType);
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(0f, 0f, ((Rect)(ref val)).width - 20f, cachedContentHeight);
			GUI.color = new Color(0.08f, 0.08f, 0.12f, 0.6f * fadeAlpha);
			GUI.DrawTexture(val, (Texture)(object)bgTexture);
			GUI.color = Color.white;
			scrollPosition = GUI.BeginScrollView(val, scrollPosition, val2, false, false, GUIStyle.none, GUIStyle.none);
			float yOffset = 10f;
			if (currentSceneType == "Lobby" || (currentSceneType == "Level" && ShowChancesInLevel))
			{
				yOffset = DrawChancesContent(val2, yOffset);
			}
			else
			{
				yOffset = DrawActiveEventsContent(val2, yOffset);
			}
			GUI.EndScrollView();
			if (cachedContentHeight > cachedScrollableHeight)
			{
				DrawScrollIndicator(val);
			}
		}

		private void DrawScrollIndicator(Rect area)
		{
			//IL_005c: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(1f, cachedContentHeight - cachedScrollableHeight);
			float num2 = scrollPosition.y / num;
			float num3 = 40f;
			float num4 = ((Rect)(ref area)).y + num2 * (((Rect)(ref area)).height - num3);
			Rect val = new Rect(((Rect)(ref area)).x + ((Rect)(ref area)).width - 6f, num4, 4f, num3);
			GUI.color = new Color(0.3f, 0.6f, 1f, 0.7f * fadeAlpha);
			GUI.DrawTexture(val, (Texture)(object)Texture2D.whiteTexture);
			GUI.color = Color.white;
		}

		private float CalculateActualContentHeight(float contentWidth, string sceneType)
		{
			float num = 10f;
			_ = REPOConfig.UILanguage.Value == "Russian";
			if (sceneType == "Lobby" || (sceneType == "Level" && ShowChancesInLevel))
			{
				if (sceneType == "Lobby")
				{
					string lobbyStatusText = REPOBlackMarketManager.GetLobbyStatusText();
					if (!string.IsNullOrWhiteSpace(lobbyStatusText))
					{
						int num2 = lobbyStatusText.Split(new char[1] { '\n' }).Length;
						num += 35f;
						num += (float)(Mathf.Max(90, 24 + num2 * 22) + 10);
					}
				}
				if (REPOConfig.EnableSharedPool.Value)
				{
					num += 35f;
					Dictionary<EventType, float> dictionary = new Dictionary<EventType, float>();
					foreach (EventType value in Enum.GetValues(typeof(EventType)))
					{
						dictionary[value] = REPOEventManager.GetSharedPoolWeight(value);
					}
					num += (float)(dictionary.Count * 32);
					num += 15f;
				}
				else
				{
					EventCategory[] array = new EventCategory[4]
					{
						EventCategory.LootModifier,
						EventCategory.EnemyModifier,
						EventCategory.PlayerModifier,
						EventCategory.EnvironmentModifier
					};
					foreach (EventCategory category in array)
					{
						List<GameEvent> list = REPOEventManager.AllEvents.Where((GameEvent e) => e.category == category && REPOConfig.ModifierEnables["Enable " + e.id].Value).ToList();
						if (list.Count == 0)
						{
							continue;
						}
						num += 35f;
						Dictionary<EventType, float> dictionary2 = new Dictionary<EventType, float>();
						foreach (GameEvent item in list)
						{
							EventType eventType2 = item.eventType;
							if (!dictionary2.ContainsKey(eventType2))
							{
								dictionary2[eventType2] = 0f;
							}
							dictionary2[eventType2] += REPOEventManager.GetEventWeight(eventType2);
						}
						num += (float)(dictionary2.Count * 32);
						num += 10f;
					}
				}
			}
			else
			{
				num += 35f;
				string activeEventsStatusText = REPOBlackMarketManager.GetActiveEventsStatusText();
				if (!string.IsNullOrWhiteSpace(activeEventsStatusText))
				{
					int num3 = activeEventsStatusText.Split(new char[1] { '\n' }).Length;
					num += (float)(45 + Mathf.Max(90, num3 * 24));
				}
				if (ChallengeManager.HasActiveChallenge)
				{
					num += 35f;
					num += 80f;
				}
				num += 90f;
				if (REPOEventManager.ActiveEvents.Count > 0)
				{
					num += 35f;
					num += (float)(REPOEventManager.ActiveEvents.Count * 68);
					num += 10f;
				}
				if (sceneType == "Level" && (Object)(object)RunManager.instance != (Object)null && REPOConfig.EnableLevelScaling.Value)
				{
					num += 35f;
					num += 110f;
				}
				if (sceneType == "Level" && (Object)(object)RunManager.instance != (Object)null && REPOConfig.HideVanillaMoonUI.Value)
				{
					num += 35f;
					num += 100f;
				}
				if (sceneType == "Level" && (Object)(object)RunManager.instance != (Object)null)
				{
					int level = RunManager.instance.levelsCompleted + 1;
					float num4 = CalculateScaling(level, REPOConfig.EnableEnemyHPScaling.Value, REPOConfig.EnemyHPStartLevel.Value, REPOConfig.EnemyHPMultiplier.Value, REPOConfig.EnemyHPUseExponentialScaling.Value, REPOConfig.EnemyHPMaxLevel.Value);
					float num5 = CalculateScaling(level, REPOConfig.EnableEnemyCapScaling.Value, REPOConfig.EnemyCapStartLevel.Value, REPOConfig.EnemyCapMultiplier.Value, REPOConfig.EnemyCapUseExponentialScaling.Value, REPOConfig.EnemyCapMaxLevel.Value);
					float num6 = CalculateScaling(level, REPOConfig.EnableMapValueScaling.Value, REPOConfig.MapValueStartLevel.Value, REPOConfig.MapValueMultiplier.Value, REPOConfig.MapValueUseExponentialScaling.Value, REPOConfig.MapValueMaxLevel.Value);
					float playerDamageFromEnemyHPMultiplier = EnemyScaling.GetPlayerDamageFromEnemyHPMultiplier();
					float weaponDamageFromEnemyHPMultiplier = EnemyScaling.GetWeaponDamageFromEnemyHPMultiplier();
					float enemyRespawnFromCapMultiplier = EnemyScaling.GetEnemyRespawnFromCapMultiplier();
					if (num4 > 1f || num5 > 1f || num6 > 1f || playerDamageFromEnemyHPMultiplier > 1f || weaponDamageFromEnemyHPMultiplier > 1f || enemyRespawnFromCapMultiplier > 1f)
					{
						num += 35f;
						float num7 = 10f;
						if (num4 > 1f)
						{
							num7 += 25f;
						}
						if (num5 > 1f)
						{
							num7 += 25f;
						}
						if (num6 > 1f)
						{
							num7 += 25f;
						}
						if (playerDamageFromEnemyHPMultiplier > 1f)
						{
							num7 += 25f;
						}
						if (weaponDamageFromEnemyHPMultiplier > 1f)
						{
							num7 += 25f;
						}
						if (enemyRespawnFromCapMultiplier > 1f)
						{
							num7 += 25f;
						}
						num += num7 + 20f;
					}
				}
			}
			return num + 20f;
		}

		private float DrawChancesContent(Rect viewRect, float yOffset)
		{
			//IL_0028: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			bool isRu = REPOConfig.UILanguage.Value == "Russian";
			if (GetCurrentSceneType() == "Lobby")
			{
				yOffset = DrawBlackMarketLobbySection(viewRect, yOffset, isRu);
			}
			yOffset = ((!REPOConfig.EnableSharedPool.Value) ? DrawCategoryChances(viewRect, yOffset, isRu) : DrawSharedPoolChances(viewRect, yOffset, isRu));
			return yOffset;
		}

		private float DrawBlackMarketLobbySection(Rect viewRect, float yOffset, bool isRu)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			string lobbyStatusText = REPOBlackMarketManager.GetLobbyStatusText();
			if (string.IsNullOrWhiteSpace(lobbyStatusText))
			{
				return yOffset;
			}
			yOffset = DrawModernCategory(viewRect, yOffset, "BLACK MARKET", new Color(1f, 0.62f, 0.14f, fadeAlpha));
			int num = lobbyStatusText.Split(new char[1] { '\n' }).Length;
			float num2 = Mathf.Max(90f, 24f + (float)num * 22f);
			Rect rect = default(Rect);
			((Rect)(ref rect))..ctor(10f, yOffset, ((Rect)(ref viewRect)).width - 20f, num2);
			DrawModernCard(rect, new Color(1f, 0.62f, 0.14f));
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				fontSize = 14,
				alignment = (TextAnchor)4
			};
			val.normal.textColor = new Color(1f, 0.9f, 0.65f, fadeAlpha);
			val.wordWrap = true;
			GUIStyle val2 = val;
			GUI.Label(new Rect(((Rect)(ref rect)).x + 12f, ((Rect)(ref rect)).y + 10f, ((Rect)(ref rect)).width - 24f, ((Rect)(ref rect)).height - 20f), lobbyStatusText, val2);
			return yOffset + num2 + 10f;
		}

		private float DrawSharedPoolChances(Rect viewRect, float yOffset, bool isRu)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			string value = REPOConfig.UILanguage.Value;
			string text = ((value == "Korean") ? "공유 풀" : ((!(value == "Russian")) ? "SHARED POOL" : "ОБЩИЙ ПУЛ"));
			string title = text;
			yOffset = DrawModernCategory(viewRect, yOffset, title, new Color(1f, 0.8f, 0.2f, fadeAlpha));
			Dictionary<EventType, float> dictionary = new Dictionary<EventType, float>();
			foreach (EventType value2 in Enum.GetValues(typeof(EventType)))
			{
				dictionary[value2] = REPOEventManager.GetSharedPoolWeight(value2);
			}
			float num = dictionary.Values.Sum();
			foreach (KeyValuePair<EventType, float> item in dictionary.OrderBy((KeyValuePair<EventType, float> k) => (int)k.Key))
			{
				EventType key = item.Key;
				float chance = item.Value / num * 100f;
				string eventIcon = GetEventIcon(key);
				string eventTypeName = GetEventTypeName(key, isRu);
				yOffset = DrawModernChanceItem(viewRect, yOffset, eventIcon, eventTypeName, chance, REPOEventManager.GetEventColor(key));
			}
			return yOffset + 15f;
		}

		private float DrawCategoryChances(Rect viewRect, float yOffset, bool isRu)
		{
			//IL_005f: 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_0160: 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)
			EventCategory[] array = new EventCategory[4]
			{
				EventCategory.LootModifier,
				EventCategory.EnemyModifier,
				EventCategory.PlayerModifier,
				EventCategory.EnvironmentModifier
			};
			foreach (EventCategory category in array)
			{
				List<GameEvent> list = REPOEventManager.AllEvents.Where((GameEvent e) => e.category == category && REPOConfig.ModifierEnables["Enable " + e.id].Value).ToList();
				if (list.Count == 0)
				{
					continue;
				}
				string categoryName = GetCategoryName(category, isRu);
				yOffset = DrawModernCategory(viewRect, yOffset, categoryName, GetCategoryColor(category));
				Dictionary<EventType, float> dictionary = new Dictionary<EventType, float>();
				foreach (GameEvent item in list)
				{
					EventType eventType = item.eventType;
					if (!dictionary.ContainsKey(eventType))
					{
						dictionary[eventType] = 0f;
					}
					dictionary[eventType] += REPOEventManager.GetEventWeight(eventType);
				}
				float num = dictionary.Values.Sum();
				foreach (KeyValuePair<EventType, float> item2 in dictionary.OrderBy((KeyValuePair<EventType, float> k) => (int)k.Key))
				{
					EventType key = item2.Key;
					float chance = item2.Value / num * 100f;
					string eventIcon = GetEventIcon(key);
					string eventTypeName = GetEventTypeName(key, isRu);
					yOffset = DrawModernChanceItem(viewRect, yOffset, eventIcon, eventTypeName, chance, REPOEventManager.GetEventColor(key));
				}
				yOffset += 10f;
			}
			return yOffset;
		}

		private float DrawActiveEventsContent(Rect viewRect, float yOffset)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			bool isRu = REPOConfig.UILanguage.Value == "Russian";
			string currentSceneType = GetCurrentSceneType();
			yOffset = DrawBlackMarketSection(viewRect, yOffset, isRu);
			yOffset = DrawChallengeSection(viewRect, yOffset, isRu);
			yOffset = DrawEconomySection(viewRect, yOffset, isRu);
			yOffset = DrawModifiersSection(viewRect, yOffset, isRu);
			if (currentSceneType == "Level" && (Object)(object)RunManager.instance != (Object)null && REPOConfig.EnableLevelScaling.Value)
			{
				yOffset = DrawLevelScalingSection(viewRect, yOffset, isRu);
			}
			if (currentSceneType == "Level" && (Object)(object)RunManager.instance != (Object)null)
			{
				yOffset = DrawMapScalingSection(viewRect, yOffset, isRu);
			}
			if (currentSceneType == "Level" && (Object)(object)RunManager.instance != (Object)null && REPOConfig.HideVanillaMoonUI.Value)
			{
				yOffset = DrawMoonScalingSection(viewRect, yOffset, isRu);
			}
			return yOffset;
		}

		private float DrawBlackMarketSection(Rect viewRect, float yOffset, bool isRu)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			string activeEventsStatusText = REPOBlackMarketManager.GetActiveEventsStatusText();
			if (string.IsNullOrWhiteSpace(activeEventsStatusText))
			{
				return yOffset;
			}
			string value = REPOConfig.UILanguage.Value;
			string text = ((value == "Korean") ? "암시장" : ((!(value == "Russian")) ? "BLACK MARKET" : "ЧЁРНЫЙ РЫНОК"));
			string title = text;
			yOffset = DrawModernCategory(viewRect, yOffset, title, new Color(1f, 0.62f, 0.14f, fadeAlpha));
			int num = activeEventsStatusText.Split(new char[1] { '\n' }).Length;
			float num2 = Mathf.Max(90f, 24f + (float)num * 22f);
			Rect rect = default(Rect);
			((Rect)(ref rect))..ctor(10f, yOffset, ((Rect)(ref viewRect)).width - 20f, num2);
			DrawModernCard(rect, new Color(1f, 0.62f, 0.14f));
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				fontSize = 14,
				alignment = (TextAnchor)4
			};
			val.normal.textColor = new Color(1f, 0.9f, 0.65f, fadeAlpha);
			val.wordWrap = true;
			GUIStyle val2 = val;
			GUI.Label(new Rect(((Rect)(ref rect)).x + 12f, ((Rect)(ref rect)).y + 10f, ((Rect)(ref rect)).width - 24f, ((Rect)(ref rect)).height - 20f), activeEventsStatusText, val2);
			return yOffset + num2 + 10f;
		}

		private float DrawChallengeSection(Rect viewRect, float yOffset, bool isRu)
		{
			//IL_004f: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: 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_00f1: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Expected O, but got Unknown
			//IL_0176: 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_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Expected O, but got Unknown
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or miss