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.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CollectCruiserItemCompany.Commands;
using CollectCruiserItemCompany.Extensions;
using CollectCruiserItemCompany.Helpers;
using CollectCruiserItemCompany.Managers;
using CollectCruiserItemCompany.NetworkObjects;
using CollectCruiserItemCompany.Utils;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Mathematics;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.aoirint.CollectCruiserItemCompany")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyInformationalVersion("0.3.0+3257d0df9725840daa90290e5837dc28890fa2f0")]
[assembly: AssemblyProduct("CollectCruiserItemCompany")]
[assembly: AssemblyTitle("com.aoirint.CollectCruiserItemCompany")]
[assembly: AssemblyVersion("0.3.0.0")]
[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 CollectCruiserItemCompany
{
public enum Permission
{
HostOnly,
Everone
}
[BepInPlugin("com.aoirint.CollectCruiserItemCompany", "CollectCruiserItemCompany", "0.3.0")]
[BepInProcess("Lethal Company.exe")]
public class CollectCruiserItemCompany : BaseUnityPlugin
{
internal static Harmony harmony = new Harmony("com.aoirint.CollectCruiserItemCompany");
internal static ManualLogSource? Logger { get; private set; }
internal static LandingHistoryManager LandingHistoryManager { get; } = new LandingHistoryManager();
internal static TerminalCommandManager TerminalCommandManager { get; } = new TerminalCommandManager();
internal static CollectCruiserItemManager CollectCruiserItemManager { get; } = new CollectCruiserItemManager();
internal static ConfigEntry<Permission>? PermissionConfig { get; private set; }
internal static ConfigEntry<string>? ExclusionListConfig { get; private set; }
internal static ConfigEntry<string>? ScrapExclusionListConfig { get; private set; }
internal static ConfigEntry<string>? ToolExclusionListConfig { get; private set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
PermissionConfig = ((BaseUnityPlugin)this).Config.Bind<Permission>("General", "Permission", Permission.HostOnly, "Controls who can collect items from cruiser by terminal. If HostOnly, only the host can collect items. If Everyone, all players can collect items if they have installed this mod.");
ExclusionListConfig = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Global Exclusion List", "", "Excludes items from being collected by any `collect` command. A comma-separated list of item names, exact match and case-insensitive. Example: `Easter egg, Shovel`");
ScrapExclusionListConfig = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Scrap Exclusion List", "Shotgun, Knife", "Additional exclusion list for `collect scrap`.");
ToolExclusionListConfig = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Tool Exclusion List", "", "Additional exclusion list for `collect tool`.");
harmony.PatchAll();
Logger.LogInfo((object)"Plugin CollectCruiserItemCompany v0.3.0 is loaded!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.aoirint.CollectCruiserItemCompany";
public const string PLUGIN_NAME = "CollectCruiserItemCompany";
public const string PLUGIN_VERSION = "0.3.0";
}
}
namespace CollectCruiserItemCompany.Utils
{
internal static class FindItemUtils
{
[CompilerGenerated]
private sealed class <GetAllItems>d__2 : IEnumerable<GrabbableObject>, IEnumerable, IEnumerator<GrabbableObject>, IEnumerator, IDisposable
{
private int <>1__state;
private GrabbableObject <>2__current;
private int <>l__initialThreadId;
private GrabbableObject[] <>7__wrap1;
private int <>7__wrap2;
GrabbableObject IEnumerator<GrabbableObject>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <GetAllItems>d__2(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>7__wrap1 = null;
<>1__state = -2;
}
private bool MoveNext()
{
int num = <>1__state;
if (num != 0)
{
if (num != 1)
{
return false;
}
<>1__state = -1;
goto IL_006a;
}
<>1__state = -1;
GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>() ?? throw new Exception("Failed to find GrabbableObject objects.");
<>7__wrap1 = array;
<>7__wrap2 = 0;
goto IL_0078;
IL_006a:
<>7__wrap2++;
goto IL_0078;
IL_0078:
if (<>7__wrap2 < <>7__wrap1.Length)
{
GrabbableObject val = <>7__wrap1[<>7__wrap2];
if (!((Object)(object)val == (Object)null))
{
<>2__current = val;
<>1__state = 1;
return true;
}
goto IL_006a;
}
<>7__wrap1 = null;
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();
}
[DebuggerHidden]
IEnumerator<GrabbableObject> IEnumerable<GrabbableObject>.GetEnumerator()
{
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
return this;
}
return new <GetAllItems>d__2(0);
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<GrabbableObject>)this).GetEnumerator();
}
}
[CompilerGenerated]
private sealed class <GetAllItemsInCruiserInternal>d__3 : IEnumerable<GrabbableObject>, IEnumerable, IEnumerator<GrabbableObject>, IEnumerator, IDisposable
{
private int <>1__state;
private GrabbableObject <>2__current;
private int <>l__initialThreadId;
private string commaSeparatedExclusionListString;
public string <>3__commaSeparatedExclusionListString;
private Transform <elevatorTransform>5__2;
private Transform <shipTransform>5__3;
private Transform[] <vehicleTransforms>5__4;
private string[] <exclusionList>5__5;
private IEnumerator<GrabbableObject> <>7__wrap5;
private GrabbableObject <item>5__7;
private string <itemName>5__8;
private Transform[] <>7__wrap8;
private int <>7__wrap9;
GrabbableObject IEnumerator<GrabbableObject>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <GetAllItemsInCruiserInternal>d__3(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 1)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<elevatorTransform>5__2 = null;
<shipTransform>5__3 = null;
<vehicleTransforms>5__4 = null;
<exclusionList>5__5 = null;
<>7__wrap5 = null;
<item>5__7 = null;
<itemName>5__8 = null;
<>7__wrap8 = null;
<>1__state = -2;
}
private bool MoveNext()
{
try
{
int num = <>1__state;
if (num != 0)
{
if (num != 1)
{
return false;
}
<>1__state = -3;
goto IL_041b;
}
<>1__state = -1;
StartOfRound val = StartOfRound.Instance ?? throw new Exception("StartOfRound.Instance is null.");
<elevatorTransform>5__2 = val.elevatorTransform ?? throw new Exception("StartOfRound.Instance.elevatorTransform is null.");
<shipTransform>5__3 = ShipUtils.GetShipTransform() ?? throw new Exception("Ship transform is null.");
<vehicleTransforms>5__4 = ShipUtils.GetVehicleTransforms() ?? throw new Exception("Vehicle transforms is null.");
<exclusionList>5__5 = (from name in commaSeparatedExclusionListString.Split(',')
select name.Trim().ToLower() into name
where !string.IsNullOrEmpty(name)
select name).ToArray();
Logger.LogInfo((object)("Exclusion list: " + string.Join(", ", <exclusionList>5__5)));
IEnumerable<GrabbableObject> allItems = GetAllItems();
<>7__wrap5 = allItems.GetEnumerator();
<>1__state = -3;
goto IL_046b;
IL_041b:
<>7__wrap9++;
goto IL_0429;
IL_0429:
if (<>7__wrap9 < <>7__wrap8.Length)
{
Transform val2 = <>7__wrap8[<>7__wrap9];
if (!((Object)(object)val2 == (Object)null) && ((Component)<item>5__7).transform.IsChildOf(val2))
{
Logger.LogDebug((object)("Take item. itemName=" + <itemName>5__8 + " vehicleParent=" + ((Object)val2).name));
<>2__current = <item>5__7;
<>1__state = 1;
return true;
}
goto IL_041b;
}
<>7__wrap8 = null;
Logger.LogDebug((object)("Skipping item because it is outside cruiser. itemName=" + <itemName>5__8));
<itemName>5__8 = null;
<item>5__7 = null;
goto IL_046b;
IL_046b:
while (true)
{
if (<>7__wrap5.MoveNext())
{
<item>5__7 = <>7__wrap5.Current;
Item itemProperties = <item>5__7.itemProperties;
if ((Object)(object)itemProperties == (Object)null)
{
Logger.LogError((object)("Skipping item because itemProperties is null. name=" + ((Object)<item>5__7).name));
continue;
}
<itemName>5__8 = itemProperties.itemName;
bool isInShipRoom = <item>5__7.isInShipRoom;
bool isInElevator = <item>5__7.isInElevator;
bool isHeld = <item>5__7.isHeld;
bool isHeldByEnemy = <item>5__7.isHeldByEnemy;
bool isPocketed = <item>5__7.isPocketed;
Transform parent = ((Component)<item>5__7).transform.parent;
string text = ((parent != null) ? ((Object)parent).name : null) ?? "null";
Logger.LogDebug((object)("Checking item. itemName=" + <itemName>5__8 + $" isInShipRoom={isInShipRoom}" + $" isInElevator={isInElevator}" + $" isPocketed={isPocketed}" + $" isHeld={isHeld}" + $" isHeldByEnemy={isHeldByEnemy}" + " parent=" + text));
if (isInShipRoom)
{
Logger.LogDebug((object)("Skipping item because it is in ship room. itemName=" + <itemName>5__8));
continue;
}
if (isHeld)
{
Logger.LogDebug((object)("Skipping item because it is held. itemName=" + <itemName>5__8));
continue;
}
if (isHeldByEnemy)
{
Logger.LogDebug((object)("Skipping item because it is held by enemy. itemName=" + <itemName>5__8));
continue;
}
if (<exclusionList>5__5.Contains(<itemName>5__8.ToLower()))
{
Logger.LogDebug((object)("Skipping item because it is in the exclusion list. itemName=" + <itemName>5__8));
continue;
}
if (((Component)<item>5__7).transform.IsChildOf(<elevatorTransform>5__2))
{
Logger.LogDebug((object)("Skipping item because it is on elevator. itemName=" + <itemName>5__8));
continue;
}
if (!((Component)<item>5__7).transform.IsChildOf(<shipTransform>5__3))
{
break;
}
Logger.LogDebug((object)("Skipping item because it is on ship. itemName=" + <itemName>5__8));
continue;
}
<>m__Finally1();
<>7__wrap5 = null;
return false;
}
<>7__wrap8 = <vehicleTransforms>5__4;
<>7__wrap9 = 0;
goto IL_0429;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<>7__wrap5 != null)
{
<>7__wrap5.Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<GrabbableObject> IEnumerable<GrabbableObject>.GetEnumerator()
{
<GetAllItemsInCruiserInternal>d__3 <GetAllItemsInCruiserInternal>d__;
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
<GetAllItemsInCruiserInternal>d__ = this;
}
else
{
<GetAllItemsInCruiserInternal>d__ = new <GetAllItemsInCruiserInternal>d__3(0);
}
<GetAllItemsInCruiserInternal>d__.commaSeparatedExclusionListString = <>3__commaSeparatedExclusionListString;
return <GetAllItemsInCruiserInternal>d__;
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<GrabbableObject>)this).GetEnumerator();
}
}
[CompilerGenerated]
private sealed class <GetAllScraps>d__5 : IEnumerable<GrabbableObject>, IEnumerable, IEnumerator<GrabbableObject>, IEnumerator, IDisposable
{
private int <>1__state;
private GrabbableObject <>2__current;
private int <>l__initialThreadId;
private IEnumerator<GrabbableObject> <>7__wrap1;
GrabbableObject IEnumerator<GrabbableObject>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <GetAllScraps>d__5(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 1)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<>7__wrap1 = null;
<>1__state = -2;
}
private bool MoveNext()
{
try
{
switch (<>1__state)
{
default:
return false;
case 0:
{
<>1__state = -1;
string text = CollectCruiserItemCompany.ExclusionListConfig?.Value ?? "";
string text2 = CollectCruiserItemCompany.ScrapExclusionListConfig?.Value ?? "";
IEnumerable<GrabbableObject> allItemsInCruiserInternal = GetAllItemsInCruiserInternal(string.Join(",", text, text2));
<>7__wrap1 = allItemsInCruiserInternal.GetEnumerator();
<>1__state = -3;
break;
}
case 1:
<>1__state = -3;
break;
}
while (<>7__wrap1.MoveNext())
{
GrabbableObject current = <>7__wrap1.Current;
Item itemProperties = current.itemProperties;
if (!((Object)(object)itemProperties == (Object)null) && itemProperties.isScrap)
{
<>2__current = current;
<>1__state = 1;
return true;
}
}
<>m__Finally1();
<>7__wrap1 = null;
return false;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<>7__wrap1 != null)
{
<>7__wrap1.Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<GrabbableObject> IEnumerable<GrabbableObject>.GetEnumerator()
{
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
return this;
}
return new <GetAllScraps>d__5(0);
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<GrabbableObject>)this).GetEnumerator();
}
}
[CompilerGenerated]
private sealed class <GetAllTools>d__6 : IEnumerable<GrabbableObject>, IEnumerable, IEnumerator<GrabbableObject>, IEnumerator, IDisposable
{
private int <>1__state;
private GrabbableObject <>2__current;
private int <>l__initialThreadId;
private IEnumerator<GrabbableObject> <>7__wrap1;
GrabbableObject IEnumerator<GrabbableObject>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <GetAllTools>d__6(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 1)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<>7__wrap1 = null;
<>1__state = -2;
}
private bool MoveNext()
{
try
{
switch (<>1__state)
{
default:
return false;
case 0:
{
<>1__state = -1;
string text = CollectCruiserItemCompany.ExclusionListConfig?.Value ?? "";
string text2 = CollectCruiserItemCompany.ToolExclusionListConfig?.Value ?? "";
IEnumerable<GrabbableObject> allItemsInCruiserInternal = GetAllItemsInCruiserInternal(string.Join(",", text, text2));
<>7__wrap1 = allItemsInCruiserInternal.GetEnumerator();
<>1__state = -3;
break;
}
case 1:
<>1__state = -3;
break;
}
while (<>7__wrap1.MoveNext())
{
GrabbableObject current = <>7__wrap1.Current;
Item itemProperties = current.itemProperties;
if (!((Object)(object)itemProperties == (Object)null) && !itemProperties.isScrap)
{
<>2__current = current;
<>1__state = 1;
return true;
}
}
<>m__Finally1();
<>7__wrap1 = null;
return false;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<>7__wrap1 != null)
{
<>7__wrap1.Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<GrabbableObject> IEnumerable<GrabbableObject>.GetEnumerator()
{
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
return this;
}
return new <GetAllTools>d__6(0);
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<GrabbableObject>)this).GetEnumerator();
}
}
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
[IteratorStateMachine(typeof(<GetAllItems>d__2))]
internal static IEnumerable<GrabbableObject> GetAllItems()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <GetAllItems>d__2(-2);
}
[IteratorStateMachine(typeof(<GetAllItemsInCruiserInternal>d__3))]
internal static IEnumerable<GrabbableObject> GetAllItemsInCruiserInternal(string commaSeparatedExclusionListString)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <GetAllItemsInCruiserInternal>d__3(-2)
{
<>3__commaSeparatedExclusionListString = commaSeparatedExclusionListString
};
}
internal static IEnumerable<GrabbableObject> GetAllItemsInCruiser()
{
return GetAllItemsInCruiserInternal(CollectCruiserItemCompany.ExclusionListConfig?.Value ?? "");
}
[IteratorStateMachine(typeof(<GetAllScraps>d__5))]
internal static IEnumerable<GrabbableObject> GetAllScraps()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <GetAllScraps>d__5(-2);
}
[IteratorStateMachine(typeof(<GetAllTools>d__6))]
internal static IEnumerable<GrabbableObject> GetAllTools()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <GetAllTools>d__6(-2);
}
}
internal static class KeywordUtils
{
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
internal static bool IsCollectCommand(string keyword)
{
keyword = keyword.ToLower();
switch (keyword)
{
case "collect":
case "colect":
case "collec":
return true;
default:
return false;
}
}
internal static bool IsScrapArgument(string keyword)
{
keyword = keyword.ToLower();
if (((keyword.Length > 0) ? keyword.Substring(0, 1) : "") == "s")
{
return true;
}
return false;
}
internal static bool IsToolArgument(string keyword)
{
keyword = keyword.ToLower();
if (((keyword.Length > 0) ? keyword.Substring(0, 1) : "") == "t")
{
return true;
}
return false;
}
internal static bool IsAllArgument(string keyword)
{
keyword = keyword.ToLower();
if (((keyword.Length > 0) ? keyword.Substring(0, 1) : "") == "a")
{
return true;
}
return false;
}
}
internal static class NetworkBehaviourUtils
{
private static CollectionNetworkBehaviour? cachedCollectionNetworkBehaviour;
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
public static CollectionNetworkBehaviour? GetCollectionNetworkBehaviour()
{
if ((Object)(object)cachedCollectionNetworkBehaviour != (Object)null)
{
return cachedCollectionNetworkBehaviour;
}
StartOfRound instance = StartOfRound.Instance;
if ((Object)(object)instance == (Object)null)
{
Logger.LogError((object)"StartOfRound.Instance is null.");
return null;
}
CollectionNetworkBehaviour component = ((Component)instance).GetComponent<CollectionNetworkBehaviour>();
if ((Object)(object)component == (Object)null)
{
Logger.LogError((object)"CollectionNetworkBehaviour component not found on StartOfRound instance.");
return null;
}
cachedCollectionNetworkBehaviour = component;
return component;
}
}
internal static class NetworkUtils
{
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
public static bool IsServer()
{
NetworkManager singleton = NetworkManager.Singleton;
if ((Object)(object)singleton == (Object)null)
{
Logger.LogError((object)"NetworkManager.Singleton is null.");
return false;
}
return singleton.IsServer;
}
public static bool IsHost()
{
NetworkManager singleton = NetworkManager.Singleton;
if ((Object)(object)singleton == (Object)null)
{
Logger.LogError((object)"NetworkManager.Singleton is null.");
return false;
}
return singleton.IsHost;
}
public static bool IsClient()
{
NetworkManager singleton = NetworkManager.Singleton;
if ((Object)(object)singleton == (Object)null)
{
Logger.LogError((object)"NetworkManager.Singleton is null.");
return false;
}
return singleton.IsClient;
}
}
internal static class PlayerUtils
{
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
internal static PlayerControllerB? GetLocalPlayer()
{
GameNetworkManager instance = GameNetworkManager.Instance;
if ((Object)(object)instance == (Object)null)
{
Logger.LogError((object)"GameNetworkManager.Instance is null.");
return null;
}
PlayerControllerB localPlayerController = instance.localPlayerController;
if ((Object)(object)localPlayerController == (Object)null)
{
Logger.LogError((object)"GameNetworkManager.Instance.localPlayerController is null.");
return null;
}
return localPlayerController;
}
}
internal static class RoundUtils
{
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
public static bool IsInOrbit()
{
StartOfRound instance = StartOfRound.Instance;
if ((Object)(object)instance == (Object)null)
{
Logger.LogError((object)"StartOfRound.Instance is null.");
return false;
}
if (!instance.inShipPhase)
{
return false;
}
return true;
}
public static bool IsFirstDay()
{
StartOfRound instance = StartOfRound.Instance;
if ((Object)(object)instance == (Object)null)
{
Logger.LogError((object)"StartOfRound.Instance is null.");
return false;
}
EndOfGameStats gameStats = instance.gameStats;
if (gameStats == null)
{
Logger.LogError((object)"StartOfRound.Instance.gameStats is null.");
return false;
}
int daysSpent = gameStats.daysSpent;
Logger.LogDebug((object)$"daysSpent={daysSpent}");
return daysSpent == 0;
}
public static bool IsSceneNameCompany(string sceneName)
{
Logger.LogDebug((object)("IsSceneNameCompany? sceneName=" + sceneName));
return sceneName == "CompanyBuilding";
}
public static bool IsRoutingToCompany()
{
StartOfRound instance = StartOfRound.Instance;
if ((Object)(object)instance == (Object)null)
{
Logger.LogError((object)"StartOfRound.Instance is null.");
return false;
}
SelectableLevel currentLevel = instance.currentLevel;
if ((Object)(object)currentLevel == (Object)null)
{
Logger.LogError((object)"StartOfRound.Instance.currentLevel is null.");
return false;
}
return IsSceneNameCompany(currentLevel.sceneName);
}
public static SelectableLevel? GetLevelById(int levelId)
{
StartOfRound instance = StartOfRound.Instance;
if ((Object)(object)instance == (Object)null)
{
Logger.LogError((object)"StartOfRound.Instance is null.");
return null;
}
SelectableLevel[] levels = instance.levels;
if (levels == null)
{
Logger.LogError((object)"StartOfRound.Instance.levels is null.");
return null;
}
SelectableLevel val = levels.ElementAtOrDefault(levelId);
if ((Object)(object)val == (Object)null)
{
Logger.LogError((object)$"Level not found. levelId={levelId}");
return null;
}
return val;
}
}
internal static class ShipUtils
{
private static GameObject? cachedShipObject;
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
public static GameObject? GetShipObject()
{
if ((Object)(object)cachedShipObject != (Object)null)
{
return cachedShipObject;
}
GameObject val = GameObject.Find("Environment/HangarShip");
if ((Object)(object)val == (Object)null)
{
Logger.LogError((object)"Failed to find ship object in scene.");
return null;
}
cachedShipObject = val;
return val;
}
public static Transform? GetShipTransform()
{
GameObject shipObject = GetShipObject();
if ((Object)(object)shipObject == (Object)null)
{
Logger.LogError((object)"Ship object is null. Cannot get transform.");
return null;
}
Transform transform = shipObject.transform;
if ((Object)(object)transform == (Object)null)
{
Logger.LogError((object)"Ship transform is null.");
return null;
}
return transform;
}
public static Transform? GetElevatorTransform()
{
StartOfRound instance = StartOfRound.Instance;
if ((Object)(object)instance == (Object)null)
{
Logger.LogError((object)"StartOfRound.Instance is null.");
return null;
}
Transform elevatorTransform = instance.elevatorTransform;
if ((Object)(object)elevatorTransform == (Object)null)
{
Logger.LogError((object)"StartOfRound.elevatorTransform is null.");
return null;
}
return elevatorTransform;
}
public static Bounds? GetShipBounds()
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
StartOfRound instance = StartOfRound.Instance;
if ((Object)(object)instance == (Object)null)
{
Logger.LogError((object)"StartOfRound.Instance is null.");
return null;
}
Collider shipBounds = instance.shipBounds;
if ((Object)(object)shipBounds == (Object)null)
{
Logger.LogError((object)"StartOfRound.shipBounds is null.");
return null;
}
return shipBounds.bounds;
}
public static Transform[]? GetVehicleTransforms()
{
VehicleController[] array = Object.FindObjectsOfType<VehicleController>();
if (array == null)
{
Logger.LogError((object)"Failed to find VehicleController objects.");
return null;
}
List<Transform> list = new List<Transform>();
VehicleController[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
Transform transform = ((Component)array2[i]).transform;
if ((Object)(object)transform == (Object)null)
{
Logger.LogError((object)"VehicleController.transform is null.");
return null;
}
list.Add(transform);
}
return list.ToArray();
}
public static Vector3? GetBaseSpawnPosition()
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
StartOfRound instance = StartOfRound.Instance;
if ((Object)(object)instance == (Object)null)
{
Logger.LogError((object)"StartOfRound.Instance is null.");
return null;
}
Transform[] playerSpawnPositions = instance.playerSpawnPositions;
if (playerSpawnPositions == null)
{
Logger.LogError((object)"StartOfRound.Instance.playerSpawnPositions is null.");
return null;
}
Transform val = playerSpawnPositions.ElementAtOrDefault(1);
if ((Object)(object)val == (Object)null)
{
Logger.LogError((object)"Player spawn position is null for ID 1.");
return null;
}
return val.position;
}
}
internal enum ClientTeleportMethod
{
Throw,
Place
}
internal static class TeleportItemUtils
{
[CompilerGenerated]
private sealed class <>c__DisplayClass4_0
{
public Vector3 localPosition;
public Random random;
public Func<GrabbableObject, Vector3> <>9__0;
internal Vector3 <TeleportItemsToShip>b__0(GrabbableObject offsetVector)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
return localPosition + new Vector3(((Random)(ref random)).NextFloat(-0.7f, 0.7f), 0.5f, 2f);
}
}
[CompilerGenerated]
private sealed class <>c__DisplayClass4_1
{
public Vector3[] positions;
internal Vector3 <TeleportItemsToShip>b__1(GrabbableObject item, int index)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
return item.GetItemFloorPosition(positions[index]);
}
}
[CompilerGenerated]
private sealed class <TeleportItemsToShip>d__4 : IEnumerable<GrabbableObject>, IEnumerable, IEnumerator<GrabbableObject>, IEnumerator, IDisposable
{
private int <>1__state;
private GrabbableObject <>2__current;
private int <>l__initialThreadId;
private Vector3 localPosition;
public Vector3 <>3__localPosition;
private IEnumerable<GrabbableObject> items;
public IEnumerable<GrabbableObject> <>3__items;
private <>c__DisplayClass4_0 <>8__1;
private Transform newParentTransform;
public Transform <>3__newParentTransform;
private <>c__DisplayClass4_1 <>8__2;
private PlayerControllerB localPlayer;
public PlayerControllerB <>3__localPlayer;
private IEnumerator<List<GrabbableObject>> <>7__wrap1;
private Vector3[] <worldNewItemPositions>5__3;
private IEnumerator<(GrabbableObject item, int index)> <>7__wrap3;
GrabbableObject IEnumerator<GrabbableObject>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <TeleportItemsToShip>d__4(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if ((uint)(num - -4) <= 1u || num == 1)
{
try
{
if (num == -4 || num == 1)
{
try
{
}
finally
{
<>m__Finally2();
}
}
}
finally
{
<>m__Finally1();
}
}
<>8__1 = null;
<>8__2 = null;
<>7__wrap1 = null;
<worldNewItemPositions>5__3 = null;
<>7__wrap3 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0031: 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_005b: 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_01c4: 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)
//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_0243: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
//IL_0274: Unknown result type (might be due to invalid IL or missing references)
//IL_0280: Unknown result type (might be due to invalid IL or missing references)
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
try
{
int num = <>1__state;
if (num != 0)
{
if (num != 1)
{
return false;
}
<>1__state = -4;
goto IL_02f4;
}
<>1__state = -1;
<>8__1 = new <>c__DisplayClass4_0();
<>8__1.localPosition = localPosition;
uint num2 = BitConverter.ToUInt32(Guid.NewGuid().ToByteArray(), 0);
if (num2 == 0)
{
num2 = 1u;
}
<>8__1.random = new Random(num2);
<>7__wrap1 = IEnumerableExtensions.Chunk(items, 20).GetEnumerator();
<>1__state = -3;
goto IL_031f;
IL_031f:
if (<>7__wrap1.MoveNext())
{
List<GrabbableObject> current = <>7__wrap1.Current;
<>8__2 = new <>c__DisplayClass4_1();
current.Count();
<>8__2.positions = current.Select((GrabbableObject offsetVector) => <>8__1.localPosition + new Vector3(((Random)(ref <>8__1.random)).NextFloat(-0.7f, 0.7f), 0.5f, 2f)).ToArray();
newParentTransform.TransformPoints((Span<Vector3>)<>8__2.positions);
<>8__2.positions = current.Select((GrabbableObject item, int index) => item.GetItemFloorPosition(<>8__2.positions[index])).ToArray();
<worldNewItemPositions>5__3 = <>8__2.positions.ToArray();
newParentTransform.InverseTransformPoints((Span<Vector3>)<>8__2.positions);
<>7__wrap3 = current.Select((GrabbableObject item, int index) => (item, index)).GetEnumerator();
<>1__state = -4;
goto IL_02f4;
}
<>m__Finally1();
<>7__wrap1 = null;
return false;
IL_02f4:
if (<>7__wrap3.MoveNext())
{
(GrabbableObject item, int index) current2 = <>7__wrap3.Current;
GrabbableObject item2 = current2.item;
int item3 = current2.index;
Vector3 position = ((Component)item2).transform.position;
Vector3 val = <>8__2.positions[item3];
Vector3 val2 = <worldNewItemPositions>5__3[item3];
Logger.LogInfo((object)("Teleporting item. name=" + ((Object)item2).name + $" worldOldItemPosition=({position.x:F2}, {position.y:F2}, {position.z:F2})" + $" localNewItemPosition=({val.x:F2}, {val.y:F2}, {val.z:F2})" + $" worldNewItemPosition=({val2.x:F2}, {val2.y:F2}, {val2.z:F2})"));
TeleportItemForOwnerInternal(item2, newParentTransform, val, localPlayer);
ThrowObjectClientRpc(localPlayer, droppedInElevator: true, droppedInShipRoom: true, val, NetworkObjectReference.op_Implicit(((NetworkBehaviour)item2).NetworkObject), -1);
<>2__current = item2;
<>1__state = 1;
return true;
}
<>m__Finally2();
<>7__wrap3 = null;
<>8__2 = null;
<worldNewItemPositions>5__3 = null;
goto IL_031f;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<>7__wrap1 != null)
{
<>7__wrap1.Dispose();
}
}
private void <>m__Finally2()
{
<>1__state = -3;
if (<>7__wrap3 != null)
{
<>7__wrap3.Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<GrabbableObject> IEnumerable<GrabbableObject>.GetEnumerator()
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
<TeleportItemsToShip>d__4 <TeleportItemsToShip>d__;
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
<TeleportItemsToShip>d__ = this;
}
else
{
<TeleportItemsToShip>d__ = new <TeleportItemsToShip>d__4(0);
}
<TeleportItemsToShip>d__.items = <>3__items;
<TeleportItemsToShip>d__.newParentTransform = <>3__newParentTransform;
<TeleportItemsToShip>d__.localPosition = <>3__localPosition;
<TeleportItemsToShip>d__.localPlayer = <>3__localPlayer;
return <TeleportItemsToShip>d__;
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<GrabbableObject>)this).GetEnumerator();
}
}
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
private static void ThrowObjectClientRpc(PlayerControllerB instance, bool droppedInElevator, bool droppedInShipRoom, Vector3 targetFloorPosition, NetworkObjectReference grabbedObject, int floorYRot)
{
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
MethodInfo methodInfo = AccessTools.Method(typeof(PlayerControllerB), "ThrowObjectClientRpc", (Type[])null, (Type[])null);
if (methodInfo == null)
{
Logger.LogError((object)"Could not find PlayerControllerB.ThrowObjectClientRpc method.");
return;
}
try
{
methodInfo.Invoke(instance, new object[5] { droppedInElevator, droppedInShipRoom, targetFloorPosition, grabbedObject, floorYRot });
}
catch (Exception arg)
{
Logger.LogError((object)$"Error invoking PlayerControllerB.ThrowObjectClientRpc: {arg}");
}
}
private static void TeleportItemForOwnerInternal(GrabbableObject item, Transform newParentTransform, Vector3 newLocalPosition, PlayerControllerB localPlayer)
{
//IL_0012: 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_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: 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_003c: Unknown result type (might be due to invalid IL or missing references)
((Component)item).transform.SetParent(newParentTransform);
((Component)item).transform.localPosition = newLocalPosition;
((Component)item).transform.rotation = Quaternion.identity;
item.fallTime = 0f;
item.startFallingPosition = newLocalPosition;
item.targetFloorPosition = newLocalPosition;
localPlayer.SetItemInElevator(true, true, item);
}
[IteratorStateMachine(typeof(<TeleportItemsToShip>d__4))]
internal static IEnumerable<GrabbableObject> TeleportItemsToShip(IEnumerable<GrabbableObject> items, Transform newParentTransform, Vector3 localPosition, PlayerControllerB localPlayer)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <TeleportItemsToShip>d__4(-2)
{
<>3__items = items,
<>3__newParentTransform = newParentTransform,
<>3__localPosition = localPosition,
<>3__localPlayer = localPlayer
};
}
}
internal static class TerminalUtils
{
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
public static TerminalNode CreateTerminalNode(string displayText, bool clearPreviousText)
{
TerminalNode obj = ScriptableObject.CreateInstance<TerminalNode>();
obj.displayText = displayText;
obj.clearPreviousText = clearPreviousText;
return obj;
}
}
}
namespace CollectCruiserItemCompany.Patches
{
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
[HarmonyPatch("Awake")]
[HarmonyPostfix]
public static void AwakePrefix(StartOfRound __instance)
{
if ((Object)(object)((Component)__instance).gameObject == (Object)null)
{
Logger.LogError((object)"StartOfRound.gameObject is null.");
}
else
{
((Component)__instance).gameObject.AddComponent<CollectionNetworkBehaviour>();
}
}
}
[HarmonyPatch(typeof(Terminal))]
internal class TerminalPatch
{
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
internal static string? RemovePunctuation(Terminal instance, string input)
{
MethodInfo methodInfo = AccessTools.Method(typeof(Terminal), "RemovePunctuation", (Type[])null, (Type[])null);
if (methodInfo == null)
{
Logger.LogError((object)"Could not find Terminal.RemovePunctuation method.");
return null;
}
try
{
return (methodInfo.Invoke(instance, new object[1] { input }) as string) ?? throw new Exception("Return value of Terminal.RemovePunctuation is not a string.");
}
catch (Exception arg)
{
Logger.LogError((object)$"Error invoking Terminal.RemovePunctuation: {arg}");
return null;
}
}
[HarmonyPatch("ParsePlayerSentence")]
[HarmonyPrefix]
public static bool ParsePlayerSentencePrefix(Terminal __instance, ref TerminalNode __result)
{
TerminalCommandManager terminalCommandManager = CollectCruiserItemCompany.TerminalCommandManager;
if (terminalCommandManager == null)
{
Logger.LogError((object)"TerminalCommandManager is null.");
return true;
}
TMP_InputField screenText = __instance.screenText;
if ((Object)(object)screenText == (Object)null)
{
Logger.LogError((object)"Terminal.screenText is null.");
return true;
}
int textAdded = __instance.textAdded;
string text = screenText.text;
text = text.Substring(text.Length - textAdded);
text = RemovePunctuation(__instance, text);
if (text == null)
{
Logger.LogError((object)"Failed to remove punctuation from terminal input.");
return true;
}
string[] args = text.Split(' ', StringSplitOptions.RemoveEmptyEntries);
TerminalNode val = terminalCommandManager.ParseCommand(args);
if ((Object)(object)val == (Object)null)
{
return true;
}
__result = val;
return false;
}
}
}
namespace CollectCruiserItemCompany.NetworkObjects
{
internal class CollectionNetworkBehaviour : NetworkBehaviour
{
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
[ServerRpc(RequireOwnership = false)]
public void CollectRequestServerRpc(CollectType collectType, ServerRpcParams rpcParams = default(ServerRpcParams))
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
if (!NetworkUtils.IsServer())
{
Logger.LogError((object)"CollectRequestServerRpc called on client. Ignoring.");
return;
}
Logger.LogInfo((object)"Received CollectRequestServerRpc from client.");
CollectCruiserItemManager collectCruiserItemManager = CollectCruiserItemCompany.CollectCruiserItemManager;
if (collectCruiserItemManager == null)
{
Logger.LogError((object)"CollectCruiserItemManager is null. Cannot process collect request.");
return;
}
bool flag = rpcParams.Receive.SenderClientId == 0;
Permission permission = CollectCruiserItemCompany.PermissionConfig?.Value ?? Permission.HostOnly;
Logger.LogDebug((object)$"Current permission setting: {permission}");
if (permission == Permission.HostOnly && !flag)
{
Logger.LogInfo((object)"Cruiser collection is requested but cancelled. Permission is HostOnly and sender is not the host.");
}
else
{
((MonoBehaviour)this).StartCoroutine(collectCruiserItemManager.CollectToShipCoroutine(collectType));
}
}
}
}
namespace CollectCruiserItemCompany.Managers
{
internal enum CollectType
{
All,
Scrap,
Tool
}
internal class CollectCruiserItemManager
{
[CompilerGenerated]
private sealed class <CollectToShipCoroutine>d__3 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public CollectCruiserItemManager <>4__this;
public CollectType collectType;
private IEnumerator <innerCoroutine>5__2;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <CollectToShipCoroutine>d__3(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<innerCoroutine>5__2 = null;
<>1__state = -2;
}
private bool MoveNext()
{
int num = <>1__state;
CollectCruiserItemManager collectCruiserItemManager = <>4__this;
if (num != 0)
{
if (num != 1)
{
return false;
}
<>1__state = -1;
}
else
{
<>1__state = -1;
if (!NetworkUtils.IsServer())
{
Logger.LogWarning((object)"CollectToShipCoroutine called on client. Ignoring.");
return false;
}
if (!collectCruiserItemManager.IsCruiserCollectionAllowed())
{
Logger.LogWarning((object)"Cruiser collection is not allowed in the current round state. Aborting collection.");
return false;
}
Logger.LogInfo((object)$"Starting CollectToShipCoroutine. collectType={collectType}.");
<innerCoroutine>5__2 = collectCruiserItemManager.CollectToShipCoroutineInternal(collectType);
}
bool flag;
try
{
flag = <innerCoroutine>5__2.MoveNext();
}
catch (Exception arg)
{
Logger.LogError((object)$"Exception in CollectToShipCoroutineInternal: {arg}");
return false;
}
if (flag)
{
<>2__current = <innerCoroutine>5__2.Current;
<>1__state = 1;
return true;
}
Logger.LogInfo((object)"Finished CollectToShipCoroutine.");
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();
}
}
[CompilerGenerated]
private sealed class <CollectToShipCoroutineInternal>d__4 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public CollectType collectType;
private IEnumerator<GrabbableObject> <>7__wrap1;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <CollectToShipCoroutineInternal>d__4(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 1)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<>7__wrap1 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Expected O, but got Unknown
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
try
{
switch (<>1__state)
{
default:
return false;
case 0:
{
<>1__state = -1;
Transform val = (StartOfRound.Instance ?? throw new Exception("StartOfRound.Instance is null.")).elevatorTransform ?? throw new Exception("StartOfRound.Instance.elevatorTransform is null.");
PlayerControllerB localPlayer = PlayerUtils.GetLocalPlayer() ?? throw new Exception("Local player is null.");
IEnumerable<GrabbableObject> items;
if (collectType == CollectType.All)
{
items = FindItemUtils.GetAllItemsInCruiser();
}
else if (collectType == CollectType.Scrap)
{
items = FindItemUtils.GetAllScraps();
}
else
{
if (collectType != CollectType.Tool)
{
throw new Exception($"Unknown CollectType: {collectType}");
}
items = FindItemUtils.GetAllTools();
}
Vector3 val2 = ShipUtils.GetBaseSpawnPosition() ?? throw new Exception("Base spawn position is null.");
Vector3 localPosition = val.InverseTransformPoint(val2);
<>7__wrap1 = TeleportItemUtils.TeleportItemsToShip(items, val, localPosition, localPlayer).GetEnumerator();
<>1__state = -3;
break;
}
case 1:
<>1__state = -3;
break;
}
if (<>7__wrap1.MoveNext())
{
_ = <>7__wrap1.Current;
<>2__current = (object)new WaitForSecondsRealtime(0.1f);
<>1__state = 1;
return true;
}
<>m__Finally1();
<>7__wrap1 = null;
return false;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<>7__wrap1 != null)
{
<>7__wrap1.Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
internal bool IsCruiserCollectionAllowed()
{
Logger.LogDebug((object)"Checking if cruiser collection is allowed.");
bool flag = RoundHelpers.IsLandedOnCompany();
bool flag2 = RoundHelpers.IsInFirstDayOrbitAndRoutingToCompany();
bool flag3 = RoundHelpers.IsInOrbitAndLastLandedOnCompanyAndRoutingToCompany();
Logger.LogDebug((object)("Flags:" + $" IsLandedOnCompany={flag}" + $" IsInFirstDayOrbitAndRoutingToCompany={flag2}" + $" isInOrbitAndLastLandedOnCompanyAndRoutingToCompany={flag3}"));
return flag || flag2 || flag3;
}
[IteratorStateMachine(typeof(<CollectToShipCoroutine>d__3))]
internal IEnumerator CollectToShipCoroutine(CollectType collectType)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <CollectToShipCoroutine>d__3(0)
{
<>4__this = this,
collectType = collectType
};
}
[IteratorStateMachine(typeof(<CollectToShipCoroutineInternal>d__4))]
internal IEnumerator CollectToShipCoroutineInternal(CollectType collectType)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <CollectToShipCoroutineInternal>d__4(0)
{
collectType = collectType
};
}
}
internal class LandingHistoryManager
{
private const int LANDING_HISTORY_SIZE = 1;
private List<string> landingEntries = new List<string>();
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
public bool AddLandingHistory(string sceneName)
{
if (string.IsNullOrEmpty(sceneName))
{
Logger.LogError((object)"Scene name is null or empty. Cannot add to landing history.");
return false;
}
landingEntries.Add(sceneName);
landingEntries = landingEntries.TakeLast(1).ToList();
Logger.LogDebug((object)("Updated landing history. landingEntries=" + string.Join(", ", landingEntries)));
return true;
}
public List<string> GetLandingHistory()
{
return landingEntries.ToList();
}
public bool ClearLandingHistory()
{
landingEntries.Clear();
return true;
}
}
internal class TerminalCommandManager
{
private ConfirmableCommand? waitingCommand;
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
internal static Command[] COMMANDS { get; } = new Command[4]
{
new CollectTypeCommand(CollectType.Scrap),
new CollectTypeCommand(CollectType.Tool),
new CollectTypeCommand(CollectType.All),
new HelpCommand()
};
internal TerminalNode? ParseCommand(string[] args)
{
if (waitingCommand != null)
{
ExecuteResult executeResult = waitingCommand.ExecuteConfirmation(args);
if (executeResult == null)
{
Logger.LogError((object)"ExecuteConfirmation returned null.");
Reset();
return CreateInvalidStateNode();
}
waitingCommand = executeResult.NextWaitingCommand;
return executeResult.TerminalNode;
}
Command[] cOMMANDS = COMMANDS;
foreach (Command command in cOMMANDS)
{
if (command.IsMatch(args))
{
ExecuteResult executeResult2 = command.Execute(args);
if (executeResult2 == null)
{
Logger.LogError((object)"Execute returned null.");
Reset();
return CreateInvalidStateNode();
}
waitingCommand = executeResult2.NextWaitingCommand;
return executeResult2.TerminalNode;
}
}
return null;
}
internal void Reset()
{
Command[] cOMMANDS = COMMANDS;
for (int i = 0; i < cOMMANDS.Length; i++)
{
cOMMANDS[i].Reset();
}
waitingCommand = null;
}
internal TerminalNode CreateInvalidStateNode()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Invalid state.");
return TerminalUtils.CreateTerminalNode(stringBuilder.ToString(), clearPreviousText: false);
}
}
}
namespace CollectCruiserItemCompany.Helpers
{
internal static class LandingHistoryHelpers
{
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
public static bool AddLandingHistory(string sceneName)
{
LandingHistoryManager landingHistoryManager = CollectCruiserItemCompany.LandingHistoryManager;
if (landingHistoryManager == null)
{
Logger.LogError((object)"LandingHistoryManager is null.");
return false;
}
Logger.LogDebug((object)("Adding landing history. sceneName=" + sceneName));
if (!landingHistoryManager.AddLandingHistory(sceneName))
{
Logger.LogError((object)("Failed to add landing history. sceneName=" + sceneName));
return false;
}
Logger.LogDebug((object)("Added landing history. sceneName=" + sceneName));
return true;
}
public static bool ClearLandingHistory()
{
LandingHistoryManager landingHistoryManager = CollectCruiserItemCompany.LandingHistoryManager;
if (landingHistoryManager == null)
{
Logger.LogError((object)"LandingHistoryManager is null.");
return false;
}
Logger.LogDebug((object)"Clearing landing history.");
if (!landingHistoryManager.ClearLandingHistory())
{
Logger.LogError((object)"Failed to clear landing history.");
return false;
}
Logger.LogDebug((object)"Cleared landing history.");
return true;
}
public static bool IsLastLandedOnCompany()
{
LandingHistoryManager landingHistoryManager = CollectCruiserItemCompany.LandingHistoryManager;
if (landingHistoryManager == null)
{
Logger.LogError((object)"LandingHistoryManager is null.");
return false;
}
List<string> landingHistory = landingHistoryManager.GetLandingHistory();
if (landingHistory == null)
{
Logger.LogError((object)"Landing history is null.");
return false;
}
string text = landingHistory.LastOrDefault();
if (text == null)
{
Logger.LogDebug((object)"Last landed scene name is null.");
return false;
}
if (!RoundUtils.IsSceneNameCompany(text))
{
Logger.LogDebug((object)"Last landed scene is not company.");
return false;
}
return true;
}
}
internal static class RoundHelpers
{
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
public static bool IsInFirstDayOrbit()
{
if (!RoundUtils.IsInOrbit())
{
Logger.LogDebug((object)"Not in orbit.");
return false;
}
if (!RoundUtils.IsFirstDay())
{
Logger.LogDebug((object)"Not first day.");
return false;
}
return true;
}
public static bool IsInFirstDayOrbitAndRoutingToCompany()
{
if (!IsInFirstDayOrbit())
{
Logger.LogDebug((object)"Not in first day orbit.");
return false;
}
if (!RoundUtils.IsRoutingToCompany())
{
Logger.LogDebug((object)"Not routing to company.");
return false;
}
return true;
}
public static bool IsLandedOnCompany()
{
if (RoundUtils.IsInOrbit())
{
Logger.LogDebug((object)"In orbit.");
return false;
}
if (!RoundUtils.IsRoutingToCompany())
{
Logger.LogDebug((object)"Not routing to company.");
return false;
}
return true;
}
public static bool IsInOrbitAndLastLandedOnCompanyAndRoutingToCompany()
{
if (!RoundUtils.IsInOrbit())
{
Logger.LogDebug((object)"Not in orbit.");
return false;
}
if (!LandingHistoryHelpers.IsLastLandedOnCompany())
{
Logger.LogDebug((object)"Last landed level is not company.");
return false;
}
if (!RoundUtils.IsRoutingToCompany())
{
Logger.LogDebug((object)"Not routing to company.");
return false;
}
return true;
}
}
}
namespace CollectCruiserItemCompany.Extensions
{
internal static class IEnumerableExtensions
{
[CompilerGenerated]
private sealed class <Chunk>d__0<T> : IEnumerable<List<T>>, IEnumerable, IEnumerator<List<T>>, IEnumerator, IDisposable
{
private int <>1__state;
private List<T> <>2__current;
private int <>l__initialThreadId;
private int size;
public int <>3__size;
private IEnumerable<T> source;
public IEnumerable<T> <>3__source;
private IEnumerator<T> <e>5__2;
List<T> IEnumerator<List<T>>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <Chunk>d__0(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 1)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<e>5__2 = null;
<>1__state = -2;
}
private bool MoveNext()
{
bool result;
try
{
switch (<>1__state)
{
default:
result = false;
goto end_IL_0000;
case 0:
<>1__state = -1;
if (size <= 0)
{
throw new ArgumentOutOfRangeException("size", "Size must be greater than 0.");
}
<e>5__2 = source.GetEnumerator();
<>1__state = -3;
break;
case 1:
<>1__state = -3;
break;
}
if (<e>5__2.MoveNext())
{
List<T> list = new List<T>(size) { <e>5__2.Current };
while (list.Count < size && <e>5__2.MoveNext())
{
list.Add(<e>5__2.Current);
}
<>2__current = list;
<>1__state = 1;
result = true;
}
else
{
result = false;
<>m__Finally1();
}
end_IL_0000:;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
return result;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<e>5__2 != null)
{
<e>5__2.Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<List<T>> IEnumerable<List<T>>.GetEnumerator()
{
<Chunk>d__0<T> <Chunk>d__;
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
<Chunk>d__ = this;
}
else
{
<Chunk>d__ = new <Chunk>d__0<T>(0);
}
<Chunk>d__.source = <>3__source;
<Chunk>d__.size = <>3__size;
return <Chunk>d__;
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<List<T>>)this).GetEnumerator();
}
}
[IteratorStateMachine(typeof(<Chunk>d__0<>))]
public static IEnumerable<List<T>> Chunk<T>(this IEnumerable<T> source, int size)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <Chunk>d__0<T>(-2)
{
<>3__source = source,
<>3__size = size
};
}
}
}
namespace CollectCruiserItemCompany.Commands
{
internal class CollectTypeCommand : ConfirmableCommand
{
internal readonly CollectType CollectType;
internal CollectTypeCommand(CollectType collectType)
{
CollectType = collectType;
}
internal override bool IsMatch(string[] args)
{
args = args.Select((string arg) => arg.ToLower()).ToArray();
if (args.Length < 2)
{
return false;
}
string keyword = args[0];
string keyword2 = args[1];
if (!KeywordUtils.IsCollectCommand(keyword))
{
return false;
}
if (CollectType == CollectType.All && KeywordUtils.IsAllArgument(keyword2))
{
return true;
}
if (CollectType == CollectType.Scrap && KeywordUtils.IsScrapArgument(keyword2))
{
return true;
}
if (CollectType == CollectType.Tool && KeywordUtils.IsToolArgument(keyword2))
{
return true;
}
return false;
}
internal override ExecuteResult? ExecuteCore(string[] args)
{
if (!CollectCruiserItemCompany.CollectCruiserItemManager.IsCruiserCollectionAllowed())
{
Command.Logger.LogInfo((object)"Cruiser collection is not allowed in the current round state. Cannot proceed with collection request.");
return new ExecuteResult(CreateCollectionRequestNotAllowedNode(), null);
}
StringBuilder stringBuilder = new StringBuilder();
if (CollectType == CollectType.All)
{
stringBuilder.AppendLine("You have requested to collect all items from the cruiser.");
}
else if (CollectType == CollectType.Scrap)
{
stringBuilder.AppendLine("You have requested to collect all scraps from the cruiser.");
}
else if (CollectType == CollectType.Tool)
{
stringBuilder.AppendLine("You have requested to collect all tools from the cruiser.");
}
stringBuilder.AppendLine();
stringBuilder.AppendLine("Please CONFIRM or DENY.");
return new ExecuteResult(TerminalUtils.CreateTerminalNode(stringBuilder.ToString(), clearPreviousText: true), this);
}
internal override ExecuteResult ExecuteConfirm()
{
//IL_005c: 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 (!CollectCruiserItemCompany.CollectCruiserItemManager.IsCruiserCollectionAllowed())
{
Command.Logger.LogInfo((object)"Cruiser collection is not allowed in the current round state. Cannot proceed with collection request.");
return new ExecuteResult(CreateCollectionRequestNotAllowedNode(), null);
}
CollectionNetworkBehaviour collectionNetworkBehaviour = NetworkBehaviourUtils.GetCollectionNetworkBehaviour();
if ((Object)(object)collectionNetworkBehaviour == (Object)null)
{
Command.Logger.LogError((object)"CollectionNetworkBehaviour is null. Cannot send collect request.");
return new ExecuteResult(CreateCollectionRequestNotAllowedNode(), null);
}
collectionNetworkBehaviour.CollectRequestServerRpc(CollectType);
StringBuilder stringBuilder = new StringBuilder();
if (CollectType == CollectType.All)
{
stringBuilder.AppendLine("Starting collection of all items from the cruiser.");
}
else if (CollectType == CollectType.Scrap)
{
stringBuilder.AppendLine("Starting collection of all scraps from the cruiser.");
}
else
{
if (CollectType != CollectType.Tool)
{
Command.Logger.LogError((object)$"Unknown CollectType. CollectType={CollectType}");
return new ExecuteResult(CreateCollectionRequestFailedNode(), null);
}
stringBuilder.AppendLine("Starting collection of all tools from the cruiser.");
}
stringBuilder.AppendLine("");
stringBuilder.AppendLine("If the host player does not allow collection by clients, this request will be ignored.");
return new ExecuteResult(TerminalUtils.CreateTerminalNode(stringBuilder.ToString(), clearPreviousText: false), null);
}
internal override ExecuteResult ExecuteDeny()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Cancelled collection.");
return new ExecuteResult(TerminalUtils.CreateTerminalNode(stringBuilder.ToString(), clearPreviousText: false), null);
}
internal TerminalNode CreateCollectionRequestNotAllowedNode()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Collection is not allowed currently.");
return TerminalUtils.CreateTerminalNode(stringBuilder.ToString(), clearPreviousText: false);
}
internal TerminalNode CreateCollectionRequestFailedNode()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Failed to start collection.");
return TerminalUtils.CreateTerminalNode(stringBuilder.ToString(), clearPreviousText: false);
}
}
internal sealed class ExecuteResult
{
internal TerminalNode TerminalNode { get; }
internal ConfirmableCommand? NextWaitingCommand { get; }
internal ExecuteResult(TerminalNode terminalNode, ConfirmableCommand? nextWaitingCommand)
{
TerminalNode = terminalNode;
NextWaitingCommand = nextWaitingCommand;
}
}
internal abstract class Command
{
internal static ManualLogSource Logger => CollectCruiserItemCompany.Logger;
internal abstract bool IsMatch(string[] args);
internal ExecuteResult? Execute(string[] args)
{
ExecuteResult executeResult = ExecuteCore(args);
if (executeResult == null)
{
Logger.LogError((object)"ExecuteCore returned null.");
return null;
}
ExecuteCorePostfix(executeResult);
return executeResult;
}
internal abstract ExecuteResult? ExecuteCore(string[] args);
internal virtual void ExecuteCorePostfix(ExecuteResult result)
{
}
internal virtual void Reset()
{
}
}
internal abstract class ConfirmableCommand : Command
{
private TerminalNode? previousNode;
internal abstract ExecuteResult ExecuteConfirm();
internal abstract ExecuteResult ExecuteDeny();
internal virtual ExecuteResult? ExecuteInvalid()
{
if ((Object)(object)previousNode == (Object)null)
{
Command.Logger.LogError((object)"previousNode is null.");
return null;
}
return new ExecuteResult(previousNode, this);
}
internal ExecuteResult? ExecuteConfirmation(string[] args)
{
ExecuteResult executeResult = ExecuteConfirmationCore(args);
if (executeResult == null)
{
Command.Logger.LogError((object)"ExecuteConfirmationCore returned null.");
return null;
}
previousNode = executeResult.TerminalNode;
return executeResult;
}
internal ExecuteResult? ExecuteConfirmationCore(string[] args)
{
bool? flag = IsConfirmed(args);
if (flag.GetValueOrDefault())
{
return ExecuteConfirm();
}
if (flag == false)
{
return ExecuteDeny();
}
return ExecuteInvalid();
}
internal override void ExecuteCorePostfix(ExecuteResult result)
{
previousNode = result.TerminalNode;
}
internal override void Reset()
{
previousNode = null;
}
internal bool? IsConfirmed(string[] args)
{
args = args.Select((string arg) => arg.ToLower()).ToArray();
if (args.Length == 0)
{
return null;
}
string text = args[0];
string text2 = ((text.Length > 0) ? text.Substring(0, 1) : string.Empty);
if (text2 == "c")
{
return true;
}
if (text2 == "d")
{
return false;
}
return null;
}
}
internal class HelpCommand : Command
{
internal override bool IsMatch(string[] args)
{
args = args.Select((string arg) => arg.ToLower()).ToArray();
if (args.Length == 0)
{
return false;
}
if (!KeywordUtils.IsCollectCommand(args[0]))
{
return false;
}
return true;
}
internal override ExecuteResult? ExecuteCore(string[] args)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("CollectCruiserItemCompany v0.3.0");
stringBuilder.AppendLine();
stringBuilder.AppendLine(">COLLECT SCRAP");
stringBuilder.AppendLine("Collect all scraps from the cruiser into your ship.");
stringBuilder.AppendLine();
stringBuilder.AppendLine(">COLLECT TOOL");
stringBuilder.AppendLine("Collect all tools from the cruiser into your ship.");
stringBuilder.AppendLine();
stringBuilder.AppendLine(">COLLECT ALL");
stringBuilder.AppendLine("Collect all items from the cruiser into your ship.");
stringBuilder.AppendLine();
return new ExecuteResult(TerminalUtils.CreateTerminalNode(stringBuilder.ToString(), clearPreviousText: true), null);
}
}
}