Decompiled source of artifactofpreparation v1.0.0

ArtifactofPreparation.dll

Decompiled a day ago
using System;
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.Logging;
using HG;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API;
using RoR2;
using UnityEngine;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ArtifactofPreparation")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ArtifactofPreparation")]
[assembly: AssemblyTitle("ArtifactofPreparation")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 ArtifactOfPreparation
{
	[BepInPlugin("com.scott_jc.artifactofpreparation", "Artifact of Preparation", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ArtifactOfPreparationPlugin : BaseUnityPlugin
	{
		public static ArtifactDef PreparationArtifact;

		public void Awake()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			RegisterArtifact();
			Run.Start += new hook_Start(Run_Start);
			Debug.Log((object)"[ArtifactOfPreparation] Awake complete");
		}

		private void RegisterArtifact()
		{
			PreparationArtifact = ScriptableObject.CreateInstance<ArtifactDef>();
			PreparationArtifact.cachedName = "ARTIFACT_PREPARATION";
			PreparationArtifact.nameToken = "ARTIFACT_PREPARATION_NAME";
			PreparationArtifact.descriptionToken = "ARTIFACT_PREPARATION_DESC";
			string path = Path.Combine(Paths.BepInExRootPath, "plugins", "scottjc-artifactofpreparation");
			string path2 = Path.Combine(path, "starterIcon.png");
			string path3 = Path.Combine(path, "starterdeIcon.png");
			Sprite smallIconSelectedSprite = LoadSprite(path2);
			Sprite smallIconDeselectedSprite = LoadSprite(path3);
			PreparationArtifact.smallIconSelectedSprite = smallIconSelectedSprite;
			PreparationArtifact.smallIconDeselectedSprite = smallIconDeselectedSprite;
			LanguageAPI.Add("ARTIFACT_PREPARATION_NAME", "Artifact of Preparation");
			LanguageAPI.Add("ARTIFACT_PREPARATION_DESC", "At the start of the run, each player receives a random set of items.");
			ContentAddition.AddArtifactDef(PreparationArtifact);
			Debug.Log((object)"[ArtifactOfPreparation] Artifact registered");
		}

		private Sprite LoadSprite(string path)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			if (!File.Exists(path))
			{
				return null;
			}
			byte[] array = File.ReadAllBytes(path);
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, array);
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}

		private void Run_Start(orig_Start orig, Run self)
		{
			orig.Invoke(self);
			if (!NetworkServer.active || !Object.op_Implicit((Object)(object)RunArtifactManager.instance) || !RunArtifactManager.instance.IsArtifactEnabled(PreparationArtifact))
			{
				return;
			}
			List<ItemIndex> pool = BuildItemList((ItemTier)0);
			List<ItemIndex> pool2 = BuildItemList((ItemTier)1);
			List<ItemIndex> pool3 = BuildItemList((ItemTier)2);
			List<EquipmentIndex> pool4 = BuildEquipmentList();
			foreach (CharacterMaster readOnlyInstances in CharacterMaster.readOnlyInstancesList)
			{
				if (!((Object)(object)((readOnlyInstances != null) ? readOnlyInstances.inventory : null) == (Object)null))
				{
					GiveRandomItems(readOnlyInstances.inventory, pool, 5);
					GiveRandomItems(readOnlyInstances.inventory, pool2, 3);
					GiveRandomItems(readOnlyInstances.inventory, pool3, 1);
					GiveRandomEquipment(readOnlyInstances.inventory, pool4);
				}
			}
		}

		private static List<ItemIndex> BuildItemList(ItemTier tier)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0015: 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_0044: 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_0059: Invalid comparison between Unknown and I4
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			List<ItemIndex> list = new List<ItemIndex>();
			Enumerator<ItemDef> enumerator = ItemCatalog.allItemDefs.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ItemDef current = enumerator.Current;
					if (!((Object)(object)current == (Object)null) && !current.hidden && current.tier == tier && (int)current.tier != 3)
					{
						list.Add(current.itemIndex);
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			return list;
		}

		private static List<EquipmentIndex> BuildEquipmentList()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			List<EquipmentIndex> list = new List<EquipmentIndex>();
			EquipmentDef[] equipmentDefs = EquipmentCatalog.equipmentDefs;
			foreach (EquipmentDef val in equipmentDefs)
			{
				if (!((Object)(object)val == (Object)null) && !val.isLunar && val.canDrop)
				{
					list.Add(val.equipmentIndex);
				}
			}
			return list;
		}

		private static void GiveRandomItems(Inventory inventory, List<ItemIndex> pool, int count)
		{
			//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_0029: Unknown result type (might be due to invalid IL or missing references)
			if (pool.Count != 0)
			{
				for (int i = 0; i < count; i++)
				{
					ItemIndex val = pool[Random.Range(0, pool.Count)];
					inventory.GiveItem(val, 1);
				}
			}
		}

		private static void GiveRandomEquipment(Inventory inventory, List<EquipmentIndex> pool)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (pool.Count != 0)
			{
				EquipmentIndex equipmentIndex = pool[Random.Range(0, pool.Count)];
				inventory.SetEquipmentIndex(equipmentIndex);
			}
		}
	}
}
namespace ExamplePlugin
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

		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)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
}