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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalLib.Modules;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
using Microsoft.CodeAnalysis;
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(".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("ScienceBird.MoreCupboards")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.3.2.0")]
[assembly: AssemblyInformationalVersion("1.3.2+147949c40d932cedd8055248d85aa922b94d149f")]
[assembly: AssemblyProduct("MoreCupboards")]
[assembly: AssemblyTitle("ScienceBird.MoreCupboards")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.2.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.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]
[Microsoft.CodeAnalysis.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]
[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 MoreCupboards
{
public class AddCupboards
{
public static AssetBundle CupboardAssets;
public static ContentLoader ContentLoader;
public static Dictionary<string, GameObject> Prefabs = new Dictionary<string, GameObject>();
private static int price = 300;
public static bool mattyPresent = false;
public static void RegisterCupboards()
{
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Expected O, but got Unknown
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Expected O, but got Unknown
mattyPresent = false;
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
if (assembly.GetName().Name == "MattyFixes")
{
MoreCupboards.Logger.LogDebug((object)"Found matty!");
mattyPresent = true;
break;
}
}
if (MoreCupboards.cupboardPrice.Value >= 0)
{
price = MoreCupboards.cupboardPrice.Value;
}
CupboardAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "cupboardunlockable"));
ContentLoader = new ContentLoader(MoreCupboards.pluginInfo, CupboardAssets, (Action<CustomContent, GameObject>)delegate(CustomContent content, GameObject prefab)
{
Prefabs.Add(content.ID, prefab);
});
string text = "";
if (MoreCupboards.noDoors.Value)
{
text = "Alt";
}
List<CustomContent> list = new List<CustomContent>();
for (int j = 1; j <= MoreCupboards.maximumCupboards.Value; j++)
{
list.Add((CustomContent)new Unlockable(j + "Cupboard", "Assets/LethalCompany/Mods/MoreCupboards/Cupboard" + j + text + "UnlockableItemDef.asset", price, (string)null, (string)null, "Assets/LethalCompany/Mods/MoreCupboards/CupboardInfo.asset", (StoreType)1, (Action<UnlockableItem>)null));
}
CustomContent[] array = list.ToArray();
ContentLoader.RegisterAll(array);
}
}
public class LobbyCompatibility
{
public static void RegisterCompatibility()
{
PluginHelper.RegisterPlugin("ScienceBird.MoreCupboards", Version.Parse("1.3.2"), (CompatibilityLevel)2, (VersionStrictness)0);
}
}
[BepInPlugin("ScienceBird.MoreCupboards", "MoreCupboards", "1.3.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class MoreCupboards : BaseUnityPlugin
{
public static PluginInfo pluginInfo;
public static ConfigFile config;
public static ConfigEntry<int> cupboardPrice;
public static ConfigEntry<int> maximumCupboards;
public static ConfigEntry<bool> noDoors;
public static ConfigEntry<bool> separateCupboardEntries;
public static ConfigEntry<bool> autoParent;
public static MoreCupboards Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
internal static Harmony? Harmony { get; set; }
private void Awake()
{
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
pluginInfo = ((BaseUnityPlugin)this).Info;
cupboardPrice = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Cupboard Price", 300, "How much it costs to buy cupboards from the store.");
maximumCupboards = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Maximum Cupboards", 5, new ConfigDescription("Maximum extra cupboards you're allowed to buy for your ship. This is in addition to the vanilla cupboard, so the actual number of cupboards you can have on the ship will be one higher than this.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 5), Array.Empty<object>()));
noDoors = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "No Doors", false, "Remove doors from purchased cupboards (does not affect vanilla cupboard).");
separateCupboardEntries = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Separate Cupboard Entries", false, "Rather than the shop listing a single cupboard, it and the storage menu will list numbered cupboards (1Cupboard, 2Cupboard, etc.) so you can request specific cupboards (if you're experiencing unusal behaviour in the terminal, try enabling this).");
autoParent = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Auto Parent", true, "If Matty Fixes is found, attempt to parent items to cupboards (only try turning this off if you're having any major errors or other issues with the mod).");
AddCupboards.RegisterCupboards();
Patch();
Logger.LogInfo((object)"ScienceBird.MoreCupboards v1.3.2 has loaded!");
}
internal static void Patch()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("ScienceBird.MoreCupboards");
}
bool flag = false;
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
if (assembly.GetName().Name == "BMX.LobbyCompatibility")
{
Logger.LogDebug((object)"Found BMX!");
flag = true;
break;
}
}
if (flag)
{
LobbyCompatibility.RegisterCompatibility();
}
Logger.LogDebug((object)"Patching...");
Harmony.PatchAll();
Logger.LogDebug((object)"Finished patching!");
}
internal static void Unpatch()
{
Logger.LogDebug((object)"Unpatching...");
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Logger.LogDebug((object)"Finished unpatching!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "ScienceBird.MoreCupboards";
public const string PLUGIN_NAME = "MoreCupboards";
public const string PLUGIN_VERSION = "1.3.2";
}
}
namespace MoreCupboards.Patches
{
[HarmonyPatch]
internal class InteractSurfaceCopy
{
internal static bool storeFlag = false;
public static bool mrovPresent = false;
public static bool getData = true;
[HarmonyPatch(typeof(StartOfRound), "SceneManager_OnLoadComplete1")]
[HarmonyPostfix]
private static void DestroyCupboardDoors(StartOfRound __instance, string sceneName)
{
getData = true;
if (sceneName == "SampleSceneRelay" && MoreCupboards.noDoors.Value)
{
GameObject val = GameObject.Find("StorageCloset");
Animator[] componentsInChildren = val.GetComponentsInChildren<Animator>();
Animator[] array = componentsInChildren;
foreach (Animator val2 in array)
{
if (((Object)((Component)val2).gameObject).name == "Cube.000" || ((Object)((Component)val2).gameObject).name == "Cube.002")
{
Object.Destroy((Object)(object)((Component)val2).gameObject);
}
}
}
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
if (assembly.GetName().Name == "TerminalFormatter")
{
mrovPresent = true;
break;
}
}
}
[HarmonyPatch(typeof(Terminal), "LoadNewNode")]
[HarmonyPrefix]
[HarmonyBefore(new string[] { "mrov.terminalformatter" })]
private static void TerminalTextCheck(Terminal __instance, TerminalNode node)
{
if (!MoreCupboards.separateCupboardEntries.Value && node.displayText.Contains("[buyableItemsList]"))
{
storeFlag = true;
}
}
[HarmonyPatch(typeof(Terminal), "LoadNewNode")]
[HarmonyPostfix]
[HarmonyPriority(0)]
[HarmonyAfter(new string[] { "mrov.terminalformatter" })]
private static void TerminalTextOverride(Terminal __instance)
{
if (MoreCupboards.separateCupboardEntries.Value)
{
return;
}
string text = "";
if (mrovPresent && storeFlag)
{
text = " ";
}
for (int i = 1; i <= MoreCupboards.maximumCupboards.Value; i++)
{
string text2 = i + "Cupboard";
if (__instance.currentText.Contains(text2))
{
__instance.currentText = __instance.currentText.Replace(text2, "Cupboard" + text);
}
}
if (storeFlag)
{
int num = __instance.currentText.Split("Cupboard").Length - 1;
if (MoreCupboards.maximumCupboards.Value > 1 && __instance.currentText.IndexOf("Cupboard") > 0 && num > 1)
{
string text3 = __instance.currentText.Substring(__instance.currentText.IndexOf("Cupboard"));
string text4 = text3.Substring(text3.IndexOf("\n") + 2);
string text5 = text4.Substring(text4.LastIndexOf("Cupboard"));
string text6 = text4.Substring(0, text5.IndexOf("\n") + text4.LastIndexOf("Cupboard") + 2);
if (num == 2)
{
__instance.currentText = __instance.currentText.Remove(__instance.currentText.LastIndexOf(text6), text6.Length);
}
else
{
__instance.currentText = __instance.currentText.Replace(text6, "");
}
}
storeFlag = false;
}
__instance.screenText.text = __instance.currentText;
}
[HarmonyPatch(typeof(Terminal), "OnSubmit")]
[HarmonyPrefix]
private static void CupboardCommandOverride(Terminal __instance)
{
if (MoreCupboards.separateCupboardEntries.Value)
{
return;
}
string text = __instance.screenText.text.Substring(__instance.screenText.text.Length - __instance.textAdded);
if (!(text.ToLower() == "cupboard") && text.ToLower().IndexOf("cupb") != 0 && text.ToLower().IndexOf("cupb") != 1)
{
return;
}
text = "cupboard";
UnlockableItem[] array = StartOfRound.Instance.unlockablesList.unlockables.ToArray();
int num = 0;
int num2 = 0;
for (int i = 1; i <= MoreCupboards.maximumCupboards.Value; i++)
{
string text2 = i + "Cupboard";
UnlockableItem[] array2 = array;
foreach (UnlockableItem val in array2)
{
if (val.unlockableName == "Cupboard" && val.inStorage)
{
num = -1;
break;
}
if (val.unlockableName == text2 && val.inStorage)
{
num = i;
break;
}
}
if (num2 == 0 && num == 0)
{
UnlockableItem[] array3 = array;
foreach (UnlockableItem val2 in array3)
{
if (val2.unlockableName == text2 && !val2.hasBeenUnlockedByPlayer)
{
num2 = i;
break;
}
}
}
if (num != 0)
{
break;
}
}
switch (num)
{
default:
MoreCupboards.Logger.LogInfo((object)$"Retrieving cupboard{num}");
text = num + text;
break;
case 0:
if (num2 != 0)
{
MoreCupboards.Logger.LogInfo((object)$"Buying cupboard{num2}");
text = num2 + text;
break;
}
MoreCupboards.Logger.LogInfo((object)"Unable to find cupboards!");
return;
case -1:
break;
}
if (num != -1)
{
__instance.screenText.text = __instance.screenText.text.Substring(0, __instance.screenText.text.Length - __instance.textAdded) + text;
}
}
[HarmonyPatch(typeof(ShipBuildModeManager), "StoreObjectLocalClient")]
[HarmonyPrefix]
private static void UnparentItemsOnStore(ShipBuildModeManager __instance)
{
if (__instance.timeSincePlacingObject <= 0.25f || !__instance.InBuildMode || (Object)(object)__instance.placingObject == (Object)null || !StartOfRound.Instance.unlockablesList.unlockables[__instance.placingObject.unlockableID].canBeStored)
{
return;
}
UnlockableItem val = StartOfRound.Instance.unlockablesList.unlockables[__instance.placingObject.unlockableID];
if (!val.unlockableName.Contains("Cupboard"))
{
return;
}
StartOfRound val2 = Object.FindObjectOfType<StartOfRound>();
PlaceableShipObject placingObject = __instance.placingObject;
object obj;
if (placingObject == null)
{
obj = null;
}
else
{
AutoParentToShip parentObject = placingObject.parentObject;
if (parentObject == null)
{
obj = null;
}
else
{
GameObject gameObject = ((Component)parentObject).gameObject;
obj = ((gameObject != null) ? gameObject.GetComponentsInChildren<GrabbableObject>() : null);
}
}
GrabbableObject[] array = (GrabbableObject[])obj;
GrabbableObject[] array2 = array;
foreach (GrabbableObject val3 in array2)
{
val3.parentObject = null;
((Component)val3).transform.SetParent(val2.elevatorTransform, true);
}
}
[HarmonyPatch(typeof(ShipBuildModeManager), "StoreObjectServerRpc")]
[HarmonyPrefix]
private static void UnparentItemsOnStoreServer(ShipBuildModeManager __instance, NetworkObjectReference objectRef)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
NetworkObjectReference val = objectRef;
NetworkObject val2 = default(NetworkObject);
if (!((NetworkObjectReference)(ref val)).TryGet(ref val2, (NetworkManager)null))
{
return;
}
PlaceableShipObject componentInChildren = ((Component)val2).gameObject.GetComponentInChildren<PlaceableShipObject>();
if (!StartOfRound.Instance.unlockablesList.unlockables[componentInChildren.unlockableID].unlockableName.Contains("Cupboard"))
{
return;
}
StartOfRound val3 = Object.FindObjectOfType<StartOfRound>();
object obj;
if (componentInChildren == null)
{
obj = null;
}
else
{
AutoParentToShip parentObject = componentInChildren.parentObject;
if (parentObject == null)
{
obj = null;
}
else
{
GameObject gameObject = ((Component)parentObject).gameObject;
obj = ((gameObject != null) ? gameObject.GetComponentsInChildren<GrabbableObject>() : null);
}
}
GrabbableObject[] array = (GrabbableObject[])obj;
GrabbableObject[] array2 = array;
foreach (GrabbableObject val4 in array2)
{
val4.parentObject = null;
((Component)val4).transform.SetParent(val3.elevatorTransform, true);
}
}
[HarmonyPatch(typeof(ShipBuildModeManager), "StoreShipObjectClientRpc")]
[HarmonyPrefix]
private static void UnparentItemsOnStoreClient(ShipBuildModeManager __instance, NetworkObjectReference objectRef, int playerWhoStored)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)NetworkManager.Singleton == (Object)null || ((NetworkBehaviour)__instance).NetworkManager.ShutdownInProgress || ((NetworkBehaviour)__instance).IsServer || playerWhoStored == (int)GameNetworkManager.Instance.localPlayerController.playerClientId)
{
return;
}
NetworkObjectReference val = objectRef;
NetworkObject val2 = default(NetworkObject);
if (!((NetworkObjectReference)(ref val)).TryGet(ref val2, (NetworkManager)null))
{
return;
}
PlaceableShipObject componentInChildren = ((Component)val2).gameObject.GetComponentInChildren<PlaceableShipObject>();
if (!StartOfRound.Instance.unlockablesList.unlockables[componentInChildren.unlockableID].unlockableName.Contains("Cupboard"))
{
return;
}
StartOfRound val3 = Object.FindObjectOfType<StartOfRound>();
object obj;
if (componentInChildren == null)
{
obj = null;
}
else
{
AutoParentToShip parentObject = componentInChildren.parentObject;
if (parentObject == null)
{
obj = null;
}
else
{
GameObject gameObject = ((Component)parentObject).gameObject;
obj = ((gameObject != null) ? gameObject.GetComponentsInChildren<GrabbableObject>() : null);
}
}
GrabbableObject[] array = (GrabbableObject[])obj;
GrabbableObject[] array2 = array;
foreach (GrabbableObject val4 in array2)
{
val4.parentObject = null;
((Component)val4).transform.SetParent(val3.elevatorTransform, true);
}
}
[HarmonyPatch(typeof(StartOfRound), "SceneManager_OnLoadComplete1")]
[HarmonyPostfix]
private static void ParentCupboardsOnLoad(StartOfRound __instance)
{
MoreCupboards.Logger.LogDebug((object)"Parenting existing cupboards to ship...");
GameObject val = GameObject.Find("/Environment/HangarShip");
for (int i = 1; i <= MoreCupboards.maximumCupboards.Value; i++)
{
GameObject val2 = GameObject.Find($"StorageCloset{i}(Clone)");
GameObject val3 = GameObject.Find($"StorageCloset{i}Alt(Clone)");
if ((Object)(object)val2 != (Object)null && (Object)(object)val != (Object)null)
{
val2.transform.SetParent(val.transform, true);
}
else if ((Object)(object)val3 != (Object)null && (Object)(object)val != (Object)null)
{
val3.transform.SetParent(val.transform, true);
}
}
}
[HarmonyPatch(typeof(StartOfRound), "SpawnUnlockable")]
[HarmonyPostfix]
private static void ParentNewCupboard(StartOfRound __instance, int unlockableIndex)
{
UnlockableItem val = __instance.unlockablesList.unlockables[unlockableIndex];
if (!val.unlockableName.Contains("Cupboard") || !(val.unlockableName != "Cupboard"))
{
return;
}
try
{
MoreCupboards.Logger.LogDebug((object)"Parenting cupboard to ship...");
int num = ((!string.IsNullOrEmpty(val.unlockableName.Replace("Cupboard", ""))) ? int.Parse(val.unlockableName.Replace("Cupboard", "")) : 0);
if (num <= MoreCupboards.maximumCupboards.Value && num > 0)
{
GameObject val2 = GameObject.Find("/Environment/HangarShip");
GameObject val3 = GameObject.Find($"StorageCloset{num}(Clone)");
GameObject val4 = GameObject.Find($"StorageCloset{num}Alt(Clone)");
if ((Object)(object)val3 != (Object)null && (Object)(object)val2 != (Object)null)
{
val3.transform.SetParent(val2.transform, true);
}
else if ((Object)(object)val4 != (Object)null && (Object)(object)val2 != (Object)null)
{
val4.transform.SetParent(val2.transform, true);
}
}
}
catch (FormatException)
{
MoreCupboards.Logger.LogWarning((object)"Incorrect cupboard name string passed!");
}
}
}
[HarmonyPatch]
internal class CupboardSaveStoredItems
{
private static bool doSync = false;
private static int syncTimer = 30;
private static void ApplyCupboardParents()
{
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
if (!AddCupboards.mattyPresent || !MoreCupboards.autoParent.Value)
{
return;
}
MoreCupboards.Logger.LogDebug((object)"Finding objects in cupboards...");
GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
List<BoxCollider> list = new List<BoxCollider>();
for (int i = 0; i <= MoreCupboards.maximumCupboards.Value; i++)
{
string text = i.ToString();
GameObject val;
if (i == 0)
{
if (AddCupboards.mattyPresent)
{
continue;
}
text = string.Empty;
val = GameObject.Find("/Environment/HangarShip/StorageCloset/PlacementCollider");
}
else
{
val = GameObject.Find("StorageCloset" + text + "(Clone)/PlacementCollider");
if ((Object)(object)val == (Object)null)
{
val = GameObject.Find("StorageCloset" + text + "Alt(Clone)/PlacementCollider");
}
}
if ((Object)(object)val == (Object)null)
{
MoreCupboards.Logger.LogDebug((object)("Unable to find specified cupboard! StorageCloset" + text));
continue;
}
BoxCollider component = val.GetComponent<BoxCollider>();
if ((Object)(object)component != (Object)null)
{
list.Add(component);
}
}
GrabbableObject[] array2 = array;
foreach (GrabbableObject val2 in array2)
{
foreach (BoxCollider item in list)
{
Transform parent = ((Component)item).gameObject.transform.parent;
Bounds bounds = ((Collider)item).bounds;
if (((Bounds)(ref bounds)).Contains(((Component)val2).transform.position) && (Object)(object)parent != (Object)null)
{
((Component)val2).transform.parent = parent;
val2.targetFloorPosition = ((Component)val2).transform.localPosition;
}
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "LateUpdate")]
private static void OnUpdate(StartOfRound __instance)
{
if (AddCupboards.mattyPresent && MoreCupboards.autoParent.Value && doSync)
{
syncTimer--;
if (syncTimer <= 0)
{
ApplyCupboardParents();
doSync = false;
syncTimer = 30;
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "LoadShipGrabbableItems")]
private static void LoadOnServerSpawn(StartOfRound __instance)
{
if (AddCupboards.mattyPresent && MoreCupboards.autoParent.Value)
{
doSync = true;
syncTimer = 30;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "SyncShipUnlockablesClientRpc")]
private static void LoadAfterCupboardSync(StartOfRound __instance)
{
if (AddCupboards.mattyPresent && MoreCupboards.autoParent.Value)
{
doSync = true;
syncTimer = 30;
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}