using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CollectAllStaff")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CollectAllStaff")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("76f66471-a5d5-4063-b03f-4de4a10bcb32")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HoppinHauler.TeleportAllScrapToShip;
[BepInPlugin("HoppinHauler.teleportallscrap", "Teleport All Scrap To Ship", "0.2.0")]
public sealed class TeleportAllScrapToShipPlugin : BaseUnityPlugin
{
private struct TeleportEntry
{
public ulong NetId;
public Vector3 Pos;
}
[CompilerGenerated]
private sealed class <RegisterNetcodeHandlerWhenReady>d__16 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public TeleportAllScrapToShipPlugin <>4__this;
private float <start>5__1;
private CustomMessagingManager <cmm>5__2;
private Exception <e>5__3;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <RegisterNetcodeHandlerWhenReady>d__16(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<cmm>5__2 = null;
<e>5__3 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<start>5__1 = Time.realtimeSinceStartup;
break;
case 1:
<>1__state = -1;
break;
}
if ((Object)(object)NetworkManager.Singleton == (Object)null)
{
if (Time.realtimeSinceStartup - <start>5__1 > 15f)
{
((BaseUnityPlugin)<>4__this).Logger.LogWarning((object)"NetworkManager.Singleton not found (timeout).");
return false;
}
<>2__current = null;
<>1__state = 1;
return true;
}
<cmm>5__2 = NetworkManager.Singleton.CustomMessagingManager;
if (<cmm>5__2 == null)
{
((BaseUnityPlugin)<>4__this).Logger.LogWarning((object)"CustomMessagingManager is null.");
return false;
}
if (<>4__this._handlerRegistered)
{
return false;
}
try
{
<cmm>5__2.RegisterNamedMessageHandler("HoppinHauler.TeleportAllScrapToShip.TeleportBatch", new HandleNamedMessageDelegate(<>4__this.OnTeleportBatchMessage));
<>4__this._handlerRegistered = true;
((BaseUnityPlugin)<>4__this).Logger.LogDebug((object)"Registered netcode message handler.");
}
catch (Exception ex)
{
<e>5__3 = ex;
((BaseUnityPlugin)<>4__this).Logger.LogError((object)$"Failed to register message handler: {<e>5__3}");
}
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
public const string PluginGuid = "HoppinHauler.teleportallscrap";
public const string PluginName = "Teleport All Scrap To Ship";
public const string PluginVersion = "0.2.0";
private const string MessageName = "HoppinHauler.TeleportAllScrapToShip.TeleportBatch";
private bool _handlerRegistered;
private float _lastPressTime;
private ConfigEntry<string> _hotkeyName;
private ConfigEntry<float> _spacing;
private ConfigEntry<float> _maxRadius;
private ConfigEntry<float> _layerHeight;
private ConfigEntry<int> _hardLimit;
private Key _hotkey;
private bool _hotkeyResolved;
private void Awake()
{
_hotkeyName = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Hotkey", "P", "InputSystem key name (e.g. P, F8, KeypadEnter).");
_spacing = ((BaseUnityPlugin)this).Config.Bind<float>("Placement", "Spacing", 0.45f, "Item spacing in meters (smaller = more compact, more collisions).");
_maxRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Placement", "MaxRadius", 2.2f, "Max radius around anchor to place items (meters). When capacity is exceeded, items stack in layers.");
_layerHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Placement", "LayerHeight", 0.18f, "Vertical offset per layer (meters). Smaller = denser vertical stacking.");
_hardLimit = ((BaseUnityPlugin)this).Config.Bind<int>("Safety", "HardLimit", 400, "Max number of items to teleport in one press (prevents physics spikes).");
_hotkeyResolved = false;
_hotkeyName.SettingChanged += delegate
{
_hotkeyResolved = false;
};
SceneManager.sceneLoaded += OnSceneLoaded;
((MonoBehaviour)this).StartCoroutine(RegisterNetcodeHandlerWhenReady());
((BaseUnityPlugin)this).Logger.LogInfo((object)"Teleport All Scrap To Ship 0.2.0 loaded.");
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
_handlerRegistered = false;
((MonoBehaviour)this).StartCoroutine(RegisterNetcodeHandlerWhenReady());
}
[IteratorStateMachine(typeof(<RegisterNetcodeHandlerWhenReady>d__16))]
private IEnumerator RegisterNetcodeHandlerWhenReady()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <RegisterNetcodeHandlerWhenReady>d__16(0)
{
<>4__this = this
};
}
private void Update()
{
if (WasHotkeyPressed())
{
float realtimeSinceStartup = Time.realtimeSinceStartup;
if (!(realtimeSinceStartup - _lastPressTime < 0.25f))
{
_lastPressTime = realtimeSinceStartup;
TryTeleportAllScrapToShip();
}
}
}
private bool WasHotkeyPressed()
{
//IL_008b: 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)
Keyboard current = Keyboard.current;
if (current == null)
{
return false;
}
if (!_hotkeyResolved)
{
_hotkeyResolved = TryResolveKey(_hotkeyName.Value, out _hotkey);
if (!_hotkeyResolved)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Invalid Hotkey '" + _hotkeyName.Value + "'. Falling back to P."));
_hotkey = (Key)30;
_hotkeyResolved = true;
}
}
KeyControl val = current[_hotkey];
return val != null && ((ButtonControl)val).wasPressedThisFrame;
}
private static bool TryResolveKey(string name, out Key key)
{
key = (Key)0;
if (string.IsNullOrEmpty(name))
{
return false;
}
string text = name.Trim();
if (text.Length == 1)
{
text = text.ToUpperInvariant();
}
return Enum.TryParse<Key>(text, ignoreCase: true, out key);
}
private void TryTeleportAllScrapToShip()
{
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
NetworkManager singleton = NetworkManager.Singleton;
if ((Object)(object)singleton == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"NetworkManager not ready.");
return;
}
if (!singleton.IsHost)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"TeleportAllScrapToShip: host only.");
return;
}
if (!_handlerRegistered)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Message handler not registered yet (will still try to send).");
}
if (!TryGetShipAnchor(out var anchor))
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Failed to resolve ship anchor reliably; using fallback position.");
}
List<GrabbableObject> list = FindAllScrapItems();
if (list.Count == 0)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"No scrap items found to teleport.");
return;
}
int num = Mathf.Max(1, _hardLimit.Value);
if (list.Count > num)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)$"Too many items ({list.Count}). Limiting to {num}.");
list = list.Take(num).ToList();
}
FastBufferWriter val = BuildTeleportPayload(list, anchor);
try
{
CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager;
if (customMessagingManager == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"CustomMessagingManager missing; cannot send.");
((FastBufferWriter)(ref val)).Dispose();
}
else
{
customMessagingManager.SendNamedMessageToAll("HoppinHauler.TeleportAllScrapToShip.TeleportBatch", val, (NetworkDelivery)3);
((FastBufferWriter)(ref val)).Dispose();
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Teleported batch: {list.Count} items.");
}
}
catch (Exception arg)
{
((BaseUnityPlugin)this).Logger.LogError((object)$"Failed to send teleport batch: {arg}");
}
}
private List<GrabbableObject> FindAllScrapItems()
{
//IL_0018: 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_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
List<GrabbableObject> list = new List<GrabbableObject>(128);
GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>(true);
Scene sceneByName = SceneManager.GetSceneByName("HideAndDontSave");
foreach (GrabbableObject val in array)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
GameObject gameObject = ((Component)val).gameObject;
if ((Object)(object)gameObject == (Object)null || gameObject.scene == sceneByName)
{
continue;
}
Item itemProperties = val.itemProperties;
if (!((Object)(object)itemProperties == (Object)null) && (itemProperties.isScrap || val.scrapValue > 0) && !val.isHeld && !val.heldByPlayerOnServer)
{
NetworkObject componentInChildren = ((Component)val).GetComponentInChildren<NetworkObject>(true);
if (!((Object)(object)componentInChildren == (Object)null) && componentInChildren.IsSpawned)
{
list.Add(val);
}
}
}
return list;
}
private FastBufferWriter BuildTeleportPayload(List<GrabbableObject> items, Vector3 anchor)
{
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: 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_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
float spacing = Mathf.Clamp(_spacing.Value, 0.2f, 1.5f);
float maxRadius = Mathf.Clamp(_maxRadius.Value, 0.8f, 6f);
float layerHeight = Mathf.Clamp(_layerHeight.Value, 0.1f, 0.45f);
List<TeleportEntry> list = new List<TeleportEntry>(items.Count);
Vector3[] array = GenerateCompactLayeredPositions(anchor, items.Count, spacing, maxRadius, layerHeight);
for (int i = 0; i < items.Count; i++)
{
GrabbableObject val = items[i];
if (!((Object)(object)val == (Object)null))
{
NetworkObject componentInChildren = ((Component)val).GetComponentInChildren<NetworkObject>(true);
if (!((Object)(object)componentInChildren == (Object)null))
{
list.Add(new TeleportEntry
{
NetId = componentInChildren.NetworkObjectId,
Pos = array[i]
});
}
}
}
int num = 4 + list.Count * 20;
FastBufferWriter result = default(FastBufferWriter);
((FastBufferWriter)(ref result))..ctor(num, (Allocator)2, -1);
int count = list.Count;
((FastBufferWriter)(ref result)).WriteValueSafe<int>(ref count, default(ForPrimitives));
for (int j = 0; j < list.Count; j++)
{
TeleportEntry teleportEntry = list[j];
((FastBufferWriter)(ref result)).WriteValueSafe<ulong>(ref teleportEntry.NetId, default(ForPrimitives));
((FastBufferWriter)(ref result)).WriteValueSafe<float>(ref teleportEntry.Pos.x, default(ForPrimitives));
((FastBufferWriter)(ref result)).WriteValueSafe<float>(ref teleportEntry.Pos.y, default(ForPrimitives));
((FastBufferWriter)(ref result)).WriteValueSafe<float>(ref teleportEntry.Pos.z, default(ForPrimitives));
}
return result;
}
private static Vector3[] GenerateCompactLayeredPositions(Vector3 anchor, int count, float spacing, float maxRadius, float layerHeight)
{
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: 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_009c: Unknown result type (might be due to invalid IL or missing references)
if (count <= 0)
{
return Array.Empty<Vector3>();
}
Vector3[] array = (Vector3[])(object)new Vector3[count];
int num = Mathf.Max(1, Mathf.FloorToInt(maxRadius / spacing * (maxRadius / spacing)));
for (int i = 0; i < count; i++)
{
int num2 = i / num;
int num3 = i % num;
float num4 = spacing * Mathf.Sqrt((float)num3);
if (num4 > maxRadius)
{
num4 = maxRadius;
}
float num5 = (float)num3 * 2.3999631f;
float num6 = num4 * Mathf.Cos(num5);
float num7 = num4 * Mathf.Sin(num5);
float num8 = (float)num2 * layerHeight;
array[i] = anchor + new Vector3(num6, num8, num7);
}
return array;
}
private bool TryGetShipAnchor(out Vector3 anchor)
{
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//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_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
try
{
Type type = FindTypeInLoadedAssemblies("DepositItemsDesk");
if (type != null)
{
Object[] array = Resources.FindObjectsOfTypeAll(type);
if (array != null)
{
Scene sceneByName = SceneManager.GetSceneByName("HideAndDontSave");
foreach (Object obj in array)
{
Component val = (Component)(object)((obj is Component) ? obj : null);
if (!((Object)(object)val == (Object)null) && !((Object)(object)val.gameObject == (Object)null) && !(val.gameObject.scene == sceneByName))
{
anchor = val.transform.position;
return true;
}
}
}
}
}
catch
{
}
try
{
PlayerControllerB[] array2 = Resources.FindObjectsOfTypeAll<PlayerControllerB>();
Scene sceneByName2 = SceneManager.GetSceneByName("HideAndDontSave");
foreach (PlayerControllerB val2 in array2)
{
if (!((Object)(object)val2 == (Object)null) && !((Object)(object)((Component)val2).gameObject == (Object)null) && !(((Component)val2).gameObject.scene == sceneByName2) && val2.isInHangarShipRoom)
{
anchor = ((Component)val2).transform.position;
return true;
}
}
}
catch
{
}
try
{
StartOfRound instance = StartOfRound.Instance;
if ((Object)(object)instance != (Object)null && (Object)(object)instance.shipAnimator != (Object)null)
{
anchor = ((Component)instance.shipAnimator).transform.position;
return true;
}
}
catch
{
}
anchor = Vector3.zero;
return false;
}
private static Type FindTypeInLoadedAssemblies(string typeName)
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
if (assembly == null)
{
continue;
}
try
{
Type type = assembly.GetTypes().FirstOrDefault((Type x) => x != null && x.Name == typeName);
if (type != null)
{
return type;
}
}
catch
{
}
}
return null;
}
private void OnTeleportBatchMessage(ulong senderClientId, FastBufferReader reader)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: 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_0086: 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)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
try
{
int num = default(int);
((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
if (num <= 0)
{
return;
}
NetworkManager singleton = NetworkManager.Singleton;
if ((Object)(object)singleton == (Object)null || singleton.SpawnManager == null)
{
return;
}
ulong key = default(ulong);
float num2 = default(float);
float num3 = default(float);
float num4 = default(float);
for (int i = 0; i < num; i++)
{
((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref key, default(ForPrimitives));
((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref num2, default(ForPrimitives));
((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref num3, default(ForPrimitives));
((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref num4, default(ForPrimitives));
if (!singleton.SpawnManager.SpawnedObjects.TryGetValue(key, out var value) || (Object)(object)value == (Object)null)
{
continue;
}
GameObject gameObject = ((Component)value).gameObject;
if (!((Object)(object)gameObject == (Object)null))
{
GrabbableObject val = gameObject.GetComponentInParent<GrabbableObject>();
if ((Object)(object)val == (Object)null)
{
val = gameObject.GetComponent<GrabbableObject>();
}
if (!((Object)(object)val == (Object)null))
{
ApplyImperiumStyleItemTeleport(val, new Vector3(num2, num3, num4));
}
}
}
}
catch (Exception arg)
{
((BaseUnityPlugin)this).Logger.LogError((object)$"Teleport batch handler error: {arg}");
}
}
private static void ApplyImperiumStyleItemTeleport(GrabbableObject item, Vector3 destination)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: 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_003b: 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_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//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)
if ((Object)(object)item == (Object)null)
{
return;
}
Transform transform = ((Component)item).transform;
if (!((Object)(object)transform == (Object)null))
{
transform.position = destination + Vector3.up;
item.startFallingPosition = transform.position;
if ((Object)(object)transform.parent != (Object)null)
{
item.startFallingPosition = transform.parent.InverseTransformPoint(item.startFallingPosition);
}
item.FallToGround(false, false, default(Vector3));
item.PlayDropSFX();
}
}
}