[Question]Dmap into C# form

01/02/2011 19:08 OELABOELA#1
I'm trying to make my proxy load a dmap into it like this:
[Only registered and activated users can see links. Click Here To Register...]
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 ImFlamedCOD#2
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 : [Only registered and activated users can see links. Click Here To Register...]
01/02/2011 22:42 OELABOELA#3
Quote:
Originally Posted by ImFlamedCOD View Post
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 : [Only registered and activated users can see links. Click Here To Register...]
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 Real~Death#4
Quote:
Originally Posted by OELABOELA View Post
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 OELABOELA#5
Quote:
Originally Posted by Real~Death View Post
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 Real~Death#6
doesent one of the paid proxies have this in it?gab or trig who can help us?
01/03/2011 02:39 OELABOELA#7
Quote:
Originally Posted by Real~Death View Post
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 ImFlamedCOD#8
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 OELABOELA#9
Quote:
Originally Posted by ImFlamedCOD View Post
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 shitboi#10
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 Korvacs#11
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 OELABOELA#12
Quote:
Originally Posted by Korvacs View Post
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 :)
[Only registered and activated users can see links. Click Here To Register...]
Just a random map. Loaded into my SUPER basic gui.
01/04/2011 11:54 Ian*#13
Quote:
Originally Posted by OELABOELA View Post
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 :)
[Only registered and activated users can see links. Click Here To Register...]
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 OELABOELA#14
Quote:
Originally Posted by Ian* View Post
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 shit outta the program, i have a big enough pc, with enough ram)
01/04/2011 22:56 Ian*#15
Quote:
Originally Posted by OELABOELA View Post
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 shit 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>.