Decompiled source of Ephemeral Coins v2.3.5

EphemeralCoins.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HG.Reflection;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour.HookGen;
using On.RoR2;
using On.RoR2.UI;
using ProperSave;
using R2API;
using R2API.Networking;
using R2API.Networking.Interfaces;
using R2API.Utils;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.Items;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("EphemeralCoins")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("2.3.3.0")]
[assembly: AssemblyInformationalVersion("2.3.3+633b3f934b8cbafb1f51c5d53cbe7c6c02103fda")]
[assembly: AssemblyProduct("EphemeralCoins")]
[assembly: AssemblyTitle("EphemeralCoins")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.3.3.0")]
[module: UnverifiableCode]
namespace EphemeralCoins;

public static class Assets
{
	public static AssetBundle mainBundle;

	public const string bundleName = "ephemeralcoins";

	public static ArtifactDef NewMoonArtifact;

	internal static string[] lunarInteractables = new string[5] { "RoR2/Base/LunarRecycler/LunarRecycler.prefab", "RoR2/Base/LunarChest/LunarChest.prefab", "RoR2/Base/LunarShopTerminal/LunarShopTerminal.prefab", "RoR2/Base/bazaar/SeerStation.prefab", "RoR2/Base/moon/FrogInteractable.prefab" };

	public static string AssetBundlePath => Path.Combine(Path.GetDirectoryName(EphemeralCoins.PInfo.Location), "ephemeralcoins");

	public static void Init()
	{
		mainBundle = AssetBundle.LoadFromFile(AssetBundlePath);
		NewMoonArtifact = ScriptableObject.CreateInstance<ArtifactDef>();
		NewMoonArtifact.nameToken = "Artifact of the New Moon";
		NewMoonArtifact.descriptionToken = "Lunar Coins become Ephemeral Coins, a temporary per-run currency. <size=70%>(Your saved Lunar Coin count is unaffected.)</size>";
		NewMoonArtifact.smallIconSelectedSprite = mainBundle.LoadAsset<Sprite>("texArtifactNewMoonEnabled");
		NewMoonArtifact.smallIconDeselectedSprite = mainBundle.LoadAsset<Sprite>("texArtifactNewMoonDisabled");
	}
}
public class BepConfig
{
	public static ConfigEntry<float> EnableArtifact;

	public static ConfigEntry<float> StartingCoins;

	public static ConfigEntry<float> DropChance;

	public static ConfigEntry<float> DropMulti;

	public static ConfigEntry<float> DropMin;

	public static ConfigEntry<float> PodCost;

	public static ConfigEntry<float> PortalChance;

	public static ConfigEntry<bool> PortalScale;

	public static ConfigEntry<float> FrogCost;

	public static ConfigEntry<float> FrogPets;

	public static ConfigEntry<float> ShopCost;

	public static ConfigEntry<bool> ShopRefresh;

	public static ConfigEntry<float> SeerCost;

	public static ConfigEntry<float> RerollCost;

	public static ConfigEntry<float> RerollAmount;

	public static ConfigEntry<float> RerollScale;

	public static void Init()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Expected O, but got Unknown
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Expected O, but got Unknown
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Expected O, but got Unknown
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Expected O, but got Unknown
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Expected O, but got Unknown
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Expected O, but got Unknown
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Expected O, but got Unknown
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Expected O, but got Unknown
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Expected O, but got Unknown
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Expected O, but got Unknown
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Expected O, but got Unknown
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Expected O, but got Unknown
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Expected O, but got Unknown
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: Expected O, but got Unknown
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0324: Expected O, but got Unknown
		EnableArtifact = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<float>("1. Artifact", "Run Mode", 1f, new ConfigDescription("If set to 0, disables the artifact. If set to 1, enables the artifact. If set to 2, disables the artifact but enables the artifact's effects at all times.", (AcceptableValueBase)null, Array.Empty<object>()));
		StartingCoins = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<float>("1. Artifact", "Starting Coins", 0f, new ConfigDescription("The number of coins each player starts with when using the artifact.", (AcceptableValueBase)null, Array.Empty<object>()));
		DropChance = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<float>("2. Enemy and Stage", "Drop Chance", 5f, new ConfigDescription("The initial %chance for enemies to drop coins. Vanilla is 0.5%", (AcceptableValueBase)null, Array.Empty<object>()));
		DropMulti = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<float>("2. Enemy and Stage", "Drop Multiplier", 0.9f, new ConfigDescription("The multiplier applied to the drop chance after a coin has dropped. Vanilla is 0.5 (50%)", (AcceptableValueBase)null, Array.Empty<object>()));
		DropMin = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<float>("2. Enemy and Stage", "Drop Min Chance", 0.5f, new ConfigDescription("The lowest %chance for enemies to drop coins after DropMulti is applied. Vanilla has no lower limit", (AcceptableValueBase)null, Array.Empty<object>()));
		PodCost = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<float>("2. Enemy and Stage", "Pod Cost", 0f, new ConfigDescription("The cost of Lunar Pods. Vanilla is 1", (AcceptableValueBase)null, Array.Empty<object>()));
		PortalChance = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<float>("2. Enemy and Stage", "Portal Chance", 0.375f, new ConfigDescription("The chance of a Blue Orb appearing on stage start. Vanilla is 0.375 (37.5%)", (AcceptableValueBase)null, Array.Empty<object>()));
		PortalScale = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<bool>("2. Enemy and Stage", "Portal Scale", false, new ConfigDescription("Scale down the chance of a Blue Orb appearing for each time BTB has been visited? Vanilla behavior is true", (AcceptableValueBase)null, Array.Empty<object>()));
		FrogCost = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<float>("2. Enemy and Stage", "Frog Cost", 0f, new ConfigDescription("The cost of the Frog. Vanilla is 1", (AcceptableValueBase)null, Array.Empty<object>()));
		FrogPets = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<float>("2. Enemy and Stage", "Frog Pets", 1f, new ConfigDescription("The number of times you have to interact with the Frog before something happens. Vanilla is 10", (AcceptableValueBase)null, Array.Empty<object>()));
		ShopCost = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<float>("3. Bazaar Between Time", "Shop Cost", 1f, new ConfigDescription("The cost of Lunar Buds in BTB. Vanilla is 2", (AcceptableValueBase)null, Array.Empty<object>()));
		ShopRefresh = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<bool>("3. Bazaar Between Time", "Shop Refresh", true, new ConfigDescription("Do empty Lunar Buds in BTB refresh when the Slab (reroller) is used? Vanilla is false", (AcceptableValueBase)null, Array.Empty<object>()));
		SeerCost = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<float>("3. Bazaar Between Time", "Seer Cost", 1f, new ConfigDescription("The cost of Lunar Seers in BTB. Vanilla is 3", (AcceptableValueBase)null, Array.Empty<object>()));
		RerollCost = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<float>("3. Bazaar Between Time", "Reroll Cost", 0f, new ConfigDescription("The initial cost of the Slab (reroller) in BTB. Vanilla is 1", (AcceptableValueBase)null, Array.Empty<object>()));
		RerollAmount = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<float>("3. Bazaar Between Time", "Reroll Amount", 1f, new ConfigDescription("How many times can the Slab (reroller) in BTB be used? Enter 0 for infinite (vanilla).", (AcceptableValueBase)null, Array.Empty<object>()));
		RerollScale = ((BaseUnityPlugin)EphemeralCoins.instance).Config.Bind<float>("3. Bazaar Between Time", "Reroll Scale", 2f, new ConfigDescription("The cost multiplier per use of the Slab (reroller) in BTB. Vanilla is 2", (AcceptableValueBase)null, Array.Empty<object>()));
		if (EnableArtifact.Value == 1f)
		{
			ContentAddition.AddArtifactDef(Assets.NewMoonArtifact);
		}
		if (RiskOfOptionsCompatibility.enabled)
		{
			RiskOfOptionsCompatibility.InvokeAddOptionStepSlider(EnableArtifact, 0, 2, 1f, checkArtifact: false, restartRequired: true);
			RiskOfOptionsCompatibility.InvokeAddOptionStepSlider(StartingCoins, 0, 100, 1f, checkArtifact: true);
			RiskOfOptionsCompatibility.InvokeAddOptionStepSlider(DropChance, 0, 100, 0.5f);
			RiskOfOptionsCompatibility.InvokeAddOptionStepSlider(DropMulti, 0, 1, 0.01f);
			RiskOfOptionsCompatibility.InvokeAddOptionStepSlider(DropMin, 0, 100, 0.5f);
			RiskOfOptionsCompatibility.InvokeAddOptionStepSlider(PodCost, 0, 10, 1f);
			RiskOfOptionsCompatibility.InvokeAddOptionStepSlider(PortalChance, 0, 1, 0.01f);
			RiskOfOptionsCompatibility.InvokeAddOptionCheckBox(PortalScale);
			RiskOfOptionsCompatibility.InvokeAddOptionStepSlider(FrogCost, 0, 10, 1f);
			RiskOfOptionsCompatibility.InvokeAddOptionStepSlider(FrogPets, 0, 20, 1f);
			RiskOfOptionsCompatibility.InvokeAddOptionStepSlider(ShopCost, 0, 10, 1f);
			RiskOfOptionsCompatibility.InvokeAddOptionCheckBox(ShopRefresh);
			RiskOfOptionsCompatibility.InvokeAddOptionStepSlider(SeerCost, 0, 10, 1f);
			RiskOfOptionsCompatibility.InvokeAddOptionStepSlider(RerollCost, 0, 10, 1f);
			RiskOfOptionsCompatibility.InvokeAddOptionStepSlider(RerollAmount, 0, 10, 1f);
			RiskOfOptionsCompatibility.InvokeAddOptionStepSlider(RerollScale, 0, 10, 1f);
			RiskOfOptionsCompatibility.InvokeSetModIcon(Assets.mainBundle.LoadAsset<Sprite>("texArtifactNewMoonEnabled"));
			RiskOfOptionsCompatibility.InvokeSetModDescription("<size=200%><uppercase><align=center><color=#adf2fa>Ephemeral Coins</color></align></uppercase></size>\n<size=80%>Provides settings to control various aspects relating to Lunar Coins, including an Artifact that replaces them with temporary, per-run fascimiles that do not affect your save file's coin count. Almost all settings are independant and can be used with or without the Artifact.</size>\n\n<b><color=#CECE00>### WARNING ###\nSettings cannot be changed during a run.\nIn multiplayer, if your settings differ from the host, there may be errors (UNTESTED)!</color></b>");
		}
	}
}
public class CoinStorage
{
	public NetworkInstanceId user;

	public string name;

	public uint ephemeralCoinCount;
}
public class SyncCoinStorage : INetMessage, ISerializableObject
{
	public NetworkInstanceId user;

	public string name;

	public uint ephemeralCoinCount;

	public SyncCoinStorage()
	{
	}

	public SyncCoinStorage(NetworkInstanceId user, string name, uint ephemeralCoinCount)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		this.user = user;
		this.name = name;
		this.ephemeralCoinCount = ephemeralCoinCount;
	}

	public void Deserialize(NetworkReader reader)
	{
		//IL_0003: 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)
		user = reader.ReadNetworkId();
		name = reader.ReadString();
		ephemeralCoinCount = reader.ReadUInt32();
	}

	public void OnReceived()
	{
		//IL_0028: 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_0071: Unknown result type (might be due to invalid IL or missing references)
		if (NetworkServer.active)
		{
			EphemeralCoins.Logger.LogWarning((object)"SyncCoinStorage: Host ran this. Skipping.");
			return;
		}
		CoinStorage coinStorage = new CoinStorage();
		coinStorage.user = user;
		coinStorage.name = name;
		coinStorage.ephemeralCoinCount = ephemeralCoinCount;
		bool flag = false;
		foreach (CoinStorage coinCount in EphemeralCoins.instance.coinCounts)
		{
			if (((NetworkInstanceId)(ref coinCount.user)).Equals(coinStorage.user))
			{
				coinCount.name = coinStorage.name;
				coinCount.ephemeralCoinCount = coinStorage.ephemeralCoinCount;
				flag = true;
				break;
			}
		}
		if (!flag)
		{
			EphemeralCoins.instance.coinCounts.Add(coinStorage);
		}
	}

	public void Serialize(NetworkWriter writer)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		writer.Write(user);
		writer.Write(name);
		writer.Write(ephemeralCoinCount);
	}
}
[BepInDependency("com.bepis.r2api", "4.1.8")]
[R2APISubmoduleDependency(new string[] { "NetworkingAPI" })]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.Varna.EphemeralCoins", "Ephemeral_Coins", "2.3.5")]
public class EphemeralCoins : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static PayCostDelegate <>9__15_1;

		internal void <AddCostType>b__15_1(CostTypeDef costTypeDef, PayCostContext context)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			NetworkUser val = Util.LookUpBodyNetworkUser(((Component)context.activator).gameObject);
			if (Object.op_Implicit((Object)(object)val))
			{
				val.DeductLunarCoins((uint)context.cost);
				MultiShopCardUtils.OnNonMoneyPurchase(context);
			}
		}
	}

	public int numTimesRerolled;

	public List<CoinStorage> coinCounts = new List<CoinStorage>();

	public static EphemeralCoins instance;

	public static ManualLogSource Logger;

	public bool artifactEnabled => BepConfig.EnableArtifact.Value == 2f || (Object.op_Implicit((Object)(object)RunArtifactManager.instance) && RunArtifactManager.instance.IsArtifactEnabled(Assets.NewMoonArtifact));

	public static PluginInfo PInfo { get; private set; }

	public void Awake()
	{
		PInfo = ((BaseUnityPlugin)this).Info;
		instance = this;
		Logger = ((BaseUnityPlugin)this).Logger;
		numTimesRerolled = 0;
		RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(AddCostType));
		RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(AlwaysOnMode));
		Assets.Init();
		BepConfig.Init();
		Hooks.Init();
		NetworkingAPI.RegisterMessageType<SyncCoinStorage>();
	}

	public void SetupCoinStorage(List<CoinStorage> coinStorage, bool NewRun = true)
	{
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		if (NewRun)
		{
			coinStorage.Clear();
		}
		foreach (NetworkUser readOnlyInstances in NetworkUser.readOnlyInstancesList)
		{
			if (coinStorage != null && (Object)(object)readOnlyInstances == (Object)null)
			{
				Logger.LogDebug((object)"A player disconnected! Skipping over what remains of them...");
				continue;
			}
			if (!NewRun && coinStorage != null)
			{
				bool flag = false;
				foreach (CoinStorage item in coinStorage)
				{
					if (((object)(NetworkInstanceId)(ref item.user)).Equals((object?)readOnlyInstances.id))
					{
						flag = true;
						break;
					}
				}
				if (flag)
				{
					continue;
				}
			}
			CoinStorage coinStorage2 = new CoinStorage();
			coinStorage2.user = readOnlyInstances.Network_masterObjectId;
			coinStorage2.name = readOnlyInstances.userName;
			coinStorage2.ephemeralCoinCount = 0u;
			coinStorage.Add(coinStorage2);
			Logger.LogDebug((object)(coinStorage2.name + " added to CoinStorage!"));
			NetMessageExtensions.Send((INetMessage)(object)new SyncCoinStorage(coinStorage2.user, coinStorage2.name, 0u), (NetworkDestination)1);
		}
		Logger.LogDebug((object)"Setting up CoinStorage finished.");
	}

	public void giveCoinsToUser(NetworkUser user, uint count)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		foreach (CoinStorage coinCount in coinCounts)
		{
			if (((NetworkInstanceId)(ref coinCount.user)).Equals(user.Network_masterObjectId))
			{
				coinCount.ephemeralCoinCount += count;
				Logger.LogDebug((object)("giveCoinsToUser: " + user.userName + " " + count));
			}
		}
	}

	public void takeCoinsFromUser(NetworkUser user, uint count)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		foreach (CoinStorage coinCount in coinCounts)
		{
			if (((NetworkInstanceId)(ref coinCount.user)).Equals(user.Network_masterObjectId))
			{
				coinCount.ephemeralCoinCount -= count;
				Logger.LogDebug((object)("takeCoinsFromUser: " + user.userName + " " + count));
			}
		}
	}

	public uint getCoinsFromUser(NetworkUser user)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Run.instance != (Object)null)
		{
			foreach (CoinStorage coinCount in coinCounts)
			{
				if (((NetworkInstanceId)(ref coinCount.user)).Equals(user.Network_masterObjectId))
				{
					return coinCount.ephemeralCoinCount;
				}
			}
		}
		return 0u;
	}

	public void AddCostType()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: 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_0031: Expected O, but got Unknown
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		CostTypeDef val = new CostTypeDef
		{
			costStringFormatToken = "COST_LUNARCOIN_FORMAT",
			saturateWorldStyledCostString = false,
			darkenWorldStyledCostString = true,
			isAffordable = (IsAffordableDelegate)delegate(CostTypeDef costTypeDef, IsAffordableContext context)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: 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)
				NetworkUser val5 = Util.LookUpBodyNetworkUser(((Component)context.activator).gameObject);
				if (artifactEnabled)
				{
					foreach (CoinStorage coinCount in coinCounts)
					{
						if (((NetworkInstanceId)(ref coinCount.user)).Equals(val5.Network_masterObjectId))
						{
							return coinCount.ephemeralCoinCount >= context.cost;
						}
					}
				}
				return Object.op_Implicit((Object)(object)val5) && val5.lunarCoins >= context.cost;
			}
		};
		object obj = <>c.<>9__15_1;
		if (obj == null)
		{
			PayCostDelegate val2 = delegate(CostTypeDef costTypeDef, PayCostContext context)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				NetworkUser val4 = Util.LookUpBodyNetworkUser(((Component)context.activator).gameObject);
				if (Object.op_Implicit((Object)(object)val4))
				{
					val4.DeductLunarCoins((uint)context.cost);
					MultiShopCardUtils.OnNonMoneyPurchase(context);
				}
			};
			<>c.<>9__15_1 = val2;
			obj = (object)val2;
		}
		val.payCost = (PayCostDelegate)obj;
		val.colorIndex = (ColorIndex)12;
		CostTypeDef val3 = val;
		CostTypeCatalog.Register((CostTypeIndex)3, val3);
	}

	public void AlwaysOnMode()
	{
		if (artifactEnabled)
		{
			Logger.LogDebug((object)"Artifact mode 2 (always on/hidden); setting up prefabs.");
			NewMoonArtifactManager.PrefabSetup(set: true);
		}
	}

	public IEnumerator DelayedLunarPriceChange()
	{
		yield return (object)new WaitForSeconds(2f);
		List<PurchaseInteraction> purchaseInteractions = InstanceTracker.GetInstancesList<PurchaseInteraction>();
		foreach (PurchaseInteraction purchaseInteraction in purchaseInteractions)
		{
			if (((Object)purchaseInteraction).name.StartsWith("LunarShop"))
			{
				purchaseInteraction.Networkcost = (int)BepConfig.ShopCost.Value;
				if (BepConfig.ShopCost.Value == 0f)
				{
					purchaseInteraction.costType = (CostTypeIndex)0;
				}
			}
			else if (((Object)purchaseInteraction).name.StartsWith("LunarRecycler"))
			{
				purchaseInteraction.Networkcost = (int)BepConfig.RerollCost.Value;
				if (BepConfig.RerollCost.Value == 0f)
				{
					purchaseInteraction.costType = (CostTypeIndex)0;
				}
			}
		}
	}

	public IEnumerator DelayedStartingLunarCoins()
	{
		yield return (object)new WaitForSeconds(1f);
		Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
		{
			baseToken = "<color=#beeca1><size=15px>A new moon rises...</size></color>"
		});
		yield return (object)new WaitForSeconds(3f);
		if (BepConfig.StartingCoins.Value > 0f)
		{
			SimpleChatMessage val = new SimpleChatMessage();
			val.baseToken = "<nobr><color=#adf2fa><sprite name=\"LunarCoin\" tint=1>" + BepConfig.StartingCoins.Value + "</color></nobr> " + ((BepConfig.StartingCoins.Value > 1f) ? "coins fade" : "coin fades") + " into existence...";
			Chat.SendBroadcastChat((ChatMessageBase)(object)val);
			for (int i = 0; i < PlayerCharacterMasterController.instances.Count; i++)
			{
				PlayerCharacterMasterController.instances[i].networkUser.AwardLunarCoins((uint)BepConfig.StartingCoins.Value);
			}
		}
	}
}
public class Hooks
{
	public static void Init()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Expected O, but got Unknown
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Expected O, but got Unknown
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Expected O, but got Unknown
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Expected O, but got Unknown
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Expected O, but got Unknown
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Expected O, but got Unknown
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Expected O, but got Unknown
		Run.Start += new hook_Start(Run_Start);
		HUD.Update += new hook_Update(HUD_Update);
		Run.OnUserAdded += new hook_OnUserAdded(Run_OnUserAdded);
		NetworkUser.RpcAwardLunarCoins += new hook_RpcAwardLunarCoins(NetworkUser_RpcAwardLunarCoins);
		NetworkUser.RpcDeductLunarCoins += new hook_RpcDeductLunarCoins(NetworkUser_RpcDeductLunarCoins);
		NetworkUser.SyncLunarCoinsToServer += new hook_SyncLunarCoinsToServer(NetworkUser_SyncLunarCoinsToServer);
		PlayerCharacterMasterController.Awake += new hook_Awake(PlayerCharacterMasterController_Awake);
		BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
		MethodInfo methodCached = Reflection.GetMethodCached(typeof(PlayerCharacterMasterController).GetNestedTypes(bindingAttr)[0], "<Init>b__81_0");
		HookEndpointManager.Modify((MethodBase)methodCached, (Delegate)new Action<ILContext>(CoinDropHook));
		TeleporterInteraction.Start += new hook_Start(TeleporterInteraction_Start);
		SceneDirector.Start += new hook_Start(SceneDirector_Start);
		PurchaseInteraction.SetAvailable += new hook_SetAvailable(PurchaseInteraction_SetAvailable);
		PurchaseInteraction.ScaleCost += new hook_ScaleCost(PurchaseInteraction_ScaleCost);
		ShopTerminalBehavior.GenerateNewPickupServer += new hook_GenerateNewPickupServer(ShopTerminalBehavior_GenerateNewPickupServer);
		BazaarController.SetUpSeerStations += new hook_SetUpSeerStations(BazaarController_SetUpSeerStations);
	}

	private static void Run_Start(orig_Start orig, Run self)
	{
		orig.Invoke(self);
		if (NetworkServer.active && EphemeralCoins.instance.artifactEnabled && ((!ProperSaveCompatibility.enabled) ? ((Run.instance.stageClearCount == 0) ? true : false) : ProperSaveCompatibility.IsRunNew()))
		{
			EphemeralCoins.instance.SetupCoinStorage(EphemeralCoins.instance.coinCounts);
			((MonoBehaviour)EphemeralCoins.instance).StartCoroutine(EphemeralCoins.instance.DelayedStartingLunarCoins());
		}
	}

	private static void HUD_Update(orig_Update orig, HUD self)
	{
		orig.Invoke(self);
		if (EphemeralCoins.instance.artifactEnabled)
		{
			self.lunarCoinText.targetValue = (int)EphemeralCoins.instance.getCoinsFromUser(self._localUserViewer.currentNetworkUser);
			if ((Object)(object)self.lunarCoinContainer.transform.Find("LunarCoinSign") != (Object)null)
			{
				((TMP_Text)((Component)self.lunarCoinContainer.transform.Find("LunarCoinSign")).GetComponent<HGTextMeshProUGUI>()).text = "<sprite name=\"LunarCoin\" color=#adf2fa>";
			}
		}
	}

	private static void Run_OnUserAdded(orig_OnUserAdded orig, Run self, NetworkUser user)
	{
		orig.Invoke(self, user);
		if (NetworkServer.active && Run.instance.time > 1f)
		{
			EphemeralCoins.instance.SetupCoinStorage(EphemeralCoins.instance.coinCounts, NewRun: false);
		}
	}

	private static void NetworkUser_RpcAwardLunarCoins(orig_RpcAwardLunarCoins orig, NetworkUser self, uint count)
	{
		if (EphemeralCoins.instance.artifactEnabled)
		{
			orig.Invoke(self, 0u);
			EphemeralCoins.instance.giveCoinsToUser(self, count);
			self.SyncLunarCoinsToServer();
		}
		else
		{
			orig.Invoke(self, count);
		}
	}

	private static void NetworkUser_RpcDeductLunarCoins(orig_RpcDeductLunarCoins orig, NetworkUser self, uint count)
	{
		if (EphemeralCoins.instance.artifactEnabled)
		{
			orig.Invoke(self, 0u);
			EphemeralCoins.instance.takeCoinsFromUser(self, count);
			self.SyncLunarCoinsToServer();
		}
		else
		{
			orig.Invoke(self, count);
		}
	}

	private static void NetworkUser_SyncLunarCoinsToServer(orig_SyncLunarCoinsToServer orig, NetworkUser self)
	{
		orig.Invoke(self);
		if (EphemeralCoins.instance.artifactEnabled)
		{
			self.CallCmdSetNetLunarCoins(EphemeralCoins.instance.getCoinsFromUser(self));
		}
	}

	private static void PlayerCharacterMasterController_Awake(orig_Awake orig, PlayerCharacterMasterController self)
	{
		orig.Invoke(self);
		Reflection.SetFieldValue<float>((object)self, "lunarCoinChanceMultiplier", BepConfig.DropChance.Value);
	}

	private static void CoinDropHook(ILContext il)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		ILCursor val = new ILCursor(il);
		val.GotoNext(new Func<Instruction, bool>[4]
		{
			(Instruction x) => ILPatternMatchingExt.MatchDup(x),
			(Instruction x) => ILPatternMatchingExt.MatchLdfld<PlayerCharacterMasterController>(x, "lunarCoinChanceMultiplier"),
			(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.5f),
			(Instruction x) => ILPatternMatchingExt.MatchMul(x)
		});
		val.Index += 2;
		val.Next.Operand = BepConfig.DropMulti.Value;
		val.Index += 2;
		val.EmitDelegate<Func<float, float>>((Func<float, float>)((float originalChance) => Math.Max(originalChance, BepConfig.DropMin.Value)));
	}

	private static void TeleporterInteraction_Start(orig_Start orig, TeleporterInteraction self)
	{
		self.baseShopSpawnChance = BepConfig.PortalChance.Value;
		if (!BepConfig.PortalScale.Value)
		{
			int shopPortalCount = Run.instance.shopPortalCount;
			Run.instance.shopPortalCount = 0;
			orig.Invoke(self);
			Run.instance.shopPortalCount = shopPortalCount;
		}
		else
		{
			orig.Invoke(self);
		}
	}

	private static void SceneDirector_Start(orig_Start orig, SceneDirector self)
	{
		orig.Invoke(self);
		if (NetworkServer.active)
		{
			((MonoBehaviour)EphemeralCoins.instance).StartCoroutine(EphemeralCoins.instance.DelayedLunarPriceChange());
			EphemeralCoins.instance.numTimesRerolled = 0;
		}
	}

	private static void BazaarController_SetUpSeerStations(orig_SetUpSeerStations orig, BazaarController self)
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		orig.Invoke(self);
		SeerStationController[] seerStations = self.seerStations;
		foreach (SeerStationController val in seerStations)
		{
			((Component)val).GetComponent<PurchaseInteraction>().Networkcost = (int)BepConfig.SeerCost.Value;
			if (BepConfig.SeerCost.Value == 0f)
			{
				((Component)val).GetComponent<PurchaseInteraction>().costType = (CostTypeIndex)0;
			}
		}
	}

	public static void PurchaseInteraction_ScaleCost(orig_ScaleCost orig, PurchaseInteraction self, float scalar)
	{
		if (((Object)self).name.StartsWith("LunarRecycler"))
		{
			scalar = BepConfig.RerollScale.Value;
		}
		orig.Invoke(self, scalar);
	}

	[Server]
	private static void PurchaseInteraction_SetAvailable(orig_SetAvailable orig, PurchaseInteraction self, bool newAvailable)
	{
		if (((Object)self).name.StartsWith("LunarRecycler"))
		{
			if (BepConfig.RerollAmount.Value < 1f || BepConfig.RerollAmount.Value > (float)EphemeralCoins.instance.numTimesRerolled)
			{
				orig.Invoke(self, newAvailable);
			}
			else
			{
				orig.Invoke(self, false);
			}
			EphemeralCoins.instance.numTimesRerolled++;
		}
		else
		{
			orig.Invoke(self, newAvailable);
		}
	}

	[Server]
	private static void ShopTerminalBehavior_GenerateNewPickupServer(orig_GenerateNewPickupServer orig, ShopTerminalBehavior self)
	{
		if (BepConfig.ShopRefresh.Value && ((Object)self).name.StartsWith("LunarShop"))
		{
			self.NetworkhasBeenPurchased = false;
		}
		orig.Invoke(self);
		if (BepConfig.ShopRefresh.Value && ((Object)self).name.StartsWith("LunarShop"))
		{
			((Component)self).GetComponent<PurchaseInteraction>().SetAvailable(true);
		}
	}
}
public static class ProperSaveCompatibility
{
	private static bool? _enabled;

	public static bool enabled
	{
		get
		{
			if (!_enabled.HasValue)
			{
				_enabled = Chainloader.PluginInfos.ContainsKey("com.KingEnderBrine.ProperSave");
			}
			return _enabled.Value;
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining)]
	public static bool IsRunNew()
	{
		return !Loading.IsLoading;
	}
}
public static class RiskOfOptionsCompatibility
{
	private static bool? _enabled;

	public static bool enabled
	{
		get
		{
			if (!_enabled.HasValue)
			{
				_enabled = Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");
			}
			return _enabled.Value;
		}
	}

	public static void InvokeAddOptionStepSlider(ConfigEntry<float> configEntry, int min, int max, float increment)
	{
		InvokeAddOptionStepSlider(configEntry, min, max, increment, checkArtifact: false, restartRequired: false);
	}

	public static void InvokeAddOptionStepSlider(ConfigEntry<float> configEntry, int min, int max, float increment, bool checkArtifact)
	{
		InvokeAddOptionStepSlider(configEntry, min, max, increment, checkArtifact, restartRequired: false);
	}

	public static void InvokeAddOptionStepSlider(ConfigEntry<float> configEntry, int min, int max, float increment, bool checkArtifact, bool restartRequired)
	{
		//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_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		//IL_004b: Expected O, but got Unknown
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		ModSettingsManager.AddOption((BaseOption)new StepSliderOption(configEntry, new StepSliderConfig
		{
			min = min,
			max = max,
			increment = increment,
			restartRequired = restartRequired,
			checkIfDisabled = (IsDisabledDelegate)(() => checkIfDisabled(checkArtifact))
		}));
	}

	public static void InvokeAddOptionCheckBox(ConfigEntry<bool> configEntry)
	{
		InvokeAddOptionCheckBox(configEntry, checkArtifact: false, restartRequired: false);
	}

	public static void InvokeAddOptionCheckBox(ConfigEntry<bool> configEntry, bool checkArtifact)
	{
		InvokeAddOptionCheckBox(configEntry, checkArtifact, restartRequired: false);
	}

	public static void InvokeAddOptionCheckBox(ConfigEntry<bool> configEntry, bool checkArtifact, bool restartRequired)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		//IL_0032: Expected O, but got Unknown
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(configEntry, new CheckBoxConfig
		{
			restartRequired = restartRequired,
			checkIfDisabled = (IsDisabledDelegate)(() => checkIfDisabled(checkArtifact))
		}));
	}

	public static bool checkIfDisabled(bool checkArtifact = false)
	{
		return ((Object)(object)Run.instance != (Object)null) | (checkArtifact & (BepConfig.EnableArtifact.Value == 0f));
	}

	public static void InvokeSetModIcon(Sprite iconSprite)
	{
		ModSettingsManager.SetModIcon(iconSprite);
	}

	public static void InvokeSetModDescription(string desc)
	{
		ModSettingsManager.SetModDescription(desc);
	}
}
public static class NewMoonArtifactManager
{
	[SystemInitializer(new Type[] { typeof(ArtifactCatalog) })]
	private static void Init()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		EphemeralCoins.Logger.LogDebug((object)"NewMoonArtifactManager initialized");
		RunArtifactManager.onArtifactEnabledGlobal += new ArtifactStateChangeDelegate(OnArtifactEnabled);
		RunArtifactManager.onArtifactDisabledGlobal += new ArtifactStateChangeDelegate(OnArtifactDisabled);
	}

	private static void OnArtifactEnabled(RunArtifactManager runArtifactManager, ArtifactDef artifactDef)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		if (!((Object)(object)artifactDef != (Object)(object)Assets.NewMoonArtifact))
		{
			EphemeralCoins.Logger.LogDebug((object)"OnArtifactEnabled hook applied");
			Run.Start += new hook_Start(Run_Start);
		}
	}

	private static void Run_Start(orig_Start orig, Run self)
	{
		EphemeralCoins.Logger.LogDebug((object)"Artifact enabled");
		PrefabSetup(set: true);
		orig.Invoke(self);
	}

	private static void OnArtifactDisabled(RunArtifactManager runArtifactManager, ArtifactDef artifactDef)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		if (!((Object)(object)artifactDef != (Object)(object)Assets.NewMoonArtifact))
		{
			Run.Start -= new hook_Start(Run_Start);
			EphemeralCoins.Logger.LogDebug((object)"Artifact disabled");
			PrefabSetup();
		}
	}

	public static void PrefabSetup(bool set = false)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: 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_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		EphemeralCoins.Logger.LogDebug((object)("PrefabSetup " + set));
		PickupIndex val = PickupCatalog.FindPickupIndex("LunarCoin.Coin0");
		PickupDef pickupDef = ((PickupIndex)(ref val)).pickupDef;
		pickupDef.nameToken = (set ? "Ephemeral Coin" : "PICKUP_LUNAR_COIN");
		pickupDef.interactContextToken = (set ? "Pick up Ephemeral Coin" : "LUNAR_COIN_PICKUP_CONTEXT");
		pickupDef.baseColor = Color32.op_Implicit(set ? new Color32((byte)96, (byte)254, byte.MaxValue, byte.MaxValue) : new Color32((byte)48, (byte)127, byte.MaxValue, byte.MaxValue));
		pickupDef.darkColor = Color32.op_Implicit(set ? new Color32((byte)152, (byte)168, byte.MaxValue, byte.MaxValue) : new Color32((byte)76, (byte)84, (byte)144, byte.MaxValue));
		GameObject val2 = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/LunarCoin/PickupLunarCoin.prefab").WaitForCompletion();
		((Component)val2.transform.Find("Coin5Mesh")).GetComponent<MeshFilter>().mesh = (set ? Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Common/VFX/mdlLunarCoin.fbx").WaitForCompletion().GetComponent<MeshFilter>()
			.mesh : Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Common/VFX/mdlLunarCoinWithHole.fbx").WaitForCompletion().GetComponent<MeshFilter>()
			.mesh);
		((Renderer)((Component)val2.transform.Find("Coin5Mesh")).GetComponent<MeshRenderer>()).material = (set ? Assets.mainBundle.LoadAsset<Material>("matEphemeralCoin") : Addressables.LoadAssetAsync<Material>((object)"RoR2/Base/Common/VFX/matLunarCoinPlaceholder.mat").WaitForCompletion());
		string[] lunarInteractables = Assets.lunarInteractables;
		foreach (string text in lunarInteractables)
		{
			GameObject val3 = Addressables.LoadAssetAsync<GameObject>((object)text).WaitForCompletion();
			int num = 0;
			switch (((Object)val3).name)
			{
			case "LunarRecycler":
				num = (int)BepConfig.RerollCost.Value;
				break;
			case "LunarChest":
				num = (int)BepConfig.PodCost.Value;
				break;
			case "LunarShopTerminal":
				num = (int)BepConfig.ShopCost.Value;
				break;
			case "SeerStation":
				num = (int)BepConfig.SeerCost.Value;
				break;
			case "FrogInteractable":
				num = (int)BepConfig.FrogCost.Value;
				val3.GetComponent<FrogController>().maxPets = (int)BepConfig.FrogPets.Value;
				break;
			default:
				EphemeralCoins.Logger.LogWarning((object)("Unknown lunarInteractable " + text + ", will default to 0 cost!"));
				break;
			}
			val3.GetComponent<PurchaseInteraction>().Networkcost = num;
			if (num == 0)
			{
				val3.GetComponent<PurchaseInteraction>().costType = (CostTypeIndex)0;
			}
		}
	}
}