public bool SelectItem(ServerItem item) { if (!this.Loaded) { return(false); } if (this.CurrentServerItem == item) { return(true); } int index; if (item == null || (index = this.serverItemListBox.Items.IndexOf(item)) == -1) { this.ResetControls(); return(false); } this.EditItem(item); this.editDuplicateItemMenuItem.Enabled = true; this.editReloadItemMenuItem.Enabled = true; this.optionsGroupBox.Enabled = true; this.appearanceGroupBox.Enabled = true; this.serverItemListBox.SelectedIndex = index; return(true); }
private void ReloadItem(ServerItem item) { if (!this.Loaded || item == null) { return; } // to avoid problems with events ServerItem tmpItem = this.CurrentServerItem; this.CurrentServerItem = null; ClientItem clientItem; if (this.CurrentPlugin.Instance.Items.TryGetValue(item.ClientId, out clientItem)) { Trace.WriteLine(string.Format("Reloading item id: {0}.", item.ID)); ushort tmpId = item.ID; item.CopyPropertiesFrom(clientItem); item.ID = tmpId; Buffer.BlockCopy(clientItem.SpriteHash, 0, item.SpriteHash, 0, clientItem.SpriteHash.Length); this.CurrentServerItem = tmpItem; } }
public void CreateEmptyOTB(string filePath, SupportedClient client, bool isTemporary = true) { ServerItem item = new ServerItem(); item.SpriteHash = new byte[16]; item.ClientId = 100; item.ID = 100; ServerItemList items = new ServerItemList(); items.MajorVersion = 3; items.MinorVersion = client.OtbVersion; items.BuildNumber = 1; items.ClientVersion = client.Version; items.Add(item); if (!File.Exists(filePath)) { using (File.Create(filePath)) { //// } } OtbWriter writer = new OtbWriter(items); if (writer.Write(filePath)) { this.Open(filePath); this.IsTemporary = isTemporary; this.Saved = !isTemporary; } }
private void ReloadSelectedItem() { ServerItem item = this.CurrentServerItem; this.ReloadItem(item); this.SelectItem(null); this.SelectItem(item); }
private ServerItem CopyItem(ServerItem item) { if (item == null) { return(null); } ServerItem copy = new ServerItem(item); copy.SpriteHash = new byte[16]; copy.ClientId = item.ClientId; Buffer.BlockCopy(item.SpriteHash, 0, copy.SpriteHash, 0, copy.SpriteHash.Length); return(copy); }
public ServerItem AddNewItem() { if (!this.Loaded) { return(null); } ServerItem item = this.CreateItem(); item.ID = (ushort)(this.serverItems.MaxId + 1); this.serverItems.Add(item); this.serverItemListBox.Add(item); this.SelectItem(item); this.itemsCountLabel.Text = this.serverItemListBox.Count + " Items"; Trace.WriteLine(string.Format("Create item id {0}", item.ID)); return(item); }
public bool DuplicateItem(ServerItem item) { if (!this.Loaded || item == null) { return(false); } ServerItem copyItem = this.CopyItem(item); copyItem.ID = (ushort)(this.serverItems.MaxId + 1); this.serverItems.Add(copyItem); this.serverItemListBox.Add(copyItem); this.SelectItem(copyItem); this.itemsCountLabel.Text = this.serverItemListBox.Count + " Items"; Trace.WriteLine(string.Format("Duplicated item id {0} to new item id {1}", item.ID, copyItem.ID)); return(true); }
public bool SelectItem(ushort sid) { if (!this.Loaded) { return(false); } if (sid >= this.serverItems.MinId && sid <= this.serverItems.MaxId) { ServerItem item = this.serverItems.Find(i => i.ID == sid); if (item != null) { return(this.SelectItem(item)); } } return(false); }
private bool CompareItem(ServerItem item, bool compareHash) { if (item.Type == ServerItemType.Deprecated) { return(true); } ClientItem clientItem; if (this.CurrentPlugin.Instance.Items.TryGetValue(item.ClientId, out clientItem)) { if (compareHash && !Utils.ByteArrayCompare(item.SpriteHash, clientItem.SpriteHash)) { return(false); } return(item.Equals(clientItem)); } return(false); }
private ServerItem CreateItem(Item item = null) { // create a new otb item ServerItem newItem = new ServerItem(); newItem.ID = (ushort)(this.serverItems.MaxId + 1); if (item != null) { newItem.CopyPropertiesFrom(item); newItem.ClientId = item.ID; newItem.SpriteHash = new byte[16]; Buffer.BlockCopy(item.SpriteHash, 0, newItem.SpriteHash, 0, newItem.SpriteHash.Length); } else { newItem.ClientId = this.serverItems.MinId; newItem.SpriteHash = new byte[16]; newItem.IsCustomCreated = true; } return(newItem); }
private void CandidatePictureBox_Click(object sender, EventArgs e) { if (this.CurrentServerItem != null) { ClientItemView box = (ClientItemView)sender; if (box.Tag is ServerItem) { ServerItem newItem = (ServerItem)box.Tag; ClientItem clientItem; if (!this.CurrentPlugin.Instance.Items.TryGetValue(newItem.ClientId, out clientItem)) { return; } if (!clientItem.Equals(this.CurrentServerItem)) { DialogResult result = MessageBox.Show( "The item attributes does not match the current information, would you like to continue anyway?", "Item attributes does not match", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result != DialogResult.Yes) { return; } } this.CurrentServerItem.PreviousClientId = this.CurrentServerItem.ClientId; this.CurrentServerItem.ClientId = clientItem.ID; this.EditItem(this.CurrentServerItem); } } }
public static bool Open(string filename, ref ServerItemList items) { FileStream fileStream = new FileStream(filename, FileMode.Open); try { using (OtbLoader reader = new OtbLoader(fileStream)) { //get root node BinaryReader nodeReader = reader.getRootNode(); if (nodeReader == null) { return(false); } nodeReader.ReadByte(); //first byte of otb is 0 nodeReader.ReadUInt32(); //4 bytes flags, unused byte attr = nodeReader.ReadByte(); if ((RootAttribute)attr == RootAttribute.ROOT_ATTR_VERSION) { UInt16 datalen = nodeReader.ReadUInt16(); if (datalen != 140) // 4 + 4 + 4 + 1 * 128 { Trace.WriteLine(String.Format("Size of version header is invalid, updated .otb version?")); return(false); } items.dwMajorVersion = nodeReader.ReadUInt32(); //major, file version items.dwMinorVersion = nodeReader.ReadUInt32(); //minor, client version items.dwBuildNumber = nodeReader.ReadUInt32(); //build number, revision nodeReader.BaseStream.Seek(128, SeekOrigin.Current); } nodeReader = reader.getChildNode(); if (nodeReader == null) { return(false); } do { ServerItem item = new ServerItem(); byte itemGroup = nodeReader.ReadByte(); switch ((ItemGroup)itemGroup) { case ItemGroup.NONE: item.type = ItemType.None; break; case ItemGroup.GROUND: item.type = ItemType.Ground; break; case ItemGroup.SPLASH: item.type = ItemType.Splash; break; case ItemGroup.FLUID: item.type = ItemType.Fluid; break; case ItemGroup.CONTAINER: item.type = ItemType.Container; break; case ItemGroup.DEPRECATED: item.type = ItemType.Deprecated; break; default: break; } ItemFlag flags = (ItemFlag)nodeReader.ReadUInt32(); item.isUnpassable = ((flags & ItemFlag.BLOCK_SOLID) == ItemFlag.BLOCK_SOLID); item.blockMissiles = ((flags & ItemFlag.BLOCK_MISSILE) == ItemFlag.BLOCK_MISSILE); item.blockPathfinder = ((flags & ItemFlag.BLOCK_PATHFINDER) == ItemFlag.BLOCK_PATHFINDER); item.isPickupable = ((flags & ItemFlag.PICKUPABLE) == ItemFlag.PICKUPABLE); item.isMoveable = ((flags & ItemFlag.MOVEABLE) == ItemFlag.MOVEABLE); item.isStackable = ((flags & ItemFlag.STACKABLE) == ItemFlag.STACKABLE); item.alwaysOnTop = ((flags & ItemFlag.ALWAYS_ON_TOP) == ItemFlag.ALWAYS_ON_TOP); item.isVertical = ((flags & ItemFlag.VERTICAL_WALL) == ItemFlag.VERTICAL_WALL); item.isHorizontal = ((flags & ItemFlag.HORIZONTAL_WALL) == ItemFlag.HORIZONTAL_WALL); item.isHangable = ((flags & ItemFlag.HANGABLE) == ItemFlag.HANGABLE); item.isRotatable = ((flags & ItemFlag.ROTABLE) == ItemFlag.ROTABLE); item.isReadable = ((flags & ItemFlag.READABLE) == ItemFlag.READABLE); item.multiUse = ((flags & ItemFlag.USEABLE) == ItemFlag.USEABLE); item.hasElevation = ((flags & ItemFlag.HAS_ELEVATION) == ItemFlag.HAS_ELEVATION); item.ignoreLook = ((flags & ItemFlag.IGNORE_LOOK) == ItemFlag.IGNORE_LOOK); item.allowDistRead = ((flags & ItemFlag.ALLOW_DISTANCE_READ) == ItemFlag.ALLOW_DISTANCE_READ); item.isAnimation = ((flags & ItemFlag.ANIMATION) == ItemFlag.ANIMATION); item.fullGround = ((flags & ItemFlag.FULL_GROUND) == ItemFlag.FULL_GROUND); while (nodeReader.PeekChar() != -1) { ItemAttribute attribute = (ItemAttribute)nodeReader.ReadByte(); UInt16 datalen = nodeReader.ReadUInt16(); switch (attribute) { case ItemAttribute.SERVER_ID: item.id = nodeReader.ReadUInt16(); break; case ItemAttribute.CLIENT_ID: item.spriteId = nodeReader.ReadUInt16(); break; case ItemAttribute.GROUND_SPEED: item.groundSpeed = nodeReader.ReadUInt16(); break; case ItemAttribute.NAME: item.name = new string(nodeReader.ReadChars(datalen)); break; case ItemAttribute.SPRITE_HASH: item.SpriteHash = nodeReader.ReadBytes(datalen); break; case ItemAttribute.MINIMAP_COLOR: item.minimapColor = nodeReader.ReadUInt16(); break; case ItemAttribute.MAX_READ_WRITE_CHARS: item.maxReadWriteChars = nodeReader.ReadUInt16(); break; case ItemAttribute.MAX_READ_CHARS: item.maxReadChars = nodeReader.ReadUInt16(); break; case ItemAttribute.LIGHT: item.lightLevel = nodeReader.ReadUInt16(); item.lightColor = nodeReader.ReadUInt16(); break; case ItemAttribute.TOP_ORDER: item.alwaysOnTopOrder = nodeReader.ReadByte(); break; case ItemAttribute.TRADE_AS: item.tradeAs = nodeReader.ReadUInt16(); break; default: nodeReader.BaseStream.Seek(datalen, SeekOrigin.Current); break; } } if (item.SpriteHash == null && item.type != ItemType.Deprecated) { item.SpriteHash = new byte[16]; } items.Add(item); nodeReader = reader.getNextNode(); } while (nodeReader != null); } } finally { fileStream.Close(); } return(true); }
private bool EditItem(ServerItem item) { this.CurrentServerItem = null; this.ResetDataBindings(this); this.ResetToolTips(); if (item == null) { return(false); } ClientItem clientItem; if (!this.CurrentPlugin.Instance.Items.TryGetValue(item.ClientId, out clientItem)) { return(false); } this.pictureBox.ClientItem = clientItem; if (!item.IsCustomCreated && item.SpriteHash != null && clientItem.SpriteHash != null) { this.pictureBox.BackColor = Utils.ByteArrayCompare(item.SpriteHash, clientItem.SpriteHash) ? Color.White : Color.Red; } this.typeCombo.Text = item.Type.ToString(); this.typeCombo.ForeColor = item.Type == clientItem.Type ? Color.Black : Color.Red; this.stackOrderComboBox.Text = item.StackOrder.ToString(); this.stackOrderComboBox.ForeColor = item.StackOrder == clientItem.StackOrder ? Color.Black : Color.Red; this.serverIdLbl.DataBindings.Add("Text", item, "ID"); this.clientIdUpDown.Minimum = this.serverItems.MinId; this.clientIdUpDown.Maximum = (this.CurrentPlugin.Instance.Items.Count + this.serverItems.MinId) - 1; this.clientIdUpDown.DataBindings.Add("Value", clientItem, "ID"); // Attributes this.AddBinding(this.unpassableCheck, "Checked", item, "Unpassable", item.Unpassable, clientItem.Unpassable); this.AddBinding(this.movableCheck, "Checked", item, "Movable", item.Movable, clientItem.Movable); this.AddBinding(this.blockMissilesCheck, "Checked", item, "BlockMissiles", item.BlockMissiles, clientItem.BlockMissiles); this.AddBinding(this.blockPathfinderCheck, "Checked", item, "BlockPathfinder", item.BlockPathfinder, clientItem.BlockPathfinder); this.AddBinding(this.forceUseCheckBox, "Checked", item, "ForceUse", item.ForceUse, clientItem.ForceUse); this.AddBinding(this.useableCheck, "Checked", item, "MultiUse", item.MultiUse, clientItem.MultiUse); this.AddBinding(this.pickupableCheck, "Checked", item, "Pickupable", item.Pickupable, clientItem.Pickupable); this.AddBinding(this.stackableCheck, "Checked", item, "Stackable", item.Stackable, clientItem.Stackable); this.AddBinding(this.readableCheck, "Checked", item, "Readable", item.Readable, clientItem.Readable); this.AddBinding(this.rotatableCheck, "Checked", item, "Rotatable", item.Rotatable, clientItem.Rotatable); this.AddBinding(this.hangableCheck, "Checked", item, "Hangable", item.Hangable, clientItem.Hangable); this.AddBinding(this.hookSouthCheck, "Checked", item, "HookSouth", item.HookSouth, clientItem.HookSouth); this.AddBinding(this.hookEastCheck, "Checked", item, "HookEast", item.HookEast, clientItem.HookEast); this.AddBinding(this.hasElevationCheck, "Checked", item, "HasElevation", item.HasElevation, clientItem.HasElevation); this.AddBinding(this.ignoreLookCheck, "Checked", item, "IgnoreLook", item.IgnoreLook, clientItem.IgnoreLook); this.AddBinding(this.fullGroundCheck, "Checked", item, "FullGround", item.FullGround, clientItem.FullGround); this.AddBinding(this.groundSpeedText, "Text", item, "GroundSpeed", item.GroundSpeed, clientItem.GroundSpeed, true); this.AddBinding(this.lightLevelText, "Text", item, "LightLevel", item.LightLevel, clientItem.LightLevel, true); this.AddBinding(this.lightColorText, "Text", item, "LightColor", item.LightColor, clientItem.LightColor, true); this.AddBinding(this.maxReadCharsText, "Text", item, "MaxReadChars", item.MaxReadChars, clientItem.MaxReadChars, true); this.AddBinding(this.maxReadWriteCharsText, "Text", item, "MaxReadWriteChars", item.MaxReadWriteChars, clientItem.MaxReadWriteChars, true); this.AddBinding(this.minimapColorText, "Text", item, "MinimapColor", item.MinimapColor, clientItem.MinimapColor, true); this.AddBinding(this.wareIdText, "Text", item, "TradeAs", item.TradeAs, clientItem.TradeAs, true); this.AddBinding(this.nameText, "Text", item, "Name", item.Name, clientItem.Name, true); this.candidatesButton.Enabled = false; for (int i = 0; i < this.candidatesTableLayoutPanel.ColumnCount; ++i) { ClientItemView box = (ClientItemView)this.candidatesTableLayoutPanel.GetControlFromPosition(i, 0); box.ClientItem = null; } if (this.PreviousPlugin != null) { ClientItem prevClientItem; if (this.PreviousPlugin.Instance.Items.TryGetValue(item.PreviousClientId, out prevClientItem)) { this.previousPictureBox.ClientItem = prevClientItem; if (prevClientItem.SpriteSignature != null) { // Sprite does not match, use the sprite signature to find possible candidates this.ShowSpriteCandidates(prevClientItem); } } else { this.previousPictureBox.ClientItem = null; } } this.CurrentServerItem = item; return(true); }
private void ToolsUpdateVersionMenuItem_Click(object sender, EventArgs e) { UpdateForm form = new UpdateForm(); form.MainForm = this; DialogResult result = form.ShowDialog(); if (result == DialogResult.OK) { // Update OTB Plugin updatePlugin = form.SelectedPlugin; SupportedClient updateClient = form.UpdateClient; if (updatePlugin == null) { return; } if (!this.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. ClientItems currentClientItems = this.CurrentPlugin.Instance.Items; this.GenerateSpriteSignatures(ref currentClientItems); ClientItems updateClientItems = updatePlugin.Instance.Items; this.GenerateSpriteSignatures(ref updateClientItems); } ClientItems currentItems = this.CurrentPlugin.Instance.Items; ClientItems updateItems = updatePlugin.Instance.Items; List <ushort> assignedSpriteIdList = new List <ushort>(); // store the previous plugin (so we can display previous sprite, and do other comparisions) this.PreviousPlugin = this.CurrentPlugin; // update the current plugin the one we are updating to this.CurrentPlugin = updatePlugin; // update version information this.serverItems.ClientVersion = updateClient.Version; this.serverItems.MinorVersion = updateClient.OtbVersion; this.serverItems.BuildNumber = this.serverItems.BuildNumber + 1; this.CurrentOtbVersion = this.serverItems.MinorVersion; // Most items does have the same sprite after an update, so lets try that first uint foundItemCounter = 0; foreach (ServerItem item in this.serverItems) { item.SpriteAssigned = false; if (item.Type == ServerItemType.Deprecated) { continue; } ClientItem updateClientItem; if (updateItems.TryGetValue(item.ClientId, out updateClientItem)) { bool compareResult = updateClientItem.Equals(item); if (Utils.ByteArrayCompare(updateClientItem.SpriteHash, item.SpriteHash)) { if (compareResult) { item.PreviousClientId = item.ClientId; item.ClientId = updateClientItem.ID; item.SpriteAssigned = true; assignedSpriteIdList.Add(updateClientItem.ID); ++foundItemCounter; // Trace.WriteLine(String.Format("Match found id: {0}, clientid: {1}", item.otb.id, item.dat.id)); } else { // Sprite matches, but not the other attributes. // Trace.WriteLine(String.Format("Attribute changes found id: {0}.", item.id)); } } } } if (updateSettingsForm.reassignUnmatchedSpritesCheck.Checked) { foreach (Item updateItem in updateItems.Values) { foreach (ServerItem item in this.serverItems) { if (item.Type == ServerItemType.Deprecated) { continue; } if (item.SpriteAssigned) { continue; } if (Utils.ByteArrayCompare(updateItem.SpriteHash, item.SpriteHash)) { if (updateItem.Equals(item)) { if (updateItem.ID != item.ClientId) { Trace.WriteLine(string.Format("New sprite found id: {0}, old: {1}, new: {2}.", item.ID, item.ClientId, updateItem.ID)); } item.PreviousClientId = item.ClientId; item.ClientId = updateItem.ID; item.SpriteAssigned = true; assignedSpriteIdList.Add(updateItem.ID); ++foundItemCounter; break; } } } } } Trace.WriteLine(string.Format("Found {0} of {1}.", foundItemCounter, this.serverItems.MaxId)); if (updateSettingsForm.reloadItemAttributesCheck.Checked) { uint reloadedItemCounter = 0; foreach (ServerItem item in this.serverItems) { if (item.Type == ServerItemType.Deprecated) { continue; } // implicit assigned item.PreviousClientId = item.ClientId; item.SpriteAssigned = true; if (!assignedSpriteIdList.Contains(item.ClientId)) { assignedSpriteIdList.Add(item.ClientId); } if (!this.CompareItem(item, true)) { // sync with dat info this.ReloadItem(item); ++reloadedItemCounter; } } Trace.WriteLine(string.Format("Reloaded {0} of {1} items.", reloadedItemCounter, this.serverItems.MaxId)); } if (updateSettingsForm.createNewItemsCheck.Checked) { uint newItemCounter = 0; foreach (Item updateItem in updateItems.Values) { if (!assignedSpriteIdList.Contains(updateItem.ID)) { ++newItemCounter; ServerItem newItem = this.CreateItem(updateItem); this.serverItems.Add(newItem); Trace.WriteLine(string.Format("Creating item id {0}", newItem.ID)); } } Trace.WriteLine(string.Format("Created {0} new items.", newItemCounter)); } // done this.BuildItemsListBox(); } }