JazzJackrabbit Community Forums

JazzJackrabbit Community Forums (http://www.jazz2online.com/jcf/index.php)
-   General Jazz Jackrabbit Talk (http://www.jazz2online.com/jcf/forumdisplay.php?f=4)
-   -   JJ2 File Format Specifications (http://www.jazz2online.com/jcf/showthread.php?t=15059)

Cpp Dec 21, 2008 12:58 PM

I think it's the whole data block.

EDIT: My server is currently off-line so I'll just pastebin my source code.
http://pastebin.com/m45d6c54c
http://pastebin.com/m269ed95e

Ricerind Dec 21, 2008 01:42 PM

Yes that is basically taking the CRC32 of the whole compressed data block, everything that's not part of the header.

Violet CLM Dec 21, 2008 08:16 PM

Okay, it looks like I can read and understand that. Thank you both! :D

Krezack Feb 4, 2009 12:38 AM

This should be stickied.

Violet CLM Feb 5, 2009 11:07 AM

It's in ERE...
but as it's been bumped, I figure I may as well ask, is
Code:

fileHeader.crc32 = crc32(0L, Z_NULL, 0);
substantially different from
Code:

fileHeader.crc32 = 0;
? I assume it is, but I don't really know what those variables refer to.

Cpp Feb 6, 2009 11:11 PM

Not quite sure, but I believe the first line initializes the CRC32 for further calculation while the second line only sets it to zero. Check the output variable and see whether they are the same. I think they should differ.

Violet CLM Feb 7, 2009 09:45 AM

I don't use the language, though. The only semi-native CRC implementation at my disposal gets the CRC of an entire file, without asking me what polynomial I would like, so I'm rebuilding it by hand.

Krezack Feb 8, 2009 09:07 PM

Quote:

Originally Posted by Neobeo (Post 394616)
Four-month revival, but I was just wondering whether anyone has been using this information.

I'm coding a function in Python now that basically takes a j2t file and pulls out the mask and image so they can be used in a game I'm making (i.e. my game can accept Jazz 2 tilesets).

So yes, I certainly use it. More accurate specifications would certainly be welcome.

FawFul Feb 8, 2009 11:07 PM

isn't there already something for that called "tileset extractor?"

Violet CLM Feb 8, 2009 11:33 PM

That renders tilesets as image files, but if you're making a game, it's simpler just to have the game read .j2t files directly.

djazz Mar 10, 2009 01:10 AM

J2l format reader in PHP
 
HELLO
I have coded some in PHP now, and I can read ALL J2L data and put it in nicely arrays. I'm even about to read out event-data, but those parameters are hardcoded. It uses JCS.ini for the event-names.
The "Data3" stream is parsed into a easy to use array and all Level Properties too.
I haven't yet finished the read-out of the level, with those "words" in Data3. ALL Layer Properties are parsed into an array, as the Help Strings are too.
I love what you do Neobeo, and thanks the I C E Man's tileset-php code :-)


Have a look here (not complete):
http://djazz.mine.nu/content/jj2rela...2_formats/j2l/

Stijn Mar 10, 2009 02:59 AM

Oh, that's awesome. I started writing a class to do that once but never got around to finishing it. Great that you've done it. Will the source code be available?

Violet CLM Mar 11, 2009 09:28 PM

Quote:

Originally Posted by Unknown Rabbit (Post 443513)
It's in ERE...
but as it's been bumped, I figure I may as well ask, is
Code:

fileHeader.crc32 = crc32(0L, Z_NULL, 0);
substantially different from
Code:

fileHeader.crc32 = 0;
? I assume it is, but I don't really know what those variables refer to.

I ask again. I kind of need to be able to compile things... what is the result of this setting? As I understand it otherwise, taking the CRC (with any polynomial) of 0 is just going to be 0, so there's got to be some sort of starting value, but what is it? Or do I just totally misunderstand the process?

djazz Mar 26, 2009 02:57 AM

Quote:

Originally Posted by Stijn (Post 444730)
Oh, that's awesome. I started writing a class to do that once but never got around to finishing it. Great that you've done it. Will the source code be available?

Thank you :-)
Yes I will release the source soon!

Stijn May 4, 2009 03:08 PM

I made a J2T image generator thingy (in PHP) for J2O today and decided to share it.

Documentation: http://www.stijnpeeters.nl/j2o/class.Tileset/
Source: http://stijnpeeters.nl/j2o/class.Tileset/source.php

It's very basic and doesn't do any file integrity checks, but perhaps it is of use to someone.

(Props to Neobeo, Ice M A N and Grytolle for hints/input/posts in this thread)

Grytolle May 4, 2009 03:20 PM

Yeah you'll find that this thread is full of usefull hints made by me :P "jam lets make dll ok??:D lol hi btw"

Stijn May 4, 2009 03:26 PM

I meant on IRC!

Violet CLM May 4, 2009 10:12 PM

Can anyone answer my question? Please? Or do I just need to go learn a new programming language for one simple task?

djazz May 5, 2009 12:27 AM

Ok here is the source:
http://djazz.mine.nu/content/jj2rela...j2l/index.phps
I haven't modified it since last post
:-)

Grytolle May 5, 2009 01:27 PM

I have no idea, UR, sorry

Violet CLM May 6, 2009 09:10 AM

Another question (though the first remains open), has anyone tried zlibbing the blocks with compression rates other than that which JCS uses? Can JJ2 still read them?

Cpp May 6, 2009 09:15 AM

Quote:

Originally Posted by Unknown Rabbit (Post 447075)
Can anyone answer my question? Please? Or do I just need to go learn a new programming language for one simple task?

This snippet is taken from the zlib manual.

Quote:

uLong crc32 (uLong crc, const Bytef *buf, uInt len);
Update a running crc with the bytes buf[0..len-1] and return the updated crc. If buf is NULL, this function returns the required initial value for the crc. Pre- and post-conditioning (one's complement) is performed within this function so it shouldn't be done by the application. Usage example:
Code:

        uLong crc = crc32(0L, Z_NULL, 0);

        while (read_buffer(buffer, length) != EOF) {
          crc = crc32(crc, buffer, length);
        }
        if (crc != original_crc) error();


Also, have you taken a look at the C++ source code I posted a few replies earlier?

Quote:

Originally Posted by Unknown Rabbit (Post 447167)
Another question (though the first remains open), has anyone tried zlibbing the blocks with compression rates other than that which JCS uses? Can JJ2 still read them?

Yes, it can.

Violet CLM May 6, 2009 10:38 AM

Quote:

Originally Posted by Cpp (Post 447168)
If buf is NULL, this function returns the required initial value for the crc.

I'm asking what this required initial value is. The example usage there is the same as in your source code (albeit with while instead of for), and I think I've managed to hardcode the crc-ing of the four buffers with respect to an existing polynomial, but I don't know what the polynomial should start as, because I don't know what the value of crc32(0L, Z_NULL, 0) is.

Cpp May 6, 2009 11:09 AM

Why do you want to hardcode it in? Last time I checked crc32(0L, Z_NULL, 0), it returned a zero, but I am not sure whether this is always the case. That's why I always initialize the crc variable with whatever value the crc32(0L, Z_NULL, 0) function call returns.

Violet CLM May 6, 2009 11:22 AM

Unless I go learn a new language, the only semi-native CRC support I have is extremely limited and seems only to use a fixed polynomial. Therefore I go through the bit stream and gradually xor onto the polynomial manually, a bit at a time. But if the initial polynomial is 0, then xor isn't going to do a thing and the final CRC will still be 0, right?

Cpp May 6, 2009 11:34 AM

Ah, now I understand your problem. You're not using the zlib library and/or C++ language. Personally I am not sure how the code you're using works, but I've checked the zlib source code and apparently the crc32 function always returns zero when the buffer param is set to Z_NULL. So in this case crc32(0L, Z_NULL, 0) = 0. If you pass a zero to your function, it won't work?

Code:

unsigned long ZEXPORT crc32(crc, buf, len)
    unsigned long crc;
    const unsigned char FAR *buf;
    unsigned len;
{
    if (buf == Z_NULL) return 0UL;

#ifdef DYNAMIC_CRC_TABLE
    if (crc_table_empty)
        make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */

#ifdef BYFOUR
    if (sizeof(void *) == sizeof(ptrdiff_t)) {
        u4 endian;

        endian = 1;
        if (*((unsigned char *)(&endian)))
            return crc32_little(crc, buf, len);
        else
            return crc32_big(crc, buf, len);
    }
#endif /* BYFOUR */
    crc = crc ^ 0xffffffffUL;
    while (len >= 8) {
        DO8;
        len -= 8;
    }
    if (len) do {
        DO1;
    } while (--len);
    return crc ^ 0xffffffffUL;
}


Violet CLM May 9, 2009 09:40 AM

Huh. I guess I just don't understand the function somehow, then... I'll have to do some more digging around and find an explanation of CRC that doesn't instruct me to xor lots of stuff by 0. Thanks.

Stijn May 25, 2009 04:08 AM

I updated my Tileset class and wrote a Level class, capable of rendering a preview of an arbitrary layer in a level. Note that especially the Level class is very basic and neither have error handling or checksum checking or stuff like that built-in.

Source code:
http://www.jazz2online.com/junk/sour...lass.Level.php
http://www.jazz2online.com/junk/sour...ss.Tileset.php

Thanks to Neobeo/J2NSM for the source code their file format documentation.

djazz May 31, 2009 09:47 AM

Wow, fantastic Stijn ;-)

I haven't tried it out yet, but I will! :D
Your code looks much better than mine too.

You maybe should add an example showing how to use?

GJ! :-)


________
Edit:

I got some errors that's listed below:
PHP Code:

Notice:  Undefined index:  tiles in C:\wamp\www\Daniels_Server\content\jj2related\JJ2_formats\j2l\class.Tileset.php on line 265

Warning
:  imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\wamp\www\Daniels_Server\content\jj2related\JJ2_formats\j2l\class.Tileset.php on line 265

Warning
:  imagecolorallocate(): supplied argument is not a valid Image resource in C:\wamp\www\Daniels_Server\content\jj2related\JJ2_formats\j2l\class.Tileset.php on line 266

Warning
:  imagefill(): supplied argument is not a valid Image resource in C:\wamp\www\Daniels_Server\content\jj2related\JJ2_formats\j2l\class.Tileset.php on line 266

Warning
:  imagecopy(): supplied argument is not a valid Image resource in C:\wamp\www\Daniels_Server\content\jj2related\JJ2_formats\j2l\class.Level.php on line 638 

On line 265: $iImag e = imagecreatetruecolor(320,(($this->aOffsets['tiles']/10)*32));

Do you know how to fix this? I have tried with multiple j2l files.

my code for the classes:
PHP Code:

<?php
require_once("class.Level.php");
$Level = new Level("test.j2l");
//header("Content-type: image/png");
imagepng($Level->getRealPreview());
?>


Stijn May 31, 2009 10:06 AM

Code:

<?php
require 'class.Level.php';
require 'class.Tileset.php';

$oLevel = new Level('battle1.j2l');

header('Content-type: image/png');
echo $oLevel->getRealPreview();

To see it in action check the J2O downloads and click a file name in the "file contents" part ;)

I've made a few tweaks to it since I published the code there, I'll probably put an updated version online soon.

djazz May 31, 2009 10:11 AM

Sorry still not working for me :(

And please make the source files downloadable, that copy-paste adds # signs

Stijn May 31, 2009 10:12 AM

Source and documentation updated now... several changes to the code structure, but the most interesting improvement will be that animated, flipped and translucent tiles are now supported.

What does not work for you? It might be hard to debug since the classes still lack proper error handling. I've had little need for that since they work for their primary purpose - previews on J2O - but it's open source so feel free to improve that by yourself ;)

Stijn May 31, 2009 11:06 AM

Oh, I see the errors you pasted - strange... "tiles" should be defined at that point since the method that defines it is called from the object constructor... unless the constructor terminates before it reaches that point because it can't find the tileset file. Are you 100% sure the tileset path passed on to the Tileset constructor (line 596, class.Level.php) is correct? Did you perhaps forget to change the Level::ROOT_DIR constant to point to the correct location?

Cpp May 31, 2009 01:03 PM

Quote:

Originally Posted by Stijn (Post 448019)
To see it in action check the J2O downloads and click a file name in the "file contents" part ;)

This is indeed a nice addition to the website. May I suggest a feature where you can choose to download individual files from the package... assuming the new J2O file storage standard is in place.

EDIT: I just noticed the foreground layer tiling doesn't seem to work.
http://www.jazz2online.com/J2Ov2/dow...=160&sizey=248

EDIT2: Is it just me or is this level displayed entirely black?
http://www.jazz2online.com/J2Ov2/dow...024&sizey=1024

Stijn May 31, 2009 02:09 PM

Yes @ both. When a tileset is not found it will use black tiles.

We will not allow downloading individual files I think, simply because people upload their stuff as archives to our site, not as individual files :) An option to, for example, ignore music files might be implemented later though.

EDIT: In the case of this particular level it appears that there are two different sets named "pk2.j2t" on J2O. Since there is no way to determine which one is correct based on the J2L file alone, it uses the wrong tileset. The black tiles are references to tiles that don't exist in the "other" pk2.j2t.

Cpp May 31, 2009 09:49 PM

Quote:

Originally Posted by Stijn (Post 448030)
EDIT: In the case of this particular level it appears that there are two different sets named "pk2.j2t" on J2O. Since there is no way to determine which one is correct based on the J2L file alone, it uses the wrong tileset. The black tiles are references to tiles that don't exist in the "other" pk2.j2t.

Is it not obvious to select the one that comes along in the archive?

Stijn Jun 1, 2009 12:43 AM

Not if the code is structured like it is now.

djazz Jun 1, 2009 05:56 AM

Ok, got it fixed, I don't know how but it's working :D

Are there any todos left? flipped tiles, have you fixed them? Here is a code for flipping images: http://se2.php.net/manual/en/functio...copy.php#85992

More improovements is to put an image where it should be a event

Stijn Jun 1, 2009 08:20 AM

Flipped tiles are supported.

Events are certainly possible but image generation would take a lot longer then so it's not a priority for me (the primary use for me personally is still J2O image preview).

djazz Jun 1, 2009 11:04 AM

See you've updated the source, but, could you please add a download link, it's so hard to remove all # signs and extra linebreaks

The PHP works rly nice, but it's very slow


All times are GMT -8. The time now is 10:23 AM.

Powered by vBulletin® Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
JCF © 2001-Infinity Jazz2Online