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.Bootstrap; using BepInEx.Configuration; using IL.RoR2; using Mono.Cecil.Cil; using MonoMod.Cil; using On.RoR2.UI; using PartialInventorySort.Modules; using R2API.Utils; using RoR2; using RoR2.UI; using UnityEngine; [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 = "")] [assembly: AssemblyCompany("PartialInventorySort")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("PartialInventorySort")] [assembly: AssemblyTitle("PartialInventorySort")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: UnverifiableCode] namespace PartialInventorySort { [NetworkCompatibility(/*Could not decode attribute arguments.*/)] [BepInPlugin("com.RiskOfBrainrot.PartialInventorySortSystem", "PartialInventorySortSystem", "1.0.1")] public class PartialInventorySortPlugin : BaseUnityPlugin { public static PluginInfo PInfo; public const string guid = "com.RiskOfBrainrot.PartialInventorySortSystem"; public const string teamName = "RiskOfBrainrot"; public const string modName = "PartialInventorySortSystem"; public const string version = "1.0.1"; public static SortMode questItemSortMode => Bindings.questSortMode.Value; public static SortMode scrapItemSortMode => Bindings.scrapSortMode.Value; public static SortMode lunarItemSortMode => Bindings.lunarSortMode.Value; public static void AddHooks() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown Inventory.SetItemAcquiredServer += new Manipulator(ChangeItemAcquisitionOrder); } public static void ChangeItemAcquisitionOrder(ILContext il) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0079: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); if (!val.TryGotoNext((MoveType)2, new Func[2] { (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, "itemAcquisitionOrder"), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 1) })) { DebugBreakpoint("ChangeItemAcquisitionOrder"); return; } val.Remove(); val.Emit(OpCodes.Ldarg_0); val.EmitDelegate, ItemIndex, Inventory>>((Action, ItemIndex, Inventory>)delegate(List acquisitionOrder, ItemIndex itemIndexToAdd, Inventory inventory) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003c: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) if (lunarItemSortMode == SortMode.Unsorted && questItemSortMode == SortMode.Unsorted && scrapItemSortMode == SortMode.Unsorted) { inventory.itemAcquisitionOrder.Add(itemIndexToAdd); } else { ItemDef itemDef2 = ItemCatalog.GetItemDef(itemIndexToAdd); SortMode sortMode = GetSortMode(itemIndexToAdd); if (sortMode == SortMode.VeryLast) { inventory.itemAcquisitionOrder.Add(itemIndexToAdd); } else { List list = new List(); List list2 = new List(); foreach (ItemIndex item in acquisitionOrder) { SortMode sortMode2 = GetSortMode(item); if (sortMode2 > sortMode) { list2.Add(item); } else { list.Add(item); } } inventory.itemAcquisitionOrder = new List(); inventory.itemAcquisitionOrder.AddRange(list); inventory.itemAcquisitionOrder.Add(itemIndexToAdd); inventory.itemAcquisitionOrder.AddRange(list2); } } }); static SortMode GetSortMode(ItemIndex indexToSort) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Invalid comparison between Unknown and I4 ItemDef itemDef = ItemCatalog.GetItemDef(indexToSort); if (lunarItemSortMode != SortMode.Unsorted && (int)itemDef.deprecatedTier == 3) { return lunarItemSortMode; } if (questItemSortMode != SortMode.Unsorted && itemDef.ContainsTag((ItemTag)33)) { return questItemSortMode; } if (scrapItemSortMode != SortMode.Unsorted && (itemDef.ContainsTag((ItemTag)10) || itemDef.ContainsTag((ItemTag)14))) { return scrapItemSortMode; } return SortMode.Unsorted; } } public static void SortInventoryDisplay(orig_UpdateDisplay orig, ItemInventoryDisplay self) { if ((Object)(object)self == (Object)null || (Object)(object)Run.instance == (Object)null || !Run.instance.isRunning) { orig.Invoke(self); } } private void Awake() { Bindings.Init(); AddHooks(); Bindings.Save(); } public static void DebugBreakpoint(string methodName, int breakpointNumber = -1) { string text = "(PartialInventorySortSystem) " + methodName + " IL hook failed!"; if (breakpointNumber >= 0) { text += $" (breakpoint {breakpointNumber})"; } Debug.LogError((object)text); } } public enum SortMode { VeryFirst, BeforeUnsorted, Unsorted, AfterUnsorted, VeryLast } } namespace PartialInventorySort.Modules { public static class Tools { internal static bool isLoaded(string modguid) { foreach (KeyValuePair pluginInfo in Chainloader.PluginInfos) { string key = pluginInfo.Key; PluginInfo value = pluginInfo.Value; if (key == modguid) { return true; } } return false; } } public static class Assets { internal static Dictionary loadedBundles = new Dictionary(); internal static AssetBundle LoadAssetBundle(string bundleName) { if (loadedBundles.ContainsKey(bundleName)) { return loadedBundles[bundleName]; } AssetBundle val = null; val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(PartialInventorySortPlugin.PInfo.Location), bundleName)); loadedBundles[bundleName] = val; return val; } } public static class Bindings { internal static ConfigEntry lunarSortMode; internal static ConfigEntry questSortMode; internal static ConfigEntry scrapSortMode; internal static ConfigEntry bulkSortMode; internal static ConfigFile CustomConfigFile { get; set; } public static bool BindSection(string sectionName) { return CustomConfigFile.Bind("Bad Item Academy : Full Section Config", sectionName, true, "Vanilla is FALSE. Set to false if you wish to disable changes made to an entire item or group of items.").Value; } public static void Init() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown CustomConfigFile = new ConfigFile(Paths.ConfigPath + "\\PartialInventorySortSystem.cfg", true); CustomConfigFile.SaveOnConfigSet = false; lunarSortMode = CustomConfigFile.Bind("PISS", "Lunar Item Sort Mode", SortMode.Unsorted, (ConfigDescription)null); questSortMode = CustomConfigFile.Bind("PISS", "Quest Item Sort Mode", SortMode.BeforeUnsorted, (ConfigDescription)null); scrapSortMode = CustomConfigFile.Bind("PISS", "Scrap Item Sort Mode", SortMode.VeryFirst, (ConfigDescription)null); } public static void Save() { CustomConfigFile.SaveOnConfigSet = true; CustomConfigFile.Save(); } } }