Exemplo n.º 1
0
        public object Part1()
        {
            var     mem  = new Dictionary <ulong, ulong>();
            Bitmask mask = null;

            foreach (var i in Instructions)
            {
                if (i.Type == InstructionType.SetMask)
                {
                    mask = (Bitmask)i.Value;
                }
                else if (i.Type == InstructionType.SetMemory)
                {
                    var a        = ((ulong index, ulong value))i.Value;
                    var newValue = mask.Mask(a.value);
                    if (mem.ContainsKey(a.index))
                    {
                        mem[a.index] = newValue;
                    }
                    else
                    {
                        mem.Add(a.index, newValue);
                    }
                }
            }
            var sum = (ulong)0;

            foreach (var m in mem.Values)
            {
                sum += m;
            }
            return(sum);
        }
Exemplo n.º 2
0
            public BitmapData(CacheBase Cache, int Address)
            {
                EndianReader Reader = Cache.Reader;

                Reader.SeekTo(Address);

                Class  = Reader.ReadString(4);
                Width  = Reader.ReadInt16();
                Height = Reader.ReadInt16();
                Depth  = Reader.ReadByte();
                Flags  = new Bitmask(Reader.ReadByte());
                Type   = (TextureType)Reader.ReadByte();
                Reader.ReadByte(); //dunno what this is
                Format = (TextureFormat)Reader.ReadInt16();

                if ((int)Format > 31) //change to match defined format list
                {
                    Format -= 5;
                }

                MoreFlags   = new Bitmask(Reader.ReadInt16());
                RegX        = Reader.ReadInt16();
                RegY        = Reader.ReadInt16();
                MipmapCount = Reader.ReadByte();
                Reader.ReadByte();
                InterleavedIndex = Reader.ReadByte();
                Index2           = Reader.ReadByte();
                PixelsOffset     = Reader.ReadInt32();
                PixelsSize       = Reader.ReadInt32();
            }
Exemplo n.º 3
0
    static void Main(string[] args)
    {
        var memory = new Dictionary <long, long>();
        var mask   = new Bitmask();

        foreach (string line in File.ReadLines("input.txt"))
        {
            var data = line.Split(" = ");
            if (data[0] == "mask")
            {
                mask = Bitmask.FromString(data[1]);
            }
            else
            {
                var value = int.Parse(data[1]);
                var place = int.Parse(new String(data[0].Where(Char.IsDigit).ToArray()));
                foreach (var modifiedPlace in mask.Apply(place))
                {
                    memory[modifiedPlace] = value;
                }
            }
        }
        long sum = 0L;

        foreach (var entry in memory)
        {
            sum += entry.Value;
        }
        Console.WriteLine(sum);
    }
Exemplo n.º 4
0
 /**
  * The biome-making process involves iterating over the whole map, computing the tile index based on its tile mask,
  *   computing the block mask, and generating the texture (perhaps using random tiles for central tile).
  */
 public override void Process(Action <uint, uint, Texture2D, Rect> painter, Bitmask currentBlockMask)
 {
     for (uint y = 0; y < Height; y++)
     {
         for (uint x = 0; x < Width; x++)
         {
             // Right now this does not mess with biomatic markers.
             // Just the block mask and the texture.
             int presenceIndex = 0;
             if (ParsedPresenceData[x, y])
             {
                 presenceIndex += 8;
             }
             if (ParsedPresenceData[x + 1, y])
             {
                 presenceIndex += 4;
             }
             if (ParsedPresenceData[x, y + 1])
             {
                 presenceIndex += 2;
             }
             if (ParsedPresenceData[x + 1, y + 1])
             {
                 presenceIndex += 1;
             }
             Rect?picked  = (presenceIndex == 15 && OtherTilesPicker != null) ? OtherTilesPicker.Pick() : null;
             Rect section = picked != null ? picked.Value : SourceRects[presenceIndex];
             painter(x, y, picked != null ? OtherTilesPicker.Source : Source, section);
             if ((PresenceBlockingMode != null) && (ExtendedPresence ? (presenceIndex != 0) : (presenceIndex == 15)))
             {
                 currentBlockMask[x, y] = PresenceBlockingMode.Value;
             }
         }
     }
 }
Exemplo n.º 5
0
                // Constructor

                /**
                 * Constructing a map involves constructing the internal objects layer and the internal block layer.
                 * The block mask will be immutable, since it will never be modified. OTOH the solid mask (for the objects layer)
                 *   will be mutable. But those layers are initialized inside the tilemap.
                 */
                public Tilemap(Behaviours.Map relatedMap, uint width, uint height, Texture2D source, int maskApplicationOffsetX = 0, int maskApplicationOffsetY = 0)
                {
                    if (relatedMap == null)
                    {
                        throw new NullReferenceException("Related map for tile map must not be null");
                    }

                    if (width < 1 || width > MAX_WIDTH || height < 1 || height > MAX_HEIGHT)
                    {
                        throw new InvalidDimensionsException(width, height);
                    }

                    RelatedMap = relatedMap;
                    Width      = width;
                    Height     = height;
                    solidMask  = new SolidMask(width, height);
                    if (source != null)
                    {
                        Bitmask bitMask = new Bitmask(source);
                        if (width != bitMask.Width || height != bitMask.Height || maskApplicationOffsetX != 0 || maskApplicationOffsetY != 0)
                        {
                            bitMask = bitMask.Translated(width, height, maskApplicationOffsetX, maskApplicationOffsetY);
                        }
                        blockMask = bitMask;
                    }
                    else
                    {
                        blockMask = new Bitmask(width, height);
                    }
                }
Exemplo n.º 6
0
 public void UpdateRequirementMask(Bitmask mask)
 {
     if (IgnoreEvents)
     {
         return;
     }
     AssembledData.RequirementMask = mask;
 }
Exemplo n.º 7
0
 public bool Equals(Bitmask <T> other)
 {
     if (other == null)
     {
         return(false);
     }
     return(mask == other.mask);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Does this bitmask intersects with the specified bitmask.
 /// </summary>
 /// <param name="bitmask">Bitmask to compare</param>
 /// <returns>True if the bitmask intersects with the specified bitmask, False otherwise.</returns>
 public bool Intersect(Bitmask <T> bitmask)
 {
     if (bitmask == null)
     {
         return(mask == 0);
     }
     return((mask & bitmask.mask) != 0);
 }
Exemplo n.º 9
0
 public void UpdatePartBDMask(Bitmask mask)
 {
     if (EditSlot == null || IgnoreEvents)
     {
         return;
     }
     EditSlot.Slot.EquipedPart.BDMask = mask;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Is this bitmask a subset of the specified bitmask.
 /// </summary>
 /// <param name="bitmask">Bitmask to compare (potential superset)</param>
 /// <returns>True if the bitmask is a subset of the specified bitmask, False otherwise.</returns>
 public bool IsSubsetOf(Bitmask <T> bitmask)
 {
     if (bitmask == null)
     {
         return(false);
     }
     return((mask & bitmask.mask) == mask);
 }
Exemplo n.º 11
0
 public BiomeLayer(uint width, uint height, Texture2D source, Texture2D presenceData, bool extendedPresence, bool?presenceBlockingMode = null,
                   int presenceDataOffsetX = 0, int presenceDataOffsetY = 0, RandomAlternatePicker picker = null) : base(width, height)
 {
     Source               = source;
     ExtendedPresence     = extendedPresence;
     PresenceBlockingMode = presenceBlockingMode;
     ParsedPresenceData   = ParsePresenceData(presenceData, presenceDataOffsetX, presenceDataOffsetY);
     OtherTilesPicker     = picker;
 }
Exemplo n.º 12
0
        public void AnyBitSet_UInt32HasSomeBitsSet()
        {
            uint target = 0x00010100;

            //Act
            var actual = Bitmask.AnyBitSet(target, 0x00010000);

            //Assert
            actual.Should().BeTrue();
        }
Exemplo n.º 13
0
        public void AnyBitSet_ByteHasNoBitsSet()
        {
            sbyte target = 0x01;

            //Act
            var actual = Bitmask.AnyBitSet(target, (byte)0x10);

            //Assert
            actual.Should().BeFalse();
        }
Exemplo n.º 14
0
        public void AnyBitSet_ByteHasSomeBitsSet()
        {
            byte target = 0x10;

            //Act
            var actual = Bitmask.AnyBitSet(target, (byte)0x11);

            //Assert
            actual.Should().BeTrue();
        }
Exemplo n.º 15
0
        public void AllBitsSet_SByteHasSomeBitsSet()
        {
            sbyte target = 0x01;

            //Act
            var actual = Bitmask.AllBitsSet(target, (sbyte)0x11);

            //Assert
            actual.Should().BeFalse();
        }
Exemplo n.º 16
0
        public void AllBitsSet_UInt64HasAllBitsSet()
        {
            ulong target = 0x00010100;

            //Act
            var actual = Bitmask.AllBitsSet(target, 0x00010100);

            //Assert
            actual.Should().BeTrue();
        }
Exemplo n.º 17
0
        public void AllBitsSet_UInt16HasAllBitsSet()
        {
            ushort target = 0x0101;

            //Act
            var actual = Bitmask.AllBitsSet(target, (ushort)0x0101);

            //Assert
            actual.Should().BeTrue();
        }
Exemplo n.º 18
0
    public static Bitmask FromString(string line)
    {
        var mask = new Bitmask();

        for (var i = 0; i < BIT_COUNT; i++)
        {
            mask.Bits[i] = CharToState(line[line.Length - i - 1]);
        }
        return(mask);
    }
Exemplo n.º 19
0
        public void AnyBitSet_UInt64HasNoBitsSet()
        {
            ulong target = 0x00010000;

            //Act
            var actual = Bitmask.AnyBitSet(target, 0x00001000);

            //Assert
            actual.Should().BeFalse();
        }
Exemplo n.º 20
0
        public void AnyBitSet_UInt16HasNoBitsSet()
        {
            ushort target = 0x0001;

            //Act
            var actual = Bitmask.AnyBitSet(target, (ushort)0x0100);

            //Assert
            actual.Should().BeFalse();
        }
Exemplo n.º 21
0
            public Codec(CacheBase Cache, int Address)
            {
                EndianReader Reader = Cache.Reader;

                Reader.SeekTo(Address);

                Unknown = Reader.ReadByte();
                Type    = (SoundType)Reader.ReadByte();
                Flags   = new Bitmask(Reader.ReadByte());
            }
Exemplo n.º 22
0
        public void AllBitsSet_Int16HasSomeBitsSet()
        {
            short target = 0x0001;

            //Act
            var actual = Bitmask.AllBitsSet(target, (short)0x0101);

            //Assert
            actual.Should().BeFalse();
        }
Exemplo n.º 23
0
        public void AllBitsSet_Int32HasSomeBitsSet()
        {
            int target = 0x00010000;

            //Act
            var actual = Bitmask.AllBitsSet(target, 0x00011000);

            //Assert
            actual.Should().BeFalse();
        }
Exemplo n.º 24
0
 void Awake()
 {
     MeshFilter meshFilter = gameObject.AddComponent<MeshFilter>();
     MeshRenderer meshRenderer = gameObject.AddComponent<MeshRenderer>();
     meshRenderer.material = material;
     MeshMaker2D meshMaker = new MeshMaker2D(Map2D.getWidth(), Map2D.getHeight(), alightment == Alignment.Centered);
     Mesh mesh = meshMaker.getMesh();
     Bitmask mapConverter = new Bitmask(Map2D.map);
     mesh.uv = meshMaker.getUVmap((int)atlasSize.x, (int)atlasSize.y, mapConverter.convertMap(), buffer);
     meshFilter.mesh = mesh;
 }
Exemplo n.º 25
0
		public void Count ()
		{
			Bitmask<long> x = new Bitmask<long> ();
			Assert.AreEqual (0, x.Count (), "0");
			x.SetAll ();
			Assert.AreEqual (64, x.Count (), "64");
			for (int i = 63; i >= 0; i--) {
				x.Clear (i);
				Assert.AreEqual (i, x.Count (), i.ToString ());
			}
		}
Exemplo n.º 26
0
        private static Bitmask <int> GetStringFormatExpectedParameters(string format)
        {
            Bitmask <int> result = new Bitmask <int> (false);

            if (format == null)
            {
                return(result);
            }

            // if last character is { then there's no digit after it
            for (int index = 0; index < format.Length - 1; index++)
            {
                if (format [index] != '{')
                {
                    continue;
                }

                char nextChar = format [index + 1];
                if (nextChar == '{')
                {
                    index++;                     // skip special {{
                    continue;
                }

                if (!char.IsDigit(nextChar))
                {
                    continue;
                }

                int value = nextChar - '0';

                index++;                 // next char is already added to value

                int tenPower = 1;
                while (index++ < format.Length)
                {
                    char current = format [index];
                    if (!char.IsDigit(current))
                    {
                        break;
                    }
                    tenPower *= 10;
                    value     = value * tenPower + current - '0';
                }

                if (index == format.Length)
                {
                    break;                     // Incorrect format
                }
                result.Set(value);
            }

            return(result);
        }
Exemplo n.º 27
0
        public void SetBits_UInt64SomeBitsWereSet()
        {
            ulong expected = 0x1111000011110000;
            ulong target   = 0x1111000011110000;
            ulong mask     = 0x1100000011000000;

            //Act
            var actual = Bitmask.SetBits(target, mask);

            //Assert
            actual.Should().Be(expected);
        }
Exemplo n.º 28
0
        public void SetBits_UInt32SomeBitsWereSet()
        {
            uint expected = 0x11110000;
            uint target   = 0x11110000;
            uint mask     = 0x11000000;

            //Act
            var actual = Bitmask.SetBits(target, mask);

            //Assert
            actual.Should().Be(expected);
        }
Exemplo n.º 29
0
        public void SetBits_UInt16NoBitsWereSet()
        {
            ushort expected = 0x1011;
            ushort target   = 0x1000;
            ushort mask     = 0x0011;

            //Act
            var actual = Bitmask.SetBits(target, mask);

            //Assert
            actual.Should().Be(expected);
        }
Exemplo n.º 30
0
        public void SetBits_Int32NoBitsWereSet()
        {
            int expected = 0x10101111;
            int target   = 0x10100000;
            int mask     = 0x00001111;

            //Act
            var actual = Bitmask.SetBits(target, mask);

            //Assert
            actual.Should().Be(expected);
        }
Exemplo n.º 31
0
        public void SetBits_Int16SomeBitsWereSet()
        {
            short expected = 0x1100;
            short target   = 0x1100;
            short mask     = 0x1000;

            //Act
            var actual = Bitmask.SetBits(target, mask);

            //Assert
            actual.Should().Be(expected);
        }
Exemplo n.º 32
0
        public void SetBits_ByteSomeBitsWereSet()
        {
            byte expected = 0x11;
            byte target   = 0x10;
            byte mask     = 0x11;

            //Act
            var actual = Bitmask.SetBits(target, mask);

            //Assert
            actual.Should().Be(expected);
        }
Exemplo n.º 33
0
		public void Intersect ()
		{
			Bitmask<long> x = new Bitmask<long> ();
			Assert.IsTrue (x.Intersect (null), "null"); // special case since they are equals
			Assert.IsFalse (x.Intersect (x), "self");

			Bitmask<long> all = new Bitmask<long> ();
			all.SetAll ();
			Assert.IsFalse (x.Intersect (all), "x N all");
			Assert.IsFalse (all.Intersect (x), "all N x");

			x.Set (0);
			Assert.IsTrue (x.Intersect (all), "1 N all");
			Assert.IsTrue (all.Intersect (x), "all N 1");

			Assert.IsTrue (x.Intersect (x), "self 1");
		}
Exemplo n.º 34
0
		public void BitmaskSeverity ()
		{
			Bitmask<Severity> x = new Bitmask<Severity> ();
			Assert.IsFalse (x.Get (Severity.Audit), "Empty/Audit");
			Assert.AreEqual (0, x.GetHashCode (), "Empty/GetHashCode");
			Assert.AreEqual ("0", x.ToString (), "Empty/ToString");
	
			x.Set (Severity.Audit);
			Assert.IsTrue (x.Get (Severity.Audit), "Set/Audit");
			Assert.AreEqual (16, x.GetHashCode (), "GetHashCode");
			Assert.AreEqual ("10000", x.ToString (), "ToString");
			Assert.IsTrue (x.Equals (x), "Equals(self)");
			Assert.IsTrue (x.Equals ((object) x), "Equals((object)self)");
			Assert.IsFalse (x.Equals (Severity.Audit), "Equals");

			x.Clear (Severity.Audit);
			Assert.IsFalse (x.Get (Severity.Audit), "Clear/Audit");
		}
Exemplo n.º 35
0
		public void IsSubsetOf ()
		{
			Bitmask<long> x = new Bitmask<long> ();
			Assert.IsFalse (x.IsSubsetOf (null), "null");
			Assert.IsTrue (x.IsSubsetOf (x), "self");

			Bitmask<long> all = new Bitmask<long> ();
			all.SetAll ();
			Assert.IsTrue (x.IsSubsetOf (all), "x < all");
			Assert.IsFalse (all.IsSubsetOf (x), "all < x");

			x.Set (0);
			Assert.IsTrue (x.IsSubsetOf (all), "1 < all");
			Assert.IsFalse (all.IsSubsetOf (x), "all < 1");

			Assert.IsTrue (x.IsSubsetOf (x), "self 1");
		}
Exemplo n.º 36
0
        /// <summary>
        /// The load ent controls.
        /// </summary>
        /// <param name="entArray">The ent array.</param>
        /// <remarks></remarks>
        private void LoadENTControls(object[] entArray)
        {
            this.selectedTagType = map.SelectedMeta.type;

            this.toolStripTagType.Text = "[" + this.selectedTagType + "]";
            this.toolStripTagName.Text = map.SelectedMeta.name;

            // this.Padding = new Padding(10);
            int colorSpaceCount = 4;

            // Custom Plugins access
            //ra = new RegistryAccess(
            //    Registry.CurrentUser,
            //    RegistryAccess.RegPaths.Halo2CustomPlugins + pluginName + "\\" + this.selectedTagType);
            //if (pluginName == null)
            //{
            //    ra.CloseReg();
            //}

            if (entArray != null)
                foreach (object o in entArray)
                {
                    IFPIO.BaseObject tempbase = (IFPIO.BaseObject)o;
                    if (tempbase.visible == false)
                    {
                        if (ShowInvisibles == false)
                        {
                            continue;
                        }
                    }

                    // skip hidden custom plugins variables (mark reflexives to be removed if empty)
                    bool skipEmptyReflex = false;
                    //if (ra.isOpen && ra.getValue(tempbase.offset.ToString()) == bool.FalseString)
                    //{
                    //    if (tempbase.ObjectType == IFPIO.ObjectEnum.Struct)
                    //    {
                    //        skipEmptyReflex = true;
                    //    }
                    //    else
                    //    {
                    //        continue;
                    //    }
                    //}

                    switch (tempbase.ObjectType)
                    {
                        case IFPIO.ObjectEnum.Struct:
                            {
                                if (ShowReflexives == false)
                                {
                                    break;
                                }

                                // tempLabel is a blank space located above reflexives
                                Label tempLabel = new Label();
                                tempLabel.AutoSize = true;
                                tempLabel.Location = new Point(0, 0);
                                tempLabel.Name = "label1";
                                tempLabel.Dock = DockStyle.Top;
                                tempLabel.Size = new Size(35, 13);
                                tempLabel.TabIndex = tabIndex;

                                // tempReflexive is the reflexive and all data (incl other reflexives) within it
                                ReflexiveControl tempReflexive = new ReflexiveControl(
                                    map,
                                    map.SelectedMeta.offset,
                                    ((IFPIO.Reflexive)tempbase).HasCount,
                                    tempbase.lineNumber,
                                    this);

                                // tempReflexive.Location = new System.Drawing.Point(10, 0);
                                tempReflexive.Name = "reflexive";
                                tempReflexive.TabIndex = tabIndex;
                                tempReflexive.LoadENTControls(
                                    (IFPIO.Reflexive)tempbase,
                                    ((IFPIO.Reflexive)tempbase).items,
                                    true,
                                    0,
                                    ref tabIndex,
                                    tempbase.offset.ToString());

                                // Label, Combobox & Button are always added ( = 3)
                                if (!(tempReflexive.Controls.Count <= 2 && skipEmptyReflex))
                                {
                                    this.Controls[0].Controls.Add(tempLabel);
                                    tempLabel.BringToFront();
                                    this.Controls[0].Controls.Add(tempReflexive);
                                    tempReflexive.BringToFront();
                                }

                                break;
                            }

                        case IFPIO.ObjectEnum.Ident:
                            {
                                if (ShowIdents == false)
                                {
                                    break;
                                }

                                Ident tempident = new Ident(
                                    tempbase.name,
                                    map,
                                    tempbase.offset,
                                    ((IFPIO.Ident)tempbase).hasTagType,
                                    tempbase.lineNumber);
                                tempident.Name = "ident";
                                tempident.TabIndex = tabIndex;
                                tempident.Populate(map.SelectedMeta.offset);
                                tempident.Tag = "[" + tempident.Controls[2].Text + "] " + tempident.Controls[1].Text;
                                tempident.Controls[1].ContextMenuStrip = identContext;
                                this.Controls[0].Controls.Add(tempident);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                break;
                            }

                        case IFPIO.ObjectEnum.StringID:
                            {
                                if (ShowSIDs == false)
                                {
                                    break;
                                }

                                SID tempSID = new SID(tempbase.name, map, tempbase.offset, tempbase.lineNumber);
                                tempSID.Name = "sid";
                                tempSID.TabIndex = tabIndex;
                                tempSID.Populate(map.SelectedMeta.offset);
                                this.Controls[0].Controls.Add(tempSID);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                break;
                            }

                        case IFPIO.ObjectEnum.Float:
                            {
                                if (ShowFloats == false)
                                {
                                    break;
                                }

                                DataValues tempFloat = new DataValues(
                                    tempbase.name, map, tempbase.offset, IFPIO.ObjectEnum.Float, tempbase.lineNumber);
                                tempFloat.TabIndex = tabIndex;
                                tempFloat.Populate(map.SelectedMeta.offset);
                                this.Controls[0].Controls.Add(tempFloat);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                break;
                            }

                        case IFPIO.ObjectEnum.String32:
                            {
                                if (ShowString32s == false && tempbase.ObjectType == IFPIO.ObjectEnum.String32)
                                {
                                    break;
                                }

                                EntStrings tempstring = new EntStrings(
                                    tempbase.name,
                                    map,
                                    tempbase.offset,
                                    ((IFPIO.IFPString)tempbase).size,
                                    ((IFPIO.IFPString)tempbase).type,
                                    tempbase.lineNumber);
                                tempstring.Name = "string";
                                tempstring.TabIndex = tabIndex;
                                tempstring.Populate(map.SelectedMeta.offset);
                                this.Controls[0].Controls.Add(tempstring);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                break;
                            }

                        case IFPIO.ObjectEnum.UnicodeString256:
                            {
                                if (ShowUnicodeString256s == false)
                                {
                                    break;
                                }

                                goto case IFPIO.ObjectEnum.String32;
                            }

                        case IFPIO.ObjectEnum.String256:
                            {
                                if (ShowString256s == false)
                                {
                                    break;
                                }

                                goto case IFPIO.ObjectEnum.String32;
                            }

                        case IFPIO.ObjectEnum.UnicodeString64:
                            {
                                if (ShowUnicodeString64s == false)
                                {
                                    break;
                                }

                                goto case IFPIO.ObjectEnum.String32;
                            }

                        case IFPIO.ObjectEnum.String:
                            {
                                if (ShowString32s == false && tempbase.ObjectType == IFPIO.ObjectEnum.String32)
                                {
                                    break;
                                }

                                EntStrings tempstring = new EntStrings(
                                    tempbase.name,
                                    map,
                                    tempbase.offset,
                                    ((IFPIO.IFPString)tempbase).size,
                                    ((IFPIO.IFPString)tempbase).type,
                                    tempbase.lineNumber);
                                tempstring.Name = "string";
                                tempstring.TabIndex = tabIndex;
                                tempstring.Populate(map.SelectedMeta.offset);
                                this.Controls[0].Controls.Add(tempstring);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                break;
                            }

                        case IFPIO.ObjectEnum.Int:
                            {
                                if (((IFPIO.IFPInt)tempbase).entIndex.nulled)
                                {
                                    if ((ShowInts == false && tempbase.ObjectType == IFPIO.ObjectEnum.Int) ||
                                        (ShowShorts == false && tempbase.ObjectType == IFPIO.ObjectEnum.Short) ||
                                        (ShowUshorts == false && tempbase.ObjectType == IFPIO.ObjectEnum.UShort) ||
                                        (ShowUints == false && tempbase.ObjectType == IFPIO.ObjectEnum.UInt))
                                    {
                                        break;
                                    }

                                    DataValues tempdatavalues = new DataValues(
                                        tempbase.name, map, tempbase.offset, tempbase.ObjectType, tempbase.lineNumber);
                                    tempdatavalues.TabIndex = tabIndex;
                                    tempdatavalues.Populate(map.SelectedMeta.offset);
                                    this.Controls[0].Controls.Add(tempdatavalues);
                                    this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                }
                                else
                                {
                                    if ((ShowBlockIndex32s == false &&
                                         (tempbase.ObjectType == IFPIO.ObjectEnum.Int |
                                          tempbase.ObjectType == IFPIO.ObjectEnum.UInt)) ||
                                        (ShowBlockIndex16s == false &&
                                         (tempbase.ObjectType == IFPIO.ObjectEnum.Short |
                                          tempbase.ObjectType == IFPIO.ObjectEnum.UShort)) ||
                                        (ShowBlockIndex8s == false && tempbase.ObjectType == IFPIO.ObjectEnum.Byte))
                                    {
                                        break;
                                    }

                                    Indices tempdatavalues = new Indices(
                                        tempbase.name,
                                        map,
                                        tempbase.offset,
                                        tempbase.ObjectType,
                                        ((IFPIO.IFPInt)tempbase).entIndex);
                                    tempdatavalues.TabIndex = tabIndex;
                                    this.Controls[0].Controls.Add(tempdatavalues);
                                    this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                }

                                break;
                            }

                        case IFPIO.ObjectEnum.Short:
                            {
                                goto case IFPIO.ObjectEnum.Int;
                            }

                        case IFPIO.ObjectEnum.UShort:
                            {
                                goto case IFPIO.ObjectEnum.Int;
                            }

                        case IFPIO.ObjectEnum.UInt:
                            {
                                goto case IFPIO.ObjectEnum.Int;
                            }

                        case IFPIO.ObjectEnum.Unknown:
                            {
                                if (ShowUndefineds == false)
                                {
                                    break;
                                }

                                DataValues tempUnknown = new DataValues(
                                    tempbase.name, map, tempbase.offset, IFPIO.ObjectEnum.Unknown, tempbase.lineNumber);
                                tempUnknown.TabIndex = tabIndex;
                                tempUnknown.Populate(map.SelectedMeta.offset);
                                this.Controls[0].Controls.Add(tempUnknown);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                break;
                            }

                        case IFPIO.ObjectEnum.Byte_Flags:
                            {
                                if (ShowBitmask8s == false)
                                {
                                    break;
                                }

                                Bitmask tempbitmask = new Bitmask(
                                    tempbase.name,
                                    map,
                                    tempbase.offset,
                                    ((IFPIO.Bitmask)tempbase).bitmaskSize,
                                    ((IFPIO.Bitmask)tempbase).options,
                                    tempbase.lineNumber);
                                tempbitmask.TabIndex = tabIndex;
                                tempbitmask.Populate(map.SelectedMeta.offset);
                                this.Controls[0].Controls.Add(tempbitmask);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                break;
                            }

                        case IFPIO.ObjectEnum.Word_Flags:
                            {
                                if (ShowBitmask16s == false)
                                {
                                    break;
                                }

                                Bitmask tempbitmask = new Bitmask(
                                    tempbase.name,
                                    map,
                                    tempbase.offset,
                                    ((IFPIO.Bitmask)tempbase).bitmaskSize,
                                    ((IFPIO.Bitmask)tempbase).options,
                                    tempbase.lineNumber);
                                tempbitmask.TabIndex = tabIndex;
                                tempbitmask.Populate(map.SelectedMeta.offset);
                                this.Controls[0].Controls.Add(tempbitmask);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                break;
                            }

                        case IFPIO.ObjectEnum.Long_Flags:
                            {
                                if (ShowBitmask32s == false)
                                {
                                    break;
                                }

                                Bitmask tempbitmask = new Bitmask(
                                    tempbase.name,
                                    map,
                                    tempbase.offset,
                                    ((IFPIO.Bitmask)tempbase).bitmaskSize,
                                    ((IFPIO.Bitmask)tempbase).options,
                                    tempbase.lineNumber);
                                tempbitmask.TabIndex = tabIndex;
                                tempbitmask.Populate(map.SelectedMeta.offset);
                                this.Controls[0].Controls.Add(tempbitmask);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                break;
                            }

                        case IFPIO.ObjectEnum.Char_Enum:
                            {
                                if (ShowEnum8s == false)
                                {
                                    break;
                                }

                                Enums tempenum = new Enums(
                                    tempbase.name,
                                    map,
                                    tempbase.offset,
                                    ((IFPIO.IFPEnum)tempbase).enumSize,
                                    ((IFPIO.IFPEnum)tempbase).options,
                                    tempbase.lineNumber);
                                tempenum.TabIndex = tabIndex;
                                tempenum.Populate(map.SelectedMeta.offset);
                                this.Controls[0].Controls.Add(tempenum);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                break;
                            }

                        case IFPIO.ObjectEnum.Enum:
                            {
                                if (ShowEnum16s == false)
                                {
                                    break;
                                }

                                Enums tempenum = new Enums(
                                    tempbase.name,
                                    map,
                                    tempbase.offset,
                                    ((IFPIO.IFPEnum)tempbase).enumSize,
                                    ((IFPIO.IFPEnum)tempbase).options,
                                    tempbase.lineNumber);
                                tempenum.TabIndex = tabIndex;
                                tempenum.Populate(map.SelectedMeta.offset);
                                this.Controls[0].Controls.Add(tempenum);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                break;
                            }

                        case IFPIO.ObjectEnum.Long_Enum:
                            {
                                if (ShowEnum32s == false)
                                {
                                    break;
                                }

                                Enums tempenum = new Enums(
                                    tempbase.name,
                                    map,
                                    tempbase.offset,
                                    ((IFPIO.IFPEnum)tempbase).enumSize,
                                    ((IFPIO.IFPEnum)tempbase).options,
                                    tempbase.lineNumber);
                                tempenum.TabIndex = tabIndex;
                                tempenum.Populate(map.SelectedMeta.offset);
                                this.Controls[0].Controls.Add(tempenum);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                break;
                            }

                        case IFPIO.ObjectEnum.Byte:
                            {
                                if (((IFPIO.IFPByte)tempbase).entIndex.nulled)
                                {
                                    if (ShowBytes == false)
                                    {
                                        break;
                                    }

                                    DataValues tempByte = new DataValues(
                                        tempbase.name, map, tempbase.offset, IFPIO.ObjectEnum.Byte, tempbase.lineNumber);
                                    tempByte.TabIndex = tabIndex;
                                    this.Controls[0].Controls.Add(tempByte);
                                    this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                }
                                else
                                {
                                    if (ShowBlockIndex8s == false)
                                    {
                                        break;
                                    }

                                    Indices tempdatavalues = new Indices(
                                        tempbase.name,
                                        map,
                                        tempbase.offset,
                                        tempbase.ObjectType,
                                        ((IFPIO.IFPByte)tempbase).entIndex);
                                    tempdatavalues.TabIndex = tabIndex;
                                    this.Controls[0].Controls.Add(tempdatavalues);
                                    this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                }

                                break;
                            }

                        case IFPIO.ObjectEnum.Unused:
                            {
                                DataValues tempUnknown = new DataValues(
                                    tempbase.name, map, tempbase.offset, IFPIO.ObjectEnum.Unused, tempbase.lineNumber);
                                tempUnknown.TabIndex = tabIndex;
                                tempUnknown.Populate(map.SelectedMeta.offset);
                                this.Controls[0].Controls.Add(tempUnknown);
                                this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();
                                break;
                            }

                        case IFPIO.ObjectEnum.TagType:
                            continue;
                    }

                    if (!(tempbase is IFPIO.Reflexive))
                    {
                        ToolTip1.SetToolTip(this.Controls[0].Controls[0].Controls[0], "offset: " + tempbase.offset);
                    }

                    if (this.Controls[0].Controls.Count > 0 && this.Controls[0].Controls[0] is DataValues)
                    {
                        // if (((tempbase.name.ToLower().Contains(" a") & tempbase.name[tempbase.name.ToLower().IndexOf(" a")]) ||
                        // tempbase.name.ToLower().Contains("alpha"))& alphaControl == null)
                        if (ColorWheel.checkForColor(tempbase.name, alphaControl, " a", "alpha"))
                        {
                            alphaControl = (DataValues)this.Controls[0].Controls[0];
                            colorSpaceCount = 0;
                        }

                            // if (tempbase.name.ToLower().Contains(" r") & redControl == null)
                        else if (ColorWheel.checkForColor(tempbase.name, redControl, " r", "red"))
                        {
                            redControl = (DataValues)this.Controls[0].Controls[0];
                            colorSpaceCount = 0;
                        }

                            // if (tempbase.name.ToLower().Contains(" g") & greenControl == null)
                        else if (ColorWheel.checkForColor(tempbase.name, greenControl, " g", "green"))
                        {
                            greenControl = (DataValues)this.Controls[0].Controls[0];
                            colorSpaceCount = 0;
                        }

                            // if (tempbase.name.ToLower().Contains(" b") & blueControl == null)
                        else if (ColorWheel.checkForColor(tempbase.name, blueControl, " b", "blue"))
                        {
                            blueControl = (DataValues)this.Controls[0].Controls[0];
                            colorSpaceCount = 0;
                        }
                        else
                        {
                            colorSpaceCount++;
                            if (colorSpaceCount == 1)
                            {
                                alphaControl = null;
                                redControl = null;
                                greenControl = null;
                                blueControl = null;
                            }
                        }

                        if (redControl != null & greenControl != null & blueControl != null)
                        {
                            // Create the new ColorWheel class, indicating
                            // the locations of the color wheel itself, the
                            // brightness area, and the position of the selected color.
                            ColorWheel cw = new ColorWheel();

                            if (alphaControl != null)
                            {
                                cw.setTextBox(alphaControl.textBox1, Color.White);
                            }

                            cw.setTextBox(redControl.textBox1, Color.Red);
                            cw.setTextBox(greenControl.textBox1, Color.Green);
                            cw.setTextBox(blueControl.textBox1, Color.Blue);

                            // p.I.AddRange(new Rectangle[] { SelectedColorRectangle });
                            cw.Dock = DockStyle.Top;
                            this.Controls[0].Controls.Add(cw);
                            this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].BringToFront();

                            // Reset for next batch
                            colorSpaceCount++;
                            alphaControl = null;
                            redControl = null;
                            greenControl = null;
                            blueControl = null;
                        }
                    }
                    else
                    {
                        colorSpaceCount++;
                    }

                    tabIndex++;
                }

            //ra.CloseReg();
        }
		private static Bitmask<int> GetStringFormatExpectedParameters (string format)
		{
			Bitmask<int> result = new Bitmask<int> (false);

			if (format == null)
				return result;

			// if last character is { then there's no digit after it
			for (int index = 0; index < format.Length - 1; index++) {
				if (format [index] != '{')
					continue;

				char nextChar = format [index + 1];
				if (nextChar == '{') {
					index++; // skip special {{
					continue;
				}

				if (!char.IsDigit (nextChar))
					continue;

				int value = nextChar - '0';

				index++; // next char is already added to value

				int tenPower = 1;
				while (index++ < format.Length) {
					char current = format [index];
					if (!char.IsDigit (current))
						break;
					tenPower *= 10;
					value = value * tenPower + current - '0';
				}

				if (index == format.Length)
					break; // Incorrect format

				result.Set (value);
			}

			return result;
		}
Exemplo n.º 38
0
		public void SetClearAll ()
		{
			Bitmask<long> x = new Bitmask<long> ();
			for (int i = 0; i < 64; i++) {
				Assert.IsFalse (x.Get (i), "Default#" + i.ToString ());
			}
			x.SetAll ();
			for (int i = 0; i < 64; i++) {
				Assert.IsTrue (x.Get (i), "SetAll#" + i.ToString ());
			}
			x.ClearAll ();
			for (int i = 0; i < 64; i++) {
				Assert.IsFalse (x.Get (i), "ClearAll#" + i.ToString ());
			}
		}
 private void EnsureBitmasksPopulated()
 {
     using (Storage storage = new Storage())
     {
         if (storage.Bitmasks.Any()) return;
         long v = 1;
         foreach (var b in storage.Bitmasks)
         {
             storage.Bitmasks.Remove(b);
         }
         storage.SaveChanges();
         for (int r = 0; r < 63; ++r)
         {
             var b = new Bitmask { B1 = -(v << 1), B2 = v, B3 = v << 1 };
             storage.Bitmasks.Add(b);
             v <<= 1;
         }
         storage.SaveChanges();
     }
 }
Exemplo n.º 40
0
		public void SetUp ()
		{
			Bitmask<long> x = new Bitmask<long> (true);
			for (int i = 0; i < 64; i++) {
				Assert.IsTrue (x.Get (i), "true#" + i.ToString ());
			}
			x.ClearAll ();
			x.SetUp (16);
			for (int i = 0; i < 16; i++) {
				Assert.IsFalse (x.Get (i), "SetUp#" + i.ToString ());
			}
			for (int i = 16; i < 64; i++) {
				Assert.IsTrue (x.Get (i), "SetUp#" + i.ToString ());
			}
		}
Exemplo n.º 41
0
		public void SetDown ()
		{
			Bitmask<long> x = new Bitmask<long> (false);
			for (int i = 0; i < 64; i++) {
				Assert.IsFalse (x.Get (i), "false#" + i.ToString ());
			}
			x.SetDown (48);
			for (int i = 0; i <= 48; i++) {
				Assert.IsTrue (x.Get (i), "SetDown#" + i.ToString ());
			}
			for (int i = 49; i < 64; i++) {
				Assert.IsFalse (x.Get (i), "SetDown#" + i.ToString ());
			}
		}
Exemplo n.º 42
0
            /// <summary>
            /// The button 1_ click.
            /// </summary>
            /// <param name="sender">The sender.</param>
            /// <param name="e">The e.</param>
            /// <remarks></remarks>
            private void button1_Click(object sender, EventArgs e)
            {
                ControlSwapper parent = (ControlSwapper)this.Parent.Parent.Parent;

                // Add selected control
                IFPIO.Option[] options = null;
                //int strLength = 0;
                Control con = null;
                switch (((dataTypeStruct)comboBox1.SelectedItem).name.ToLower())
                {
                    /*
                    parent.splitContainer1.Panel2.Controls.Add(new DataValues(parent.name, null, parent.chunkoffset, IFPIO.ObjectEnum.Byte, parent.lineNum));
                    parent.splitContainer1.Panel2.Controls.Add(new DataValues(parent.name, null, parent.chunkoffset, IFPIO.ObjectEnum.Short, parent.lineNum));
                    parent.splitContainer1.Panel2.Controls.Add(new DataValues(parent.name, null, parent.chunkoffset, IFPIO.ObjectEnum.Int, parent.lineNum));
                    parent.splitContainer1.Panel2.Controls.Add(new DataValues(parent.name, null, parent.chunkoffset, IFPIO.ObjectEnum.Float, parent.lineNum));
                */
                    case "byte":
                    case "short":
                    case "ushort":
                    case "int":
                    case "uint":
                    case "float":
                    case "unknown":
                    case "unused":
                        con = new DataValues(
                            parent.name,
                            null,
                            parent.chunkoffset,
                            (IFPIO.ObjectEnum)
                            Enum.Parse(typeof(IFPIO.ObjectEnum), ((dataTypeStruct)comboBox1.SelectedItem).name, true),
                            parent.lineNum);
                        break;
                    case "char_enum":
                    case "enum":
                    case "long_enum":
                        options = new IFPIO.Option[((dataTypeStruct)comboBox1.SelectedItem).size << 3];

                        // Size * 8 bits
                        for (int x = 0; x < options.Length; x++)
                        {
                            options[x] = new IFPIO.Option("Bit " + x, x.ToString(), parent.lineNum);
                        }

                        if (parent.splitContainer1.Panel1.Controls[0] is Bitmask)
                        {
                            Bitmask b = (Bitmask)parent.splitContainer1.Panel1.Controls[0];
                            foreach (IFPIO.Option o in b.Options)
                            {
                                if (o.value < options.Length)
                                {
                                    options[o.value].name = o.name;
                                }
                            }
                        }

                        ;
                        if (parent.splitContainer1.Panel1.Controls[0] is Enums)
                        {
                            Enums en = (Enums)parent.splitContainer1.Panel1.Controls[0];
                            foreach (IFPIO.Option o in en.Options)
                            {
                                if (o.value < options.Length)
                                {
                                    options[o.value].name = o.name;
                                }
                            }
                        }

                        ;
                        con = new Enums(parent.name, null, parent.chunkoffset, options.Length, options, parent.lineNum);
                        break;
                    case "byte_flags":
                    case "word_flags":
                    case "long_flags":
                        options = new IFPIO.Option[((dataTypeStruct)comboBox1.SelectedItem).size << 3];

                        // Size * 8 bits
                        for (int x = 0; x < options.Length; x++)
                        {
                            options[x] = new IFPIO.Option("Bit " + x, x.ToString(), parent.lineNum);
                        }

                        if (parent.splitContainer1.Panel1.Controls[0] is Bitmask)
                        {
                            Bitmask b = (Bitmask)parent.splitContainer1.Panel1.Controls[0];
                            foreach (IFPIO.Option o in b.Options)
                            {
                                options[o.value].name = o.name;
                            }
                        }

                        ;
                        if (parent.splitContainer1.Panel1.Controls[0] is Enums)
                        {
                            Enums en = (Enums)parent.splitContainer1.Panel1.Controls[0];
                            foreach (IFPIO.Option o in en.Options)
                            {
                                options[o.value].name = o.name;
                            }
                        }

                        ;
                        con = new Bitmask(
                            parent.name, null, parent.chunkoffset, options.Length, options, parent.lineNum);
                        break;
                    case "stringid":
                        con = new SID(parent.name, null, parent.chunkoffset, parent.lineNum);
                        break;
                    case "string":
                        con = new EntStrings(
                            parent.name,
                            null,
                            parent.chunkoffset,
                            ((dataTypeStruct)comboBox1.SelectedItem).size,
                            false,
                            parent.lineNum);
                        break;
                    case "unicodestring":
                        con = new EntStrings(
                            parent.name,
                            null,
                            parent.chunkoffset,
                            ((dataTypeStruct)comboBox1.SelectedItem).size,
                            true,
                            parent.lineNum);
                        break;
                    case "block":
                        con = new TagBlock(parent.name, null, parent.chunkoffset, parent.lineNum);
                        break;
                    case "ident":
                        con = new Ident(parent.name, null, parent.chunkoffset, true, parent.lineNum);
                        break;
                    case "struct":

                        // Unhandled
                        //int ifkdn = 0;
                        break;
                    default:
                        {
                            return;
                        }
                }

                Button but = new Button();
                but.Dock = DockStyle.Right;
                but.Size = new Size(30, 30);
                but.Text = "-";
                but.Click += but_Click;

                if (con != null)
                {
                    con.Controls.Add(but);

                    // con.Enabled = false;
                    con.Dock = DockStyle.Top;
                    Point loc = con.Controls[con.Controls.Count - 2].Location;
                    loc.X -= 50;
                    con.Controls[con.Controls.Count - 2].Location = loc;

                    // con.TabIndex--;
                    parent.splitContainer1.Panel2.Controls.Add(con);
                    con.BringToFront();
                    ((ControlSwapper)this.TopLevelControl).newControlSize +=
                        ((ControlSwapper)this.TopLevelControl).getSizeOf(((dataTypeStruct)comboBox1.SelectedItem).name);
                    if (((ControlSwapper)this.TopLevelControl).label1.Text.Contains(" :: "))
                    {
                        ((ControlSwapper)this.TopLevelControl).label1.Text =
                            ((ControlSwapper)this.TopLevelControl).label1.Text.Remove(
                                ((ControlSwapper)this.TopLevelControl).label1.Text.IndexOf(" :: "));
                    }

                    ((ControlSwapper)this.TopLevelControl).label1.Text += " :: New Control Size : " +
                                                                          ((ControlSwapper)this.TopLevelControl).
                                                                              newControlSize;
                }

                parent.splitContainer1.Panel2.Controls[parent.splitContainer1.Panel2.Controls.IndexOf(this)].
                    BringToFront();
                parent.splitContainer1.Panel2.Controls[parent.splitContainer1.Panel2.Controls.IndexOf(this)].TabIndex++;
            }