Link to home
Start Free TrialLog in
Avatar of Michael Lam
Michael Lam

asked on

how to convert .bin file to .tmx (Tiled Map Editor) file

i am trying to do some reverse engineering here to reuse/modify some good existing map files in my game that are in the .bin format.  normally, you used Tiled with QT plugin to export a visual map (.tmx) file to a .bin file.  i was able to further convert the .bin file to a text file by converting the byte array into a HEX string, which i can display as a text file.  this way i can find out how the map actually works.  

so what's in the .tmx file as:

<data encoding="base64" compression="gzip">
   H4sIAAAAAAAAC+3YsQmAQBAAQbEDsQf7L1HNxECDBUWZgcuP5fjghwEAeNr89gIfp1+jX6Nfo1+jX6Nfo1+jX6NfM20zXszy3mq/sPfVsNGw07A7vpVaNu6x07DTsNOw07DTsNOw07A7/0vo2bjJ7u6v7IuzAjr0Cq0AKAAA
  </data>

now becomes the following HEX string:

FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
12121212121212121212121212FFFF1212121212

to do the reverse engineeing, i do the following:
1) convert the HEX string back to byte array
2) do gzip compression using the following method:
      public static String gzipCompress(String str) throws IOException
      {
            if (str == null || str.length() == 0)
            {
                  return str;
            }
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            GZIPOutputStream gzip = new GZIPOutputStream(out);
            gzip.write(str.getBytes());
            gzip.close();
            return out.toString("UTF-8");
      }


3) do base64 encoding using:

      Base64 base = new Base64();
      byte[] dataBytes = base.encode(data.getBytes());
      
but the resulting string looks a little bit different:
H4sIAAAAAAAAAPv/fxQMZyA0at6oeaPm4QQCjBCgSm1zR6A/o6E4auAwNXBIlBCMZAAAqt26ygAK&#13;AAA=&#13;

can someone tell me what i am missing?  thanks.
SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:)