using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FixedItemRotation;
using GameNetcodeStuff;
using HarmonyLib;
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: AssemblyCompany("LethalCompanyTemplate")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A template for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+63d5223bd0294da828623259f64db8568ec37082")]
[assembly: AssemblyProduct("LethalCompanyTemplate")]
[assembly: AssemblyTitle("LethalCompanyTemplate")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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 LethalCompanyTemplate
{
public static class PluginInfo
{
public const string PLUGIN_GUID = "LethalCompanyTemplate";
public const string PLUGIN_NAME = "LethalCompanyTemplate";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace ItemDeclutter
{
[HarmonyPatch(typeof(StartOfRound))]
internal class ShipLoadItems
{
[HarmonyPatch("LoadShipGrabbableItems")]
[HarmonyPostfix]
internal static void LoadShipItemsPatch()
{
GameObject val = GameObject.Find("/Environment/HangarShip");
GrabbableObject[] componentsInChildren = val.GetComponentsInChildren<GrabbableObject>();
GrabbableObject[] array = componentsInChildren;
foreach (GrabbableObject val2 in array)
{
Plugin.logger.LogDebug((object)("Found " + ((Object)val2).name));
StackTooltip.UpdateAllTooltips(((Object)val2).name);
}
}
}
}
namespace FixedItemRotation
{
[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)
{
if (droppedInShipRoom)
{
floorYRot = 1;
}
}
[HarmonyPatch(typeof(GrabbableObject))]
[HarmonyPatch("DiscardItemClientRpc")]
[HarmonyPostfix]
internal static void ItemDroppedOnShipPatchPostfix(GrabbableObject __instance)
{
if (__instance.isInShipRoom)
{
string itemName = __instance.itemProperties.itemName;
__instance.floorYRot = 1;
Plugin.logger.LogInfo((object)("dropped " + itemName));
__instance.customGrabTooltip = StackTooltip.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 = StackTooltip.UpdateAllTooltips(itemName);
}
}
}
}
internal class StackTooltip
{
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;
}
CollectionExtensions.Do<GrabbableObject>((IEnumerable<GrabbableObject>)list, (Action<GrabbableObject>)delegate(GrabbableObject item)
{
if ((Object)(object)item.playerHeldBy != (Object)null)
{
ItemsOnShip.Remove(item);
}
});
int num = ItemsOnShip.Count();
string text = $"{itemName} (x{num}) \n Grab : [E]";
foreach (GrabbableObject item in ItemsOnShip)
{
item.customGrabTooltip = text;
}
return text;
}
}
[BepInPlugin("FixedItemRotation", "FixedItemRotation", "0.0.1")]
public class Plugin : BaseUnityPlugin
{
private readonly Harmony harmony = new Harmony("FixedItemRotation");
internal static ManualLogSource logger;
private void Awake()
{
harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin FixedItemRotation is loaded!");
}
}
}