public static void RewriteMap(string path, int map, int width, int height)
{
string mapPath = Files.GetFilePath("map{0}.mul", map);
FileStream m_map;
BinaryReader m_mapReader;
if (mapPath != null)
{
m_map = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.Read);
m_mapReader = new BinaryReader(m_map);
}
else
return;
int blockx = width >> 3;
int blocky = height >> 3;
string mul = Path.Combine(path, String.Format("map{0}.mul", map));
using (FileStream fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write))
{
MemoryStream memmul = new MemoryStream();
using (BinaryWriter binmul = new BinaryWriter(memmul))
{
for (int x = 0; x < blockx; ++x)
{
for (int y = 0; y < blocky; ++y)
{
try
{
m_mapReader.BaseStream.Seek(((x * blocky) + y) * 196, SeekOrigin.Begin);
int header = m_mapReader.ReadInt32();
binmul.Write(header);
for (int i = 0; i < 64; ++i)
{
short tileid = m_mapReader.ReadInt16();
sbyte z = m_mapReader.ReadSByte();
if ((tileid < 0) || (tileid >= 0x4000))
tileid = 0;
if (z < -128)
z = -128;
if (z > 127)
z = 127;
binmul.Write(tileid);
binmul.Write(z);
}
}
catch //fill rest
{
binmul.BaseStream.Seek(((x * blocky) + y) * 196, SeekOrigin.Begin);
for (; x < blockx; ++x)
{
for (; y < blocky; ++y)
{
binmul.Write((int)0);
for (int i = 0; i < 64; ++i)
{
binmul.Write((short)0);
binmul.Write((sbyte)0);
}
}
y = 0;
}
}
}
}
memmul.WriteTo(fsmul);
}
}
m_mapReader.Close();
}