using System; using System.Diagnostics; using System.Linq; 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 DropSourceForItems; using Mdh.RoR2.PickupDropletController; using Microsoft.CodeAnalysis; using MiscFixes.Modules; using MonoDetour; using MonoDetour.Cil; using MonoDetour.DetourTypes; using MonoDetour.HookGen; using RoR2; using RoR2.ContentManagement; using RoR2.ExpansionManagement; using RoR2BepInExPack.GameAssetPaths.Version_1_39_0; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; [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("LordVGames.NoHiddenRealmItemFarming")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+16d1fe16493aa3f5fce68ee09e33c8c5c3184bcc")] [assembly: AssemblyProduct("LordVGames.NoHiddenRealmItemFarming")] [assembly: AssemblyTitle("NoHiddenRealmItemFarming")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] 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 Mdh.RoR2.PickupDropletController { internal static class CreatePickupDroplet_RoR2_GenericPickupController_CreatePickupInfo_UnityEngine_Vector3_UnityEngine_Vector3 { public delegate void PrefixSignature(ref CreatePickupInfo pickupInfo, ref Vector3 position, ref Vector3 velocity); public delegate ReturnFlow ControlFlowPrefixSignature(ref CreatePickupInfo pickupInfo, ref Vector3 position, ref Vector3 velocity); public delegate void PostfixSignature(ref CreatePickupInfo pickupInfo, ref Vector3 position, ref Vector3 velocity); public static MonoDetourHook Prefix(PrefixSignature hook, MonoDetourConfig? config = null, bool applyByDefault = true, MonoDetourManager? manager = null) { return (manager ?? DefaultMonoDetourManager.Instance).Hook(Target(), (Delegate)hook, config, applyByDefault); } public static MonoDetourHook ControlFlowPrefix(ControlFlowPrefixSignature hook, MonoDetourConfig? config = null, bool applyByDefault = true, MonoDetourManager? manager = null) { return (manager ?? DefaultMonoDetourManager.Instance).Hook(Target(), (Delegate)hook, config, applyByDefault); } public static MonoDetourHook Postfix(PostfixSignature hook, MonoDetourConfig? config = null, bool applyByDefault = true, MonoDetourManager? manager = null) { return (manager ?? DefaultMonoDetourManager.Instance).Hook(Target(), (Delegate)hook, config, applyByDefault); } public static MonoDetourHook ILHook(Manipulator manipulator, MonoDetourConfig? config = null, bool applyByDefault = true, MonoDetourManager? manager = null) { return (manager ?? DefaultMonoDetourManager.Instance).ILHook(Target(), manipulator, config, applyByDefault); } public static MethodBase Target() { Type typeFromHandle = typeof(PickupDropletController); MethodInfo method = typeFromHandle.GetMethod("CreatePickupDroplet", (BindingFlags)(-1), null, new Type[3] { typeof(CreatePickupInfo), typeof(Vector3), typeof(Vector3) }, null); if ((object)method == null) { throw new MissingMethodException("RoR2.PickupDropletController", "CreatePickupDroplet"); } return method; } } internal static class Init { public delegate void PrefixSignature(); public delegate ReturnFlow ControlFlowPrefixSignature(); public delegate void PostfixSignature(); public static MonoDetourHook Prefix(PrefixSignature hook, MonoDetourConfig? config = null, bool applyByDefault = true, MonoDetourManager? manager = null) { return (manager ?? DefaultMonoDetourManager.Instance).Hook(Target(), (Delegate)hook, config, applyByDefault); } public static MonoDetourHook ControlFlowPrefix(ControlFlowPrefixSignature hook, MonoDetourConfig? config = null, bool applyByDefault = true, MonoDetourManager? manager = null) { return (manager ?? DefaultMonoDetourManager.Instance).Hook(Target(), (Delegate)hook, config, applyByDefault); } public static MonoDetourHook Postfix(PostfixSignature hook, MonoDetourConfig? config = null, bool applyByDefault = true, MonoDetourManager? manager = null) { return (manager ?? DefaultMonoDetourManager.Instance).Hook(Target(), (Delegate)hook, config, applyByDefault); } public static MonoDetourHook ILHook(Manipulator manipulator, MonoDetourConfig? config = null, bool applyByDefault = true, MonoDetourManager? manager = null) { return (manager ?? DefaultMonoDetourManager.Instance).ILHook(Target(), manipulator, config, applyByDefault); } public static MethodBase Target() { Type typeFromHandle = typeof(PickupDropletController); MethodInfo method = typeFromHandle.GetMethod("Init", (BindingFlags)(-1), null, Array.Empty(), null); if ((object)method == null) { throw new MissingMethodException("RoR2.PickupDropletController", "Init"); } return method; } } } 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 BepInEx { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] [Embedded] internal sealed class BepInAutoPluginAttribute : Attribute { public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace BepInEx.Preloader.Core.Patching { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] [Embedded] internal sealed class PatcherAutoPluginAttribute : Attribute { public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace Microsoft.CodeAnalysis { [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace NoHiddenRealmItemFarming { public static class ConfigOptions { public enum ItemPreventionType { NoDropping, MakeTemporary } private const string _sectionName = "config options are here"; internal static ConfigEntry ShowDebugLogging; public static ConfigEntry ItemPreventionMode; public static ConfigEntry ItemTiersWhitelisted; internal static string[] ItemTiersWhitelistedList; public static ConfigEntry StagesBlacklisted; internal static string[] StagesBlacklistedList; private static void ItemTiersWhitelisted_SettingChanged(object sender, EventArgs e) { ItemTiersWhitelistedList = ItemTiersWhitelisted.Value.Split(','); } private static void StagesBlacklisted_SettingChanged(object sender, EventArgs e) { StagesBlacklistedList = StagesBlacklisted.Value.Split(','); } internal static void BindConfigOptions(ConfigFile config) { ShowDebugLogging = Extensions.BindOption(config, "config options are here", "Show debug logging", "does what it says", false, (ConfigFlags)0); ItemPreventionMode = Extensions.BindOption(config, "config options are here", "How to prevent item drops", "Choose the way item drops in hidden realms should be prevented/nerfed. MakeTemporary requires the Alloyed Collective DLC.", ItemPreventionType.NoDropping, (ConfigFlags)0); StagesBlacklisted = Extensions.BindOption(config, "config options are here", "Blacklisted stage names", "Use this to prevent item drops in certain stages/hidden realms. Uses the internal name of the stages (use DebugTooalkit's next_stage command to find those out), separate each with a comma.", "goldshores,arena", (ConfigFlags)0); StagesBlacklistedList = StagesBlacklisted.Value.Split(','); StagesBlacklisted.SettingChanged += StagesBlacklisted_SettingChanged; ItemTiersWhitelisted = Extensions.BindOption(config, "config options are here", "Whitelisted item tier indices", "Use this to allow certain item tiers to always drop in blacklisted hidden realms. Uses the indices/numbers of item tiers (use DebugToolkit's list_itemtier command to find those out), separate each with a comma.\n\nThe default number 4 is for boss items and 1002 is for Starstorm 2s sibylline item tier. I'm not sure if modded item tiers can change when more are added so double check if the sibylline item tier number is correct in your modpack.", "4,1002", (ConfigFlags)0); ItemTiersWhitelistedList = ItemTiersWhitelisted.Value.Split(','); ItemTiersWhitelisted.SettingChanged += ItemTiersWhitelisted_SettingChanged; } } internal static class Log { private static ManualLogSource _logSource; internal static void Init(ManualLogSource logSource) { _logSource = logSource; } internal static void Debug(object data) { if (ConfigOptions.ShowDebugLogging.Value) { _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); } } [MonoDetourTargets(typeof(PickupDropletController), GenerateControlFlowVariants = true)] internal static class Main { private static readonly AssetReferenceT _alloyedCollectiveReference = new AssetReferenceT(RoR2_DLC3.DLC3_asset); private static ExpansionDef _alloyedCollective; [MonoDetourHookInitialize] private static void Setup() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) CreatePickupDroplet_RoR2_GenericPickupController_CreatePickupInfo_UnityEngine_Vector3_UnityEngine_Vector3.ControlFlowPrefix(GoAwayHiddenRealmFarming); AsyncOperationHandle val = AssetAsyncReferenceManager.LoadAsset(_alloyedCollectiveReference, (AsyncReferenceHandleUnloadType)2); val.Completed += delegate(AsyncOperationHandle handle) { _alloyedCollective = handle.Result; }; } private static ReturnFlow GoAwayHiddenRealmFarming(ref CreatePickupInfo pickupInfo, ref Vector3 position, ref Vector3 velocity) { //IL_001e: 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_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected I4, but got Unknown //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) if (ConfigOptions.StagesBlacklistedList.Contains(Stage.instance.sceneDef.cachedName)) { _ = ((CreatePickupInfo)(ref pickupInfo)).pickup; UniquePickup pickup = ((CreatePickupInfo)(ref pickupInfo)).pickup; if (!((UniquePickup)(ref pickup)).isTempItem && !((Object)(object)PatchedPickupInfoInterop.GetPickupDropSource(ref pickupInfo) != (Object)null) && !ConfigOptions.ItemTiersWhitelistedList.Contains(((int)PickupCatalog.GetPickupDef(((CreatePickupInfo)(ref pickupInfo)).pickup.pickupIndex).itemTier).ToString())) { Log.Debug("preventing/nerfing non chest item drop in a hidden realm!"); if (ConfigOptions.ItemPreventionMode.Value != ConfigOptions.ItemPreventionType.NoDropping && Run.instance.IsExpansionEnabled(_alloyedCollective)) { UniquePickup pickup2 = ((CreatePickupInfo)(ref pickupInfo)).pickup; pickup2.decayValue = 1f; ((CreatePickupInfo)(ref pickupInfo)).pickup = pickup2; return (ReturnFlow)0; } return (ReturnFlow)1; } return (ReturnFlow)0; } return (ReturnFlow)0; } } [BepInPlugin("LordVGames.NoHiddenRealmItemFarming", "NoHiddenRealmItemFarming", "1.0.0")] public class Plugin : BaseUnityPlugin { public const string Id = "LordVGames.NoHiddenRealmItemFarming"; public static string Name => "NoHiddenRealmItemFarming"; public static string Version => "1.0.0"; public void Awake() { ConfigOptions.BindConfigOptions(((BaseUnityPlugin)this).Config); Log.Init(((BaseUnityPlugin)this).Logger); MonoDetourManager.InvokeHookInitializers(typeof(Plugin).Assembly); } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }