using Audio; using Platform; namespace Harmony.BlockDoorSecurePatches { [HarmonyPatch(typeof(BlockDoorSecure))] [HarmonyPatch("GetActivationText")] public class GetActivationTextPatch { public static bool Prefix(BlockDoorSecure __instance, ref string __result, WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, global::EntityAlive _entityFocusing) { if (_world.IsEditor()) { return true; } if (_blockValue.ischild) { Vector3i parentPos = _blockValue.Block.multiBlockPos.GetParentPos(_blockPos, _blockValue); BlockValue block = _world.GetBlock(parentPos); __result = __instance.GetActivationText(_world, block, _clrIdx, parentPos, _entityFocusing); return false; } TileEntitySecureDoor tileEntitySecureDoor = (TileEntitySecureDoor)_world.GetTileEntity(_clrIdx, _blockPos); if (tileEntitySecureDoor == null && !_world.IsEditor()) { __result = ""; return false; } bool flag = (!_world.IsEditor()) ? tileEntitySecureDoor.IsLocked() : ((_blockValue.meta & 4) > 0); PlayerActionsLocal playerInput = ((EntityPlayerLocal)_entityFocusing).playerInput; string arg = playerInput.Activate.GetBindingXuiMarkupString(XUiUtils.EmptyBindingStyle.EmptyString, XUiUtils.DisplayStyle.Plain, null) + playerInput.PermanentActions.Activate.GetBindingXuiMarkupString(XUiUtils.EmptyBindingStyle.EmptyString, XUiUtils.DisplayStyle.Plain, null); string arg2 = Localization.Get("door"); bool hasOwner = (tileEntitySecureDoor.GetOwner() != null); if (!flag) { __result = string.Format(Localization.Get("tooltipUnlocked"), arg, arg2); return false; } bool isOpen = BlockDoor.IsDoorOpen(_blockValue.meta); if (isOpen && !hasOwner) { __result = string.Format(Localization.Get("tooltipUnlocked"), arg, arg2); return false; } __result = string.Format(Localization.Get("tooltipLocked"), arg, arg2); return false; } } [HarmonyPatch(typeof(BlockDoorSecure))] [HarmonyPatch("OnBlockActivated")] public class OnBlockActivatedPatch { public static bool Prefix(BlockDoorSecure __instance, ref bool __result, string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, global::EntityAlive _player, string ___lockedSound, string ___lockingSound, string ___unlockingSound ) { if (_world.IsEditor()) { return true; } //Log.Out("BlockDoorSecurePatches-OnBlockActivated START"); if (_blockValue.ischild) { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 1"); Vector3i parentPos = _blockValue.Block.multiBlockPos.GetParentPos(_blockPos, _blockValue); BlockValue block = _world.GetBlock(parentPos); __result = __instance.OnBlockActivated(_commandName, _world, _cIdx, parentPos, block, (EntityPlayerLocal)_player); return false; } TileEntitySecureDoor tileEntitySecureDoor = (TileEntitySecureDoor)_world.GetTileEntity(_cIdx, _blockPos); if (tileEntitySecureDoor == null && !_world.IsEditor()) { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 2"); __result = false; return false; } bool hasOwner = (tileEntitySecureDoor.GetOwner() != null); bool flag = (!_world.IsEditor()) ? tileEntitySecureDoor.IsLocked() : ((_blockValue.meta & 4) > 0); bool flag2 = !_world.IsEditor() && tileEntitySecureDoor.IsUserAllowed(PlatformManager.InternalLocalUserIdentifier); if (!(_commandName == "close")) { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 3"); if (!(_commandName == "open")) { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 4"); if (_commandName == "lock") { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 5"); if (_world.IsEditor()) { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 6"); _blockValue.meta |= 4; _world.SetBlockRPC(_cIdx, _blockPos, _blockValue); } else { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 7"); tileEntitySecureDoor.SetLocked(true); } Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, ___lockingSound); GameManager.ShowTooltip(_player as EntityPlayerLocal, "doorLocked"); __result = true; return false; } if (_commandName == "unlock") { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 8"); if (_world.IsEditor()) { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 9"); _blockValue.meta = (byte)((int)_blockValue.meta & -5); _world.SetBlockRPC(_cIdx, _blockPos, _blockValue); } else { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 10"); tileEntitySecureDoor.SetLocked(false); } Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, ___unlockingSound); GameManager.ShowTooltip(_player as EntityPlayerLocal, "doorUnlocked"); __result = true; return false; } if (!(_commandName == "keypad")) { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 11"); if (_commandName == "trigger") { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 12"); XUiC_TriggerProperties.Show(((EntityPlayerLocal)_player).PlayerUI.xui, _cIdx, _blockPos, true, true); } __result = false; return false; } LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(_player as EntityPlayerLocal); if (uiforPlayer != null && tileEntitySecureDoor != null) { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 13"); XUiC_KeypadWindow.Open(uiforPlayer, tileEntitySecureDoor); } __result = true; return false; } else { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 14"); if (_world.IsEditor() || !flag || flag2) { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 15"); __instance.HandleTrigger((EntityPlayer)_player, (World)_world, _cIdx, _blockPos, _blockValue); __result = __instance.OnBlockActivated(_world, _cIdx, _blockPos, _blockValue, (EntityPlayerLocal)_player); return false; } Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, ___lockedSound); __result = false; return false; } } else { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 16"); if (_world.IsEditor() || !flag || flag2 || !hasOwner) { //Log.Out("BlockDoorSecurePatches-OnBlockActivated 17"); __instance.HandleTrigger((EntityPlayer)_player, (World)_world, _cIdx, _blockPos, _blockValue); __result = __instance.OnBlockActivated(_world, _cIdx, _blockPos, _blockValue, (EntityPlayerLocal)_player); if (!hasOwner) { tileEntitySecureDoor.SetLocked(false); } return false; } Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, ___lockedSound); __result = false; return false; } //Log.Out("BlockDoorSecurePatches-OnBlockActivated END"); __result = false; return false; } } }