public static void Export(IFileSystem fs, MapInfo[] gimmicks, string outDir) { Directory.CreateDirectory(Path.Combine(outDir, "png")); foreach (MapInfo map in gimmicks) { //if (map.Name != "ma02a") continue; foreach (MapAreaInfo area in map.Areas) { //if (area.Name != "ma02a_f01") continue; string texPath = $"/menu/image/{area.Name}_map.wilay"; byte[] texBytes = fs.ReadFile(texPath); var wilay = new WilayRead(texBytes); LahdTexture texture = wilay.Textures[0]; Bitmap bitmapBase = texture.ToBitmap(); float scale = 1; bitmapBase = ResizeImage(bitmapBase, (int)(bitmapBase.Width * scale), (int)(bitmapBase.Height * scale)); var outerBrush = new SolidBrush(System.Drawing.Color.Black); //var backing = new SolidBrush(System.Drawing.Color.White); var innerBrush = new SolidBrush(System.Drawing.Color.GreenYellow); var pen = new Pen(outerBrush, 1 * scale); bitmapBase.RotateFlip(RotateFlipType.Rotate180FlipNone); foreach (KeyValuePair <string, List <InfoEntry> > gmkType in area.Gimmicks) { string type = gmkType.Key; //if (type != "landmark") continue; var bitmap = (Bitmap)bitmapBase.Clone(); using (Graphics graphics = Graphics.FromImage(bitmap)) { foreach (InfoEntry gmk in gmkType.Value) { Point2 point = area.Get2DPosition(gmk.Xfrm.Position); graphics.FillCircle(innerBrush, point.X * scale, point.Y * scale, 8 * scale); graphics.DrawCircle(pen, point.X * scale, point.Y * scale, 8 * scale); } //foreach (InfoEntry gmk in gmkType.Value) //{ // //if (gmk.String != "landmark_ma02a_101") continue; // var point = area.Get2DPosition(gmk.Xfrm.Position); // var pointS = area.Get2DPosition(gmk.Xfrm.Scale); // //graphics.FillCircle(innerBrush, point.X * scale, point.Y * scale, 5 * scale); // //DrawEllipse(graphics, pen, point.X * scale, point.Y * scale, pointS.X / 2 * scale, pointS.Y / 2 * scale); // DrawRect(graphics, pen, point.X * scale, point.Y * scale, pointS.X / 2 * scale, pointS.Y / 2 * scale); // //graphics.DrawCircle(pen, point.X * scale, point.Y * scale, 5 * scale); //} //foreach (InfoEntry gmk in gmkType.Value) //{ // //var text = gmk.String.Split('_').Last(); // var text = gmk.Type.ToString(); // var point = area.Get2DPosition(gmk.Xfrm.Position); // //graphics.FillRectangle(backing, point.X * scale, point.Y * scale, 30 * scale, 12 * scale); // graphics.FillRectangle(backing, point.X * scale, point.Y * scale, 12 * scale, 12 * scale); // graphics.DrawString(text, new Font("Arial", 8 * scale), outerBrush, point.X * scale, point.Y * scale); //} } byte[] png = bitmap.ToPng(); File.WriteAllBytes(Path.Combine(outDir, $"png/{map.DisplayName} - {area.DisplayName} - {type}.png"), png); } } } }
public static void ReadMap(BdatStringCollection bdats, Options options) { var bdatMiniMapLists = bdats.Tables.Where(x => x.Key.Contains("minimaplist")).Select(x => x.Value).ToList(); var bdatMaps = bdats.Tables["FLD_maplist"]; foreach (var map in bdatMaps.Items) { string index = map.Values["resource"].Value.ToString().Substring(2); if (index != "2501" && index != "2601") { continue; } var minimap = bdatMiniMapLists.FirstOrDefault(x => x.Name.Contains(index)); if (minimap == null) { continue; } int.TryParse(map["minimap_lt_x"].Value.ToString(), out int minX); int.TryParse(map["minimap_lt_z"].Value.ToString(), out int minZ); int.TryParse(map["minimap_rb_x"].Value.ToString(), out int maxX); int.TryParse(map["minimap_rb_z"].Value.ToString(), out int maxZ); Rectangle mapBounds = new Rectangle(minX, minZ, maxX - minX, maxZ - minZ); // var landmarks = bdatLandmarks.Items.Where(x => x["mapID"].Reference == map).ToList(); if (!bdats.Tables.ContainsKey("Litemlist" + index)) { continue; } var collectables = bdats.Tables["Litemlist" + index]?.Items?.Where(x => CheckDrop(x, options.Filter)); //var fb = bdats.Tables["poplist" + index]?.Items?.Where(x => x["NAMED_FLG"].DisplayString != "0" && x["ene1Per"].DisplayString == "100"); //var um = bdats.Tables["poplist" + index]?.Items?.Where(x => x["NAMED_FLG"].DisplayString != "0" && x["ene1Per"].DisplayString == "30"); var etherMine = bdats.Tables["gemMineList2501"].Items.Where(x => x.Id == 102 || x.Id == 120 || x.Id == 122 || x.Id == 126 || x.Id == 127 || x.Id == 128 || x.Id == 124 || x.Id == 103); var um = bdats.Tables["poplist" + index]?.Items?.Where(x => x["NAMED_FLG"].DisplayString != "0"); var landmarks = bdats.Tables["landmarklist"].Items.Where(x => x["mapID"].Reference == map && (x["category"].DisplayString == "0" || x["category"].DisplayString == "1")).ToList(); // if (!collectables.Any()) continue; int ground = int.MinValue; foreach (var floor in minimap.Items) { int.TryParse(floor["height"].Value.ToString(), out int ceiling); var map_file_name = floor["mapimg"].Reference["filename"].Value.ToString(); if (floor["mapimg1"].Reference != null) { map_file_name = floor["mapimg1"].Reference["filename"].Value.ToString(); } if (floor["mapimg2"].Reference != null) { map_file_name = floor["mapimg2"].Reference["filename"].Value.ToString(); } var map_file = Path.Combine(Path.Combine(options.Input, "image"), map_file_name + ".wilay"); byte[] file = File.ReadAllBytes(map_file); var wilay = new WilayRead(file); LahdTexture texture = wilay.Textures[0]; Bitmap bitmap = texture.ToBitmap(); var brush1 = new SolidBrush(System.Drawing.Color.Red); var brush2 = new SolidBrush(System.Drawing.Color.Yellow); var brush3 = new SolidBrush(System.Drawing.Color.Blue); var outerBrush = new SolidBrush(System.Drawing.Color.Black); Pen pen = new Pen(outerBrush, 2); using (Graphics graphics = Graphics.FromImage(bitmap)) { // Landmarks //graphics.MarkItems(landmarks, innerBrush, pen, mapBounds, bitmap.Size, ground, ceiling); // Collectables // graphics.MarkItems(collectables.ToList(), brush1, pen, mapBounds, bitmap.Size, ground, ceiling); // Enemies // graphics.MarkItems(fb.ToList(), brush2, pen, mapBounds, bitmap.Size, ground, ceiling); // graphics.MarkItems(um.ToList(), brush1, pen, mapBounds, bitmap.Size, ground, ceiling); // graphics.MarkItems(landmarks.ToList(), brush3, pen, mapBounds, bitmap.Size, ground, ceiling); graphics.MarkItems(etherMine.ToList(), brush1, pen, mapBounds, bitmap.Size, ground, ceiling); } byte[] png = bitmap.ToPng(); File.WriteAllBytes(Path.Combine(options.Output, $"png/{map["name"].DisplayString} - f{floor["floorname"].Value.ToString()}.png"), png); Console.WriteLine(""); ground = ceiling; } } }