Example #1
0
        private void OnIndexChangedSec(object sender, EventArgs e)
        {
            if ((listBoxSec.SelectedIndex == -1) || (listBoxSec.Items.Count < 1))
            {
                return;
            }

            int i   = int.Parse(listBoxSec.Items[listBoxSec.SelectedIndex].ToString());
            int pos = listBoxOrg.Items.IndexOf(i);

            if (pos >= 0)
            {
                listBoxOrg.SelectedIndex = pos;
            }
            if (SecondArt.IsValidStatic(i))
            {
                Bitmap bmp = SecondArt.GetStatic(i);
                if (bmp != null)
                {
                    pictureBoxSec.BackgroundImage = bmp;
                }
                else
                {
                    pictureBoxSec.BackgroundImage = null;
                }
            }
            else
            {
                pictureBoxSec.BackgroundImage = null;
            }
            listBoxSec.Invalidate();
        }
Example #2
0
        public static Bitmap GetStatic(int index)
        {
            index  = SecondArt.GetLegalItemID(index);
            index += 0x4000;

            if (m_Cache[index] != null)
            {
                return(m_Cache[index]);
            }

            int    length, extra;
            Stream stream = m_FileIndex.Seek(index, out length, out extra);

            if (stream == null)
            {
                return(null);
            }

            if (Files.CacheData)
            {
                return(m_Cache[index] = LoadStatic(stream, length));
            }
            else
            {
                return(LoadStatic(stream, length));
            }
        }
Example #3
0
        private void DrawItemSec(object sender, DrawItemEventArgs e)
        {
            if (e.Index == -1)
            {
                return;
            }

            Brush fontBrush = Brushes.Gray;

            int i = int.Parse(listBoxSec.Items[e.Index].ToString());

            if (listBoxSec.SelectedIndex == e.Index)
            {
                e.Graphics.FillRectangle(Brushes.LightSteelBlue, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
            }
            if (!SecondArt.IsValidStatic(i))
            {
                fontBrush = Brushes.Red;
            }
            else if (!Compare(i))
            {
                fontBrush = Brushes.Blue;
            }

            e.Graphics.DrawString(String.Format("0x{0:X}", i), Font, fontBrush,
                                  new PointF((float)5,
                                             e.Bounds.Y + ((e.Bounds.Height / 2) -
                                                           (e.Graphics.MeasureString(String.Format("0x{0:X}", i), Font).Height / 2))));
        }
Example #4
0
        public static unsafe bool IsValidStatic(int index)
        {
            index  = SecondArt.GetLegalItemID(index);
            index += 0x4000;

            if (m_Cache[index] != null)
            {
                return(true);
            }

            int    length, extra;
            Stream stream = m_FileIndex.Seek(index, out length, out extra);

            if (stream == null)
            {
                return(false);
            }

            if (Validbuffer == null)
            {
                Validbuffer = new byte[4];
            }
            stream.Seek(4, SeekOrigin.Current);
            stream.Read(Validbuffer, 0, 4);
            fixed(byte *b = Validbuffer)
            {
                short *dat = (short *)b;

                if (*dat++ <= 0 || *dat <= 0)
                {
                    return(false);
                }
                return(true);
            }
        }
Example #5
0
        private void OnClickCopy(object sender, EventArgs e)
        {
            if (listBoxSec.SelectedIndex == -1)
            {
                return;
            }
            int i = int.Parse(listBoxSec.Items[listBoxSec.SelectedIndex].ToString());

            if (!SecondArt.IsValidStatic(i))
            {
                return;
            }
            int staticlength = Art.GetMaxItemID() + 1;

            if (i >= staticlength)
            {
                return;
            }
            Bitmap copy = new Bitmap(SecondArt.GetStatic(i));

            Ultima.Art.ReplaceStatic(i, copy);
            FiddlerControls.Options.ChangedUltimaClass["Art"] = true;
            FiddlerControls.Events.FireItemChangeEvent(this, i);
            m_Compare[i] = true;
            listBoxOrg.BeginUpdate();
            bool done = false;

            for (int id = 0; id < staticlength; id++)
            {
                if (id > i)
                {
                    listBoxOrg.Items.Insert(id, i);
                    done = true;
                    break;
                }
                if (id == i)
                {
                    done = true;
                    break;
                }
            }
            if (!done)
            {
                listBoxOrg.Items.Add(i);
            }
            listBoxOrg.EndUpdate();
            listBoxOrg.Invalidate();
            listBoxSec.Invalidate();
            OnIndexChangedOrg(this, null);
        }
Example #6
0
        private void LoadSecond()
        {
            m_Compare.Clear();
            listBoxSec.BeginUpdate();
            listBoxSec.Items.Clear();
            List <object> cache        = new List <object>();
            int           staticlength = SecondArt.GetMaxItemID() + 1;

            for (int i = 0; i < staticlength; i++)
            {
                cache.Add(i);
            }
            listBoxSec.Items.AddRange(cache.ToArray());
            listBoxSec.EndUpdate();
        }
Example #7
0
        private void OnClickLoadSecond(object sender, EventArgs e)
        {
            if (textBoxSecondDir.Text == null)
            {
                return;
            }
            string path  = textBoxSecondDir.Text;
            string file  = Path.Combine(path, "art.mul");
            string file2 = Path.Combine(path, "artidx.mul");

            if ((File.Exists(file)) && (File.Exists(file2)))
            {
                SecondArt.SetFileIndex(file2, file);
                LoadSecond();
            }
        }
Example #8
0
        public static byte[] GetRawStatic(int index)
        {
            index  = SecondArt.GetLegalItemID(index);
            index += 0x4000;

            int    length, extra;
            Stream stream = m_FileIndex.Seek(index, out length, out extra);

            if (stream == null)
            {
                return(null);
            }
            byte[] buffer = new byte[length];
            stream.Read(buffer, 0, length);
            return(buffer);
        }
Example #9
0
        private void LoadSecond()
        {
            m_Compare.Clear();
            listBoxSec.BeginUpdate();
            listBoxSec.Items.Clear();
            List <object> cache        = new List <object>();
            int           staticlength = 0x4000;

            if (SecondArt.IsUOSA())
            {
                staticlength = 0x8000;
            }
            for (int i = 0; i < staticlength; i++)
            {
                cache.Add(i);
            }
            listBoxSec.Items.AddRange(cache.ToArray());
            listBoxSec.EndUpdate();
        }
Example #10
0
        private bool Compare(int index)
        {
            if (m_Compare.ContainsKey(index))
            {
                return(m_Compare[index]);
            }
            Bitmap bitorg = Art.GetLand(index);
            Bitmap bitsec = SecondArt.GetLand(index);

            if ((bitorg == null) && (bitsec == null))
            {
                m_Compare[index] = true;
                return(true);
            }
            if (((bitorg == null) || (bitsec == null)) ||
                (bitorg.Size != bitsec.Size))
            {
                m_Compare[index] = false;
                return(false);
            }

            byte[] btImage1 = new byte[1];
            btImage1 = (byte[])ic.ConvertTo(bitorg, btImage1.GetType());
            byte[] btImage2 = new byte[1];
            btImage2 = (byte[])ic.ConvertTo(bitsec, btImage2.GetType());

            string hash1string = BitConverter.ToString(shaM.ComputeHash(btImage1));
            string hash2string = BitConverter.ToString(shaM.ComputeHash(btImage2));

            bool res;

            if (hash1string != hash2string)
            {
                res = false;
            }
            else
            {
                res = true;
            }

            m_Compare[index] = res;
            return(res);
        }
Example #11
0
        private void OnChangeShowDiff(object sender, EventArgs e)
        {
            if (m_Compare.Count < 1)
            {
                if (checkBox1.Checked)
                {
                    MessageBox.Show("Second Item file is not loaded!");
                    checkBox1.Checked = false;
                }
                return;
            }

            listBoxOrg.BeginUpdate();
            listBoxSec.BeginUpdate();
            listBoxOrg.Items.Clear();
            listBoxSec.Items.Clear();
            List <object> cache        = new List <object>();
            int           staticlength = Math.Max(Art.GetMaxItemID(), SecondArt.GetMaxItemID());

            if (checkBox1.Checked)
            {
                for (int i = 0; i < staticlength; i++)
                {
                    if (!Compare(i))
                    {
                        cache.Add(i);
                    }
                }
            }
            else
            {
                for (int i = 0; i < staticlength; i++)
                {
                    cache.Add(i);
                }
            }
            listBoxOrg.Items.AddRange(cache.ToArray());
            listBoxSec.Items.AddRange(cache.ToArray());
            listBoxOrg.EndUpdate();
            listBoxSec.EndUpdate();
        }
Example #12
0
        private bool Compare(int index)
        {
            if (m_Compare.ContainsKey(index))
            {
                return(m_Compare[index]);
            }
            Bitmap bitorg = Art.GetStatic(index);
            Bitmap bitsec = SecondArt.GetStatic(index);

            if ((bitorg == null) && (bitsec == null))
            {
                m_Compare[index] = true;
                return(true);
            }
            if (((bitorg == null) || (bitsec == null)) ||
                (bitorg.Size != bitsec.Size))
            {
                m_Compare[index] = false;
                return(false);
            }

            byte[] btImage1 = new byte[1];
            btImage1 = (byte[])ic.ConvertTo(bitorg, btImage1.GetType());
            byte[] btImage2 = new byte[1];
            btImage2 = (byte[])ic.ConvertTo(bitsec, btImage2.GetType());

            byte[] checksum1 = shaM.ComputeHash(btImage1);
            byte[] checksum2 = shaM.ComputeHash(btImage2);
            bool   res       = true;

            for (int j = 0; j < checksum1.Length; ++j)
            {
                if (checksum1[j] != checksum2[j])
                {
                    res = false;
                    break;
                }
            }
            m_Compare[index] = res;
            return(res);
        }
Example #13
0
        private void ExportAsTiff(object sender, EventArgs e)
        {
            if (listBoxSec.SelectedIndex == -1)
            {
                return;
            }
            int i = int.Parse(listBoxSec.Items[listBoxSec.SelectedIndex].ToString());

            if (!SecondArt.IsValidStatic(i))
            {
                return;
            }
            string path     = FiddlerControls.Options.OutputPath;
            string FileName = Path.Combine(path, String.Format("Item(Sec) 0x{0:X}.tiff", i));

            SecondArt.GetStatic(i).Save(FileName, ImageFormat.Tiff);
            MessageBox.Show(
                String.Format("Item saved to {0}", FileName),
                "Saved",
                MessageBoxButtons.OK,
                MessageBoxIcon.Information,
                MessageBoxDefaultButton.Button1);
        }
Example #14
0
        private void ExportAsBmp(object sender, EventArgs e)
        {
            if (listBoxSec.SelectedIndex == -1)
            {
                return;
            }
            int i = int.Parse(listBoxSec.Items[listBoxSec.SelectedIndex].ToString());

            if (!SecondArt.IsValidStatic(i))
            {
                return;
            }
            string path     = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            string FileName = Path.Combine(path, String.Format("Item(Sec) 0x{0:X}.bmp", i));

            SecondArt.GetStatic(i).Save(FileName, ImageFormat.Bmp);
            MessageBox.Show(
                String.Format("Item saved to {0}", FileName),
                "Saved",
                MessageBoxButtons.OK,
                MessageBoxIcon.Information,
                MessageBoxDefaultButton.Button1);
        }