Ejemplo n.º 1
0
        /// <param name="args">EntityIds as long</param>
        private static void TextPanel_DisplayEntities(MyFunctionalBlock block, ListReader <Ingame.TerminalActionParameter> args)
        {
            s_detectedIds.Clear();

            for (int i = 0; i < args.Count; i++)
            {
                if (args[i].TypeCode != TypeCode.Int64)
                {
                    Logger.DebugLog("TerminalActionParameter # " + i + " is of wrong type, expected Int64, got " + args[i].TypeCode, Logger.severity.WARNING);
                    if (MyAPIGateway.Session.Player != null)
                    {
                        block.AppendCustomInfo("Failed to display entities:\nTerminalActionParameter #" + i + " is of wrong type, expected Int64 (AKA long), got " + args[i].TypeCode + '\n');
                    }
                    return;
                }
                s_detectedIds.Add((long)args[i].Value);
            }

            TextPanel panel;

            if (!Registrar.TryGetValue(block.EntityId, out panel))
            {
                Logger.AlwaysLog("Text panel not found in registrar: " + block.EntityId, Logger.severity.ERROR);
                return;
            }

            Logger.DebugLog("Found text panel with id: " + block.EntityId);

            panel.Display(s_detectedIds);
        }
Ejemplo n.º 2
0
        private HashSet <long> GetAllOwners()
        {
            HashSet <long>      owners   = new HashSet <long>();
            HashSet <IMyEntity> entities = new HashSet <IMyEntity>();

            MyAPIGateway.Entities.GetEntities(entities);

            foreach (IMyEntity entity in entities)
            {
                if (!(entity is IMyCubeGrid))
                {
                    continue;
                }

                MyCubeGrid grid = (MyCubeGrid)entity;

                foreach (MySlimBlock slimBlock in grid.CubeBlocks)
                {
                    MyFunctionalBlock block = slimBlock?.FatBlock as MyFunctionalBlock;

                    if (block == null)
                    {
                        continue;
                    }

                    if (block.OwnerId != 0 && !owners.Contains(block.OwnerId))
                    {
                        owners.Add(block.OwnerId);
                    }
                }
            }
            return(owners);
        }
Ejemplo n.º 3
0
        /// <param name="args">Recipient grid, recipient block, message</param>
        private static void ProgrammableBlock_SendMessage(MyFunctionalBlock block, ListReader <Ingame.TerminalActionParameter> args)
        {
            if (args.Count != 3)
            {
                Logger.DebugLog("Wrong number of arguments, expected 3, got " + args.Count, Logger.severity.WARNING);
                if (MyAPIGateway.Session.Player != null)
                {
                    block.AppendCustomInfo("Failed to send message:\nWrong number of arguments, expected 3, got " + args.Count + '\n');
                }
                return;
            }

            string[] stringArgs = new string[3];
            for (int i = 0; i < 3; i++)
            {
                if (args[i].TypeCode != TypeCode.String)
                {
                    Logger.DebugLog("TerminalActionParameter #" + i + " is of wrong type, expected String, got " + args[i].TypeCode, Logger.severity.WARNING);
                    if (MyAPIGateway.Session.Player != null)
                    {
                        block.AppendCustomInfo("Failed to send message:\nTerminalActionParameter #" + i + " is of wrong type, expected String, got " + args[i].TypeCode + '\n');
                    }
                    return;
                }

                stringArgs[i] = (string)args[i].Value;
            }

            int count = Message.CreateAndSendMessage(block.EntityId, stringArgs[0], stringArgs[1], stringArgs[2]);

            if (MyAPIGateway.Session.Player != null)
            {
                (block as IMyTerminalBlock).AppendCustomInfo("Sent message to " + count + " block" + (count == 1 ? "" : "s"));
            }
        }
        public static void SendEnableRequest(MyFunctionalBlock block, bool enable)
        {
            var msg = new EnableMsg();

            msg.EntityId = block.EntityId;
            msg.Enable   = enable;

            Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request);
        }
Ejemplo n.º 5
0
        public void Initialize(Vector3 panelOrientation, bool isTwoSided, float panelOffset, MyFunctionalBlock solarBlock)
        {
            m_initialized = true;

            m_panelOrientation = panelOrientation;
            m_isTwoSided       = isTwoSided;
            m_panelOffset      = panelOffset;
            m_solarBlock       = solarBlock;

            //Warning: this will change the NeedsUpdate variable on the entity
            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
        }
Ejemplo n.º 6
0
        private static void Abort(MyFunctionalBlock block)
        {
            ManualMessage instance;

            if (!Registrar.TryGetValue(block.EntityId, out instance))
            {
                throw new ArgumentException("block id not found in registrar");
            }

            instance.m_sending = false;
            block.RebuildControls();
        }
Ejemplo n.º 7
0
        private static void KillBlock(MyFunctionalBlock block)
        {
            if (Thread.CurrentThread != MySandboxGame.Static.UpdateThread)
            {
                BlockLimiter.Instance.Torch.Invoke(() => block.Enabled = false);
            }
            else
            {
                block.Enabled = false;
            }

            BlockLimiter.Instance.Log.Info($"Turned off {block.BlockDefinition?.Id.ToString().Substring(16)} from {block.CubeGrid?.DisplayName}");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Create a RadarEquipment for a block, getting the definition from the block.
        /// </summary>
        public RadarEquipment(IMyCubeBlock block)
        {
            this.Log = new Logger(block);

            this.Entity         = block;
            this.RelationsBlock = block;
            this.myDefinition   = GetDefinition(block);

            Registrar.Add(block, this);

            TermBlock.OnClose += CustomInfoBlock_OnClose;

            TermBlock.AppendingCustomInfo += AppendingCustomInfo;

            UpdateTargetPowerLevel();
            PowerLevel_Current = Math.Min(PowerLevel_Target, myDefinition.MaxPowerLevel);
            MyAPIGateway.Utilities.InvokeOnGameThread(UpdatePowerConsumption);

            // maybe this is a bug fix?
            MyFunctionalBlock func = (MyFunctionalBlock)block;

            func.Enabled = false;
            func.Enabled = true;

            TermBlock.UpdateCustomInfo();

            byte detectionTypes = 0;

            if (myDefinition.Radar)
            {
                detectionTypes++;
            }
            if (myDefinition.PassiveDetect_Jamming > 0)
            {
                detectionTypes++;
            }
            if (myDefinition.PassiveDetect_Radar > 0)
            {
                detectionTypes++;
            }
            if (detectionTypes > 1)
            {
                detectedObjects_hash = new Dictionary <IMyEntity, DetectedInfo>();
            }

            m_beaconLight = GetLight();

            Log.DebugLog("Radar equipment initialized, power level: " + PowerLevel_Current, Logger.severity.INFO);
        }
Ejemplo n.º 9
0
        private static void KeepBlocksOff(MyFunctionalBlock __instance)
        {
            if (!BlockLimiterConfig.Instance.EnableLimits || !BlockLimiterConfig.Instance.KillNoOwnerBlocks || __instance.OwnerId != 0)
            {
                return;
            }
            var block = __instance;

            if (block.Enabled == false || block is MyParachute || block is MyButtonPanel ||
                block is IMyPowerProducer || block.BlockDefinition?.ContainsComputer() == false)
            {
                return;
            }

            BlockLimiter.Instance.Log.Info($"Keeping {block.BlockDefinition?.Id.ToString().Substring(16)} from {block.CubeGrid?.DisplayName} off due to no ownership");
            block.Enabled = false;
        }
Ejemplo n.º 10
0
        //   internal static readonly MethodInfo ownershipChange =
        //typeof(MyCubeGrid).GetMethod("ChangeOwnerRequest", BindingFlags.Instance | BindingFlags.Public) ??
        //throw new Exception("Failed to find patch method");

        //   internal static readonly MethodInfo ownershipPatch =
        //       typeof(NobodyPatchKEEEEEN).GetMethod(nameof(PatchOwnership), BindingFlags.Static | BindingFlags.Public) ??
        //       throw new Exception("Failed to find patch method");


        //public static void PatchOwnership(MyCubeGrid grid, MyCubeBlock block, long playerId, MyOwnershipShareModeEnum shareMode)
        //{
        //    if (block != null && block is MyFunctionalBlock fblock && playerId == 0)
        //    {
        //      //  fblock.Enabled = false;
        //        IMyFunctionalBlock ffblock = fblock;
        //        ffblock.Enabled = false;
        //    }
        //}
        public static bool PatchTurningOn(MyFunctionalBlock __instance)
        {
            if (CrunchUtilitiesPlugin.file != null && CrunchUtilitiesPlugin.file.NobodyPatch)
            {
                // Log.Info("Button");
                MyFunctionalBlock block = __instance;
                if (block.BlockDefinition?.ContainsComputer() == false)
                {
                    return(true);
                }
                if (block != null && block.OwnerId == 0)
                {
                    block.Enabled = false;
                    // Log.Info("Beacon button");
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 11
0
        private static void KeepBlocksOff(MyFunctionalBlock __instance)
        {
            if (!BlockLimiterConfig.Instance.EnableLimits)
            {
                return;
            }
            var block = __instance;

            if (block == null || block.Enabled == false || block is MyParachute || block is MyButtonPanel || block is IMyPowerProducer)
            {
                return;
            }

            if ((!BlockLimiterConfig.Instance.KillNoOwnerBlocks || block.BlockDefinition?.ContainsComputer() == false || block.OwnerId != 0))
            {
                return;
            }

            lock (KeepOffBlocks)
            {
                if (KeepOffBlocks.Count > 0)
                {
                    lock (KeepOffBlocks)
                    {
                        try
                        {
                            if (!KeepOffBlocks.Contains(block))
                            {
                                return;
                            }
                        }
                        catch (Exception e)
                        {
                            //ignore
                        }
                    }
                }
            }
            block.Enabled = false;
            Log.Info(
                $"Turned off {block.BlockDefinition?.BlockPairName} from {block.CubeGrid?.DisplayName}");
        }
Ejemplo n.º 12
0
        public bool IsBlockTypeOf(MyFunctionalBlock block, BlockCategory category)
        {
            switch (category)
            {
            case BlockCategory.Power:
                return(block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_Reactor) ||
                       block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_BatteryBlock) ||
                       block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_SolarPanel));

            case BlockCategory.Production:
                return(block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_Assembler) ||
                       block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_Refinery) ||
                       block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_OxygenGenerator));

            case BlockCategory.Weapons:
                return(block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_InteriorTurret) ||
                       block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_LargeGatlingTurret) ||
                       block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_LargeMissileTurret));

            default:
                throw new InvalidBranchException();
            }
        }
Ejemplo n.º 13
0
        private static void SendMessage(MyFunctionalBlock block)
        {
            ManualMessage instance;

            if (!Registrar.TryGetValue(block.EntityId, out instance))
            {
                throw new ArgumentException("block id not found in registrar");
            }

            block.RebuildControls();

            if (instance.m_sending)
            {
                if (instance.m_targetShipName.Length < 3)
                {
                    block.AppendCustomInfo("Ship Name(s) must be at least 3 characters");
                    return;
                }
                if (instance.m_targetBlockName.Length < 3)
                {
                    block.AppendCustomInfo("Block Name(s) must be at least 3 characters");
                    return;
                }

                int count = Message.CreateAndSendMessage(block.EntityId, instance.m_targetShipName.ToString(), instance.m_targetBlockName.ToString(), instance.m_message.ToString());
                if (MyAPIGateway.Session.Player != null)
                {
                    (block as IMyTerminalBlock).AppendCustomInfo("Sent message to " + count + " block" + (count == 1 ? "" : "s"));
                }

                instance.m_sending = false;
            }
            else
            {
                instance.m_sending = true;
            }
        }
 public FunctionalBlockWrapper(MySlimBlock block) : base(block)
 {
     Block = (MyFunctionalBlock)block.FatBlock;
 }