예제 #1
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();
            }
        }
예제 #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();
            }
        }