So, you all know about that convenient little program that converts jm files to wmap files, correct?
Well, up until now, you haven't been able to reverse the process. I found myself needing to
do such a thing, so I came up with this. It turns a wmap file into a usable jm file.
First, edit Program.cs in Json2wmapConv:
Code:
using System;
using System.Collections.Generic;
using terrain;
namespace terrain
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 2 || args.Length > 3)
{
Console.WriteLine("usage: Json2wmapConv.exe jsonfile wmapfile");
return;
}
try
{
FileInfo fi = new FileInfo(args[0].ToString());
if (fi.Exists)
if (args.Length != 3)
terrain.Json2Wmap.Convert(args[0], args[1]);
else
terrain.Json2Wmap.ConvertReverse(args[0], args[1]);
else
{
Console.WriteLine("input file not found: " + fi.FullName);
return;
}
}
catch (Exception e)
{
Console.WriteLine("Exception : " + e);
}
Console.WriteLine("done");
}
}
}
After that, insert the following two functions into Json2Wmap.cs inside the terrain project:
Code:
public static void ConvertReverse(string from, string to)
{
var x = ConvertReverse(File.ReadAllBytes(from));
File.WriteAllText(to, x);
}
public static string ConvertReverse(byte[] wmap)
{
var obj = new json_dat();
List<TerrainTile> terdict = new List<TerrainTile>();
List<loc> dict = new List<loc>();
List<byte> wmb = new List<byte>();
foreach (var i in wmap)
wmb.Add(i);
wmb.RemoveAt(0);
wmap = ZlibStream.UncompressBuffer(wmb.ToArray());
List<byte> dat = new List<byte>();
List<short> newDat = new List<short>();
using (var rdr = new BinaryReader(new MemoryStream(wmap)))
{
short dicLength = rdr.ReadInt16();
for (short i = 0; i < dicLength; i++)
{
terdict.Add(new TerrainTile()
{
TileId = rdr.ReadInt16(),
TileObj = rdr.ReadString(),
Name = rdr.ReadString(),
Terrain = (TerrainType)rdr.ReadByte(),
Region = (TileRegion)rdr.ReadByte()
});
}
obj.width = rdr.ReadInt32();
obj.height = rdr.ReadInt32();
dat = rdr.ReadBytes(obj.width * obj.height * 3).ToList();
}
using (var rdr = new BinaryReader(new MemoryStream(dat.ToArray())))
{
for (int i = 0; i < obj.width * obj.height; i++)
{
newDat.Add(rdr.ReadInt16());
rdr.ReadByte(); //Elevation, don't need
}
}
foreach (var i in terdict)
{
dict.Add(new loc()
{
ground = XmlDatas.TileDescs[i.TileId].ObjectId,
objs = i.TileObj == null ? null : new obj[] { new obj(){ id = i.TileObj, name = i.Name } },
regions = i.Region == TileRegion.None ? null : new obj[] { new obj(){ id = i.Region.ToString().Replace('_', ' '), name = "" } }
});
}
MemoryStream s = new MemoryStream();
using (var wtr = new NWriter(s))
{
foreach (var i in newDat)
{
wtr.Write(i);
}
}
obj.dict = dict.ToArray();
obj.data = ZlibStream.CompressBuffer(s.ToArray());
return JsonConve******rializeObject(obj);
}
Finally, make a World Decompiler.bat in the same folder as your World Converter.bat and use this code:
Code:
@echo off
set /p wmap="Enter map name: "
copy %wmap%.wmap Json2wmapConv\bin\Debug
Json2wmapConv\bin\Debug\Json2wmapConv %wmap%.wmap %wmap%.jm decompile
echo Decompiled map!
pause