Decompiled source of ShapingReshaped v1.0.2

plugins/ShapingReshaped.dll

Decompiled 9 hours ago
using System;
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 Logger;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.ContentManagement;
using RoR2BepInExPack.GameAssetPathsBetter;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: OptIn]
[assembly: IgnoresAccessChecksTo("ItemQualities")]
[assembly: IgnoresAccessChecksTo("ItemQualities.Patcher")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ShapingReshaped")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2740217de751db41c69b8cfba765f2a1225eeb3a")]
[assembly: AssemblyProduct("ShapingReshaped")]
[assembly: AssemblyTitle("ShapingReshaped")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MonoDetour.HookGen
{
	internal static class DefaultMonoDetourManager
	{
		internal static MonoDetourManager Instance { get; } = New();

		internal static MonoDetourManager New()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			return new MonoDetourManager(typeof(DefaultMonoDetourManager).Assembly.GetName().Name);
		}
	}
	[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
	internal class MonoDetourTargetsAttribute(Type? targetType = null) : Attribute(), IMonoDetourTargets
	{
		public Type? TargetType { get; } = targetType;

		public bool IncludeNestedTypes { get; set; } = true;

		public string[]? Members { get; set; }

		public string[]? MemberNamePrefixes { get; set; }

		public string[]? MemberNameSuffixes { get; set; }

		public bool GenerateControlFlowVariants { get; set; }
	}
}
namespace Logger
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void message(object data)
		{
			_logSource.LogInfo(data);
			if (data != null)
			{
				Chat.AddMessage(data.ToString());
			}
			else
			{
				Chat.AddMessage("Null");
			}
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			StackFrame stackFrame = new StackFrame(1);
			MethodBase method = stackFrame.GetMethod();
			_logSource.LogInfo((object)("[" + method.Name + "]: " + data));
		}

		internal static void Message(object data)
		{
			message(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
}
namespace ShapingReshaped
{
	internal static class Options
	{
		public static bool IsEnabled => Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");

		public static void Init()
		{
			ShapingReshaped.InitialSoulCost = ((BaseUnityPlugin)ShapingReshaped.Instance).Config.Bind<int>("General", "Initial Soul Cost", 20, "How much Soul (curse) you pay for activating the shaping shrine (only use intervals of 10)");
			ShapingReshaped.DeathSoulCost = ((BaseUnityPlugin)ShapingReshaped.Instance).Config.Bind<int>("General", "Death Soul Cost", 30, "How much permanent Soul (curse) you pay for dying after being revived with the shrine");
			ShapingReshaped.ShrineWeightMultiplier = ((BaseUnityPlugin)ShapingReshaped.Instance).Config.Bind<float>("General", "Shrine Weight Multiplier", 0.5f, "Shrine weight is multiplied by this value");
			if (IsEnabled)
			{
				RiskOfOptionsConfig();
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void RiskOfOptionsConfig()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_003a: 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)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(ShapingReshaped.InitialSoulCost), "Onyx.ShapingReshaped", "ShapingReshaped");
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(ShapingReshaped.DeathSoulCost), "Onyx.ShapingReshaped", "ShapingReshaped");
			ModSettingsManager.AddOption((BaseOption)new SliderOption(ShapingReshaped.ShrineWeightMultiplier, new SliderConfig
			{
				min = 0f,
				max = 2f
			}), "Onyx.ShapingReshaped", "ShapingReshaped");
			ModSettingsManager.SetModDescription("Options for ShapingReshaped", "Onyx.ShapingReshaped", "ShapingReshaped");
			FileInfo fileInfo = null;
			DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
			do
			{
				FileInfo[] files = directoryInfo.GetFiles("icon.png", SearchOption.TopDirectoryOnly);
				if (files != null && files.Length != 0)
				{
					fileInfo = files[0];
					break;
				}
				directoryInfo = directoryInfo.Parent;
			}
			while (directoryInfo != null && directoryInfo.Exists && !string.Equals(directoryInfo.Name, "plugins", StringComparison.OrdinalIgnoreCase));
			if (fileInfo != null)
			{
				Texture2D val = new Texture2D(256, 256);
				if (ImageConversion.LoadImage(val, File.ReadAllBytes(fileInfo.FullName)))
				{
					Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
					((Object)val2).name = "ShapingReshapedIcon";
					ModSettingsManager.SetModIcon(val2, "Onyx.ShapingReshaped", "ShapingReshaped");
				}
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Onyx.ShapingReshaped", "ShapingReshaped", "1.0.2")]
	public sealed class ShapingReshaped : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_GenerateInteractableCardSelection <0>__GenerateInteractableCardSelection;
		}

		public const string PluginGUID = "Onyx.ShapingReshaped";

		public const string PluginAuthor = "Onyx";

		public const string PluginName = "ShapingReshaped";

		public const string PluginVersion = "1.0.2";

		public static ShapingReshaped Instance;

		public static ItemDef ShapingPermanentSoulCost;

		public static InteractableSpawnCard shrineShapingCard;

		public static ConfigEntry<int> InitialSoulCost { get; set; }

		public static ConfigEntry<int> DeathSoulCost { get; set; }

		public static ConfigEntry<float> ShrineWeightMultiplier { get; set; }

		public void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Expected O, but got Unknown
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Expected O, but got Unknown
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			Instance = SingletonHelper.Assign<ShapingReshaped>(Instance, this);
			Options.Init();
			AsyncOperationHandle<GameObject> val = AssetAsyncReferenceManager<GameObject>.LoadAsset(new AssetReferenceT<GameObject>(RoR2_DLC2.ShrineColossusAccess_prefab), (AsyncReferenceHandleUnloadType)2);
			val.Completed += delegate(AsyncOperationHandle<GameObject> x)
			{
				PurchaseInteraction val4 = default(PurchaseInteraction);
				if (x.Result.TryGetComponent<PurchaseInteraction>(ref val4))
				{
					val4.cost = InitialSoulCost.Value;
				}
			};
			AsyncOperationHandle<InteractableSpawnCard> val2 = AssetAsyncReferenceManager<InteractableSpawnCard>.LoadAsset(new AssetReferenceT<InteractableSpawnCard>(RoR2_DLC2.iscShrineColossusAccess_asset), (AsyncReferenceHandleUnloadType)2);
			val2.Completed += delegate(AsyncOperationHandle<InteractableSpawnCard> x)
			{
				shrineShapingCard = x.Result;
			};
			ShapingPermanentSoulCost = ScriptableObject.CreateInstance<ItemDef>();
			((Object)ShapingPermanentSoulCost).name = "ShapingPermanentSoulCost";
			ShapingPermanentSoulCost.nameToken = "SHAPINGPERMANENTSOULCOST_NAME";
			ShapingPermanentSoulCost.pickupToken = "SHAPINGPERMANENTSOULCOST_PICKUP";
			ShapingPermanentSoulCost.descriptionToken = "SHAPINGPERMANENTSOULCOST_DESC";
			ShapingPermanentSoulCost.loreToken = "SHAPINGPERMANENTSOULCOST_LORE";
			ShapingPermanentSoulCost.hidden = true;
			ShapingPermanentSoulCost.deprecatedTier = (ItemTier)5;
			ShapingPermanentSoulCost.tags = (ItemTag[])(object)new ItemTag[1] { (ItemTag)9 };
			ItemAPI.Add(new CustomItem(ShapingPermanentSoulCost, new ItemDisplayRuleDict((ItemDisplayRule[])null)));
			CharacterMaster.TryReviveOnBodyDeath += new hook_TryReviveOnBodyDeath(TryReviveOnBodyDeath);
			object obj = <>O.<0>__GenerateInteractableCardSelection;
			if (obj == null)
			{
				hook_GenerateInteractableCardSelection val3 = GenerateInteractableCardSelection;
				<>O.<0>__GenerateInteractableCardSelection = val3;
				obj = (object)val3;
			}
			SceneDirector.GenerateInteractableCardSelection += (hook_GenerateInteractableCardSelection)obj;
			RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(GetStatCoefficients);
		}

		private void GetStatCoefficients(CharacterBody sender, StatHookEventArgs args)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)sender) && Object.op_Implicit((Object)(object)sender.inventory) && sender.inventory.GetItemCountEffective(ShapingPermanentSoulCost.itemIndex) > 0)
			{
				args.baseCurseAdd += (float)(sender.inventory.GetItemCountEffective(ShapingPermanentSoulCost.itemIndex) * DeathSoulCost.Value) / 100f;
			}
		}

		private static WeightedSelection<DirectorCard> GenerateInteractableCardSelection(orig_GenerateInteractableCardSelection orig, SceneDirector self)
		{
			//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_0016: 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)
			WeightedSelection<DirectorCard> val = orig.Invoke(self);
			for (int i = 0; i < val.Count; i++)
			{
				ChoiceInfo<DirectorCard> choice = val.GetChoice(i);
				if ((Object)(object)choice.value.spawnCard == (Object)(object)shrineShapingCard)
				{
					val.ModifyChoiceWeight(i, choice.weight * ShrineWeightMultiplier.Value);
				}
			}
			return val;
		}

		private bool TryReviveOnBodyDeath(orig_TryReviveOnBodyDeath orig, CharacterMaster self, CharacterBody body)
		{
			if (body.HasBuff(Buffs.ExtraLifeBuff))
			{
				body.inventory.GiveItemPermanent(ShapingPermanentSoulCost, 1);
			}
			return orig.Invoke(self, body);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}