using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ReservedItemSlotCore;
using ReservedItemSlotCore.Networking;
using ReservedItemSlotCore.Patches;
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("ReservedBoomboxSlot")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ReservedBoomboxSlot")]
[assembly: AssemblyTitle("ReservedBoomboxSlot")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
}
}
}
namespace ReservedBoomboxSlot
{
[BepInPlugin("Luck.ReservedBoomboxSlot", "ReservedBoomboxSlot", "1.0.8")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class Plugin : BaseUnityPlugin
{
public static Plugin instance;
private Harmony _harmony;
public static ReservedItemInfo defaultBoombox = new ReservedItemInfo("Boombox", 21, false, false, false, false);
private void Awake()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
instance = this;
_harmony = new Harmony("ReservedBoomboxSlot");
if (Chainloader.PluginInfos.ContainsKey("Luck.ReservedBoomboxSlot"))
{
}
_harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"ReservedBoomboxSlot loaded");
}
public static void Log(string message)
{
((BaseUnityPlugin)instance).Logger.LogInfo((object)message);
}
}
}
namespace ReservedBoomboxSlot.Patches
{
[HarmonyPatch]
internal static class Patcher
{
private static Vector3 playerShoulderPositionOffset = new Vector3(-0.4f, 0.3f, 0f);
private static Vector3 playerShoulderRotationOffset = new Vector3(0f, 90f, 90f);
public static HashSet<BoomboxItem> pocketingBoomboxes = new HashSet<BoomboxItem>();
public static PlayerControllerB localPlayerController => PlayerPatcher.localPlayerController;
public static PlayerControllerB GetPreviousPlayerHeldBy(BoomboxItem boomboxItem)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
return (PlayerControllerB)Traverse.Create((object)boomboxItem).Field("previousPlayerHeldBy").GetValue();
}
public static BoomboxItem GetMainBoombox(PlayerControllerB playerController)
{
return GetCurrentlySelectedBoombox(playerController) ?? GetReservedBoombox(playerController);
}
public static BoomboxItem GetReservedBoombox(PlayerControllerB playerController)
{
return (BoomboxItem)(SyncManager.syncReservedItemsList.Contains(Plugin.defaultBoombox) ? /*isinst with value type is only supported in some contexts*/: null);
}
public static BoomboxItem GetCurrentlySelectedBoombox(PlayerControllerB playerController)
{
GrabbableObject obj = ((playerController != null) ? playerController.ItemSlots[playerController.currentItemSlot] : null);
return (BoomboxItem)(object)((obj is BoomboxItem) ? obj : null);
}
[HarmonyPatch(typeof(GrabbableObject), "PocketItem")]
[HarmonyPostfix]
public static void OnPocketBoomboxLocal(GrabbableObject __instance)
{
if (__instance is BoomboxItem)
{
OnPocketBoombox(__instance);
}
}
private static void OnPocketBoombox(GrabbableObject boomboxItem)
{
if (boomboxItem is BoomboxItem && !((Object)(object)boomboxItem.playerHeldBy == (Object)null))
{
if ((Object)(object)boomboxItem.playerHeldBy == (Object)(object)localPlayerController)
{
((Component)boomboxItem).gameObject.layer = 23;
}
else
{
((Component)boomboxItem).gameObject.layer = 6;
}
if ((Object)(object)boomboxItem == (Object)(object)GetReservedBoombox(boomboxItem.playerHeldBy))
{
boomboxItem.parentObject = boomboxItem.playerHeldBy.playerGlobalHead.parent;
}
}
}
[HarmonyPatch(typeof(GrabbableObject), "EquipItem")]
[HarmonyPostfix]
public static void OnEquipBoombox(GrabbableObject __instance)
{
if (__instance is BoomboxItem && !((Object)(object)__instance.playerHeldBy == (Object)null))
{
((Component)__instance).gameObject.layer = 6;
__instance.parentObject = (((Object)(object)__instance.playerHeldBy == (Object)(object)localPlayerController) ? __instance.playerHeldBy.localItemHolder : __instance.playerHeldBy.serverItemHolder);
}
}
[HarmonyPatch(typeof(GrabbableObject), "DiscardItem")]
[HarmonyPostfix]
public static void ResetLayerAfterDiscard(GrabbableObject __instance)
{
if (__instance is BoomboxItem)
{
((Component)__instance).gameObject.layer = 6;
}
}
[HarmonyPatch(typeof(GrabbableObject), "LateUpdate")]
[HarmonyPostfix]
public static void SetPositionOffset(GrabbableObject __instance)
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//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_0085: 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_009d: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
if (__instance is BoomboxItem && (Object)(object)__instance.playerHeldBy != (Object)null && (Object)(object)__instance.parentObject != (Object)null && __instance.isPocketed && (Object)(object)__instance == (Object)(object)GetReservedBoombox(__instance.playerHeldBy) && (Object)(object)__instance != (Object)(object)GetCurrentlySelectedBoombox(__instance.playerHeldBy))
{
Transform transform = ((Component)__instance.parentObject).transform;
((Component)__instance).transform.rotation = ((Component)__instance.parentObject).transform.rotation * Quaternion.Euler(playerShoulderRotationOffset);
((Component)__instance).transform.position = transform.position + transform.rotation * playerShoulderPositionOffset;
}
}
[HarmonyPatch(typeof(GrabbableObject), "EnableItemMeshes")]
[HarmonyPrefix]
public static void OnEnableItemMeshes(ref bool enable, GrabbableObject __instance)
{
if (__instance is BoomboxItem)
{
enable = true;
}
}
[HarmonyPatch(typeof(BoomboxItem), "PocketItem")]
[HarmonyPrefix]
public static void OnPocketBoombox(BoomboxItem __instance)
{
pocketingBoomboxes.Add(__instance);
}
[HarmonyPatch(typeof(BoomboxItem), "StartMusic")]
[HarmonyPrefix]
public static bool PreventStoppingMusicOnPocket(bool startMusic, BoomboxItem __instance)
{
if (pocketingBoomboxes.Contains(__instance))
{
pocketingBoomboxes.Remove(__instance);
return false;
}
return true;
}
}
}