private void makebitmap(PictureBox box, BitmapType btype) { try { image = new Bitmap(512, 512); if (btype == BitmapType.SMA) { var idx = SmaFormatter.GetIndex("tileinfo", "EventType"); var temp = (_SmaData[1] as object[]).Select(x => (byte)(x as object[])[idx]).ToArray(); for (int x = 0; x < 256; x++) { for (int y = 0; y < 256; y++) { for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { image.SetPixel(2 * (255 - y) + i, 2 * x + j, temp[x + 256 * y] == 0 ? Color.LightBlue : Color.Black); } } } } box.Image = image; } if (btype == BitmapType.DAT) { var idx = MapFormatter.GetIndex("tileinfo", "EventType"); var temp = (_DatData[2] as object[]).Select(x => (byte)(x as object[])[idx]).ToArray(); for (int x = 0; x < 256; x++) { for (int y = 0; y < 256; y++) { for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { image.SetPixel(2 * (255 - y) + i, 2 * x + j, temp[x + 256 * y] == 0 ? Color.LightBlue : Color.Black); } } } } box.Image = image; } }catch (Exception ex) { ErrorLogger.LogException(ex); } }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { var node = e.Node; if (node == null || !(node.Tag is Tuple <string, int, int>)) { return; } var info = node.Tag as Tuple <string, int, int>; toolStripLabel2.Text = "Location: " + info.Item1 + " Map: " + info.Item2 + " Size: " + info.Item3; if (info.Item2 != -1)//just little handling because if u click [+]xxxx it will want to open file named -1 { var source = File.OpenRead(LoadingData.directory + info.Item2 + ".sma"); _SmaData = SmaFormatter.Read(source, (uint)info.Item3); } switch (info.Item1) { case "header": var tempdt = SmaFormatter.GetFormatter(0).GetSchema(); tempdt.Rows.Add(_SmaData[0] as object[]); dataGridView2.DataSource = tempdt; //it crashes the program atm! // dataGridView2.DataSource = SmaFormatter.GetFormatter(0).GetSchema(_SmaData[0] as object[][]); break; case "tileinfo": dataGridView2.DataSource = SmaFormatter.GetFormatter(1).GetSchema(_SmaData[1] as object[][]); makebitmap(pictureBox1, BitmapType.SMA); break; case "monsterinfo": dataGridView2.DataSource = SmaFormatter.GetFormatter(2).GetSchema(_SmaData[2] as object[][]); var temp = SmaFormatter.GetFormatter(2).GetSchema(_SmaData[2] as object[][]); Draw.MonsterData = null; panel1.Controls.Clear(); Draw.MonsterData = Draw.PrepareMonsterData(_SmaData[2] as object[][]); panel1.BackgroundImage = new Bitmap(PaintStuff.GetMapImage(Directory.GetCurrentDirectory() + @"..\..\..\map\" + info.Item2 + ".map"), new Size(512, 512)); foreach (var spawn in Draw.MonsterData) { //spawn.Item3.BackColor = Color.Red; ToolTip tt = new ToolTip(); tt.SetToolTip(spawn.Item3, "Region Name: " + spawn.Item1 + "\n MonsterNum: " + spawn.Item2 + "\n MaxCount: " + spawn.Item4); panel1.Controls.Add(spawn.Item3); } // image = new Bitmap(PaintStuff.GetMapImage(@"C:\Ares_Source\BuildResult\Client\Release\Res-Map\" + info.Item2+".map"), new Size(512, 512)); // pictureBox1.Image = image; //if (dataGridView2.SelectedRows.Count == 1) //{ // // Bitmap test = new Bitmap(512, 512); // var selectedrow = dataGridView2.SelectedRows[0]; // int sx = GetSize(int.Parse(selectedrow.Cells[2].Value.ToString())); // int sy = GetSize(int.Parse(selectedrow.Cells[3].Value.ToString())); // int ex = GetSize(int.Parse(selectedrow.Cells[4].Value.ToString())); // int ey = GetSize(int.Parse(selectedrow.Cells[5].Value.ToString())); // Graphics g = Graphics.FromImage(image); // g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // //g.DrawRectangle(new Pen(Color.Red), sx,sy,ex-sx,ey-sy); i think rectangle its abit off so its disabled atm ! // g.DrawString("S", new Font(FontFamily.GenericSansSerif, 18, FontStyle.Regular), new SolidBrush(Color.Green), sx - 9, sy - 9); // g.DrawString("E", new Font(FontFamily.GenericSansSerif, 18, FontStyle.Regular), new SolidBrush(Color.Red), sx - 9, ey - 9); // g.Dispose(); // pictureBox1.Refresh(); //} break; } }
/// <summary> /// Generates an array of map ideces and monster unique numbers /// from dat and sma files. 2017-01-05 panoskj /// </summary> public static object[] SomeQuery() { var dats = Directory.GetFiles(@"..\..\..\map", "*.dat"); var smas = Directory.GetFiles(@"..\..\..\map", "*.sma"); // data from map config var mapcfg = GetMapConfig(@"..\..\..\config\map.cfg"). ToDictionary(x => x.Item1, x => new Tuple <int, int>(x.Item2, x.Item3)); // reads a dat file Func <string, Tuple <int, object> > readDat = (s) => { int idx = int.Parse(Path.GetFileNameWithoutExtension(s)); using (AtumZip.ZippedFile zpf = File.OpenRead(s)) return(new Tuple <int, object>(idx, MapFormatter.Read(zpf.At(0)))); }; // reads a sma file Func <string, Tuple <int, object> > readSma = (s) => { int idx = int.Parse(Path.GetFileNameWithoutExtension(s)); using (var src = File.OpenRead(s)) if (mapcfg.ContainsKey(idx) && mapcfg[idx].Item1 == mapcfg[idx].Item2) { return(new Tuple <int, object>(idx, SmaFormatter.Read(src, (uint)mapcfg[idx].Item1))); } else { return(null); } }; // collects all tables containing spawn information var datmondata = dats.Select(x => readDat(x)).Where(x => x != null). Select(x => new { Index = x.Item1, Data = (x.Item2 as object[])[3] as object[][] }); // collects all tables containing spawn information var smamondata = smas.Select(x => readSma(x)).Where(x => x != null). Select(x => new { Index = x.Item1, Data = (x.Item2 as object[])[2] as object[][] }); // indeces for later use var idx1 = MapFormatter.GetIndex("objectinfo", "ObjectMonsterUniqueNumber"); var idx2 = SmaFormatter.GetIndex("monsterinfo", "Monster Num"); // from each object spawn row of each collected table // select the map index and ObjectMonsterUniqueNumber // if ObjectMonsterUniqueNumber is in range [2000000, 3000000) var res1 = from data in datmondata from spawn in data.Data where (uint)spawn[idx1] >= 2000000 && (uint)spawn[idx1] < 3000000 // or check for EventType == 6 select new { Index = data.Index, Monster = (uint)spawn[idx1] }; // from each monster spawn of each collected table // select the map index and Monster Num // if Monster Num is not 0 var res2 = from data in smamondata from spawn in data.Data where (uint)spawn[idx2] != 0 select new { Index = data.Index, Monster = (uint)spawn[idx2] }; // return the distinct results return(res1.Concat(res2).Distinct().ToArray()); }