Some mods may be broken due to the recent Alloyed Collective update.
Decompiled source of artifactofpreparation v1.0.2
ArtifactofPreparation.dll
Decompiled 2 days agousing 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.Configuration; 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.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class ArtifactOfPreparationPlugin : BaseUnityPlugin { public static ArtifactDef PreparationArtifact; private static bool poolsBuilt; private static List<ItemIndex> whitePool; private static List<ItemIndex> greenPool; private static List<ItemIndex> redPool; private static List<ItemIndex> yellowPool; private static List<ItemIndex> bluePool; private static List<ItemIndex> purplePool; private static List<EquipmentIndex> equipmentPool; private static ConfigEntry<bool> configRefresh; private static ConfigEntry<bool> configexcludescrap; private static ConfigEntry<bool> configexcludedebugequip; private static ConfigEntry<int> configprepgivered; private static ConfigEntry<int> configprepgivegreen; private static ConfigEntry<int> configprepgivewhite; private static ConfigEntry<int> configprepgivepurple; private static ConfigEntry<int> configprepgiveblue; private static ConfigEntry<int> configprepgiveyellow; private static ConfigEntry<bool> configprepgiveequip; private static ConfigEntry<bool> configprepgiveequiplunar; 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); } private void RegisterArtifact() { PreparationArtifact = ScriptableObject.CreateInstance<ArtifactDef>(); PreparationArtifact.cachedName = "ARTIFACT_PREPARATION"; PreparationArtifact.nameToken = "ARTIFACT_PREPARATION_NAME"; PreparationArtifact.descriptionToken = "ARTIFACT_PREPARATION_DESC"; Sprite smallIconSelectedSprite = LoadSprite(Path.Combine(Paths.BepInExRootPath, "plugins", "scottjc-artifactofpreparation", "starterIcon.png")); Sprite smallIconDeselectedSprite = LoadSprite(Path.Combine(Paths.BepInExRootPath, "plugins", "scottjc-artifactofpreparation", "starterdeIcon.png")); 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); } 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; } LoadConfig(); if (!poolsBuilt || configRefresh.Value) { whitePool = BuildItemList((ItemTier)0); greenPool = BuildItemList((ItemTier)1); redPool = BuildItemList((ItemTier)2); yellowPool = BuildItemList((ItemTier)4); bluePool = BuildItemList((ItemTier)3); purplePool = BuildVoidItemList(); equipmentPool = BuildEquipmentList(); poolsBuilt = true; } foreach (CharacterMaster readOnlyInstances in CharacterMaster.readOnlyInstancesList) { if (!((Object)(object)((readOnlyInstances != null) ? readOnlyInstances.inventory : null) == (Object)null)) { GiveRandomItems(readOnlyInstances.inventory, whitePool, configprepgivewhite.Value); GiveRandomItems(readOnlyInstances.inventory, greenPool, configprepgivegreen.Value); GiveRandomItems(readOnlyInstances.inventory, redPool, configprepgivered.Value); GiveRandomItems(readOnlyInstances.inventory, yellowPool, configprepgiveyellow.Value); GiveRandomItems(readOnlyInstances.inventory, bluePool, configprepgiveblue.Value); GiveRandomItems(readOnlyInstances.inventory, purplePool, configprepgivepurple.Value); if (configprepgiveequip.Value) { GiveRandomEquipment(readOnlyInstances.inventory, equipmentPool); } } } } private void LoadConfig() { configRefresh = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "configRefresh", false, "Whether or not I should build the item lists every single run or not (Failsafe for other mod interactions)"); configexcludescrap = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "excludescrap", true, "Whether or not I Exclude scrap or not"); configexcludedebugequip = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "excludedebugequip", true, "Whether or not I Exclude debug equips or not"); configprepgivered = ((BaseUnityPlugin)this).Config.Bind<int>("Main", "prepgivered", 1, "How many legendary (Red) items to give"); configprepgivegreen = ((BaseUnityPlugin)this).Config.Bind<int>("Main", "prepgivegreen", 3, "How many Uncommon (Green) Items to give"); configprepgivewhite = ((BaseUnityPlugin)this).Config.Bind<int>("Main", "prepgivewhite", 5, "How many Common (White) items to give"); configprepgiveequip = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "prepgiveequip", true, "Whether to give an equipment or not"); configprepgiveequiplunar = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "prepgiveequiplunar", false, "Whether or not to include lunar equipments in the list."); configprepgivepurple = ((BaseUnityPlugin)this).Config.Bind<int>("Main", "prepgivepurple", 0, "How many Void (Purple) Items to give"); configprepgiveyellow = ((BaseUnityPlugin)this).Config.Bind<int>("Main", "prepgiveyellow", 0, "How many Boss (Yellow) items to give"); configprepgiveblue = ((BaseUnityPlugin)this).Config.Bind<int>("Main", "prepgiveblue", 0, "How many Lunar (Blue) Items to give"); } 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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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) 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 && (!current.ContainsTag((ItemTag)10) || !configexcludescrap.Value)) { list.Add(current.itemIndex); } } } finally { ((IDisposable)enumerator).Dispose(); } return list; } private static List<ItemIndex> BuildVoidItemList() { //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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Invalid comparison between Unknown and I4 //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Invalid comparison between Unknown and I4 //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Invalid comparison between Unknown and I4 //IL_0072: 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_005f: Invalid comparison between Unknown and I4 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 && ((int)current.tier == 6 || (int)current.tier == 7 || (int)current.tier == 8 || (int)current.tier == 9)) { list.Add(current.itemIndex); } } } finally { ((IDisposable)enumerator).Dispose(); } return list; } private static List<EquipmentIndex> BuildEquipmentList() { //IL_0075: 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 || configprepgiveequiplunar.Value) && val.canDrop && configexcludedebugequip.Value) { list.Add(val.equipmentIndex); } } return list; } private static void GiveRandomItems(Inventory inventory, List<ItemIndex> pool, int count) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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); } } }