?
Solved

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

Posted on 2011-04-29
4
Medium Priority
?
918 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:mmingfeilam
  • 2
4 Comments
 
LVL 92

Assisted Solution

by:objects
objects earned 664 total points
ID: 35490024
try specifying the encoding in your call to getBytes(), its possibly UTF-8
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 668 total points
ID: 35490159
>>2) do gzip compression using the following method:

Shouldn't you be DEcompressing it?
0
 
LVL 63

Assisted Solution

by:☠ MASQ ☠
☠ MASQ ☠ earned 668 total points
ID: 35490258
.tmx to .bin - YES

.bin to .tmx - NO

Don't forget that to get to the.bin the .xml of the .tmx is being compiled, the best you'll get is pretty much where you are now, the header file which isn't converted (metadata like <header>, <prop> and <note>) the <body> part of the .tmx can't be "decompiled" back to the .xml source code.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35727692
:)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here, we have shared an easy step by step tutorial on how to download instagram images and videos on PC, Android Mobile and iOS mobile.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question