Code:
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(fileName));
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.ExpandEnvironmentVariables("%APPDATA%\\Tibia\\Automap\\"));
FileStream fst = new FileStream("C:\\Users\\Josh\\Desktop\\Output.txt", FileMode.Create);
foreach (string fl in files)
{
Console.WriteLine("fl[43+7] " + fl[43+7]);
Console.WriteLine("fl[43+8] " + fl[43+8]);
Console.WriteLine("---------------");
if (fl[43+7] == '0' && fl[43+8] == '7')
{
foreach (char c in fl)
{
fst.Write(BitConverter.GetBytes(c), 0, 1);
fst.Flush();
}
fst.Write(BitConverter.GetBytes('\n'), 0, 1);
}
}
fst.Close();
Bitmap bmp = new Bitmap(256 * 8 + 8, 256 * 8 + 8, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bmp);
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
// Draw bitmap at x = x+124, y = y+121 onto position x*256, y*256
// Get the name of the file to draw
StringBuilder sb = new StringBuilder();
sb.Append(Environment.ExpandEnvironmentVariables("%APPDATA%\\Tibia\\Automap\\"));
sb.Append(Convert.ToString(124 + x));
sb.Append(Convert.ToString(121 + y));
sb.Append("07.map");
// And draw the file to our graphics object
if (File.Exists(sb.ToString()))
g.DrawImage(getMapFile(sb.ToString()), x * 256 + x, y * 256 + y);
else
g.FillRectangle(Brushes.Black, x * 256 + x, y * 256 + y, 256, 256);
}
}
// Save the graphics object, pushing changes to bmp
g.Save();
// Save the bmp object to file
bmp.Save("C:\\Users\\Josh\\Desktop\\LargeBMP.bmp");
Console.ReadLine();
}
}
}
And here is the output image: