using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Extras;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using SelfSortingStorage.Cupboard;
using SelfSortingStorage.NetcodePatcher;
using SelfSortingStorage.Utils;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("SelfSortingStorage")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ce8394e670cdb7ac0cb9927335fe66532ac15131")]
[assembly: AssemblyProduct("SelfSortingStorage")]
[assembly: AssemblyTitle("SelfSortingStorage")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: NetcodePatchedAssembly]
internal class <Module>
{
static <Module>()
{
}
}
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace SelfSortingStorage
{
internal class Config
{
public bool GeneralImprovements = false;
public readonly ConfigEntry<bool> enableSaving;
public readonly ConfigEntry<bool> allowScrapItems;
public readonly ConfigEntry<string> cupboardColor;
public readonly ConfigEntry<string> boxPosition;
public readonly ConfigEntry<bool> rescaleItems;
public readonly ConfigEntry<int> cupboardPrice;
public readonly ConfigEntry<bool> verboseLogging;
public Config(ConfigFile cfg)
{
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Expected O, but got Unknown
cfg.SaveOnConfigSet = false;
enableSaving = cfg.Bind<bool>("General", "Save items", true, "Allows stored items to be saved in the host player's current save file.");
allowScrapItems = cfg.Bind<bool>("General", "Allow Scrap items", true, "Allows scrap items to be stored in the Smart Cupboard.");
cupboardColor = cfg.Bind<string>("General", "Cupboard Color", "#000E57", "Customize the color of the storage, default color is dark blue.");
boxPosition = cfg.Bind<string>("Storage", "Box position", "R", new ConfigDescription("Adjust the position of the storage box, this can be 'L' for left or 'R' for right.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "L", "R" }), Array.Empty<object>()));
rescaleItems = cfg.Bind<bool>("Storage", "Rescale big items", true, "Big items will be rescaled when stored in the Smart Cupboard.");
cupboardPrice = cfg.Bind<int>("Shop", "Price", 20, "The price of the Smart Cupboard in the store.");
verboseLogging = cfg.Bind<bool>("Logs", "Verbose logs", false, "Enable more explicit logs in the console (for debug reasons).");
cfg.Save();
cfg.SaveOnConfigSet = true;
}
public void SetupCustomConfigs()
{
if (Chainloader.PluginInfos.ContainsKey("ShaosilGaming.GeneralImprovements"))
{
GeneralImprovements = true;
}
if (!GeneralImprovements)
{
Plugin.logger.LogError((object)"GeneralImprovements is not installed! The mod will still work but you may notice some item rotation issues.");
}
}
}
[BepInPlugin("zigzag.SelfSortingStorage", "SelfSortingStorage", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
private const string GUID = "zigzag.SelfSortingStorage";
private const string NAME = "SelfSortingStorage";
private const string VERSION = "1.0.0";
public static Plugin instance;
public static ManualLogSource logger;
private readonly Harmony harmony = new Harmony("zigzag.SelfSortingStorage");
internal const string VANILLA_NAME = "LethalCompanyGame";
internal static readonly List<(Func<PlayerControllerB, bool>, string)> spTriggerValidations = new List<(Func<PlayerControllerB, bool>, string)>();
internal static Config config { get; private set; } = null;
private void HarmonyPatchAll()
{
harmony.PatchAll();
}
private void Awake()
{
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
instance = this;
logger = ((BaseUnityPlugin)this).Logger;
string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "selfsortingstorage");
AssetBundle val = AssetBundle.LoadFromFile(text);
string text2 = "Assets/Data/_Misc/";
UnlockableItemDef val2 = val.LoadAsset<UnlockableItemDef>(text2 + "SSS_Module/SSSModuleUnlockable.asset");
config = new Config(((BaseUnityPlugin)this).Config);
config.SetupCustomConfigs();
Effects.SetupNetwork();
GameObject prefabObject = val2.unlockable.prefabObject;
Color color = default(Color);
ColorUtility.TryParseHtmlString(config.cupboardColor.Value, ref color);
((Renderer)prefabObject.GetComponent<MeshRenderer>()).materials[0].color = color;
if (config.boxPosition.Value == "R")
{
Transform val3 = prefabObject.transform.Find("ChutePosition/ActualPos");
Transform val4 = prefabObject.transform.Find("ChutePosition/Pos2");
if ((Object)(object)val3 != (Object)null && (Object)(object)val4 != (Object)null)
{
val3.position = val4.position;
val3.rotation = val4.rotation;
}
}
NetworkPrefabs.RegisterNetworkPrefab(prefabObject);
Utilities.FixMixerGroups(prefabObject);
Unlockables.RegisterUnlockable(val2, config.cupboardPrice.Value, (StoreType)1);
HarmonyPatchAll();
logger.LogInfo((object)"SelfSortingStorage is loaded !");
}
}
}
namespace SelfSortingStorage.Utils
{
internal class Effects
{
public class ItemNetworkReference
{
public NetworkObjectReference netObjectRef;
public int value;
public int save;
public ItemNetworkReference(NetworkObjectReference netObjectRef, int value, int save)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
this.netObjectRef = netObjectRef;
this.value = value;
this.save = save;
}
}
public static void SetupNetwork()
{
IEnumerable<Type> enumerable;
try
{
enumerable = Assembly.GetExecutingAssembly().GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
enumerable = ex.Types.Where((Type t) => t != null);
}
foreach (Type item in enumerable)
{
MethodInfo[] methods = item.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo[] array = methods;
foreach (MethodInfo methodInfo in array)
{
object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
if (customAttributes.Length != 0)
{
methodInfo.Invoke(null, null);
}
}
}
}
public static void Message(string title, string bottom, bool warning = false)
{
HUDManager.Instance.DisplayTip(title, bottom, warning, false, "LC_Tip1");
}
public static bool IsTriggerValid(PlayerControllerB player, out string notValidText)
{
notValidText = "[Nothing to store]";
if (player.isHoldingObject && !player.isGrabbingObjectAnimation && (Object)(object)player.currentlyHeldObjectServer != (Object)null)
{
if (!StartOfRound.Instance.inShipPhase && (StartOfRound.Instance.shipIsLeaving || !StartOfRound.Instance.shipHasLanded))
{
notValidText = "[Wait for ship to " + (StartOfRound.Instance.shipIsLeaving ? "leave" : "land") + "]";
return false;
}
if (player.currentlyHeldObjectServer.itemProperties.itemName == "Body")
{
notValidText = "[Bodies not allowed]";
return false;
}
if (player.currentlyHeldObjectServer.itemProperties.itemName == "Belt bag")
{
notValidText = "[Belt bags not compatible]";
return false;
}
if (!Plugin.config.allowScrapItems.Value && player.currentlyHeldObjectServer.itemProperties.isScrap)
{
notValidText = "[Scraps not allowed]";
return false;
}
foreach (var spTriggerValidation in Plugin.spTriggerValidations)
{
if (!spTriggerValidation.Item1(player))
{
notValidText = spTriggerValidation.Item2;
return false;
}
}
return true;
}
return false;
}
public static Item? GetItem(string id)
{
string[] idParts = id.Split('/');
if (idParts == null || idParts.Length <= 1)
{
return null;
}
if (idParts[0] == "LethalCompanyGame")
{
return ((IEnumerable<Item>)StartOfRound.Instance.allItemsList.itemsList).FirstOrDefault((Func<Item, bool>)((Item i) => i.itemName.Equals(idParts[1])));
}
return SmartMemory.CacheItems.GetValueOrDefault(id);
}
public static ItemNetworkReference SpawnItem(Item item, SmartCupboard cupboard, int spawnIndex, int value = 0, int save = 0)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
cupboard.GetPlacePosition(spawnIndex, out Transform parent, out Vector3 position, out Quaternion rotation);
GameObject val = Object.Instantiate<GameObject>(item.spawnPrefab, position, rotation, parent ?? StartOfRound.Instance.elevatorTransform);
GrabbableObject component = val.GetComponent<GrabbableObject>();
((Component)component).transform.rotation = Quaternion.Euler(component.itemProperties.restingRotation);
((Component)component).transform.localRotation = rotation;
component.fallTime = 1f;
component.hasHitGround = true;
component.reachedFloorTarget = true;
component.isInElevator = true;
component.isInShipRoom = true;
if (component.itemProperties.isScrap)
{
component.SetScrapValue(value);
}
if (component.itemProperties.saveItemVariable)
{
component.LoadItemSaveData(save);
}
((NetworkBehaviour)component).NetworkObject.Spawn(false);
return new ItemNetworkReference(NetworkObjectReference.op_Implicit(val.GetComponent<NetworkObject>()), value, component.itemProperties.saveItemVariable ? component.GetItemDataToSave() : save);
}
public static IEnumerator SyncItem(NetworkObjectReference itemRef, SmartCupboard cupboard, int spawnIndex, int value, int save)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
NetworkObject itemNetObject = null;
float startTime = Time.realtimeSinceStartup;
while (Time.realtimeSinceStartup - startTime < 8f && !((NetworkObjectReference)(ref itemRef)).TryGet(ref itemNetObject, (NetworkManager)null))
{
yield return (object)new WaitForSeconds(0.03f);
}
if ((Object)(object)itemNetObject == (Object)null)
{
Plugin.logger.LogError((object)"Error while trying to sync the item.");
yield break;
}
yield return (object)new WaitForEndOfFrame();
GrabbableObject component = ((Component)itemNetObject).GetComponent<GrabbableObject>();
if (!((NetworkBehaviour)component).IsServer)
{
cupboard.GetPlacePosition(spawnIndex, out Transform parent, out Vector3 _, out Quaternion _);
Vector3 targetPosition = Vector3.zero + component.itemProperties.verticalOffset * new Vector3(0f, 0f, 1f);
component.parentObject = null;
((Component)component).transform.SetParent(parent ?? StartOfRound.Instance.elevatorTransform, true);
component.startFallingPosition = ((Component)component).transform.localPosition;
((Component)component).transform.localPosition = targetPosition;
component.targetFloorPosition = targetPosition;
component.reachedFloorTarget = false;
component.hasHitGround = false;
}
component.isInElevator = true;
component.isInShipRoom = true;
component.fallTime = 0f;
if (component.itemProperties.isScrap)
{
component.SetScrapValue(value);
}
if (component.itemProperties.saveItemVariable)
{
component.LoadItemSaveData(save);
}
}
public static void RescaleItemIfTooBig(GrabbableObject component)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
BoxCollider component2 = ((Component)component).GetComponent<BoxCollider>();
if (!((Object)(object)component2 == (Object)null))
{
Bounds bounds = ((Collider)component2).bounds;
RescaleItemIfTooBig(component, ((Bounds)(ref bounds)).extents);
}
}
public static void RescaleItemIfTooBig(GrabbableObject component, Vector3 size)
{
//IL_0018: 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_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: 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_007d: Unknown result type (might be due to invalid IL or missing references)
BoxCollider component2 = ((Component)component).GetComponent<BoxCollider>();
if ((Object)(object)component2 == (Object)null)
{
return;
}
float num = size.x * 2f * (size.y * 2f) * (size.z * 2f);
if (num > 0.08f)
{
((Component)component).transform.localScale = ((num < 1f) ? (7f / num) : 20f) * ((Component)component).transform.localScale / 100f;
if (Plugin.config.verboseLogging.Value)
{
Plugin.logger.LogInfo((object)"Item was rescaled");
}
}
}
public static void ScaleBackItem(GrabbableObject component)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
((Component)component).transform.localScale = component.originalScale;
}
public static void OverrideOriginalScale(GrabbableObject component, Vector3 value)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
component.originalScale = value;
}
}
[HarmonyPatch(typeof(GameNetworkManager))]
internal class GameNetworkManagerPatch
{
[HarmonyPrefix]
[HarmonyPatch("SaveItemsInShip")]
public static void SaveSmartCupboard()
{
if (Plugin.config.enableSaving.Value && !((Object)(object)StartOfRound.Instance == (Object)null) && ((NetworkBehaviour)StartOfRound.Instance).IsServer)
{
string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
SavingModule.Save(currentSaveFileName);
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPostfix]
[HarmonyPatch("LoadShipGrabbableItems")]
public static void LoadSmartCupboard()
{
if (Plugin.config.enableSaving.Value && !((Object)(object)StartOfRound.Instance == (Object)null) && ((NetworkBehaviour)StartOfRound.Instance).IsServer)
{
string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
SavingModule.Load(currentSaveFileName);
}
}
[HarmonyPostfix]
[HarmonyPatch("ResetShip")]
public static void ResetSmartCupboard()
{
if ((Object)(object)StartOfRound.Instance == (Object)null || !((NetworkBehaviour)StartOfRound.Instance).IsServer || SmartMemory.Instance == null || SmartMemory.Instance.Size == 0)
{
return;
}
SmartCupboard smartCupboard = Object.FindObjectOfType<SmartCupboard>();
if (!((Object)(object)smartCupboard == (Object)null))
{
SmartMemory.Instance.ClearAll();
smartCupboard.placedItems.Clear();
if (Plugin.config.verboseLogging.Value)
{
Plugin.logger.LogInfo((object)"Smart Cupboard was reseted due to a game over.");
}
}
}
}
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatch
{
[HarmonyPostfix]
[HarmonyPatch("DespawnPropsAtEndOfRound")]
public static void ResetSmartCupboardIfAllDeads()
{
if ((Object)(object)RoundManager.Instance == (Object)null || !((NetworkBehaviour)RoundManager.Instance).IsServer || SmartMemory.Instance == null || SmartMemory.Instance.Size == 0 || (Object)(object)StartOfRound.Instance == (Object)null || !StartOfRound.Instance.allPlayersDead)
{
return;
}
int num = 0;
SmartCupboard smartCupboard = Object.FindObjectOfType<SmartCupboard>();
if ((Object)(object)smartCupboard == (Object)null)
{
return;
}
foreach (List<SmartMemory.Data> item in SmartMemory.Instance.ItemList)
{
foreach (SmartMemory.Data item2 in item)
{
if (item2.IsValid() && item2.Values[0] != 0)
{
item2.Id = "INVALID";
SmartMemory.Instance.Size--;
smartCupboard.placedItems.Remove(num);
}
num++;
}
}
if (Plugin.config.verboseLogging.Value)
{
Plugin.logger.LogInfo((object)"Smart Cupboard stored scraps were removed due to all players being dead.");
}
}
}
[HarmonyPatch(typeof(BeltBagItem))]
internal class BeltBagItemPatch
{
[HarmonyPrefix]
[HarmonyPatch("TryAddObjectToBagServerRpc")]
public static bool TryAddObjectToBagServerRpcPatch(BeltBagItem __instance, NetworkObjectReference netObjectRef, int playerWhoAdded)
{
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)StartOfRound.Instance == (Object)null || !((NetworkBehaviour)StartOfRound.Instance).IsServer || SmartMemory.Instance == null || SmartMemory.Instance.Size == 0)
{
return true;
}
SmartCupboard smartCupboard = Object.FindObjectOfType<SmartCupboard>();
if ((Object)(object)smartCupboard == (Object)null || smartCupboard.placedItems.Count == 0)
{
return true;
}
NetworkObject val = default(NetworkObject);
if (((NetworkObjectReference)(ref netObjectRef)).TryGet(ref val, (NetworkManager)null))
{
GrabbableObject component = ((Component)val).GetComponent<GrabbableObject>();
if ((Object)(object)component != (Object)null && !component.isHeld && !component.heldByPlayerOnServer && !component.isHeldByEnemy)
{
foreach (var (_, val3) in smartCupboard.placedItems)
{
if (component.itemProperties.itemName == val3.itemProperties.itemName && ((Component)component).transform.position == ((Component)val3).transform.position)
{
__instance.CancelAddObjectToBagClientRpc(playerWhoAdded);
return false;
}
}
}
}
return true;
}
}
}
namespace SelfSortingStorage.Cupboard
{
internal class SavingModule
{
public const string SaveKey = "SmartCupboardItems";
public static void Save(string saveFile)
{
if (!GetItems(out SmartMemory.Data[] items))
{
ES3.DeleteKey("SmartCupboardItems", saveFile);
return;
}
ES3.Save<string>("SmartCupboardItems", JsonConvert.SerializeObject((object)items), saveFile);
Plugin.logger.LogInfo((object)"SmartCupboard items saved.");
}
public static void Load(string saveFile)
{
if (!ES3.KeyExists("SmartCupboardItems", saveFile) || SmartMemory.Instance == null)
{
return;
}
SmartCupboard smartCupboard = Object.FindObjectOfType<SmartCupboard>();
string text = ES3.Load<string>("SmartCupboardItems", saveFile);
IEnumerable<SmartMemory.Data> enumerable = JsonConvert.DeserializeObject<IEnumerable<SmartMemory.Data>>(text);
if (enumerable == null || (Object)(object)smartCupboard == (Object)null)
{
Plugin.logger.LogError((object)"Items from SmartCupboard could not be loaded.");
return;
}
int num = 0;
SmartMemory.Data[] array = enumerable.ToArray();
SmartMemory.Data[] array2 = array;
foreach (SmartMemory.Data data in array2)
{
if (data.IsValid())
{
SmartMemory.Instance.StoreData(data, out var _, freeSpaceOnly: true);
}
else
{
SmartMemory.Instance.IgnoreSpaces.Add(num);
}
num++;
}
SmartMemory.Instance.IgnoreSpaces.Clear();
((MonoBehaviour)smartCupboard).StartCoroutine(smartCupboard.ReloadPlacedItems());
Plugin.logger.LogInfo((object)"SmartCupboard items loaded.");
}
private static bool GetItems(out SmartMemory.Data[]? items)
{
items = null;
if (SmartMemory.Instance == null || SmartMemory.Instance.Size == 0)
{
return false;
}
int count = SmartMemory.Instance.ItemList.Count;
List<SmartMemory.Data> list = new List<SmartMemory.Data>();
for (int i = 0; i < count; i++)
{
for (int j = 0; j < count; j++)
{
SmartMemory.Data item = SmartMemory.Instance.ItemList[i][j];
list.Add(item);
}
}
items = list.ToArray();
return true;
}
}
public class SmartCupboard : NetworkBehaviour
{
public NetworkObject parentObject;
public InteractTrigger triggerScript;
public Transform[] placePositions;
public SmartMemory memory = new SmartMemory();
public readonly Dictionary<int, GrabbableObject> placedItems = new Dictionary<int, GrabbableObject>();
private readonly List<int> indexToRemove = new List<int>();
private GrabbableObject? awaitingObject = null;
private bool responseOnAwaiting = false;
public override void OnNetworkSpawn()
{
((NetworkBehaviour)this).OnNetworkSpawn();
if (((NetworkBehaviour)this).IsServer)
{
memory.Initialize();
}
else
{
((MonoBehaviour)this).StartCoroutine(SyncCupboard());
}
}
public void Update()
{
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
//IL_0196: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
{
if (CheckIsFull(GameNetworkManager.Instance.localPlayerController))
{
triggerScript.interactable = false;
triggerScript.disabledHoverTip = "[Full!]";
}
else
{
triggerScript.interactable = Effects.IsTriggerValid(GameNetworkManager.Instance.localPlayerController, out string notValidText);
if (!triggerScript.interactable)
{
triggerScript.disabledHoverTip = notValidText;
}
}
if (!((NetworkBehaviour)this).IsServer && (Object)(object)awaitingObject != (Object)null && ((Object)(object)GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer != (Object)(object)awaitingObject))
{
responseOnAwaiting = false;
awaitingObject = null;
}
}
if (!((NetworkBehaviour)this).IsServer)
{
return;
}
foreach (var (num2, val2) in placedItems)
{
if (val2.isHeld || val2.isHeldByEnemy)
{
if (Plugin.config.rescaleItems.Value)
{
ScaleItemClientRpc(NetworkObjectReference.op_Implicit(((Component)val2).gameObject.GetComponent<NetworkObject>()), scaleMode: false);
}
SmartMemory.Data data = memory.RetrieveData(num2);
if (!memory.IsFull())
{
SetSizeClientRpc(memory.Size);
}
indexToRemove.Add(num2);
if (data != null && data.Quantity >= 1)
{
SpawnItem(data, num2, isStacked: true);
}
}
}
if (indexToRemove.Count == 0)
{
return;
}
foreach (int item in indexToRemove)
{
placedItems.Remove(item);
}
indexToRemove.Clear();
}
public static void AddTriggerValidation(Func<PlayerControllerB, bool> func, string notValidText)
{
Plugin.spTriggerValidations.Add((func, notValidText));
}
public IEnumerator ReloadPlacedItems()
{
yield return (object)new WaitForSeconds(1f);
int spawnIndex = 0;
float distanceSearch = 1f;
GrabbableObject[] array = Object.FindObjectsByType<GrabbableObject>((FindObjectsSortMode)0);
foreach (List<SmartMemory.Data> list in memory.ItemList)
{
foreach (SmartMemory.Data item in list)
{
if (item.IsValid())
{
for (int i = 0; i < array.Length; i++)
{
if (array[i].itemProperties.itemName == item.Id.Split('/')[1] && Vector3.Distance(placePositions[spawnIndex].position, ((Component)array[i]).transform.position) <= distanceSearch)
{
if (Plugin.config.rescaleItems.Value)
{
Effects.RescaleItemIfTooBig(array[i]);
}
placedItems[spawnIndex] = array[i];
}
}
}
spawnIndex++;
}
}
}
public void StoreObject(PlayerControllerB player)
{
if (!((Object)(object)player == (Object)null) && player.isHoldingObject && !player.isGrabbingObjectAnimation && !((Object)(object)player.currentlyHeldObjectServer == (Object)null))
{
StoreDataServerRpc(player.playerClientId);
player.DestroyItemInSlotAndSync(player.currentItemSlot);
}
}
public void GetPlacePosition(int spawnIndex, out Transform parent, out Vector3 position, out Quaternion rotation)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: 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_003a: Unknown result type (might be due to invalid IL or missing references)
parent = placePositions[spawnIndex];
position = parent.position;
rotation = parent.rotation * Quaternion.Euler(0f, 0f, 180f);
}
[ServerRpc(RequireOwnership = false)]
private void StoreDataServerRpc(ulong playerId)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: 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_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager == null || !networkManager.IsListening)
{
return;
}
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3359588108u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, playerId);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3359588108u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
{
return;
}
PlayerControllerB val3 = StartOfRound.Instance.allPlayerScripts[playerId];
if ((Object)(object)val3 == (Object)null)
{
return;
}
GrabbableObject currentlyHeldObjectServer = val3.currentlyHeldObjectServer;
if (!((Object)(object)currentlyHeldObjectServer == (Object)null))
{
SmartMemory.Data data = new SmartMemory.Data(currentlyHeldObjectServer);
int spawnIndex;
bool flag = memory.StoreData(data, out spawnIndex);
if (memory.IsFull())
{
SetSizeClientRpc(memory.Size);
}
GrabbableObject value;
if (flag)
{
SpawnItem(data, spawnIndex);
}
else if (placedItems.TryGetValue(spawnIndex, out value))
{
PlayDropSFXClientRpc(NetworkObjectReference.op_Implicit(((Component)value).gameObject.GetComponent<NetworkObject>()));
}
if (Plugin.config.verboseLogging.Value)
{
Plugin.logger.LogWarning((object)memory.ToString());
}
}
}
private void SpawnItem(SmartMemory.Data itemData, int spawnIndex, bool isStacked = false)
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
if (itemData.IsValid())
{
Item item = Effects.GetItem(itemData.Id);
if ((Object)(object)item != (Object)null)
{
Effects.ItemNetworkReference itemNetworkReference = Effects.SpawnItem(item, this, spawnIndex, itemData.Values[0], itemData.Saves[0]);
SyncItemClientRpc(itemNetworkReference.netObjectRef, itemNetworkReference.value, itemNetworkReference.save, spawnIndex, isStacked);
}
}
}
[ClientRpc]
private void SyncItemClientRpc(NetworkObjectReference itemRef, int value, int save, int spawnIndex, bool isStacked)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: 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_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: 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_011b: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(52998418u, val, (RpcDelivery)0);
((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkObjectReference>(ref itemRef, default(ForNetworkSerializable));
BytePacker.WriteValueBitPacked(val2, value);
BytePacker.WriteValueBitPacked(val2, save);
BytePacker.WriteValueBitPacked(val2, spawnIndex);
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref isStacked, default(ForPrimitives));
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 52998418u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
((MonoBehaviour)this).StartCoroutine(SyncItem(itemRef, value, save, spawnIndex, isStacked));
}
}
}
private IEnumerator SyncItem(NetworkObjectReference itemRef, int value, int save, int spawnIndex, bool isStacked)
{
//IL_000e: 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)
yield return Effects.SyncItem(itemRef, this, spawnIndex, value, save);
NetworkObject itemNetObject = default(NetworkObject);
if (!((NetworkObjectReference)(ref itemRef)).TryGet(ref itemNetObject, (NetworkManager)null))
{
yield break;
}
GrabbableObject component = ((Component)itemNetObject).GetComponent<GrabbableObject>();
if (!isStacked)
{
component.PlayDropSFX();
}
if (!((NetworkBehaviour)this).IsServer)
{
yield break;
}
placedItems[spawnIndex] = component;
if (Plugin.config.rescaleItems.Value)
{
BoxCollider collider = ((Component)component).GetComponent<BoxCollider>();
if (!((Object)(object)collider == (Object)null))
{
SmartCupboard smartCupboard = this;
NetworkObjectReference itemRef2 = itemRef;
Bounds bounds = ((Collider)collider).bounds;
smartCupboard.ScaleItemClientRpc(itemRef2, scaleMode: true, ((Bounds)(ref bounds)).extents);
}
}
}
[ClientRpc]
private void PlayDropSFXClientRpc(NetworkObjectReference itemRef)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: 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_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: 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)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(4245719167u, val, (RpcDelivery)0);
((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkObjectReference>(ref itemRef, default(ForNetworkSerializable));
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 4245719167u, val, (RpcDelivery)0);
}
NetworkObject val3 = default(NetworkObject);
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && ((NetworkObjectReference)(ref itemRef)).TryGet(ref val3, (NetworkManager)null))
{
((Component)val3).GetComponent<GrabbableObject>().PlayDropSFX();
}
}
}
[ClientRpc]
private void ScaleItemClientRpc(NetworkObjectReference itemRef, bool scaleMode, Vector3 size = default(Vector3), bool overrideOriginalScale = false, ClientRpcParams clientRpcParams = default(ClientRpcParams))
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: 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_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: 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_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(4123351311u, clientRpcParams, (RpcDelivery)0);
((FastBufferWriter)(ref val)).WriteValueSafe<NetworkObjectReference>(ref itemRef, default(ForNetworkSerializable));
((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref scaleMode, default(ForPrimitives));
((FastBufferWriter)(ref val)).WriteValueSafe(ref size);
((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref overrideOriginalScale, default(ForPrimitives));
((NetworkBehaviour)this).__endSendClientRpc(ref val, 4123351311u, clientRpcParams, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && Plugin.config.rescaleItems.Value)
{
((MonoBehaviour)this).StartCoroutine(ScaleItem(itemRef, scaleMode, size, overrideOriginalScale));
}
}
}
private IEnumerator ScaleItem(NetworkObjectReference itemRef, bool scaleMode, Vector3 size, bool overrideOriginalScale)
{
//IL_000e: 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_001c: 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)
NetworkObject itemNetObject = default(NetworkObject);
if (scaleMode)
{
NetworkObject itemNetObject2 = default(NetworkObject);
while (!((NetworkObjectReference)(ref itemRef)).TryGet(ref itemNetObject2, (NetworkManager)null))
{
yield return (object)new WaitForSeconds(0.03f);
}
GrabbableObject component = ((Component)itemNetObject2).GetComponent<GrabbableObject>();
while (component.originalScale == Vector3.zero)
{
yield return (object)new WaitForSeconds(0.03f);
}
if (!overrideOriginalScale)
{
Effects.RescaleItemIfTooBig(component, size);
}
else
{
Effects.OverrideOriginalScale(component, size);
}
}
else if (((NetworkObjectReference)(ref itemRef)).TryGet(ref itemNetObject, (NetworkManager)null))
{
Effects.ScaleBackItem(((Component)itemNetObject).GetComponent<GrabbableObject>());
}
}
private bool CheckIsFull(PlayerControllerB player)
{
if (!memory.IsFull())
{
return false;
}
if (!player.isHoldingObject || player.isGrabbingObjectAnimation || (Object)(object)player.currentlyHeldObjectServer == (Object)null)
{
return true;
}
if (((NetworkBehaviour)this).IsServer)
{
return ServerCheckingIsFull(player);
}
if (responseOnAwaiting)
{
return false;
}
if ((Object)(object)awaitingObject != (Object)null)
{
return true;
}
awaitingObject = player.currentlyHeldObjectServer;
AskServerCheckIsFullServerRpc(player.playerClientId, ((NetworkBehaviour)player).OwnerClientId);
return true;
}
[ServerRpc(RequireOwnership = false)]
private void AskServerCheckIsFullServerRpc(ulong playerId, ulong clientId)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: 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_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: 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_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3104039900u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, playerId);
BytePacker.WriteValueBitPacked(val2, clientId);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3104039900u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
PlayerControllerB val3 = StartOfRound.Instance.allPlayerScripts[playerId];
bool response = (Object)(object)val3 == (Object)null || (Object)(object)val3.currentlyHeldObjectServer == (Object)null || ServerCheckingIsFull(val3);
ClientRpcParams val4 = default(ClientRpcParams);
val4.Send = new ClientRpcSendParams
{
TargetClientIds = new ulong[1] { clientId }
};
ClientRpcParams clientRpcParams = val4;
ServerResponseCheckIsFullClientRpc(response, clientRpcParams);
}
}
}
private bool ServerCheckingIsFull(PlayerControllerB player)
{
foreach (var (_, val2) in placedItems)
{
if (player.currentlyHeldObjectServer.itemProperties.itemName == val2.itemProperties.itemName && ((Object)player.currentlyHeldObjectServer.itemProperties).name == ((Object)val2.itemProperties).name)
{
return false;
}
}
return true;
}
[ClientRpc]
private void ServerResponseCheckIsFullClientRpc(bool response, ClientRpcParams clientRpcParams = default(ClientRpcParams))
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: 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_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: 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)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(2155821034u, clientRpcParams, (RpcDelivery)0);
((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref response, default(ForPrimitives));
((NetworkBehaviour)this).__endSendClientRpc(ref val, 2155821034u, clientRpcParams, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !response)
{
responseOnAwaiting = true;
}
}
}
private IEnumerator SyncCupboard()
{
if (Plugin.config.verboseLogging.Value)
{
Plugin.logger.LogInfo((object)"Syncing Cupboard from host player");
}
while ((Object)(object)GameNetworkManager.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
{
yield return (object)new WaitForSeconds(0.03f);
}
SyncServerRpc(((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).OwnerClientId);
}
[ServerRpc(RequireOwnership = false)]
private void SyncServerRpc(ulong clientId)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: 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_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: 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)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: 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_01a3: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager == null || !networkManager.IsListening)
{
return;
}
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2989470694u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, clientId);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2989470694u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
{
return;
}
if (memory.IsFull())
{
SetSizeClientRpc(memory.Size);
}
if (placedItems.Count == 0 || !Plugin.config.rescaleItems.Value)
{
return;
}
ClientRpcParams val3 = default(ClientRpcParams);
val3.Send = new ClientRpcSendParams
{
TargetClientIds = new ulong[1] { clientId }
};
ClientRpcParams clientRpcParams = val3;
foreach (var (_, val5) in placedItems)
{
if (!val5.isHeld && !val5.isHeldByEnemy)
{
ScaleItemClientRpc(NetworkObjectReference.op_Implicit(((Component)val5).gameObject.GetComponent<NetworkObject>()), scaleMode: true, val5.originalScale, overrideOriginalScale: true, clientRpcParams);
}
}
}
[ClientRpc]
private void SetSizeClientRpc(int size)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: 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_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1820484504u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, size);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1820484504u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
memory.Size = size;
}
}
}
protected override void __initializeVariables()
{
((NetworkBehaviour)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_SmartCupboard()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Expected O, but got Unknown
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(3359588108u, new RpcReceiveHandler(__rpc_handler_3359588108));
NetworkManager.__rpc_func_table.Add(52998418u, new RpcReceiveHandler(__rpc_handler_52998418));
NetworkManager.__rpc_func_table.Add(4245719167u, new RpcReceiveHandler(__rpc_handler_4245719167));
NetworkManager.__rpc_func_table.Add(4123351311u, new RpcReceiveHandler(__rpc_handler_4123351311));
NetworkManager.__rpc_func_table.Add(3104039900u, new RpcReceiveHandler(__rpc_handler_3104039900));
NetworkManager.__rpc_func_table.Add(2155821034u, new RpcReceiveHandler(__rpc_handler_2155821034));
NetworkManager.__rpc_func_table.Add(2989470694u, new RpcReceiveHandler(__rpc_handler_2989470694));
NetworkManager.__rpc_func_table.Add(1820484504u, new RpcReceiveHandler(__rpc_handler_1820484504));
}
private static void __rpc_handler_3359588108(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0023: 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_0050: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
ulong playerId = default(ulong);
ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
target.__rpc_exec_stage = (__RpcExecStage)1;
((SmartCupboard)(object)target).StoreDataServerRpc(playerId);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_52998418(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: 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_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: 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_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: 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_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
NetworkObjectReference itemRef = default(NetworkObjectReference);
((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref itemRef, default(ForNetworkSerializable));
int value = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref value);
int save = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref save);
int spawnIndex = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref spawnIndex);
bool isStacked = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref isStacked, default(ForPrimitives));
target.__rpc_exec_stage = (__RpcExecStage)2;
((SmartCupboard)(object)target).SyncItemClientRpc(itemRef, value, save, spawnIndex, isStacked);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_4245719167(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: 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_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: 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)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
NetworkObjectReference itemRef = default(NetworkObjectReference);
((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref itemRef, default(ForNetworkSerializable));
target.__rpc_exec_stage = (__RpcExecStage)2;
((SmartCupboard)(object)target).PlayDropSFXClientRpc(itemRef);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_4123351311(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: 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_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: 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_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: 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_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
NetworkObjectReference itemRef = default(NetworkObjectReference);
((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref itemRef, default(ForNetworkSerializable));
bool scaleMode = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref scaleMode, default(ForPrimitives));
Vector3 size = default(Vector3);
((FastBufferReader)(ref reader)).ReadValueSafe(ref size);
bool overrideOriginalScale = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref overrideOriginalScale, default(ForPrimitives));
ClientRpcParams client = rpcParams.Client;
target.__rpc_exec_stage = (__RpcExecStage)2;
((SmartCupboard)(object)target).ScaleItemClientRpc(itemRef, scaleMode, size, overrideOriginalScale, client);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_3104039900(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: 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)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
ulong playerId = default(ulong);
ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
ulong clientId = default(ulong);
ByteUnpacker.ReadValueBitPacked(reader, ref clientId);
target.__rpc_exec_stage = (__RpcExecStage)1;
((SmartCupboard)(object)target).AskServerCheckIsFullServerRpc(playerId, clientId);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_2155821034(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: 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_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: 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_006c: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool response = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref response, default(ForPrimitives));
ClientRpcParams client = rpcParams.Client;
target.__rpc_exec_stage = (__RpcExecStage)2;
((SmartCupboard)(object)target).ServerResponseCheckIsFullClientRpc(response, client);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_2989470694(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0023: 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_0050: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
ulong clientId = default(ulong);
ByteUnpacker.ReadValueBitPacked(reader, ref clientId);
target.__rpc_exec_stage = (__RpcExecStage)1;
((SmartCupboard)(object)target).SyncServerRpc(clientId);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_1820484504(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0023: 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_0050: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
int sizeClientRpc = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref sizeClientRpc);
target.__rpc_exec_stage = (__RpcExecStage)2;
((SmartCupboard)(object)target).SetSizeClientRpc(sizeClientRpc);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
protected internal override string __getTypeName()
{
return "SmartCupboard";
}
}
public class SmartMemory
{
[Serializable]
public class Data
{
public string Id = "INVALID";
public List<int> Values = new List<int>();
public List<int> Saves = new List<int>();
public int Quantity = 1;
public Data()
{
}
public Data(GrabbableObject item)
{
Id = ConvertID(item.itemProperties);
Values.Add(item.itemProperties.isScrap ? item.scrapValue : 0);
Saves.Add(item.itemProperties.saveItemVariable ? item.GetItemDataToSave() : 0);
}
public bool IsValid()
{
return Id != "INVALID";
}
public void Update(Data data)
{
Id = data.Id;
Values.Clear();
Values.AddRange(data.Values);
Saves.Clear();
Saves.AddRange(data.Saves);
Quantity = data.Quantity;
}
private string ConvertID(Item sourceItem)
{
foreach (var (result, val2) in CacheItems)
{
if ((Object)(object)val2 == (Object)(object)sourceItem)
{
return result;
}
}
return "LethalCompanyGame/" + sourceItem.itemName;
}
public unsafe void NetworkerSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: 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_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: 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_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: 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)
serializer.SerializeValue(ref Id, false);
if (serializer.IsWriter)
{
FastBufferWriter fastBufferWriter = serializer.GetFastBufferWriter();
int count = Values.Count;
((FastBufferWriter)(ref fastBufferWriter)).WriteValueSafe<int>(ref count, default(ForPrimitives));
foreach (int value in Values)
{
int current = value;
((FastBufferWriter)(ref fastBufferWriter)).WriteValueSafe<int>(ref current, default(ForPrimitives));
}
count = Saves.Count;
((FastBufferWriter)(ref fastBufferWriter)).WriteValueSafe<int>(ref count, default(ForPrimitives));
foreach (int safe in Saves)
{
int current2 = safe;
((FastBufferWriter)(ref fastBufferWriter)).WriteValueSafe<int>(ref current2, default(ForPrimitives));
}
}
if (serializer.IsReader)
{
FastBufferReader fastBufferReader = serializer.GetFastBufferReader();
int num = default(int);
((FastBufferReader)(ref fastBufferReader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
int item = default(int);
for (int i = 0; i < num; i++)
{
((FastBufferReader)(ref fastBufferReader)).ReadValueSafe<int>(ref item, default(ForPrimitives));
Values.Add(item);
}
((FastBufferReader)(ref fastBufferReader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
int item2 = default(int);
for (int j = 0; j < num; j++)
{
((FastBufferReader)(ref fastBufferReader)).ReadValueSafe<int>(ref item2, default(ForPrimitives));
Saves.Add(item2);
}
}
((BufferSerializer<int>*)(&serializer))->SerializeValue<int>(ref Quantity, default(ForPrimitives));
}
}
public static SmartMemory? Instance;
public readonly int Capacity = 16;
public int Size = 0;
public readonly List<int> IgnoreSpaces = new List<int>();
public readonly List<List<Data>> ItemList = new List<List<Data>>(4);
public static readonly Dictionary<string, Item> CacheItems = new Dictionary<string, Item>();
public SmartMemory()
{
ClearAll(resetData: false);
}
public bool IsFull()
{
return Size == Capacity;
}
public void ClearAll(bool resetData = true)
{
if (resetData)
{
ItemList.ForEach(delegate(List<Data> x)
{
x.Clear();
});
ItemList.Clear();
Size = 0;
}
for (int i = 0; i < 4; i++)
{
List<Data> list = new List<Data>(4);
for (int j = 0; j < 4; j++)
{
list.Add(new Data());
}
ItemList.Add(list);
}
}
public void Initialize()
{
Instance = this;
foreach (ScrapItem scrapItem in Items.scrapItems)
{
CacheItems.TryAdd(scrapItem.modName + "/" + scrapItem.item.itemName, scrapItem.item);
}
foreach (ShopItem shopItem in Items.shopItems)
{
CacheItems.TryAdd(shopItem.modName + "/" + shopItem.item.itemName, shopItem.item);
}
foreach (PlainItem plainItem in Items.plainItems)
{
CacheItems.TryAdd(plainItem.modName + "/" + plainItem.item.itemName, plainItem.item);
}
}
public bool StoreData(Data data, out int spawnIndex, bool freeSpaceOnly = false)
{
if (Plugin.config.verboseLogging.Value)
{
Plugin.logger.LogWarning((object)ToString());
Plugin.logger.LogWarning((object)("Storing: " + data.Id));
}
spawnIndex = 0;
int lastFreeSpaceId = -1;
foreach (List<Data> item in ItemList)
{
foreach (Data item2 in item)
{
if (!item2.IsValid() && lastFreeSpaceId == -1)
{
lastFreeSpaceId = spawnIndex;
if (IgnoreSpaces.Count > 0 && IgnoreSpaces.Exists((int e) => e == lastFreeSpaceId))
{
lastFreeSpaceId = -1;
}
else if (freeSpaceOnly)
{
break;
}
}
else if (!freeSpaceOnly && item2.IsValid() && item2.Id == data.Id)
{
if (Plugin.config.verboseLogging.Value)
{
Plugin.logger.LogWarning((object)"Found a similar item");
}
item2.Values.Add(data.Values[0]);
item2.Saves.Add(data.Saves[0]);
item2.Quantity++;
return false;
}
spawnIndex++;
}
if (freeSpaceOnly && lastFreeSpaceId != -1)
{
break;
}
}
if (lastFreeSpaceId != -1)
{
if (Plugin.config.verboseLogging.Value)
{
Plugin.logger.LogWarning((object)"Found 1 free space");
}
spawnIndex = lastFreeSpaceId;
int num = (int)((float)lastFreeSpaceId / 4f);
int index = lastFreeSpaceId - num * 4;
ItemList[num][index].Update(data);
Size++;
return true;
}
Plugin.logger.LogError((object)("SmartCupboard was full when " + data.Id + " tried to be stored."));
return false;
}
public Data? RetrieveData(int spawnIndex, bool updateQuantity = true)
{
if (Plugin.config.verboseLogging.Value)
{
Plugin.logger.LogWarning((object)ToString());
Plugin.logger.LogWarning((object)("Retrieving item at position: " + spawnIndex));
}
int num = (int)((float)spawnIndex / 4f);
int num2 = spawnIndex - num * 4;
if (num >= 4 || num2 >= 4)
{
return null;
}
Data data = ItemList[num][num2];
if (!data.IsValid())
{
return null;
}
if (updateQuantity)
{
data.Values.RemoveAt(0);
data.Saves.RemoveAt(0);
data.Quantity--;
if (data.Quantity <= 0)
{
Size--;
ItemList[num][num2] = new Data();
}
}
if (Plugin.config.verboseLogging.Value)
{
Plugin.logger.LogWarning((object)ToString());
}
return data;
}
public override string ToString()
{
int num = 0;
StringBuilder stringBuilder = new StringBuilder().Append("Stored items:\n");
if (Size == 0)
{
return stringBuilder.Append("None\n").ToString();
}
foreach (List<Data> item in ItemList)
{
foreach (Data item2 in item)
{
if (item2.IsValid())
{
stringBuilder.Append(num + ": " + item2.Id + " x" + item2.Quantity + "\n");
}
num++;
}
}
return stringBuilder.ToString();
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
namespace SelfSortingStorage.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}