|
You last visited: Today at 21:11
Advertisement
[Question]Dmap into C# form
Discussion on [Question]Dmap into C# form within the CO2 Programming forum part of the Conquer Online 2 category.
01/02/2011, 19:08
|
#1
|
elite*gold: 223
Join Date: Dec 2007
Posts: 1,076
Received Thanks: 257
|
[Question]Dmap into C# form
I'm trying to make my proxy load a dmap into it like this:
As you can see, Korvacs made it, without to much effort(i believe) Can anyone explain me how to do this, because it looks pretty neat to have this in your gui, and later on i want to try to do things with it, like teleporting.
Any help is appreciated,
OELABOELA
|
|
|
01/02/2011, 19:29
|
#2
|
elite*gold: 0
Join Date: Jun 2009
Posts: 378
Received Thanks: 140
|
Go to Korvacs profile page , go under his thread created. Look for his open source COUP *Conquer Online Underground Private Server* and download it he has a map reader in there.
Link :
|
|
|
01/02/2011, 22:42
|
#3
|
elite*gold: 223
Join Date: Dec 2007
Posts: 1,076
Received Thanks: 257
|
Quote:
Originally Posted by ImFlamedCOD
Go to Korvacs profile page , go under his thread created. Look for his open source COUP *Conquer Online Underground Private Server* and download it he has a map reader in there.
Link :
|
So this is what im searching for?
Code:
internal void LoadMap()
{
FileStream File = null;
while (!Monitor.TryEnter(Console.Out, 500)) { }
int CursorPos = Console.CursorLeft;
int CursorTop = Console.CursorTop;
Monitor.Exit(Console.Out);
try
{
File = new FileStream(Settings.SmallMap.Replace("{0}", _mapID.ToString()), FileMode.Open);
while (!Monitor.TryEnter(Console.Out, 500)) { }
Console.Write(_mapID);
Console.SetCursorPosition(CursorPos, 0);
Monitor.Exit(Console.Out);
}
catch (Exception e)
{
while (!Monitor.TryEnter(Console.Out, 500)) { }
Console.SetCursorPosition(0, GameMap.ConsoleTop);
Console.WriteLine("[Game Server] Missing file: {0}", _mapID.ToString() + ".smap");
Console.SetCursorPosition(CursorPos, CursorTop);
GameMap.ConsoleTop++;
Monitor.Exit(Console.Out);
return;
}
using (BinaryReader Reader = new BinaryReader(File))
{
int count = 0;
File.Seek(8, SeekOrigin.Begin);
_width = Reader.ReadInt32(); _height = Reader.ReadInt32();
Tiles = new Tile[_width * _height];
byte Data = Reader.ReadByte();
for (ushort y = 0; y < _height; y++)
{
for (ushort x = 0; x < _width; x++)
{
switch (count)
{
case 0:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.First)); break;
case 1:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.Second)); break;
case 2:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.Third)); break;
case 3:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.Fourth)); break;
case 4:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.Fifth)); break;
case 5:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.Sixth)); break;
case 6:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.Seventh)); break;
case 7:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.Eighth)); count = 0; Data = Reader.ReadByte(); break;
}
}
}
}
}
|
|
|
01/03/2011, 01:18
|
#4
|
elite*gold: 0
Join Date: Jun 2007
Posts: 1,272
Received Thanks: 246
|
Quote:
Originally Posted by OELABOELA
So this is what im searching for?
Code:
internal void LoadMap()
{
FileStream File = null;
while (!Monitor.TryEnter(Console.Out, 500)) { }
int CursorPos = Console.CursorLeft;
int CursorTop = Console.CursorTop;
Monitor.Exit(Console.Out);
try
{
File = new FileStream(Settings.SmallMap.Replace("{0}", _mapID.ToString()), FileMode.Open);
while (!Monitor.TryEnter(Console.Out, 500)) { }
Console.Write(_mapID);
Console.SetCursorPosition(CursorPos, 0);
Monitor.Exit(Console.Out);
}
catch (Exception e)
{
while (!Monitor.TryEnter(Console.Out, 500)) { }
Console.SetCursorPosition(0, GameMap.ConsoleTop);
Console.WriteLine("[Game Server] Missing file: {0}", _mapID.ToString() + ".smap");
Console.SetCursorPosition(CursorPos, CursorTop);
GameMap.ConsoleTop++;
Monitor.Exit(Console.Out);
return;
}
using (BinaryReader Reader = new BinaryReader(File))
{
int count = 0;
File.Seek(8, SeekOrigin.Begin);
_width = Reader.ReadInt32(); _height = Reader.ReadInt32();
Tiles = new Tile[_width * _height];
byte Data = Reader.ReadByte();
for (ushort y = 0; y < _height; y++)
{
for (ushort x = 0; x < _width; x++)
{
switch (count)
{
case 0:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.First)); break;
case 1:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.Second)); break;
case 2:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.Third)); break;
case 3:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.Fourth)); break;
case 4:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.Fifth)); break;
case 5:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.Sixth)); break;
case 6:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.Seventh)); break;
case 7:
Tiles[x * _width + y] = new Tile(GetBool(Data, BitValues.Eighth)); count = 0; Data = Reader.ReadByte(); break;
}
}
}
}
}
|
let us/me know if this is the code needed.I couldn't figure it out on my own and thought it would be a lot harder.Now if we could get a good explanation of what clint and ash did to get that dot-matrix code in sirhooks would be amazing.
|
|
|
01/03/2011, 01:31
|
#5
|
elite*gold: 223
Join Date: Dec 2007
Posts: 1,076
Received Thanks: 257
|
Quote:
Originally Posted by Real~Death
let us/me know if this is the code needed.I couldn't figure it out on my own and thought it would be a lot harder.Now if we could get a good explanation of what clint and ash did to get that dot-matrix code in sirhooks would be amazing.
|
Indeed, i really want to have this working. But it seems that this is not the only part we need.
|
|
|
01/03/2011, 01:57
|
#6
|
elite*gold: 0
Join Date: Jun 2007
Posts: 1,272
Received Thanks: 246
|
doesent one of the paid proxies have this in it?gab or trig who can help us?
|
|
|
01/03/2011, 02:39
|
#7
|
elite*gold: 223
Join Date: Dec 2007
Posts: 1,076
Received Thanks: 257
|
Quote:
Originally Posted by Real~Death
doesent one of the paid proxies have this in it?gab or trig who can help us?
|
Both have it, but i don't think they want to help us.
|
|
|
01/03/2011, 03:38
|
#8
|
elite*gold: 0
Join Date: Jun 2009
Posts: 378
Received Thanks: 140
|
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using COUP.Core.Entities;
namespace COUP.Core.Forms
{
public partial class MapView : Form
{
private Color CanWalk = Color.White;
private Color CantWalk = Color.Black;
private Bitmap _mapImage;
private int _selectedMap;
public Dictionary<int, Map> _maps;
public bool Display { get; set; }
public int RefreshRate = 500;
public MapView(Dictionary<int, Map> Maps)
{
CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
SetStyle(
ControlStyles.ResizeRedraw |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer, true);
_maps = Maps;
foreach (Map _map in _maps.Values)
{
comboBox1.Items.Add(_map._mapID);
}
Display = true;
}
public void SetBackground(Map Target)
{
Bitmap MapImage = new Bitmap(Target._width, Target._height, PixelFormat.Format32bppArgb);
BitmapData MapData = MapImage.LockBits(new Rectangle(0, 0, Target._width, Target._height), ImageLockMode.WriteOnly, MapImage.PixelFormat);
for (int y = 0; y < MapData.Height; y++)
{
IntPtr ptrRowStart = new IntPtr(MapData.Scan0.ToInt32() + MapData.Stride * y);
for (int x = 0; x < MapData.Width; x++)
{
Color TileColour = Target.CheckMove(new Point(x, y)) ? this.CanWalk : this.CantWalk;
Marshal.WriteInt32(new IntPtr(ptrRowStart.ToInt32() + x * 4), TileColour.ToArgb());
}
}
MapImage.UnlockBits(MapData);
_mapImage = MapImage;
}
public void DisplaySectors(Map Target, Graphics e)
{
while (!Monitor.TryEnter(Target, 50)) { }
foreach (iEntity Entity in Target.Query(new Rectangle(0, 0, Target._width, Target._height)))
{
if(Entity is Monster)
e.DrawRectangle(new Pen(Color.Blue, 1), new Rectangle(Entity.Location, new Size(1, 1)));
else if (Entity is Character)
e.DrawRectangle(new Pen(Color.DarkGreen, 4), new Rectangle(Entity.Location, new Size(1, 1)));
}
foreach (Sector Sect in Target.GetSectors(new Rectangle(0, 0, Target._width, Target._height)))
{
if(Sect != null)
e.DrawRectangle(new Pen(Color.DarkRed, 3), Sect.Bounds);
}
Monitor.Exit(Target);
}
private void Transform(Graphics e)
{
double largestRatio = Math.Max((double)this._mapImage.Width / this.pictureBox1.Width,
(double)this._mapImage.Height / this.pictureBox1.Height);
float posX = (float)(this.pictureBox1.Width * largestRatio / 2 - this._mapImage.Width / 2);
float posY = (float)(this.pictureBox1.Height * largestRatio / 2 - this._mapImage.Height / 2);
Matrix mx = new Matrix(1.0f / (float)largestRatio, 0, 0, 1.0f / (float)largestRatio, 0, 0);
mx.Translate(posX, posY);
e.Transform = mx;
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (_selectedMap == 0)
return;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
Transform(e.Graphics);
e.Graphics.DrawImageUnscaled(_mapImage, new Point(0, 0));
DisplaySectors(_maps[_selectedMap], e.Graphics);
}
private void button1_Click(object sender, EventArgs e)
{
int MapID = int.Parse(comboBox1.SelectedItem.ToString());
SetBackground(_maps[MapID]);
_selectedMap = MapID;
}
private void comboBox2_SelectedValueChanged(object sender, EventArgs e)
{
if (comboBox2.SelectedItem.ToString() == "Never")
RefreshRate = Timeout.Infinite;
else
RefreshRate = int.Parse(comboBox2.SelectedItem.ToString().Remove(comboBox2.SelectedItem.ToString().Length - 2));
}
}
}
Next time look harder for what i told you was there . . .
|
|
|
01/03/2011, 10:50
|
#9
|
elite*gold: 223
Join Date: Dec 2007
Posts: 1,076
Received Thanks: 257
|
Quote:
Originally Posted by ImFlamedCOD
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using COUP.Core.Entities;
namespace COUP.Core.Forms
{
public partial class MapView : Form
{
private Color CanWalk = Color.White;
private Color CantWalk = Color.Black;
private Bitmap _mapImage;
private int _selectedMap;
public Dictionary<int, Map> _maps;
public bool Display { get; set; }
public int RefreshRate = 500;
public MapView(Dictionary<int, Map> Maps)
{
CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
SetStyle(
ControlStyles.ResizeRedraw |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer, true);
_maps = Maps;
foreach (Map _map in _maps.Values)
{
comboBox1.Items.Add(_map._mapID);
}
Display = true;
}
public void SetBackground(Map Target)
{
Bitmap MapImage = new Bitmap(Target._width, Target._height, PixelFormat.Format32bppArgb);
BitmapData MapData = MapImage.LockBits(new Rectangle(0, 0, Target._width, Target._height), ImageLockMode.WriteOnly, MapImage.PixelFormat);
for (int y = 0; y < MapData.Height; y++)
{
IntPtr ptrRowStart = new IntPtr(MapData.Scan0.ToInt32() + MapData.Stride * y);
for (int x = 0; x < MapData.Width; x++)
{
Color TileColour = Target.CheckMove(new Point(x, y)) ? this.CanWalk : this.CantWalk;
Marshal.WriteInt32(new IntPtr(ptrRowStart.ToInt32() + x * 4), TileColour.ToArgb());
}
}
MapImage.UnlockBits(MapData);
_mapImage = MapImage;
}
public void DisplaySectors(Map Target, Graphics e)
{
while (!Monitor.TryEnter(Target, 50)) { }
foreach (iEntity Entity in Target.Query(new Rectangle(0, 0, Target._width, Target._height)))
{
if(Entity is Monster)
e.DrawRectangle(new Pen(Color.Blue, 1), new Rectangle(Entity.Location, new Size(1, 1)));
else if (Entity is Character)
e.DrawRectangle(new Pen(Color.DarkGreen, 4), new Rectangle(Entity.Location, new Size(1, 1)));
}
foreach (Sector Sect in Target.GetSectors(new Rectangle(0, 0, Target._width, Target._height)))
{
if(Sect != null)
e.DrawRectangle(new Pen(Color.DarkRed, 3), Sect.Bounds);
}
Monitor.Exit(Target);
}
private void Transform(Graphics e)
{
double largestRatio = Math.Max((double)this._mapImage.Width / this.pictureBox1.Width,
(double)this._mapImage.Height / this.pictureBox1.Height);
float posX = (float)(this.pictureBox1.Width * largestRatio / 2 - this._mapImage.Width / 2);
float posY = (float)(this.pictureBox1.Height * largestRatio / 2 - this._mapImage.Height / 2);
Matrix mx = new Matrix(1.0f / (float)largestRatio, 0, 0, 1.0f / (float)largestRatio, 0, 0);
mx.Translate(posX, posY);
e.Transform = mx;
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (_selectedMap == 0)
return;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
Transform(e.Graphics);
e.Graphics.DrawImageUnscaled(_mapImage, new Point(0, 0));
DisplaySectors(_maps[_selectedMap], e.Graphics);
}
private void button1_Click(object sender, EventArgs e)
{
int MapID = int.Parse(comboBox1.SelectedItem.ToString());
SetBackground(_maps[MapID]);
_selectedMap = MapID;
}
private void comboBox2_SelectedValueChanged(object sender, EventArgs e)
{
if (comboBox2.SelectedItem.ToString() == "Never")
RefreshRate = Timeout.Infinite;
else
RefreshRate = int.Parse(comboBox2.SelectedItem.ToString().Remove(comboBox2.SelectedItem.ToString().Length - 2));
}
}
}
Next time look harder for what i told you was there . . .
|
I only looked in Map.cs, and while searching for button, just button nothing came up. So maybe i did something wrong at searching, but thank you
<Edit>
The only problem left is sectors, I can't find to find the struct/interface or whatelse of Sector. This is the only thing i need to get on with it.
|
|
|
01/03/2011, 10:50
|
#10
|
elite*gold: 0
Join Date: Jun 2006
Posts: 457
Received Thanks: 67
|
nice thread... hopefully these info will be useful to me soon. I'm giving myself a lightning crash course in C# atm.
|
|
|
01/03/2011, 11:07
|
#11
|
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
|
All my map does is display the dmap data, and when used in my server displays the sectors and players which are on that map, teleporting would require there to be a teleport exploit available, and you would need to write in the correct packet handling for that, not to mention a proxy to make it work.
|
|
|
01/03/2011, 11:39
|
#12
|
elite*gold: 223
Join Date: Dec 2007
Posts: 1,076
Received Thanks: 257
|
Quote:
Originally Posted by Korvacs
All my map does is display the dmap data, and when used in my server displays the sectors and players which are on that map, teleporting would require there to be a teleport exploit available, and you would need to write in the correct packet handling for that, not to mention a proxy to make it work.
|
I already have a proxy and such, but im still stuck at the dmap data dislay, it crashes my program when i push the button to load up the pic.
<Edit>
Finally got something
Just a random map. Loaded into my SUPER basic gui.
|
|
|
01/04/2011, 11:54
|
#13
|
elite*gold: 0
Join Date: Nov 2006
Posts: 805
Received Thanks: 464
|
Quote:
Originally Posted by OELABOELA
I already have a proxy and such, but im still stuck at the dmap data dislay, it crashes my program when i push the button to load up the pic.
<Edit>
Finally got something
Just a random map. Loaded into my SUPER basic gui.
|
There's an image box property to automatically resize the image being displayed (your dmap) to the same size as your image box.
That's really all you need and you should be set. There's a lot of image box properties y ou might like, for instance zooming into the image box, drawing images ontop of your map(player stars etc..). Make sure it's all threaded properly and you will be good to go.
|
|
|
01/04/2011, 22:19
|
#14
|
elite*gold: 223
Join Date: Dec 2007
Posts: 1,076
Received Thanks: 257
|
Quote:
Originally Posted by Ian*
There's an image box property to automatically resize the image being displayed (your dmap) to the same size as your image box.
That's really all you need and you should be set. There's a lot of image box properties y ou might like, for instance zooming into the image box, drawing images ontop of your map(player stars etc..). Make sure it's all threaded properly and you will be good to go.
|
That's the problem, i have it all non-threaded into my gui, but it works, and i have player and such drawed.
(Maybe its because im doing a 32 bit program on a 64 bit pc, this could also lagg the **** outta the program, i have a big enough pc, with enough ram)
|
|
|
01/04/2011, 22:56
|
#15
|
elite*gold: 0
Join Date: Nov 2006
Posts: 805
Received Thanks: 464
|
Quote:
Originally Posted by OELABOELA
That's the problem, i have it all non-threaded into my gui, but it works, and i have player and such drawed.
(Maybe its because im doing a 32 bit program on a 64 bit pc, this could also lagg the **** outta the program, i have a big enough pc, with enough ram)
|
Well when you try to access your dmap from another thread it will crash your program and thrown an exception saying something like no cross thread calls allowed.
If this is j ust a GUI with no functionality in it then I can totally see why there is no issue <yet>.
|
|
|
|
|
Similar Threads
|
[Question] Inventar Form ändern/vergrössern
06/17/2011 - Flyff Private Server - 12 Replies
Heey, E*pvper's
Ich bin dabei ein neues Ingame Design zu entwerfen.
Ich hab mir da mal das Inventar angeschaut und mir überlegt wie man es doch vergrössern oder gar die Form verändern könnte.
Ich hab da schon einiges versucht, leider erfolglos <.<
Die SuFu spuckte auch nicht's aus ._.
Ich freue mich auf jede hilfreiche Antwort :)
Liebe Grüsse Apfelsuchtii
|
DMap Info [Question]
08/08/2009 - CO2 Private Server - 12 Replies
I have a DMap Reader on my source. I want to check the access of some locations when a player drop an item, jump, walk, etc... But, if I load the DMap in an array, I have like 20mo of RAM used by one map. An other solution is to read the DMap when the player have to check the location but I don't want to kill my computer:rolleyes: The best solution, I think, is to load in memory the most used map like TC and for the other, check when the player use the map.
What is the best solution?
|
.DMap
06/29/2006 - Conquer Online 2 - 10 Replies
Hello, It is my first post here I usually just read topics and learn from them ect.. Thank you elitepvpers for all these weeks of help but now i need something not found..
I want to make costum little map the ones at the top right of your screen i wanted to make an edited one with lets say a star where the ganaderma spawns but i dont know how to open or save as .DMap can someone help m with this? are there any specifications when doing this? filesize ect..
|
DMAP
04/09/2006 - Conquer Online 2 - 5 Replies
Ok i checked on forum i couldn't find anything base on this so i'm want to know if there any program open dmap files so i can edit the maps if so could you let me know I appreciate it.
|
.dmap question
10/23/2005 - Conquer Online 2 - 0 Replies
does any1 kno wich .dmap snake array is..thx :rolleyes:
|
All times are GMT +2. The time now is 21:11.
|
|