Any idea to decrypt .map files? I want to start doing pathfinder from point to point
Any idea to decrypt .map files? I want to start doing pathfinder from point to point
Automap strucutre is really simple, is a two-dimensional matrix of bytes each byte indicates a tile type(wall, water, etc) and each tile type has a color. It must be a list of that colors for each byte in google somewhere.
The height and the width of the matrix is the same for every file and I think it's the width and height of the minimap at full zoom out.
Every file has a number, that allow you to order them in the right sequence.
You'll have to make a general path with this method and then check for obstructions while walking, since some things may block your path and may not be desplayed in the minimap.
There are two memory structures in tibia that allow you to check whether a tile is walkeable or not.
I strongly recommend you to use dijkstra or a* algorithms to create the path
Good luck!
Just ask if you need any help!
Last edited by Lolrapa; 06-01-2015 at 08:24 PM.
I tried to explain it (GlobalMap.lua file): https://github.com/Blequi/TibiaHardDrive
I think it is detailed enough. Since it's coded in Lua, it is not a problem for the majority of Tibia related programmers
I was trying to read the maps files some days ago and I got stuck with the 255 values on sqm's with fire/poison fields, because if you use a FF to block the way and then move away from that point, after some minutes it will still be marked as "Can not walk (255)", it will update the value only if you walk in that position again, so if you need to calculate a path to X position that was covered by fire fields, like on Yalahar dragon lords, it won't work, since the sqm's is blocked in the map file/memory.
Do you know a way to "fix" this? Or am I doing something wrong?
There's nothing wrong with your thinking.
I never built a cavebot, but the way I can think of is through local map (tiles around you). When you have an obstacle in a certain position, split the search area in 7x7 squares (for tiles available in the local map) and try to get closer to the goal location, repeating this process until you reach the desired location.
The local map idea works because you can bypass fire (or energy, etc) fields if it's the only blocking item in the tile stack.
Ye, I was just messing around with the map files, testing some pathfinders, then I faced this problem, was trying to create a path on all fenrock dragon lords, since the space to walk inside the cave is small, so this "split" thing wouldn't work that good I guess, since most of the ways are 3~4 sqm's and DL's aways trap all the sqm's, then I got stuck about that and how would be possible to "fix" it, but didn't try that much, I tought about update the visible area after walk X sqm's, but the path won't be found either, maybe I will take a look on that when I get free time.
well, if all the ways surrounding you are blocked, then there is no path and indeed, any pathfinder will fail to trace paths. You could see creatures or humans standing in sqm's as walkable in your pathfinder, when accounting for it in the local map, because if I'm not mistaken, they have a 99 id or something like that.
I don't play Tibia in ages, but if I recall correctly, creatures are always non-blocking unless some fighting mode enabled.
I'm pretty sure you cant walk through creatures in open pvp at least.
There are three information sources you have at hand, maybe separated are inefficient or usless but together I'm sure it work 100%
1) The can/can't walk info in map file.
As you say this method fails when a tile is temporarily blocked and you leave the screen like that, but also can give us a good idea of what could be walkable.
This method may show you a tile not walkable when it is.
2) The color palette
The colours of the map can give you an idea of whether a tile is or not walkeable, and will not change if there is fire or any other field or creature
This method may show a tile walkeable when is not, since some stones or trees aren't shown in map.
3)The local map
The local map gives a detailed view of every tile and it's items since every item like fire, stones, etc has an id and the tile info is stored in the .data file you can easily check if you can walk or not over a tile using tile flags like BlockPathFinding or IsGround
Remember that the more information we have the better. Just a little logic is needed to conect these three parts
Last edited by Lolrapa; 06-03-2015 at 01:12 PM.
This is how I load whole tibiaMap into memory, verry elegant and fast.
http://pastebin.com/fjh30vFn
How to find battlelist address --> http://tpforums.org/forum/thread-8146.html
Updating addresses --> http://tpforums.org/forum/thread-8625.html
DataReader --> http://tpforums.org/forum/thread-10387.html
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
byte[,,] TibiaMap;
private void button1_Click(object sender, EventArgs e)
{
string Path = Environment.GetFolderPath(Environment.SpecialFolde r.ApplicationData) + "\\Tibia\\Automap\\";
int StartX = 31744;
int StartY = 30976;
int MaxHeight = 2048;
int MaxWidth = 2048;
TibiaMap = new byte[16, 2048, 2048];
DirectoryInfo di = new DirectoryInfo(Path);
for (int z = 0; z < 16; z++)
{
FileInfo[] mapFiles = di.GetFiles("1??1??" +
z.ToString("00") +
".map");
foreach (FileInfo inf in mapFiles)
{
Location RealLocation = MapFileNameToLocation(inf.Name);
int ArrayX = RealLocation.X - StartX;
int ArrayY = RealLocation.Y - StartY;
byte[] ColorArray = new byte[65536];
FileStream fs = new FileStream(inf.FullName, FileMode.Open);
BufferedStream bs = new BufferedStream(fs);
bs.Read(ColorArray, 0, 65536);
int index = 0;
for (int x = 0; x < 256; x++)
{
for (int y = 0; y < 256; y++)
{
TibiaMap[z, x + ArrayX,y + ArrayY] = ColorArray[index];
index += 1;
}
}
fs.Close();
}
}
}
private Location MapFileNameToLocation(string fileName)
{
Location l = new Location(0, 0, 0);
if (fileName.Length == 12 || fileName.Length == 8)
{
l.X = Int32.Parse(fileName.Substring(0, 3)) * 256;
l.Y = Int32.Parse(fileName.Substring(3, 3)) * 256;
l.Z = Int32.Parse(fileName.Substring(6, 2));
}
return l;
}
}
}
-----------------------------------------------------------------------
Declarate of Location? plz
log:
Error 1 'System.Windows.Forms.Form.Location' is a 'property' but is used like a 'type'
Last edited by MaCrOs; 09-06-2015 at 08:50 AM. Reason: new inf