ByteArrayCompare() public static method

public static ByteArrayCompare ( byte a1, byte a2 ) : bool
a1 byte
a2 byte
return bool
コード例 #1
0
        private bool compareItem(OtbItem item, bool compareHash)
        {
            if (item.type == ItemType.Deprecated)
            {
                return(true);
            }

            SpriteItem spriteItem;

            if (currentPlugin.Instance.Items.TryGetValue(item.spriteId, out spriteItem))
            {
                if (compareHash && !Utils.ByteArrayCompare(item.spriteHash, spriteItem.spriteHash))
                {
                    return(false);
                }

                return(item.isEqual(spriteItem));
            }

            return(false);
        }
コード例 #2
0
        private void updateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            UpdateForm form = new UpdateForm();

            form.mainForm = this;

            DialogResult result = form.ShowDialog();

            if (result == DialogResult.OK)
            {
                //Update OTB
                Host.Types.Plugin updatePlugin = form.selectedPlugin;
                SupportedClient   updateClient = form.updateClient;

                if (updatePlugin == null)
                {
                    return;
                }

                if (!loadClient(updatePlugin, updateClient.otbVersion))
                {
                    return;
                }

                UpdateSettingsForm updateSettingsForm = new UpdateSettingsForm();
                result = updateSettingsForm.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }

                if (updateSettingsForm.generateSignatureCheck.Checked)
                {
                    //Calculate an image signature using fourier transformation and calculate a signature we can
                    //use to compare it to other images (kinda similar to md5 hash) except this
                    //can also be used to find images with some variation.
                    SpriteItems currentSpriteItems = currentPlugin.Instance.Items;
                    generateSpriteSignatures(ref currentSpriteItems);

                    SpriteItems updateSpriteItems = updatePlugin.Instance.Items;
                    generateSpriteSignatures(ref updateSpriteItems);
                }

                SpriteItems   currentItems         = currentPlugin.Instance.Items;
                SpriteItems   updateItems          = updatePlugin.Instance.Items;
                List <UInt16> assignedSpriteIdList = new List <UInt16>();

                //store the previous plugin (so we can display previous sprite, and do other comparisions)
                previousPlugin = currentPlugin;

                //update the current plugin the one we are updating to
                currentPlugin = updatePlugin;

                //update version information
                items.clientVersion  = updateClient.version;
                items.dwMinorVersion = updateClient.otbVersion;
                items.dwBuildNumber  = items.dwBuildNumber + 1;
                currentOtbVersion    = items.dwMinorVersion;

                //Most items does have the same sprite after an update, so lets try that first
                UInt32 foundItemCounter = 0;
                foreach (OtbItem item in items)
                {
                    item.spriteAssigned = false;

                    if (item.type == ItemType.Deprecated)
                    {
                        continue;
                    }

                    SpriteItem updateSpriteItem;
                    if (updateItems.TryGetValue(item.spriteId, out updateSpriteItem))
                    {
                        bool compareResult = updateSpriteItem.isEqual(item);

                        if (Utils.ByteArrayCompare(updateSpriteItem.spriteHash, item.spriteHash))
                        {
                            if (compareResult)
                            {
                                item.prevSpriteId   = item.spriteId;
                                item.spriteId       = updateSpriteItem.id;
                                item.spriteAssigned = true;

                                assignedSpriteIdList.Add(updateSpriteItem.id);
                                ++foundItemCounter;

                                if (showUpdateOutput)
                                {
                                    //Trace.WriteLine(String.Format("Match found id: {0}, clientid: {1}", item.otb.id, item.dat.id));
                                }
                            }
                            else
                            {
                                //Sprite matches, but not the other attributes.
                                if (showUpdateOutput)
                                {
                                    Trace.WriteLine(String.Format("Attribute changes found id: {0}", item.id));
                                }
                            }
                        }
                    }
                }

                if (updateSettingsForm.reassignUnmatchedSpritesCheck.Checked)
                {
                    foreach (Item updateItem in updateItems.Values)
                    {
                        foreach (OtbItem item in items)
                        {
                            if (item.type == ItemType.Deprecated)
                            {
                                continue;
                            }

                            if (item.spriteAssigned)
                            {
                                continue;
                            }

                            if (Utils.ByteArrayCompare(updateItem.spriteHash, item.spriteHash))
                            {
                                if (updateItem.isEqual(item))
                                {
                                    if (updateItem.id != item.spriteId)
                                    {
                                        if (showUpdateOutput)
                                        {
                                            Trace.WriteLine(String.Format("New sprite found id: {0}, old: {1}, new: {2}", item.id, item.spriteId, updateItem.id));
                                        }
                                    }

                                    item.prevSpriteId   = item.spriteId;
                                    item.spriteId       = updateItem.id;
                                    item.spriteAssigned = true;

                                    assignedSpriteIdList.Add(updateItem.id);
                                    ++foundItemCounter;
                                    break;
                                }
                            }
                        }
                    }
                }

                if (showUpdateOutput)
                {
                    Trace.WriteLine(String.Format("Found {0} of {1}", foundItemCounter, items.maxId));
                }

                if (updateSettingsForm.reloadItemAttributesCheck.Checked)
                {
                    UInt32 reloadedItemCounter = 0;
                    foreach (OtbItem item in items)
                    {
                        if (item.type == ItemType.Deprecated)
                        {
                            continue;
                        }

                        //implicit assigned
                        item.prevSpriteId   = item.spriteId;
                        item.spriteAssigned = true;

                        if (!assignedSpriteIdList.Contains(item.spriteId))
                        {
                            assignedSpriteIdList.Add(item.spriteId);
                        }

                        if (!compareItem(item, true))
                        {
                            //sync with dat info
                            reloadItem(item);
                            ++reloadedItemCounter;
                        }
                    }

                    if (showUpdateOutput)
                    {
                        Trace.WriteLine(String.Format("Reloaded {0} of {1}", reloadedItemCounter, items.maxId));
                    }
                }

                if (updateSettingsForm.createNewItemsCheck.Checked)
                {
                    UInt32 newItemCounter = 0;
                    foreach (Item updateItem in updateItems.Values)
                    {
                        if (!assignedSpriteIdList.Contains(updateItem.id))
                        {
                            ++newItemCounter;

                            UInt16 newId = createItem(updateItem);

                            if (showUpdateOutput)
                            {
                                Trace.WriteLine(String.Format("Creating item id {0}", newId));
                            }
                        }
                    }

                    if (showUpdateOutput)
                    {
                        Trace.WriteLine(String.Format("Created {0} new items", newItemCounter));
                    }
                }

                //done
                buildTreeView();
            }
        }
コード例 #3
0
        private bool showItem(OtbItem item)
        {
            currentItem = null;
            resetAllDatabindings(this);

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

            SpriteItem spriteItem;

            if (!currentPlugin.Instance.Items.TryGetValue(item.spriteId, out spriteItem))
            {
                return(false);
            }

            duplicateItemToolStripMenuItem.Enabled = true;

            drawSprite(pictureBox, spriteItem);
            if (!item.isCustomCreated && item.spriteHash != null && spriteItem.spriteHash != null)
            {
                pictureBox.BackColor = ((Utils.ByteArrayCompare(item.spriteHash, spriteItem.spriteHash) ? Color.White : Color.Red));
            }

            typeCombo.Text      = item.type.ToString();
            typeCombo.ForeColor = (item.type == spriteItem.type ? Color.Black : Color.Red);

            //
            serverIdLbl.DataBindings.Add("Text", item, "id");
            clientIdUpDown.Minimum = items.minId;
            clientIdUpDown.Maximum = items.maxId;
            clientIdUpDown.DataBindings.Add("Value", spriteItem, "id");

            //Options
            blockObjectCheck.DataBindings.Add("Checked", item, "blockObject");
            blockObjectCheck.ForeColor = (item.blockObject == spriteItem.blockObject ? Color.Black : Color.Red);

            blockProjectileCheck.DataBindings.Add("Checked", item, "blockProjectile");
            blockProjectileCheck.ForeColor = (item.blockProjectile == spriteItem.blockProjectile ? Color.Black : Color.Red);

            blockPathFindCheck.DataBindings.Add("Checked", item, "blockPathFind");
            blockPathFindCheck.ForeColor = (item.blockPathFind == spriteItem.blockPathFind ? Color.Black : Color.Red);

            moveableCheck.DataBindings.Add("Checked", item, "isMoveable");
            moveableCheck.ForeColor = (item.isMoveable == spriteItem.isMoveable ? Color.Black : Color.Red);

            hasHeightCheck.DataBindings.Add("Checked", item, "hasHeight");
            hasHeightCheck.ForeColor = (item.hasHeight == spriteItem.hasHeight ? Color.Black : Color.Red);

            pickupableCheck.DataBindings.Add("Checked", item, "isPickupable");
            pickupableCheck.ForeColor = (item.isPickupable == spriteItem.isPickupable ? Color.Black : Color.Red);

            hangableCheck.DataBindings.Add("Checked", item, "isHangable");
            hangableCheck.ForeColor = (item.isHangable == spriteItem.isHangable ? Color.Black : Color.Red);

            useableCheck.DataBindings.Add("Checked", item, "hasUseWith");
            useableCheck.ForeColor = (item.hasUseWith == spriteItem.hasUseWith ? Color.Black : Color.Red);

            rotatableCheck.DataBindings.Add("Checked", item, "isRotatable");
            rotatableCheck.ForeColor = (item.isRotatable == spriteItem.isRotatable ? Color.Black : Color.Red);

            stackableCheck.DataBindings.Add("Checked", item, "isStackable");
            stackableCheck.ForeColor = (item.isStackable == spriteItem.isStackable ? Color.Black : Color.Red);

            verticalCheck.DataBindings.Add("Checked", item, "isVertical");
            verticalCheck.ForeColor = (item.isVertical == spriteItem.isVertical ? Color.Black : Color.Red);

            walkStackCheck.DataBindings.Add("Checked", item, "walkStack");
            walkStackCheck.ForeColor = (item.walkStack == spriteItem.walkStack ? Color.Black : Color.Red);

            horizontalCheck.DataBindings.Add("Checked", item, "isHorizontal");
            horizontalCheck.ForeColor = (item.isHorizontal == spriteItem.isHorizontal ? Color.Black : Color.Red);

            alwaysOnTopCheck.DataBindings.Add("Checked", item, "alwaysOnTop");
            alwaysOnTopCheck.ForeColor = (item.alwaysOnTop == spriteItem.alwaysOnTop ? Color.Black : Color.Red);

            readableCheck.DataBindings.Add("Checked", item, "isReadable");
            readableCheck.ForeColor = (item.isReadable == spriteItem.isReadable ? Color.Black : Color.Red);

            speedText.DataBindings.Add("Text", item, "groundSpeed");
            speedText.ForeColor = (item.groundSpeed == spriteItem.groundSpeed ? Color.Black : Color.Red);

            topOrderText.DataBindings.Add("Text", item, "alwaysOnTopOrder");
            topOrderText.ForeColor = (item.alwaysOnTopOrder == spriteItem.alwaysOnTopOrder ? Color.Black : Color.Red);

            lightLevelText.DataBindings.Add("Text", item, "lightLevel");
            lightLevelText.ForeColor = (item.lightLevel == spriteItem.lightLevel ? Color.Black : Color.Red);

            lightColorText.DataBindings.Add("Text", item, "lightColor");
            lightColorText.ForeColor = (item.lightColor == spriteItem.lightColor ? Color.Black : Color.Red);

            maxReadCharsText.DataBindings.Add("Text", item, "maxReadChars");
            maxReadCharsText.ForeColor = (item.maxReadChars == spriteItem.maxReadChars ? Color.Black : Color.Red);

            maxReadWriteCharsText.DataBindings.Add("Text", item, "maxReadWriteChars");
            maxReadWriteCharsText.ForeColor = (item.maxReadWriteChars == spriteItem.maxReadWriteChars ? Color.Black : Color.Red);

            lookThroughCheck.DataBindings.Add("Checked", item, "lookThrough");
            lookThroughCheck.ForeColor = (item.lookThrough == spriteItem.lookThrough ? Color.Black : Color.Red);

            minimapColorText.DataBindings.Add("Text", item, "minimapColor");
            minimapColorText.ForeColor = (item.minimapColor == spriteItem.minimapColor ? Color.Black : Color.Red);

            wareIdText.DataBindings.Add("Text", item, "wareId");
            wareIdText.ForeColor = (item.wareId == spriteItem.wareId ? Color.Black : Color.Red);

            nameText.DataBindings.Add("Text", item, "name");
            nameText.ForeColor = (item.name.CompareTo(spriteItem.name) == 0 ? Color.Black : Color.Red);

            tableLayoutPanelCandidates.Visible = false;
            for (int i = 0; i < tableLayoutPanelCandidates.ColumnCount; ++i)
            {
                PictureBox box = (PictureBox)tableLayoutPanelCandidates.GetControlFromPosition(i, 0);
                box.Image = null;
            }

            if (previousPlugin != null)
            {
                SpriteItem prevSpriteItem;
                if (previousPlugin.Instance.Items.TryGetValue(item.prevSpriteId, out prevSpriteItem))
                {
                    drawSprite(prevPictureBox, prevSpriteItem);

                    if (prevSpriteItem.spriteSignature != null)
                    {
                        //Sprite does not match, use the sprite signature to find possible candidates
                        showSpriteCandidates(prevSpriteItem);
                    }
                }
                else
                {
                    prevPictureBox.Image = null;
                }
            }

            currentItem = item;
            return(true);
        }
コード例 #4
0
        private bool compareItems()
        {
            if (System.IO.File.Exists(file1Text.Text) && System.IO.File.Exists(file2Text.Text))
            {
                OtbList items1 = new OtbList();
                OtbList items2 = new OtbList();

                bool result;
                result = otb.open(file1Text.Text, ref items1, false);
                if (!result)
                {
                    MessageBox.Show("Could not open {0}", file1Text.Text);
                    return(false);
                }

                result = otb.open(file2Text.Text, ref items2, false);
                if (!result)
                {
                    MessageBox.Show("Could not open {0}", file2Text.Text);
                    return(false);
                }

                IEnumerator <OtbItem> enumerator1 = items1.GetEnumerator();
                IEnumerator <OtbItem> enumerator2 = items2.GetEnumerator();

                if (items1.Count != items2.Count)
                {
                    resultTextBox.AppendText(string.Format("Item count:  [{0}]/[{1}]" + Environment.NewLine, items1.Count, items2.Count));
                }

                while (enumerator1.MoveNext())
                {
                    if (!enumerator2.MoveNext())
                    {
                        return(false);
                    }

                    OtbItem item1 = enumerator1.Current;
                    OtbItem item2 = enumerator2.Current;

                    if (item1.spriteId != item2.spriteId)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} Sprite changed [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.spriteId, item2.spriteId));
                        continue;
                    }

                    if (item1.spriteHash != null && item2.spriteHash != null && !Utils.ByteArrayCompare(item1.spriteHash, item2.spriteHash))
                    {
                        resultTextBox.AppendText(string.Format("id: {0} Sprite updated" + Environment.NewLine, item1.id));
                    }

                    if (item1.type != item2.type)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} type [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.type, item2.type));
                    }

                    if (item1.alwaysOnTop != item2.alwaysOnTop)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} alwaysOnTop [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.alwaysOnTop, item2.alwaysOnTop));
                    }

                    if (item1.alwaysOnTopOrder != item2.alwaysOnTopOrder)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} alwaysOnTopOrder [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.alwaysOnTopOrder, item2.alwaysOnTopOrder));
                    }

                    if (item1.blockObject != item2.blockObject)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} blockObject [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.blockObject, item2.blockObject));
                    }

                    if (item1.blockPathFind != item2.blockPathFind)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} blockPathFind [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.blockPathFind, item2.blockPathFind));
                    }

                    if (item1.blockProjectile != item2.blockProjectile)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} blockProjectile [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.blockProjectile, item2.blockProjectile));
                    }

                    if (item1.groundSpeed != item2.groundSpeed)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} groundSpeed [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.groundSpeed, item2.groundSpeed));
                    }

                    if (item1.hasHeight != item2.hasHeight)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} hasHeight [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.hasHeight, item2.hasHeight));
                    }

                    if (item1.hasUseWith != item2.hasUseWith)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} Useable [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.hasUseWith, item2.hasUseWith));
                    }

                    if (item1.isHangable != item2.isHangable)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} isHangable [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.isHangable, item2.isHangable));
                    }

                    if (item1.isHorizontal != item2.isHorizontal)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} isHorizontal [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.isHorizontal, item2.isHorizontal));
                    }

                    if (item1.isMoveable != item2.isMoveable)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} isMoveable [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.isMoveable, item2.isMoveable));
                    }

                    if (item1.isPickupable != item2.isPickupable)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} isPickupable [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.isPickupable, item2.isPickupable));
                    }

                    if (item1.isReadable != item2.isReadable)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} isReadable [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.isReadable, item2.isReadable));
                    }

                    if (item1.isRotatable != item2.isRotatable)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} isRotatable [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.isRotatable, item2.isRotatable));
                    }

                    if (item1.isStackable != item2.isStackable)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} isStackable [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.isStackable, item2.isStackable));
                    }

                    if (item1.isVertical != item2.isVertical)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} isVertical [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.isVertical, item2.isVertical));
                    }

                    if (item1.lightColor != item2.lightColor)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} lightColor [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.lightColor, item2.lightColor));
                    }

                    if (item1.lightLevel != item2.lightLevel)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} lightLevel [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.lightLevel, item2.lightLevel));
                    }

                    if (item1.lookThrough != item2.lookThrough)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} lookThrough [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.lookThrough, item2.lookThrough));
                    }

                    if (item1.maxReadChars != item2.maxReadChars)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} maxReadChars [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.maxReadChars, item2.maxReadChars));
                    }

                    if (item1.maxReadWriteChars != item2.maxReadWriteChars)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} maxReadWriteChars [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.maxReadWriteChars, item2.maxReadWriteChars));
                    }

                    if (item1.minimapColor != item2.minimapColor)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} minimapColor [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.minimapColor, item2.minimapColor));
                    }

                    if (item1.name != item2.name)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} name [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.name, item2.name));
                    }

                    if (item1.walkStack != item2.walkStack)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} walkstack [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.walkStack, item2.walkStack));
                    }

                    if (item1.wareId != item2.wareId)
                    {
                        resultTextBox.AppendText(string.Format("id: {0} wareid [{1}]/[{2}]" + Environment.NewLine, item1.id, item1.wareId, item2.wareId));
                    }
                }

                if (resultTextBox.Text.Length == 0)
                {
                    MessageBox.Show("No differences found!");
                }

                return(true);
            }

            return(false);
        }