XtrmJash
12-23-2013, 12:38 AM
So I had to read map files today, and it was a right pain in the arse to fix some software to do it. I did it, and here's the sauce. Use as you wish.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading.Tasks;
using System.IO;
namespace MapParser
{
class Program
{
public struct Colour // This is for the minimap shit, dunno where to put it so I dumped it here.
{
public int r; // RED
public int g; // GREEN
public int b; // BLUE
} // FUUUUUUUUUUUUUUUUUUUUUU
public static Colour[] colourlist;
public static Colour[] speedcolourlist;
public static Colour getClr(int r, int g, int b)
{
Colour Clr = new Colour();
Clr.r = r;
Clr.g = g;
Clr.b = b;
return Clr;
}
public static byte[] ReadFile(string filePath)
{
byte[] buffer;
using (FileStream fileStream = new FileStream(Environment.ExpandEnvironmentVariables( filePath), FileMode.Open, FileAccess.Read))
{
int length = (int)fileStream.Length; // get file length
buffer = new byte[length]; // create buffer
int count; // actual number of bytes read
int sum = 0; // total number of bytes read
// read until Read method returns 0 (end of the stream has been reached)
while ((count = fileStream.Read(buffer, sum, length - sum)) > 0)
sum += count; // sum is a buffer offset for next reading
}
return buffer;
}
public static void fillSpeedColourList()
{
speedcolourlist = new Colour[256];
for (int i = 0; i < 256; i++)
{
speedcolourlist[i] = getClr(i, i, i);
}
}
public static void fillColourList()
{
colourlist = new Colour[256];
colourlist[0] = getClr(0, 0, 0); // Undiscovered / tar / void / inner cave walls
colourlist[12] = getClr(0, 102, 0); // tree / bush
colourlist[24] = getClr(0, 204, 0); // grass or stone ground
colourlist[30] = getClr(0, 255, 0); // old swamp
colourlist[40] = getClr(51, 0, 204); // water
colourlist[86] = getClr(102, 102, 102); // mountain / rock
colourlist[114] = getClr(153, 51, 0); // cave wall
colourlist[121] = getClr(153, 102, 51); // cave mud
colourlist[129] = getClr(153, 153, 153); // normal floor / path
colourlist[179] = getClr(204, 255, 255); // ice wall
colourlist[186] = getClr(255, 51, 0); // wall
colourlist[192] = getClr(255, 102, 0); // lava
colourlist[207] = getClr(255, 204, 153); // sand
colourlist[210] = getClr(255, 255, 0); // portal (or stairs etc)
colourlist[215] = getClr(255, 255, 255); // snow
colourlist[255] = getClr(150, 0, 255); // unknown but appeared once apparently
colourlist[140] = getClr(153, 255, 102); // some noob retard fag claimed this was changed from swamp color
}
public static Bitmap getMapFile(string fileName)
{
Bitmap bmp = new Bitmap(256, 256, System.Drawing.Imaging.PixelFormat.Format32bppArgb );
fillColourList();
byte[] fileContents = ReadFile(Environment.ExpandEnvironmentVariables(fi leName));
int index = 0;
Rectangle rect = new Rectangle();
rect.Height = 256;
rect.Width = 256;
rect.X = 0;
rect.Y = 0;
Colour color = new Colour();
color = colourlist[0];
Graphics.FromImage(bmp).FillRectangle(new SolidBrush(Color.FromArgb(color.r, color.g, color.b)), rect);
for (int x = 0; x < 256; x++)
{
for (int y = 0; y < 256; y++)
{
Colour clr;
clr = colourlist[fileContents[index]];
if (!(clr.r == color.r && clr.g == color.g && clr.b == color.b))
{
bmp.SetPixel(x, y, System.Drawing.Color.FromArgb((byte)255, (byte)clr.r, (byte)clr.g, (byte)clr.b));
}
index++;
}
}
return bmp;
}
static void Main(string[] args)
{
string[] files = Directory.GetFiles(Environment.ExpandEnvironmentVa riables("%APPDATA%\\Tibia\\Automap\\"));
int index = 0;
foreach (string fl in files)
{
Bitmap bmp = getMapFile(fl);
bmp.Save("C:\\Users\\Josh\\Desktop\\" + index.ToString() + ".bmp");
index++;
}
}
}
}
Should prove useful to at least one person out there. This generates a bitmap for EVERY file in your automap directory, and dumps it to the file path specified at the end of the source.
Provided with no implied warranty etc, entirely free of charge and all that shit.
A side note, you may not be able to access the Bitmap class by default, if so, right click your PROJECT (not solution) in the solution explorer, select Add -> Reference, and find System.Drawing in the list of classes, check the box next to it and click OK.
Enjoy :)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading.Tasks;
using System.IO;
namespace MapParser
{
class Program
{
public struct Colour // This is for the minimap shit, dunno where to put it so I dumped it here.
{
public int r; // RED
public int g; // GREEN
public int b; // BLUE
} // FUUUUUUUUUUUUUUUUUUUUUU
public static Colour[] colourlist;
public static Colour[] speedcolourlist;
public static Colour getClr(int r, int g, int b)
{
Colour Clr = new Colour();
Clr.r = r;
Clr.g = g;
Clr.b = b;
return Clr;
}
public static byte[] ReadFile(string filePath)
{
byte[] buffer;
using (FileStream fileStream = new FileStream(Environment.ExpandEnvironmentVariables( filePath), FileMode.Open, FileAccess.Read))
{
int length = (int)fileStream.Length; // get file length
buffer = new byte[length]; // create buffer
int count; // actual number of bytes read
int sum = 0; // total number of bytes read
// read until Read method returns 0 (end of the stream has been reached)
while ((count = fileStream.Read(buffer, sum, length - sum)) > 0)
sum += count; // sum is a buffer offset for next reading
}
return buffer;
}
public static void fillSpeedColourList()
{
speedcolourlist = new Colour[256];
for (int i = 0; i < 256; i++)
{
speedcolourlist[i] = getClr(i, i, i);
}
}
public static void fillColourList()
{
colourlist = new Colour[256];
colourlist[0] = getClr(0, 0, 0); // Undiscovered / tar / void / inner cave walls
colourlist[12] = getClr(0, 102, 0); // tree / bush
colourlist[24] = getClr(0, 204, 0); // grass or stone ground
colourlist[30] = getClr(0, 255, 0); // old swamp
colourlist[40] = getClr(51, 0, 204); // water
colourlist[86] = getClr(102, 102, 102); // mountain / rock
colourlist[114] = getClr(153, 51, 0); // cave wall
colourlist[121] = getClr(153, 102, 51); // cave mud
colourlist[129] = getClr(153, 153, 153); // normal floor / path
colourlist[179] = getClr(204, 255, 255); // ice wall
colourlist[186] = getClr(255, 51, 0); // wall
colourlist[192] = getClr(255, 102, 0); // lava
colourlist[207] = getClr(255, 204, 153); // sand
colourlist[210] = getClr(255, 255, 0); // portal (or stairs etc)
colourlist[215] = getClr(255, 255, 255); // snow
colourlist[255] = getClr(150, 0, 255); // unknown but appeared once apparently
colourlist[140] = getClr(153, 255, 102); // some noob retard fag claimed this was changed from swamp color
}
public static Bitmap getMapFile(string fileName)
{
Bitmap bmp = new Bitmap(256, 256, System.Drawing.Imaging.PixelFormat.Format32bppArgb );
fillColourList();
byte[] fileContents = ReadFile(Environment.ExpandEnvironmentVariables(fi leName));
int index = 0;
Rectangle rect = new Rectangle();
rect.Height = 256;
rect.Width = 256;
rect.X = 0;
rect.Y = 0;
Colour color = new Colour();
color = colourlist[0];
Graphics.FromImage(bmp).FillRectangle(new SolidBrush(Color.FromArgb(color.r, color.g, color.b)), rect);
for (int x = 0; x < 256; x++)
{
for (int y = 0; y < 256; y++)
{
Colour clr;
clr = colourlist[fileContents[index]];
if (!(clr.r == color.r && clr.g == color.g && clr.b == color.b))
{
bmp.SetPixel(x, y, System.Drawing.Color.FromArgb((byte)255, (byte)clr.r, (byte)clr.g, (byte)clr.b));
}
index++;
}
}
return bmp;
}
static void Main(string[] args)
{
string[] files = Directory.GetFiles(Environment.ExpandEnvironmentVa riables("%APPDATA%\\Tibia\\Automap\\"));
int index = 0;
foreach (string fl in files)
{
Bitmap bmp = getMapFile(fl);
bmp.Save("C:\\Users\\Josh\\Desktop\\" + index.ToString() + ".bmp");
index++;
}
}
}
}
Should prove useful to at least one person out there. This generates a bitmap for EVERY file in your automap directory, and dumps it to the file path specified at the end of the source.
Provided with no implied warranty etc, entirely free of charge and all that shit.
A side note, you may not be able to access the Bitmap class by default, if so, right click your PROJECT (not solution) in the solution explorer, select Add -> Reference, and find System.Drawing in the list of classes, check the box next to it and click OK.
Enjoy :)