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 ItemDeclutter v0.4.4
ItemDeclutter.dll
Decompiled 2 years agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; 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 GameNetcodeStuff; using HarmonyLib; using LethalNetworkAPI; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using Steamworks.Data; using Unity.Netcode; 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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("ItemDeclutter")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("Declutter your ship")] [assembly: AssemblyFileVersion("0.0.1.0")] [assembly: AssemblyInformationalVersion("0.0.1+7b05afce5e7f48f3c102e1f73b596cd56557d40f")] [assembly: AssemblyProduct("ItemDeclutter")] [assembly: AssemblyTitle("ItemDeclutter")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.1.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 ItemDeclutter { public class ConfigManager { public static ConfigManager Instance { get; private set; } public static ConfigEntry<bool> DivideCheapExpensive { get; private set; } public static ConfigEntry<int> ExpensiveValue { get; private set; } public static ConfigEntry<bool> DivideOneTwoHanded { get; private set; } public static ConfigEntry<bool> ShouldItemsAssumeZones { get; private set; } public static void Init(ConfigFile config) { Instance = new ConfigManager(config); } private ConfigManager(ConfigFile config) { DivideCheapExpensive = config.Bind<bool>("Item Zones", "DivideCheapExpensive", true, "Divide cheap and expensive items into different zones."); ExpensiveValue = config.Bind<int>("Item Zones", "ExpensiveValue", 65, "At what point value is considered expensive?"); DivideOneTwoHanded = config.Bind<bool>("Item Zones", "DivideOneTwoHanded", true, "Divide normal and two handed items into different zones."); ShouldItemsAssumeZones = config.Bind<bool>("Item Zones", "ShouldItemsAssumeZones", true, "Should items assume zones if they are not defined in the config?"); } } public class ZoneManagerConfig { public static ConfigEntry<bool> LogCreatedZones { get; private set; } public static ConfigEntry<float> ZoningStartX { get; private set; } public static ConfigEntry<float> ZoningStartY { get; private set; } public static ConfigEntry<float> ZoningStartZ { get; private set; } public static ConfigEntry<float> ZoneDistanceX { get; private set; } public static ConfigEntry<float> ZoneDistanceY { get; private set; } public static ConfigEntry<float> ZoneDistanceZ { get; private set; } public static ConfigEntry<int> HowManyZonesX { get; private set; } public static ConfigEntry<int> HowManyZonesY { get; private set; } public static ConfigEntry<int> HowManyZonesZ { get; private set; } public static ZoneManagerConfig Instance { get; private set; } public static ConfigEntry<bool> Debug { get; private set; } public static void Init(ConfigFile config) { Instance = new ZoneManagerConfig(config); } private ZoneManagerConfig(ConfigFile config) { LogCreatedZones = config.Bind<bool>("Log created zones", "Log", true, "Log created zones to console."); ZoningStartX = config.Bind<float>("Start Position", "ZoningStartX", -6f, "Start position on X axis (entrance -> console)"); ZoningStartY = config.Bind<float>("Start Position", "ZoningStartY", 0.25f, "Start position on Y axis (floor -> ceiling)"); ZoningStartZ = config.Bind<float>("Start Position", "ZoningStartZ", -5f, "Start position on Z axis (left -> right)"); ZoneDistanceX = config.Bind<float>("Distance between zones", "ZoneDistanceX", 0.65f, "Distance between zones on X axis (entrance -> console)"); ZoneDistanceY = config.Bind<float>("Distance between zones", "ZoneDistanceY", 1.25f, "Distance between zones on Y axis (floor -> ceiling)"); ZoneDistanceZ = config.Bind<float>("Distance between zones", "ZoneDistanceZ", 1f, "Distance between zones on Z axis (left -> right)"); HowManyZonesX = config.Bind<int>("How many zones to create", "HowManyZonesX", 20, "How many zones on X axis (entrance -> console)"); HowManyZonesY = config.Bind<int>("How many zones to create", "HowManyZonesY", 5, "How many zones on Y axis (floor -> ceiling)"); HowManyZonesZ = config.Bind<int>("How many zones to create", "HowManyZonesZ", 4, "How many zones on Z axis (left -> right)"); } } [JsonObject(/*Could not decode attribute arguments.*/)] public class PositionData { [JsonProperty] public string ItemName { get; set; } [JsonProperty] public Vector3 Position { get; set; } } internal class ConfigSync { public static LethalServerMessage<string> sendItemConfig = new LethalServerMessage<string>("configData", (Action<string, ulong>)null); public static LethalClientMessage<string> receiveItemConfig = new LethalClientMessage<string>("configData", (Action<string>)null, (Action<string, ulong>)null); public static LethalServerMessage<string> sendItemPosition = new LethalServerMessage<string>("itemPositionData", (Action<string, ulong>)null); public static LethalClientMessage<string> receiveItemPosition = new LethalClientMessage<string>("itemPositionData", (Action<string>)null, (Action<string, ulong>)null); public static LethalServerEvent sendItemPositionEvent = new LethalServerEvent("itemPositionEvent", (Action<ulong>)null); public static LethalClientEvent receiveItemPositionEvent = new LethalClientEvent("itemPositionEvent", (Action)null, (Action<ulong>)null); public static LethalNetworkVariable<string> synchronizedConfig = new LethalNetworkVariable<string>("synchronizedConfig"); public static void Start() { sendItemPositionEvent.OnReceived += ItemPositionRequest; synchronizedConfig.OnValueChanged += MessageReceivedFromServer; receiveItemPosition.OnReceived += ItemPositionReceived; } private static void MessageReceivedFromServer(string message) { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) if (((NetworkBehaviour)StartOfRound.Instance).IsHost) { return; } Plugin.logger.LogInfo((object)("Config received from server: " + message)); List<PositionData> list = JsonConvert.DeserializeObject<List<PositionData>>(message); foreach (PositionData item in list) { Plugin.logger.LogInfo((object)$"Deserialized: {item.ItemName} - {item.Position}"); Positions.PositionsDictionary[item.ItemName] = item.Position; } } private static void ItemPositionReceived(string message) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) if (!((NetworkBehaviour)StartOfRound.Instance).IsHost) { Plugin.logger.LogInfo((object)("Item settings received from server: " + message)); PositionData positionData = JsonConvert.DeserializeObject<PositionData>(message); Positions.PositionsDictionary[positionData.ItemName] = positionData.Position; } } private static void ItemPositionRequest(ulong clientId) { Plugin.logger.LogInfo((object)"ItemPositionRequest called"); if (((NetworkBehaviour)StartOfRound.Instance).IsHost) { SendItemsPositionData(clientId); } } public static void SendItemsPositionData(ulong clientId) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown List<PositionData> itemsPositionData = GetItemsPositionData(); sendItemConfig.SendClient(JsonConvert.SerializeObject((object)itemsPositionData, (Formatting)0, new JsonSerializerSettings { ReferenceLoopHandling = (ReferenceLoopHandling)1 }), clientId); Plugin.logger.LogInfo((object)$"Sending data: {itemsPositionData}"); } public static void SetNetworkedConfig() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) List<PositionData> itemsPositionData = GetItemsPositionData(); synchronizedConfig.Value = JsonConvert.SerializeObject((object)itemsPositionData, (Formatting)0, new JsonSerializerSettings { ReferenceLoopHandling = (ReferenceLoopHandling)1 }); Plugin.logger.LogInfo((object)$"Setting networked config: {itemsPositionData}"); Lobby? currentLobby = GameNetworkManager.Instance.currentLobby; if (currentLobby.HasValue) { Lobby valueOrDefault = currentLobby.GetValueOrDefault(); ((Lobby)(ref valueOrDefault)).SetData("ItemDeclutterConfig", synchronizedConfig.Value); } } public static List<PositionData> GetItemsPositionData() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) List<PositionData> list = new List<PositionData>(); foreach (string key in Positions.PositionsDictionary.Keys) { Vector3 val = Positions.PositionsDictionary[key]; if (Positions.DroppedItemsYCoordinateDictionary.ContainsKey(key)) { val.y = Positions.DroppedItemsYCoordinateDictionary[key]; Plugin.logger.LogInfo((object)$"Updating {key} Y coordinate from dictionary: {val.y}"); } PositionData positionData = new PositionData { ItemName = key, Position = val }; Plugin.logger.LogInfo((object)$"Serialized: {positionData.ItemName} - {positionData.Position}"); list.Add(positionData); } return list; } public static void DeserializeConfig(string serialized) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) if (serialized == "" || serialized == null) { return; } List<PositionData> list = JsonConvert.DeserializeObject<List<PositionData>>(serialized); foreach (PositionData item in list) { Plugin.logger.LogInfo((object)$"Deserialized: {item.ItemName} - {item.Position}"); Positions.PositionsDictionary[item.ItemName] = item.Position; } } public static string GetSerializedConfig() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown return JsonConvert.SerializeObject((object)GetItemsPositionData(), (Formatting)0, new JsonSerializerSettings { ReferenceLoopHandling = (ReferenceLoopHandling)1 }); } public static void UpdateItemPositionData(GrabbableObject item) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected O, but got Unknown if (((NetworkBehaviour)StartOfRound.Instance).IsHost) { Plugin.logger.LogInfo((object)"Updating item position data"); PositionData positionData = new PositionData { ItemName = item.itemProperties.itemName, Position = Positions.PositionsDictionary[item.itemProperties.itemName] }; sendItemPosition.SendAllClients(JsonConvert.SerializeObject((object)positionData, (Formatting)0, new JsonSerializerSettings { ReferenceLoopHandling = (ReferenceLoopHandling)1 }), true); Plugin.logger.LogInfo((object)$"Sending {item.itemProperties.itemName} data: {positionData}"); } } } [HarmonyPatch(typeof(GrabbableObject))] internal class FallToGroundPatch { [HarmonyPatch("FallToGround")] [HarmonyPrefix] internal static bool FallToGroundPatchLogic(GrabbableObject __instance, ref bool randomizePosition) { //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) Plugin.logger.LogDebug((object)("FallToGroundPatchLogic called for " + __instance.itemProperties.itemName + ".")); if ((Object)(object)__instance == (Object)null) { return true; } if ((Object)(object)((Component)__instance).transform.parent == (Object)null) { return true; } Plugin.logger.LogDebug((object)("Transform parent name: " + ((Object)((Component)__instance).transform.parent).name)); if (((Object)((Component)__instance).transform.parent).name == "HangarShip") { string name = ItemZone.GetName(__instance); Plugin.logger.LogDebug((object)("Resolved zone for " + __instance.itemProperties.itemName + " to " + name)); if (name == null) { return true; } if (name == true.ToString()) { Plugin.logger.LogDebug((object)(__instance.itemProperties.itemName + " is in the dictionary - zone " + name)); } else { Plugin.logger.LogDebug((object)(__instance.itemProperties.itemName + " is not in the dictionary - checking if " + name + " is a valid zone name.")); if (!Positions.Zones.ContainsKey(name)) { Plugin.logger.LogDebug((object)(name + " is not a valid zone name.")); return true; } Plugin.logger.LogDebug((object)(name + " is a valid zone name - adding " + __instance.itemProperties.itemName + " to the dictionary.")); Positions.PositionsDictionary[__instance.itemProperties.itemName] = Positions.Zones[name]; } if (ZoneManagerConfig.ZoningStartY.Value != ((Component)__instance).transform.localPosition.y) { Plugin.logger.LogDebug((object)(__instance.itemProperties.itemName + "'s position is not on the floor.")); __instance.targetFloorPosition = Positions.PositionsDictionary[__instance.itemProperties.itemName]; return false; } return true; } Plugin.logger.LogMessage((object)(__instance.itemProperties.itemName + " is not on the ship. - calling original method.")); return true; } } public static class ItemZone { public static string GetName(GrabbableObject droppedObject) { if (Positions.PositionsDictionary.ContainsKey(droppedObject.itemProperties.itemName)) { return true.ToString(); } bool isScrap = droppedObject.itemProperties.isScrap; bool twoHanded = droppedObject.itemProperties.twoHanded; int scrapValue = droppedObject.scrapValue; return null; } public static Vector3 GetCoordinates(GrabbableObject droppedObject) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_003e: 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_0078: Unknown result type (might be due to invalid IL or missing references) //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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) string name = GetName(droppedObject); if (name == null) { return Vector3.zero; } if (name == true.ToString()) { return Positions.PositionsDictionary[droppedObject.itemProperties.itemName]; } if (Positions.Zones.ContainsKey(name)) { return Positions.Zones[name]; } return Positions.Zones["Default"]; } } internal class ItemStackTooltip { public static string UpdateAllTooltips(string itemName) { GameObject val = GameObject.Find("/Environment/HangarShip"); List<GrabbableObject> ItemsOnShip = (from obj in val.GetComponentsInChildren<GrabbableObject>() where obj.itemProperties.itemName == itemName select obj).ToList(); List<GrabbableObject> list = ItemsOnShip.ToList(); if (list.Count() == 0) { return null; } if (!Positions.PositionsDictionary.ContainsKey(itemName)) { return null; } CollectionExtensions.Do<GrabbableObject>((IEnumerable<GrabbableObject>)list, (Action<GrabbableObject>)delegate(GrabbableObject item) { if ((Object)(object)item.playerHeldBy != (Object)null) { Plugin.logger.LogDebug((object)("Found a player holding " + item.itemProperties.itemName)); ItemsOnShip.Remove(item); } }); int num = ItemsOnShip.Count(); Plugin.logger.LogInfo((object)$"Found {num} {itemName} on ship"); string text = $"{itemName} (x{num}) \n Grab : [E]"; foreach (GrabbableObject item in ItemsOnShip) { item.customGrabTooltip = text; } return text; } } [HarmonyPatch(typeof(StartOfRound))] internal class JoinServerPatch { internal static Dictionary<string, LethalNetworkVariable<Vector3>> ItemZoneSynchronizedConfig = new Dictionary<string, LethalNetworkVariable<Vector3>>(); [HarmonyPatch("Start")] [HarmonyPostfix] internal static void PatchLogic() { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) bool isHost = ((NetworkBehaviour)StartOfRound.Instance).IsHost; Plugin.logger.LogInfo((object)$"JoinServerPatch called - isHost: {isHost}"); if (isHost) { return; } Plugin.logger.LogInfo((object)"creating weird shit on client"); Positions.PositionsDictionary.Clear(); if (!GameNetworkManager.Instance.disableSteam && GameNetworkManager.Instance.currentLobby.HasValue) { Lobby? currentLobby = GameNetworkManager.Instance.currentLobby; object obj; if (!currentLobby.HasValue) { obj = null; } else { Lobby valueOrDefault = currentLobby.GetValueOrDefault(); obj = ((Lobby)(ref valueOrDefault)).GetData("ItemDeclutterConfig"); } string serialized = (string)obj; ConfigSync.DeserializeConfig(serialized); } ConfigSync.receiveItemPositionEvent.InvokeServer(); } } [HarmonyPatch(typeof(StartOfRound))] internal class LoadIntoShipPatch { internal static Dictionary<string, ConfigEntry<string>> ItemZoneConfig = new Dictionary<string, ConfigEntry<string>>(); [HarmonyPatch("LoadShipGrabbableItems")] [HarmonyPrefix] internal static void PatchLogic() { Positions.PositionsDictionary.Clear(); Positions.ZoneAllocated.Clear(); Positions.Zones.Clear(); CreateZones(); PopulateItemScrapConfig(); TranslateDictionaries(); ConfigSync.SetNetworkedConfig(); } internal static void PopulateItemScrapConfig() { List<Item> itemsList = StartOfRound.Instance.allItemsList.itemsList; foreach (Item item in itemsList) { if (!item.isScrap) { string text = ""; if (Positions.DefaultZones.ContainsKey(item.itemName)) { Plugin.logger.LogMessage((object)(item.itemName + " has a default zone : " + Positions.DefaultZones[item.itemName])); text = Positions.DefaultZones[item.itemName]; } ItemZoneConfig[item.itemName] = Plugin.ItemZoneConfig.Bind<string>(item.itemName, item.itemName, text, "Set zone for " + item.itemName + "."); Plugin.logger.LogMessage((object)("Added config entry for " + item.itemName + ".")); Plugin.logger.LogMessage((object)("ItemZoneConfig[item.itemName]: " + ItemZoneConfig[item.itemName].Value)); } } foreach (Item item2 in itemsList) { if (item2.isScrap) { string text2 = ""; if (Positions.DefaultZones.ContainsKey(item2.itemName)) { Plugin.logger.LogMessage((object)(item2.itemName + " has a default zone : " + Positions.DefaultZones[item2.itemName])); text2 = Positions.DefaultZones[item2.itemName]; } ItemZoneConfig[item2.itemName] = Plugin.ScrapZoneConfig.Bind<string>(item2.itemName, item2.itemName, text2, "Set zone for " + item2.itemName + "."); Plugin.logger.LogMessage((object)("Added config entry for " + item2.itemName + ".")); Plugin.logger.LogMessage((object)("ItemZoneConfig[item.itemName]: " + ItemZoneConfig[item2.itemName].Value)); } } } internal static void CreateZones() { //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) Vector3 val = default(Vector3); for (int i = 0; i < ZoneManagerConfig.HowManyZonesY.Value; i++) { for (int j = 0; j < ZoneManagerConfig.HowManyZonesX.Value; j++) { for (int k = 0; k < ZoneManagerConfig.HowManyZonesZ.Value; k++) { string text = ZoneNames.zoneYNames[i] + k.ToString("0") + j.ToString("00"); ((Vector3)(ref val))..ctor(ZoneManagerConfig.ZoningStartX.Value + ZoneManagerConfig.ZoneDistanceX.Value * (float)j, ZoneManagerConfig.ZoningStartY.Value + ZoneManagerConfig.ZoneDistanceY.Value * (float)i, ZoneManagerConfig.ZoningStartZ.Value + ZoneManagerConfig.ZoneDistanceZ.Value * (float)k * -1f); if (ZoneManagerConfig.LogCreatedZones.Value) { Plugin.logger.LogInfo((object)$"Created zone {text} at {val.x}, {val.y}, {val.z}"); } Positions.Zones.Add(text, val); } } } } internal static void TranslateDictionaries() { //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) foreach (KeyValuePair<string, ConfigEntry<string>> item in ItemZoneConfig) { string value = item.Value.Value; if (value == null || value == "") { continue; } if (!Positions.Zones.ContainsKey(value)) { Plugin.logger.LogMessage((object)("Zone " + value + " does not exist - skipping.")); continue; } if (Positions.PositionsDictionary.ContainsKey(item.Key)) { Plugin.logger.LogMessage((object)(item.Key + " is already in the dictionary - changing default position to configured.")); Positions.PositionsDictionary.Remove(item.Key); Positions.ZoneAllocated.Remove(value); } Vector3 val = Positions.Zones[value]; Plugin.logger.LogMessage((object)$"itemZone: {value}, itemPosition: {val}"); Positions.PositionsDictionary.Add(item.Key, val); Positions.ZoneAllocated.Add(value, value: true); Plugin.logger.LogMessage((object)$"Added {item.Key} to PositionsDictionary with position {val.x}, {val.y}, {val.z}."); } } internal static void AssumeZones() { List<Item> itemsList = StartOfRound.Instance.allItemsList.itemsList; foreach (Item item in itemsList) { if (!item.isScrap) { if (Positions.PositionsDictionary.ContainsKey(item.itemName)) { Plugin.logger.LogMessage((object)(item.itemName + " is already in the dictionary - skipping.")); continue; } Plugin.logger.LogMessage((object)(item.itemName + " is not in the dictionary - finding a free zone.")); FindFurthestFreeZone(item); } } } internal static void FindFurthestFreeZone(Item item) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) int num = ZoneManagerConfig.HowManyZonesX.Value - 1; int num2 = ZoneManagerConfig.HowManyZonesZ.Value - 1; for (int num3 = num; num3 >= 0; num3--) { for (int num4 = num2; num4 >= 0; num4--) { string text = "A" + num4.ToString("0") + num3.ToString("00"); Vector3 value = Positions.Zones[text]; if (!Positions.ZoneAllocated.ContainsKey(text)) { Positions.PositionsDictionary.Add(item.itemName, value); Positions.ZoneAllocated.Add(text, value: true); Plugin.logger.LogMessage((object)("Auto-allocated " + item.itemName + " into zone " + text + ".")); return; } } } } } [HarmonyPatch(typeof(PlayerControllerB))] internal class PlayerDropItemPatch { [HarmonyPatch("SetObjectAsNoLongerHeld")] [HarmonyPrefix] internal static void ItemDroppedOnShipPatch(bool droppedInElevator, bool droppedInShipRoom, ref Vector3 targetFloorPosition, ref GrabbableObject dropObject, ref int floorYRot) { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) if (!droppedInShipRoom) { return; } string itemName = dropObject.itemProperties.itemName; Plugin.logger.LogInfo((object)$"Dropped {itemName} in ship room at {targetFloorPosition.x}, {targetFloorPosition.y}, {targetFloorPosition.z}"); if (!Positions.PositionsDictionary.ContainsKey(itemName)) { return; } Vector3 coordinates = ItemZone.GetCoordinates(dropObject); Vector3 val = targetFloorPosition; bool flag = false; Vector3 val2 = coordinates; Plugin.logger.LogInfo((object)$"Dropped {itemName} in ship room at {targetFloorPosition.x}, {targetFloorPosition.y}, {targetFloorPosition.z} - updating drop position to {val2.x}, {val2.y}, {val2.z}"); targetFloorPosition = val2; if (ZoneManagerConfig.ZoningStartY.Value == targetFloorPosition.y) { Plugin.logger.LogDebug((object)(dropObject.itemProperties.itemName + "'s position is in the lowest zone - resolving Y coordinate")); if (Positions.DroppedItemsYCoordinateDictionary.ContainsKey(itemName)) { Plugin.logger.LogDebug((object)$"{dropObject.itemProperties.itemName} is in the Y coordinate dictionary - updating Y coordinate to {Positions.DroppedItemsYCoordinateDictionary[itemName]}"); targetFloorPosition.y = Positions.DroppedItemsYCoordinateDictionary[itemName]; } else { targetFloorPosition.y = val.y; dropObject.FallToGround(false); Positions.DroppedItemsYCoordinateDictionary[itemName] = val.y; Plugin.logger.LogDebug((object)$"{dropObject.itemProperties.itemName} is not in the Y coordinate dictionary - updating Y coordinate to {val.y} and adding to dictionary"); ConfigSync.UpdateItemPositionData(dropObject); } } floorYRot = 0; } [HarmonyPatch(typeof(GrabbableObject))] [HarmonyPatch("DiscardItemClientRpc")] [HarmonyPostfix] internal static void ItemDroppedOnShipPatchPostfix(GrabbableObject __instance) { if (__instance.isInShipRoom) { string itemName = __instance.itemProperties.itemName; __instance.customGrabTooltip = ItemStackTooltip.UpdateAllTooltips(itemName); } else { __instance.customGrabTooltip = null; } } } [HarmonyPatch(typeof(PlayerControllerB))] internal class PlayerPickupItem { [HarmonyPatch("GrabObjectClientRpc")] [HarmonyPostfix] internal static void GrabObjectPatch(bool grabValidated, ref NetworkObjectReference grabbedObject) { NetworkObject val = default(NetworkObject); ((NetworkObjectReference)(ref grabbedObject)).TryGet(ref val, (NetworkManager)null); if (!((Object)(object)val == (Object)null)) { GrabbableObject component = ((Component)val).GetComponent<GrabbableObject>(); if (!((Object)(object)component == (Object)null)) { string itemName = component.itemProperties.itemName; component.customGrabTooltip = ItemStackTooltip.UpdateAllTooltips(itemName); } } } } [HarmonyPatch(typeof(StartOfRound))] internal class SetShipReadyToLand { [HarmonyPatch("SetShipReadyToLand")] [HarmonyPrefix] internal static void PatchLogic() { Plugin.logger.LogInfo((object)"SetShipReadyToLand called"); GameObject val = GameObject.Find("/Environment/HangarShip"); GrabbableObject[] componentsInChildren = val.GetComponentsInChildren<GrabbableObject>(); foreach (KeyValuePair<string, Vector3> item in Positions.PositionsDictionary) { IEnumerable<GrabbableObject> source = componentsInChildren.Where((GrabbableObject obj) => obj.itemProperties.itemName == item.Key); Plugin.logger.LogDebug((object)$"Found {source.Count()} items of type {item.Key}"); if (source.Count() != 0) { ItemStackTooltip.UpdateAllTooltips(item.Key); } } } } [HarmonyPatch(typeof(StartOfRound))] internal class ShipLoadItems { [HarmonyPatch("LoadShipGrabbableItems")] [HarmonyPostfix] internal static void LoadShipItemsPatch() { //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.Find("/Environment/HangarShip"); GrabbableObject[] componentsInChildren = val.GetComponentsInChildren<GrabbableObject>(); foreach (KeyValuePair<string, Vector3> item in Positions.PositionsDictionary) { IEnumerable<GrabbableObject> enumerable = componentsInChildren.Where((GrabbableObject obj) => obj.itemProperties.itemName == item.Key); Plugin.logger.LogDebug((object)$"Found {enumerable.Count()} items of type {item.Key}"); if (enumerable.Count() == 0) { continue; } foreach (GrabbableObject item2 in enumerable) { Vector3 value = item.Value; ((Component)item2).transform.localPosition = value; item2.isInShipRoom = true; if (ZoneManagerConfig.ZoningStartY.Value == value.y) { item2.FallToGround(false); Positions.DroppedItemsYCoordinateDictionary[item.Key] = item2.targetFloorPosition.y; Plugin.logger.LogDebug((object)$"{item.Key}'s position is in the lowest zone (on the floor) - updating Y coordinate dictionary to {item2.targetFloorPosition.y}"); } } ItemStackTooltip.UpdateAllTooltips(item.Key); } } } [BepInPlugin("ItemDeclutter", "ItemDeclutter", "0.0.1")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource logger; private readonly Harmony harmony = new Harmony("ItemDeclutter"); public static ConfigFile ItemZoneConfig = new ConfigFile(Path.Combine(Paths.ConfigPath, "Declutter/Items.cfg"), true); public static ConfigFile ScrapZoneConfig = new ConfigFile(Path.Combine(Paths.ConfigPath, "Declutter/Scrap.cfg"), true); private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown ConfigManager.Init(new ConfigFile(Path.Combine(Paths.ConfigPath, "Declutter/BaseConfig.cfg"), true)); ZoneManagerConfig.Init(new ConfigFile(Path.Combine(Paths.ConfigPath, "Declutter/DefineZones.cfg"), true)); logger = ((BaseUnityPlugin)this).Logger; harmony.PatchAll(); ConfigSync.Start(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ItemDeclutter is loaded!"); } } public class Positions { public static Dictionary<string, Vector3> Zones = new Dictionary<string, Vector3>(); public static Dictionary<string, bool> ZoneAllocated = new Dictionary<string, bool>(); public static Dictionary<string, float> DroppedItemsYCoordinateDictionary = new Dictionary<string, float>(); public static Dictionary<string, Vector3> PositionsDictionary = new Dictionary<string, Vector3>(); public static Dictionary<string, string> DefaultZones = new Dictionary<string, string> { { "Default", "A000" }, { "Shovel", "A000" }, { "Stun grenade", "A002" }, { "Pro-flashlight", "A003" }, { "Flashlight", "A103" }, { "Walkie-talkie", "A004" }, { "Lockpicker", "A005" }, { "Key", "A105" }, { "Shotgun", "A006" }, { "Ammo", "A007" }, { "Spray paint", "A008" }, { "Zap gun", "A009" }, { "Jetpack", "D301" }, { "Extension ladder", "D001" } }; public static Vector3 vectorConstrctor(double x, double y, double z) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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) return new Vector3((float)x, (float)y, (float)z); } } public class ZoneNames { public static string[] zoneYNames = new string[6] { "A", "B", "C", "D", "E", "F" }; } public static class PluginInfo { public const string PLUGIN_GUID = "ItemDeclutter"; public const string PLUGIN_NAME = "ItemDeclutter"; public const string PLUGIN_VERSION = "0.0.1"; } }