Skip to content

Commit

Permalink
implement compatibility for A22
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualDev-FR committed Jun 24, 2024
1 parent 6397413 commit 6637558
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
15 changes: 14 additions & 1 deletion Harmony/BlockEfficientBaseRepair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
57 changes: 57 additions & 0 deletions Harmony/EfficientBaseRepair.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Audio;
using HarmonyLib;
using Twitch;
using UnityEngine;

namespace Harmony
{
Expand All @@ -12,6 +16,7 @@ public void InitMod(Mod _modInstance)
harmony.PatchAll(Assembly.GetExecutingAssembly());
}


[HarmonyPatch(typeof(TileEntity))]
[HarmonyPatch("Instantiate")]
public class TileEntity_Instantiate
Expand All @@ -27,6 +32,7 @@ public static bool Prefix(TileEntityType type, Chunk _chunk, ref TileEntity __re
}
}


[HarmonyPatch(typeof(GameManager))]
[HarmonyPatch("lootContainerOpened")]
public class GameManager_lootContainerOpened
Expand Down Expand Up @@ -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<ConnectionManager>.Instance.IsServer)
{
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(NetPackageManager.GetPackage<NetPackageTELock>().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<ITileEntity, int> 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;
}
}
}
}
2 changes: 1 addition & 1 deletion Harmony/XUiC_EfficientBaseRepairStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6637558

Please sign in to comment.