using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using CG;
using CG.Game;
using CG.Game.Player;
using CG.Game.SpaceObjects;
using CG.Objects;
using CG.Ship.Hull;
using CG.Utils;
using Client.Galaxy.Interactions;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using VoidManager;
using VoidManager.MPModChecks;
using VoidManager.ModMessages;
using VoidManager.Utilities;
[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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ThrowToSlot")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ThrowToSlot")]
[assembly: AssemblyTitle("If a thrown item hits an empty slot, it will be put in that slot.")]
[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 ThrowToSlot
{
[HarmonyPatch(typeof(CarryableInteract), "EndThrow")]
internal class CarryableInteractPatch
{
private static void Prefix(CarryableInteract __instance)
{
if (VoidManagerPlugin.Enabled)
{
object obj;
if (__instance == null)
{
obj = null;
}
else
{
LocalPlayer player = __instance.player;
obj = ((player != null) ? ((Player)player).Payload : null);
}
if (!((Object)obj == (Object)null))
{
MessageHandler.Send(((MonoBehaviourPun)((Player)__instance.player).Payload).photonView.ViewID);
}
}
}
}
[HarmonyPatch(typeof(CollisionComponent), "OnTriggerEnter")]
internal class CollisionComponentPatch
{
private static void Prefix(CollisionComponent __instance)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//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)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: 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)
if (!VoidManagerPlugin.Enabled || !HostSide.thrownItems.ContainsKey(__instance.MyObject))
{
return;
}
Player val = HostSide.thrownItems[__instance.MyObject];
Vector3 val2 = val.Position - ((IBaseObject)__instance.MyObject).Transform.position;
if (((Vector3)(ref val2)).magnitude < 3.5f)
{
return;
}
IOrbitObject myObject = __instance.MyObject;
CarryableObject val3 = (CarryableObject)(object)((myObject is CarryableObject) ? myObject : null);
if ((Object)(object)val3 == (Object)null)
{
return;
}
float num = float.PositiveInfinity;
CarryablesSocket val4 = null;
CarryablesSocket[] sockets = HostSide.sockets;
foreach (CarryablesSocket val5 in sockets)
{
val2 = ((Component)val5).transform.position - ((AbstractCloneStarObject)val3).Transform.position;
float magnitude = ((Vector3)(ref val2)).magnitude;
if (magnitude < num && val5.DoesAccept(val3) && (Object)(object)val5.Payload == (Object)null)
{
num = magnitude;
val4 = val5;
}
}
if (!((Object)(object)val4 == (Object)null) && !(num > 2.5f))
{
val4.TryInsertCarryable(val3);
HostSide.thrownItems.Remove((IOrbitObject)(object)val3);
}
}
}
internal class HostSide
{
internal static Dictionary<IOrbitObject, Player> thrownItems = new Dictionary<IOrbitObject, Player>();
internal static CarryablesSocket[] sockets = (CarryablesSocket[])(object)new CarryablesSocket[0];
}
internal class MessageHandler : ModMessage
{
private const int version = 0;
public override void Handle(object[] arguments, Player sender)
{
if (!PhotonNetwork.IsMasterClient || arguments.Length < 1 || !(arguments[0] is int))
{
return;
}
int num = (int)arguments[0];
if (num != 0)
{
BepinPlugin.Log.LogInfo((object)$"Received version {num} from {sender.NickName}, expected {0}");
}
else if (arguments.Length >= 2 && arguments[1] is int)
{
int num2 = (int)arguments[1];
CarryableObject thrownItem = ((Component)PhotonView.Find(num2)).gameObject.GetComponent<CarryableObject>();
if (HostSide.thrownItems.ContainsKey((IOrbitObject)(object)thrownItem))
{
HostSide.thrownItems.Remove((IOrbitObject)(object)thrownItem);
}
HostSide.thrownItems.Add((IOrbitObject)(object)thrownItem, Player.GetByActorId(sender.ActorNumber));
Tools.DelayDoUnique((object)thrownItem, (Action)delegate
{
HostSide.thrownItems.Remove((IOrbitObject)(object)thrownItem);
}, 5000.0);
HostSide.sockets = ((Component)ClientGame.Current.playerShip).gameObject.GetComponentsInChildren<CarryablesSocket>();
}
}
internal static void Send(int viewId)
{
ModMessage.Send("id107.throwtoslot", ModMessage.GetIdentifier(typeof(MessageHandler)), (ReceiverGroup)2, new object[2] { 0, viewId }, false);
}
}
public class MyPluginInfo
{
public const string PLUGIN_GUID = "id107.throwtoslot";
public const string PLUGIN_NAME = "ThrowToSlot";
public const string USERS_PLUGIN_NAME = "Throw To Slot";
public const string PLUGIN_VERSION = "1.0.0";
public const string PLUGIN_DESCRIPTION = "If a thrown item hits an empty slot, it will be put in that slot.";
public const string PLUGIN_ORIGINAL_AUTHOR = "18107";
public const string PLUGIN_AUTHORS = "18107";
public const string PLUGIN_THUNDERSTORE_ID = "";
}
[BepInPlugin("id107.throwtoslot", "Throw To Slot", "1.0.0")]
[BepInProcess("Void Crew.exe")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BepinPlugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin id107.throwtoslot is loaded!");
}
}
public class VoidManagerPlugin : VoidPlugin
{
public static bool Enabled { get; private set; }
public override MultiplayerType MPType => (MultiplayerType)14;
public override string Author => "18107";
public override string Description => "If a thrown item hits an empty slot, it will be put in that slot.";
public override string ThunderstoreID => "";
public override SessionChangedReturn OnSessionChange(SessionChangedInput input)
{
//IL_0001: 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)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
Enabled = input.HostHasMod;
SessionChangedReturn result = default(SessionChangedReturn);
result.SetMod_Session = true;
return result;
}
}
}