using 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.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using ItemDeclutter.Definitions;
using ItemDeclutter.Managers;
using ItemDeclutter.Networking;
using Microsoft.CodeAnalysis;
using MrovLib;
using Newtonsoft.Json;
using Unity.Collections;
using Unity.Netcode;
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: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("ItemDeclutter")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Declutter your ship")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-dev.53+802a92249af32c79bae04d308755c8c6af05278c")]
[assembly: AssemblyProduct("ItemDeclutter")]
[assembly: AssemblyTitle("ItemDeclutter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 ItemDeclutter
{
public abstract class ConfigHandler<T, CT> : ConfigHandler<T, CT>
{
public ConfigHandler(CT value)
{
((ConfigHandler<T, CT>)this).DefaultValue = value;
}
}
public class ZoneConfigHandler : ConfigHandler<Vector3, string>
{
public string RawValue => ((ConfigHandler<Vector3, string>)this).ConfigEntry.Value;
public override Vector3 Value => ZoneManager.Zones.GetValueOrDefault(((ConfigHandler<Vector3, string>)this).DefaultValue);
public ZoneConfigHandler(string defaultValue, string itemName)
: base(defaultValue)
{
string text = Regex.Replace(itemName, "[=\\n\\t\\\\\"\\'\\[\\] ]", "_");
((ConfigHandler<Vector3, string>)this).ConfigEntry = ConfigManager.ConfigFile.Bind<string>(text, "Item zone", defaultValue, "Set zone for " + itemName + ".");
}
}
public class ConfigManager
{
public static ConfigManager Instance { get; private set; }
public static ConfigFile ConfigFile { get; private set; }
public static ConfigEntry<bool> LogCreatedZones { 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 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 void Init(ConfigFile config)
{
Instance = new ConfigManager(config);
ConfigFile = config;
}
private ConfigManager(ConfigFile config)
{
DivideCheapExpensive = config.Bind<bool>("|Scrap Properties", "DivideCheapExpensive", true, "Divide cheap and expensive items into different zones.");
ExpensiveValue = config.Bind<int>("|Scrap Properties", "ExpensiveValue", 65, "At what point value is considered expensive?");
DivideOneTwoHanded = config.Bind<bool>("|Scrap Properties", "DivideOneTwoHanded", true, "Divide normal and two handed items into different zones.");
ShouldItemsAssumeZones = config.Bind<bool>("|Zone Allocation", "ShouldItemsAssumeZones", false, "Should items assume zones if they are not defined in the config?");
LogCreatedZones = config.Bind<bool>("|Logging", "Created Zones", true, "Log created zones in console.");
ZoningStartX = config.Bind<float>("|Zone Settings: Start Position", "ZoningStartX", -6f, "Start position on X axis (entrance -> console)");
ZoningStartY = config.Bind<float>("|Zone Settings: Start Position", "ZoningStartY", 0.25f, "Start position on Y axis (floor -> ceiling)");
ZoningStartZ = config.Bind<float>("|Zone Settings: Start Position", "ZoningStartZ", -5f, "Start position on Z axis (left -> right)");
ZoneDistanceX = config.Bind<float>("|Zone Settings: Distance between zones", "ZoneDistanceX", 0.65f, "Distance between zones on X axis (entrance -> console)");
ZoneDistanceY = config.Bind<float>("|Zone Settings: Distance between zones", "ZoneDistanceY", 1.25f, "Distance between zones on Y axis (floor -> ceiling)");
ZoneDistanceZ = config.Bind<float>("|Zone Settings: Distance between zones", "ZoneDistanceZ", 1f, "Distance between zones on Z axis (left -> right)");
HowManyZonesX = config.Bind<int>("|Zone Settings: How many zones to create", "HowManyZonesX", 20, "How many zones on X axis (entrance -> console)");
HowManyZonesY = config.Bind<int>("|Zone Settings: How many zones to create", "HowManyZonesY", 5, "How many zones on Y axis (floor -> ceiling)");
HowManyZonesZ = config.Bind<int>("|Zone Settings: How many zones to create", "HowManyZonesZ", 4, "How many zones on Z axis (left -> right)");
}
}
internal class DeclutterSync : NetworkBehaviour
{
public NetworkVariable<ItemZoneDataWrapper> ItemZones = new NetworkVariable<ItemZoneDataWrapper>(new ItemZoneDataWrapper
{
ItemZonesData = Array.Empty<ItemZoneData>()
}, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);
public static GameObject DeclutterSyncPrefab;
public static NetworkManager networkManager;
public static bool networkHasStarted = false;
internal static DeclutterSync _instance;
private static List<GameObject> queuedNetworkPrefabs = new List<GameObject>();
public ItemZoneData[] ItemZonesData
{
get
{
return ItemZones.Value.ItemZonesData;
}
set
{
ItemZones.Value = new ItemZoneDataWrapper
{
ItemZonesData = value
};
}
}
public static DeclutterSync Instance
{
get
{
if ((Object)(object)_instance == (Object)null)
{
_instance = Object.FindObjectOfType<DeclutterSync>();
if ((Object)(object)_instance == (Object)null)
{
Plugin.logger.LogError((object)"DeclutterSync instance is null");
}
}
return _instance;
}
private set
{
_instance = value;
}
}
public override void OnNetworkSpawn()
{
((NetworkBehaviour)this).OnNetworkSpawn();
InitializeInstance();
NetworkVariable<ItemZoneDataWrapper> itemZones = ItemZones;
itemZones.OnValueChanged = (OnValueChangedDelegate<ItemZoneDataWrapper>)(object)Delegate.Combine((Delegate?)(object)itemZones.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<ItemZoneDataWrapper>(ItemDeclutter.Networking.ItemZones.ItemZonesReceived));
Plugin.logger.LogDebug((object)"DeclutterSync OnNetworkSpawn");
}
public void SetNewOnHost(Dictionary<string, Vector3> ItemLocations)
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Expected O, but got Unknown
Plugin.logger.LogDebug((object)"Setting new item zones on host");
if (!((NetworkBehaviour)StartOfRound.Instance).IsHost)
{
Plugin.logger.LogDebug((object)"Cannot set item zones, not a host!");
return;
}
ItemZoneData[] array = ItemLocations.Select(delegate(KeyValuePair<string, Vector3> x)
{
//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_001f: 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_0045: Unknown result type (might be due to invalid IL or missing references)
ItemZoneData result = default(ItemZoneData);
result.ObjectName = FixedString64Bytes.op_Implicit(x.Key);
result.XCoordinate = x.Value.x;
result.YCoordinate = x.Value.y;
result.ZCoordinate = x.Value.z;
return result;
}).ToArray();
Plugin.logger.LogDebug((object)JsonConvert.SerializeObject((object)array, (Formatting)0, new JsonSerializerSettings
{
ReferenceLoopHandling = (ReferenceLoopHandling)1
}));
ItemZones.Set(new ItemZoneDataWrapper
{
ItemZonesData = array
});
}
public static void RegisterNetworkPrefab(GameObject prefab)
{
if (!networkHasStarted)
{
Plugin.logger.LogDebug((object)("Registering NetworkPrefab: " + (object)prefab));
queuedNetworkPrefabs.Add(prefab);
}
else
{
Plugin.logger.LogWarning((object)("Attempted To Register NetworkPrefab: " + ((object)prefab)?.ToString() + " After GameNetworkManager Has Started!"));
}
}
internal static void RegisterPrefabs(NetworkManager networkManager)
{
Plugin.logger.LogDebug((object)"Registering NetworkPrefabs in NetworkManager");
List<GameObject> existingPrefabs = GetExistingPrefabs(networkManager);
RegisterQueuedPrefabs(networkManager, existingPrefabs);
networkHasStarted = true;
}
private void InitializeInstance()
{
((Object)((Component)this).gameObject).name = "DeclutterSync";
Instance = this;
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
Plugin.logger.LogDebug((object)$"Declutter data: {ItemZones.Value}");
}
private static List<GameObject> GetExistingPrefabs(NetworkManager networkManager)
{
List<GameObject> list = new List<GameObject>();
foreach (NetworkPrefab prefab in networkManager.NetworkConfig.Prefabs.m_Prefabs)
{
list.Add(prefab.Prefab);
}
return list;
}
private static void RegisterQueuedPrefabs(NetworkManager networkManager, List<GameObject> addedNetworkPrefabs)
{
int num = 0;
foreach (GameObject queuedNetworkPrefab in queuedNetworkPrefabs)
{
Plugin.logger.LogDebug((object)("Trying To Register Prefab: " + (object)queuedNetworkPrefab));
if (!addedNetworkPrefabs.Contains(queuedNetworkPrefab))
{
networkManager.AddNetworkPrefab(queuedNetworkPrefab);
addedNetworkPrefabs.Add(queuedNetworkPrefab);
}
else
{
num++;
}
}
Plugin.logger.LogDebug((object)("Skipped Registering " + num + " NetworkObjects As They Were Already Registered."));
}
}
public static class Defaults
{
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 string[] zoneYNames = new string[10] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };
}
[HarmonyPatch(typeof(StartOfRound))]
public static class StartOfRoundDisablePatch
{
[HarmonyPatch("OnDisable")]
[HarmonyPostfix]
public static void PatchLogic()
{
Plugin.logger.LogInfo((object)"StartOfRoundDisablePatch called");
ResetHandler.Reset();
}
}
[BepInPlugin("ItemDeclutter", "ItemDeclutter", "0.2.1")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource logger;
private readonly Harmony harmony = new Harmony("ItemDeclutter");
internal static ManualLogSource debugLogger => logger;
private void Awake()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
ConfigManager.Init(new ConfigFile(Path.Combine(Paths.ConfigPath, "Declutter/BaseConfig.cfg"), true));
logger = ((BaseUnityPlugin)this).Logger;
harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ItemDeclutter is loaded!");
}
}
public static class ResetHandler
{
public static void Reset()
{
DeclutterSync.Instance.SetNewOnHost(new Dictionary<string, Vector3>());
ZoneManager.Reset();
ItemManager.Reset();
PositionManager.Reset();
}
}
internal class TooltipHelper
{
public static string GetTooltip(string itemName)
{
GameObject val = GameObject.Find("/Environment/HangarShip");
List<GrabbableObject> source = (from obj in val.GetComponentsInChildren<GrabbableObject>()
where obj.itemProperties.itemName == itemName
where !obj.heldByPlayerOnServer
select obj).ToList();
List<GrabbableObject> itemsOnShip = source.ToList();
return GetTooltip(itemsOnShip, itemName);
}
public static string GetTooltip(List<GrabbableObject> ItemsOnShip, string itemName)
{
int num = ItemsOnShip.Count();
Plugin.logger.LogInfo((object)$"Found {num} {itemName} on ship");
return $"{itemName} (x{num}) \n Grab : [E]";
}
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
where !obj.heldByPlayerOnServer
select obj).ToList();
List<GrabbableObject> list = ItemsOnShip.ToList();
if (list.Count() == 0)
{
return null;
}
if (!PositionManager.IsItemDefined(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);
}
});
string tooltip = GetTooltip(ItemsOnShip, itemName);
foreach (GrabbableObject item in ItemsOnShip)
{
item.customGrabTooltip = tooltip;
}
return tooltip;
}
public static string UpdateAllTooltips(GrabbableObject grabbable)
{
return UpdateAllTooltips(grabbable.itemProperties.itemName);
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "ItemDeclutter";
public const string PLUGIN_NAME = "ItemDeclutter";
public const string PLUGIN_VERSION = "0.2.1";
}
}
namespace ItemDeclutter.Patches
{
[HarmonyPatch(typeof(GameNetworkManager), "Start")]
internal class GameNetworkManagerStartPatch
{
[HarmonyPrefix]
public static void GameMethodPatch(GameNetworkManager __instance)
{
//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_001e: Expected O, but got Unknown
DeclutterSync.networkManager = ((Component)__instance).GetComponent<NetworkManager>();
GameObject val = new GameObject("DeclutterSyncInnit")
{
hideFlags = (HideFlags)61
};
val.AddComponent<NetworkObject>();
byte[] value = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes("DeclutterSync"));
val.GetComponent<NetworkObject>().GlobalObjectIdHash = BitConverter.ToUInt32(value, 0);
val.AddComponent<DeclutterSync>();
val.GetComponent<NetworkObject>().DontDestroyWithOwner = true;
val.GetComponent<NetworkObject>().SceneMigrationSynchronization = true;
val.GetComponent<NetworkObject>().DestroyWithScene = false;
Object.DontDestroyOnLoad((Object)(object)val);
DeclutterSync.DeclutterSyncPrefab = val;
DeclutterSync.RegisterNetworkPrefab(val);
DeclutterSync.RegisterPrefabs(((Component)__instance).GetComponent<NetworkManager>());
Plugin.logger.LogDebug((object)"DeclutterSync initialized in GameNetworkManager.Start");
}
}
[HarmonyPatch(typeof(GrabbableObject))]
internal class FallToGroundPatch
{
[HarmonyPatch("FallToGround")]
[HarmonyPrefix]
internal static bool FallToGroundPatchLogic(GrabbableObject __instance, ref bool randomizePosition)
{
//IL_0091: 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_0097: 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)
Plugin.debugLogger.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.debugLogger.LogDebug((object)("Transform parent name: " + ((Object)((Component)__instance).transform.parent).name));
if (((Object)((Component)__instance).transform.parent).name == "HangarShip")
{
string itemName = __instance.itemProperties.itemName;
Vector3 itemCoordinates = PositionManager.GetItemCoordinates(itemName);
if (itemCoordinates == new Vector3(0f, 0f, 0f))
{
Plugin.debugLogger.LogDebug((object)("Coordinates for " + itemName + " are null."));
return true;
}
return false;
}
Plugin.debugLogger.LogMessage((object)(__instance.itemProperties.itemName + " is not on the ship. - calling original method."));
return true;
}
}
[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 = TooltipHelper.GetTooltip(itemName);
}
}
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerDropItemPatch
{
[HarmonyPatch("SetObjectAsNoLongerHeld")]
[HarmonyPrefix]
internal static void ItemDroppedOnShipPatch(bool droppedInShipRoom, ref Vector3 targetFloorPosition, ref GrabbableObject dropObject, ref int floorYRot)
{
//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_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: 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_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
if (!droppedInShipRoom)
{
return;
}
GrabbableObject val = dropObject;
string itemName = val.itemProperties.itemName;
Plugin.logger.LogInfo((object)$"Dropped {itemName} in ship room at {targetFloorPosition.x}, {targetFloorPosition.y}, {targetFloorPosition.z}");
Vector3 itemCoordinates = PositionManager.GetItemCoordinates(itemName);
Vector3 val2 = targetFloorPosition;
Vector3 val3 = itemCoordinates;
if (itemCoordinates == new Vector3(0f, 0f, 0f))
{
Plugin.logger.LogInfo((object)("Coordinates for " + itemName + " are null"));
return;
}
if (itemCoordinates.y == ConfigManager.ZoningStartY.Value)
{
Plugin.logger.LogInfo((object)$"{itemName}'s position is in the lowest zone - changing Y coordinate to {val2.y}");
val3.y = val2.y;
}
Plugin.logger.LogInfo((object)$"Dropped {itemName} in ship room at {targetFloorPosition.x}, {targetFloorPosition.y}, {targetFloorPosition.z} - updating drop position to {val3.x}, {val3.y}, {val3.z}");
targetFloorPosition = val3;
floorYRot = 0;
}
[HarmonyPatch(typeof(GrabbableObject))]
[HarmonyPatch("DiscardItemClientRpc")]
[HarmonyPostfix]
internal static void ItemDroppedOnShipPatchPostfix(GrabbableObject __instance)
{
if (__instance.isInShipRoom)
{
string itemName = __instance.itemProperties.itemName;
__instance.customGrabTooltip = TooltipHelper.GetTooltip(itemName);
}
else
{
__instance.customGrabTooltip = null;
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
public class StartOfRoundAwakePatch
{
[HarmonyPatch("Awake")]
[HarmonyPrefix]
[HarmonyPriority(800)]
internal static void StartOfRoundAwakePrefix(RoundManager __instance)
{
Plugin.logger.LogInfo((object)"StartOfRoundAwakePrefix Patch");
Plugin.logger.LogWarning((object)((Component)GameNetworkManager.Instance).GetComponent<NetworkManager>().IsHost);
if (((Component)GameNetworkManager.Instance).GetComponent<NetworkManager>().IsHost)
{
Plugin.logger.LogDebug((object)"Host detected, spawning DeclutterSync");
DeclutterSync component = Object.Instantiate<GameObject>(DeclutterSync.DeclutterSyncPrefab).GetComponent<DeclutterSync>();
((Component)component).GetComponent<NetworkObject>().Spawn(false);
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class LoadIntoShipPatch
{
[HarmonyPatch("LoadShipGrabbableItems")]
[HarmonyPrefix]
internal static void PatchLogic()
{
if (((NetworkBehaviour)StartOfRound.Instance).IsHost)
{
ZoneManager.CreateZones();
ItemManager.PopulateItemScrapConfig();
PositionManager.SetDictionaryOnHost();
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class ShipLoadItems
{
[HarmonyPatch("LoadShipGrabbableItems")]
[HarmonyPostfix]
internal static void LoadShipItemsPatch()
{
//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_00a5: 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 PositionManager.ItemCoordinates)
{
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;
}
TooltipHelper.UpdateAllTooltips(item.Key);
}
}
}
[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 PositionManager.ItemCoordinates)
{
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)
{
TooltipHelper.UpdateAllTooltips(item.Key);
}
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class JoinServerPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
internal static void PatchLogic()
{
bool isHost = ((NetworkBehaviour)StartOfRound.Instance).IsHost;
Plugin.logger.LogInfo((object)$"JoinServerPatch called - isHost: {isHost}");
if (!isHost)
{
Plugin.logger.LogInfo((object)"creating weird shit on client");
PositionManager.ItemCoordinates.Clear();
}
}
}
}
namespace ItemDeclutter.Networking
{
public class ItemZones
{
internal static void ItemZonesReceived(ItemZoneDataWrapper previousValue, ItemZoneDataWrapper newValue)
{
if (!((NetworkBehaviour)StartOfRound.Instance).IsHost)
{
PositionManager.ItemCoordinates.Clear();
PositionManager.SetDictionaryFromSyncedData(newValue.ItemZonesData);
}
}
}
}
namespace ItemDeclutter.Managers
{
public static class ItemManager
{
public static List<ItemConfig> Grabbables = new List<ItemConfig>();
public static List<ItemConfig> Items => Grabbables.FindAll((ItemConfig x) => !x.Item.isScrap);
public static List<ItemConfig> Scraps => Grabbables.FindAll((ItemConfig x) => x.Item.isScrap);
internal static void PopulateItemScrapConfig()
{
List<Item> itemsList = StartOfRound.Instance.allItemsList.itemsList;
foreach (Item item2 in itemsList)
{
string itemName = item2.itemName;
ItemConfig item = new ItemConfig
{
Item = item2,
ZoneConfig = new ZoneConfigHandler(Defaults.DefaultZones.ContainsKey(itemName) ? Defaults.DefaultZones[itemName] : "", itemName)
};
Grabbables.Add(item);
if (Defaults.DefaultZones.ContainsKey(itemName))
{
Plugin.logger.LogMessage((object)(itemName + " has a default zone : " + Defaults.DefaultZones[itemName]));
}
Plugin.logger.LogMessage((object)("Added config entry for " + item2.itemName + "."));
}
}
internal static void Reset()
{
Grabbables.Clear();
}
}
public static class PositionManager
{
public static Dictionary<string, Vector3> ItemCoordinates = new Dictionary<string, Vector3>();
public static void Reset()
{
ItemCoordinates.Clear();
}
public static void AddItem(string itemName, Vector3 coordinates)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
ItemCoordinates.Add(itemName, coordinates);
}
public static void SetDictionaryFromSyncedData(ItemZoneData[] itemZoneData)
{
//IL_0037: 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_004b: Unknown result type (might be due to invalid IL or missing references)
ItemCoordinates.Clear();
Vector3 value = default(Vector3);
for (int i = 0; i < itemZoneData.Length; i++)
{
ItemZoneData itemZoneData2 = itemZoneData[i];
((Vector3)(ref value))..ctor(itemZoneData2.XCoordinate, itemZoneData2.YCoordinate, itemZoneData2.ZCoordinate);
Dictionary<string, Vector3> itemCoordinates = ItemCoordinates;
FixedString64Bytes objectName = itemZoneData2.ObjectName;
itemCoordinates.Add(((object)(FixedString64Bytes)(ref objectName)).ToString(), value);
}
}
public static Vector3 GetItemCoordinates(string itemName)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
return ItemCoordinates.GetValueOrDefault(itemName);
}
public static Vector3 GetItemCoordinates(GrabbableObject item)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
return GetItemCoordinates(item.itemProperties.itemName);
}
public static bool IsItemDefined(string itemName)
{
return ItemCoordinates.ContainsKey(itemName);
}
public static void SetDictionaryOnHost()
{
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
if (!((NetworkBehaviour)StartOfRound.Instance).IsHost)
{
return;
}
foreach (ItemConfig grabbable in ItemManager.Grabbables)
{
string zone = grabbable.Zone;
if (zone != null && !(zone == ""))
{
if (!ZoneManager.Zones.ContainsKey(zone))
{
Plugin.logger.LogMessage((object)("Zone " + zone + " does not exist - skipping."));
continue;
}
Vector3 zoneCoordinates = ZoneManager.GetZoneCoordinates(zone);
Plugin.logger.LogMessage((object)$"itemZone: {zone}, coordinates: {zoneCoordinates}");
AddItem(grabbable.ObjectName, zoneCoordinates);
Plugin.logger.LogMessage((object)$"Added {grabbable.ObjectName} to PositionsDictionary with position {grabbable.XCoordinate}, {grabbable.YCoordinate}, {grabbable.ZCoordinate}.");
}
}
if ((Object)(object)DeclutterSync.Instance == (Object)null)
{
Plugin.logger.LogError((object)"DeclutterSync instance is null");
}
else
{
DeclutterSync.Instance.SetNewOnHost(ItemCoordinates);
}
}
}
public class ZoneManager
{
public static Dictionary<string, Vector3> Zones = new Dictionary<string, Vector3>();
public static Dictionary<string, bool> ZoneAllocated = new Dictionary<string, bool>();
public static void CreateZone(string zoneName, Vector3 coordinates)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
Zones.Add(zoneName, coordinates);
}
public static void RemoveZone(string zoneName)
{
Zones.Remove(zoneName);
}
public static Vector3 GetZoneCoordinates(string zoneName)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
return Zones.GetValueOrDefault(zoneName);
}
public static bool IsZoneAllocated(string zoneName)
{
return ZoneAllocated.GetValueOrDefault(zoneName);
}
public static void SetZoneAllocated(string zoneName, bool isAllocated)
{
ZoneAllocated[zoneName] = isAllocated;
}
public static void SetZoneAllocated(string zoneName)
{
SetZoneAllocated(zoneName, isAllocated: true);
}
public static void Reset()
{
Zones.Clear();
ZoneAllocated.Clear();
}
internal static void CreateZones()
{
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
if (!((NetworkBehaviour)StartOfRound.Instance).IsHost)
{
return;
}
Vector3 val = default(Vector3);
for (int i = 0; i < ConfigManager.HowManyZonesY.Value; i++)
{
for (int j = 0; j < ConfigManager.HowManyZonesX.Value; j++)
{
for (int k = 0; k < ConfigManager.HowManyZonesZ.Value; k++)
{
string text = Defaults.zoneYNames[i] + k.ToString("0") + j.ToString("00");
((Vector3)(ref val))..ctor(ConfigManager.ZoningStartX.Value + ConfigManager.ZoneDistanceX.Value * (float)j, ConfigManager.ZoningStartY.Value + ConfigManager.ZoneDistanceY.Value * (float)i, ConfigManager.ZoningStartZ.Value + ConfigManager.ZoneDistanceZ.Value * (float)k * -1f);
if (ConfigManager.LogCreatedZones.Value)
{
Plugin.logger.LogInfo((object)$"Created zone {text} at {val.x}, {val.y}, {val.z}");
}
Zones.Add(text, val);
}
}
}
}
}
}
namespace ItemDeclutter.Definitions
{
public struct ItemZoneData : INetworkSerializable
{
public FixedString64Bytes ObjectName;
public float XCoordinate;
public float YCoordinate;
public float ZCoordinate;
public unsafe void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{
//IL_000a: 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_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: 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_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
((BufferSerializer<FixedString64Bytes>*)(&serializer))->SerializeValue<FixedString64Bytes>(ref ObjectName, default(ForFixedStrings));
((BufferSerializer<float>*)(&serializer))->SerializeValue<float>(ref XCoordinate, default(ForPrimitives));
((BufferSerializer<float>*)(&serializer))->SerializeValue<float>(ref YCoordinate, default(ForPrimitives));
((BufferSerializer<float>*)(&serializer))->SerializeValue<float>(ref ZCoordinate, default(ForPrimitives));
}
public override readonly string ToString()
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
return $"ObjectName: {ObjectName}, Coordinates: {XCoordinate}/{YCoordinate}/{ZCoordinate}";
}
}
public struct ItemZoneDataWrapper : INetworkSerializable
{
public ItemZoneData[] ItemZonesData;
public unsafe void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{
//IL_001a: 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_004f: 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)
int num = 0;
if (!serializer.IsReader)
{
num = ItemZonesData.Length;
}
((BufferSerializer<int>*)(&serializer))->SerializeValue<int>(ref num, default(ForPrimitives));
if (serializer.IsReader)
{
ItemZonesData = new ItemZoneData[num];
}
for (int i = 0; i < num; i++)
{
((BufferSerializer<ItemZoneData>*)(&serializer))->SerializeValue<ItemZoneData>(ref ItemZonesData[i], default(ForNetworkSerializable));
}
}
}
public interface IItemConfig
{
string ObjectName { get; }
Vector3 Coordinates { get; }
}
public class ItemConfig : IItemConfig
{
public ZoneConfigHandler ZoneConfig;
public Item Item { get; set; }
public string ObjectName => Item.itemName;
public string Zone => ZoneConfig.RawValue;
public Vector3 Coordinates => ((ConfigHandler<Vector3, string>)ZoneConfig).Value;
public float XCoordinate => Coordinates.x;
public float YCoordinate => Coordinates.y;
public float ZCoordinate => Coordinates.z;
public override string ToString()
{
return ObjectName + " (" + (Item.isScrap ? "Scrap" : "Item") + ")";
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}