Пример #1
0
        /// <summary>
        /// Sets same <see cref="FEngColor"/> to a specific color.
        /// </summary>
        /// <param name="index">Index of the <see cref="FEngColor"/> to match.</param>
        /// <param name="newbase">New <see cref="FEngColor"/> to set.</param>
        /// <param name="keepalpha">True if alpha value should be kept; false otherwise.</param>
        public virtual void SetSame(int index, FEngColor newbase, bool keepalpha)
        {
            var excolor = this.GetColor(index);

            if (excolor == null)
            {
                throw new ArgumentException($"Color with index {index} does not exist.");
            }

            var sample = new FEngColor(null)
            {
                Alpha = excolor.Alpha,
                Red   = excolor.Red,
                Green = excolor.Green,
                Blue  = excolor.Blue
            };

            foreach (var color in this._colorinfo)
            {
                if (color == sample)
                {
                    color.Red   = newbase.Red;
                    color.Green = newbase.Green;
                    color.Blue  = newbase.Blue;
                    if (!keepalpha)
                    {
                        color.Alpha = newbase.Alpha;
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Deserializes byte array into an instance by loading data from the file provided.
        /// </summary>
        /// <param name="br"><see cref="BinaryReader"/> to read data with.</param>
        public override void Deserialize(BinaryReader br)
        {
            int size  = br.ReadInt32();
            var array = br.ReadBytes(size);

            array = Interop.Decompress(array);

            using var ms     = new MemoryStream(array);
            using var reader = new BinaryReader(ms);

            this.CollectionName = reader.ReadNullTermUTF8();
            var count = reader.ReadInt32();

            this._colorinfo.Capacity = count;

            for (int loop = 0; loop < count; ++loop)
            {
                var color = new FEngColor(this)
                {
                    Offset = reader.ReadUInt32(),
                    Alpha  = reader.ReadByte(),
                    Red    = reader.ReadByte(),
                    Green  = reader.ReadByte(),
                    Blue   = reader.ReadByte()
                };

                this._colorinfo.Add(color);
            }

            count      = reader.ReadInt32();
            this._data = reader.ReadBytes(count);
        }
Пример #3
0
        /// <summary>
        /// Disassembles array into <see cref="FNGroup"/> properties.
        /// </summary>
        /// <param name="br"><see cref="BinaryReader"/> to read <see cref="FNGroup"/> with.</param>
        public override void Disassemble(BinaryReader br)
        {
            var ID   = br.ReadUInt32();
            var size = br.ReadInt32();

            this._data = SAT.Decompress(br.ReadBytes(size), ID);

            using var ms     = new MemoryStream(this._data);
            using var reader = new BinaryReader(ms);

            reader.BaseStream.Position = 0x28;
            this.CollectionName        = reader.ReadNullTermUTF8().ToUpper();

            if (this.CollectionName.EndsWith(".FNG"))
            {
                this.CollectionName.GetFormattedValue("{X}.FNG", out string name);
                this.CollectionName = name;
            }

            reader.BaseStream.Position = 0x28;

            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                byte b1 = reader.ReadByte();
                byte b2 = reader.ReadByte();
                byte b3 = reader.ReadByte();
                byte b4 = reader.ReadByte();

                // SAT, SAD, SA(0x90) or 1111
                if ((b1 == 'S' && b2 == 'A') || (b1 == Byte.MaxValue && b2 == Byte.MaxValue &&
                                                 b3 == Byte.MaxValue && b4 == Byte.MaxValue))
                {
                    uint Offset = (uint)reader.BaseStream.Position;
                    uint Blue   = reader.ReadUInt32();
                    uint Green  = reader.ReadUInt32();
                    uint Red    = reader.ReadUInt32();
                    uint Alpha  = reader.ReadUInt32();

                    if (Blue <= Byte.MaxValue && Green <= Byte.MaxValue &&
                        Red <= Byte.MaxValue && Alpha <= Byte.MaxValue)
                    {
                        var color = new FEngColor(this)
                        {
                            Offset = Offset,
                            Blue   = (byte)Blue,
                            Green  = (byte)Green,
                            Red    = (byte)Red,
                            Alpha  = (byte)Alpha
                        };

                        this._colorinfo.Add(color);
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Disassembles frontend group array into separate properties.
        /// </summary>
        /// <param name="byteptr_t">Pointer to the frontend group array.</param>
        protected override unsafe void Disassemble(byte[] data)
        {
            this._DATA = new byte[data.Length];
            Buffer.BlockCopy(data, 0, this._DATA, 0, data.Length);

            fixed(byte *byteptr_t = &this._DATA[0])
            {
                this.Size = *(uint *)(byteptr_t + 4);

                // For some reason HUFF compression has the same ID as FEng files
                if (*(uint *)(byteptr_t + 8) == 0x46465548)
                {
                    this.Destroy = true;
                    return;
                }

                // Read CollectionName
                this.CollectionName = ScriptX.NullTerminatedString(byteptr_t + 0x30, this._DATA.Length - 0x30);
                if (this.CollectionName.EndsWith(".fng"))
                {
                    this.CollectionName = FormatX.GetString(this.CollectionName, "{X}.fng");
                }

                for (uint offset = 0x30; offset < this._DATA.Length; offset += 4)
                {
                    byte b1 = *(byteptr_t + offset);
                    byte b2 = *(byteptr_t + offset + 1);
                    byte b3 = *(byteptr_t + offset + 2);
                    byte b4 = *(byteptr_t + offset + 3);

                    // SAT, SAD, SA(0x90) or 1111
                    if ((b1 == 'S' && b2 == 'A') || (b1 == 0xFF && b2 == 0xFF && b3 == 0xFF && b4 == 0xFF))
                    {
                        uint Blue  = *(uint *)(byteptr_t + offset + 4);
                        uint Green = *(uint *)(byteptr_t + offset + 8);
                        uint Red   = *(uint *)(byteptr_t + offset + 12);
                        uint Alpha = *(uint *)(byteptr_t + offset + 16);

                        // If it is a color, add to the list
                        if (Resolve.IsColor(Alpha, Red, Green, Blue))
                        {
                            var TempColor = new FEngColor(this);
                            TempColor.Offset = offset;
                            TempColor.Alpha  = (byte)Alpha;
                            TempColor.Red    = (byte)Red;
                            TempColor.Green  = (byte)Green;
                            TempColor.Blue   = (byte)Blue;
                            this._colorinfo.Add(TempColor);
                        }
                        offset += 0x14;
                    }
                }
            }
        }
Пример #5
0
        private void ButtonOK_Click(object sender, EventArgs e)
        {
            string path = $"{eCommands.update} {FNGroups} {this._color.ThisFNGroup.CollectionName}";
            string hex  = SAT.ColorToHex(this.NewColorBox.BackColor.A, this.NewColorBox.BackColor.R,
                                         this.NewColorBox.BackColor.G, this.NewColorBox.BackColor.B);
            bool keepalpha = this.CheckKeepAlpha.Checked;

            if (this.CheckReplaceSame.Checked)
            {
                var newcolor = new FEngColor(null)
                {
                    Alpha = this.NewColorBox.BackColor.A,
                    Red   = this.NewColorBox.BackColor.R,
                    Green = this.NewColorBox.BackColor.G,
                    Blue  = this.NewColorBox.BackColor.B
                };
                this._color.ThisFNGroup.TrySetSame(this._index, newcolor, keepalpha);
                if (keepalpha)
                {
                    this.CommandProcessed = $"{path} {ReplaceSameNoAlpha}[{this._index}] {hex}";
                }
                else
                {
                    this.CommandProcessed = $"{path} {ReplaceSameWithAlpha}[{this._index}] {hex}";
                }
            }
            else
            {
                this._color.Alpha = this.NewColorBox.BackColor.A;
                this._color.Red   = this.NewColorBox.BackColor.R;
                this._color.Green = this.NewColorBox.BackColor.G;
                this._color.Blue  = this.NewColorBox.BackColor.B;
                if (this.CheckReplaceAll.Checked)
                {
                    this._color.ThisFNGroup.TrySetAll(this._color, keepalpha);
                    if (keepalpha)
                    {
                        this.CommandProcessed = $"{path} {ReplaceAllNoAlpha} {hex}";
                    }
                    else
                    {
                        this.CommandProcessed = $"{path} {ReplaceAllWithAlpha} {hex}";
                    }
                }
                else
                {
                    this.CommandProcessed = $"{path} Color[{this._index}] {hex}";
                }
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Пример #6
0
 /// <summary>
 /// Sets all <see cref="FEngColor"/> to a specific color.
 /// </summary>
 /// <param name="color"><see cref="FEngColor"/> to set for all colors.</param>
 /// <param name="keepalpha">True if alpha value should be kept; false otherwise.</param>
 public virtual void TrySetAll(FEngColor color, bool keepalpha)
 {
     foreach (var thiscolor in this._colorinfo)
     {
         thiscolor.Red   = color.Red;
         thiscolor.Green = color.Green;
         thiscolor.Blue  = color.Blue;
         if (!keepalpha)
         {
             thiscolor.Alpha = color.Alpha;
         }
     }
 }
Пример #7
0
        /// <summary>
        /// Sets new <see cref="FEngColor"/> at specific color.
        /// </summary>
        /// <param name="index">Index of the color to set.</param>
        /// <param name="color">New <see cref="FEngColor"/> to set.</param>
        public virtual void SetOne(int index, FEngColor color)
        {
            var thiscolor = this.GetColor(index);

            if (thiscolor == null)
            {
                throw new ArgumentException($"Color with index {index} does not exist");
            }

            thiscolor.Alpha = color.Alpha;
            thiscolor.Red   = color.Red;
            thiscolor.Green = color.Green;
            thiscolor.Blue  = color.Blue;
        }
Пример #8
0
 public FEngEditor(FEngColor color, int index)
 {
     this._color = color;
     this._index = index;
     this.InitializeComponent();
 }
Пример #9
0
        private static string ExecuteUpdateFNG(BasicBase db, string node, string field, string value)
        {
            if (!db.TryGetCollection(node, FNGroups, out var collection))
            {
                return($"Collection {node} does not exist in root {FNGroups}.");
            }
            if (!(collection is FNGroup fng))
            {
                return($"Collection {node} is not a {FNGroups} collection.");
            }

            if (!SAT.CanBeColor(value))
            {
                return($"Value {value} is not an 8-digit hexadecimal color-type.");
            }

            var color = new FEngColor(null);

            color.Alpha = SAT.GetAlpha(value);
            color.Red   = SAT.GetRed(value);
            color.Green = SAT.GetGreen(value);
            color.Blue  = SAT.GetBlue(value);

            if (field.StartsWith("ReplaceSame"))
            {
                if (field.StartsWith("ReplaceSameNoAlpha[") && field.EndsWith("]"))
                {
                    if (FormatX.GetInt32(field, "ReplaceSameNoAlpha[{X}]", out int index))
                    {
                        fng.TrySetSame(index, color, true);
                    }
                    else
                    {
                        return($"Unable to get color index from field named {field}.");
                    }
                }
                else if (field.StartsWith("ReplaceSameWithAlpha[") && field.EndsWith("]"))
                {
                    if (FormatX.GetInt32(field, "ReplaceSameWithAlpha[{X}]", out int index))
                    {
                        fng.TrySetSame(index, color, false);
                    }
                    else
                    {
                        return($"Unable to get color index from field named {field}.");
                    }
                }
                else
                {
                    return($"Incorrect passed parameter named {field}.");
                }
            }
            else if (field == "ReplaceAllNoAlpha")
            {
                fng.TrySetAll(color, true);
            }
            else if (field == "ReplaceAllWithAlpha")
            {
                fng.TrySetAll(color, false);
            }
            else
            {
                int index = SAT.GetIndex(field);
                if (index >= fng.InfoLength || index == -1)
                {
                    return($"Field named {field} does not exist.");
                }
                fng.TrySetOne(index, color);
            }
            return(null);
        }