using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Unity.Netcode; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("OldMarket.ShelfReplace")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("OldMarket.ShelfReplace")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("bdf5b2d1-095e-4269-ab6f-6d9f4f1ac25b")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace OldMarketMods.ShelfReplaceHelper; [HarmonyPatch(typeof(PlayerInventory), "HandleDrop")] internal static class PlayerInventory_HandleDrop_Patch { private static void Prefix(PlayerInventory __instance) { //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_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: 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_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) try { if (!((NetworkBehaviour)__instance).IsOwner) { return; } PlayerActions player = InputManager.Instance.inputMaster.Player; if (!((PlayerActions)(ref player)).Drop.WasPerformedThisFrame()) { return; } ShelfReplaceManager instance = ShelfReplaceManager.Instance; if (instance == null || !instance.HasData) { return; } NetworkList slots = __instance.slots; if (slots == null || slots.Count == 0) { return; } NetworkVariable value = Traverse.Create((object)__instance).Field("currentSlot").GetValue>(); if (value != null) { int value2 = value.Value; if (value2 >= 0 && value2 < slots.Count && slots[value2].itemId == instance.ShelfBlockId) { float num = 0.25f; float num2 = 1f; Vector3 position = ((Component)__instance).transform.position; Vector3 forward = ((Component)__instance).transform.forward; forward.y = 0f; Vector3 dropPosition = position + forward * num + new Vector3(0f, num2, 0f); instance.DropAtPosition(dropPosition); } } } catch (Exception arg) { ManualLogSource log = ShelfReplacePlugin.Log; if (log != null) { log.LogError((object)$"[ShelfReplace] HandleDrop Prefix error: {arg}"); } } } } [HarmonyPatch(typeof(PlayerInventory), "HandleNewBlockPlacement")] internal static class PlayerInventory_HandleNewBlockPlacement_Patch { private static readonly FieldInfo BlockBlueprintField = AccessTools.Field(typeof(PlayerInventory), "blockBlueprint"); private static readonly FieldInfo MeshRenderersBlockBlueprintField = AccessTools.Field(typeof(PlayerInventory), "meshRenderersBlockBlueprint"); private static void Postfix(PlayerInventory __instance) { try { if (!((NetworkBehaviour)__instance).IsOwner) { return; } ShelfReplaceManager instance = ShelfReplaceManager.Instance; if (instance == null || !instance.HasData || BlockBlueprintField == null || MeshRenderersBlockBlueprintField == null) { return; } object? value = BlockBlueprintField.GetValue(__instance); GameObject val = (GameObject)((value is GameObject) ? value : null); if ((Object)(object)val == (Object)null || (Object)(object)val.GetComponent() != (Object)null) { return; } Block componentInChildren = val.GetComponentInChildren(); if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren.blockSO == (Object)null || !ShelfReplaceUtil.IsShelfLikeBlock(componentInChildren)) { return; } BlockSO blockSO = componentInChildren.blockSO; if ((Object)(object)blockSO == (Object)null || (instance.ShelfBlockId != 0L && instance.ShelfBlockId != ((ItemSO)blockSO).id)) { return; } List rendererList = MeshRenderersBlockBlueprintField.GetValue(__instance) as List; if (rendererList == null) { return; } Transform root = ((Component)componentInChildren).transform; instance.ForEachItemForBlueprint(delegate(long itemId, Vector3 localPos, Quaternion localRot) { //IL_0040: 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_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0051: 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) //IL_005b: 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) //IL_0067: 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_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) try { if (!((Object)(object)GameManager.Instance == (Object)null)) { ItemSO itemById = GameManager.Instance.GetItemById(itemId); if (!((Object)(object)itemById == (Object)null) && !((Object)(object)itemById.prefab == (Object)null)) { Vector3 val2 = root.position + root.rotation * localPos; Quaternion val3 = root.rotation * localRot; GameObject val4 = Object.Instantiate(itemById.prefab, val2, val3); val4.transform.SetParent(root, true); Collider[] componentsInChildren = val4.GetComponentsInChildren(); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = false; } NetworkObject component = val4.GetComponent(); if ((Object)(object)component != (Object)null) { Object.Destroy((Object)(object)component); } MonoBehaviour[] componentsInChildren2 = val4.GetComponentsInChildren(); for (int i = 0; i < componentsInChildren2.Length; i++) { ((Behaviour)componentsInChildren2[i]).enabled = false; } MeshRenderer[] componentsInChildren3 = val4.GetComponentsInChildren(); if (componentsInChildren3 != null && componentsInChildren3.Length != 0) { rendererList.AddRange(componentsInChildren3); } } } } catch (Exception ex2) { ManualLogSource log2 = ShelfReplacePlugin.Log; if (log2 != null) { log2.LogError((object)("[ShelfLayoutKeeper] Blueprint ghost spawn failed: " + ex2)); } } }); Traverse.Create((object)__instance).Method("BuildBlockBlueprintMaterialCache", Array.Empty()).GetValue(); val.AddComponent(); } catch (Exception ex) { ManualLogSource log = ShelfReplacePlugin.Log; if (log != null) { log.LogError((object)("[ShelfLayoutKeeper] HandleNewBlockPlacement Postfix error: " + ex)); } } } } internal class ShelfBlueprintMarker : MonoBehaviour { internal long BlockId; internal readonly List GhostTransforms = new List(); internal readonly List BaseLocalPositions = new List(); } [HarmonyPatch(typeof(GameManager), "RemoveBlockServerRpc")] internal static class GameManager_RemoveBlockServerRpc_Patch { private static void Prefix(NetworkObjectReference target, ServerRpcParams serverRpcParams) { //IL_0024: 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_0060: 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_0068: Unknown result type (might be due to invalid IL or missing references) try { ShelfReplaceManager instance = ShelfReplaceManager.Instance; if (instance == null || !instance.HasData) { return; } NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null)) { ulong senderClientId = serverRpcParams.Receive.SenderClientId; if (singleton.ConnectedClients.TryGetValue(senderClientId, out var value) && value != null && !((Object)(object)value.PlayerObject == (Object)null)) { Vector3 position = ((Component)value.PlayerObject).transform.position; instance.DropAtPosition(position); } } } catch (Exception arg) { ManualLogSource log = ShelfReplacePlugin.Log; if (log != null) { log.LogError((object)$"[ShelfReplace] RemoveBlockServerRpc Prefix error: {arg}"); } } } } [HarmonyPatch(typeof(GameManager), "LoadWorldServer")] internal static class GameManager_LoadWorldServer_Patch { private static void Prefix(GameManager __instance) { try { if (((NetworkBehaviour)__instance).IsServer) { ShelfReplaceManager.Instance?.Clear(); } } catch (Exception arg) { ManualLogSource log = ShelfReplacePlugin.Log; if (log != null) { log.LogError((object)$"[ShelfReplace] LoadWorldServer Prefix error: {arg}"); } } } } [HarmonyPatch(typeof(Block), "OnNetworkDespawn")] internal static class Block_OnNetworkDespawn_Patch { private static void Prefix(Block __instance) { try { if (!((NetworkBehaviour)__instance).IsServer || !ShelfReplaceUtil.IsShelfLikeBlock(__instance) || (Object)(object)GameManager.Instance == (Object)null || (Object)(object)__instance.blueprintTrigger == (Object)null) { return; } ShelfReplaceManager instance = ShelfReplaceManager.Instance; if (instance == null) { return; } BlockSO blockSO = __instance.blockSO; bool flag = (Object)(object)blockSO != (Object)null && blockSO.isStand; List itemsInTrigger = GameManager.Instance.GetItemsInTrigger(__instance.blueprintTrigger); if (itemsInTrigger == null || itemsInTrigger.Count == 0) { return; } List list = new List(); foreach (Item item in itemsInTrigger) { if ((Object)(object)item == (Object)null) { continue; } Block supportingBlockForItem = ShelfReplaceUtil.GetSupportingBlockForItem(item); if (flag) { if ((Object)(object)supportingBlockForItem != (Object)null && (Object)(object)supportingBlockForItem != (Object)(object)__instance) { continue; } } else if ((Object)(object)supportingBlockForItem != (Object)(object)__instance) { continue; } if (instance.ShouldCapture(__instance, item)) { list.Add(item); } } if (list.Count == 0) { return; } instance.Capture(__instance, list); for (int num = list.Count - 1; num >= 0; num--) { Item val = list[num]; if ((Object)(object)val != (Object)null && (Object)(object)((NetworkBehaviour)val).NetworkObject != (Object)null && ((NetworkBehaviour)val).NetworkObject.IsSpawned) { ((NetworkBehaviour)val).NetworkObject.Despawn(true); } } } catch (Exception ex) { ManualLogSource log = ShelfReplacePlugin.Log; if (log != null) { log.LogError((object)("[ShelfLayoutKeeper] OnNetworkDespawn Prefix error: " + ex)); } } } } [HarmonyPatch(typeof(Block), "OnNetworkSpawn")] internal static class Block_OnNetworkSpawn_Patch { private static void Postfix(Block __instance) { try { if (((NetworkBehaviour)__instance).IsServer && ShelfReplaceUtil.IsShelfLikeBlock(__instance)) { ShelfReplaceManager instance = ShelfReplaceManager.Instance; if (instance != null && instance.HasData) { instance.AttachTo(__instance); } } } catch (Exception arg) { ManualLogSource log = ShelfReplacePlugin.Log; if (log != null) { log.LogError((object)$"[ShelfReplace] OnNetworkSpawn Postfix error: {arg}"); } } } } internal class ShelfReplaceManager { private class ShelfItemData { internal long itemId; internal int amount; internal int cost; internal int dayCounter; internal Vector3 localPosition; internal Quaternion localRotation; } private static ShelfReplaceManager _instance; private readonly List _items = new List(); private bool _hasData; private long _shelfBlockId; private static MethodInfo _serverSetupItemMethod; private static FieldInfo _onStandField; private static PropertyInfo _networkVarBoolValueProp; internal static ShelfReplaceManager Instance => _instance ?? (_instance = new ShelfReplaceManager()); internal bool HasData { get { if (_hasData) { return _items.Count > 0; } return false; } } internal long ShelfBlockId => _shelfBlockId; internal void Clear() { _items.Clear(); _hasData = false; _shelfBlockId = 0L; } internal bool ShouldCapture(Block shelf, Item item) { if ((Object)(object)shelf == (Object)null || (Object)(object)shelf.blockSO == (Object)null || (Object)(object)item == (Object)null || (Object)(object)item.itemSO == (Object)null) { return false; } BlockSO blockSO = shelf.blockSO; if ((Object)(object)blockSO == (Object)null) { return false; } if (blockSO.isStand) { return IsItemOnStand(item); } return true; } private static bool IsItemOnStand(Item item) { if ((Object)(object)item == (Object)null) { return false; } try { if (_onStandField == null) { _onStandField = typeof(Item).GetField("onStand", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (_onStandField == null) { FieldInfo[] fields = typeof(Item).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (fieldInfo.FieldType.IsGenericType && !(fieldInfo.FieldType.GetGenericTypeDefinition() != typeof(NetworkVariable<>))) { Type[] genericArguments = fieldInfo.FieldType.GetGenericArguments(); if (genericArguments.Length == 1 && genericArguments[0] == typeof(bool) && fieldInfo.Name.IndexOf("stand", StringComparison.OrdinalIgnoreCase) >= 0) { _onStandField = fieldInfo; break; } } } if (_onStandField == null) { ManualLogSource log = ShelfReplacePlugin.Log; if (log != null) { log.LogWarning((object)"[ShelfReplace] Item.onStand field not found. Capture will not filter floor items."); } return true; } } } object value = _onStandField.GetValue(item); if (value == null) { return false; } if (_networkVarBoolValueProp == null) { _networkVarBoolValueProp = value.GetType().GetProperty("Value", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (_networkVarBoolValueProp == null || _networkVarBoolValueProp.PropertyType != typeof(bool)) { ManualLogSource log2 = ShelfReplacePlugin.Log; if (log2 != null) { log2.LogWarning((object)"[ShelfReplace] NetworkVariable.Value property not found. Capture will not filter floor items."); } return true; } } if (_networkVarBoolValueProp.GetValue(value, null) is bool result) { return result; } return false; } catch (Exception ex) { ManualLogSource log3 = ShelfReplacePlugin.Log; if (log3 != null) { log3.LogError((object)("[ShelfReplace] IsItemOnStand failed: " + ex)); } return true; } } internal void Capture(Block shelf, List items) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0129: 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) Clear(); if ((Object)(object)shelf == (Object)null || items == null || items.Count == 0 || (Object)(object)shelf.blockSO == (Object)null) { return; } _shelfBlockId = ((ItemSO)shelf.blockSO).id; Vector3 position = ((Component)shelf).transform.position; Quaternion val = Quaternion.Inverse(((Component)shelf).transform.rotation); foreach (Item item in items) { if ((Object)(object)item == (Object)null || (Object)(object)item.itemSO == (Object)null) { continue; } try { Vector3 position2 = ((Component)item).transform.position; Quaternion rotation = ((Component)item).transform.rotation; Vector3 localPosition = val * (position2 - position); Quaternion localRotation = val * rotation; int amount = ((item.amount == null) ? 1 : item.amount.Value); int dayCounter = ((item.dayCounter != null) ? item.dayCounter.Value : 0); _items.Add(new ShelfItemData { itemId = item.itemSO.id, amount = amount, cost = item.cost, dayCounter = dayCounter, localPosition = localPosition, localRotation = localRotation }); } catch (Exception arg) { ManualLogSource log = ShelfReplacePlugin.Log; if (log != null) { log.LogError((object)$"[ShelfReplace] Capture item failed: {arg}"); } } } _hasData = _items.Count > 0; } internal void ForEachItemForBlueprint(Action handler) { //IL_002b: 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) if (handler == null || !HasData) { return; } foreach (ShelfItemData item in _items) { handler(item.itemId, item.localPosition, item.localRotation); } } private static void EnsureServerSetupItemMethod() { if (_serverSetupItemMethod != null) { return; } _serverSetupItemMethod = typeof(Item).GetMethod("ServerSetupItem", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[8] { typeof(long), typeof(bool), typeof(int), typeof(int), typeof(int), typeof(bool), typeof(bool), typeof(float) }, null); if (_serverSetupItemMethod == null) { ManualLogSource log = ShelfReplacePlugin.Log; if (log != null) { log.LogError((object)"[ShelfReplace] Item.ServerSetupItem not found."); } } } private void SpawnStandItemOnShelf(ShelfItemData data, Block shelf) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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) //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_0049: 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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: 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) //IL_0059: 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) if ((Object)(object)GameManager.Instance == (Object)null) { return; } EnsureServerSetupItemMethod(); if (_serverSetupItemMethod == null) { return; } Vector3 position = ((Component)shelf).transform.position; Quaternion rotation = ((Component)shelf).transform.rotation; Vector3 val = position + rotation * data.localPosition; Quaternion val2 = rotation * data.localRotation; float y = ((Quaternion)(ref rotation)).eulerAngles.y; try { GameObject item = GameManager.Instance.item; if (!((Object)(object)item == (Object)null)) { GameObject obj = Object.Instantiate(item, val, val2); NetworkObject component = obj.GetComponent(); if ((Object)(object)component != (Object)null) { component.Spawn(false); } Item component2 = obj.GetComponent(); if (!((Object)(object)component2 == (Object)null)) { object[] parameters = new object[8] { data.itemId, false, data.amount, data.cost, data.dayCounter, true, false, y }; _serverSetupItemMethod.Invoke(component2, parameters); } } } catch (Exception ex) { ManualLogSource log = ShelfReplacePlugin.Log; if (log != null) { log.LogError((object)("[ShelfReplace] SpawnStandItemOnShelf failed: " + ex)); } } } internal void AttachTo(Block newShelf) { //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: 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_0109: 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_0113: 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_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0126: 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_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: 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) if (!HasData) { return; } if ((Object)(object)newShelf == (Object)null || (Object)(object)newShelf.blockSO == (Object)null) { Clear(); return; } BlockSO blockSO = newShelf.blockSO; bool flag = (Object)(object)blockSO != (Object)null && blockSO.isStand; long num = (((Object)(object)blockSO != (Object)null) ? ((ItemSO)blockSO).id : 0); if (_shelfBlockId != 0L && num != _shelfBlockId) { return; } if ((Object)(object)GameManager.Instance == (Object)null) { Clear(); return; } if (flag) { foreach (ShelfItemData item in _items) { SpawnStandItemOnShelf(item, newShelf); } } else { Vector3 position = ((Component)newShelf).transform.position; Quaternion rotation = ((Component)newShelf).transform.rotation; foreach (ShelfItemData item2 in _items) { try { Vector3 val = position + rotation * item2.localPosition; Quaternion val2 = rotation * item2.localRotation; GameManager.Instance.SpawnItemAtPositionServerRpc(item2.itemId, val, val2, true, Vector3.zero, item2.amount, item2.cost, item2.dayCounter); } catch (Exception ex) { ManualLogSource log = ShelfReplacePlugin.Log; if (log != null) { log.LogError((object)("[ShelfReplace] Attach spawn (storage) failed: " + ex)); } } } } Clear(); } internal void DropAtPosition(Vector3 dropPosition) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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) if (!HasData) { return; } if ((Object)(object)GameManager.Instance == (Object)null) { Clear(); return; } Vector3 val = dropPosition + Vector3.up * 0.1f; Quaternion identity = Quaternion.identity; foreach (ShelfItemData item in _items) { try { GameManager.Instance.SpawnItemAtPositionServerRpc(item.itemId, val, identity, true, Vector3.zero, item.amount, item.cost, item.dayCounter); } catch (Exception ex) { ManualLogSource log = ShelfReplacePlugin.Log; if (log != null) { log.LogError((object)("[ShelfReplace] DropAtPosition failed: " + ex)); } } } Clear(); } } internal static class ShelfReplaceUtil { internal static bool IsShelfLikeBlock(Block block) { if ((Object)(object)block == (Object)null) { return false; } BlockSO blockSO = block.blockSO; if ((Object)(object)blockSO == (Object)null) { return false; } if (blockSO.isStand) { return true; } if (!string.IsNullOrEmpty(((Object)blockSO).name) && ((Object)blockSO).name.Contains("CellarStand")) { return true; } if (!string.IsNullOrEmpty(((Object)block).name) && ((Object)block).name.Contains("CellarStand")) { return true; } return false; } internal static Block GetSupportingBlockForItem(Item item) { //IL_0012: 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) //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_002b: 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_0037: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)item == (Object)null) { return null; } try { Vector3 val = ((Component)item).transform.position + Vector3.up * 0.05f; Vector3 down = Vector3.down; float num = 2f; RaycastHit[] array = Physics.RaycastAll(val, down, num, -1, (QueryTriggerInteraction)1); Block result = null; float num2 = float.MaxValue; for (int i = 0; i < array.Length; i++) { Collider collider = ((RaycastHit)(ref array[i])).collider; if (!((Object)(object)collider == (Object)null)) { Block componentInParent = ((Component)collider).GetComponentInParent(); if (!((Object)(object)componentInParent == (Object)null) && ((RaycastHit)(ref array[i])).distance < num2) { num2 = ((RaycastHit)(ref array[i])).distance; result = componentInParent; } } } return result; } catch (Exception ex) { ManualLogSource log = ShelfReplacePlugin.Log; if (log != null) { log.LogError((object)("[ShelfLayoutKeeper] GetSupportingBlockForItem failed: " + ex)); } return null; } } } internal sealed class ShelfHotbarMarker : MonoBehaviour { private PlayerInventory _inventory; private readonly List _markedSlots = new List(); private float _timer; private const float Interval = 0.2f; internal void Initialize(PlayerInventory inventory) { _inventory = inventory; } private void Update() { if (!((Object)(object)_inventory == (Object)null) && ((NetworkBehaviour)_inventory).IsLocalPlayer) { _timer += Time.unscaledDeltaTime; if (!(_timer < 0.2f)) { _timer = 0f; Refresh(); } } } private void Refresh() { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) ShelfReplaceManager instance = ShelfReplaceManager.Instance; if (instance == null || !instance.HasData) { ClearAllMarkers(); return; } if ((Object)(object)GameManager.Instance == (Object)null) { ClearAllMarkers(); return; } long shelfBlockId = instance.ShelfBlockId; if (shelfBlockId == 0L) { ClearAllMarkers(); return; } NetworkList slots = _inventory.slots; Transform transform = _inventory.itemSlots.transform; int num = Mathf.Min(slots.Count, transform.childCount); ClearAllMarkers(); for (int i = 0; i < num; i++) { InventorySlot val = slots[i]; Transform child = transform.GetChild(i); if (((Component)child).gameObject.activeInHierarchy && val.itemId == shelfBlockId && !((Object)/*isinst with value type is only supported in some contexts*/ == (Object)null)) { AddMarker(child); } } } private void AddMarker(Transform slotTransform) { //IL_002f: 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_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_007c: 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_00a5: 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) if (!((Object)(object)slotTransform == (Object)null)) { if ((Object)(object)slotTransform.Find("ShelfReplace_Marker") != (Object)null) { _markedSlots.Add(slotTransform); return; } GameObject val = new GameObject("ShelfReplace_Marker"); val.transform.SetParent(slotTransform, false); RectTransform obj = val.AddComponent(); obj.anchorMin = new Vector2(1f, 1f); obj.anchorMax = new Vector2(1f, 1f); obj.pivot = new Vector2(1f, 1f); obj.sizeDelta = new Vector2(12f, 12f); obj.anchoredPosition = new Vector2(-4f, -4f); Image obj2 = val.AddComponent(); ((Graphic)obj2).raycastTarget = false; ((Graphic)obj2).color = new Color(0f, 1f, 0f, 0.9f); _markedSlots.Add(slotTransform); } } private void ClearAllMarkers() { for (int i = 0; i < _markedSlots.Count; i++) { Transform val = _markedSlots[i]; if (!((Object)(object)val == (Object)null)) { Transform val2 = val.Find("ShelfReplace_Marker"); if ((Object)(object)val2 != (Object)null) { Object.Destroy((Object)(object)((Component)val2).gameObject); } } } _markedSlots.Clear(); } private void OnDestroy() { ClearAllMarkers(); } } [HarmonyPatch(typeof(PlayerInventory), "OnNetworkSpawn")] internal static class PlayerInventory_OnNetworkSpawn_Patch { private static void Postfix(PlayerInventory __instance) { try { if (((NetworkBehaviour)__instance).IsLocalPlayer && !((Object)(object)__instance.itemSlots == (Object)null) && !((Object)(object)__instance.itemSlots.GetComponent() != (Object)null)) { __instance.itemSlots.gameObject.AddComponent().Initialize(__instance); } } catch (Exception arg) { ManualLogSource log = ShelfReplacePlugin.Log; if (log != null) { log.LogError((object)$"[ShelfReplace] PlayerInventory_OnNetworkSpawn error: {arg}"); } } } } [BepInPlugin("oldmarket.shelflayoutkeeper", "Old Market Shelf Layout Keeper", "1.1.3")] [BepInProcess("Old Market Simulator.exe")] public class ShelfReplacePlugin : BaseUnityPlugin { public const string PluginGuid = "oldmarket.shelflayoutkeeper"; public const string PluginName = "Old Market Shelf Layout Keeper"; public const string PluginVersion = "1.1.3"; internal static ManualLogSource Log; private void Awake() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; try { new Harmony("oldmarket.shelflayoutkeeper").PatchAll(); } catch (Exception arg) { Log.LogError((object)$"[ShelfReplace] Harmony patch failed: {arg}"); } } }