private void btnImportMultis_Click(object sender, EventArgs e) { string inp = Microsoft.VisualBasic.Interaction.InputBox("Paste the raw, colon-delimited packet data here: ", "Enter packet data"); if (inp.Length == 0) return; inp = inp.Replace(":", ""); if (inp.Length%2 != 0) return; inp = inp.Substring(4); byte[] data = new byte[inp.Length / 2]; for (int i = 0; i < inp.Length; i += 2) data[i/2] = Convert.ToByte(inp.Substring(i, 2), 16); //no need to decrypt since it's init data Packet pkt = new Packet(data); pkt.Skip(3); txtDMulti.Text = pkt.GetByte().ToString(); txtEMulti.Text = pkt.GetByte().ToString(); m_processor.RecvMulti = pkt.Get()[5]; m_processor.SendMulti = pkt.Get()[6]; }
private void Load(string fileName) { Rid = new byte[4]; Name = String.Empty; NPCSpawns = new List<NPCSpawn>(); Unknowns = new List<byte[]>(); Chests = new List<MapChest>(); TileRows = new List<TileRow>(); WarpRows = new List<WarpRow>(); GfxRows = new List<GFXRow>[(int)MapLayers.NUM_LAYERS]; Signs = new List<MapSign>(); for (int layer = (int)MapLayers.GroundTile; layer < (int)MapLayers.NUM_LAYERS; ++layer) { GfxRows[layer] = new List<GFXRow>(); } Packet file = new Packet(File.ReadAllBytes(fileName)); if (file.Length == 0) throw new FileLoadException("The file is empty."); file.ReadPos = 0; //use packet wrapper for convenience functions/decoding if (file.GetFixedString(3) != "EMF") throw new Exception("Corrupt or not an EMF file"); FileSize = file.Length; Rid = file.GetBytes(4); byte[] rawname = file.GetBytes(24); Name = _decodeMapString(rawname); //account for override in Rid to make a map PK - byte 0 is 0xff and byte 1 is 0x01 IsPK = (pkByte = file.GetChar()) == 3 || (Rid[0] == 0xff && Rid[1] == 0x01); Effect = (MapEffect)file.GetChar(); Music = file.GetChar(); MusicExtra = file.GetChar(); AmbientNoise = file.GetShort(); Width = file.GetChar(); Height = file.GetChar(); FillTile = file.GetShort(); MapAvailable = (availByte = file.GetChar()) == 1; CanScroll = (scrollByte = file.GetChar()) == 1; RelogX = file.GetChar(); RelogY = file.GetChar(); Unknown2 = file.GetChar(); WarpLookup = new Warp[Height + 1, Width + 1]; TileLookup = new Tile[Height + 1, Width + 1]; int innersize; int outersize = file.GetChar(); for (int i = 0; i < outersize; ++i) { NPCSpawns.Add(new NPCSpawn { x = file.GetChar(), y = file.GetChar(), id = file.GetShort(), spawnType = file.GetChar(), spawnTime = file.GetShort(), amount = file.GetChar() }); } outersize = file.GetChar(); for (int i = 0; i < outersize; ++i) { Unknowns.Add(file.GetBytes(4)); } outersize = file.GetChar(); for (int i = 0; i < outersize; ++i) { Chests.Add(new MapChest { x = file.GetChar(), y = file.GetChar(), key = (ChestKey)file.GetShort(), slot = file.GetChar(), item = file.GetShort(), time = file.GetShort(), amount = file.GetThree() }); } outersize = file.GetChar(); for (int i = 0; i < outersize; ++i) { byte y = file.GetChar(); innersize = file.GetChar(); TileRow row = new TileRow { y = y, tiles = new List<Tile>(innersize) }; for (int ii = 0; ii < innersize; ++ii) { Tile t; row.tiles.Add(t = new Tile { x = file.GetChar(), spec = (TileSpec)file.GetChar() }); TileLookup[row.y, t.x] = t; } TileRows.Add(row); } outersize = file.GetChar(); for (int i = 0; i < outersize; ++i) { byte y = file.GetChar(); innersize = file.GetChar(); WarpRow row = new WarpRow { y = y, tiles = new List<Warp>(innersize) }; for (int ii = 0; ii < innersize; ++ii) { Warp w; row.tiles.Add(w = new Warp { x = file.GetChar(), warpMap = file.GetShort(), warpX = file.GetChar(), warpY = file.GetChar(), levelRequirement = file.GetChar(), door = (DoorSpec)file.GetShort() }); if (row.y <= Height && w.x <= Width) WarpLookup[row.y, w.x] = w; } WarpRows.Add(row); } GFXLookup = new List<int[,]>((int)MapLayers.NUM_LAYERS); for (int i = 0; i < (int)MapLayers.NUM_LAYERS; ++i) { GFXLookup.Add(new int[Height + 1, Width + 1]); for (int row = 0; row <= Height; row++) { for (int col = 0; col <= Width; col++) { GFXLookup[i][row, col] = -1; } } } for (int layer = 0; layer < (int)MapLayers.NUM_LAYERS; ++layer) { if (file.ReadPos == file.Length) break; outersize = file.GetChar(); GfxRows[layer] = new List<GFXRow>(outersize); for (int i = 0; i < outersize; ++i) { byte y = file.GetChar(); innersize = file.GetChar(); GFXRow row = new GFXRow { y = y, tiles = new List<GFX>(innersize) }; for (int ii = 0; ii < innersize; ++ii) { byte tempx = file.GetChar(); ushort temptile = (ushort)file.GetShort(); if (row.y <= Height && tempx <= Width) { GFXLookup[layer][row.y, tempx] = temptile; } row.tiles.Add(new GFX { x = tempx, tile = temptile }); } GfxRows[layer].Add(row); } } if (file.ReadPos == file.Length) return; outersize = file.GetChar(); for (int i = 0; i < outersize; ++i) { MapSign sign = new MapSign {x = file.GetChar(), y = file.GetChar()}; int msgLength = file.GetShort() - 1; string data = _decodeMapString(file.GetBytes(msgLength)); int titleLength = file.GetChar(); sign.title = data.Substring(0, titleLength); sign.message = data.Substring(titleLength); Signs.Add(sign); } }
public void Save(string fileName) { Packet file = new Packet(PacketFamily.Internal, PacketAction.Server) {ReadPos = 0, WritePos = 0}; //map header file.AddString("EMF"); file.AddBytes(Rid); byte[] tmpName = _encodeMapString(Name); byte[] rawName = new byte[24]; for (int i = rawName.Length - 1; i >= 0; --i) rawName[i] = 0xFF; Array.Copy(tmpName, 0, rawName, rawName.Length - tmpName.Length, tmpName.Length); file.AddBytes(rawName); file.AddChar(pkByte); file.AddChar((byte)Effect); file.AddChar(Music); file.AddChar(MusicExtra); file.AddShort(AmbientNoise); file.AddChar(Width); file.AddChar(Height); file.AddShort(FillTile); file.AddChar(availByte); file.AddChar(scrollByte); file.AddChar(RelogX); file.AddChar(RelogY); file.AddChar(Unknown2); //NPC Spawns file.AddChar((byte)NPCSpawns.Count); foreach (NPCSpawn spawn in NPCSpawns) { file.AddChar(spawn.x); file.AddChar(spawn.y); file.AddShort(spawn.id); file.AddChar(spawn.spawnType); file.AddShort(spawn.spawnTime); file.AddChar(spawn.amount); } //unknowns file.AddChar((byte)Unknowns.Count); foreach(byte[] b in Unknowns) file.AddBytes(b); //chests file.AddChar((byte)Chests.Count); foreach (MapChest chest in Chests) { file.AddChar(chest.x); file.AddChar(chest.y); file.AddShort((short)chest.key); file.AddChar(chest.slot); file.AddShort(chest.item); file.AddShort(chest.time); file.AddThree(chest.amount); } //tile specs file.AddChar((byte)TileRows.Count); foreach (TileRow tr in TileRows) { file.AddChar(tr.y); file.AddChar((byte)tr.tiles.Count); foreach (Tile tt in tr.tiles) { file.AddChar(tt.x); file.AddChar((byte)tt.spec); } } //warps file.AddChar((byte)WarpRows.Count); foreach (WarpRow wr in WarpRows) { file.AddChar(wr.y); file.AddChar((byte)wr.tiles.Count); foreach (Warp ww in wr.tiles) { file.AddChar(ww.x); file.AddShort(ww.warpMap); file.AddChar(ww.warpX); file.AddChar(ww.warpY); file.AddChar(ww.levelRequirement); file.AddShort((short)ww.door); } } //gfx for (int layer = 0; layer < (int) MapLayers.NUM_LAYERS; ++layer) { file.AddChar((byte)GfxRows[layer].Count); foreach (GFXRow row in GfxRows[layer]) { file.AddChar(row.y); file.AddChar((byte)row.tiles.Count); foreach (GFX gfx in row.tiles) { file.AddChar(gfx.x); file.AddShort((short)gfx.tile); } } } //signs file.AddChar((byte)Signs.Count); foreach (MapSign sign in Signs) { file.AddChar(sign.x); file.AddChar(sign.y); file.AddShort((short)(sign.message.Length + sign.title.Length + 1)); byte[] fileMsg = new byte[sign.message.Length + sign.title.Length]; byte[] rawTitle = _encodeMapString(sign.title); byte[] rawMessage = _encodeMapString(sign.message); Array.Copy(rawTitle, fileMsg, fileMsg.Length); Array.Copy(rawMessage, 0, fileMsg, rawTitle.Length, rawMessage.Length); file.AddBytes(fileMsg); file.AddChar((byte)rawTitle.Length); } File.WriteAllBytes(fileName, file.Data); }
private void _checkRequiredInputs() { txtOutput.Text = ""; if (txtDMulti.TextLength == 0 || txtEMulti.TextLength == 0 || txtOffset.TextLength == 0) return; if (txtLength.TextLength == 0 && m_type == DataTypes.FixedString) return; string inputData = txtInputData.Text; if (inputData.Length == 0) return; //input data is copied from wireshark. colon delimited. string bytes = inputData.Replace(":", ""); string len = bytes.Substring(0, 4);//first 2 bytes are the length! bytes = bytes.Substring(4); byte[] data = new byte[bytes.Length / 2]; byte[] lenDat = new byte[2]; for (int i = 0; i < len.Length; i += 2) { lenDat[i/2] = Convert.ToByte(len.Substring(i, 2), 16); } lblPacketLength.Text = "Packet Length: " + Packet.DecodeNumber(lenDat).ToString(); for (int i = 0; i < bytes.Length; i += 2) { data[i/2] = Convert.ToByte(bytes.Substring(i, 2), 16); } m_processor.Decode(ref data); Packet pkt = new Packet(data) {ReadPos = m_packetOffset}; lblFamily.Text = pkt.Family.ToString(); lblAction.Text = pkt.Action.ToString(); string decoded = ""; for (int i = 0; i < data.Length; i++) { decoded += string.Format("{0} ", data[i].ToString("D3")); } txtDecoded.Text = decoded; switch ((DataTypes) cmbOutputFmt.SelectedIndex) { case DataTypes.None: txtOutput.Text = pkt.GetEndString(); break; case DataTypes.PacketFamily: txtOutput.Text = ((PacketFamily) pkt.PeekByte()).ToString(); break; case DataTypes.PacketAction: txtOutput.Text = ((PacketAction)pkt.PeekByte()).ToString(); break; case DataTypes.Byte: txtOutput.Text = pkt.PeekByte().ToString(); break; case DataTypes.Char: txtOutput.Text = pkt.PeekChar().ToString(); break; case DataTypes.Short: txtOutput.Text = pkt.PeekShort().ToString(); break; case DataTypes.Three: txtOutput.Text = pkt.PeekThree().ToString(); break; case DataTypes.Int: txtOutput.Text = pkt.PeekInt().ToString(); break; case DataTypes.BreakString: txtOutput.Text = pkt.PeekBreakString(); break; case DataTypes.EndString: txtOutput.Text = pkt.PeekEndString(); break; case DataTypes.FixedString: txtOutput.Text = pkt.PeekFixedString(m_dataLength); break; default: throw new ArgumentOutOfRangeException(); } int selLen; if (m_dataLength > 0) selLen = m_dataLength; else switch (m_type) { case DataTypes.EndString: selLen = 3*(pkt.Length - pkt.ReadPos) - 1; break; case DataTypes.BreakString: int oldPos = pkt.ReadPos; while (pkt.GetByte() != 255) ; selLen = pkt.ReadPos - oldPos; pkt.ReadPos = oldPos; break; default: selLen = 0; break; } txtDecoded.Select(4 * m_packetOffset, 4 * selLen - 1); if (m_type == DataTypes.EndString || m_type == DataTypes.BreakString) { m_suppressEvent = true; txtLength.Text = selLen.ToString(); m_suppressEvent = false; } }
private void _settingChange(object sender, EventArgs e) { if (sender == m_buttons[0]) { if (!m_soundChanged && !w.SoundEnabled) { EODialog.Show(DATCONST1.SETTINGS_SOUND_DISABLED, XNADialogButtons.OkCancel, EODialogStyle.SmallDialogSmallHeader, (o, args) => { if (args.Result == XNADialogResult.OK) { m_soundChanged = true; w.SoundEnabled = !w.SoundEnabled; World.Instance.ActiveMapRenderer.PlayOrStopAmbientNoise(); m_leftSide[0].Text = World.GetString(w.SoundEnabled ? DATCONST2.SETTING_ENABLED : DATCONST2.SETTING_DISABLED); } }); } else { if (!m_soundChanged) m_soundChanged = true; w.SoundEnabled = !w.SoundEnabled; World.Instance.ActiveMapRenderer.PlayOrStopAmbientNoise(); m_leftSide[0].Text = World.GetString(w.SoundEnabled ? DATCONST2.SETTING_ENABLED : DATCONST2.SETTING_DISABLED); } } else if (sender == m_buttons[1]) { if (!m_musicChanged && !w.MusicEnabled) { EODialog.Show(DATCONST1.SETTINGS_MUSIC_DISABLED, XNADialogButtons.OkCancel, EODialogStyle.SmallDialogSmallHeader, (o, args) => { if (args.Result == XNADialogResult.OK) { m_musicChanged = true; w.MusicEnabled = !w.MusicEnabled; World.Instance.ActiveMapRenderer.PlayOrStopBackgroundMusic(); m_leftSide[1].Text = World.GetString(w.MusicEnabled ? DATCONST2.SETTING_ENABLED : DATCONST2.SETTING_DISABLED); } }); } else { if (!m_musicChanged) m_musicChanged = true; w.MusicEnabled = !w.MusicEnabled; World.Instance.ActiveMapRenderer.PlayOrStopBackgroundMusic(); m_leftSide[1].Text = World.GetString(w.MusicEnabled ? DATCONST2.SETTING_ENABLED : DATCONST2.SETTING_DISABLED); } } else if (sender == m_buttons[2]) { m_keyboard++; if (m_keyboard > KeyLayout.Azerty) m_keyboard = 0; m_leftSide[2].Text = World.GetString(DATCONST2.SETTING_KEYBOARD_ENGLISH + (int)m_keyboard); } else if (sender == m_buttons[3]) { if(w.Language != EOLanguage.Portuguese) w.Language++; else w.Language = 0; _setTextForLanguage(); //need to reset all strings when language changes } else if (sender == m_buttons[4]) { w.HearWhispers = !w.HearWhispers; m_leftSide[4].Text = World.GetString(w.HearWhispers ? DATCONST2.SETTING_ENABLED : DATCONST2.SETTING_DISABLED); Packet pkt = new Packet(PacketFamily.Global, w.HearWhispers ? PacketAction.Remove : PacketAction.Player); pkt.AddChar(w.HearWhispers ? (byte) 'n' : (byte) 'y'); w.Client.SendPacket(pkt); } else if (sender == m_buttons[5]) { w.ShowChatBubbles = !w.ShowChatBubbles; m_rightSide[0].Text = World.GetString(w.ShowChatBubbles ? DATCONST2.SETTING_ENABLED : DATCONST2.SETTING_DISABLED); } else if (sender == m_buttons[6]) { w.ShowShadows = !w.ShowShadows; m_rightSide[1].Text = World.GetString(w.ShowShadows ? DATCONST2.SETTING_ENABLED : DATCONST2.SETTING_DISABLED); } else if (sender == m_buttons[7]) { DATCONST2 str; if (w.StrictFilterEnabled) { w.StrictFilterEnabled = false; str = DATCONST2.SETTING_DISABLED; } else if (w.CurseFilterEnabled) { w.CurseFilterEnabled = false; w.StrictFilterEnabled = true; str = DATCONST2.SETTING_EXCLUSIVE; } else { w.CurseFilterEnabled = true; str = DATCONST2.SETTING_NORMAL; } m_rightSide[2].Text = World.GetString(str); } else if (sender == m_buttons[8]) { w.LogChatToFile = !w.LogChatToFile; m_rightSide[3].Text = World.GetString(w.LogChatToFile ? DATCONST2.SETTING_ENABLED : DATCONST2.SETTING_DISABLED); } else if (sender == m_buttons[9]) { w.Interaction = !w.Interaction; m_rightSide[4].Text = World.GetString(w.Interaction ? DATCONST2.SETTING_ENABLED : DATCONST2.SETTING_DISABLED); } }
private void _upgrade() { if (LockerUpgrades == 7) { EOMessageBox.Show(DATCONST1.LOCKER_UPGRADE_IMPOSSIBLE, XNADialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader); return; } int requiredGold = (LockerUpgrades + 1) * 1000; InventoryItem item = World.Instance.MainPlayer.ActiveCharacter.Inventory.Find(i => i.id == 1); if (item.amount < requiredGold) { EOMessageBox.Show(DATCONST1.WARNING_YOU_HAVE_NOT_ENOUGH, "gold", XNADialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader); return; } EOMessageBox.Show(DATCONST1.LOCKER_UPGRADE_UNIT, string.Format("{0} gold?", requiredGold), XNADialogButtons.OkCancel, EOMessageBoxStyle.SmallDialogSmallHeader, (o, e) => { if (e.Result == XNADialogResult.Cancel) return; Packet pkt = new Packet(PacketFamily.Locker, PacketAction.Buy); World.Instance.Client.SendPacket(pkt); }); }
public void SetSelectedTab(ChatTabs tabToSelect) { if ((ChatTabs) currentSelTab == ChatTabs.Global && tabToSelect != ChatTabs.Global) { Packet pkt = new Packet(PacketFamily.Global, PacketAction.Close); pkt.AddChar((byte) 'n'); World.Instance.Client.SendPacket(pkt); } else if(tabToSelect == ChatTabs.Global && (ChatTabs)currentSelTab != ChatTabs.Global) { Packet pkt = new Packet(PacketFamily.Global, PacketAction.Open); pkt.AddChar((byte) 'y'); World.Instance.Client.SendPacket(pkt); } tabs[currentSelTab].Selected = false; tabs[currentSelTab = (int)tabToSelect].Selected = true; }