From 6637558875aa25f7312e9005da6bca92974d96b7 Mon Sep 17 00:00:00 2001 From: Thomas Menanteau <91687641+VisualDev-FR@users.noreply.github.com> Date: Tue, 25 Jun 2024 00:08:02 +0200 Subject: [PATCH] implement compatibility for A22 --- Harmony/BlockEfficientBaseRepair.cs | 15 ++++++- Harmony/EfficientBaseRepair.cs | 57 ++++++++++++++++++++++++ Harmony/XUiC_EfficientBaseRepairStats.cs | 2 +- 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/Harmony/BlockEfficientBaseRepair.cs b/Harmony/BlockEfficientBaseRepair.cs index bfbb625..4c60e2c 100644 --- a/Harmony/BlockEfficientBaseRepair.cs +++ b/Harmony/BlockEfficientBaseRepair.cs @@ -69,7 +69,7 @@ private void BloodMoonDenied(EntityPlayerLocal _player) } // copied from BlockSecureLoot - public override bool OnBlockActivated(string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player) + public override bool OnBlockActivated(string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player) { if (_blockValue.ischild) @@ -243,4 +243,17 @@ protected virtual void HandleTakeInternalItems(TileEntityEfficientBaseRepair te, } } + + public override void OnBlockRemoved(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue) + { + Log.Out($"[EfficientBaseRepair] OnBlockRemoved: {StackTraceUtility.ExtractStackTrace()}"); + base.OnBlockRemoved(world, _chunk, _blockPos, _blockValue); + } + + public override DestroyedResult OnBlockDestroyedBy(WorldBase _world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue, int _entityId, bool _bUseHarvestTool) + { + Log.Out($"[EfficientBaseRepair] OnBlockDestroyedBy: {StackTraceUtility.ExtractStackTrace()}"); + + return base.OnBlockDestroyedBy(_world, _clrIdx, _blockPos, _blockValue, _entityId, _bUseHarvestTool); + } } \ No newline at end of file diff --git a/Harmony/EfficientBaseRepair.cs b/Harmony/EfficientBaseRepair.cs index 73268d2..cdde73c 100644 --- a/Harmony/EfficientBaseRepair.cs +++ b/Harmony/EfficientBaseRepair.cs @@ -1,6 +1,10 @@ +using System; +using System.Collections.Generic; using System.Reflection; +using Audio; using HarmonyLib; using Twitch; +using UnityEngine; namespace Harmony { @@ -12,6 +16,7 @@ public void InitMod(Mod _modInstance) harmony.PatchAll(Assembly.GetExecutingAssembly()); } + [HarmonyPatch(typeof(TileEntity))] [HarmonyPatch("Instantiate")] public class TileEntity_Instantiate @@ -27,6 +32,7 @@ public static bool Prefix(TileEntityType type, Chunk _chunk, ref TileEntity __re } } + [HarmonyPatch(typeof(GameManager))] [HarmonyPatch("lootContainerOpened")] public class GameManager_lootContainerOpened @@ -69,5 +75,56 @@ public static bool Prefix(GameManager __instance, TileEntityLootContainer _te, L return false; } } + + + [HarmonyPatch(typeof(GameManager))] + [HarmonyPatch("TEUnlockServer")] + public class GameManager_TEUnlockServer + { + public static bool Prefix(GameManager __instance, int _clrIdx, Vector3i _blockPos, int _lootEntityId, bool _allowContainerDestroy = true) + { + if (!SingletonMonoBehaviour.Instance.IsServer) + { + SingletonMonoBehaviour.Instance.SendToServer(NetPackageManager.GetPackage().Setup(NetPackageTELock.TELockType.UnlockServer, _clrIdx, _blockPos, _lootEntityId, -1, null, _allowContainerDestroy)); + return false; + } + + TileEntity tileEntity = null; + if (_lootEntityId == -1) + { + tileEntity = __instance.m_World.GetTileEntity(_blockPos); + } + else + { + tileEntity = __instance.m_World.GetTileEntity(_lootEntityId); + if (tileEntity == null) + { + foreach (KeyValuePair lockedTileEntity in __instance.lockedTileEntities) + { + if (lockedTileEntity.Key.EntityId == _lootEntityId) + { + __instance.lockedTileEntities.Remove(lockedTileEntity.Key); + break; + } + } + } + } + + if (tileEntity != null) + { + __instance.lockedTileEntities.Remove(tileEntity); + + if (tileEntity.GetTileEntityType() == (TileEntityType)191) + return false; + + if (_allowContainerDestroy) + { + __instance.DestroyLootOnClose(tileEntity, _blockPos, _lootEntityId); + } + } + + return false; + } + } } } \ No newline at end of file diff --git a/Harmony/XUiC_EfficientBaseRepairStats.cs b/Harmony/XUiC_EfficientBaseRepairStats.cs index 0c04d8a..c208a0b 100644 --- a/Harmony/XUiC_EfficientBaseRepairStats.cs +++ b/Harmony/XUiC_EfficientBaseRepairStats.cs @@ -305,7 +305,7 @@ public override void OnClose() if (!XUiC_CameraWindow.hackyIsOpeningMaximizedWindow) { tileEntity.SetUserAccessing(_bUserAccessing: false); - instance.TEUnlockServer(tileEntity.GetClrIdx(), blockPos, tileEntity.entityId); + instance.TEUnlockServer(tileEntity.GetClrIdx(), blockPos, tileEntity.entityId, false); tileEntity.SetModified(); } base.OnClose();