override public MerchantManager GetMerchantData(NPCSpawnList npcsl) { List <EQApplicationPacket> PacketList = Packets.PacketList; UInt32 OP_ShopRequest = OpManager.OpCodeNameToNumber("OP_ShopRequest"); UInt32 OP_ShopEnd = OpManager.OpCodeNameToNumber("OP_ShopEnd"); UInt32 OP_ItemPacket = OpManager.OpCodeNameToNumber("OP_ItemPacket"); MerchantManager mm = new MerchantManager(); for (int i = 0; i < PacketList.Count; ++i) { EQApplicationPacket p = PacketList[i]; if ((p.Direction == PacketDirection.ServerToClient) && (p.OpCode == OP_ShopRequest)) { ByteStream Buffer = new ByteStream(p.Buffer); UInt32 MerchantSpawnID = Buffer.ReadUInt32(); NPCSpawn npc = npcsl.GetNPC(MerchantSpawnID); UInt32 NPCTypeID; if (npc != null) { NPCTypeID = npc.NPCTypeID; } else { NPCTypeID = 0; } mm.AddMerchant(MerchantSpawnID); for (int j = i + 1; j < PacketList.Count; ++j) { p = PacketList[j]; if (p.OpCode == OP_ShopEnd) { break; } if (p.OpCode == OP_ItemPacket) { Buffer = new ByteStream(p.Buffer); UInt32 StackSize = Buffer.ReadUInt32(); Buffer.SkipBytes(4); UInt32 Slot = Buffer.ReadUInt32(); UInt32 MerchantSlot = Buffer.ReadUInt32(); UInt32 Price = Buffer.ReadUInt32(); Int32 Quantity = Buffer.ReadInt32(); Buffer.SetPosition(68); // Point to item name string ItemName = Buffer.ReadString(true); string Lore = Buffer.ReadString(true); string IDFile = Buffer.ReadString(true); UInt32 ItemID = Buffer.ReadUInt32(); //if (Quantity == -1) mm.AddMerchantItem(MerchantSpawnID, ItemID, ItemName, MerchantSlot, Quantity); } } } } return(mm); }
private static void ProcessFiles(string src, string dst, bool singleFile) { string[] inFiles = singleFile ? new[] { src } : Directory.GetFiles(src, "*.emf"); for (int map = 0; map < inFiles.Length; ++map) { MapFile EMF = new MapFile(inFiles[map]); bool changesMade = false; string lastPart = inFiles[map].Substring(inFiles[map].Contains('\\') ? inFiles[map].LastIndexOf('\\') + 1 : 0, inFiles[map].Length - inFiles[map].LastIndexOf('\\') - 1); for (int i = EMF.TileRows.Count - 1; i >= 0; --i) { TileRow tr = EMF.TileRows[i]; for (int j = tr.tiles.Count - 1; j >= 0; --j) { Tile tt = tr.tiles[j]; if (tt.x > EMF.Width || tr.y > EMF.Height) { Console.WriteLine("[MAP {3}] Tile {0}x{1} ({2}) is out of map bounds. Removing.", tt.x, tr.y, Enum.GetName(typeof(TileSpec), tt.spec), lastPart); tr.tiles.RemoveAt(j); changesMade = true; } } } for (int i = EMF.WarpRows.Count - 1; i >= 0; --i) { WarpRow tr = EMF.WarpRows[i]; for (int j = tr.tiles.Count - 1; j >= 0; --j) { Warp tt = tr.tiles[j]; if (tt.x > EMF.Width || tr.y > EMF.Height) { Console.WriteLine("[MAP {2}] Warp {0}x{1} is out of map bounds. Removing.", tt.x, tr.y, lastPart); tr.tiles.RemoveAt(j); changesMade = true; } } } for (int i = EMF.NPCSpawns.Count - 1; i >= 0; --i) { NPCSpawn npc = EMF.NPCSpawns[i]; NPCRecord npcRec = (NPCRecord)ENF.Data.Find(rec => ((NPCRecord)rec).ID == npc.id); if (npc.id > ENF.Data.Count || npcRec == null) { Console.WriteLine("[MAP {0}] NPC Spawn {1}x{2} uses non-existent NPC #{3}. Removing.", lastPart, npc.x, npc.y, npc.id); EMF.NPCSpawns.RemoveAt(i); changesMade = true; continue; } if (npc.x > EMF.Width || npc.y > EMF.Height) { Console.WriteLine("[MAP {0}] NPC Spawn {1}x{2} ({3}) is out of map bounds. Removing.", lastPart, npc.x, npc.y, npcRec.Name); EMF.NPCSpawns.RemoveAt(i); changesMade = true; continue; } if (!CheckTile(EMF, npc.x, npc.y)) { Console.WriteLine("[MAP {0}] NPC Spawn {1}x{2} ({3}) is invalid...", lastPart, npc.x, npc.y, npcRec.Name); bool found = false; for (int row = npc.y - 2; row < npc.y + 2; ++row) { if (found) { break; } for (int col = npc.x - 2; col < npc.x + 2; ++col) { if (found) { break; } if (CheckTile(EMF, col, row)) { Console.WriteLine("[MAP {0}] Found valid spawn point. Continuing.", lastPart); found = true; } } } if (!found) { Console.WriteLine("[MAP {0}] NPC couldn't spawn anywhere valid! Removing."); EMF.NPCSpawns.RemoveAt(i); changesMade = true; } } } for (int i = EMF.Chests.Count - 1; i >= 0; --i) { MapChest chest = EMF.Chests[i]; ItemRecord rec = EIF.GetItemRecordByID(chest.item); if (chest.item > EIF.Data.Count || rec == null) { Console.WriteLine("[MAP {0}] Chest Spawn {1}x{2} uses non-existent Item #{3}. Removing.", lastPart, chest.x, chest.y, chest.item); EMF.Chests.RemoveAt(i); changesMade = true; continue; } if (chest.x > EMF.Width || chest.y > EMF.Height || (EMF.TileLookup[chest.y, chest.x] ?? new Tile { spec = TileSpec.Wall }).spec != TileSpec.Chest) { Console.WriteLine("[MAP {0}] Chest Spawn {1}x{2} points to a non-chest. Removing.", lastPart, chest.x, chest.y); EMF.Chests.RemoveAt(i); changesMade = true; } } if (!changesMade) { Console.WriteLine("Map {0} processed without any errors. No changes made.", lastPart); continue; } if (map == 0 && singleFile && inFiles.Length == 1) { EMF.Save(dst); break; } EMF.Save(Path.Combine(dst, lastPart)); } }