We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

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

Medium Priority
1,013 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.
Comment
Watch Question

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2016
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2013
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2016

Commented:
:)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.