Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of CommandExcludeTemporaryItems v1.0.0
CommandExcludeTemporaryItems.dll
Decompiled 2 days agousing System; using System.Collections.Generic; using System.Collections.ObjectModel; 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 Microsoft.CodeAnalysis; using On.RoR2; using R2API; using RoR2; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("CommandExcludeTemporaryItems")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+9ec90b6d7a1c9511711b420853d5f830d2a2442a")] [assembly: AssemblyProduct("CommandExcludeTemporaryItems")] [assembly: AssemblyTitle("CommandExcludeTemporaryItems")] [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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace CommandExcludeTemporaryItems { internal static class ArtifactRegistration { private static Sprite _fallbackArtifactIcon; private const string ArtifactNameToken = "COMMANDEXCLUDETEMPORARYITEMS_ARTIFACT_COMMAND_EXCLUDE_TEMP_NAME"; private const string ArtifactDescriptionToken = "COMMANDEXCLUDETEMPORARYITEMS_ARTIFACT_COMMAND_EXCLUDE_TEMP_DESC"; private const string UnlockableNameToken = "COMMANDEXCLUDETEMPORARYITEMS_UNLOCKABLE_COMMAND_EXCLUDE_TEMP_NAME"; internal static ArtifactDef ExcludeTemporaryItemsArtifact { get; private set; } internal static UnlockableDef ExcludeTemporaryItemsUnlockable { get; private set; } internal static void Register() { ExcludeTemporaryItemsUnlockable = ScriptableObject.CreateInstance<UnlockableDef>(); ExcludeTemporaryItemsUnlockable.cachedName = "UNLOCKABLE_COMMAND_EXCLUDE_TEMPORARY_ITEMS"; ExcludeTemporaryItemsUnlockable.nameToken = "COMMANDEXCLUDETEMPORARYITEMS_UNLOCKABLE_COMMAND_EXCLUDE_TEMP_NAME"; ExcludeTemporaryItemsUnlockable.hidden = false; ContentAddition.AddUnlockableDef(ExcludeTemporaryItemsUnlockable); ExcludeTemporaryItemsArtifact = ScriptableObject.CreateInstance<ArtifactDef>(); ExcludeTemporaryItemsArtifact.cachedName = "COMMAND_EXCLUDE_TEMPORARY_ITEMS"; ExcludeTemporaryItemsArtifact.nameToken = "COMMANDEXCLUDETEMPORARYITEMS_ARTIFACT_COMMAND_EXCLUDE_TEMP_NAME"; ExcludeTemporaryItemsArtifact.descriptionToken = "COMMANDEXCLUDETEMPORARYITEMS_ARTIFACT_COMMAND_EXCLUDE_TEMP_DESC"; ExcludeTemporaryItemsArtifact.unlockableDef = ExcludeTemporaryItemsUnlockable; ArtifactDef command = Artifacts.Command; Sprite val = command?.smallIconDeselectedSprite; Sprite val2 = command?.smallIconSelectedSprite; Sprite val3 = val2 ?? val ?? GetFallbackArtifactIcon(); ExcludeTemporaryItemsArtifact.smallIconDeselectedSprite = val ?? val3; ExcludeTemporaryItemsArtifact.smallIconSelectedSprite = val2 ?? val3; LanguageAPI.Add("COMMANDEXCLUDETEMPORARYITEMS_ARTIFACT_COMMAND_EXCLUDE_TEMP_NAME", "Command: Exclude Temporary Items"); LanguageAPI.Add("COMMANDEXCLUDETEMPORARYITEMS_ARTIFACT_COMMAND_EXCLUDE_TEMP_DESC", "While Artifact of Command is active, temporary item drops spawn as normal pickups instead of command choices."); LanguageAPI.Add("COMMANDEXCLUDETEMPORARYITEMS_UNLOCKABLE_COMMAND_EXCLUDE_TEMP_NAME", "Command: Exclude Temporary Items"); ContentAddition.AddArtifactDef(ExcludeTemporaryItemsArtifact); LocalUserManager.onUserSignIn += LocalUserManager_onUserSignIn; GrantUnlockableToExistingLocalUsers(); Log.Info("Registered artifact: Command: Exclude Temporary Items", "F:\\projects\\risk-of-rain-2-mod-command-exclude-temporary-items\\ArtifactRegistration.cs", 48); } private static void LocalUserManager_onUserSignIn(LocalUser localUser) { GrantUnlockable(localUser); } private static void GrantUnlockableToExistingLocalUsers() { ReadOnlyCollection<LocalUser> readOnlyLocalUsersList = LocalUserManager.readOnlyLocalUsersList; if (readOnlyLocalUsersList == null) { return; } foreach (LocalUser item in readOnlyLocalUsersList) { GrantUnlockable(item); } } private static void GrantUnlockable(LocalUser localUser) { if (localUser != null && localUser.userProfile != null && !((Object)(object)ExcludeTemporaryItemsUnlockable == (Object)null) && !localUser.userProfile.HasUnlockable(ExcludeTemporaryItemsUnlockable)) { localUser.userProfile.GrantUnlockable(ExcludeTemporaryItemsUnlockable); } } private static Sprite GetFallbackArtifactIcon() { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Expected O, but got Unknown if ((Object)(object)_fallbackArtifactIcon != (Object)null) { return _fallbackArtifactIcon; } _fallbackArtifactIcon = LegacyResourcesAPI.Load<Sprite>("Textures/MiscIcons/texMysteryIcon"); if ((Object)(object)_fallbackArtifactIcon != (Object)null) { return _fallbackArtifactIcon; } _fallbackArtifactIcon = LegacyResourcesAPI.Load<Sprite>("textures/miscicons/texMysteryIcon"); if ((Object)(object)_fallbackArtifactIcon != (Object)null) { return _fallbackArtifactIcon; } Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false) { name = "CommandExcludeTemporaryItems_FallbackArtifactIcon" }; val.SetPixel(0, 0, Color32.op_Implicit(new Color32(byte.MaxValue, (byte)0, byte.MaxValue, byte.MaxValue))); val.Apply(); _fallbackArtifactIcon = Sprite.Create(val, new Rect(0f, 0f, 1f, 1f), new Vector2(0.5f, 0.5f), 1f); return _fallbackArtifactIcon; } } internal static class Hooks { [CompilerGenerated] private static class <>O { public static hook_IfCommandChestSpawned <0>__PickupDropletController_IfCommandChestSpawned; public static hook_CreateCommandCube <1>__PickupDropletController_CreateCommandCube; public static hook_CreatePickup <2>__GenericPickupController_CreatePickup; public static hook_SetOptionsFromPickupForCommandArtifact_UniquePickup <3>__PickupPickerController_SetOptionsFromPickupForCommandArtifact_UniquePickup; } private static int _suppressCommandChestSpawnDepth; private static FieldInfo _createPickupInfoPickupIndexField; private static FieldInfo _createPickupInfoUniquePickupField; private static FieldInfo _createPickupInfoCommandBoolField; private static bool _createPickupInfoFieldsInitialized; internal static void Init() { //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_001b: Expected O, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //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) //IL_005b: Expected O, but got Unknown //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Expected O, but got Unknown object obj = <>O.<0>__PickupDropletController_IfCommandChestSpawned; if (obj == null) { hook_IfCommandChestSpawned val = PickupDropletController_IfCommandChestSpawned; <>O.<0>__PickupDropletController_IfCommandChestSpawned = val; obj = (object)val; } PickupDropletController.IfCommandChestSpawned += (hook_IfCommandChestSpawned)obj; object obj2 = <>O.<1>__PickupDropletController_CreateCommandCube; if (obj2 == null) { hook_CreateCommandCube val2 = PickupDropletController_CreateCommandCube; <>O.<1>__PickupDropletController_CreateCommandCube = val2; obj2 = (object)val2; } PickupDropletController.CreateCommandCube += (hook_CreateCommandCube)obj2; object obj3 = <>O.<2>__GenericPickupController_CreatePickup; if (obj3 == null) { hook_CreatePickup val3 = GenericPickupController_CreatePickup; <>O.<2>__GenericPickupController_CreatePickup = val3; obj3 = (object)val3; } GenericPickupController.CreatePickup += (hook_CreatePickup)obj3; object obj4 = <>O.<3>__PickupPickerController_SetOptionsFromPickupForCommandArtifact_UniquePickup; if (obj4 == null) { hook_SetOptionsFromPickupForCommandArtifact_UniquePickup val4 = PickupPickerController_SetOptionsFromPickupForCommandArtifact_UniquePickup; <>O.<3>__PickupPickerController_SetOptionsFromPickupForCommandArtifact_UniquePickup = val4; obj4 = (object)val4; } PickupPickerController.SetOptionsFromPickupForCommandArtifact_UniquePickup += (hook_SetOptionsFromPickupForCommandArtifact_UniquePickup)obj4; } private static void PickupPickerController_SetOptionsFromPickupForCommandArtifact_UniquePickup(orig_SetOptionsFromPickupForCommandArtifact_UniquePickup orig, PickupPickerController self, UniquePickup pickup) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) if (!ShouldApplyCommandTemporaryExclusion() || !IsTemporaryPickup(pickup)) { orig.Invoke(self, pickup); return; } self.CreatePickup(pickup); if ((Object)(object)self != (Object)null) { Object.Destroy((Object)(object)((Component)self).gameObject); } } private static void PickupDropletController_CreateCommandCube(orig_CreateCommandCube orig, PickupDropletController self) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) if (_suppressCommandChestSpawnDepth > 0) { orig.Invoke(self); return; } if (!ShouldApplyCommandTemporaryExclusion() || !IsTemporaryPickup(self.pickupState)) { orig.Invoke(self); return; } _suppressCommandChestSpawnDepth++; try { self.CreatePickup(); } finally { _suppressCommandChestSpawnDepth--; } } private static GenericPickupController GenericPickupController_CreatePickup(orig_CreatePickup orig, ref CreatePickupInfo createPickupInfo) { if (!ShouldApplyCommandTemporaryExclusion() || !IsTemporaryCreatePickup(ref createPickupInfo)) { return orig.Invoke(ref createPickupInfo); } TryDisableCommandForCreatePickup(ref createPickupInfo); _suppressCommandChestSpawnDepth++; try { return orig.Invoke(ref createPickupInfo); } finally { _suppressCommandChestSpawnDepth--; } } private static void PickupDropletController_IfCommandChestSpawned(orig_IfCommandChestSpawned orig, bool value, PickupIndex pickupIndex, Vector3 position, Vector3 velocity) { //IL_0005: 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_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_0036: 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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: 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_0045: Unknown result type (might be due to invalid IL or missing references) if (!value) { orig.Invoke(value, pickupIndex, position, velocity); return; } if (_suppressCommandChestSpawnDepth > 0) { orig.Invoke(false, pickupIndex, position, velocity); return; } if (!ShouldApplyCommandTemporaryExclusion()) { orig.Invoke(value, pickupIndex, position, velocity); return; } if (IsTemporaryPickup(pickupIndex)) { value = false; } orig.Invoke(value, pickupIndex, position, velocity); } private static bool ShouldApplyCommandTemporaryExclusion() { RunArtifactManager instance = RunArtifactManager.instance; if ((Object)(object)instance == (Object)null) { return false; } ArtifactDef excludeTemporaryItemsArtifact = ArtifactRegistration.ExcludeTemporaryItemsArtifact; if ((Object)(object)excludeTemporaryItemsArtifact == (Object)null) { return false; } if (instance.IsArtifactEnabled(Artifacts.Command)) { return instance.IsArtifactEnabled(excludeTemporaryItemsArtifact); } return false; } private static bool TryGetItemDef(PickupIndex pickupIndex, out ItemDef itemDef) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 //IL_001a: Unknown result type (might be due to invalid IL or missing references) itemDef = null; PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex); if (pickupDef == null || (int)pickupDef.itemIndex == -1) { return false; } itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex); return (Object)(object)itemDef != (Object)null; } private static bool IsTemporaryPickup(PickupIndex pickupIndex) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (pickupIndex == PickupIndex.none) { return false; } if (TryGetItemDef(pickupIndex, out var itemDef)) { return Utilities.IsTemporaryItem(itemDef); } return false; } private static bool IsTemporaryPickup(UniquePickup pickupState) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (!((UniquePickup)(ref pickupState)).isValid) { return false; } if (((UniquePickup)(ref pickupState)).isTempItem) { return true; } return IsTemporaryPickup(pickupState.pickupIndex); } private static bool IsTemporaryCreatePickup(ref CreatePickupInfo createPickupInfo) { //IL_0006: 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) //IL_004f: Unknown result type (might be due to invalid IL or missing references) EnsureCreatePickupInfoFields(); object obj = createPickupInfo; if (_createPickupInfoUniquePickupField != null && IsTemporaryPickup((UniquePickup)_createPickupInfoUniquePickupField.GetValue(obj))) { return true; } if (_createPickupInfoPickupIndexField != null) { return IsTemporaryPickup((PickupIndex)_createPickupInfoPickupIndexField.GetValue(obj)); } return false; } private static void TryDisableCommandForCreatePickup(ref CreatePickupInfo createPickupInfo) { //IL_0014: 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_0037: Unknown result type (might be due to invalid IL or missing references) EnsureCreatePickupInfoFields(); if (!(_createPickupInfoCommandBoolField == null)) { object obj = createPickupInfo; _createPickupInfoCommandBoolField.SetValue(obj, false); createPickupInfo = (CreatePickupInfo)obj; } } private static void EnsureCreatePickupInfoFields() { if (_createPickupInfoFieldsInitialized) { return; } _createPickupInfoFieldsInitialized = true; FieldInfo[] fields = typeof(CreatePickupInfo).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (_createPickupInfoUniquePickupField == null && fieldInfo.FieldType == typeof(UniquePickup)) { _createPickupInfoUniquePickupField = fieldInfo; } else if (_createPickupInfoPickupIndexField == null && fieldInfo.FieldType == typeof(PickupIndex) && fieldInfo.Name.IndexOf("pickup", StringComparison.OrdinalIgnoreCase) >= 0) { _createPickupInfoPickupIndexField = fieldInfo; } else if (_createPickupInfoCommandBoolField == null && fieldInfo.FieldType == typeof(bool) && fieldInfo.Name.IndexOf("command", StringComparison.OrdinalIgnoreCase) >= 0) { _createPickupInfoCommandBoolField = fieldInfo; } } } } internal static class Log { private static ManualLogSource _logSource; internal static void Init(ManualLogSource logSource) { _logSource = logSource; } private static string Format(object data, string file, int line) { string fileName = Path.GetFileName(file); return $"[{fileName}:{line}] {data}"; } internal static void Debug(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) { _logSource.LogDebug((object)Format(data, file, line)); } internal static void Error(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) { _logSource.LogError((object)Format(data, file, line)); } internal static void Fatal(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) { _logSource.LogFatal((object)Format(data, file, line)); } internal static void Info(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) { _logSource.LogInfo((object)Format(data, file, line)); } internal static void Message(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) { _logSource.LogMessage((object)Format(data, file, line)); } internal static void Warning(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) { _logSource.LogWarning((object)Format(data, file, line)); } } [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("RiskOfRain2Modding.CommandExcludeTemporaryItems", "CommandExcludeTemporaryItems", "1.0.0")] public class Plugin : BaseUnityPlugin { public const string PluginAuthor = "RiskOfRain2Modding"; public const string PluginName = "CommandExcludeTemporaryItems"; public const string PluginVersion = "1.0.0"; public const string PluginGUID = "RiskOfRain2Modding.CommandExcludeTemporaryItems"; public void Awake() { Log.Init(((BaseUnityPlugin)this).Logger); ArtifactRegistration.Register(); Hooks.Init(); } } internal static class Utilities { private static readonly HashSet<ItemIndex> TemporaryItemIndices = new HashSet<ItemIndex>(); private static bool _seeded; private static readonly string[] TemporaryItemInternalNames = new string[2] { "RegeneratingScrap", "RegeneratingScrapConsumed" }; internal static bool IsTemporaryItem(ItemDef item) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)item == (Object)null) { return false; } if (item.isConsumed) { return true; } EnsureTemporaryItemSeed(); return TemporaryItemIndices.Contains(item.itemIndex); } private static void EnsureTemporaryItemSeed() { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: 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_0023: Invalid comparison between Unknown and I4 //IL_002a: Unknown result type (might be due to invalid IL or missing references) if (_seeded) { return; } _seeded = true; string[] temporaryItemInternalNames = TemporaryItemInternalNames; for (int i = 0; i < temporaryItemInternalNames.Length; i++) { ItemIndex val = ItemCatalog.FindItemIndex(temporaryItemInternalNames[i]); if ((int)val != -1) { TemporaryItemIndices.Add(val); } } } } }