예제 #1
0
        public static DefenseShieldsEnforcement LoadEnforcement(IMyFunctionalBlock shield)
        {
            if (shield.Storage == null)
            {
                return(null);
            }

            string rawData;

            if (shield.Storage.TryGetValue(Session.Instance.ControllerEnforceGuid, out rawData))
            {
                DefenseShieldsEnforcement loadedEnforce = null;
                var base64 = Convert.FromBase64String(rawData);
                loadedEnforce = MyAPIGateway.Utilities.SerializeFromBinary <DefenseShieldsEnforcement>(base64);
                if (Session.Enforced.Debug == 3)
                {
                    Log.Line($"Enforcement Loaded {loadedEnforce != null} - Version:{loadedEnforce?.Version} - ShieldId [{shield.EntityId}]");
                }
                if (loadedEnforce != null)
                {
                    return(loadedEnforce);
                }
            }
            return(null);
        }
예제 #2
0
 public DataEnforce(ulong sender, long entityId, PacketType action)
 {
     Type     = action;
     Sender   = sender;
     EntityId = entityId;
     Enforce  = null;
 }
예제 #3
0
        }                        // empty ctor is required for deserialization

        public DataEnforce(ulong sender, long entityId, DefenseShieldsEnforcement enforce)
        {
            Type     = PacketType.Enforce;
            Sender   = sender;
            EntityId = entityId;
            Enforce  = enforce;
        }
예제 #4
0
        public static void SaveEnforcement(IMyFunctionalBlock shield, DefenseShieldsEnforcement enforce, bool createStorage = false)
        {
            if (createStorage && shield.Storage == null)
            {
                shield.Storage = new MyModStorageComponent();
            }
            else if (shield.Storage == null)
            {
                return;
            }

            var binary = MyAPIGateway.Utilities.SerializeToBinary(enforce);

            shield.Storage[Session.Instance.ControllerEnforceGuid] = Convert.ToBase64String(binary);
            if (Session.Enforced.Debug == 3)
            {
                Log.Line($"Enforcement Saved - Version:{enforce.Version} - ShieldId [{shield.EntityId}]");
            }
        }
 public DataEnforce(long entityId, DefenseShieldsEnforcement state) : base(entityId)
 {
     State = state;
 }